1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11 * Copyright(c) 2018 Intel Corporation
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * The full GNU General Public License is included in this distribution
23 * in the file called COPYING.
25 * Contact Information:
27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34 * Copyright(c) 2018 Intel Corporation
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
47 * * Neither the name Intel Corporation nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *****************************************************************************/
64 #include <linux/kernel.h>
65 #include <linux/slab.h>
66 #include <linux/skbuff.h>
67 #include <linux/netdevice.h>
68 #include <linux/etherdevice.h>
70 #include <linux/if_arp.h>
71 #include <linux/time.h>
72 #include <net/mac80211.h>
73 #include <net/ieee80211_radiotap.h>
76 #include "iwl-op-mode.h"
80 #include "time-event.h"
81 #include "iwl-eeprom-parse.h"
82 #include "iwl-phy-db.h"
84 #include "fw/error-dump.h"
86 #include "iwl-nvm-parse.h"
88 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
91 .types = BIT(NL80211_IFTYPE_STATION),
95 .types = BIT(NL80211_IFTYPE_AP) |
96 BIT(NL80211_IFTYPE_P2P_CLIENT) |
97 BIT(NL80211_IFTYPE_P2P_GO),
101 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
105 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
107 .num_different_channels = 2,
109 .limits = iwl_mvm_limits,
110 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
114 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
116 * Use the reserved field to indicate magic values.
117 * these values will only be used internally by the driver,
118 * and won't make it to the fw (reserved will be 0).
119 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
120 * be the vif's ip address. in case there is not a single
121 * ip address (0, or more than 1), this attribute will
123 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
124 * the LSB bytes of the vif's mac address
127 BC_FILTER_MAGIC_NONE = 0,
132 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
136 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
139 /* frame type - arp, hw type - ethernet */
141 BCAST_FILTER_OFFSET_PAYLOAD_START,
142 .offset = sizeof(rfc1042_header),
143 .val = cpu_to_be32(0x08060001),
144 .mask = cpu_to_be32(0xffffffff),
149 BCAST_FILTER_OFFSET_PAYLOAD_START,
150 .offset = sizeof(rfc1042_header) + 2 +
151 sizeof(struct arphdr) +
152 ETH_ALEN + sizeof(__be32) +
154 .mask = cpu_to_be32(0xffffffff),
155 /* mark it as special field */
156 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
161 /* dhcp offer bcast */
163 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
166 /* udp dest port - 68 (bootp client)*/
167 .offset_type = BCAST_FILTER_OFFSET_IP_END,
168 .offset = offsetof(struct udphdr, dest),
169 .val = cpu_to_be32(0x00440000),
170 .mask = cpu_to_be32(0xffff0000),
173 /* dhcp - lsb bytes of client hw address */
174 .offset_type = BCAST_FILTER_OFFSET_IP_END,
176 .mask = cpu_to_be32(0xffffffff),
177 /* mark it as special field */
178 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
182 /* last filter must be empty */
187 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
189 if (!iwl_mvm_is_d0i3_supported(mvm))
192 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
193 spin_lock_bh(&mvm->refs_lock);
194 mvm->refs[ref_type]++;
195 spin_unlock_bh(&mvm->refs_lock);
196 iwl_trans_ref(mvm->trans);
199 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
201 if (!iwl_mvm_is_d0i3_supported(mvm))
204 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
205 spin_lock_bh(&mvm->refs_lock);
206 if (WARN_ON(!mvm->refs[ref_type])) {
207 spin_unlock_bh(&mvm->refs_lock);
210 mvm->refs[ref_type]--;
211 spin_unlock_bh(&mvm->refs_lock);
212 iwl_trans_unref(mvm->trans);
215 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
216 enum iwl_mvm_ref_type except_ref)
220 if (!iwl_mvm_is_d0i3_supported(mvm))
223 spin_lock_bh(&mvm->refs_lock);
224 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
225 if (except_ref == i || !mvm->refs[i])
228 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
230 for (j = 0; j < mvm->refs[i]; j++)
231 iwl_trans_unref(mvm->trans);
234 spin_unlock_bh(&mvm->refs_lock);
237 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
242 if (!iwl_mvm_is_d0i3_supported(mvm))
245 spin_lock_bh(&mvm->refs_lock);
246 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
252 spin_unlock_bh(&mvm->refs_lock);
257 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
259 iwl_mvm_ref(mvm, ref_type);
261 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
262 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
265 iwl_mvm_unref(mvm, ref_type);
272 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
276 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
277 for (i = 0; i < NUM_PHY_CTX; i++) {
278 mvm->phy_ctxts[i].id = i;
279 mvm->phy_ctxts[i].ref = 0;
283 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
285 enum iwl_mcc_source src_id,
288 struct ieee80211_regdomain *regd = NULL;
289 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
290 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
291 struct iwl_mcc_update_resp *resp;
293 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
295 lockdep_assert_held(&mvm->mutex);
297 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
298 if (IS_ERR_OR_NULL(resp)) {
299 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
300 PTR_ERR_OR_ZERO(resp));
305 *changed = (resp->status == MCC_RESP_NEW_CHAN_PROFILE);
307 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
308 __le32_to_cpu(resp->n_channels),
310 __le16_to_cpu(resp->mcc),
311 __le16_to_cpu(resp->geo_info));
312 /* Store the return source id */
313 src_id = resp->source_id;
315 if (IS_ERR_OR_NULL(regd)) {
316 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
317 PTR_ERR_OR_ZERO(regd));
321 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
322 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
323 mvm->lar_regdom_set = true;
324 mvm->mcc_src = src_id;
330 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
333 struct ieee80211_regdomain *regd;
335 if (!iwl_mvm_is_lar_supported(mvm))
338 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
339 if (!IS_ERR_OR_NULL(regd)) {
340 /* only update the regulatory core if changed */
342 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
348 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
351 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
352 iwl_mvm_is_wifi_mcc_supported(mvm) ?
353 MCC_SOURCE_GET_CURRENT :
354 MCC_SOURCE_OLD_FW, changed);
357 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
359 enum iwl_mcc_source used_src;
360 struct ieee80211_regdomain *regd;
363 const struct ieee80211_regdomain *r =
364 rtnl_dereference(mvm->hw->wiphy->regd);
369 /* save the last source in case we overwrite it below */
370 used_src = mvm->mcc_src;
371 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
372 /* Notify the firmware we support wifi location updates */
373 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
374 if (!IS_ERR_OR_NULL(regd))
378 /* Now set our last stored MCC and source */
379 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
381 if (IS_ERR_OR_NULL(regd))
384 /* update cfg80211 if the regdomain was changed */
386 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
394 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
396 struct ieee80211_hw *hw = mvm->hw;
398 static const u32 mvm_ciphers[] = {
399 WLAN_CIPHER_SUITE_WEP40,
400 WLAN_CIPHER_SUITE_WEP104,
401 WLAN_CIPHER_SUITE_TKIP,
402 WLAN_CIPHER_SUITE_CCMP,
405 /* Tell mac80211 our characteristics */
406 ieee80211_hw_set(hw, SIGNAL_DBM);
407 ieee80211_hw_set(hw, SPECTRUM_MGMT);
408 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
409 ieee80211_hw_set(hw, QUEUE_CONTROL);
410 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
411 ieee80211_hw_set(hw, SUPPORTS_PS);
412 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
413 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
414 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
415 ieee80211_hw_set(hw, CONNECTION_MONITOR);
416 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
417 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
418 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
419 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
420 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
421 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
422 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
424 if (iwl_mvm_has_tlc_offload(mvm)) {
425 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
426 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
429 if (iwl_mvm_has_new_rx_api(mvm))
430 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
432 if (fw_has_capa(&mvm->fw->ucode_capa,
433 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
434 ieee80211_hw_set(hw, AP_LINK_PS);
435 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
437 * we absolutely need this for the new TX API since that comes
438 * with many more queues than the current code can deal with
439 * for station powersave
444 if (mvm->trans->num_rx_queues > 1)
445 ieee80211_hw_set(hw, USES_RSS);
447 if (mvm->trans->max_skb_frags)
448 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
450 hw->queues = IEEE80211_MAX_QUEUES;
451 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
452 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
453 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
454 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
455 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
457 hw->radiotap_timestamp.units_pos =
458 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
459 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
460 /* this is the case for CCK frames, it's better (only 8) for OFDM */
461 hw->radiotap_timestamp.accuracy = 22;
463 if (!iwl_mvm_has_tlc_offload(mvm))
464 hw->rate_control_algorithm = RS_NAME;
466 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
467 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
469 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
470 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
471 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
472 hw->wiphy->cipher_suites = mvm->ciphers;
474 if (iwl_mvm_has_new_rx_api(mvm)) {
475 mvm->ciphers[hw->wiphy->n_cipher_suites] =
476 WLAN_CIPHER_SUITE_GCMP;
477 hw->wiphy->n_cipher_suites++;
478 mvm->ciphers[hw->wiphy->n_cipher_suites] =
479 WLAN_CIPHER_SUITE_GCMP_256;
480 hw->wiphy->n_cipher_suites++;
483 /* Enable 11w if software crypto is not enabled (as the
484 * firmware will interpret some mgmt packets, so enabling it
485 * with software crypto isn't safe).
487 if (!iwlwifi_mod_params.swcrypto) {
488 ieee80211_hw_set(hw, MFP_CAPABLE);
489 mvm->ciphers[hw->wiphy->n_cipher_suites] =
490 WLAN_CIPHER_SUITE_AES_CMAC;
491 hw->wiphy->n_cipher_suites++;
492 if (iwl_mvm_has_new_rx_api(mvm)) {
493 mvm->ciphers[hw->wiphy->n_cipher_suites] =
494 WLAN_CIPHER_SUITE_BIP_GMAC_128;
495 hw->wiphy->n_cipher_suites++;
496 mvm->ciphers[hw->wiphy->n_cipher_suites] =
497 WLAN_CIPHER_SUITE_BIP_GMAC_256;
498 hw->wiphy->n_cipher_suites++;
502 /* currently FW API supports only one optional cipher scheme */
503 if (mvm->fw->cs[0].cipher) {
504 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
505 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
507 mvm->hw->n_cipher_schemes = 1;
509 cs->cipher = le32_to_cpu(fwcs->cipher);
510 cs->iftype = BIT(NL80211_IFTYPE_STATION);
511 cs->hdr_len = fwcs->hdr_len;
512 cs->pn_len = fwcs->pn_len;
513 cs->pn_off = fwcs->pn_off;
514 cs->key_idx_off = fwcs->key_idx_off;
515 cs->key_idx_mask = fwcs->key_idx_mask;
516 cs->key_idx_shift = fwcs->key_idx_shift;
517 cs->mic_len = fwcs->mic_len;
519 mvm->hw->cipher_schemes = mvm->cs;
520 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
521 hw->wiphy->n_cipher_suites++;
524 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
525 hw->wiphy->features |=
526 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
527 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
528 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
530 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
531 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
532 hw->chanctx_data_size = sizeof(u16);
534 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
535 BIT(NL80211_IFTYPE_P2P_CLIENT) |
536 BIT(NL80211_IFTYPE_AP) |
537 BIT(NL80211_IFTYPE_P2P_GO) |
538 BIT(NL80211_IFTYPE_P2P_DEVICE) |
539 BIT(NL80211_IFTYPE_ADHOC);
541 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
542 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
543 if (iwl_mvm_is_lar_supported(mvm))
544 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
546 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
547 REGULATORY_DISABLE_BEACON_HINTS;
549 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
550 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
552 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
553 hw->wiphy->n_iface_combinations =
554 ARRAY_SIZE(iwl_mvm_iface_combinations);
556 hw->wiphy->max_remain_on_channel_duration = 10000;
557 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
559 /* Extract MAC address */
560 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
561 hw->wiphy->addresses = mvm->addresses;
562 hw->wiphy->n_addresses = 1;
564 /* Extract additional MAC addresses if available */
565 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
566 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
568 for (i = 1; i < num_mac; i++) {
569 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
571 mvm->addresses[i].addr[5]++;
572 hw->wiphy->n_addresses++;
575 iwl_mvm_reset_phy_ctxts(mvm);
577 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
579 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
581 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
582 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
583 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
585 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
586 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
588 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
590 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
591 hw->wiphy->bands[NL80211_BAND_2GHZ] =
592 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
593 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
594 hw->wiphy->bands[NL80211_BAND_5GHZ] =
595 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
597 if (fw_has_capa(&mvm->fw->ucode_capa,
598 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
599 fw_has_api(&mvm->fw->ucode_capa,
600 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
601 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
602 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
605 hw->wiphy->hw_version = mvm->trans->hw_id;
607 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
608 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
610 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
612 hw->wiphy->max_sched_scan_reqs = 1;
613 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
614 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
615 /* we create the 802.11 header and zero length SSID IE. */
616 hw->wiphy->max_sched_scan_ie_len =
617 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
618 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
619 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
622 * the firmware uses u8 for num of iterations, but 0xff is saved for
623 * infinite loop, so the maximum number of iterations is actually 254.
625 hw->wiphy->max_sched_scan_plan_iterations = 254;
627 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
628 NL80211_FEATURE_LOW_PRIORITY_SCAN |
629 NL80211_FEATURE_P2P_GO_OPPPS |
630 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
631 NL80211_FEATURE_DYNAMIC_SMPS |
632 NL80211_FEATURE_STATIC_SMPS |
633 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
635 if (fw_has_capa(&mvm->fw->ucode_capa,
636 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
637 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
638 if (fw_has_capa(&mvm->fw->ucode_capa,
639 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
640 hw->wiphy->features |= NL80211_FEATURE_QUIET;
642 if (fw_has_capa(&mvm->fw->ucode_capa,
643 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
644 hw->wiphy->features |=
645 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
647 if (fw_has_capa(&mvm->fw->ucode_capa,
648 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
649 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
651 if (fw_has_api(&mvm->fw->ucode_capa,
652 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
653 wiphy_ext_feature_set(hw->wiphy,
654 NL80211_EXT_FEATURE_SCAN_START_TIME);
655 wiphy_ext_feature_set(hw->wiphy,
656 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
657 wiphy_ext_feature_set(hw->wiphy,
658 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
661 if (iwl_mvm_is_oce_supported(mvm)) {
662 wiphy_ext_feature_set(hw->wiphy,
663 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
664 wiphy_ext_feature_set(hw->wiphy,
665 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
666 wiphy_ext_feature_set(hw->wiphy,
667 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
668 wiphy_ext_feature_set(hw->wiphy,
669 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
672 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
674 #ifdef CONFIG_PM_SLEEP
675 if (iwl_mvm_is_d0i3_supported(mvm) &&
676 device_can_wakeup(mvm->trans->dev)) {
677 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
678 hw->wiphy->wowlan = &mvm->wowlan;
681 if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
682 mvm->trans->ops->d3_suspend &&
683 mvm->trans->ops->d3_resume &&
684 device_can_wakeup(mvm->trans->dev)) {
685 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
686 WIPHY_WOWLAN_DISCONNECT |
687 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
688 WIPHY_WOWLAN_RFKILL_RELEASE |
689 WIPHY_WOWLAN_NET_DETECT;
690 if (!iwlwifi_mod_params.swcrypto)
691 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
692 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
693 WIPHY_WOWLAN_4WAY_HANDSHAKE;
695 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
696 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
697 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
698 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
699 hw->wiphy->wowlan = &mvm->wowlan;
703 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
704 /* assign default bcast filtering configuration */
705 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
708 ret = iwl_mvm_leds_init(mvm);
712 if (fw_has_capa(&mvm->fw->ucode_capa,
713 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
714 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
715 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
716 ieee80211_hw_set(hw, TDLS_WIDER_BW);
719 if (fw_has_capa(&mvm->fw->ucode_capa,
720 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
721 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
722 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
725 hw->netdev_features |= mvm->cfg->features;
726 if (!iwl_mvm_is_csum_supported(mvm)) {
727 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
729 /* We may support SW TX CSUM */
730 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
731 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
734 ret = ieee80211_register_hw(mvm->hw);
736 iwl_mvm_leds_exit(mvm);
737 mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
739 if (mvm->cfg->vht_mu_mimo_supported)
740 wiphy_ext_feature_set(hw->wiphy,
741 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
746 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
747 struct ieee80211_sta *sta,
750 struct iwl_mvm_sta *mvmsta;
754 * double check the IN_D0I3 flag both before and after
755 * taking the spinlock, in order to prevent taking
756 * the spinlock when not needed.
758 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
761 spin_lock(&mvm->d0i3_tx_lock);
763 * testing the flag again ensures the skb dequeue
764 * loop (on d0i3 exit) hasn't run yet.
766 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
769 mvmsta = iwl_mvm_sta_from_mac80211(sta);
770 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
771 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
774 __skb_queue_tail(&mvm->d0i3_tx, skb);
775 ieee80211_stop_queues(mvm->hw);
778 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
779 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
783 spin_unlock(&mvm->d0i3_tx_lock);
787 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
788 struct ieee80211_tx_control *control,
791 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
792 struct ieee80211_sta *sta = control->sta;
793 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
794 struct ieee80211_hdr *hdr = (void *)skb->data;
796 if (iwl_mvm_is_radio_killed(mvm)) {
797 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
801 if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
802 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
803 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
806 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
807 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
808 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
809 ieee80211_is_mgmt(hdr->frame_control) &&
810 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
813 /* If there is no sta, and it's not offchannel - send through AP */
814 if (info->control.vif->type == NL80211_IFTYPE_STATION &&
815 info->hw_queue != IWL_MVM_OFFCHANNEL_QUEUE && !sta) {
816 struct iwl_mvm_vif *mvmvif =
817 iwl_mvm_vif_from_mac80211(info->control.vif);
818 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
820 if (ap_sta_id < IWL_MVM_STATION_COUNT) {
821 /* mac80211 holds rcu read lock */
822 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
823 if (IS_ERR_OR_NULL(sta))
829 if (iwl_mvm_defer_tx(mvm, sta, skb))
831 if (iwl_mvm_tx_skb(mvm, skb, sta))
836 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
840 ieee80211_free_txskb(hw, skb);
843 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
845 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
850 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
852 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
854 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
857 /* enabled by default */
861 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
863 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
865 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
869 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
870 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
871 enum ieee80211_ampdu_mlme_action action)
873 struct iwl_fw_dbg_trigger_tlv *trig;
874 struct iwl_fw_dbg_trigger_ba *ba_trig;
876 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
881 ba_trig = (void *)trig->data;
884 case IEEE80211_AMPDU_TX_OPERATIONAL: {
885 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
886 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
888 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
889 "TX AGG START: MAC %pM tid %d ssn %d\n",
890 sta->addr, tid, tid_data->ssn);
893 case IEEE80211_AMPDU_TX_STOP_CONT:
894 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
895 "TX AGG STOP: MAC %pM tid %d\n",
898 case IEEE80211_AMPDU_RX_START:
899 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
900 "RX AGG START: MAC %pM tid %d ssn %d\n",
901 sta->addr, tid, rx_ba_ssn);
903 case IEEE80211_AMPDU_RX_STOP:
904 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
905 "RX AGG STOP: MAC %pM tid %d\n",
913 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
914 struct ieee80211_vif *vif,
915 struct ieee80211_ampdu_params *params)
917 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
919 bool tx_agg_ref = false;
920 struct ieee80211_sta *sta = params->sta;
921 enum ieee80211_ampdu_mlme_action action = params->action;
922 u16 tid = params->tid;
923 u16 *ssn = ¶ms->ssn;
924 u16 buf_size = params->buf_size;
925 bool amsdu = params->amsdu;
926 u16 timeout = params->timeout;
928 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
929 sta->addr, tid, action);
931 if (!(mvm->nvm_data->sku_cap_11n_enable))
934 /* return from D0i3 before starting a new Tx aggregation */
936 case IEEE80211_AMPDU_TX_START:
937 case IEEE80211_AMPDU_TX_STOP_CONT:
938 case IEEE80211_AMPDU_TX_STOP_FLUSH:
939 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
940 case IEEE80211_AMPDU_TX_OPERATIONAL:
942 * for tx start, wait synchronously until D0i3 exit to
943 * get the correct sequence number for the tid.
944 * additionally, some other ampdu actions use direct
945 * target access, which is not handled automatically
946 * by the trans layer (unlike commands), so wait for
947 * d0i3 exit in these cases as well.
949 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
959 mutex_lock(&mvm->mutex);
962 case IEEE80211_AMPDU_RX_START:
963 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
964 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
965 struct iwl_mvm_vif *mvmvif;
966 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
967 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
969 mdata->opened_rx_ba_sessions = true;
970 mvmvif = iwl_mvm_vif_from_mac80211(vif);
971 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
973 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
977 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
980 case IEEE80211_AMPDU_RX_STOP:
981 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
984 case IEEE80211_AMPDU_TX_START:
985 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
989 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
991 case IEEE80211_AMPDU_TX_STOP_CONT:
992 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
994 case IEEE80211_AMPDU_TX_STOP_FLUSH:
995 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
996 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
998 case IEEE80211_AMPDU_TX_OPERATIONAL:
999 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1011 if (action == IEEE80211_AMPDU_RX_START)
1014 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1017 mutex_unlock(&mvm->mutex);
1020 * If the tid is marked as started, we won't use it for offloaded
1021 * traffic on the next D0i3 entry. It's safe to unref.
1024 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1029 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1030 struct ieee80211_vif *vif)
1032 struct iwl_mvm *mvm = data;
1033 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1035 mvmvif->uploaded = false;
1036 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1038 spin_lock_bh(&mvm->time_event_lock);
1039 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1040 spin_unlock_bh(&mvm->time_event_lock);
1042 mvmvif->phy_ctxt = NULL;
1043 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1044 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
1047 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1049 /* clear the D3 reconfig, we only need it to avoid dumping a
1050 * firmware coredump on reconfiguration, we shouldn't do that
1051 * on D3->D0 transition
1053 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1054 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1055 iwl_fw_error_dump(&mvm->fwrt);
1058 /* cleanup all stale references (scan, roc), but keep the
1059 * ucode_down ref until reconfig is complete
1061 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1063 iwl_mvm_stop_device(mvm);
1065 mvm->scan_status = 0;
1066 mvm->ps_disabled = false;
1067 mvm->calibrating = false;
1069 /* just in case one was running */
1070 iwl_mvm_cleanup_roc_te(mvm);
1071 ieee80211_remain_on_channel_expired(mvm->hw);
1074 * cleanup all interfaces, even inactive ones, as some might have
1075 * gone down during the HW restart
1077 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1079 mvm->p2p_device_vif = NULL;
1080 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1082 iwl_mvm_reset_phy_ctxts(mvm);
1083 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1084 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
1085 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1086 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1088 ieee80211_wake_queues(mvm->hw);
1090 /* clear any stale d0i3 state */
1091 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1094 mvm->rx_ba_sessions = 0;
1095 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1096 mvm->monitor_on = false;
1098 /* keep statistics ticking */
1099 iwl_mvm_accu_radio_stats(mvm);
1102 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1106 lockdep_assert_held(&mvm->mutex);
1108 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1110 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1111 * so later code will - from now on - see that we're doing it.
1113 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1114 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1115 /* Clean up some internal and mac80211 state on restart */
1116 iwl_mvm_restart_cleanup(mvm);
1118 /* Hold the reference to prevent runtime suspend while
1119 * the start procedure runs. It's a bit confusing
1120 * that the UCODE_DOWN reference is taken, but it just
1121 * means "UCODE is not UP yet". ( TODO: rename this
1124 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1126 ret = iwl_mvm_up(mvm);
1128 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1129 /* Something went wrong - we need to finish some cleanup
1130 * that normally iwl_mvm_mac_restart_complete() below
1133 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1135 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1142 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1144 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1147 /* Some hw restart cleanups must not hold the mutex */
1148 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1150 * Make sure we are out of d0i3. This is needed
1151 * to make sure the reference accounting is correct
1152 * (and there is no stale d0i3_exit_work).
1154 wait_event_timeout(mvm->d0i3_exit_waitq,
1155 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1160 mutex_lock(&mvm->mutex);
1161 ret = __iwl_mvm_mac_start(mvm);
1162 mutex_unlock(&mvm->mutex);
1167 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1171 mutex_lock(&mvm->mutex);
1173 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1175 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1177 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1179 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1182 /* allow transport/FW low power modes */
1183 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1186 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1187 * of packets the FW sent out, so we must reconnect.
1189 iwl_mvm_teardown_tdls_peers(mvm);
1191 mutex_unlock(&mvm->mutex);
1194 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1196 if (iwl_mvm_is_d0i3_supported(mvm) &&
1197 iwl_mvm_enter_d0i3_on_suspend(mvm))
1198 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1199 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1202 "D0i3 exit on resume timed out\n");
1206 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1207 enum ieee80211_reconfig_type reconfig_type)
1209 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1211 switch (reconfig_type) {
1212 case IEEE80211_RECONFIG_TYPE_RESTART:
1213 iwl_mvm_restart_complete(mvm);
1215 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1216 iwl_mvm_resume_complete(mvm);
1221 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1223 lockdep_assert_held(&mvm->mutex);
1225 /* firmware counters are obviously reset now, but we shouldn't
1226 * partially track so also clear the fw_reset_accu counters.
1228 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1230 /* async_handlers_wk is now blocked */
1233 * The work item could be running or queued if the
1234 * ROC time event stops just as we get here.
1236 flush_work(&mvm->roc_done_wk);
1238 iwl_mvm_stop_device(mvm);
1240 iwl_mvm_async_handlers_purge(mvm);
1241 /* async_handlers_list is empty and will stay empty: HW is stopped */
1243 /* the fw is stopped, the aux sta is dead: clean up driver state */
1244 iwl_mvm_del_aux_sta(mvm);
1247 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1248 * hw (as restart_complete() won't be called in this case) and mac80211
1249 * won't execute the restart.
1250 * But make sure to cleanup interfaces that have gone down before/during
1251 * HW restart was requested.
1253 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1254 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1256 ieee80211_iterate_interfaces(mvm->hw, 0,
1257 iwl_mvm_cleanup_iterator, mvm);
1259 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1260 * make sure there's nothing left there and warn if any is found.
1262 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1265 for (i = 0; i < mvm->max_scans; i++) {
1266 if (WARN_ONCE(mvm->scan_uid_status[i],
1267 "UMAC scan UID %d status was not cleaned\n",
1269 mvm->scan_uid_status[i] = 0;
1274 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1276 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1278 flush_work(&mvm->d0i3_exit_work);
1279 flush_work(&mvm->async_handlers_wk);
1280 flush_work(&mvm->add_stream_wk);
1283 * Lock and clear the firmware running bit here already, so that
1284 * new commands coming in elsewhere, e.g. from debugfs, will not
1285 * be able to proceed. This is important here because one of those
1286 * debugfs files causes the firmware dump to be triggered, and if we
1287 * don't stop debugfs accesses before canceling that it could be
1288 * retriggered after we flush it but before we've cleared the bit.
1290 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1292 iwl_fw_cancel_dump(&mvm->fwrt);
1293 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1294 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1295 iwl_fw_free_dump_desc(&mvm->fwrt);
1297 mutex_lock(&mvm->mutex);
1298 __iwl_mvm_mac_stop(mvm);
1299 mutex_unlock(&mvm->mutex);
1302 * The worker might have been waiting for the mutex, let it run and
1303 * discover that its list is now empty.
1305 cancel_work_sync(&mvm->async_handlers_wk);
1308 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1312 lockdep_assert_held(&mvm->mutex);
1314 for (i = 0; i < NUM_PHY_CTX; i++)
1315 if (!mvm->phy_ctxts[i].ref)
1316 return &mvm->phy_ctxts[i];
1318 IWL_ERR(mvm, "No available PHY context\n");
1322 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1327 struct iwl_dev_tx_power_cmd v5;
1328 struct iwl_dev_tx_power_cmd_v4 v4;
1330 .v5.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1331 .v5.v3.mac_context_id =
1332 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1333 .v5.v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1336 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1337 cmd.v5.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1339 if (fw_has_api(&mvm->fw->ucode_capa,
1340 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1341 len = sizeof(cmd.v5);
1342 else if (fw_has_capa(&mvm->fw->ucode_capa,
1343 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1344 len = sizeof(cmd.v4);
1346 len = sizeof(cmd.v4.v3);
1348 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1351 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1352 struct ieee80211_vif *vif)
1354 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1355 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1359 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1362 * make sure D0i3 exit is completed, otherwise a target access
1363 * during tx queue configuration could be done when still in
1366 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1371 * Not much to do here. The stack will not allow interface
1372 * types or combinations that we didn't advertise, so we
1373 * don't really have to check the types.
1376 mutex_lock(&mvm->mutex);
1378 /* make sure that beacon statistics don't go backwards with FW reset */
1379 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1380 mvmvif->beacon_stats.accu_num_beacons +=
1381 mvmvif->beacon_stats.num_beacons;
1383 /* Allocate resources for the MAC context, and add it to the fw */
1384 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1388 /* Counting number of interfaces is needed for legacy PM */
1389 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1393 * The AP binding flow can be done only after the beacon
1394 * template is configured (which happens only in the mac80211
1395 * start_ap() flow), and adding the broadcast station can happen
1396 * only after the binding.
1397 * In addition, since modifying the MAC before adding a bcast
1398 * station is not allowed by the FW, delay the adding of MAC context to
1399 * the point where we can also add the bcast station.
1400 * In short: there's not much we can do at this point, other than
1401 * allocating resources :)
1403 if (vif->type == NL80211_IFTYPE_AP ||
1404 vif->type == NL80211_IFTYPE_ADHOC) {
1405 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1407 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1412 * Only queue for this station is the mcast queue,
1413 * which shouldn't be in TFD mask anyway
1415 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1421 iwl_mvm_vif_dbgfs_register(mvm, vif);
1425 mvmvif->features |= hw->netdev_features;
1427 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1431 ret = iwl_mvm_power_update_mac(mvm);
1433 goto out_remove_mac;
1435 /* beacon filtering */
1436 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1438 goto out_remove_mac;
1440 if (!mvm->bf_allowed_vif &&
1441 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1442 mvm->bf_allowed_vif = mvmvif;
1443 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1444 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1448 * P2P_DEVICE interface does not have a channel context assigned to it,
1449 * so a dedicated PHY context is allocated to it and the corresponding
1450 * MAC context is bound to it at this stage.
1452 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1454 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1455 if (!mvmvif->phy_ctxt) {
1460 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1461 ret = iwl_mvm_binding_add_vif(mvm, vif);
1465 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1469 /* Save a pointer to p2p device vif, so it can later be used to
1470 * update the p2p device MAC when a GO is started/stopped */
1471 mvm->p2p_device_vif = vif;
1474 iwl_mvm_tcm_add_vif(mvm, vif);
1476 if (vif->type == NL80211_IFTYPE_MONITOR)
1477 mvm->monitor_on = true;
1479 iwl_mvm_vif_dbgfs_register(mvm, vif);
1483 iwl_mvm_binding_remove_vif(mvm, vif);
1485 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1487 if (mvm->bf_allowed_vif == mvmvif) {
1488 mvm->bf_allowed_vif = NULL;
1489 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1490 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1493 mvmvif->phy_ctxt = NULL;
1494 iwl_mvm_mac_ctxt_remove(mvm, vif);
1496 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1499 mutex_unlock(&mvm->mutex);
1501 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1506 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1507 struct ieee80211_vif *vif)
1509 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1511 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1512 * We assume here that all the packets sent to the OFFCHANNEL
1513 * queue are sent in ROC session.
1515 flush_work(&mvm->roc_done_wk);
1519 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1520 struct ieee80211_vif *vif)
1522 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1523 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1524 struct iwl_probe_resp_data *probe_data;
1526 iwl_mvm_prepare_mac_removal(mvm, vif);
1528 if (!(vif->type == NL80211_IFTYPE_AP ||
1529 vif->type == NL80211_IFTYPE_ADHOC))
1530 iwl_mvm_tcm_rm_vif(mvm, vif);
1532 mutex_lock(&mvm->mutex);
1534 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1535 lockdep_is_held(&mvm->mutex));
1536 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1538 kfree_rcu(probe_data, rcu_head);
1540 if (mvm->bf_allowed_vif == mvmvif) {
1541 mvm->bf_allowed_vif = NULL;
1542 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1543 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1546 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1549 * For AP/GO interface, the tear down of the resources allocated to the
1550 * interface is be handled as part of the stop_ap flow.
1552 if (vif->type == NL80211_IFTYPE_AP ||
1553 vif->type == NL80211_IFTYPE_ADHOC) {
1554 #ifdef CONFIG_NL80211_TESTMODE
1555 if (vif == mvm->noa_vif) {
1556 mvm->noa_vif = NULL;
1557 mvm->noa_duration = 0;
1560 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1561 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1565 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1566 mvm->p2p_device_vif = NULL;
1567 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1568 iwl_mvm_binding_remove_vif(mvm, vif);
1569 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1570 mvmvif->phy_ctxt = NULL;
1573 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1576 iwl_mvm_power_update_mac(mvm);
1577 iwl_mvm_mac_ctxt_remove(mvm, vif);
1579 if (vif->type == NL80211_IFTYPE_MONITOR)
1580 mvm->monitor_on = false;
1583 mutex_unlock(&mvm->mutex);
1586 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1591 struct iwl_mvm_mc_iter_data {
1592 struct iwl_mvm *mvm;
1596 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1597 struct ieee80211_vif *vif)
1599 struct iwl_mvm_mc_iter_data *data = _data;
1600 struct iwl_mvm *mvm = data->mvm;
1601 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1602 struct iwl_host_cmd hcmd = {
1603 .id = MCAST_FILTER_CMD,
1605 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1609 /* if we don't have free ports, mcast frames will be dropped */
1610 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1613 if (vif->type != NL80211_IFTYPE_STATION ||
1614 !vif->bss_conf.assoc)
1617 cmd->port_id = data->port_id++;
1618 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1619 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1624 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1626 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1629 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1631 struct iwl_mvm_mc_iter_data iter_data = {
1635 lockdep_assert_held(&mvm->mutex);
1637 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1640 ieee80211_iterate_active_interfaces_atomic(
1641 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1642 iwl_mvm_mc_iface_iterator, &iter_data);
1645 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1646 struct netdev_hw_addr_list *mc_list)
1648 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1649 struct iwl_mcast_filter_cmd *cmd;
1650 struct netdev_hw_addr *addr;
1655 addr_count = netdev_hw_addr_list_count(mc_list);
1656 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1657 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1661 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1662 cmd = kzalloc(len, GFP_ATOMIC);
1668 return (u64)(unsigned long)cmd;
1671 netdev_hw_addr_list_for_each(addr, mc_list) {
1672 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1673 cmd->count, addr->addr);
1674 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1675 addr->addr, ETH_ALEN);
1679 return (u64)(unsigned long)cmd;
1682 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1683 unsigned int changed_flags,
1684 unsigned int *total_flags,
1687 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1688 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1690 mutex_lock(&mvm->mutex);
1692 /* replace previous configuration */
1693 kfree(mvm->mcast_filter_cmd);
1694 mvm->mcast_filter_cmd = cmd;
1699 if (changed_flags & FIF_ALLMULTI)
1700 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1705 iwl_mvm_recalc_multicast(mvm);
1707 mutex_unlock(&mvm->mutex);
1711 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1712 struct ieee80211_vif *vif,
1713 unsigned int filter_flags,
1714 unsigned int changed_flags)
1716 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1718 /* We support only filter for probe requests */
1719 if (!(changed_flags & FIF_PROBE_REQ))
1722 /* Supported only for p2p client interfaces */
1723 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1727 mutex_lock(&mvm->mutex);
1728 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1729 mutex_unlock(&mvm->mutex);
1732 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1733 struct iwl_bcast_iter_data {
1734 struct iwl_mvm *mvm;
1735 struct iwl_bcast_filter_cmd *cmd;
1740 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1741 const struct iwl_fw_bcast_filter *in_filter,
1742 struct iwl_fw_bcast_filter *out_filter)
1744 struct iwl_fw_bcast_filter_attr *attr;
1747 memcpy(out_filter, in_filter, sizeof(*out_filter));
1749 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1750 attr = &out_filter->attrs[i];
1755 switch (attr->reserved1) {
1756 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1757 if (vif->bss_conf.arp_addr_cnt != 1) {
1762 attr->val = vif->bss_conf.arp_addr_list[0];
1764 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1765 attr->val = *(__be32 *)&vif->addr[2];
1770 attr->reserved1 = 0;
1771 out_filter->num_attrs++;
1775 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1776 struct ieee80211_vif *vif)
1778 struct iwl_bcast_iter_data *data = _data;
1779 struct iwl_mvm *mvm = data->mvm;
1780 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1781 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1782 struct iwl_fw_bcast_mac *bcast_mac;
1785 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1788 bcast_mac = &cmd->macs[mvmvif->id];
1791 * enable filtering only for associated stations, but not for P2P
1794 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1795 !vif->bss_conf.assoc)
1798 bcast_mac->default_discard = 1;
1800 /* copy all configured filters */
1801 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1803 * Make sure we don't exceed our filters limit.
1804 * if there is still a valid filter to be configured,
1805 * be on the safe side and just allow bcast for this mac.
1807 if (WARN_ON_ONCE(data->current_filter >=
1808 ARRAY_SIZE(cmd->filters))) {
1809 bcast_mac->default_discard = 0;
1810 bcast_mac->attached_filters = 0;
1814 iwl_mvm_set_bcast_filter(vif,
1815 &mvm->bcast_filters[i],
1816 &cmd->filters[data->current_filter]);
1818 /* skip current filter if it contains no attributes */
1819 if (!cmd->filters[data->current_filter].num_attrs)
1822 /* attach the filter to current mac */
1823 bcast_mac->attached_filters |=
1824 cpu_to_le16(BIT(data->current_filter));
1826 data->current_filter++;
1830 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1831 struct iwl_bcast_filter_cmd *cmd)
1833 struct iwl_bcast_iter_data iter_data = {
1838 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1841 memset(cmd, 0, sizeof(*cmd));
1842 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1843 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1845 #ifdef CONFIG_IWLWIFI_DEBUGFS
1846 /* use debugfs filters/macs if override is configured */
1847 if (mvm->dbgfs_bcast_filtering.override) {
1848 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1849 sizeof(cmd->filters));
1850 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1856 /* if no filters are configured, do nothing */
1857 if (!mvm->bcast_filters)
1860 /* configure and attach these filters for each associated sta vif */
1861 ieee80211_iterate_active_interfaces(
1862 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1863 iwl_mvm_bcast_filter_iterator, &iter_data);
1868 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1870 struct iwl_bcast_filter_cmd cmd;
1872 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1875 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1878 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1882 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1888 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1889 struct ieee80211_vif *vif)
1891 struct iwl_mu_group_mgmt_cmd cmd = {};
1893 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1894 WLAN_MEMBERSHIP_LEN);
1895 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1896 WLAN_USER_POSITION_LEN);
1898 return iwl_mvm_send_cmd_pdu(mvm,
1899 WIDE_ID(DATA_PATH_GROUP,
1900 UPDATE_MU_GROUPS_CMD),
1901 0, sizeof(cmd), &cmd);
1904 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1905 struct ieee80211_vif *vif)
1907 if (vif->mu_mimo_owner) {
1908 struct iwl_mu_group_mgmt_notif *notif = _data;
1911 * MU-MIMO Group Id action frame is little endian. We treat
1912 * the data received from firmware as if it came from the
1913 * action frame, so no conversion is needed.
1915 ieee80211_update_mu_groups(vif,
1916 (u8 *)¬if->membership_status,
1917 (u8 *)¬if->user_position);
1921 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1922 struct iwl_rx_cmd_buffer *rxb)
1924 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1925 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1927 ieee80211_iterate_active_interfaces_atomic(
1928 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1929 iwl_mvm_mu_mimo_iface_iterator, notif);
1932 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1934 u8 byte_num = ppe_pos_bit / 8;
1935 u8 bit_num = ppe_pos_bit % 8;
1940 return (ppe[byte_num] >> bit_num) &
1941 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1944 * If bit_num > 5, we have to combine bits with next byte.
1945 * Calculate how many bits we need to take from current byte (called
1946 * here "residue_bits"), and add them to bits from next byte.
1949 residue_bits = 8 - bit_num;
1951 res = (ppe[byte_num + 1] &
1952 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1954 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1959 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1960 struct ieee80211_vif *vif, u8 sta_id)
1962 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1963 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
1965 .tid_limit = IWL_MAX_TID_COUNT,
1966 .bss_color = vif->bss_conf.bss_color,
1967 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
1968 .frame_time_rts_th =
1969 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
1971 struct ieee80211_sta *sta;
1977 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
1980 WARN(1, "Can't find STA to configure HE\n");
1984 if (!sta->he_cap.has_he) {
1992 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
1993 IEEE80211_HE_MAC_CAP0_HTC_HE)
1994 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
1995 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
1996 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
1997 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
1998 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2000 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
2001 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2002 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
2003 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2006 sta_ctxt_cmd.htc_flags |=
2007 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2008 else if (link_adap == 3)
2009 sta_ctxt_cmd.htc_flags |=
2010 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2012 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2013 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2014 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2015 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2016 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2017 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2018 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2020 /* If PPE Thresholds exist, parse them into a FW-familiar format */
2021 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2022 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2023 u8 nss = (sta->he_cap.ppe_thres[0] &
2024 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2025 u8 ru_index_bitmap =
2026 (sta->he_cap.ppe_thres[0] &
2027 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2028 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2029 u8 *ppe = &sta->he_cap.ppe_thres[0];
2030 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2033 * FW currently supports only nss == MAX_HE_SUPP_NSS
2035 * If nss > MAX: we can ignore values we don't support
2036 * If nss < MAX: we can set zeros in other streams
2038 if (nss > MAX_HE_SUPP_NSS) {
2039 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2041 nss = MAX_HE_SUPP_NSS;
2044 for (i = 0; i < nss; i++) {
2045 u8 ru_index_tmp = ru_index_bitmap << 1;
2048 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2050 if (!(ru_index_tmp & 1))
2053 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2054 iwl_mvm_he_get_ppe_val(ppe,
2057 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2058 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2059 iwl_mvm_he_get_ppe_val(ppe,
2062 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2066 flags |= STA_CTXT_HE_PACKET_EXT;
2070 /* Mark MU EDCA as enabled, unless none detected on some AC */
2071 flags |= STA_CTXT_HE_MU_EDCA_CW;
2072 for (i = 0; i < AC_NUM; i++) {
2073 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2074 &mvmvif->queue_params[i].mu_edca_param_rec;
2076 if (!mvmvif->queue_params[i].mu_edca) {
2077 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2081 sta_ctxt_cmd.trig_based_txf[i].cwmin =
2082 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2083 sta_ctxt_cmd.trig_based_txf[i].cwmax =
2084 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2085 sta_ctxt_cmd.trig_based_txf[i].aifsn =
2086 cpu_to_le16(mu_edca->aifsn);
2087 sta_ctxt_cmd.trig_based_txf[i].mu_time =
2088 cpu_to_le16(mu_edca->mu_edca_timer);
2091 if (vif->bss_conf.multi_sta_back_32bit)
2092 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2094 if (vif->bss_conf.ack_enabled)
2095 flags |= STA_CTXT_HE_ACK_ENABLED;
2097 if (vif->bss_conf.uora_exists) {
2098 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2100 sta_ctxt_cmd.rand_alloc_ecwmin =
2101 vif->bss_conf.uora_ocw_range & 0x7;
2102 sta_ctxt_cmd.rand_alloc_ecwmax =
2103 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2106 /* TODO: support Multi BSSID IE */
2108 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2110 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2111 DATA_PATH_GROUP, 0),
2112 0, sizeof(sta_ctxt_cmd), &sta_ctxt_cmd))
2113 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2116 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2117 struct ieee80211_vif *vif,
2118 struct ieee80211_bss_conf *bss_conf,
2121 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2125 * Re-calculate the tsf id, as the master-slave relations depend on the
2126 * beacon interval, which was not known when the station interface was
2129 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2130 if (vif->bss_conf.he_support &&
2131 !iwlwifi_mod_params.disable_11ax)
2132 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2134 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2138 * If we're not associated yet, take the (new) BSSID before associating
2139 * so the firmware knows. If we're already associated, then use the old
2140 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2141 * branch for disassociation below.
2143 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2144 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2146 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2148 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2150 /* after sending it once, adopt mac80211 data */
2151 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2152 mvmvif->associated = bss_conf->assoc;
2154 if (changes & BSS_CHANGED_ASSOC) {
2155 if (bss_conf->assoc) {
2156 /* clear statistics to get clean beacon counter */
2157 iwl_mvm_request_statistics(mvm, true);
2158 memset(&mvmvif->beacon_stats, 0,
2159 sizeof(mvmvif->beacon_stats));
2161 /* add quota for this interface */
2162 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2164 IWL_ERR(mvm, "failed to update quotas\n");
2168 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2171 * If we're restarting then the firmware will
2172 * obviously have lost synchronisation with
2173 * the AP. It will attempt to synchronise by
2174 * itself, but we can make it more reliable by
2175 * scheduling a session protection time event.
2177 * The firmware needs to receive a beacon to
2178 * catch up with synchronisation, use 110% of
2179 * the beacon interval.
2181 * Set a large maximum delay to allow for more
2182 * than a single interface.
2184 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2185 iwl_mvm_protect_session(mvm, vif, dur, dur,
2189 iwl_mvm_sf_update(mvm, vif, false);
2190 iwl_mvm_power_vif_assoc(mvm, vif);
2192 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
2193 iwl_mvm_update_smps(mvm, vif,
2194 IWL_MVM_SMPS_REQ_PROT,
2195 IEEE80211_SMPS_DYNAMIC);
2197 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2199 * If update fails - SF might be running in associated
2200 * mode while disassociated - which is forbidden.
2202 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
2203 "Failed to update SF upon disassociation\n");
2206 * If we get an assert during the connection (after the
2207 * station has been added, but before the vif is set
2208 * to associated), mac80211 will re-add the station and
2209 * then configure the vif. Since the vif is not
2210 * associated, we would remove the station here and
2211 * this would fail the recovery.
2213 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2216 * Remove AP station now that
2217 * the MAC is unassoc
2219 ret = iwl_mvm_rm_sta_id(mvm, vif,
2223 "failed to remove AP station\n");
2225 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2226 mvm->d0i3_ap_sta_id =
2227 IWL_MVM_INVALID_STA;
2228 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2231 /* remove quota for this interface */
2232 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2234 IWL_ERR(mvm, "failed to update quotas\n");
2237 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2239 /* this will take the cleared BSSID from bss_conf */
2240 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2243 "failed to update MAC %pM (clear after unassoc)\n",
2248 * The firmware tracks the MU-MIMO group on its own.
2249 * However, on HW restart we should restore this data.
2251 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2252 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2253 ret = iwl_mvm_update_mu_groups(mvm, vif);
2256 "failed to update VHT MU_MIMO groups\n");
2259 iwl_mvm_recalc_multicast(mvm);
2260 iwl_mvm_configure_bcast_filter(mvm);
2262 /* reset rssi values */
2263 mvmvif->bf_data.ave_beacon_signal = 0;
2265 iwl_mvm_bt_coex_vif_change(mvm);
2266 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2267 IEEE80211_SMPS_AUTOMATIC);
2268 if (fw_has_capa(&mvm->fw->ucode_capa,
2269 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2270 iwl_mvm_config_scan(mvm);
2273 if (changes & BSS_CHANGED_BEACON_INFO) {
2275 * We received a beacon from the associated AP so
2276 * remove the session protection.
2278 iwl_mvm_stop_session_protection(mvm, vif);
2280 iwl_mvm_sf_update(mvm, vif, false);
2281 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2284 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2286 * Send power command on every beacon change,
2287 * because we may have not enabled beacon abort yet.
2289 BSS_CHANGED_BEACON_INFO)) {
2290 ret = iwl_mvm_power_update_mac(mvm);
2292 IWL_ERR(mvm, "failed to update power mode\n");
2295 if (changes & BSS_CHANGED_TXPOWER) {
2296 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2298 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2301 if (changes & BSS_CHANGED_CQM) {
2302 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2303 /* reset cqm events tracking */
2304 mvmvif->bf_data.last_cqm_event = 0;
2305 if (mvmvif->bf_data.bf_enabled) {
2306 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2309 "failed to update CQM thresholds\n");
2313 if (changes & BSS_CHANGED_ARP_FILTER) {
2314 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2315 iwl_mvm_configure_bcast_filter(mvm);
2319 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2320 struct ieee80211_vif *vif)
2322 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2323 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2327 * iwl_mvm_mac_ctxt_add() might read directly from the device
2328 * (the system time), so make sure it is available.
2330 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2334 mutex_lock(&mvm->mutex);
2336 /* Send the beacon template */
2337 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2342 * Re-calculate the tsf id, as the master-slave relations depend on the
2343 * beacon interval, which was not known when the AP interface was added.
2345 if (vif->type == NL80211_IFTYPE_AP)
2346 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2348 mvmvif->ap_assoc_sta_count = 0;
2350 /* Add the mac context */
2351 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2355 /* Perform the binding */
2356 ret = iwl_mvm_binding_add_vif(mvm, vif);
2361 * This is not very nice, but the simplest:
2362 * For older FWs adding the mcast sta before the bcast station may
2363 * cause assert 0x2b00.
2364 * This is fixed in later FW so make the order of removal depend on
2367 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2368 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2372 * Send the bcast station. At this stage the TBTT and DTIM time
2373 * events are added and applied to the scheduler
2375 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2377 iwl_mvm_rm_mcast_sta(mvm, vif);
2382 * Send the bcast station. At this stage the TBTT and DTIM time
2383 * events are added and applied to the scheduler
2385 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2388 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2390 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2395 /* must be set before quota calculations */
2396 mvmvif->ap_ibss_active = true;
2398 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2399 iwl_mvm_vif_set_low_latency(mvmvif, true,
2400 LOW_LATENCY_VIF_TYPE);
2401 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2404 /* power updated needs to be done before quotas */
2405 iwl_mvm_power_update_mac(mvm);
2407 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2409 goto out_quota_failed;
2411 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2412 if (vif->p2p && mvm->p2p_device_vif)
2413 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2415 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2417 iwl_mvm_bt_coex_vif_change(mvm);
2419 /* we don't support TDLS during DCM */
2420 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2421 iwl_mvm_teardown_tdls_peers(mvm);
2426 iwl_mvm_power_update_mac(mvm);
2427 mvmvif->ap_ibss_active = false;
2428 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2429 iwl_mvm_rm_mcast_sta(mvm, vif);
2431 iwl_mvm_binding_remove_vif(mvm, vif);
2433 iwl_mvm_mac_ctxt_remove(mvm, vif);
2435 mutex_unlock(&mvm->mutex);
2436 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2440 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2441 struct ieee80211_vif *vif)
2443 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2444 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2446 iwl_mvm_prepare_mac_removal(mvm, vif);
2448 mutex_lock(&mvm->mutex);
2450 /* Handle AP stop while in CSA */
2451 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2452 iwl_mvm_remove_time_event(mvm, mvmvif,
2453 &mvmvif->time_event_data);
2454 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2455 mvmvif->csa_countdown = false;
2458 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2459 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2460 mvm->csa_tx_block_bcn_timeout = 0;
2463 mvmvif->ap_ibss_active = false;
2464 mvm->ap_last_beacon_gp2 = 0;
2466 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2467 iwl_mvm_vif_set_low_latency(mvmvif, false,
2468 LOW_LATENCY_VIF_TYPE);
2469 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2472 iwl_mvm_bt_coex_vif_change(mvm);
2474 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2476 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2477 if (vif->p2p && mvm->p2p_device_vif)
2478 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2480 iwl_mvm_update_quotas(mvm, false, NULL);
2483 * This is not very nice, but the simplest:
2484 * For older FWs removing the mcast sta before the bcast station may
2485 * cause assert 0x2b00.
2486 * This is fixed in later FW (which will stop beaconing when removing
2488 * So make the order of removal depend on the TLV
2490 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2491 iwl_mvm_rm_mcast_sta(mvm, vif);
2492 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2493 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2494 iwl_mvm_rm_mcast_sta(mvm, vif);
2495 iwl_mvm_binding_remove_vif(mvm, vif);
2497 iwl_mvm_power_update_mac(mvm);
2499 iwl_mvm_mac_ctxt_remove(mvm, vif);
2501 kfree(mvmvif->ap_wep_key);
2502 mvmvif->ap_wep_key = NULL;
2504 mutex_unlock(&mvm->mutex);
2508 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2509 struct ieee80211_vif *vif,
2510 struct ieee80211_bss_conf *bss_conf,
2513 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2515 /* Changes will be applied when the AP/IBSS is started */
2516 if (!mvmvif->ap_ibss_active)
2519 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2520 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2521 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2522 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2524 /* Need to send a new beacon template to the FW */
2525 if (changes & BSS_CHANGED_BEACON &&
2526 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2527 IWL_WARN(mvm, "Failed updating beacon data\n");
2529 if (changes & BSS_CHANGED_TXPOWER) {
2530 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2532 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2536 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2537 struct ieee80211_vif *vif,
2538 struct ieee80211_bss_conf *bss_conf,
2541 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2544 * iwl_mvm_bss_info_changed_station() might call
2545 * iwl_mvm_protect_session(), which reads directly from
2546 * the device (the system time), so make sure it is available.
2548 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2551 mutex_lock(&mvm->mutex);
2553 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2554 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2556 switch (vif->type) {
2557 case NL80211_IFTYPE_STATION:
2558 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2560 case NL80211_IFTYPE_AP:
2561 case NL80211_IFTYPE_ADHOC:
2562 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2564 case NL80211_IFTYPE_MONITOR:
2565 if (changes & BSS_CHANGED_MU_GROUPS)
2566 iwl_mvm_update_mu_groups(mvm, vif);
2569 /* shouldn't happen */
2573 mutex_unlock(&mvm->mutex);
2574 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2577 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2578 struct ieee80211_vif *vif,
2579 struct ieee80211_scan_request *hw_req)
2581 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2584 if (hw_req->req.n_channels == 0 ||
2585 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2588 mutex_lock(&mvm->mutex);
2589 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2590 mutex_unlock(&mvm->mutex);
2595 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2596 struct ieee80211_vif *vif)
2598 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2600 mutex_lock(&mvm->mutex);
2602 /* Due to a race condition, it's possible that mac80211 asks
2603 * us to stop a hw_scan when it's already stopped. This can
2604 * happen, for instance, if we stopped the scan ourselves,
2605 * called ieee80211_scan_completed() and the userspace called
2606 * cancel scan scan before ieee80211_scan_work() could run.
2607 * To handle that, simply return if the scan is not running.
2609 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2610 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2612 mutex_unlock(&mvm->mutex);
2616 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2617 struct ieee80211_sta *sta, u16 tids,
2619 enum ieee80211_frame_release_type reason,
2622 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2624 /* Called when we need to transmit (a) frame(s) from mac80211 */
2626 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2627 tids, more_data, false);
2631 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2632 struct ieee80211_sta *sta, u16 tids,
2634 enum ieee80211_frame_release_type reason,
2637 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2639 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2641 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2642 tids, more_data, true);
2645 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2646 enum sta_notify_cmd cmd,
2647 struct ieee80211_sta *sta)
2649 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2650 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2651 unsigned long txqs = 0, tids = 0;
2655 * If we have TVQM then we get too high queue numbers - luckily
2656 * we really shouldn't get here with that because such hardware
2657 * should have firmware supporting buffer station offload.
2659 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2662 spin_lock_bh(&mvmsta->lock);
2663 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2664 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2666 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2669 __set_bit(tid_data->txq_id, &txqs);
2671 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2674 __set_bit(tid, &tids);
2678 case STA_NOTIFY_SLEEP:
2679 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2680 ieee80211_sta_set_buffered(sta, tid, true);
2683 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2685 * The fw updates the STA to be asleep. Tx packets on the Tx
2686 * queues to this station will not be transmitted. The fw will
2687 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2690 case STA_NOTIFY_AWAKE:
2691 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2695 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2696 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2701 spin_unlock_bh(&mvmsta->lock);
2704 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2705 struct ieee80211_vif *vif,
2706 enum sta_notify_cmd cmd,
2707 struct ieee80211_sta *sta)
2709 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2712 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2714 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2715 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2716 struct ieee80211_sta *sta;
2717 struct iwl_mvm_sta *mvmsta;
2718 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2720 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2724 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2725 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2730 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2733 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2738 if (mvmsta->sleeping != sleeping) {
2739 mvmsta->sleeping = sleeping;
2740 __iwl_mvm_mac_sta_notify(mvm->hw,
2741 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2743 ieee80211_sta_ps_transition(sta, sleeping);
2747 switch (notif->type) {
2748 case IWL_MVM_PM_EVENT_AWAKE:
2749 case IWL_MVM_PM_EVENT_ASLEEP:
2751 case IWL_MVM_PM_EVENT_UAPSD:
2752 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2754 case IWL_MVM_PM_EVENT_PS_POLL:
2755 ieee80211_sta_pspoll(sta);
2765 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2766 struct ieee80211_vif *vif,
2767 struct ieee80211_sta *sta)
2769 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2770 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2773 * This is called before mac80211 does RCU synchronisation,
2774 * so here we already invalidate our internal RCU-protected
2775 * station pointer. The rest of the code will thus no longer
2776 * be able to find the station this way, and we don't rely
2777 * on further RCU synchronisation after the sta_state()
2778 * callback deleted the station.
2780 mutex_lock(&mvm->mutex);
2781 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2782 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2785 mutex_unlock(&mvm->mutex);
2788 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2793 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2794 struct iwl_mvm_tcm_mac *mdata;
2796 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2797 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2798 mdata->opened_rx_ba_sessions = false;
2801 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2804 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2805 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2810 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2811 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2815 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2816 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2817 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2822 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2826 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2827 struct ieee80211_vif *vif, u8 *peer_addr,
2828 enum nl80211_tdls_operation action)
2830 struct iwl_fw_dbg_trigger_tlv *trig;
2831 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2833 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
2834 FW_DBG_TRIGGER_TDLS);
2838 tdls_trig = (void *)trig->data;
2840 if (!(tdls_trig->action_bitmap & BIT(action)))
2843 if (tdls_trig->peer_mode &&
2844 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2847 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2848 "TDLS event occurred, peer %pM, action %d",
2852 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2853 struct iwl_mvm_sta *mvm_sta)
2855 struct iwl_mvm_tid_data *tid_data;
2856 struct sk_buff *skb;
2859 spin_lock_bh(&mvm_sta->lock);
2860 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2861 tid_data = &mvm_sta->tid_data[i];
2863 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2864 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2867 * The first deferred frame should've stopped the MAC
2868 * queues, so we should never get a second deferred
2869 * frame for the RA/TID.
2871 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
2872 ieee80211_free_txskb(mvm->hw, skb);
2875 spin_unlock_bh(&mvm_sta->lock);
2878 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2879 struct ieee80211_vif *vif,
2880 struct ieee80211_sta *sta,
2881 enum ieee80211_sta_state old_state,
2882 enum ieee80211_sta_state new_state)
2884 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2885 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2886 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2889 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2890 sta->addr, old_state, new_state);
2892 /* this would be a mac80211 bug ... but don't crash */
2893 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2897 * If we are in a STA removal flow and in DQA mode:
2899 * This is after the sync_rcu part, so the queues have already been
2900 * flushed. No more TXs on their way in mac80211's path, and no more in
2902 * Also, we won't be getting any new TX frames for this station.
2903 * What we might have are deferred TX frames that need to be taken care
2906 * Drop any still-queued deferred-frame before removing the STA, and
2907 * make sure the worker is no longer handling frames for this STA.
2909 if (old_state == IEEE80211_STA_NONE &&
2910 new_state == IEEE80211_STA_NOTEXIST) {
2911 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2912 flush_work(&mvm->add_stream_wk);
2915 * No need to make sure deferred TX indication is off since the
2916 * worker will already remove it if it was on
2920 mutex_lock(&mvm->mutex);
2921 /* track whether or not the station is associated */
2922 mvm_sta->sta_state = new_state;
2924 if (old_state == IEEE80211_STA_NOTEXIST &&
2925 new_state == IEEE80211_STA_NONE) {
2927 * Firmware bug - it'll crash if the beacon interval is less
2928 * than 16. We can't avoid connecting at all, so refuse the
2929 * station state change, this will cause mac80211 to abandon
2930 * attempts to connect to this AP, and eventually wpa_s will
2931 * blacklist the AP...
2933 if (vif->type == NL80211_IFTYPE_STATION &&
2934 vif->bss_conf.beacon_int < 16) {
2936 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2937 sta->addr, vif->bss_conf.beacon_int);
2944 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2945 IWL_MVM_TDLS_STA_COUNT ||
2946 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2947 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2952 ret = iwl_mvm_add_sta(mvm, vif, sta);
2953 if (sta->tdls && ret == 0) {
2954 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2955 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2956 NL80211_TDLS_SETUP);
2958 } else if (old_state == IEEE80211_STA_NONE &&
2959 new_state == IEEE80211_STA_AUTH) {
2961 * EBS may be disabled due to previous failures reported by FW.
2962 * Reset EBS status here assuming environment has been changed.
2964 mvm->last_ebs_successful = true;
2965 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2967 } else if (old_state == IEEE80211_STA_AUTH &&
2968 new_state == IEEE80211_STA_ASSOC) {
2969 if (vif->type == NL80211_IFTYPE_AP) {
2970 mvmvif->ap_assoc_sta_count++;
2971 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2972 if (vif->bss_conf.he_support &&
2973 !iwlwifi_mod_params.disable_11ax)
2974 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id);
2977 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2979 ret = iwl_mvm_update_sta(mvm, vif, sta);
2980 } else if (old_state == IEEE80211_STA_ASSOC &&
2981 new_state == IEEE80211_STA_AUTHORIZED) {
2983 /* we don't support TDLS during DCM */
2984 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2985 iwl_mvm_teardown_tdls_peers(mvm);
2988 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2989 NL80211_TDLS_ENABLE_LINK);
2991 /* enable beacon filtering */
2992 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2994 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2997 /* if wep is used, need to set the key for the station now */
2998 if (vif->type == NL80211_IFTYPE_AP && mvmvif->ap_wep_key)
2999 ret = iwl_mvm_set_sta_key(mvm, vif, sta,
3001 STA_KEY_IDX_INVALID);
3004 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3005 new_state == IEEE80211_STA_ASSOC) {
3006 /* disable beacon filtering */
3007 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
3009 } else if (old_state == IEEE80211_STA_ASSOC &&
3010 new_state == IEEE80211_STA_AUTH) {
3011 if (vif->type == NL80211_IFTYPE_AP) {
3012 mvmvif->ap_assoc_sta_count--;
3013 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3016 } else if (old_state == IEEE80211_STA_AUTH &&
3017 new_state == IEEE80211_STA_NONE) {
3019 } else if (old_state == IEEE80211_STA_NONE &&
3020 new_state == IEEE80211_STA_NOTEXIST) {
3021 ret = iwl_mvm_rm_sta(mvm, vif, sta);
3023 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3024 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3025 NL80211_TDLS_DISABLE_LINK);
3031 mutex_unlock(&mvm->mutex);
3033 if (sta->tdls && ret == 0) {
3034 if (old_state == IEEE80211_STA_NOTEXIST &&
3035 new_state == IEEE80211_STA_NONE)
3036 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3037 else if (old_state == IEEE80211_STA_NONE &&
3038 new_state == IEEE80211_STA_NOTEXIST)
3039 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3045 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3047 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3049 mvm->rts_threshold = value;
3054 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3055 struct ieee80211_vif *vif,
3056 struct ieee80211_sta *sta, u32 changed)
3058 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3060 if (vif->type == NL80211_IFTYPE_STATION &&
3061 changed & IEEE80211_RC_NSS_CHANGED)
3062 iwl_mvm_sf_update(mvm, vif, false);
3065 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3066 struct ieee80211_vif *vif, u16 ac,
3067 const struct ieee80211_tx_queue_params *params)
3069 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3070 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3072 mvmvif->queue_params[ac] = *params;
3075 * No need to update right away, we'll get BSS_CHANGED_QOS
3076 * The exception is P2P_DEVICE interface which needs immediate update.
3078 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3081 mutex_lock(&mvm->mutex);
3082 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3083 mutex_unlock(&mvm->mutex);
3089 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3090 struct ieee80211_vif *vif,
3093 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3094 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3095 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3098 * iwl_mvm_protect_session() reads directly from the device
3099 * (the system time), so make sure it is available.
3101 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
3104 if (req_duration > duration)
3105 duration = req_duration;
3107 mutex_lock(&mvm->mutex);
3108 /* Try really hard to protect the session and hear a beacon */
3109 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
3110 mutex_unlock(&mvm->mutex);
3112 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
3115 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3116 struct ieee80211_vif *vif,
3117 struct cfg80211_sched_scan_request *req,
3118 struct ieee80211_scan_ies *ies)
3120 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3124 mutex_lock(&mvm->mutex);
3126 if (!vif->bss_conf.idle) {
3131 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3134 mutex_unlock(&mvm->mutex);
3138 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3139 struct ieee80211_vif *vif)
3141 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3144 mutex_lock(&mvm->mutex);
3146 /* Due to a race condition, it's possible that mac80211 asks
3147 * us to stop a sched_scan when it's already stopped. This
3148 * can happen, for instance, if we stopped the scan ourselves,
3149 * called ieee80211_sched_scan_stopped() and the userspace called
3150 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3151 * could run. To handle this, simply return if the scan is
3154 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3155 mutex_unlock(&mvm->mutex);
3159 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3160 mutex_unlock(&mvm->mutex);
3161 iwl_mvm_wait_for_async_handlers(mvm);
3166 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3167 enum set_key_cmd cmd,
3168 struct ieee80211_vif *vif,
3169 struct ieee80211_sta *sta,
3170 struct ieee80211_key_conf *key)
3172 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3173 struct iwl_mvm_sta *mvmsta;
3174 struct iwl_mvm_key_pn *ptk_pn;
3175 int keyidx = key->keyidx;
3179 if (iwlwifi_mod_params.swcrypto) {
3180 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
3184 switch (key->cipher) {
3185 case WLAN_CIPHER_SUITE_TKIP:
3186 if (!mvm->trans->cfg->gen2) {
3187 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3188 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3189 } else if (vif->type == NL80211_IFTYPE_STATION) {
3190 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3192 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3196 case WLAN_CIPHER_SUITE_CCMP:
3197 case WLAN_CIPHER_SUITE_GCMP:
3198 case WLAN_CIPHER_SUITE_GCMP_256:
3199 if (!iwl_mvm_has_new_tx_api(mvm))
3200 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3202 case WLAN_CIPHER_SUITE_AES_CMAC:
3203 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3204 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3205 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3207 case WLAN_CIPHER_SUITE_WEP40:
3208 case WLAN_CIPHER_SUITE_WEP104:
3209 if (vif->type == NL80211_IFTYPE_AP) {
3210 struct iwl_mvm_vif *mvmvif =
3211 iwl_mvm_vif_from_mac80211(vif);
3213 mvmvif->ap_wep_key = kmemdup(key,
3214 sizeof(*key) + key->keylen,
3216 if (!mvmvif->ap_wep_key)
3220 if (vif->type != NL80211_IFTYPE_STATION)
3224 /* currently FW supports only one optional cipher scheme */
3225 if (hw->n_cipher_schemes &&
3226 hw->cipher_schemes->cipher == key->cipher)
3227 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3232 mutex_lock(&mvm->mutex);
3236 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3237 vif->type == NL80211_IFTYPE_AP) && !sta) {
3239 * GTK on AP interface is a TX-only key, return 0;
3240 * on IBSS they're per-station and because we're lazy
3241 * we don't support them for RX, so do the same.
3242 * CMAC/GMAC in AP/IBSS modes must be done in software.
3244 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3245 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3246 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3251 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3252 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3253 !iwl_mvm_has_new_tx_api(mvm)) {
3254 key->hw_key_idx = STA_KEY_IDX_INVALID;
3259 /* During FW restart, in order to restore the state as it was,
3260 * don't try to reprogram keys we previously failed for.
3262 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3263 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3264 IWL_DEBUG_MAC80211(mvm,
3265 "skip invalid idx key programming during restart\n");
3270 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3271 sta && iwl_mvm_has_new_rx_api(mvm) &&
3272 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3273 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3274 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3275 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3276 struct ieee80211_key_seq seq;
3279 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3280 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3281 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3282 mvm->trans->num_rx_queues),
3289 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3290 ieee80211_get_key_rx_seq(key, tid, &seq);
3291 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3292 memcpy(ptk_pn->q[q].pn[tid],
3294 IEEE80211_CCMP_PN_LEN);
3297 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3300 /* in HW restart reuse the index, otherwise request a new one */
3301 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3302 key_offset = key->hw_key_idx;
3304 key_offset = STA_KEY_IDX_INVALID;
3306 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3307 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3309 IWL_WARN(mvm, "set key failed\n");
3311 * can't add key for RX, but we don't need it
3312 * in the device for TX so still return 0
3314 key->hw_key_idx = STA_KEY_IDX_INVALID;
3320 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3325 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3326 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3327 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3328 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3329 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3330 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3331 ptk_pn = rcu_dereference_protected(
3332 mvmsta->ptk_pn[keyidx],
3333 lockdep_is_held(&mvm->mutex));
3334 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3336 kfree_rcu(ptk_pn, rcu_head);
3339 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3340 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3346 mutex_unlock(&mvm->mutex);
3350 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3351 struct ieee80211_vif *vif,
3352 struct ieee80211_key_conf *keyconf,
3353 struct ieee80211_sta *sta,
3354 u32 iv32, u16 *phase1key)
3356 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3358 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3361 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3365 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3366 struct iwl_rx_packet *pkt, void *data)
3368 struct iwl_mvm *mvm =
3369 container_of(notif_wait, struct iwl_mvm, notif_wait);
3370 struct iwl_hs20_roc_res *resp;
3371 int resp_len = iwl_rx_packet_payload_len(pkt);
3372 struct iwl_mvm_time_event_data *te_data = data;
3374 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3377 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3378 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3382 resp = (void *)pkt->data;
3385 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3386 resp->status, resp->event_unique_id);
3388 te_data->uid = le32_to_cpu(resp->event_unique_id);
3389 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3392 spin_lock_bh(&mvm->time_event_lock);
3393 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3394 spin_unlock_bh(&mvm->time_event_lock);
3399 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3400 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3401 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3402 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3403 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3404 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3405 struct ieee80211_channel *channel,
3406 struct ieee80211_vif *vif,
3409 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3410 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3411 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3412 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3413 struct iwl_notification_wait wait_time_event;
3414 u32 dtim_interval = vif->bss_conf.dtim_period *
3415 vif->bss_conf.beacon_int;
3417 struct iwl_hs20_roc_req aux_roc_req = {
3418 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3420 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3421 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3422 /* Set the channel info data */
3423 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3424 PHY_BAND_24 : PHY_BAND_5,
3425 .channel_info.channel = channel->hw_value,
3426 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3427 /* Set the time and duration */
3428 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3431 delay = AUX_ROC_MIN_DELAY;
3432 req_dur = MSEC_TO_TU(duration);
3435 * If we are associated we want the delay time to be at least one
3436 * dtim interval so that the FW can wait until after the DTIM and
3437 * then start the time event, this will potentially allow us to
3438 * remain off-channel for the max duration.
3439 * Since we want to use almost a whole dtim interval we would also
3440 * like the delay to be for 2-3 dtim intervals, in case there are
3441 * other time events with higher priority.
3443 if (vif->bss_conf.assoc) {
3444 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3445 /* We cannot remain off-channel longer than the DTIM interval */
3446 if (dtim_interval <= req_dur) {
3447 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3448 if (req_dur <= AUX_ROC_MIN_DURATION)
3449 req_dur = dtim_interval -
3450 AUX_ROC_MIN_SAFETY_BUFFER;
3454 aux_roc_req.duration = cpu_to_le32(req_dur);
3455 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3458 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3459 channel->hw_value, req_dur, duration, delay,
3461 /* Set the node address */
3462 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3464 lockdep_assert_held(&mvm->mutex);
3466 spin_lock_bh(&mvm->time_event_lock);
3468 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3469 spin_unlock_bh(&mvm->time_event_lock);
3474 te_data->duration = duration;
3475 te_data->id = HOT_SPOT_CMD;
3477 spin_unlock_bh(&mvm->time_event_lock);
3480 * Use a notification wait, which really just processes the
3481 * command response and doesn't wait for anything, in order
3482 * to be able to process the response and get the UID inside
3483 * the RX path. Using CMD_WANT_SKB doesn't work because it
3484 * stores the buffer and then wakes up this thread, by which
3485 * time another notification (that the time event started)
3486 * might already be processed unsuccessfully.
3488 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3489 time_event_response,
3490 ARRAY_SIZE(time_event_response),
3491 iwl_mvm_rx_aux_roc, te_data);
3493 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3497 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3498 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3502 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3503 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3504 /* should never fail */
3509 spin_lock_bh(&mvm->time_event_lock);
3510 iwl_mvm_te_clear_data(mvm, te_data);
3511 spin_unlock_bh(&mvm->time_event_lock);
3517 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3518 struct ieee80211_vif *vif,
3519 struct ieee80211_channel *channel,
3521 enum ieee80211_roc_type type)
3523 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3524 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3525 struct cfg80211_chan_def chandef;
3526 struct iwl_mvm_phy_ctxt *phy_ctxt;
3529 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3533 * Flush the done work, just in case it's still pending, so that
3534 * the work it does can complete and we can accept new frames.
3536 flush_work(&mvm->roc_done_wk);
3538 mutex_lock(&mvm->mutex);
3540 switch (vif->type) {
3541 case NL80211_IFTYPE_STATION:
3542 if (fw_has_capa(&mvm->fw->ucode_capa,
3543 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3544 /* Use aux roc framework (HS20) */
3545 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3549 IWL_ERR(mvm, "hotspot not supported\n");
3552 case NL80211_IFTYPE_P2P_DEVICE:
3556 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3561 for (i = 0; i < NUM_PHY_CTX; i++) {
3562 phy_ctxt = &mvm->phy_ctxts[i];
3563 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3566 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3568 * Unbind the P2P_DEVICE from the current PHY context,
3569 * and if the PHY context is not used remove it.
3571 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3572 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3575 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3577 /* Bind the P2P_DEVICE to the current PHY Context */
3578 mvmvif->phy_ctxt = phy_ctxt;
3580 ret = iwl_mvm_binding_add_vif(mvm, vif);
3581 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3584 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3585 goto schedule_time_event;
3589 /* Need to update the PHY context only if the ROC channel changed */
3590 if (channel == mvmvif->phy_ctxt->channel)
3591 goto schedule_time_event;
3593 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3596 * Change the PHY context configuration as it is currently referenced
3597 * only by the P2P Device MAC
3599 if (mvmvif->phy_ctxt->ref == 1) {
3600 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3606 * The PHY context is shared with other MACs. Need to remove the
3607 * P2P Device from the binding, allocate an new PHY context and
3608 * create a new binding
3610 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3616 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3619 IWL_ERR(mvm, "Failed to change PHY context\n");
3623 /* Unbind the P2P_DEVICE from the current PHY context */
3624 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3625 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3628 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3630 /* Bind the P2P_DEVICE to the new allocated PHY context */
3631 mvmvif->phy_ctxt = phy_ctxt;
3633 ret = iwl_mvm_binding_add_vif(mvm, vif);
3634 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3637 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3640 schedule_time_event:
3641 /* Schedule the time events */
3642 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3645 mutex_unlock(&mvm->mutex);
3646 IWL_DEBUG_MAC80211(mvm, "leave\n");
3650 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3652 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3654 IWL_DEBUG_MAC80211(mvm, "enter\n");
3656 mutex_lock(&mvm->mutex);
3657 iwl_mvm_stop_roc(mvm);
3658 mutex_unlock(&mvm->mutex);
3660 IWL_DEBUG_MAC80211(mvm, "leave\n");
3664 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3665 struct ieee80211_chanctx_conf *ctx)
3667 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3668 struct iwl_mvm_phy_ctxt *phy_ctxt;
3671 lockdep_assert_held(&mvm->mutex);
3673 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3675 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3681 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3682 ctx->rx_chains_static,
3683 ctx->rx_chains_dynamic);
3685 IWL_ERR(mvm, "Failed to add PHY context\n");
3689 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3690 *phy_ctxt_id = phy_ctxt->id;
3695 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3696 struct ieee80211_chanctx_conf *ctx)
3698 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3701 mutex_lock(&mvm->mutex);
3702 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3703 mutex_unlock(&mvm->mutex);
3708 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3709 struct ieee80211_chanctx_conf *ctx)
3711 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3712 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3714 lockdep_assert_held(&mvm->mutex);
3716 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3719 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3720 struct ieee80211_chanctx_conf *ctx)
3722 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3724 mutex_lock(&mvm->mutex);
3725 __iwl_mvm_remove_chanctx(mvm, ctx);
3726 mutex_unlock(&mvm->mutex);
3729 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3730 struct ieee80211_chanctx_conf *ctx,
3733 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3734 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3735 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3737 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3738 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3739 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3740 IEEE80211_CHANCTX_CHANGE_RADAR |
3741 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3742 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3743 phy_ctxt->ref, changed))
3746 mutex_lock(&mvm->mutex);
3748 /* we are only changing the min_width, may be a noop */
3749 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
3750 if (phy_ctxt->width == ctx->min_def.width)
3753 /* we are just toggling between 20_NOHT and 20 */
3754 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
3755 ctx->min_def.width <= NL80211_CHAN_WIDTH_20)
3759 iwl_mvm_bt_coex_vif_change(mvm);
3760 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3761 ctx->rx_chains_static,
3762 ctx->rx_chains_dynamic);
3765 mutex_unlock(&mvm->mutex);
3768 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3769 struct ieee80211_vif *vif,
3770 struct ieee80211_chanctx_conf *ctx,
3771 bool switching_chanctx)
3773 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3774 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3775 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3778 lockdep_assert_held(&mvm->mutex);
3780 mvmvif->phy_ctxt = phy_ctxt;
3782 switch (vif->type) {
3783 case NL80211_IFTYPE_AP:
3784 /* only needed if we're switching chanctx (i.e. during CSA) */
3785 if (switching_chanctx) {
3786 mvmvif->ap_ibss_active = true;
3789 case NL80211_IFTYPE_ADHOC:
3791 * The AP binding flow is handled as part of the start_ap flow
3792 * (in bss_info_changed), similarly for IBSS.
3796 case NL80211_IFTYPE_STATION:
3797 mvmvif->csa_bcn_pending = false;
3799 case NL80211_IFTYPE_MONITOR:
3800 /* always disable PS when a monitor interface is active */
3801 mvmvif->ps_disabled = true;
3808 ret = iwl_mvm_binding_add_vif(mvm, vif);
3813 * Power state must be updated before quotas,
3814 * otherwise fw will complain.
3816 iwl_mvm_power_update_mac(mvm);
3818 /* Setting the quota at this stage is only required for monitor
3819 * interfaces. For the other types, the bss_info changed flow
3820 * will handle quota settings.
3822 if (vif->type == NL80211_IFTYPE_MONITOR) {
3823 mvmvif->monitor_active = true;
3824 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3826 goto out_remove_binding;
3828 ret = iwl_mvm_add_snif_sta(mvm, vif);
3830 goto out_remove_binding;
3834 /* Handle binding during CSA */
3835 if (vif->type == NL80211_IFTYPE_AP) {
3836 iwl_mvm_update_quotas(mvm, false, NULL);
3837 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3840 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3841 u32 duration = 3 * vif->bss_conf.beacon_int;
3843 /* iwl_mvm_protect_session() reads directly from the
3844 * device (the system time), so make sure it is
3847 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3849 goto out_remove_binding;
3851 /* Protect the session to make sure we hear the first
3852 * beacon on the new channel.
3854 mvmvif->csa_bcn_pending = true;
3855 iwl_mvm_protect_session(mvm, vif, duration, duration,
3856 vif->bss_conf.beacon_int / 2,
3859 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3861 iwl_mvm_update_quotas(mvm, false, NULL);
3867 iwl_mvm_binding_remove_vif(mvm, vif);
3868 iwl_mvm_power_update_mac(mvm);
3871 mvmvif->phy_ctxt = NULL;
3874 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3875 struct ieee80211_vif *vif,
3876 struct ieee80211_chanctx_conf *ctx)
3878 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3881 mutex_lock(&mvm->mutex);
3882 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3883 mutex_unlock(&mvm->mutex);
3888 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3889 struct ieee80211_vif *vif,
3890 struct ieee80211_chanctx_conf *ctx,
3891 bool switching_chanctx)
3893 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3894 struct ieee80211_vif *disabled_vif = NULL;
3896 lockdep_assert_held(&mvm->mutex);
3898 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3900 switch (vif->type) {
3901 case NL80211_IFTYPE_ADHOC:
3903 case NL80211_IFTYPE_MONITOR:
3904 mvmvif->monitor_active = false;
3905 mvmvif->ps_disabled = false;
3906 iwl_mvm_rm_snif_sta(mvm, vif);
3908 case NL80211_IFTYPE_AP:
3909 /* This part is triggered only during CSA */
3910 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3913 mvmvif->csa_countdown = false;
3915 /* Set CS bit on all the stations */
3916 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3918 /* Save blocked iface, the timeout is set on the next beacon */
3919 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3921 mvmvif->ap_ibss_active = false;
3923 case NL80211_IFTYPE_STATION:
3924 if (!switching_chanctx)
3929 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3935 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3936 iwl_mvm_binding_remove_vif(mvm, vif);
3939 mvmvif->phy_ctxt = NULL;
3940 iwl_mvm_power_update_mac(mvm);
3943 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3944 struct ieee80211_vif *vif,
3945 struct ieee80211_chanctx_conf *ctx)
3947 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3949 mutex_lock(&mvm->mutex);
3950 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3951 mutex_unlock(&mvm->mutex);
3955 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3956 struct ieee80211_vif_chanctx_switch *vifs)
3960 mutex_lock(&mvm->mutex);
3961 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3962 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3964 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3966 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3970 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3974 "failed to assign new_ctx during channel switch\n");
3978 /* we don't support TDLS during DCM - can be caused by channel switch */
3979 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3980 iwl_mvm_teardown_tdls_peers(mvm);
3985 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3988 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3989 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3993 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3995 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4002 /* things keep failing, better restart the hw */
4003 iwl_mvm_nic_restart(mvm, false);
4006 mutex_unlock(&mvm->mutex);
4012 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
4013 struct ieee80211_vif_chanctx_switch *vifs)
4017 mutex_lock(&mvm->mutex);
4018 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4020 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4024 "failed to assign new_ctx during channel switch\n");
4031 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4033 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4040 /* things keep failing, better restart the hw */
4041 iwl_mvm_nic_restart(mvm, false);
4044 mutex_unlock(&mvm->mutex);
4049 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4050 struct ieee80211_vif_chanctx_switch *vifs,
4052 enum ieee80211_chanctx_switch_mode mode)
4054 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4057 /* we only support a single-vif right now */
4062 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4063 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4065 case CHANCTX_SWMODE_REASSIGN_VIF:
4066 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4076 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4078 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4080 return mvm->ibss_manager;
4083 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4084 struct ieee80211_sta *sta,
4087 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4088 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4090 if (!mvm_sta || !mvm_sta->vif) {
4091 IWL_ERR(mvm, "Station is not associated to a vif\n");
4095 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4098 #ifdef CONFIG_NL80211_TESTMODE
4099 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4100 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4101 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4102 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4105 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4106 struct ieee80211_vif *vif,
4107 void *data, int len)
4109 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4113 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
4118 if (!tb[IWL_MVM_TM_ATTR_CMD])
4121 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4122 case IWL_MVM_TM_CMD_SET_NOA:
4123 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4124 !vif->bss_conf.enable_beacon ||
4125 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4128 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4129 if (noa_duration >= vif->bss_conf.beacon_int)
4132 mvm->noa_duration = noa_duration;
4135 return iwl_mvm_update_quotas(mvm, true, NULL);
4136 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4137 /* must be associated client vif - ignore authorized */
4138 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4139 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4140 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4143 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4144 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4145 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4151 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4152 struct ieee80211_vif *vif,
4153 void *data, int len)
4155 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4158 mutex_lock(&mvm->mutex);
4159 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4160 mutex_unlock(&mvm->mutex);
4166 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4167 struct ieee80211_vif *vif,
4168 struct ieee80211_channel_switch *chsw)
4170 /* By implementing this operation, we prevent mac80211 from
4171 * starting its own channel switch timer, so that we can call
4172 * ieee80211_chswitch_done() ourselves at the right time
4173 * (which is when the absence time event starts).
4176 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4177 "dummy channel switch op\n");
4180 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4181 struct ieee80211_vif *vif,
4182 struct ieee80211_channel_switch *chsw)
4184 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4185 struct ieee80211_vif *csa_vif;
4186 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4190 mutex_lock(&mvm->mutex);
4192 mvmvif->csa_failed = false;
4194 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4195 chsw->chandef.center_freq1);
4197 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4198 ieee80211_vif_to_wdev(vif),
4199 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4201 switch (vif->type) {
4202 case NL80211_IFTYPE_AP:
4204 rcu_dereference_protected(mvm->csa_vif,
4205 lockdep_is_held(&mvm->mutex));
4206 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4207 "Another CSA is already in progress")) {
4212 /* we still didn't unblock tx. prevent new CS meanwhile */
4213 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4214 lockdep_is_held(&mvm->mutex))) {
4219 rcu_assign_pointer(mvm->csa_vif, vif);
4221 if (WARN_ONCE(mvmvif->csa_countdown,
4222 "Previous CSA countdown didn't complete")) {
4227 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4230 case NL80211_IFTYPE_STATION:
4231 /* Schedule the time event to a bit before beacon 1,
4232 * to make sure we're in the new channel when the
4233 * GO/AP arrives. In case count <= 1 immediately schedule the
4234 * TE (this might result with some packet loss or connection
4237 if (chsw->count <= 1)
4240 apply_time = chsw->device_timestamp +
4241 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4242 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4245 iwl_mvm_csa_client_absent(mvm, vif);
4247 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4249 if (mvmvif->bf_data.bf_enabled) {
4250 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4260 mvmvif->ps_disabled = true;
4262 ret = iwl_mvm_power_update_ps(mvm);
4266 /* we won't be on this channel any longer */
4267 iwl_mvm_teardown_tdls_peers(mvm);
4270 mutex_unlock(&mvm->mutex);
4275 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
4276 struct ieee80211_vif *vif)
4278 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4279 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4282 mutex_lock(&mvm->mutex);
4284 if (mvmvif->csa_failed) {
4285 mvmvif->csa_failed = false;
4290 if (vif->type == NL80211_IFTYPE_STATION) {
4291 struct iwl_mvm_sta *mvmsta;
4293 mvmvif->csa_bcn_pending = false;
4294 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
4297 if (WARN_ON(!mvmsta)) {
4302 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
4304 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4306 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4310 iwl_mvm_stop_session_protection(mvm, vif);
4313 mvmvif->ps_disabled = false;
4315 ret = iwl_mvm_power_update_ps(mvm);
4318 mutex_unlock(&mvm->mutex);
4323 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4327 if (!iwl_mvm_has_new_tx_api(mvm)) {
4329 mutex_lock(&mvm->mutex);
4330 iwl_mvm_flush_tx_path(mvm,
4331 iwl_mvm_flushable_queues(mvm) & queues, 0);
4332 mutex_unlock(&mvm->mutex);
4334 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4339 mutex_lock(&mvm->mutex);
4340 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4341 struct ieee80211_sta *sta;
4343 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4344 lockdep_is_held(&mvm->mutex));
4345 if (IS_ERR_OR_NULL(sta))
4349 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4351 iwl_mvm_wait_sta_queues_empty(mvm,
4352 iwl_mvm_sta_from_mac80211(sta));
4354 mutex_unlock(&mvm->mutex);
4357 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4358 struct ieee80211_vif *vif, u32 queues, bool drop)
4360 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4361 struct iwl_mvm_vif *mvmvif;
4362 struct iwl_mvm_sta *mvmsta;
4363 struct ieee80211_sta *sta;
4368 iwl_mvm_flush_no_vif(mvm, queues, drop);
4372 if (vif->type != NL80211_IFTYPE_STATION)
4375 /* Make sure we're done with the deferred traffic before flushing */
4376 flush_work(&mvm->add_stream_wk);
4378 mutex_lock(&mvm->mutex);
4379 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4381 /* flush the AP-station and all TDLS peers */
4382 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4383 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4384 lockdep_is_held(&mvm->mutex));
4385 if (IS_ERR_OR_NULL(sta))
4388 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4389 if (mvmsta->vif != vif)
4392 /* make sure only TDLS peers or the AP are flushed */
4393 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4396 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4397 IWL_ERR(mvm, "flush request fail\n");
4399 msk |= mvmsta->tfd_queue_msk;
4400 if (iwl_mvm_has_new_tx_api(mvm))
4401 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4405 mutex_unlock(&mvm->mutex);
4407 /* this can take a while, and we may need/want other operations
4408 * to succeed while doing this, so do it without the mutex held
4410 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4411 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4414 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4415 struct survey_info *survey)
4417 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4420 memset(survey, 0, sizeof(*survey));
4422 /* only support global statistics right now */
4426 if (!fw_has_capa(&mvm->fw->ucode_capa,
4427 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4430 mutex_lock(&mvm->mutex);
4432 if (iwl_mvm_firmware_running(mvm)) {
4433 ret = iwl_mvm_request_statistics(mvm, false);
4438 survey->filled = SURVEY_INFO_TIME |
4439 SURVEY_INFO_TIME_RX |
4440 SURVEY_INFO_TIME_TX |
4441 SURVEY_INFO_TIME_SCAN;
4442 survey->time = mvm->accu_radio_stats.on_time_rf +
4443 mvm->radio_stats.on_time_rf;
4444 do_div(survey->time, USEC_PER_MSEC);
4446 survey->time_rx = mvm->accu_radio_stats.rx_time +
4447 mvm->radio_stats.rx_time;
4448 do_div(survey->time_rx, USEC_PER_MSEC);
4450 survey->time_tx = mvm->accu_radio_stats.tx_time +
4451 mvm->radio_stats.tx_time;
4452 do_div(survey->time_tx, USEC_PER_MSEC);
4454 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4455 mvm->radio_stats.on_time_scan;
4456 do_div(survey->time_scan, USEC_PER_MSEC);
4460 mutex_unlock(&mvm->mutex);
4464 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4465 struct ieee80211_vif *vif,
4466 struct ieee80211_sta *sta,
4467 struct station_info *sinfo)
4469 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4470 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4471 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4473 if (mvmsta->avg_energy) {
4474 sinfo->signal_avg = mvmsta->avg_energy;
4475 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4478 if (!fw_has_capa(&mvm->fw->ucode_capa,
4479 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
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,