1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11 * Copyright(c) 2018 Intel Corporation
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * The full GNU General Public License is included in this distribution
23 * in the file called COPYING.
25 * Contact Information:
26 * Intel Linux Wireless <linuxwifi@intel.com>
27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34 * Copyright(c) 2018 Intel Corporation
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
47 * * Neither the name Intel Corporation nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *****************************************************************************/
64 #include <linux/kernel.h>
65 #include <linux/slab.h>
66 #include <linux/skbuff.h>
67 #include <linux/netdevice.h>
68 #include <linux/etherdevice.h>
70 #include <linux/if_arp.h>
71 #include <linux/time.h>
72 #include <net/mac80211.h>
73 #include <net/ieee80211_radiotap.h>
76 #include "iwl-op-mode.h"
80 #include "time-event.h"
81 #include "iwl-eeprom-parse.h"
82 #include "iwl-phy-db.h"
84 #include "fw/error-dump.h"
86 #include "iwl-nvm-parse.h"
88 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
91 .types = BIT(NL80211_IFTYPE_STATION),
95 .types = BIT(NL80211_IFTYPE_AP) |
96 BIT(NL80211_IFTYPE_P2P_CLIENT) |
97 BIT(NL80211_IFTYPE_P2P_GO),
101 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
105 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
107 .num_different_channels = 2,
109 .limits = iwl_mvm_limits,
110 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
114 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
116 * Use the reserved field to indicate magic values.
117 * these values will only be used internally by the driver,
118 * and won't make it to the fw (reserved will be 0).
119 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
120 * be the vif's ip address. in case there is not a single
121 * ip address (0, or more than 1), this attribute will
123 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
124 * the LSB bytes of the vif's mac address
127 BC_FILTER_MAGIC_NONE = 0,
132 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
136 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
139 /* frame type - arp, hw type - ethernet */
141 BCAST_FILTER_OFFSET_PAYLOAD_START,
142 .offset = sizeof(rfc1042_header),
143 .val = cpu_to_be32(0x08060001),
144 .mask = cpu_to_be32(0xffffffff),
149 BCAST_FILTER_OFFSET_PAYLOAD_START,
150 .offset = sizeof(rfc1042_header) + 2 +
151 sizeof(struct arphdr) +
152 ETH_ALEN + sizeof(__be32) +
154 .mask = cpu_to_be32(0xffffffff),
155 /* mark it as special field */
156 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
161 /* dhcp offer bcast */
163 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
166 /* udp dest port - 68 (bootp client)*/
167 .offset_type = BCAST_FILTER_OFFSET_IP_END,
168 .offset = offsetof(struct udphdr, dest),
169 .val = cpu_to_be32(0x00440000),
170 .mask = cpu_to_be32(0xffff0000),
173 /* dhcp - lsb bytes of client hw address */
174 .offset_type = BCAST_FILTER_OFFSET_IP_END,
176 .mask = cpu_to_be32(0xffffffff),
177 /* mark it as special field */
178 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
182 /* last filter must be empty */
187 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
189 if (!iwl_mvm_is_d0i3_supported(mvm))
192 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
193 spin_lock_bh(&mvm->refs_lock);
194 mvm->refs[ref_type]++;
195 spin_unlock_bh(&mvm->refs_lock);
196 iwl_trans_ref(mvm->trans);
199 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
201 if (!iwl_mvm_is_d0i3_supported(mvm))
204 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
205 spin_lock_bh(&mvm->refs_lock);
206 if (WARN_ON(!mvm->refs[ref_type])) {
207 spin_unlock_bh(&mvm->refs_lock);
210 mvm->refs[ref_type]--;
211 spin_unlock_bh(&mvm->refs_lock);
212 iwl_trans_unref(mvm->trans);
215 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
216 enum iwl_mvm_ref_type except_ref)
220 if (!iwl_mvm_is_d0i3_supported(mvm))
223 spin_lock_bh(&mvm->refs_lock);
224 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
225 if (except_ref == i || !mvm->refs[i])
228 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
230 for (j = 0; j < mvm->refs[i]; j++)
231 iwl_trans_unref(mvm->trans);
234 spin_unlock_bh(&mvm->refs_lock);
237 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
242 if (!iwl_mvm_is_d0i3_supported(mvm))
245 spin_lock_bh(&mvm->refs_lock);
246 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
252 spin_unlock_bh(&mvm->refs_lock);
257 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
259 iwl_mvm_ref(mvm, ref_type);
261 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
262 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
265 iwl_mvm_unref(mvm, ref_type);
272 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
276 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
277 for (i = 0; i < NUM_PHY_CTX; i++) {
278 mvm->phy_ctxts[i].id = i;
279 mvm->phy_ctxts[i].ref = 0;
283 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
285 enum iwl_mcc_source src_id,
288 struct ieee80211_regdomain *regd = NULL;
289 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
290 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
291 struct iwl_mcc_update_resp *resp;
293 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
295 lockdep_assert_held(&mvm->mutex);
297 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
298 if (IS_ERR_OR_NULL(resp)) {
299 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
300 PTR_ERR_OR_ZERO(resp));
305 *changed = (resp->status == MCC_RESP_NEW_CHAN_PROFILE);
307 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
308 __le32_to_cpu(resp->n_channels),
310 __le16_to_cpu(resp->mcc),
311 __le16_to_cpu(resp->geo_info));
312 /* Store the return source id */
313 src_id = resp->source_id;
315 if (IS_ERR_OR_NULL(regd)) {
316 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
317 PTR_ERR_OR_ZERO(regd));
321 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
322 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
323 mvm->lar_regdom_set = true;
324 mvm->mcc_src = src_id;
330 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
333 struct ieee80211_regdomain *regd;
335 if (!iwl_mvm_is_lar_supported(mvm))
338 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
339 if (!IS_ERR_OR_NULL(regd)) {
340 /* only update the regulatory core if changed */
342 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
348 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
351 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
352 iwl_mvm_is_wifi_mcc_supported(mvm) ?
353 MCC_SOURCE_GET_CURRENT :
354 MCC_SOURCE_OLD_FW, changed);
357 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
359 enum iwl_mcc_source used_src;
360 struct ieee80211_regdomain *regd;
363 const struct ieee80211_regdomain *r =
364 rtnl_dereference(mvm->hw->wiphy->regd);
369 /* save the last source in case we overwrite it below */
370 used_src = mvm->mcc_src;
371 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
372 /* Notify the firmware we support wifi location updates */
373 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
374 if (!IS_ERR_OR_NULL(regd))
378 /* Now set our last stored MCC and source */
379 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
381 if (IS_ERR_OR_NULL(regd))
384 /* update cfg80211 if the regdomain was changed */
386 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
394 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
396 struct ieee80211_hw *hw = mvm->hw;
398 static const u32 mvm_ciphers[] = {
399 WLAN_CIPHER_SUITE_WEP40,
400 WLAN_CIPHER_SUITE_WEP104,
401 WLAN_CIPHER_SUITE_TKIP,
402 WLAN_CIPHER_SUITE_CCMP,
405 /* Tell mac80211 our characteristics */
406 ieee80211_hw_set(hw, SIGNAL_DBM);
407 ieee80211_hw_set(hw, SPECTRUM_MGMT);
408 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
409 ieee80211_hw_set(hw, QUEUE_CONTROL);
410 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
411 ieee80211_hw_set(hw, SUPPORTS_PS);
412 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
413 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
414 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
415 ieee80211_hw_set(hw, CONNECTION_MONITOR);
416 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
417 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
418 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
419 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
420 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
421 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
423 if (iwl_mvm_has_tlc_offload(mvm)) {
424 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
425 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
428 if (iwl_mvm_has_new_rx_api(mvm))
429 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
431 if (fw_has_capa(&mvm->fw->ucode_capa,
432 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
433 ieee80211_hw_set(hw, AP_LINK_PS);
434 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
436 * we absolutely need this for the new TX API since that comes
437 * with many more queues than the current code can deal with
438 * for station powersave
443 if (mvm->trans->num_rx_queues > 1)
444 ieee80211_hw_set(hw, USES_RSS);
446 if (mvm->trans->max_skb_frags)
447 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
449 hw->queues = IEEE80211_MAX_QUEUES;
450 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
451 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
452 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
453 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
454 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
456 hw->radiotap_timestamp.units_pos =
457 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
458 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
459 /* this is the case for CCK frames, it's better (only 8) for OFDM */
460 hw->radiotap_timestamp.accuracy = 22;
462 if (!iwl_mvm_has_tlc_offload(mvm))
463 hw->rate_control_algorithm = RS_NAME;
465 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
466 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
468 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
469 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
470 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
471 hw->wiphy->cipher_suites = mvm->ciphers;
473 if (iwl_mvm_has_new_rx_api(mvm)) {
474 mvm->ciphers[hw->wiphy->n_cipher_suites] =
475 WLAN_CIPHER_SUITE_GCMP;
476 hw->wiphy->n_cipher_suites++;
477 mvm->ciphers[hw->wiphy->n_cipher_suites] =
478 WLAN_CIPHER_SUITE_GCMP_256;
479 hw->wiphy->n_cipher_suites++;
482 /* Enable 11w if software crypto is not enabled (as the
483 * firmware will interpret some mgmt packets, so enabling it
484 * with software crypto isn't safe).
486 if (!iwlwifi_mod_params.swcrypto) {
487 ieee80211_hw_set(hw, MFP_CAPABLE);
488 mvm->ciphers[hw->wiphy->n_cipher_suites] =
489 WLAN_CIPHER_SUITE_AES_CMAC;
490 hw->wiphy->n_cipher_suites++;
491 if (iwl_mvm_has_new_rx_api(mvm)) {
492 mvm->ciphers[hw->wiphy->n_cipher_suites] =
493 WLAN_CIPHER_SUITE_BIP_GMAC_128;
494 hw->wiphy->n_cipher_suites++;
495 mvm->ciphers[hw->wiphy->n_cipher_suites] =
496 WLAN_CIPHER_SUITE_BIP_GMAC_256;
497 hw->wiphy->n_cipher_suites++;
501 /* currently FW API supports only one optional cipher scheme */
502 if (mvm->fw->cs[0].cipher) {
503 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
504 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
506 mvm->hw->n_cipher_schemes = 1;
508 cs->cipher = le32_to_cpu(fwcs->cipher);
509 cs->iftype = BIT(NL80211_IFTYPE_STATION);
510 cs->hdr_len = fwcs->hdr_len;
511 cs->pn_len = fwcs->pn_len;
512 cs->pn_off = fwcs->pn_off;
513 cs->key_idx_off = fwcs->key_idx_off;
514 cs->key_idx_mask = fwcs->key_idx_mask;
515 cs->key_idx_shift = fwcs->key_idx_shift;
516 cs->mic_len = fwcs->mic_len;
518 mvm->hw->cipher_schemes = mvm->cs;
519 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
520 hw->wiphy->n_cipher_suites++;
523 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
524 hw->wiphy->features |=
525 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
526 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
527 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
529 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
530 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
531 hw->chanctx_data_size = sizeof(u16);
533 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
534 BIT(NL80211_IFTYPE_P2P_CLIENT) |
535 BIT(NL80211_IFTYPE_AP) |
536 BIT(NL80211_IFTYPE_P2P_GO) |
537 BIT(NL80211_IFTYPE_P2P_DEVICE) |
538 BIT(NL80211_IFTYPE_ADHOC);
540 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
541 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
542 if (iwl_mvm_is_lar_supported(mvm))
543 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
545 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
546 REGULATORY_DISABLE_BEACON_HINTS;
548 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
549 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
551 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
552 hw->wiphy->n_iface_combinations =
553 ARRAY_SIZE(iwl_mvm_iface_combinations);
555 hw->wiphy->max_remain_on_channel_duration = 10000;
556 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
558 /* Extract MAC address */
559 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
560 hw->wiphy->addresses = mvm->addresses;
561 hw->wiphy->n_addresses = 1;
563 /* Extract additional MAC addresses if available */
564 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
565 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
567 for (i = 1; i < num_mac; i++) {
568 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
570 mvm->addresses[i].addr[5]++;
571 hw->wiphy->n_addresses++;
574 iwl_mvm_reset_phy_ctxts(mvm);
576 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
578 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
580 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
581 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
582 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
584 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
585 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
587 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
589 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
590 hw->wiphy->bands[NL80211_BAND_2GHZ] =
591 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
592 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
593 hw->wiphy->bands[NL80211_BAND_5GHZ] =
594 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
596 if (fw_has_capa(&mvm->fw->ucode_capa,
597 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
598 fw_has_api(&mvm->fw->ucode_capa,
599 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
600 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
601 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
604 hw->wiphy->hw_version = mvm->trans->hw_id;
606 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
607 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
609 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
611 hw->wiphy->max_sched_scan_reqs = 1;
612 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
613 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
614 /* we create the 802.11 header and zero length SSID IE. */
615 hw->wiphy->max_sched_scan_ie_len =
616 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
617 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
618 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
621 * the firmware uses u8 for num of iterations, but 0xff is saved for
622 * infinite loop, so the maximum number of iterations is actually 254.
624 hw->wiphy->max_sched_scan_plan_iterations = 254;
626 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
627 NL80211_FEATURE_LOW_PRIORITY_SCAN |
628 NL80211_FEATURE_P2P_GO_OPPPS |
629 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
630 NL80211_FEATURE_DYNAMIC_SMPS |
631 NL80211_FEATURE_STATIC_SMPS |
632 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
634 if (fw_has_capa(&mvm->fw->ucode_capa,
635 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
636 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
637 if (fw_has_capa(&mvm->fw->ucode_capa,
638 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
639 hw->wiphy->features |= NL80211_FEATURE_QUIET;
641 if (fw_has_capa(&mvm->fw->ucode_capa,
642 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
643 hw->wiphy->features |=
644 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
646 if (fw_has_capa(&mvm->fw->ucode_capa,
647 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
648 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
650 if (fw_has_api(&mvm->fw->ucode_capa,
651 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
652 wiphy_ext_feature_set(hw->wiphy,
653 NL80211_EXT_FEATURE_SCAN_START_TIME);
654 wiphy_ext_feature_set(hw->wiphy,
655 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
656 wiphy_ext_feature_set(hw->wiphy,
657 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
660 if (iwl_mvm_is_oce_supported(mvm)) {
661 wiphy_ext_feature_set(hw->wiphy,
662 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
663 wiphy_ext_feature_set(hw->wiphy,
664 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
665 wiphy_ext_feature_set(hw->wiphy,
666 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
667 wiphy_ext_feature_set(hw->wiphy,
668 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
671 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
673 #ifdef CONFIG_PM_SLEEP
674 if (iwl_mvm_is_d0i3_supported(mvm) &&
675 device_can_wakeup(mvm->trans->dev)) {
676 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
677 hw->wiphy->wowlan = &mvm->wowlan;
680 if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
681 mvm->trans->ops->d3_suspend &&
682 mvm->trans->ops->d3_resume &&
683 device_can_wakeup(mvm->trans->dev)) {
684 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
685 WIPHY_WOWLAN_DISCONNECT |
686 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
687 WIPHY_WOWLAN_RFKILL_RELEASE |
688 WIPHY_WOWLAN_NET_DETECT;
689 if (!iwlwifi_mod_params.swcrypto)
690 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
691 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
692 WIPHY_WOWLAN_4WAY_HANDSHAKE;
694 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
695 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
696 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
697 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
698 hw->wiphy->wowlan = &mvm->wowlan;
702 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
703 /* assign default bcast filtering configuration */
704 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
707 ret = iwl_mvm_leds_init(mvm);
711 if (fw_has_capa(&mvm->fw->ucode_capa,
712 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
713 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
714 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
715 ieee80211_hw_set(hw, TDLS_WIDER_BW);
718 if (fw_has_capa(&mvm->fw->ucode_capa,
719 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
720 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
721 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
724 hw->netdev_features |= mvm->cfg->features;
725 if (!iwl_mvm_is_csum_supported(mvm)) {
726 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
728 /* We may support SW TX CSUM */
729 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
730 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
733 ret = ieee80211_register_hw(mvm->hw);
735 iwl_mvm_leds_exit(mvm);
736 mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
738 if (mvm->cfg->vht_mu_mimo_supported)
739 wiphy_ext_feature_set(hw->wiphy,
740 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
745 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
746 struct ieee80211_sta *sta,
749 struct iwl_mvm_sta *mvmsta;
753 * double check the IN_D0I3 flag both before and after
754 * taking the spinlock, in order to prevent taking
755 * the spinlock when not needed.
757 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
760 spin_lock(&mvm->d0i3_tx_lock);
762 * testing the flag again ensures the skb dequeue
763 * loop (on d0i3 exit) hasn't run yet.
765 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
768 mvmsta = iwl_mvm_sta_from_mac80211(sta);
769 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
770 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
773 __skb_queue_tail(&mvm->d0i3_tx, skb);
774 ieee80211_stop_queues(mvm->hw);
777 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
778 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
782 spin_unlock(&mvm->d0i3_tx_lock);
786 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
787 struct ieee80211_tx_control *control,
790 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
791 struct ieee80211_sta *sta = control->sta;
792 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
793 struct ieee80211_hdr *hdr = (void *)skb->data;
795 if (iwl_mvm_is_radio_killed(mvm)) {
796 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
800 if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
801 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
802 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
805 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
806 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
807 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
808 ieee80211_is_mgmt(hdr->frame_control) &&
809 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
813 if (iwl_mvm_defer_tx(mvm, sta, skb))
815 if (iwl_mvm_tx_skb(mvm, skb, sta))
820 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
824 ieee80211_free_txskb(hw, skb);
827 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
829 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
834 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
836 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
838 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
841 /* enabled by default */
845 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
847 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
849 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
853 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
854 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
855 enum ieee80211_ampdu_mlme_action action)
857 struct iwl_fw_dbg_trigger_tlv *trig;
858 struct iwl_fw_dbg_trigger_ba *ba_trig;
860 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
863 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
864 ba_trig = (void *)trig->data;
866 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
867 ieee80211_vif_to_wdev(vif), trig))
871 case IEEE80211_AMPDU_TX_OPERATIONAL: {
872 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
873 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
875 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
876 "TX AGG START: MAC %pM tid %d ssn %d\n",
877 sta->addr, tid, tid_data->ssn);
880 case IEEE80211_AMPDU_TX_STOP_CONT:
881 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
882 "TX AGG STOP: MAC %pM tid %d\n",
885 case IEEE80211_AMPDU_RX_START:
886 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
887 "RX AGG START: MAC %pM tid %d ssn %d\n",
888 sta->addr, tid, rx_ba_ssn);
890 case IEEE80211_AMPDU_RX_STOP:
891 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
892 "RX AGG STOP: MAC %pM tid %d\n",
900 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
901 struct ieee80211_vif *vif,
902 struct ieee80211_ampdu_params *params)
904 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
906 bool tx_agg_ref = false;
907 struct ieee80211_sta *sta = params->sta;
908 enum ieee80211_ampdu_mlme_action action = params->action;
909 u16 tid = params->tid;
910 u16 *ssn = ¶ms->ssn;
911 u16 buf_size = params->buf_size;
912 bool amsdu = params->amsdu;
913 u16 timeout = params->timeout;
915 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
916 sta->addr, tid, action);
918 if (!(mvm->nvm_data->sku_cap_11n_enable))
921 /* return from D0i3 before starting a new Tx aggregation */
923 case IEEE80211_AMPDU_TX_START:
924 case IEEE80211_AMPDU_TX_STOP_CONT:
925 case IEEE80211_AMPDU_TX_STOP_FLUSH:
926 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
927 case IEEE80211_AMPDU_TX_OPERATIONAL:
929 * for tx start, wait synchronously until D0i3 exit to
930 * get the correct sequence number for the tid.
931 * additionally, some other ampdu actions use direct
932 * target access, which is not handled automatically
933 * by the trans layer (unlike commands), so wait for
934 * d0i3 exit in these cases as well.
936 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
946 mutex_lock(&mvm->mutex);
949 case IEEE80211_AMPDU_RX_START:
950 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
951 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
952 struct iwl_mvm_vif *mvmvif;
953 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
954 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
956 mdata->opened_rx_ba_sessions = true;
957 mvmvif = iwl_mvm_vif_from_mac80211(vif);
958 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
960 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
964 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
967 case IEEE80211_AMPDU_RX_STOP:
968 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
971 case IEEE80211_AMPDU_TX_START:
972 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
976 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
978 case IEEE80211_AMPDU_TX_STOP_CONT:
979 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
981 case IEEE80211_AMPDU_TX_STOP_FLUSH:
982 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
983 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
985 case IEEE80211_AMPDU_TX_OPERATIONAL:
986 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
998 if (action == IEEE80211_AMPDU_RX_START)
1001 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1004 mutex_unlock(&mvm->mutex);
1007 * If the tid is marked as started, we won't use it for offloaded
1008 * traffic on the next D0i3 entry. It's safe to unref.
1011 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1016 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1017 struct ieee80211_vif *vif)
1019 struct iwl_mvm *mvm = data;
1020 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1022 mvmvif->uploaded = false;
1023 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1025 spin_lock_bh(&mvm->time_event_lock);
1026 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1027 spin_unlock_bh(&mvm->time_event_lock);
1029 mvmvif->phy_ctxt = NULL;
1030 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1031 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
1034 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1036 /* clear the D3 reconfig, we only need it to avoid dumping a
1037 * firmware coredump on reconfiguration, we shouldn't do that
1038 * on D3->D0 transition
1040 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1041 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1042 iwl_fw_error_dump(&mvm->fwrt);
1045 /* cleanup all stale references (scan, roc), but keep the
1046 * ucode_down ref until reconfig is complete
1048 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1050 iwl_mvm_stop_device(mvm);
1052 mvm->scan_status = 0;
1053 mvm->ps_disabled = false;
1054 mvm->calibrating = false;
1056 /* just in case one was running */
1057 iwl_mvm_cleanup_roc_te(mvm);
1058 ieee80211_remain_on_channel_expired(mvm->hw);
1061 * cleanup all interfaces, even inactive ones, as some might have
1062 * gone down during the HW restart
1064 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1066 mvm->p2p_device_vif = NULL;
1067 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1069 iwl_mvm_reset_phy_ctxts(mvm);
1070 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1071 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
1072 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1073 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1075 ieee80211_wake_queues(mvm->hw);
1077 /* clear any stale d0i3 state */
1078 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1081 mvm->rx_ba_sessions = 0;
1082 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1083 mvm->monitor_on = false;
1085 /* keep statistics ticking */
1086 iwl_mvm_accu_radio_stats(mvm);
1089 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1093 lockdep_assert_held(&mvm->mutex);
1095 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1097 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1098 * so later code will - from now on - see that we're doing it.
1100 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1101 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1102 /* Clean up some internal and mac80211 state on restart */
1103 iwl_mvm_restart_cleanup(mvm);
1105 /* Hold the reference to prevent runtime suspend while
1106 * the start procedure runs. It's a bit confusing
1107 * that the UCODE_DOWN reference is taken, but it just
1108 * means "UCODE is not UP yet". ( TODO: rename this
1111 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1113 ret = iwl_mvm_up(mvm);
1115 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1116 /* Something went wrong - we need to finish some cleanup
1117 * that normally iwl_mvm_mac_restart_complete() below
1120 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1122 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1129 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1131 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1134 /* Some hw restart cleanups must not hold the mutex */
1135 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1137 * Make sure we are out of d0i3. This is needed
1138 * to make sure the reference accounting is correct
1139 * (and there is no stale d0i3_exit_work).
1141 wait_event_timeout(mvm->d0i3_exit_waitq,
1142 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1147 mutex_lock(&mvm->mutex);
1148 ret = __iwl_mvm_mac_start(mvm);
1149 mutex_unlock(&mvm->mutex);
1154 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1158 mutex_lock(&mvm->mutex);
1160 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1162 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1164 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1166 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1169 /* allow transport/FW low power modes */
1170 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1173 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1174 * of packets the FW sent out, so we must reconnect.
1176 iwl_mvm_teardown_tdls_peers(mvm);
1178 mutex_unlock(&mvm->mutex);
1181 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1183 if (iwl_mvm_is_d0i3_supported(mvm) &&
1184 iwl_mvm_enter_d0i3_on_suspend(mvm))
1185 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1186 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1189 "D0i3 exit on resume timed out\n");
1193 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1194 enum ieee80211_reconfig_type reconfig_type)
1196 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1198 switch (reconfig_type) {
1199 case IEEE80211_RECONFIG_TYPE_RESTART:
1200 iwl_mvm_restart_complete(mvm);
1202 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1203 iwl_mvm_resume_complete(mvm);
1208 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1210 lockdep_assert_held(&mvm->mutex);
1212 /* firmware counters are obviously reset now, but we shouldn't
1213 * partially track so also clear the fw_reset_accu counters.
1215 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1217 /* async_handlers_wk is now blocked */
1220 * The work item could be running or queued if the
1221 * ROC time event stops just as we get here.
1223 flush_work(&mvm->roc_done_wk);
1225 iwl_mvm_stop_device(mvm);
1227 iwl_mvm_async_handlers_purge(mvm);
1228 /* async_handlers_list is empty and will stay empty: HW is stopped */
1230 /* the fw is stopped, the aux sta is dead: clean up driver state */
1231 iwl_mvm_del_aux_sta(mvm);
1234 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1235 * won't be called in this case).
1236 * But make sure to cleanup interfaces that have gone down before/during
1237 * HW restart was requested.
1239 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1240 ieee80211_iterate_interfaces(mvm->hw, 0,
1241 iwl_mvm_cleanup_iterator, mvm);
1243 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1244 * make sure there's nothing left there and warn if any is found.
1246 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1249 for (i = 0; i < mvm->max_scans; i++) {
1250 if (WARN_ONCE(mvm->scan_uid_status[i],
1251 "UMAC scan UID %d status was not cleaned\n",
1253 mvm->scan_uid_status[i] = 0;
1258 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1260 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1262 flush_work(&mvm->d0i3_exit_work);
1263 flush_work(&mvm->async_handlers_wk);
1264 flush_work(&mvm->add_stream_wk);
1267 * Lock and clear the firmware running bit here already, so that
1268 * new commands coming in elsewhere, e.g. from debugfs, will not
1269 * be able to proceed. This is important here because one of those
1270 * debugfs files causes the firmware dump to be triggered, and if we
1271 * don't stop debugfs accesses before canceling that it could be
1272 * retriggered after we flush it but before we've cleared the bit.
1274 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1276 iwl_fw_cancel_dump(&mvm->fwrt);
1277 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1278 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1279 iwl_fw_free_dump_desc(&mvm->fwrt);
1281 mutex_lock(&mvm->mutex);
1282 __iwl_mvm_mac_stop(mvm);
1283 mutex_unlock(&mvm->mutex);
1286 * The worker might have been waiting for the mutex, let it run and
1287 * discover that its list is now empty.
1289 cancel_work_sync(&mvm->async_handlers_wk);
1292 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1296 lockdep_assert_held(&mvm->mutex);
1298 for (i = 0; i < NUM_PHY_CTX; i++)
1299 if (!mvm->phy_ctxts[i].ref)
1300 return &mvm->phy_ctxts[i];
1302 IWL_ERR(mvm, "No available PHY context\n");
1306 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1311 struct iwl_dev_tx_power_cmd v5;
1312 struct iwl_dev_tx_power_cmd_v4 v4;
1314 .v5.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1315 .v5.v3.mac_context_id =
1316 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1317 .v5.v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1320 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1321 cmd.v5.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1323 if (fw_has_api(&mvm->fw->ucode_capa,
1324 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1325 len = sizeof(cmd.v5);
1326 else if (fw_has_capa(&mvm->fw->ucode_capa,
1327 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1328 len = sizeof(cmd.v4);
1330 len = sizeof(cmd.v4.v3);
1332 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1335 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1336 struct ieee80211_vif *vif)
1338 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1339 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1343 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1346 * make sure D0i3 exit is completed, otherwise a target access
1347 * during tx queue configuration could be done when still in
1350 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1355 * Not much to do here. The stack will not allow interface
1356 * types or combinations that we didn't advertise, so we
1357 * don't really have to check the types.
1360 mutex_lock(&mvm->mutex);
1362 /* make sure that beacon statistics don't go backwards with FW reset */
1363 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1364 mvmvif->beacon_stats.accu_num_beacons +=
1365 mvmvif->beacon_stats.num_beacons;
1367 /* Allocate resources for the MAC context, and add it to the fw */
1368 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1372 /* Counting number of interfaces is needed for legacy PM */
1373 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1377 * The AP binding flow can be done only after the beacon
1378 * template is configured (which happens only in the mac80211
1379 * start_ap() flow), and adding the broadcast station can happen
1380 * only after the binding.
1381 * In addition, since modifying the MAC before adding a bcast
1382 * station is not allowed by the FW, delay the adding of MAC context to
1383 * the point where we can also add the bcast station.
1384 * In short: there's not much we can do at this point, other than
1385 * allocating resources :)
1387 if (vif->type == NL80211_IFTYPE_AP ||
1388 vif->type == NL80211_IFTYPE_ADHOC) {
1389 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1391 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1396 * Only queue for this station is the mcast queue,
1397 * which shouldn't be in TFD mask anyway
1399 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1405 iwl_mvm_vif_dbgfs_register(mvm, vif);
1409 mvmvif->features |= hw->netdev_features;
1411 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1415 ret = iwl_mvm_power_update_mac(mvm);
1417 goto out_remove_mac;
1419 /* beacon filtering */
1420 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1422 goto out_remove_mac;
1424 if (!mvm->bf_allowed_vif &&
1425 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1426 mvm->bf_allowed_vif = mvmvif;
1427 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1428 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1432 * P2P_DEVICE interface does not have a channel context assigned to it,
1433 * so a dedicated PHY context is allocated to it and the corresponding
1434 * MAC context is bound to it at this stage.
1436 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1438 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1439 if (!mvmvif->phy_ctxt) {
1444 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1445 ret = iwl_mvm_binding_add_vif(mvm, vif);
1449 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1453 /* Save a pointer to p2p device vif, so it can later be used to
1454 * update the p2p device MAC when a GO is started/stopped */
1455 mvm->p2p_device_vif = vif;
1458 iwl_mvm_tcm_add_vif(mvm, vif);
1460 if (vif->type == NL80211_IFTYPE_MONITOR)
1461 mvm->monitor_on = true;
1463 iwl_mvm_vif_dbgfs_register(mvm, vif);
1467 iwl_mvm_binding_remove_vif(mvm, vif);
1469 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1471 if (mvm->bf_allowed_vif == mvmvif) {
1472 mvm->bf_allowed_vif = NULL;
1473 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1474 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1477 mvmvif->phy_ctxt = NULL;
1478 iwl_mvm_mac_ctxt_remove(mvm, vif);
1480 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1483 mutex_unlock(&mvm->mutex);
1485 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1490 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1491 struct ieee80211_vif *vif)
1493 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1495 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1496 * We assume here that all the packets sent to the OFFCHANNEL
1497 * queue are sent in ROC session.
1499 flush_work(&mvm->roc_done_wk);
1503 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1504 struct ieee80211_vif *vif)
1506 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1507 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1508 struct iwl_probe_resp_data *probe_data;
1510 iwl_mvm_prepare_mac_removal(mvm, vif);
1512 if (!(vif->type == NL80211_IFTYPE_AP ||
1513 vif->type == NL80211_IFTYPE_ADHOC))
1514 iwl_mvm_tcm_rm_vif(mvm, vif);
1516 mutex_lock(&mvm->mutex);
1518 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1519 lockdep_is_held(&mvm->mutex));
1520 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1522 kfree_rcu(probe_data, rcu_head);
1524 if (mvm->bf_allowed_vif == mvmvif) {
1525 mvm->bf_allowed_vif = NULL;
1526 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1527 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1530 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1533 * For AP/GO interface, the tear down of the resources allocated to the
1534 * interface is be handled as part of the stop_ap flow.
1536 if (vif->type == NL80211_IFTYPE_AP ||
1537 vif->type == NL80211_IFTYPE_ADHOC) {
1538 #ifdef CONFIG_NL80211_TESTMODE
1539 if (vif == mvm->noa_vif) {
1540 mvm->noa_vif = NULL;
1541 mvm->noa_duration = 0;
1544 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1545 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1549 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1550 mvm->p2p_device_vif = NULL;
1551 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1552 iwl_mvm_binding_remove_vif(mvm, vif);
1553 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1554 mvmvif->phy_ctxt = NULL;
1557 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1560 iwl_mvm_power_update_mac(mvm);
1561 iwl_mvm_mac_ctxt_remove(mvm, vif);
1563 if (vif->type == NL80211_IFTYPE_MONITOR)
1564 mvm->monitor_on = false;
1567 mutex_unlock(&mvm->mutex);
1570 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1575 struct iwl_mvm_mc_iter_data {
1576 struct iwl_mvm *mvm;
1580 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1581 struct ieee80211_vif *vif)
1583 struct iwl_mvm_mc_iter_data *data = _data;
1584 struct iwl_mvm *mvm = data->mvm;
1585 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1586 struct iwl_host_cmd hcmd = {
1587 .id = MCAST_FILTER_CMD,
1589 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1593 /* if we don't have free ports, mcast frames will be dropped */
1594 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1597 if (vif->type != NL80211_IFTYPE_STATION ||
1598 !vif->bss_conf.assoc)
1601 cmd->port_id = data->port_id++;
1602 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1603 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1608 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1610 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1613 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1615 struct iwl_mvm_mc_iter_data iter_data = {
1619 lockdep_assert_held(&mvm->mutex);
1621 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1624 ieee80211_iterate_active_interfaces_atomic(
1625 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1626 iwl_mvm_mc_iface_iterator, &iter_data);
1629 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1630 struct netdev_hw_addr_list *mc_list)
1632 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1633 struct iwl_mcast_filter_cmd *cmd;
1634 struct netdev_hw_addr *addr;
1639 addr_count = netdev_hw_addr_list_count(mc_list);
1640 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1641 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1645 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1646 cmd = kzalloc(len, GFP_ATOMIC);
1652 return (u64)(unsigned long)cmd;
1655 netdev_hw_addr_list_for_each(addr, mc_list) {
1656 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1657 cmd->count, addr->addr);
1658 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1659 addr->addr, ETH_ALEN);
1663 return (u64)(unsigned long)cmd;
1666 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1667 unsigned int changed_flags,
1668 unsigned int *total_flags,
1671 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1672 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1674 mutex_lock(&mvm->mutex);
1676 /* replace previous configuration */
1677 kfree(mvm->mcast_filter_cmd);
1678 mvm->mcast_filter_cmd = cmd;
1683 if (changed_flags & FIF_ALLMULTI)
1684 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1689 iwl_mvm_recalc_multicast(mvm);
1691 mutex_unlock(&mvm->mutex);
1695 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1696 struct ieee80211_vif *vif,
1697 unsigned int filter_flags,
1698 unsigned int changed_flags)
1700 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1702 /* We support only filter for probe requests */
1703 if (!(changed_flags & FIF_PROBE_REQ))
1706 /* Supported only for p2p client interfaces */
1707 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1711 mutex_lock(&mvm->mutex);
1712 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1713 mutex_unlock(&mvm->mutex);
1716 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1717 struct iwl_bcast_iter_data {
1718 struct iwl_mvm *mvm;
1719 struct iwl_bcast_filter_cmd *cmd;
1724 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1725 const struct iwl_fw_bcast_filter *in_filter,
1726 struct iwl_fw_bcast_filter *out_filter)
1728 struct iwl_fw_bcast_filter_attr *attr;
1731 memcpy(out_filter, in_filter, sizeof(*out_filter));
1733 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1734 attr = &out_filter->attrs[i];
1739 switch (attr->reserved1) {
1740 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1741 if (vif->bss_conf.arp_addr_cnt != 1) {
1746 attr->val = vif->bss_conf.arp_addr_list[0];
1748 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1749 attr->val = *(__be32 *)&vif->addr[2];
1754 attr->reserved1 = 0;
1755 out_filter->num_attrs++;
1759 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1760 struct ieee80211_vif *vif)
1762 struct iwl_bcast_iter_data *data = _data;
1763 struct iwl_mvm *mvm = data->mvm;
1764 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1765 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1766 struct iwl_fw_bcast_mac *bcast_mac;
1769 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1772 bcast_mac = &cmd->macs[mvmvif->id];
1775 * enable filtering only for associated stations, but not for P2P
1778 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1779 !vif->bss_conf.assoc)
1782 bcast_mac->default_discard = 1;
1784 /* copy all configured filters */
1785 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1787 * Make sure we don't exceed our filters limit.
1788 * if there is still a valid filter to be configured,
1789 * be on the safe side and just allow bcast for this mac.
1791 if (WARN_ON_ONCE(data->current_filter >=
1792 ARRAY_SIZE(cmd->filters))) {
1793 bcast_mac->default_discard = 0;
1794 bcast_mac->attached_filters = 0;
1798 iwl_mvm_set_bcast_filter(vif,
1799 &mvm->bcast_filters[i],
1800 &cmd->filters[data->current_filter]);
1802 /* skip current filter if it contains no attributes */
1803 if (!cmd->filters[data->current_filter].num_attrs)
1806 /* attach the filter to current mac */
1807 bcast_mac->attached_filters |=
1808 cpu_to_le16(BIT(data->current_filter));
1810 data->current_filter++;
1814 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1815 struct iwl_bcast_filter_cmd *cmd)
1817 struct iwl_bcast_iter_data iter_data = {
1822 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1825 memset(cmd, 0, sizeof(*cmd));
1826 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1827 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1829 #ifdef CONFIG_IWLWIFI_DEBUGFS
1830 /* use debugfs filters/macs if override is configured */
1831 if (mvm->dbgfs_bcast_filtering.override) {
1832 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1833 sizeof(cmd->filters));
1834 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1840 /* if no filters are configured, do nothing */
1841 if (!mvm->bcast_filters)
1844 /* configure and attach these filters for each associated sta vif */
1845 ieee80211_iterate_active_interfaces(
1846 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1847 iwl_mvm_bcast_filter_iterator, &iter_data);
1852 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1854 struct iwl_bcast_filter_cmd cmd;
1856 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1859 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1862 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1866 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1872 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1873 struct ieee80211_vif *vif)
1875 struct iwl_mu_group_mgmt_cmd cmd = {};
1877 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1878 WLAN_MEMBERSHIP_LEN);
1879 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1880 WLAN_USER_POSITION_LEN);
1882 return iwl_mvm_send_cmd_pdu(mvm,
1883 WIDE_ID(DATA_PATH_GROUP,
1884 UPDATE_MU_GROUPS_CMD),
1885 0, sizeof(cmd), &cmd);
1888 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1889 struct ieee80211_vif *vif)
1891 if (vif->mu_mimo_owner) {
1892 struct iwl_mu_group_mgmt_notif *notif = _data;
1895 * MU-MIMO Group Id action frame is little endian. We treat
1896 * the data received from firmware as if it came from the
1897 * action frame, so no conversion is needed.
1899 ieee80211_update_mu_groups(vif,
1900 (u8 *)¬if->membership_status,
1901 (u8 *)¬if->user_position);
1905 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1906 struct iwl_rx_cmd_buffer *rxb)
1908 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1909 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1911 ieee80211_iterate_active_interfaces_atomic(
1912 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1913 iwl_mvm_mu_mimo_iface_iterator, notif);
1916 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1918 u8 byte_num = ppe_pos_bit / 8;
1919 u8 bit_num = ppe_pos_bit % 8;
1924 return (ppe[byte_num] >> bit_num) &
1925 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1928 * If bit_num > 5, we have to combine bits with next byte.
1929 * Calculate how many bits we need to take from current byte (called
1930 * here "residue_bits"), and add them to bits from next byte.
1933 residue_bits = 8 - bit_num;
1935 res = (ppe[byte_num + 1] &
1936 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1938 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1943 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1944 struct ieee80211_vif *vif, u8 sta_id)
1946 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1947 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
1949 .tid_limit = IWL_MAX_TID_COUNT,
1950 .bss_color = vif->bss_conf.bss_color,
1951 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
1952 .frame_time_rts_th =
1953 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
1955 struct ieee80211_sta *sta;
1961 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
1964 WARN(1, "Can't find STA to configure HE\n");
1968 if (!sta->he_cap.has_he) {
1976 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
1977 IEEE80211_HE_MAC_CAP0_HTC_HE)
1978 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
1979 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
1980 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
1981 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
1982 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
1984 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
1985 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
1986 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
1987 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
1990 sta_ctxt_cmd.htc_flags |=
1991 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
1992 else if (link_adap == 3)
1993 sta_ctxt_cmd.htc_flags |=
1994 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
1996 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
1997 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
1998 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
1999 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2000 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2001 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2002 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2004 /* If PPE Thresholds exist, parse them into a FW-familiar format */
2005 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2006 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2007 u8 nss = (sta->he_cap.ppe_thres[0] &
2008 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2009 u8 ru_index_bitmap =
2010 (sta->he_cap.ppe_thres[0] &
2011 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2012 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2013 u8 *ppe = &sta->he_cap.ppe_thres[0];
2014 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2017 * FW currently supports only nss == MAX_HE_SUPP_NSS
2019 * If nss > MAX: we can ignore values we don't support
2020 * If nss < MAX: we can set zeros in other streams
2022 if (nss > MAX_HE_SUPP_NSS) {
2023 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2025 nss = MAX_HE_SUPP_NSS;
2028 for (i = 0; i < nss; i++) {
2029 u8 ru_index_tmp = ru_index_bitmap << 1;
2032 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2034 if (!(ru_index_tmp & 1))
2037 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2038 iwl_mvm_he_get_ppe_val(ppe,
2041 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2042 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2043 iwl_mvm_he_get_ppe_val(ppe,
2046 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2050 flags |= STA_CTXT_HE_PACKET_EXT;
2054 /* Mark MU EDCA as enabled, unless none detected on some AC */
2055 flags |= STA_CTXT_HE_MU_EDCA_CW;
2056 for (i = 0; i < AC_NUM; i++) {
2057 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2058 &mvmvif->queue_params[i].mu_edca_param_rec;
2060 if (!mvmvif->queue_params[i].mu_edca) {
2061 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2065 sta_ctxt_cmd.trig_based_txf[i].cwmin =
2066 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2067 sta_ctxt_cmd.trig_based_txf[i].cwmax =
2068 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2069 sta_ctxt_cmd.trig_based_txf[i].aifsn =
2070 cpu_to_le16(mu_edca->aifsn);
2071 sta_ctxt_cmd.trig_based_txf[i].mu_time =
2072 cpu_to_le16(mu_edca->mu_edca_timer);
2075 if (vif->bss_conf.multi_sta_back_32bit)
2076 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2078 if (vif->bss_conf.ack_enabled)
2079 flags |= STA_CTXT_HE_ACK_ENABLED;
2081 if (vif->bss_conf.uora_exists) {
2082 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2084 sta_ctxt_cmd.rand_alloc_ecwmin =
2085 vif->bss_conf.uora_ocw_range & 0x7;
2086 sta_ctxt_cmd.rand_alloc_ecwmax =
2087 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2090 /* TODO: support Multi BSSID IE */
2092 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2094 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2095 DATA_PATH_GROUP, 0),
2096 0, sizeof(sta_ctxt_cmd), &sta_ctxt_cmd))
2097 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2100 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2101 struct ieee80211_vif *vif,
2102 struct ieee80211_bss_conf *bss_conf,
2105 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2109 * Re-calculate the tsf id, as the master-slave relations depend on the
2110 * beacon interval, which was not known when the station interface was
2113 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2114 if (vif->bss_conf.he_support &&
2115 !iwlwifi_mod_params.disable_11ax)
2116 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2118 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2122 * If we're not associated yet, take the (new) BSSID before associating
2123 * so the firmware knows. If we're already associated, then use the old
2124 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2125 * branch for disassociation below.
2127 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2128 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2130 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2132 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2134 /* after sending it once, adopt mac80211 data */
2135 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2136 mvmvif->associated = bss_conf->assoc;
2138 if (changes & BSS_CHANGED_ASSOC) {
2139 if (bss_conf->assoc) {
2140 /* clear statistics to get clean beacon counter */
2141 iwl_mvm_request_statistics(mvm, true);
2142 memset(&mvmvif->beacon_stats, 0,
2143 sizeof(mvmvif->beacon_stats));
2145 /* add quota for this interface */
2146 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2148 IWL_ERR(mvm, "failed to update quotas\n");
2152 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2155 * If we're restarting then the firmware will
2156 * obviously have lost synchronisation with
2157 * the AP. It will attempt to synchronise by
2158 * itself, but we can make it more reliable by
2159 * scheduling a session protection time event.
2161 * The firmware needs to receive a beacon to
2162 * catch up with synchronisation, use 110% of
2163 * the beacon interval.
2165 * Set a large maximum delay to allow for more
2166 * than a single interface.
2168 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2169 iwl_mvm_protect_session(mvm, vif, dur, dur,
2173 iwl_mvm_sf_update(mvm, vif, false);
2174 iwl_mvm_power_vif_assoc(mvm, vif);
2176 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
2177 iwl_mvm_update_smps(mvm, vif,
2178 IWL_MVM_SMPS_REQ_PROT,
2179 IEEE80211_SMPS_DYNAMIC);
2181 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2183 * If update fails - SF might be running in associated
2184 * mode while disassociated - which is forbidden.
2186 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
2187 "Failed to update SF upon disassociation\n");
2190 * If we get an assert during the connection (after the
2191 * station has been added, but before the vif is set
2192 * to associated), mac80211 will re-add the station and
2193 * then configure the vif. Since the vif is not
2194 * associated, we would remove the station here and
2195 * this would fail the recovery.
2197 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2200 * Remove AP station now that
2201 * the MAC is unassoc
2203 ret = iwl_mvm_rm_sta_id(mvm, vif,
2207 "failed to remove AP station\n");
2209 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2210 mvm->d0i3_ap_sta_id =
2211 IWL_MVM_INVALID_STA;
2212 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2215 /* remove quota for this interface */
2216 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2218 IWL_ERR(mvm, "failed to update quotas\n");
2221 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2223 /* this will take the cleared BSSID from bss_conf */
2224 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2227 "failed to update MAC %pM (clear after unassoc)\n",
2232 * The firmware tracks the MU-MIMO group on its own.
2233 * However, on HW restart we should restore this data.
2235 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2236 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2237 ret = iwl_mvm_update_mu_groups(mvm, vif);
2240 "failed to update VHT MU_MIMO groups\n");
2243 iwl_mvm_recalc_multicast(mvm);
2244 iwl_mvm_configure_bcast_filter(mvm);
2246 /* reset rssi values */
2247 mvmvif->bf_data.ave_beacon_signal = 0;
2249 iwl_mvm_bt_coex_vif_change(mvm);
2250 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2251 IEEE80211_SMPS_AUTOMATIC);
2252 if (fw_has_capa(&mvm->fw->ucode_capa,
2253 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2254 iwl_mvm_config_scan(mvm);
2257 if (changes & BSS_CHANGED_BEACON_INFO) {
2259 * We received a beacon from the associated AP so
2260 * remove the session protection.
2262 iwl_mvm_stop_session_protection(mvm, vif);
2264 iwl_mvm_sf_update(mvm, vif, false);
2265 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2268 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2270 * Send power command on every beacon change,
2271 * because we may have not enabled beacon abort yet.
2273 BSS_CHANGED_BEACON_INFO)) {
2274 ret = iwl_mvm_power_update_mac(mvm);
2276 IWL_ERR(mvm, "failed to update power mode\n");
2279 if (changes & BSS_CHANGED_TXPOWER) {
2280 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2282 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2285 if (changes & BSS_CHANGED_CQM) {
2286 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2287 /* reset cqm events tracking */
2288 mvmvif->bf_data.last_cqm_event = 0;
2289 if (mvmvif->bf_data.bf_enabled) {
2290 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2293 "failed to update CQM thresholds\n");
2297 if (changes & BSS_CHANGED_ARP_FILTER) {
2298 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2299 iwl_mvm_configure_bcast_filter(mvm);
2303 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2304 struct ieee80211_vif *vif)
2306 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2307 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2311 * iwl_mvm_mac_ctxt_add() might read directly from the device
2312 * (the system time), so make sure it is available.
2314 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2318 mutex_lock(&mvm->mutex);
2320 /* Send the beacon template */
2321 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2326 * Re-calculate the tsf id, as the master-slave relations depend on the
2327 * beacon interval, which was not known when the AP interface was added.
2329 if (vif->type == NL80211_IFTYPE_AP)
2330 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2332 mvmvif->ap_assoc_sta_count = 0;
2334 /* Add the mac context */
2335 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2339 /* Perform the binding */
2340 ret = iwl_mvm_binding_add_vif(mvm, vif);
2345 * This is not very nice, but the simplest:
2346 * For older FWs adding the mcast sta before the bcast station may
2347 * cause assert 0x2b00.
2348 * This is fixed in later FW so make the order of removal depend on
2351 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2352 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2356 * Send the bcast station. At this stage the TBTT and DTIM time
2357 * events are added and applied to the scheduler
2359 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2361 iwl_mvm_rm_mcast_sta(mvm, vif);
2366 * Send the bcast station. At this stage the TBTT and DTIM time
2367 * events are added and applied to the scheduler
2369 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2372 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2374 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2379 /* must be set before quota calculations */
2380 mvmvif->ap_ibss_active = true;
2382 /* power updated needs to be done before quotas */
2383 iwl_mvm_power_update_mac(mvm);
2385 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2387 goto out_quota_failed;
2389 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2390 if (vif->p2p && mvm->p2p_device_vif)
2391 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2393 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2395 iwl_mvm_bt_coex_vif_change(mvm);
2397 /* we don't support TDLS during DCM */
2398 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2399 iwl_mvm_teardown_tdls_peers(mvm);
2404 iwl_mvm_power_update_mac(mvm);
2405 mvmvif->ap_ibss_active = false;
2406 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2407 iwl_mvm_rm_mcast_sta(mvm, vif);
2409 iwl_mvm_binding_remove_vif(mvm, vif);
2411 iwl_mvm_mac_ctxt_remove(mvm, vif);
2413 mutex_unlock(&mvm->mutex);
2414 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2418 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2419 struct ieee80211_vif *vif)
2421 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2422 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2424 iwl_mvm_prepare_mac_removal(mvm, vif);
2426 mutex_lock(&mvm->mutex);
2428 /* Handle AP stop while in CSA */
2429 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2430 iwl_mvm_remove_time_event(mvm, mvmvif,
2431 &mvmvif->time_event_data);
2432 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2433 mvmvif->csa_countdown = false;
2436 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2437 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2438 mvm->csa_tx_block_bcn_timeout = 0;
2441 mvmvif->ap_ibss_active = false;
2442 mvm->ap_last_beacon_gp2 = 0;
2444 iwl_mvm_bt_coex_vif_change(mvm);
2446 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2448 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2449 if (vif->p2p && mvm->p2p_device_vif)
2450 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2452 iwl_mvm_update_quotas(mvm, false, NULL);
2455 * This is not very nice, but the simplest:
2456 * For older FWs removing the mcast sta before the bcast station may
2457 * cause assert 0x2b00.
2458 * This is fixed in later FW (which will stop beaconing when removing
2460 * So make the order of removal depend on the TLV
2462 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2463 iwl_mvm_rm_mcast_sta(mvm, vif);
2464 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2465 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2466 iwl_mvm_rm_mcast_sta(mvm, vif);
2467 iwl_mvm_binding_remove_vif(mvm, vif);
2469 iwl_mvm_power_update_mac(mvm);
2471 iwl_mvm_mac_ctxt_remove(mvm, vif);
2473 kfree(mvmvif->ap_wep_key);
2474 mvmvif->ap_wep_key = NULL;
2476 mutex_unlock(&mvm->mutex);
2480 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2481 struct ieee80211_vif *vif,
2482 struct ieee80211_bss_conf *bss_conf,
2485 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2487 /* Changes will be applied when the AP/IBSS is started */
2488 if (!mvmvif->ap_ibss_active)
2491 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2492 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2493 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2494 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2496 /* Need to send a new beacon template to the FW */
2497 if (changes & BSS_CHANGED_BEACON &&
2498 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2499 IWL_WARN(mvm, "Failed updating beacon data\n");
2501 if (changes & BSS_CHANGED_TXPOWER) {
2502 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2504 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2508 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2509 struct ieee80211_vif *vif,
2510 struct ieee80211_bss_conf *bss_conf,
2513 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2516 * iwl_mvm_bss_info_changed_station() might call
2517 * iwl_mvm_protect_session(), which reads directly from
2518 * the device (the system time), so make sure it is available.
2520 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2523 mutex_lock(&mvm->mutex);
2525 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2526 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2528 switch (vif->type) {
2529 case NL80211_IFTYPE_STATION:
2530 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2532 case NL80211_IFTYPE_AP:
2533 case NL80211_IFTYPE_ADHOC:
2534 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2536 case NL80211_IFTYPE_MONITOR:
2537 if (changes & BSS_CHANGED_MU_GROUPS)
2538 iwl_mvm_update_mu_groups(mvm, vif);
2541 /* shouldn't happen */
2545 mutex_unlock(&mvm->mutex);
2546 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2549 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2550 struct ieee80211_vif *vif,
2551 struct ieee80211_scan_request *hw_req)
2553 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2556 if (hw_req->req.n_channels == 0 ||
2557 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2560 mutex_lock(&mvm->mutex);
2561 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2562 mutex_unlock(&mvm->mutex);
2567 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2568 struct ieee80211_vif *vif)
2570 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2572 mutex_lock(&mvm->mutex);
2574 /* Due to a race condition, it's possible that mac80211 asks
2575 * us to stop a hw_scan when it's already stopped. This can
2576 * happen, for instance, if we stopped the scan ourselves,
2577 * called ieee80211_scan_completed() and the userspace called
2578 * cancel scan scan before ieee80211_scan_work() could run.
2579 * To handle that, simply return if the scan is not running.
2581 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2582 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2584 mutex_unlock(&mvm->mutex);
2588 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2589 struct ieee80211_sta *sta, u16 tids,
2591 enum ieee80211_frame_release_type reason,
2594 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2596 /* Called when we need to transmit (a) frame(s) from mac80211 */
2598 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2599 tids, more_data, false);
2603 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2604 struct ieee80211_sta *sta, u16 tids,
2606 enum ieee80211_frame_release_type reason,
2609 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2611 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2613 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2614 tids, more_data, true);
2617 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2618 enum sta_notify_cmd cmd,
2619 struct ieee80211_sta *sta)
2621 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2622 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2623 unsigned long txqs = 0, tids = 0;
2627 * If we have TVQM then we get too high queue numbers - luckily
2628 * we really shouldn't get here with that because such hardware
2629 * should have firmware supporting buffer station offload.
2631 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2634 spin_lock_bh(&mvmsta->lock);
2635 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2636 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2638 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2641 __set_bit(tid_data->txq_id, &txqs);
2643 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2646 __set_bit(tid, &tids);
2650 case STA_NOTIFY_SLEEP:
2651 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2652 ieee80211_sta_set_buffered(sta, tid, true);
2655 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2657 * The fw updates the STA to be asleep. Tx packets on the Tx
2658 * queues to this station will not be transmitted. The fw will
2659 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2662 case STA_NOTIFY_AWAKE:
2663 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2667 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2668 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2673 spin_unlock_bh(&mvmsta->lock);
2676 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2677 struct ieee80211_vif *vif,
2678 enum sta_notify_cmd cmd,
2679 struct ieee80211_sta *sta)
2681 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2684 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2686 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2687 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2688 struct ieee80211_sta *sta;
2689 struct iwl_mvm_sta *mvmsta;
2690 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2692 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2696 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2697 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2702 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2705 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2710 if (mvmsta->sleeping != sleeping) {
2711 mvmsta->sleeping = sleeping;
2712 __iwl_mvm_mac_sta_notify(mvm->hw,
2713 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2715 ieee80211_sta_ps_transition(sta, sleeping);
2719 switch (notif->type) {
2720 case IWL_MVM_PM_EVENT_AWAKE:
2721 case IWL_MVM_PM_EVENT_ASLEEP:
2723 case IWL_MVM_PM_EVENT_UAPSD:
2724 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2726 case IWL_MVM_PM_EVENT_PS_POLL:
2727 ieee80211_sta_pspoll(sta);
2737 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2738 struct ieee80211_vif *vif,
2739 struct ieee80211_sta *sta)
2741 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2742 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2745 * This is called before mac80211 does RCU synchronisation,
2746 * so here we already invalidate our internal RCU-protected
2747 * station pointer. The rest of the code will thus no longer
2748 * be able to find the station this way, and we don't rely
2749 * on further RCU synchronisation after the sta_state()
2750 * callback deleted the station.
2752 mutex_lock(&mvm->mutex);
2753 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2754 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2757 mutex_unlock(&mvm->mutex);
2760 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2765 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2766 struct iwl_mvm_tcm_mac *mdata;
2768 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2769 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2770 mdata->opened_rx_ba_sessions = false;
2773 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2776 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2777 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2782 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2783 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2787 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2788 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2789 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2794 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2798 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2799 struct ieee80211_vif *vif, u8 *peer_addr,
2800 enum nl80211_tdls_operation action)
2802 struct iwl_fw_dbg_trigger_tlv *trig;
2803 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2805 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS))
2808 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS);
2809 tdls_trig = (void *)trig->data;
2810 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
2811 ieee80211_vif_to_wdev(vif), trig))
2814 if (!(tdls_trig->action_bitmap & BIT(action)))
2817 if (tdls_trig->peer_mode &&
2818 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2821 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2822 "TDLS event occurred, peer %pM, action %d",
2826 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2827 struct iwl_mvm_sta *mvm_sta)
2829 struct iwl_mvm_tid_data *tid_data;
2830 struct sk_buff *skb;
2833 spin_lock_bh(&mvm_sta->lock);
2834 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2835 tid_data = &mvm_sta->tid_data[i];
2837 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2838 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2841 * The first deferred frame should've stopped the MAC
2842 * queues, so we should never get a second deferred
2843 * frame for the RA/TID.
2845 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
2846 ieee80211_free_txskb(mvm->hw, skb);
2849 spin_unlock_bh(&mvm_sta->lock);
2852 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2853 struct ieee80211_vif *vif,
2854 struct ieee80211_sta *sta,
2855 enum ieee80211_sta_state old_state,
2856 enum ieee80211_sta_state new_state)
2858 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2859 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2860 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2863 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2864 sta->addr, old_state, new_state);
2866 /* this would be a mac80211 bug ... but don't crash */
2867 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2871 * If we are in a STA removal flow and in DQA mode:
2873 * This is after the sync_rcu part, so the queues have already been
2874 * flushed. No more TXs on their way in mac80211's path, and no more in
2876 * Also, we won't be getting any new TX frames for this station.
2877 * What we might have are deferred TX frames that need to be taken care
2880 * Drop any still-queued deferred-frame before removing the STA, and
2881 * make sure the worker is no longer handling frames for this STA.
2883 if (old_state == IEEE80211_STA_NONE &&
2884 new_state == IEEE80211_STA_NOTEXIST) {
2885 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2886 flush_work(&mvm->add_stream_wk);
2889 * No need to make sure deferred TX indication is off since the
2890 * worker will already remove it if it was on
2894 mutex_lock(&mvm->mutex);
2895 /* track whether or not the station is associated */
2896 mvm_sta->sta_state = new_state;
2898 if (old_state == IEEE80211_STA_NOTEXIST &&
2899 new_state == IEEE80211_STA_NONE) {
2901 * Firmware bug - it'll crash if the beacon interval is less
2902 * than 16. We can't avoid connecting at all, so refuse the
2903 * station state change, this will cause mac80211 to abandon
2904 * attempts to connect to this AP, and eventually wpa_s will
2905 * blacklist the AP...
2907 if (vif->type == NL80211_IFTYPE_STATION &&
2908 vif->bss_conf.beacon_int < 16) {
2910 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2911 sta->addr, vif->bss_conf.beacon_int);
2918 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2919 IWL_MVM_TDLS_STA_COUNT ||
2920 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2921 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2926 ret = iwl_mvm_add_sta(mvm, vif, sta);
2927 if (sta->tdls && ret == 0) {
2928 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2929 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2930 NL80211_TDLS_SETUP);
2932 } else if (old_state == IEEE80211_STA_NONE &&
2933 new_state == IEEE80211_STA_AUTH) {
2935 * EBS may be disabled due to previous failures reported by FW.
2936 * Reset EBS status here assuming environment has been changed.
2938 mvm->last_ebs_successful = true;
2939 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2941 } else if (old_state == IEEE80211_STA_AUTH &&
2942 new_state == IEEE80211_STA_ASSOC) {
2943 if (vif->type == NL80211_IFTYPE_AP) {
2944 mvmvif->ap_assoc_sta_count++;
2945 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2948 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2950 ret = iwl_mvm_update_sta(mvm, vif, sta);
2951 } else if (old_state == IEEE80211_STA_ASSOC &&
2952 new_state == IEEE80211_STA_AUTHORIZED) {
2954 /* we don't support TDLS during DCM */
2955 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2956 iwl_mvm_teardown_tdls_peers(mvm);
2959 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2960 NL80211_TDLS_ENABLE_LINK);
2962 /* enable beacon filtering */
2963 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2965 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2968 /* if wep is used, need to set the key for the station now */
2969 if (vif->type == NL80211_IFTYPE_AP && mvmvif->ap_wep_key)
2970 ret = iwl_mvm_set_sta_key(mvm, vif, sta,
2972 STA_KEY_IDX_INVALID);
2975 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2976 new_state == IEEE80211_STA_ASSOC) {
2977 /* disable beacon filtering */
2978 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2980 } else if (old_state == IEEE80211_STA_ASSOC &&
2981 new_state == IEEE80211_STA_AUTH) {
2982 if (vif->type == NL80211_IFTYPE_AP) {
2983 mvmvif->ap_assoc_sta_count--;
2984 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2987 } else if (old_state == IEEE80211_STA_AUTH &&
2988 new_state == IEEE80211_STA_NONE) {
2990 } else if (old_state == IEEE80211_STA_NONE &&
2991 new_state == IEEE80211_STA_NOTEXIST) {
2992 ret = iwl_mvm_rm_sta(mvm, vif, sta);
2994 iwl_mvm_recalc_tdls_state(mvm, vif, false);
2995 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2996 NL80211_TDLS_DISABLE_LINK);
3002 mutex_unlock(&mvm->mutex);
3004 if (sta->tdls && ret == 0) {
3005 if (old_state == IEEE80211_STA_NOTEXIST &&
3006 new_state == IEEE80211_STA_NONE)
3007 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3008 else if (old_state == IEEE80211_STA_NONE &&
3009 new_state == IEEE80211_STA_NOTEXIST)
3010 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3016 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3018 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3020 mvm->rts_threshold = value;
3025 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3026 struct ieee80211_vif *vif,
3027 struct ieee80211_sta *sta, u32 changed)
3029 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3031 if (vif->type == NL80211_IFTYPE_STATION &&
3032 changed & IEEE80211_RC_NSS_CHANGED)
3033 iwl_mvm_sf_update(mvm, vif, false);
3036 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3037 struct ieee80211_vif *vif, u16 ac,
3038 const struct ieee80211_tx_queue_params *params)
3040 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3041 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3043 mvmvif->queue_params[ac] = *params;
3046 * No need to update right away, we'll get BSS_CHANGED_QOS
3047 * The exception is P2P_DEVICE interface which needs immediate update.
3049 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3052 mutex_lock(&mvm->mutex);
3053 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3054 mutex_unlock(&mvm->mutex);
3060 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3061 struct ieee80211_vif *vif,
3064 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3065 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3066 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3069 * iwl_mvm_protect_session() reads directly from the device
3070 * (the system time), so make sure it is available.
3072 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
3075 if (req_duration > duration)
3076 duration = req_duration;
3078 mutex_lock(&mvm->mutex);
3079 /* Try really hard to protect the session and hear a beacon */
3080 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
3081 mutex_unlock(&mvm->mutex);
3083 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
3086 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3087 struct ieee80211_vif *vif,
3088 struct cfg80211_sched_scan_request *req,
3089 struct ieee80211_scan_ies *ies)
3091 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3095 mutex_lock(&mvm->mutex);
3097 if (!vif->bss_conf.idle) {
3102 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3105 mutex_unlock(&mvm->mutex);
3109 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3110 struct ieee80211_vif *vif)
3112 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3115 mutex_lock(&mvm->mutex);
3117 /* Due to a race condition, it's possible that mac80211 asks
3118 * us to stop a sched_scan when it's already stopped. This
3119 * can happen, for instance, if we stopped the scan ourselves,
3120 * called ieee80211_sched_scan_stopped() and the userspace called
3121 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3122 * could run. To handle this, simply return if the scan is
3125 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3126 mutex_unlock(&mvm->mutex);
3130 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3131 mutex_unlock(&mvm->mutex);
3132 iwl_mvm_wait_for_async_handlers(mvm);
3137 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3138 enum set_key_cmd cmd,
3139 struct ieee80211_vif *vif,
3140 struct ieee80211_sta *sta,
3141 struct ieee80211_key_conf *key)
3143 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3144 struct iwl_mvm_sta *mvmsta;
3145 struct iwl_mvm_key_pn *ptk_pn;
3146 int keyidx = key->keyidx;
3150 if (iwlwifi_mod_params.swcrypto) {
3151 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
3155 switch (key->cipher) {
3156 case WLAN_CIPHER_SUITE_TKIP:
3157 if (!mvm->trans->cfg->gen2) {
3158 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3159 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3160 } else if (vif->type == NL80211_IFTYPE_STATION) {
3161 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3163 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3167 case WLAN_CIPHER_SUITE_CCMP:
3168 case WLAN_CIPHER_SUITE_GCMP:
3169 case WLAN_CIPHER_SUITE_GCMP_256:
3170 if (!iwl_mvm_has_new_tx_api(mvm))
3171 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3173 case WLAN_CIPHER_SUITE_AES_CMAC:
3174 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3175 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3176 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3178 case WLAN_CIPHER_SUITE_WEP40:
3179 case WLAN_CIPHER_SUITE_WEP104:
3180 if (vif->type == NL80211_IFTYPE_AP) {
3181 struct iwl_mvm_vif *mvmvif =
3182 iwl_mvm_vif_from_mac80211(vif);
3184 mvmvif->ap_wep_key = kmemdup(key,
3185 sizeof(*key) + key->keylen,
3187 if (!mvmvif->ap_wep_key)
3191 if (vif->type != NL80211_IFTYPE_STATION)
3195 /* currently FW supports only one optional cipher scheme */
3196 if (hw->n_cipher_schemes &&
3197 hw->cipher_schemes->cipher == key->cipher)
3198 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3203 mutex_lock(&mvm->mutex);
3207 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3208 vif->type == NL80211_IFTYPE_AP) && !sta) {
3210 * GTK on AP interface is a TX-only key, return 0;
3211 * on IBSS they're per-station and because we're lazy
3212 * we don't support them for RX, so do the same.
3213 * CMAC/GMAC in AP/IBSS modes must be done in software.
3215 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3216 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3217 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3222 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3223 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3224 !iwl_mvm_has_new_tx_api(mvm)) {
3225 key->hw_key_idx = STA_KEY_IDX_INVALID;
3230 /* During FW restart, in order to restore the state as it was,
3231 * don't try to reprogram keys we previously failed for.
3233 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3234 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3235 IWL_DEBUG_MAC80211(mvm,
3236 "skip invalid idx key programming during restart\n");
3241 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3242 sta && iwl_mvm_has_new_rx_api(mvm) &&
3243 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3244 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3245 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3246 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3247 struct ieee80211_key_seq seq;
3250 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3251 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3252 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3253 mvm->trans->num_rx_queues),
3260 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3261 ieee80211_get_key_rx_seq(key, tid, &seq);
3262 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3263 memcpy(ptk_pn->q[q].pn[tid],
3265 IEEE80211_CCMP_PN_LEN);
3268 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3271 /* in HW restart reuse the index, otherwise request a new one */
3272 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3273 key_offset = key->hw_key_idx;
3275 key_offset = STA_KEY_IDX_INVALID;
3277 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3278 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3280 IWL_WARN(mvm, "set key failed\n");
3282 * can't add key for RX, but we don't need it
3283 * in the device for TX so still return 0
3285 key->hw_key_idx = STA_KEY_IDX_INVALID;
3291 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3296 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3297 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3298 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3299 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3300 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3301 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3302 ptk_pn = rcu_dereference_protected(
3303 mvmsta->ptk_pn[keyidx],
3304 lockdep_is_held(&mvm->mutex));
3305 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3307 kfree_rcu(ptk_pn, rcu_head);
3310 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3311 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3317 mutex_unlock(&mvm->mutex);
3321 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3322 struct ieee80211_vif *vif,
3323 struct ieee80211_key_conf *keyconf,
3324 struct ieee80211_sta *sta,
3325 u32 iv32, u16 *phase1key)
3327 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3329 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3332 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3336 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3337 struct iwl_rx_packet *pkt, void *data)
3339 struct iwl_mvm *mvm =
3340 container_of(notif_wait, struct iwl_mvm, notif_wait);
3341 struct iwl_hs20_roc_res *resp;
3342 int resp_len = iwl_rx_packet_payload_len(pkt);
3343 struct iwl_mvm_time_event_data *te_data = data;
3345 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3348 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3349 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3353 resp = (void *)pkt->data;
3356 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3357 resp->status, resp->event_unique_id);
3359 te_data->uid = le32_to_cpu(resp->event_unique_id);
3360 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3363 spin_lock_bh(&mvm->time_event_lock);
3364 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3365 spin_unlock_bh(&mvm->time_event_lock);
3370 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3371 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3372 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3373 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3374 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3375 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3376 struct ieee80211_channel *channel,
3377 struct ieee80211_vif *vif,
3380 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3381 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3382 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3383 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3384 struct iwl_notification_wait wait_time_event;
3385 u32 dtim_interval = vif->bss_conf.dtim_period *
3386 vif->bss_conf.beacon_int;
3388 struct iwl_hs20_roc_req aux_roc_req = {
3389 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3391 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3392 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3393 /* Set the channel info data */
3394 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3395 PHY_BAND_24 : PHY_BAND_5,
3396 .channel_info.channel = channel->hw_value,
3397 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3398 /* Set the time and duration */
3399 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3402 delay = AUX_ROC_MIN_DELAY;
3403 req_dur = MSEC_TO_TU(duration);
3406 * If we are associated we want the delay time to be at least one
3407 * dtim interval so that the FW can wait until after the DTIM and
3408 * then start the time event, this will potentially allow us to
3409 * remain off-channel for the max duration.
3410 * Since we want to use almost a whole dtim interval we would also
3411 * like the delay to be for 2-3 dtim intervals, in case there are
3412 * other time events with higher priority.
3414 if (vif->bss_conf.assoc) {
3415 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3416 /* We cannot remain off-channel longer than the DTIM interval */
3417 if (dtim_interval <= req_dur) {
3418 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3419 if (req_dur <= AUX_ROC_MIN_DURATION)
3420 req_dur = dtim_interval -
3421 AUX_ROC_MIN_SAFETY_BUFFER;
3425 aux_roc_req.duration = cpu_to_le32(req_dur);
3426 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3429 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3430 channel->hw_value, req_dur, duration, delay,
3432 /* Set the node address */
3433 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3435 lockdep_assert_held(&mvm->mutex);
3437 spin_lock_bh(&mvm->time_event_lock);
3439 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3440 spin_unlock_bh(&mvm->time_event_lock);
3445 te_data->duration = duration;
3446 te_data->id = HOT_SPOT_CMD;
3448 spin_unlock_bh(&mvm->time_event_lock);
3451 * Use a notification wait, which really just processes the
3452 * command response and doesn't wait for anything, in order
3453 * to be able to process the response and get the UID inside
3454 * the RX path. Using CMD_WANT_SKB doesn't work because it
3455 * stores the buffer and then wakes up this thread, by which
3456 * time another notification (that the time event started)
3457 * might already be processed unsuccessfully.
3459 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3460 time_event_response,
3461 ARRAY_SIZE(time_event_response),
3462 iwl_mvm_rx_aux_roc, te_data);
3464 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3468 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3469 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3473 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3474 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3475 /* should never fail */
3480 spin_lock_bh(&mvm->time_event_lock);
3481 iwl_mvm_te_clear_data(mvm, te_data);
3482 spin_unlock_bh(&mvm->time_event_lock);
3488 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3489 struct ieee80211_vif *vif,
3490 struct ieee80211_channel *channel,
3492 enum ieee80211_roc_type type)
3494 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3495 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3496 struct cfg80211_chan_def chandef;
3497 struct iwl_mvm_phy_ctxt *phy_ctxt;
3500 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3504 * Flush the done work, just in case it's still pending, so that
3505 * the work it does can complete and we can accept new frames.
3507 flush_work(&mvm->roc_done_wk);
3509 mutex_lock(&mvm->mutex);
3511 switch (vif->type) {
3512 case NL80211_IFTYPE_STATION:
3513 if (fw_has_capa(&mvm->fw->ucode_capa,
3514 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3515 /* Use aux roc framework (HS20) */
3516 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3520 IWL_ERR(mvm, "hotspot not supported\n");
3523 case NL80211_IFTYPE_P2P_DEVICE:
3527 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3532 for (i = 0; i < NUM_PHY_CTX; i++) {
3533 phy_ctxt = &mvm->phy_ctxts[i];
3534 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3537 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3539 * Unbind the P2P_DEVICE from the current PHY context,
3540 * and if the PHY context is not used remove it.
3542 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3543 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3546 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3548 /* Bind the P2P_DEVICE to the current PHY Context */
3549 mvmvif->phy_ctxt = phy_ctxt;
3551 ret = iwl_mvm_binding_add_vif(mvm, vif);
3552 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3555 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3556 goto schedule_time_event;
3560 /* Need to update the PHY context only if the ROC channel changed */
3561 if (channel == mvmvif->phy_ctxt->channel)
3562 goto schedule_time_event;
3564 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3567 * Change the PHY context configuration as it is currently referenced
3568 * only by the P2P Device MAC
3570 if (mvmvif->phy_ctxt->ref == 1) {
3571 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3577 * The PHY context is shared with other MACs. Need to remove the
3578 * P2P Device from the binding, allocate an new PHY context and
3579 * create a new binding
3581 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3587 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3590 IWL_ERR(mvm, "Failed to change PHY context\n");
3594 /* Unbind the P2P_DEVICE from the current PHY context */
3595 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3596 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3599 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3601 /* Bind the P2P_DEVICE to the new allocated PHY context */
3602 mvmvif->phy_ctxt = phy_ctxt;
3604 ret = iwl_mvm_binding_add_vif(mvm, vif);
3605 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3608 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3611 schedule_time_event:
3612 /* Schedule the time events */
3613 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3616 mutex_unlock(&mvm->mutex);
3617 IWL_DEBUG_MAC80211(mvm, "leave\n");
3621 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3623 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3625 IWL_DEBUG_MAC80211(mvm, "enter\n");
3627 mutex_lock(&mvm->mutex);
3628 iwl_mvm_stop_roc(mvm);
3629 mutex_unlock(&mvm->mutex);
3631 IWL_DEBUG_MAC80211(mvm, "leave\n");
3635 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3636 struct ieee80211_chanctx_conf *ctx)
3638 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3639 struct iwl_mvm_phy_ctxt *phy_ctxt;
3642 lockdep_assert_held(&mvm->mutex);
3644 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3646 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3652 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3653 ctx->rx_chains_static,
3654 ctx->rx_chains_dynamic);
3656 IWL_ERR(mvm, "Failed to add PHY context\n");
3660 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3661 *phy_ctxt_id = phy_ctxt->id;
3666 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3667 struct ieee80211_chanctx_conf *ctx)
3669 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3672 mutex_lock(&mvm->mutex);
3673 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3674 mutex_unlock(&mvm->mutex);
3679 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3680 struct ieee80211_chanctx_conf *ctx)
3682 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3683 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3685 lockdep_assert_held(&mvm->mutex);
3687 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3690 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3691 struct ieee80211_chanctx_conf *ctx)
3693 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3695 mutex_lock(&mvm->mutex);
3696 __iwl_mvm_remove_chanctx(mvm, ctx);
3697 mutex_unlock(&mvm->mutex);
3700 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3701 struct ieee80211_chanctx_conf *ctx,
3704 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3705 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3706 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3708 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3709 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3710 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3711 IEEE80211_CHANCTX_CHANGE_RADAR |
3712 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3713 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3714 phy_ctxt->ref, changed))
3717 mutex_lock(&mvm->mutex);
3719 /* we are only changing the min_width, may be a noop */
3720 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
3721 if (phy_ctxt->width == ctx->min_def.width)
3724 /* we are just toggling between 20_NOHT and 20 */
3725 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
3726 ctx->min_def.width <= NL80211_CHAN_WIDTH_20)
3730 iwl_mvm_bt_coex_vif_change(mvm);
3731 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3732 ctx->rx_chains_static,
3733 ctx->rx_chains_dynamic);
3736 mutex_unlock(&mvm->mutex);
3739 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3740 struct ieee80211_vif *vif,
3741 struct ieee80211_chanctx_conf *ctx,
3742 bool switching_chanctx)
3744 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3745 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3746 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3749 lockdep_assert_held(&mvm->mutex);
3751 mvmvif->phy_ctxt = phy_ctxt;
3753 switch (vif->type) {
3754 case NL80211_IFTYPE_AP:
3755 /* only needed if we're switching chanctx (i.e. during CSA) */
3756 if (switching_chanctx) {
3757 mvmvif->ap_ibss_active = true;
3760 case NL80211_IFTYPE_ADHOC:
3762 * The AP binding flow is handled as part of the start_ap flow
3763 * (in bss_info_changed), similarly for IBSS.
3767 case NL80211_IFTYPE_STATION:
3768 mvmvif->csa_bcn_pending = false;
3770 case NL80211_IFTYPE_MONITOR:
3771 /* always disable PS when a monitor interface is active */
3772 mvmvif->ps_disabled = true;
3779 ret = iwl_mvm_binding_add_vif(mvm, vif);
3784 * Power state must be updated before quotas,
3785 * otherwise fw will complain.
3787 iwl_mvm_power_update_mac(mvm);
3789 /* Setting the quota at this stage is only required for monitor
3790 * interfaces. For the other types, the bss_info changed flow
3791 * will handle quota settings.
3793 if (vif->type == NL80211_IFTYPE_MONITOR) {
3794 mvmvif->monitor_active = true;
3795 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3797 goto out_remove_binding;
3799 ret = iwl_mvm_add_snif_sta(mvm, vif);
3801 goto out_remove_binding;
3805 /* Handle binding during CSA */
3806 if (vif->type == NL80211_IFTYPE_AP) {
3807 iwl_mvm_update_quotas(mvm, false, NULL);
3808 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3811 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3812 u32 duration = 3 * vif->bss_conf.beacon_int;
3814 /* iwl_mvm_protect_session() reads directly from the
3815 * device (the system time), so make sure it is
3818 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3820 goto out_remove_binding;
3822 /* Protect the session to make sure we hear the first
3823 * beacon on the new channel.
3825 mvmvif->csa_bcn_pending = true;
3826 iwl_mvm_protect_session(mvm, vif, duration, duration,
3827 vif->bss_conf.beacon_int / 2,
3830 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3832 iwl_mvm_update_quotas(mvm, false, NULL);
3838 iwl_mvm_binding_remove_vif(mvm, vif);
3839 iwl_mvm_power_update_mac(mvm);
3842 mvmvif->phy_ctxt = NULL;
3845 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3846 struct ieee80211_vif *vif,
3847 struct ieee80211_chanctx_conf *ctx)
3849 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3852 mutex_lock(&mvm->mutex);
3853 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3854 mutex_unlock(&mvm->mutex);
3859 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3860 struct ieee80211_vif *vif,
3861 struct ieee80211_chanctx_conf *ctx,
3862 bool switching_chanctx)
3864 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3865 struct ieee80211_vif *disabled_vif = NULL;
3867 lockdep_assert_held(&mvm->mutex);
3869 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3871 switch (vif->type) {
3872 case NL80211_IFTYPE_ADHOC:
3874 case NL80211_IFTYPE_MONITOR:
3875 mvmvif->monitor_active = false;
3876 mvmvif->ps_disabled = false;
3877 iwl_mvm_rm_snif_sta(mvm, vif);
3879 case NL80211_IFTYPE_AP:
3880 /* This part is triggered only during CSA */
3881 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3884 mvmvif->csa_countdown = false;
3886 /* Set CS bit on all the stations */
3887 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3889 /* Save blocked iface, the timeout is set on the next beacon */
3890 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3892 mvmvif->ap_ibss_active = false;
3894 case NL80211_IFTYPE_STATION:
3895 if (!switching_chanctx)
3900 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3906 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3907 iwl_mvm_binding_remove_vif(mvm, vif);
3910 mvmvif->phy_ctxt = NULL;
3911 iwl_mvm_power_update_mac(mvm);
3914 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3915 struct ieee80211_vif *vif,
3916 struct ieee80211_chanctx_conf *ctx)
3918 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3920 mutex_lock(&mvm->mutex);
3921 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3922 mutex_unlock(&mvm->mutex);
3926 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3927 struct ieee80211_vif_chanctx_switch *vifs)
3931 mutex_lock(&mvm->mutex);
3932 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3933 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3935 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3937 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3941 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3945 "failed to assign new_ctx during channel switch\n");
3949 /* we don't support TDLS during DCM - can be caused by channel switch */
3950 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3951 iwl_mvm_teardown_tdls_peers(mvm);
3956 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3959 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3960 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3964 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3966 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3973 /* things keep failing, better restart the hw */
3974 iwl_mvm_nic_restart(mvm, false);
3977 mutex_unlock(&mvm->mutex);
3983 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3984 struct ieee80211_vif_chanctx_switch *vifs)
3988 mutex_lock(&mvm->mutex);
3989 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3991 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3995 "failed to assign new_ctx during channel switch\n");
4002 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4004 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4011 /* things keep failing, better restart the hw */
4012 iwl_mvm_nic_restart(mvm, false);
4015 mutex_unlock(&mvm->mutex);
4020 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4021 struct ieee80211_vif_chanctx_switch *vifs,
4023 enum ieee80211_chanctx_switch_mode mode)
4025 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4028 /* we only support a single-vif right now */
4033 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4034 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4036 case CHANCTX_SWMODE_REASSIGN_VIF:
4037 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4047 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4049 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4051 return mvm->ibss_manager;
4054 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4055 struct ieee80211_sta *sta,
4058 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4059 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4061 if (!mvm_sta || !mvm_sta->vif) {
4062 IWL_ERR(mvm, "Station is not associated to a vif\n");
4066 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4069 #ifdef CONFIG_NL80211_TESTMODE
4070 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4071 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4072 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4073 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4076 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4077 struct ieee80211_vif *vif,
4078 void *data, int len)
4080 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4084 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
4089 if (!tb[IWL_MVM_TM_ATTR_CMD])
4092 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4093 case IWL_MVM_TM_CMD_SET_NOA:
4094 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4095 !vif->bss_conf.enable_beacon ||
4096 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4099 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4100 if (noa_duration >= vif->bss_conf.beacon_int)
4103 mvm->noa_duration = noa_duration;
4106 return iwl_mvm_update_quotas(mvm, true, NULL);
4107 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4108 /* must be associated client vif - ignore authorized */
4109 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4110 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4111 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4114 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4115 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4116 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4122 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4123 struct ieee80211_vif *vif,
4124 void *data, int len)
4126 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4129 mutex_lock(&mvm->mutex);
4130 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4131 mutex_unlock(&mvm->mutex);
4137 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4138 struct ieee80211_vif *vif,
4139 struct ieee80211_channel_switch *chsw)
4141 /* By implementing this operation, we prevent mac80211 from
4142 * starting its own channel switch timer, so that we can call
4143 * ieee80211_chswitch_done() ourselves at the right time
4144 * (which is when the absence time event starts).
4147 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4148 "dummy channel switch op\n");
4151 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4152 struct ieee80211_vif *vif,
4153 struct ieee80211_channel_switch *chsw)
4155 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4156 struct ieee80211_vif *csa_vif;
4157 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4161 mutex_lock(&mvm->mutex);
4163 mvmvif->csa_failed = false;
4165 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4166 chsw->chandef.center_freq1);
4168 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4169 ieee80211_vif_to_wdev(vif),
4170 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4172 switch (vif->type) {
4173 case NL80211_IFTYPE_AP:
4175 rcu_dereference_protected(mvm->csa_vif,
4176 lockdep_is_held(&mvm->mutex));
4177 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4178 "Another CSA is already in progress")) {
4183 /* we still didn't unblock tx. prevent new CS meanwhile */
4184 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4185 lockdep_is_held(&mvm->mutex))) {
4190 rcu_assign_pointer(mvm->csa_vif, vif);
4192 if (WARN_ONCE(mvmvif->csa_countdown,
4193 "Previous CSA countdown didn't complete")) {
4198 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4201 case NL80211_IFTYPE_STATION:
4202 /* Schedule the time event to a bit before beacon 1,
4203 * to make sure we're in the new channel when the
4204 * GO/AP arrives. In case count <= 1 immediately schedule the
4205 * TE (this might result with some packet loss or connection
4208 if (chsw->count <= 1)
4211 apply_time = chsw->device_timestamp +
4212 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4213 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4216 iwl_mvm_csa_client_absent(mvm, vif);
4218 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4220 if (mvmvif->bf_data.bf_enabled) {
4221 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4231 mvmvif->ps_disabled = true;
4233 ret = iwl_mvm_power_update_ps(mvm);
4237 /* we won't be on this channel any longer */
4238 iwl_mvm_teardown_tdls_peers(mvm);
4241 mutex_unlock(&mvm->mutex);
4246 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
4247 struct ieee80211_vif *vif)
4249 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4250 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4253 mutex_lock(&mvm->mutex);
4255 if (mvmvif->csa_failed) {
4256 mvmvif->csa_failed = false;
4261 if (vif->type == NL80211_IFTYPE_STATION) {
4262 struct iwl_mvm_sta *mvmsta;
4264 mvmvif->csa_bcn_pending = false;
4265 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
4268 if (WARN_ON(!mvmsta)) {
4273 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
4275 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4277 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4281 iwl_mvm_stop_session_protection(mvm, vif);
4284 mvmvif->ps_disabled = false;
4286 ret = iwl_mvm_power_update_ps(mvm);
4289 mutex_unlock(&mvm->mutex);
4294 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4298 if (!iwl_mvm_has_new_tx_api(mvm)) {
4300 mutex_lock(&mvm->mutex);
4301 iwl_mvm_flush_tx_path(mvm,
4302 iwl_mvm_flushable_queues(mvm) & queues, 0);
4303 mutex_unlock(&mvm->mutex);
4305 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4310 mutex_lock(&mvm->mutex);
4311 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4312 struct ieee80211_sta *sta;
4314 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4315 lockdep_is_held(&mvm->mutex));
4316 if (IS_ERR_OR_NULL(sta))
4320 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4322 iwl_mvm_wait_sta_queues_empty(mvm,
4323 iwl_mvm_sta_from_mac80211(sta));
4325 mutex_unlock(&mvm->mutex);
4328 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4329 struct ieee80211_vif *vif, u32 queues, bool drop)
4331 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4332 struct iwl_mvm_vif *mvmvif;
4333 struct iwl_mvm_sta *mvmsta;
4334 struct ieee80211_sta *sta;
4339 iwl_mvm_flush_no_vif(mvm, queues, drop);
4343 if (vif->type != NL80211_IFTYPE_STATION)
4346 /* Make sure we're done with the deferred traffic before flushing */
4347 flush_work(&mvm->add_stream_wk);
4349 mutex_lock(&mvm->mutex);
4350 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4352 /* flush the AP-station and all TDLS peers */
4353 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4354 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4355 lockdep_is_held(&mvm->mutex));
4356 if (IS_ERR_OR_NULL(sta))
4359 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4360 if (mvmsta->vif != vif)
4363 /* make sure only TDLS peers or the AP are flushed */
4364 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4367 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4368 IWL_ERR(mvm, "flush request fail\n");
4370 msk |= mvmsta->tfd_queue_msk;
4371 if (iwl_mvm_has_new_tx_api(mvm))
4372 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4376 mutex_unlock(&mvm->mutex);
4378 /* this can take a while, and we may need/want other operations
4379 * to succeed while doing this, so do it without the mutex held
4381 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4382 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4385 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4386 struct survey_info *survey)
4388 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4391 memset(survey, 0, sizeof(*survey));
4393 /* only support global statistics right now */
4397 if (!fw_has_capa(&mvm->fw->ucode_capa,
4398 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4401 mutex_lock(&mvm->mutex);
4403 if (iwl_mvm_firmware_running(mvm)) {
4404 ret = iwl_mvm_request_statistics(mvm, false);
4409 survey->filled = SURVEY_INFO_TIME |
4410 SURVEY_INFO_TIME_RX |
4411 SURVEY_INFO_TIME_TX |
4412 SURVEY_INFO_TIME_SCAN;
4413 survey->time = mvm->accu_radio_stats.on_time_rf +
4414 mvm->radio_stats.on_time_rf;
4415 do_div(survey->time, USEC_PER_MSEC);
4417 survey->time_rx = mvm->accu_radio_stats.rx_time +
4418 mvm->radio_stats.rx_time;
4419 do_div(survey->time_rx, USEC_PER_MSEC);
4421 survey->time_tx = mvm->accu_radio_stats.tx_time +
4422 mvm->radio_stats.tx_time;
4423 do_div(survey->time_tx, USEC_PER_MSEC);
4425 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4426 mvm->radio_stats.on_time_scan;
4427 do_div(survey->time_scan, USEC_PER_MSEC);
4431 mutex_unlock(&mvm->mutex);
4435 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4436 struct ieee80211_vif *vif,
4437 struct ieee80211_sta *sta,
4438 struct station_info *sinfo)
4440 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4441 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4442 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4444 if (mvmsta->avg_energy) {
4445 sinfo->signal_avg = mvmsta->avg_energy;
4446 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4449 if (!fw_has_capa(&mvm->fw->ucode_capa,
4450 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4453 /* if beacon filtering isn't on mac80211 does it anyway */
4454 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4457 if (!vif->bss_conf.assoc)
4460 mutex_lock(&mvm->mutex);
4462 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4465 if (iwl_mvm_request_statistics(mvm, false))
4468 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4469 mvmvif->beacon_stats.accu_num_beacons;
4470 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
4471 if (mvmvif->beacon_stats.avg_signal) {
4472 /* firmware only reports a value after RXing a few beacons */
4473 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4474 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4477 mutex_unlock(&mvm->mutex);
4480 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4481 struct ieee80211_vif *vif,
4482 const struct ieee80211_event *event)
4484 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4486 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4488 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4491 struct iwl_fw_dbg_trigger_tlv *trig;
4492 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4494 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
4497 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
4498 trig_mlme = (void *)trig->data;
4499 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4500 ieee80211_vif_to_wdev(vif), trig))
4503 if (event->u.mlme.data == ASSOC_EVENT) {
4504 if (event->u.mlme.status == MLME_DENIED)
4505 CHECK_MLME_TRIGGER(stop_assoc_denied,
4506 "DENIED ASSOC: reason %d",
4507 event->u.mlme.reason);
4508 else if (event->u.mlme.status == MLME_TIMEOUT)
4509 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4511 } else if (event->u.mlme.data == AUTH_EVENT) {
4512 if (event->u.mlme.status == MLME_DENIED)
4513 CHECK_MLME_TRIGGER(stop_auth_denied,
4514 "DENIED AUTH: reason %d",
4515 event->u.mlme.reason);
4516 else if (event->u.mlme.status == MLME_TIMEOUT)
4517 CHECK_MLME_TRIGGER(stop_auth_timeout,
4519 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4520 CHECK_MLME_TRIGGER(stop_rx_deauth,
4521 "DEAUTH RX %d", event->u.mlme.reason);
4522 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4523 CHECK_MLME_TRIGGER(stop_tx_deauth,
4524 "DEAUTH TX %d", event->u.mlme.reason);
4526 #undef CHECK_MLME_TRIGGER
4529 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4530 struct ieee80211_vif *vif,
4531 const struct ieee80211_event *event)
4533 struct iwl_fw_dbg_trigger_tlv *trig;
4534 struct iwl_fw_dbg_trigger_ba *ba_trig;
4536 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
4539 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
4540 ba_trig = (void *)trig->data;
4541 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4542 ieee80211_vif_to_wdev(vif), trig))
4545 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4548 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4549 "BAR received from %pM, tid %d, ssn %d",
4550 event->u.ba.sta->addr, event->u.ba.tid,
4554 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4555 struct ieee80211_vif *vif,
4556 const struct ieee80211_event *event)
4558 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4560 switch (event->type) {
4562 iwl_mvm_event_mlme_callback(mvm, vif, event);
4565 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4567 case BA_FRAME_TIMEOUT:
4568 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
4576 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4577 struct iwl_mvm_internal_rxq_notif *notif,
4580 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4583 lockdep_assert_held(&mvm->mutex);
4585 if (!iwl_mvm_has_new_rx_api(mvm))
4588 notif->cookie = mvm->queue_sync_cookie;
4591 atomic_set(&mvm->queue_sync_counter,
4592 mvm->trans->num_rx_queues);
4594 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4596 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4601 ret = wait_event_timeout(mvm->rx_sync_waitq,
4602 atomic_read(&mvm->queue_sync_counter) == 0 ||
4603 iwl_mvm_is_radio_killed(mvm),
4605 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4609 atomic_set(&mvm->queue_sync_counter, 0);
4610 mvm->queue_sync_cookie++;
4613 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4615 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4616 struct iwl_mvm_internal_rxq_notif data = {
4617 .type = IWL_MVM_RXQ_EMPTY,
4621 mutex_lock(&mvm->mutex);
4622 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
4623 mutex_unlock(&mvm->mutex);
4626 const struct ieee80211_ops iwl_mvm_hw_ops = {
4627 .tx = iwl_mvm_mac_tx,
4628 .ampdu_action = iwl_mvm_mac_ampdu_action,
4629 .start = iwl_mvm_mac_start,
4630 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
4631 .stop = iwl_mvm_mac_stop,
4632 .add_interface = iwl_mvm_mac_add_interface,
4633 .remove_interface = iwl_mvm_mac_remove_interface,
4634 .config = iwl_mvm_mac_config,
4635 .prepare_multicast = iwl_mvm_prepare_multicast,
4636 .configure_filter = iwl_mvm_configure_filter,
4637 .config_iface_filter = iwl_mvm_config_iface_filter,
4638 .bss_info_changed = iwl_mvm_bss_info_changed,
4639 .hw_scan = iwl_mvm_mac_hw_scan,
4640 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
4641 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
4642 .sta_state = iwl_mvm_mac_sta_state,
4643 .sta_notify = iwl_mvm_mac_sta_notify,
4644 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
4645 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
4646 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
4647 .sta_rc_update = iwl_mvm_sta_rc_update,
4648 .conf_tx = iwl_mvm_mac_conf_tx,
4649 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
4650 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
4651 .flush = iwl_mvm_mac_flush,
4652 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4653 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
4654 .set_key = iwl_mvm_mac_set_key,
4655 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4656 .remain_on_channel = iwl_mvm_roc,
4657 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
4658 .add_chanctx = iwl_mvm_add_chanctx,
4659 .remove_chanctx = iwl_mvm_remove_chanctx,
4660 .change_chanctx = iwl_mvm_change_chanctx,
4661 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4662 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
4663 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
4665 .start_ap = iwl_mvm_start_ap_ibss,
4666 .stop_ap = iwl_mvm_stop_ap_ibss,
4667 .join_ibss = iwl_mvm_start_ap_ibss,
4668 .leave_ibss = iwl_mvm_stop_ap_ibss,
4670 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4672 .set_tim = iwl_mvm_set_tim,
4674 .channel_switch = iwl_mvm_channel_switch,
4675 .pre_channel_switch = iwl_mvm_pre_channel_switch,
4676 .post_channel_switch = iwl_mvm_post_channel_switch,
4678 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4679 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4680 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4682 .event_callback = iwl_mvm_mac_event_callback,
4684 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4686 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4688 #ifdef CONFIG_PM_SLEEP
4690 .suspend = iwl_mvm_suspend,
4691 .resume = iwl_mvm_resume,
4692 .set_wakeup = iwl_mvm_set_wakeup,
4693 .set_rekey_data = iwl_mvm_set_rekey_data,
4694 #if IS_ENABLED(CONFIG_IPV6)
4695 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4697 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4699 .get_survey = iwl_mvm_mac_get_survey,
4700 .sta_statistics = iwl_mvm_mac_sta_statistics,
4701 #ifdef CONFIG_IWLWIFI_DEBUGFS
4702 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,