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 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
27 * The full GNU General Public License is included in this distribution
28 * in the file called COPYING.
30 * Contact Information:
31 * Intel Linux Wireless <linuxwifi@intel.com>
32 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
36 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
37 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
38 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
45 * * Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * * Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in
49 * the documentation and/or other materials provided with the
51 * * Neither the name Intel Corporation nor the names of its
52 * contributors may be used to endorse or promote products derived
53 * from this software without specific prior written permission.
55 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
56 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
57 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
58 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
59 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
61 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
62 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
63 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
64 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
65 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 *****************************************************************************/
68 #include <linux/kernel.h>
69 #include <linux/slab.h>
70 #include <linux/skbuff.h>
71 #include <linux/netdevice.h>
72 #include <linux/etherdevice.h>
74 #include <linux/if_arp.h>
75 #include <linux/time.h>
76 #include <net/mac80211.h>
77 #include <net/ieee80211_radiotap.h>
80 #include "iwl-op-mode.h"
84 #include "time-event.h"
85 #include "iwl-eeprom-parse.h"
86 #include "iwl-phy-db.h"
88 #include "fw/error-dump.h"
90 #include "iwl-nvm-parse.h"
92 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
95 .types = BIT(NL80211_IFTYPE_STATION),
99 .types = BIT(NL80211_IFTYPE_AP) |
100 BIT(NL80211_IFTYPE_P2P_CLIENT) |
101 BIT(NL80211_IFTYPE_P2P_GO),
105 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
109 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
111 .num_different_channels = 2,
113 .limits = iwl_mvm_limits,
114 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
118 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
120 * Use the reserved field to indicate magic values.
121 * these values will only be used internally by the driver,
122 * and won't make it to the fw (reserved will be 0).
123 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
124 * be the vif's ip address. in case there is not a single
125 * ip address (0, or more than 1), this attribute will
127 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
128 * the LSB bytes of the vif's mac address
131 BC_FILTER_MAGIC_NONE = 0,
136 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
140 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
143 /* frame type - arp, hw type - ethernet */
145 BCAST_FILTER_OFFSET_PAYLOAD_START,
146 .offset = sizeof(rfc1042_header),
147 .val = cpu_to_be32(0x08060001),
148 .mask = cpu_to_be32(0xffffffff),
153 BCAST_FILTER_OFFSET_PAYLOAD_START,
154 .offset = sizeof(rfc1042_header) + 2 +
155 sizeof(struct arphdr) +
156 ETH_ALEN + sizeof(__be32) +
158 .mask = cpu_to_be32(0xffffffff),
159 /* mark it as special field */
160 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
165 /* dhcp offer bcast */
167 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
170 /* udp dest port - 68 (bootp client)*/
171 .offset_type = BCAST_FILTER_OFFSET_IP_END,
172 .offset = offsetof(struct udphdr, dest),
173 .val = cpu_to_be32(0x00440000),
174 .mask = cpu_to_be32(0xffff0000),
177 /* dhcp - lsb bytes of client hw address */
178 .offset_type = BCAST_FILTER_OFFSET_IP_END,
180 .mask = cpu_to_be32(0xffffffff),
181 /* mark it as special field */
182 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
186 /* last filter must be empty */
191 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
193 if (!iwl_mvm_is_d0i3_supported(mvm))
196 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
197 spin_lock_bh(&mvm->refs_lock);
198 mvm->refs[ref_type]++;
199 spin_unlock_bh(&mvm->refs_lock);
200 iwl_trans_ref(mvm->trans);
203 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
205 if (!iwl_mvm_is_d0i3_supported(mvm))
208 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
209 spin_lock_bh(&mvm->refs_lock);
210 if (WARN_ON(!mvm->refs[ref_type])) {
211 spin_unlock_bh(&mvm->refs_lock);
214 mvm->refs[ref_type]--;
215 spin_unlock_bh(&mvm->refs_lock);
216 iwl_trans_unref(mvm->trans);
219 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
220 enum iwl_mvm_ref_type except_ref)
224 if (!iwl_mvm_is_d0i3_supported(mvm))
227 spin_lock_bh(&mvm->refs_lock);
228 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
229 if (except_ref == i || !mvm->refs[i])
232 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
234 for (j = 0; j < mvm->refs[i]; j++)
235 iwl_trans_unref(mvm->trans);
238 spin_unlock_bh(&mvm->refs_lock);
241 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
246 if (!iwl_mvm_is_d0i3_supported(mvm))
249 spin_lock_bh(&mvm->refs_lock);
250 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
256 spin_unlock_bh(&mvm->refs_lock);
261 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
263 iwl_mvm_ref(mvm, ref_type);
265 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
266 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
269 iwl_mvm_unref(mvm, ref_type);
276 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
280 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
281 for (i = 0; i < NUM_PHY_CTX; i++) {
282 mvm->phy_ctxts[i].id = i;
283 mvm->phy_ctxts[i].ref = 0;
287 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
289 enum iwl_mcc_source src_id,
292 struct ieee80211_regdomain *regd = NULL;
293 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
294 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
295 struct iwl_mcc_update_resp *resp;
297 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
299 lockdep_assert_held(&mvm->mutex);
301 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
302 if (IS_ERR_OR_NULL(resp)) {
303 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
304 PTR_ERR_OR_ZERO(resp));
309 *changed = (resp->status == MCC_RESP_NEW_CHAN_PROFILE);
311 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
312 __le32_to_cpu(resp->n_channels),
314 __le16_to_cpu(resp->mcc),
315 __le16_to_cpu(resp->geo_info));
316 /* Store the return source id */
317 src_id = resp->source_id;
319 if (IS_ERR_OR_NULL(regd)) {
320 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
321 PTR_ERR_OR_ZERO(regd));
325 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
326 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
327 mvm->lar_regdom_set = true;
328 mvm->mcc_src = src_id;
334 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
337 struct ieee80211_regdomain *regd;
339 if (!iwl_mvm_is_lar_supported(mvm))
342 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
343 if (!IS_ERR_OR_NULL(regd)) {
344 /* only update the regulatory core if changed */
346 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
352 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
355 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
356 iwl_mvm_is_wifi_mcc_supported(mvm) ?
357 MCC_SOURCE_GET_CURRENT :
358 MCC_SOURCE_OLD_FW, changed);
361 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
363 enum iwl_mcc_source used_src;
364 struct ieee80211_regdomain *regd;
367 const struct ieee80211_regdomain *r =
368 rtnl_dereference(mvm->hw->wiphy->regd);
373 /* save the last source in case we overwrite it below */
374 used_src = mvm->mcc_src;
375 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
376 /* Notify the firmware we support wifi location updates */
377 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
378 if (!IS_ERR_OR_NULL(regd))
382 /* Now set our last stored MCC and source */
383 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
385 if (IS_ERR_OR_NULL(regd))
388 /* update cfg80211 if the regdomain was changed */
390 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
398 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
400 struct ieee80211_hw *hw = mvm->hw;
402 static const u32 mvm_ciphers[] = {
403 WLAN_CIPHER_SUITE_WEP40,
404 WLAN_CIPHER_SUITE_WEP104,
405 WLAN_CIPHER_SUITE_TKIP,
406 WLAN_CIPHER_SUITE_CCMP,
409 /* Tell mac80211 our characteristics */
410 ieee80211_hw_set(hw, SIGNAL_DBM);
411 ieee80211_hw_set(hw, SPECTRUM_MGMT);
412 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
413 ieee80211_hw_set(hw, QUEUE_CONTROL);
414 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
415 ieee80211_hw_set(hw, SUPPORTS_PS);
416 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
417 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
418 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
419 ieee80211_hw_set(hw, CONNECTION_MONITOR);
420 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
421 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
422 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
423 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
424 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
425 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
427 if (iwl_mvm_has_tlc_offload(mvm)) {
428 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
429 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
432 if (iwl_mvm_has_new_rx_api(mvm))
433 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
435 if (fw_has_capa(&mvm->fw->ucode_capa,
436 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
437 ieee80211_hw_set(hw, AP_LINK_PS);
438 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
440 * we absolutely need this for the new TX API since that comes
441 * with many more queues than the current code can deal with
442 * for station powersave
447 if (mvm->trans->num_rx_queues > 1)
448 ieee80211_hw_set(hw, USES_RSS);
450 if (mvm->trans->max_skb_frags)
451 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
453 hw->queues = IEEE80211_MAX_QUEUES;
454 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
455 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
456 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
457 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
458 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
460 hw->radiotap_timestamp.units_pos =
461 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
462 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
463 /* this is the case for CCK frames, it's better (only 8) for OFDM */
464 hw->radiotap_timestamp.accuracy = 22;
466 if (!iwl_mvm_has_tlc_offload(mvm))
467 hw->rate_control_algorithm = RS_NAME;
469 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
470 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
472 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
473 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
474 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
475 hw->wiphy->cipher_suites = mvm->ciphers;
477 if (iwl_mvm_has_new_rx_api(mvm)) {
478 mvm->ciphers[hw->wiphy->n_cipher_suites] =
479 WLAN_CIPHER_SUITE_GCMP;
480 hw->wiphy->n_cipher_suites++;
481 mvm->ciphers[hw->wiphy->n_cipher_suites] =
482 WLAN_CIPHER_SUITE_GCMP_256;
483 hw->wiphy->n_cipher_suites++;
486 /* Enable 11w if software crypto is not enabled (as the
487 * firmware will interpret some mgmt packets, so enabling it
488 * with software crypto isn't safe).
490 if (!iwlwifi_mod_params.swcrypto) {
491 ieee80211_hw_set(hw, MFP_CAPABLE);
492 mvm->ciphers[hw->wiphy->n_cipher_suites] =
493 WLAN_CIPHER_SUITE_AES_CMAC;
494 hw->wiphy->n_cipher_suites++;
495 if (iwl_mvm_has_new_rx_api(mvm)) {
496 mvm->ciphers[hw->wiphy->n_cipher_suites] =
497 WLAN_CIPHER_SUITE_BIP_GMAC_128;
498 hw->wiphy->n_cipher_suites++;
499 mvm->ciphers[hw->wiphy->n_cipher_suites] =
500 WLAN_CIPHER_SUITE_BIP_GMAC_256;
501 hw->wiphy->n_cipher_suites++;
505 /* currently FW API supports only one optional cipher scheme */
506 if (mvm->fw->cs[0].cipher) {
507 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
508 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
510 mvm->hw->n_cipher_schemes = 1;
512 cs->cipher = le32_to_cpu(fwcs->cipher);
513 cs->iftype = BIT(NL80211_IFTYPE_STATION);
514 cs->hdr_len = fwcs->hdr_len;
515 cs->pn_len = fwcs->pn_len;
516 cs->pn_off = fwcs->pn_off;
517 cs->key_idx_off = fwcs->key_idx_off;
518 cs->key_idx_mask = fwcs->key_idx_mask;
519 cs->key_idx_shift = fwcs->key_idx_shift;
520 cs->mic_len = fwcs->mic_len;
522 mvm->hw->cipher_schemes = mvm->cs;
523 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
524 hw->wiphy->n_cipher_suites++;
527 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
528 hw->wiphy->features |=
529 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
530 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
531 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
533 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
534 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
535 hw->chanctx_data_size = sizeof(u16);
537 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
538 BIT(NL80211_IFTYPE_P2P_CLIENT) |
539 BIT(NL80211_IFTYPE_AP) |
540 BIT(NL80211_IFTYPE_P2P_GO) |
541 BIT(NL80211_IFTYPE_P2P_DEVICE) |
542 BIT(NL80211_IFTYPE_ADHOC);
544 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
545 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
546 if (iwl_mvm_is_lar_supported(mvm))
547 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
549 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
550 REGULATORY_DISABLE_BEACON_HINTS;
552 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
553 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
555 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
556 hw->wiphy->n_iface_combinations =
557 ARRAY_SIZE(iwl_mvm_iface_combinations);
559 hw->wiphy->max_remain_on_channel_duration = 10000;
560 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
561 /* we can compensate an offset of up to 3 channels = 15 MHz */
562 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
564 /* Extract MAC address */
565 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
566 hw->wiphy->addresses = mvm->addresses;
567 hw->wiphy->n_addresses = 1;
569 /* Extract additional MAC addresses if available */
570 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
571 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
573 for (i = 1; i < num_mac; i++) {
574 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
576 mvm->addresses[i].addr[5]++;
577 hw->wiphy->n_addresses++;
580 iwl_mvm_reset_phy_ctxts(mvm);
582 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
584 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
586 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
587 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
588 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
590 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
591 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
593 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
595 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
596 hw->wiphy->bands[NL80211_BAND_2GHZ] =
597 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
598 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
599 hw->wiphy->bands[NL80211_BAND_5GHZ] =
600 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
602 if (fw_has_capa(&mvm->fw->ucode_capa,
603 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
604 fw_has_api(&mvm->fw->ucode_capa,
605 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
606 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
607 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
610 hw->wiphy->hw_version = mvm->trans->hw_id;
612 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
613 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
615 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
617 hw->wiphy->max_sched_scan_reqs = 1;
618 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
619 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
620 /* we create the 802.11 header and zero length SSID IE. */
621 hw->wiphy->max_sched_scan_ie_len =
622 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
623 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
624 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
627 * the firmware uses u8 for num of iterations, but 0xff is saved for
628 * infinite loop, so the maximum number of iterations is actually 254.
630 hw->wiphy->max_sched_scan_plan_iterations = 254;
632 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
633 NL80211_FEATURE_LOW_PRIORITY_SCAN |
634 NL80211_FEATURE_P2P_GO_OPPPS |
635 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
636 NL80211_FEATURE_DYNAMIC_SMPS |
637 NL80211_FEATURE_STATIC_SMPS |
638 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
640 if (fw_has_capa(&mvm->fw->ucode_capa,
641 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
642 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
643 if (fw_has_capa(&mvm->fw->ucode_capa,
644 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
645 hw->wiphy->features |= NL80211_FEATURE_QUIET;
647 if (fw_has_capa(&mvm->fw->ucode_capa,
648 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
649 hw->wiphy->features |=
650 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
652 if (fw_has_capa(&mvm->fw->ucode_capa,
653 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
654 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
656 if (fw_has_api(&mvm->fw->ucode_capa,
657 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
658 wiphy_ext_feature_set(hw->wiphy,
659 NL80211_EXT_FEATURE_SCAN_START_TIME);
660 wiphy_ext_feature_set(hw->wiphy,
661 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
662 wiphy_ext_feature_set(hw->wiphy,
663 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
666 if (iwl_mvm_is_oce_supported(mvm)) {
667 wiphy_ext_feature_set(hw->wiphy,
668 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
669 wiphy_ext_feature_set(hw->wiphy,
670 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
671 wiphy_ext_feature_set(hw->wiphy,
672 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
673 wiphy_ext_feature_set(hw->wiphy,
674 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
677 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
679 #ifdef CONFIG_PM_SLEEP
680 if (iwl_mvm_is_d0i3_supported(mvm) &&
681 device_can_wakeup(mvm->trans->dev)) {
682 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
683 hw->wiphy->wowlan = &mvm->wowlan;
686 if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
687 mvm->trans->ops->d3_suspend &&
688 mvm->trans->ops->d3_resume &&
689 device_can_wakeup(mvm->trans->dev)) {
690 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
691 WIPHY_WOWLAN_DISCONNECT |
692 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
693 WIPHY_WOWLAN_RFKILL_RELEASE |
694 WIPHY_WOWLAN_NET_DETECT;
695 if (!iwlwifi_mod_params.swcrypto)
696 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
697 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
698 WIPHY_WOWLAN_4WAY_HANDSHAKE;
700 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
701 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
702 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
703 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
704 hw->wiphy->wowlan = &mvm->wowlan;
708 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
709 /* assign default bcast filtering configuration */
710 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
713 ret = iwl_mvm_leds_init(mvm);
717 if (fw_has_capa(&mvm->fw->ucode_capa,
718 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
719 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
720 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
721 ieee80211_hw_set(hw, TDLS_WIDER_BW);
724 if (fw_has_capa(&mvm->fw->ucode_capa,
725 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
726 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
727 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
730 hw->netdev_features |= mvm->cfg->features;
731 if (!iwl_mvm_is_csum_supported(mvm)) {
732 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
734 /* We may support SW TX CSUM */
735 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
736 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
739 ret = ieee80211_register_hw(mvm->hw);
741 iwl_mvm_leds_exit(mvm);
742 mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
744 if (mvm->cfg->vht_mu_mimo_supported)
745 wiphy_ext_feature_set(hw->wiphy,
746 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
751 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
752 struct ieee80211_sta *sta,
755 struct iwl_mvm_sta *mvmsta;
759 * double check the IN_D0I3 flag both before and after
760 * taking the spinlock, in order to prevent taking
761 * the spinlock when not needed.
763 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
766 spin_lock(&mvm->d0i3_tx_lock);
768 * testing the flag again ensures the skb dequeue
769 * loop (on d0i3 exit) hasn't run yet.
771 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
774 mvmsta = iwl_mvm_sta_from_mac80211(sta);
775 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
776 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
779 __skb_queue_tail(&mvm->d0i3_tx, skb);
780 ieee80211_stop_queues(mvm->hw);
783 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
784 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
788 spin_unlock(&mvm->d0i3_tx_lock);
792 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
793 struct ieee80211_tx_control *control,
796 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
797 struct ieee80211_sta *sta = control->sta;
798 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
799 struct ieee80211_hdr *hdr = (void *)skb->data;
801 if (iwl_mvm_is_radio_killed(mvm)) {
802 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
806 if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
807 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
808 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
811 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
812 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
813 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
814 ieee80211_is_mgmt(hdr->frame_control) &&
815 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
819 if (iwl_mvm_defer_tx(mvm, sta, skb))
821 if (iwl_mvm_tx_skb(mvm, skb, sta))
826 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
830 ieee80211_free_txskb(hw, skb);
833 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
835 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
840 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
842 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
844 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
847 /* enabled by default */
851 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
853 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
855 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
859 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
860 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
861 enum ieee80211_ampdu_mlme_action action)
863 struct iwl_fw_dbg_trigger_tlv *trig;
864 struct iwl_fw_dbg_trigger_ba *ba_trig;
866 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
869 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
870 ba_trig = (void *)trig->data;
872 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
873 ieee80211_vif_to_wdev(vif), trig))
877 case IEEE80211_AMPDU_TX_OPERATIONAL: {
878 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
879 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
881 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
882 "TX AGG START: MAC %pM tid %d ssn %d\n",
883 sta->addr, tid, tid_data->ssn);
886 case IEEE80211_AMPDU_TX_STOP_CONT:
887 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
888 "TX AGG STOP: MAC %pM tid %d\n",
891 case IEEE80211_AMPDU_RX_START:
892 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
893 "RX AGG START: MAC %pM tid %d ssn %d\n",
894 sta->addr, tid, rx_ba_ssn);
896 case IEEE80211_AMPDU_RX_STOP:
897 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
898 "RX AGG STOP: MAC %pM tid %d\n",
906 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
907 struct ieee80211_vif *vif,
908 struct ieee80211_ampdu_params *params)
910 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
912 bool tx_agg_ref = false;
913 struct ieee80211_sta *sta = params->sta;
914 enum ieee80211_ampdu_mlme_action action = params->action;
915 u16 tid = params->tid;
916 u16 *ssn = ¶ms->ssn;
917 u8 buf_size = params->buf_size;
918 bool amsdu = params->amsdu;
919 u16 timeout = params->timeout;
921 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
922 sta->addr, tid, action);
924 if (!(mvm->nvm_data->sku_cap_11n_enable))
927 /* return from D0i3 before starting a new Tx aggregation */
929 case IEEE80211_AMPDU_TX_START:
930 case IEEE80211_AMPDU_TX_STOP_CONT:
931 case IEEE80211_AMPDU_TX_STOP_FLUSH:
932 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
933 case IEEE80211_AMPDU_TX_OPERATIONAL:
935 * for tx start, wait synchronously until D0i3 exit to
936 * get the correct sequence number for the tid.
937 * additionally, some other ampdu actions use direct
938 * target access, which is not handled automatically
939 * by the trans layer (unlike commands), so wait for
940 * d0i3 exit in these cases as well.
942 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
952 mutex_lock(&mvm->mutex);
955 case IEEE80211_AMPDU_RX_START:
956 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
957 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
958 struct iwl_mvm_vif *mvmvif;
959 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
960 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
962 mdata->opened_rx_ba_sessions = true;
963 mvmvif = iwl_mvm_vif_from_mac80211(vif);
964 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
966 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
970 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
973 case IEEE80211_AMPDU_RX_STOP:
974 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
977 case IEEE80211_AMPDU_TX_START:
978 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
982 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
984 case IEEE80211_AMPDU_TX_STOP_CONT:
985 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
987 case IEEE80211_AMPDU_TX_STOP_FLUSH:
988 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
989 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
991 case IEEE80211_AMPDU_TX_OPERATIONAL:
992 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1004 if (action == IEEE80211_AMPDU_RX_START)
1007 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1010 mutex_unlock(&mvm->mutex);
1013 * If the tid is marked as started, we won't use it for offloaded
1014 * traffic on the next D0i3 entry. It's safe to unref.
1017 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1022 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1023 struct ieee80211_vif *vif)
1025 struct iwl_mvm *mvm = data;
1026 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1028 mvmvif->uploaded = false;
1029 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1031 spin_lock_bh(&mvm->time_event_lock);
1032 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1033 spin_unlock_bh(&mvm->time_event_lock);
1035 mvmvif->phy_ctxt = NULL;
1036 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1039 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1041 /* clear the D3 reconfig, we only need it to avoid dumping a
1042 * firmware coredump on reconfiguration, we shouldn't do that
1043 * on D3->D0 transition
1045 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1046 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1047 iwl_fw_error_dump(&mvm->fwrt);
1050 /* cleanup all stale references (scan, roc), but keep the
1051 * ucode_down ref until reconfig is complete
1053 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1055 iwl_mvm_stop_device(mvm);
1057 mvm->scan_status = 0;
1058 mvm->ps_disabled = false;
1059 mvm->calibrating = false;
1061 /* just in case one was running */
1062 iwl_mvm_cleanup_roc_te(mvm);
1063 ieee80211_remain_on_channel_expired(mvm->hw);
1066 * cleanup all interfaces, even inactive ones, as some might have
1067 * gone down during the HW restart
1069 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1071 mvm->p2p_device_vif = NULL;
1072 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1074 iwl_mvm_reset_phy_ctxts(mvm);
1075 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1076 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
1077 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1078 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1080 ieee80211_wake_queues(mvm->hw);
1082 /* clear any stale d0i3 state */
1083 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1086 mvm->rx_ba_sessions = 0;
1087 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1088 mvm->monitor_on = false;
1090 /* keep statistics ticking */
1091 iwl_mvm_accu_radio_stats(mvm);
1094 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1098 lockdep_assert_held(&mvm->mutex);
1100 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1102 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1103 * so later code will - from now on - see that we're doing it.
1105 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1106 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1107 /* Clean up some internal and mac80211 state on restart */
1108 iwl_mvm_restart_cleanup(mvm);
1110 /* Hold the reference to prevent runtime suspend while
1111 * the start procedure runs. It's a bit confusing
1112 * that the UCODE_DOWN reference is taken, but it just
1113 * means "UCODE is not UP yet". ( TODO: rename this
1116 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1118 ret = iwl_mvm_up(mvm);
1120 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1121 /* Something went wrong - we need to finish some cleanup
1122 * that normally iwl_mvm_mac_restart_complete() below
1125 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1126 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1132 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1134 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1137 /* Some hw restart cleanups must not hold the mutex */
1138 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1140 * Make sure we are out of d0i3. This is needed
1141 * to make sure the reference accounting is correct
1142 * (and there is no stale d0i3_exit_work).
1144 wait_event_timeout(mvm->d0i3_exit_waitq,
1145 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1150 mutex_lock(&mvm->mutex);
1151 ret = __iwl_mvm_mac_start(mvm);
1152 mutex_unlock(&mvm->mutex);
1157 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1161 mutex_lock(&mvm->mutex);
1163 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1164 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1165 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1167 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1170 /* allow transport/FW low power modes */
1171 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1174 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1175 * of packets the FW sent out, so we must reconnect.
1177 iwl_mvm_teardown_tdls_peers(mvm);
1179 mutex_unlock(&mvm->mutex);
1182 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1184 if (iwl_mvm_is_d0i3_supported(mvm) &&
1185 iwl_mvm_enter_d0i3_on_suspend(mvm))
1186 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1187 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1190 "D0i3 exit on resume timed out\n");
1194 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1195 enum ieee80211_reconfig_type reconfig_type)
1197 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1199 switch (reconfig_type) {
1200 case IEEE80211_RECONFIG_TYPE_RESTART:
1201 iwl_mvm_restart_complete(mvm);
1203 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1204 iwl_mvm_resume_complete(mvm);
1209 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1211 lockdep_assert_held(&mvm->mutex);
1213 /* firmware counters are obviously reset now, but we shouldn't
1214 * partially track so also clear the fw_reset_accu counters.
1216 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1218 /* async_handlers_wk is now blocked */
1221 * The work item could be running or queued if the
1222 * ROC time event stops just as we get here.
1224 flush_work(&mvm->roc_done_wk);
1226 iwl_mvm_stop_device(mvm);
1228 iwl_mvm_async_handlers_purge(mvm);
1229 /* async_handlers_list is empty and will stay empty: HW is stopped */
1231 /* the fw is stopped, the aux sta is dead: clean up driver state */
1232 iwl_mvm_del_aux_sta(mvm);
1235 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1236 * won't be called in this case).
1237 * But make sure to cleanup interfaces that have gone down before/during
1238 * HW restart was requested.
1240 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1241 ieee80211_iterate_interfaces(mvm->hw, 0,
1242 iwl_mvm_cleanup_iterator, mvm);
1244 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1245 * make sure there's nothing left there and warn if any is found.
1247 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1250 for (i = 0; i < mvm->max_scans; i++) {
1251 if (WARN_ONCE(mvm->scan_uid_status[i],
1252 "UMAC scan UID %d status was not cleaned\n",
1254 mvm->scan_uid_status[i] = 0;
1259 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1261 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1263 flush_work(&mvm->d0i3_exit_work);
1264 flush_work(&mvm->async_handlers_wk);
1265 flush_work(&mvm->add_stream_wk);
1268 * Lock and clear the firmware running bit here already, so that
1269 * new commands coming in elsewhere, e.g. from debugfs, will not
1270 * be able to proceed. This is important here because one of those
1271 * debugfs files causes the firmware dump to be triggered, and if we
1272 * don't stop debugfs accesses before canceling that it could be
1273 * retriggered after we flush it but before we've cleared the bit.
1275 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1277 iwl_fw_cancel_dump(&mvm->fwrt);
1278 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1279 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1280 iwl_fw_free_dump_desc(&mvm->fwrt);
1282 mutex_lock(&mvm->mutex);
1283 __iwl_mvm_mac_stop(mvm);
1284 mutex_unlock(&mvm->mutex);
1287 * The worker might have been waiting for the mutex, let it run and
1288 * discover that its list is now empty.
1290 cancel_work_sync(&mvm->async_handlers_wk);
1293 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1297 lockdep_assert_held(&mvm->mutex);
1299 for (i = 0; i < NUM_PHY_CTX; i++)
1300 if (!mvm->phy_ctxts[i].ref)
1301 return &mvm->phy_ctxts[i];
1303 IWL_ERR(mvm, "No available PHY context\n");
1307 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1310 struct iwl_dev_tx_power_cmd cmd = {
1311 .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1312 .v3.mac_context_id =
1313 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1314 .v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1316 int len = sizeof(cmd);
1318 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1319 cmd.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1321 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1322 len = sizeof(cmd.v3);
1324 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1327 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1328 struct ieee80211_vif *vif)
1330 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1331 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1337 * make sure D0i3 exit is completed, otherwise a target access
1338 * during tx queue configuration could be done when still in
1341 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1346 * Not much to do here. The stack will not allow interface
1347 * types or combinations that we didn't advertise, so we
1348 * don't really have to check the types.
1351 mutex_lock(&mvm->mutex);
1353 /* make sure that beacon statistics don't go backwards with FW reset */
1354 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1355 mvmvif->beacon_stats.accu_num_beacons +=
1356 mvmvif->beacon_stats.num_beacons;
1358 /* Allocate resources for the MAC context, and add it to the fw */
1359 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1363 /* Counting number of interfaces is needed for legacy PM */
1364 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1368 * The AP binding flow can be done only after the beacon
1369 * template is configured (which happens only in the mac80211
1370 * start_ap() flow), and adding the broadcast station can happen
1371 * only after the binding.
1372 * In addition, since modifying the MAC before adding a bcast
1373 * station is not allowed by the FW, delay the adding of MAC context to
1374 * the point where we can also add the bcast station.
1375 * In short: there's not much we can do at this point, other than
1376 * allocating resources :)
1378 if (vif->type == NL80211_IFTYPE_AP ||
1379 vif->type == NL80211_IFTYPE_ADHOC) {
1380 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1382 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1387 * Only queue for this station is the mcast queue,
1388 * which shouldn't be in TFD mask anyway
1390 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1396 iwl_mvm_vif_dbgfs_register(mvm, vif);
1400 mvmvif->features |= hw->netdev_features;
1402 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1406 ret = iwl_mvm_power_update_mac(mvm);
1408 goto out_remove_mac;
1410 /* beacon filtering */
1411 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1413 goto out_remove_mac;
1415 if (!mvm->bf_allowed_vif &&
1416 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1417 mvm->bf_allowed_vif = mvmvif;
1418 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1419 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1423 * P2P_DEVICE interface does not have a channel context assigned to it,
1424 * so a dedicated PHY context is allocated to it and the corresponding
1425 * MAC context is bound to it at this stage.
1427 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1429 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1430 if (!mvmvif->phy_ctxt) {
1435 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1436 ret = iwl_mvm_binding_add_vif(mvm, vif);
1440 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1444 /* Save a pointer to p2p device vif, so it can later be used to
1445 * update the p2p device MAC when a GO is started/stopped */
1446 mvm->p2p_device_vif = vif;
1449 iwl_mvm_tcm_add_vif(mvm, vif);
1451 if (vif->type == NL80211_IFTYPE_MONITOR)
1452 mvm->monitor_on = true;
1454 iwl_mvm_vif_dbgfs_register(mvm, vif);
1458 iwl_mvm_binding_remove_vif(mvm, vif);
1460 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1462 if (mvm->bf_allowed_vif == mvmvif) {
1463 mvm->bf_allowed_vif = NULL;
1464 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1465 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1468 mvmvif->phy_ctxt = NULL;
1469 iwl_mvm_mac_ctxt_remove(mvm, vif);
1471 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1474 mutex_unlock(&mvm->mutex);
1476 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1481 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1482 struct ieee80211_vif *vif)
1484 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1486 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1487 * We assume here that all the packets sent to the OFFCHANNEL
1488 * queue are sent in ROC session.
1490 flush_work(&mvm->roc_done_wk);
1494 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1495 struct ieee80211_vif *vif)
1497 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1498 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1500 iwl_mvm_prepare_mac_removal(mvm, vif);
1502 if (!(vif->type == NL80211_IFTYPE_AP ||
1503 vif->type == NL80211_IFTYPE_ADHOC))
1504 iwl_mvm_tcm_rm_vif(mvm, vif);
1506 mutex_lock(&mvm->mutex);
1508 if (mvm->bf_allowed_vif == mvmvif) {
1509 mvm->bf_allowed_vif = NULL;
1510 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1511 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1514 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1517 * For AP/GO interface, the tear down of the resources allocated to the
1518 * interface is be handled as part of the stop_ap flow.
1520 if (vif->type == NL80211_IFTYPE_AP ||
1521 vif->type == NL80211_IFTYPE_ADHOC) {
1522 #ifdef CONFIG_NL80211_TESTMODE
1523 if (vif == mvm->noa_vif) {
1524 mvm->noa_vif = NULL;
1525 mvm->noa_duration = 0;
1528 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1529 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1533 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1534 mvm->p2p_device_vif = NULL;
1535 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1536 iwl_mvm_binding_remove_vif(mvm, vif);
1537 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1538 mvmvif->phy_ctxt = NULL;
1541 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1544 iwl_mvm_power_update_mac(mvm);
1545 iwl_mvm_mac_ctxt_remove(mvm, vif);
1547 if (vif->type == NL80211_IFTYPE_MONITOR)
1548 mvm->monitor_on = false;
1551 mutex_unlock(&mvm->mutex);
1554 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1559 struct iwl_mvm_mc_iter_data {
1560 struct iwl_mvm *mvm;
1564 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1565 struct ieee80211_vif *vif)
1567 struct iwl_mvm_mc_iter_data *data = _data;
1568 struct iwl_mvm *mvm = data->mvm;
1569 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1570 struct iwl_host_cmd hcmd = {
1571 .id = MCAST_FILTER_CMD,
1573 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1577 /* if we don't have free ports, mcast frames will be dropped */
1578 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1581 if (vif->type != NL80211_IFTYPE_STATION ||
1582 !vif->bss_conf.assoc)
1585 cmd->port_id = data->port_id++;
1586 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1587 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1592 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1594 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1597 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1599 struct iwl_mvm_mc_iter_data iter_data = {
1603 lockdep_assert_held(&mvm->mutex);
1605 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1608 ieee80211_iterate_active_interfaces_atomic(
1609 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1610 iwl_mvm_mc_iface_iterator, &iter_data);
1613 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1614 struct netdev_hw_addr_list *mc_list)
1616 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1617 struct iwl_mcast_filter_cmd *cmd;
1618 struct netdev_hw_addr *addr;
1623 addr_count = netdev_hw_addr_list_count(mc_list);
1624 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1625 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1629 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1630 cmd = kzalloc(len, GFP_ATOMIC);
1636 return (u64)(unsigned long)cmd;
1639 netdev_hw_addr_list_for_each(addr, mc_list) {
1640 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1641 cmd->count, addr->addr);
1642 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1643 addr->addr, ETH_ALEN);
1647 return (u64)(unsigned long)cmd;
1650 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1651 unsigned int changed_flags,
1652 unsigned int *total_flags,
1655 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1656 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1658 mutex_lock(&mvm->mutex);
1660 /* replace previous configuration */
1661 kfree(mvm->mcast_filter_cmd);
1662 mvm->mcast_filter_cmd = cmd;
1667 if (changed_flags & FIF_ALLMULTI)
1668 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1673 iwl_mvm_recalc_multicast(mvm);
1675 mutex_unlock(&mvm->mutex);
1679 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1680 struct ieee80211_vif *vif,
1681 unsigned int filter_flags,
1682 unsigned int changed_flags)
1684 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1686 /* We support only filter for probe requests */
1687 if (!(changed_flags & FIF_PROBE_REQ))
1690 /* Supported only for p2p client interfaces */
1691 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1695 mutex_lock(&mvm->mutex);
1696 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1697 mutex_unlock(&mvm->mutex);
1700 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1701 struct iwl_bcast_iter_data {
1702 struct iwl_mvm *mvm;
1703 struct iwl_bcast_filter_cmd *cmd;
1708 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1709 const struct iwl_fw_bcast_filter *in_filter,
1710 struct iwl_fw_bcast_filter *out_filter)
1712 struct iwl_fw_bcast_filter_attr *attr;
1715 memcpy(out_filter, in_filter, sizeof(*out_filter));
1717 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1718 attr = &out_filter->attrs[i];
1723 switch (attr->reserved1) {
1724 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1725 if (vif->bss_conf.arp_addr_cnt != 1) {
1730 attr->val = vif->bss_conf.arp_addr_list[0];
1732 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1733 attr->val = *(__be32 *)&vif->addr[2];
1738 attr->reserved1 = 0;
1739 out_filter->num_attrs++;
1743 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1744 struct ieee80211_vif *vif)
1746 struct iwl_bcast_iter_data *data = _data;
1747 struct iwl_mvm *mvm = data->mvm;
1748 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1749 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1750 struct iwl_fw_bcast_mac *bcast_mac;
1753 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1756 bcast_mac = &cmd->macs[mvmvif->id];
1759 * enable filtering only for associated stations, but not for P2P
1762 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1763 !vif->bss_conf.assoc)
1766 bcast_mac->default_discard = 1;
1768 /* copy all configured filters */
1769 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1771 * Make sure we don't exceed our filters limit.
1772 * if there is still a valid filter to be configured,
1773 * be on the safe side and just allow bcast for this mac.
1775 if (WARN_ON_ONCE(data->current_filter >=
1776 ARRAY_SIZE(cmd->filters))) {
1777 bcast_mac->default_discard = 0;
1778 bcast_mac->attached_filters = 0;
1782 iwl_mvm_set_bcast_filter(vif,
1783 &mvm->bcast_filters[i],
1784 &cmd->filters[data->current_filter]);
1786 /* skip current filter if it contains no attributes */
1787 if (!cmd->filters[data->current_filter].num_attrs)
1790 /* attach the filter to current mac */
1791 bcast_mac->attached_filters |=
1792 cpu_to_le16(BIT(data->current_filter));
1794 data->current_filter++;
1798 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1799 struct iwl_bcast_filter_cmd *cmd)
1801 struct iwl_bcast_iter_data iter_data = {
1806 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1809 memset(cmd, 0, sizeof(*cmd));
1810 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1811 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1813 #ifdef CONFIG_IWLWIFI_DEBUGFS
1814 /* use debugfs filters/macs if override is configured */
1815 if (mvm->dbgfs_bcast_filtering.override) {
1816 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1817 sizeof(cmd->filters));
1818 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1824 /* if no filters are configured, do nothing */
1825 if (!mvm->bcast_filters)
1828 /* configure and attach these filters for each associated sta vif */
1829 ieee80211_iterate_active_interfaces(
1830 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1831 iwl_mvm_bcast_filter_iterator, &iter_data);
1836 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1838 struct iwl_bcast_filter_cmd cmd;
1840 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1843 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1846 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1850 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1856 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1857 struct ieee80211_vif *vif)
1859 struct iwl_mu_group_mgmt_cmd cmd = {};
1861 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1862 WLAN_MEMBERSHIP_LEN);
1863 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1864 WLAN_USER_POSITION_LEN);
1866 return iwl_mvm_send_cmd_pdu(mvm,
1867 WIDE_ID(DATA_PATH_GROUP,
1868 UPDATE_MU_GROUPS_CMD),
1869 0, sizeof(cmd), &cmd);
1872 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1873 struct ieee80211_vif *vif)
1875 if (vif->mu_mimo_owner) {
1876 struct iwl_mu_group_mgmt_notif *notif = _data;
1879 * MU-MIMO Group Id action frame is little endian. We treat
1880 * the data received from firmware as if it came from the
1881 * action frame, so no conversion is needed.
1883 ieee80211_update_mu_groups(vif,
1884 (u8 *)¬if->membership_status,
1885 (u8 *)¬if->user_position);
1889 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1890 struct iwl_rx_cmd_buffer *rxb)
1892 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1893 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1895 ieee80211_iterate_active_interfaces_atomic(
1896 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1897 iwl_mvm_mu_mimo_iface_iterator, notif);
1900 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1901 struct ieee80211_vif *vif,
1902 struct ieee80211_bss_conf *bss_conf,
1905 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1909 * Re-calculate the tsf id, as the master-slave relations depend on the
1910 * beacon interval, which was not known when the station interface was
1913 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1914 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1917 * If we're not associated yet, take the (new) BSSID before associating
1918 * so the firmware knows. If we're already associated, then use the old
1919 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1920 * branch for disassociation below.
1922 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1923 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1925 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
1927 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1929 /* after sending it once, adopt mac80211 data */
1930 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1931 mvmvif->associated = bss_conf->assoc;
1933 if (changes & BSS_CHANGED_ASSOC) {
1934 if (bss_conf->assoc) {
1935 /* clear statistics to get clean beacon counter */
1936 iwl_mvm_request_statistics(mvm, true);
1937 memset(&mvmvif->beacon_stats, 0,
1938 sizeof(mvmvif->beacon_stats));
1940 /* add quota for this interface */
1941 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1943 IWL_ERR(mvm, "failed to update quotas\n");
1947 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1950 * If we're restarting then the firmware will
1951 * obviously have lost synchronisation with
1952 * the AP. It will attempt to synchronise by
1953 * itself, but we can make it more reliable by
1954 * scheduling a session protection time event.
1956 * The firmware needs to receive a beacon to
1957 * catch up with synchronisation, use 110% of
1958 * the beacon interval.
1960 * Set a large maximum delay to allow for more
1961 * than a single interface.
1963 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1964 iwl_mvm_protect_session(mvm, vif, dur, dur,
1968 iwl_mvm_sf_update(mvm, vif, false);
1969 iwl_mvm_power_vif_assoc(mvm, vif);
1971 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
1972 iwl_mvm_update_smps(mvm, vif,
1973 IWL_MVM_SMPS_REQ_PROT,
1974 IEEE80211_SMPS_DYNAMIC);
1976 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
1978 * If update fails - SF might be running in associated
1979 * mode while disassociated - which is forbidden.
1981 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1982 "Failed to update SF upon disassociation\n");
1985 * If we get an assert during the connection (after the
1986 * station has been added, but before the vif is set
1987 * to associated), mac80211 will re-add the station and
1988 * then configure the vif. Since the vif is not
1989 * associated, we would remove the station here and
1990 * this would fail the recovery.
1992 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1995 * Remove AP station now that
1996 * the MAC is unassoc
1998 ret = iwl_mvm_rm_sta_id(mvm, vif,
2002 "failed to remove AP station\n");
2004 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2005 mvm->d0i3_ap_sta_id =
2006 IWL_MVM_INVALID_STA;
2007 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2010 /* remove quota for this interface */
2011 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2013 IWL_ERR(mvm, "failed to update quotas\n");
2016 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2018 /* this will take the cleared BSSID from bss_conf */
2019 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2022 "failed to update MAC %pM (clear after unassoc)\n",
2027 * The firmware tracks the MU-MIMO group on its own.
2028 * However, on HW restart we should restore this data.
2030 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2031 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2032 ret = iwl_mvm_update_mu_groups(mvm, vif);
2035 "failed to update VHT MU_MIMO groups\n");
2038 iwl_mvm_recalc_multicast(mvm);
2039 iwl_mvm_configure_bcast_filter(mvm);
2041 /* reset rssi values */
2042 mvmvif->bf_data.ave_beacon_signal = 0;
2044 iwl_mvm_bt_coex_vif_change(mvm);
2045 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2046 IEEE80211_SMPS_AUTOMATIC);
2047 if (fw_has_capa(&mvm->fw->ucode_capa,
2048 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2049 iwl_mvm_config_scan(mvm);
2052 if (changes & BSS_CHANGED_BEACON_INFO) {
2054 * We received a beacon from the associated AP so
2055 * remove the session protection.
2057 iwl_mvm_stop_session_protection(mvm, vif);
2059 iwl_mvm_sf_update(mvm, vif, false);
2060 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2063 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2065 * Send power command on every beacon change,
2066 * because we may have not enabled beacon abort yet.
2068 BSS_CHANGED_BEACON_INFO)) {
2069 ret = iwl_mvm_power_update_mac(mvm);
2071 IWL_ERR(mvm, "failed to update power mode\n");
2074 if (changes & BSS_CHANGED_TXPOWER) {
2075 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2077 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2080 if (changes & BSS_CHANGED_CQM) {
2081 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2082 /* reset cqm events tracking */
2083 mvmvif->bf_data.last_cqm_event = 0;
2084 if (mvmvif->bf_data.bf_enabled) {
2085 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2088 "failed to update CQM thresholds\n");
2092 if (changes & BSS_CHANGED_ARP_FILTER) {
2093 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2094 iwl_mvm_configure_bcast_filter(mvm);
2098 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2099 struct ieee80211_vif *vif)
2101 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2102 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2106 * iwl_mvm_mac_ctxt_add() might read directly from the device
2107 * (the system time), so make sure it is available.
2109 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2113 mutex_lock(&mvm->mutex);
2115 /* Send the beacon template */
2116 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2121 * Re-calculate the tsf id, as the master-slave relations depend on the
2122 * beacon interval, which was not known when the AP interface was added.
2124 if (vif->type == NL80211_IFTYPE_AP)
2125 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2127 mvmvif->ap_assoc_sta_count = 0;
2129 /* Add the mac context */
2130 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2134 /* Perform the binding */
2135 ret = iwl_mvm_binding_add_vif(mvm, vif);
2140 * This is not very nice, but the simplest:
2141 * For older FWs adding the mcast sta before the bcast station may
2142 * cause assert 0x2b00.
2143 * This is fixed in later FW so make the order of removal depend on
2146 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2147 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2151 * Send the bcast station. At this stage the TBTT and DTIM time
2152 * events are added and applied to the scheduler
2154 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2156 iwl_mvm_rm_mcast_sta(mvm, vif);
2161 * Send the bcast station. At this stage the TBTT and DTIM time
2162 * events are added and applied to the scheduler
2164 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2167 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2169 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2174 /* must be set before quota calculations */
2175 mvmvif->ap_ibss_active = true;
2177 /* power updated needs to be done before quotas */
2178 iwl_mvm_power_update_mac(mvm);
2180 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2182 goto out_quota_failed;
2184 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2185 if (vif->p2p && mvm->p2p_device_vif)
2186 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2188 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2190 iwl_mvm_bt_coex_vif_change(mvm);
2192 /* we don't support TDLS during DCM */
2193 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2194 iwl_mvm_teardown_tdls_peers(mvm);
2199 iwl_mvm_power_update_mac(mvm);
2200 mvmvif->ap_ibss_active = false;
2201 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2202 iwl_mvm_rm_mcast_sta(mvm, vif);
2204 iwl_mvm_binding_remove_vif(mvm, vif);
2206 iwl_mvm_mac_ctxt_remove(mvm, vif);
2208 mutex_unlock(&mvm->mutex);
2209 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2213 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2214 struct ieee80211_vif *vif)
2216 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2217 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2219 iwl_mvm_prepare_mac_removal(mvm, vif);
2221 mutex_lock(&mvm->mutex);
2223 /* Handle AP stop while in CSA */
2224 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2225 iwl_mvm_remove_time_event(mvm, mvmvif,
2226 &mvmvif->time_event_data);
2227 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2228 mvmvif->csa_countdown = false;
2231 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2232 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2233 mvm->csa_tx_block_bcn_timeout = 0;
2236 mvmvif->ap_ibss_active = false;
2237 mvm->ap_last_beacon_gp2 = 0;
2239 iwl_mvm_bt_coex_vif_change(mvm);
2241 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2243 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2244 if (vif->p2p && mvm->p2p_device_vif)
2245 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2247 iwl_mvm_update_quotas(mvm, false, NULL);
2250 * This is not very nice, but the simplest:
2251 * For older FWs removing the mcast sta before the bcast station may
2252 * cause assert 0x2b00.
2253 * This is fixed in later FW (which will stop beaconing when removing
2255 * So make the order of removal depend on the TLV
2257 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2258 iwl_mvm_rm_mcast_sta(mvm, vif);
2259 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2260 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2261 iwl_mvm_rm_mcast_sta(mvm, vif);
2262 iwl_mvm_binding_remove_vif(mvm, vif);
2264 iwl_mvm_power_update_mac(mvm);
2266 iwl_mvm_mac_ctxt_remove(mvm, vif);
2268 mutex_unlock(&mvm->mutex);
2272 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2273 struct ieee80211_vif *vif,
2274 struct ieee80211_bss_conf *bss_conf,
2277 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2279 /* Changes will be applied when the AP/IBSS is started */
2280 if (!mvmvif->ap_ibss_active)
2283 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2284 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2285 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2286 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2288 /* Need to send a new beacon template to the FW */
2289 if (changes & BSS_CHANGED_BEACON &&
2290 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2291 IWL_WARN(mvm, "Failed updating beacon data\n");
2293 if (changes & BSS_CHANGED_TXPOWER) {
2294 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2296 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2300 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2301 struct ieee80211_vif *vif,
2302 struct ieee80211_bss_conf *bss_conf,
2305 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2308 * iwl_mvm_bss_info_changed_station() might call
2309 * iwl_mvm_protect_session(), which reads directly from
2310 * the device (the system time), so make sure it is available.
2312 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2315 mutex_lock(&mvm->mutex);
2317 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2318 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2320 switch (vif->type) {
2321 case NL80211_IFTYPE_STATION:
2322 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2324 case NL80211_IFTYPE_AP:
2325 case NL80211_IFTYPE_ADHOC:
2326 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2328 case NL80211_IFTYPE_MONITOR:
2329 if (changes & BSS_CHANGED_MU_GROUPS)
2330 iwl_mvm_update_mu_groups(mvm, vif);
2333 /* shouldn't happen */
2337 mutex_unlock(&mvm->mutex);
2338 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2341 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2342 struct ieee80211_vif *vif,
2343 struct ieee80211_scan_request *hw_req)
2345 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2348 if (hw_req->req.n_channels == 0 ||
2349 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2352 mutex_lock(&mvm->mutex);
2353 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2354 mutex_unlock(&mvm->mutex);
2359 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2360 struct ieee80211_vif *vif)
2362 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2364 mutex_lock(&mvm->mutex);
2366 /* Due to a race condition, it's possible that mac80211 asks
2367 * us to stop a hw_scan when it's already stopped. This can
2368 * happen, for instance, if we stopped the scan ourselves,
2369 * called ieee80211_scan_completed() and the userspace called
2370 * cancel scan scan before ieee80211_scan_work() could run.
2371 * To handle that, simply return if the scan is not running.
2373 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2374 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2376 mutex_unlock(&mvm->mutex);
2380 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2381 struct ieee80211_sta *sta, u16 tids,
2383 enum ieee80211_frame_release_type reason,
2386 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2388 /* Called when we need to transmit (a) frame(s) from mac80211 */
2390 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2391 tids, more_data, false);
2395 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2396 struct ieee80211_sta *sta, u16 tids,
2398 enum ieee80211_frame_release_type reason,
2401 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2403 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2405 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2406 tids, more_data, true);
2409 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2410 enum sta_notify_cmd cmd,
2411 struct ieee80211_sta *sta)
2413 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2414 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2415 unsigned long txqs = 0, tids = 0;
2419 * If we have TVQM then we get too high queue numbers - luckily
2420 * we really shouldn't get here with that because such hardware
2421 * should have firmware supporting buffer station offload.
2423 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2426 spin_lock_bh(&mvmsta->lock);
2427 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2428 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2430 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2433 __set_bit(tid_data->txq_id, &txqs);
2435 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2438 __set_bit(tid, &tids);
2442 case STA_NOTIFY_SLEEP:
2443 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2444 ieee80211_sta_set_buffered(sta, tid, true);
2447 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2449 * The fw updates the STA to be asleep. Tx packets on the Tx
2450 * queues to this station will not be transmitted. The fw will
2451 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2454 case STA_NOTIFY_AWAKE:
2455 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2459 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2460 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2465 spin_unlock_bh(&mvmsta->lock);
2468 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2469 struct ieee80211_vif *vif,
2470 enum sta_notify_cmd cmd,
2471 struct ieee80211_sta *sta)
2473 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2476 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2478 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2479 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2480 struct ieee80211_sta *sta;
2481 struct iwl_mvm_sta *mvmsta;
2482 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2484 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2488 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2489 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2494 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2497 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2502 if (mvmsta->sleeping != sleeping) {
2503 mvmsta->sleeping = sleeping;
2504 __iwl_mvm_mac_sta_notify(mvm->hw,
2505 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2507 ieee80211_sta_ps_transition(sta, sleeping);
2511 switch (notif->type) {
2512 case IWL_MVM_PM_EVENT_AWAKE:
2513 case IWL_MVM_PM_EVENT_ASLEEP:
2515 case IWL_MVM_PM_EVENT_UAPSD:
2516 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2518 case IWL_MVM_PM_EVENT_PS_POLL:
2519 ieee80211_sta_pspoll(sta);
2529 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2530 struct ieee80211_vif *vif,
2531 struct ieee80211_sta *sta)
2533 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2534 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2537 * This is called before mac80211 does RCU synchronisation,
2538 * so here we already invalidate our internal RCU-protected
2539 * station pointer. The rest of the code will thus no longer
2540 * be able to find the station this way, and we don't rely
2541 * on further RCU synchronisation after the sta_state()
2542 * callback deleted the station.
2544 mutex_lock(&mvm->mutex);
2545 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2546 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2549 mutex_unlock(&mvm->mutex);
2552 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2557 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2558 struct iwl_mvm_tcm_mac *mdata;
2560 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2561 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2562 mdata->opened_rx_ba_sessions = false;
2565 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2568 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2569 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2574 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2575 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2579 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2580 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2581 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2586 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2590 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2591 struct ieee80211_vif *vif, u8 *peer_addr,
2592 enum nl80211_tdls_operation action)
2594 struct iwl_fw_dbg_trigger_tlv *trig;
2595 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2597 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS))
2600 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS);
2601 tdls_trig = (void *)trig->data;
2602 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
2603 ieee80211_vif_to_wdev(vif), trig))
2606 if (!(tdls_trig->action_bitmap & BIT(action)))
2609 if (tdls_trig->peer_mode &&
2610 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2613 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2614 "TDLS event occurred, peer %pM, action %d",
2618 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2619 struct iwl_mvm_sta *mvm_sta)
2621 struct iwl_mvm_tid_data *tid_data;
2622 struct sk_buff *skb;
2625 spin_lock_bh(&mvm_sta->lock);
2626 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2627 tid_data = &mvm_sta->tid_data[i];
2629 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2630 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2633 * The first deferred frame should've stopped the MAC
2634 * queues, so we should never get a second deferred
2635 * frame for the RA/TID.
2637 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
2638 ieee80211_free_txskb(mvm->hw, skb);
2641 spin_unlock_bh(&mvm_sta->lock);
2644 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2645 struct ieee80211_vif *vif,
2646 struct ieee80211_sta *sta,
2647 enum ieee80211_sta_state old_state,
2648 enum ieee80211_sta_state new_state)
2650 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2651 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2652 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2655 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2656 sta->addr, old_state, new_state);
2658 /* this would be a mac80211 bug ... but don't crash */
2659 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2663 * If we are in a STA removal flow and in DQA mode:
2665 * This is after the sync_rcu part, so the queues have already been
2666 * flushed. No more TXs on their way in mac80211's path, and no more in
2668 * Also, we won't be getting any new TX frames for this station.
2669 * What we might have are deferred TX frames that need to be taken care
2672 * Drop any still-queued deferred-frame before removing the STA, and
2673 * make sure the worker is no longer handling frames for this STA.
2675 if (old_state == IEEE80211_STA_NONE &&
2676 new_state == IEEE80211_STA_NOTEXIST) {
2677 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2678 flush_work(&mvm->add_stream_wk);
2681 * No need to make sure deferred TX indication is off since the
2682 * worker will already remove it if it was on
2686 mutex_lock(&mvm->mutex);
2687 /* track whether or not the station is associated */
2688 mvm_sta->sta_state = new_state;
2690 if (old_state == IEEE80211_STA_NOTEXIST &&
2691 new_state == IEEE80211_STA_NONE) {
2693 * Firmware bug - it'll crash if the beacon interval is less
2694 * than 16. We can't avoid connecting at all, so refuse the
2695 * station state change, this will cause mac80211 to abandon
2696 * attempts to connect to this AP, and eventually wpa_s will
2697 * blacklist the AP...
2699 if (vif->type == NL80211_IFTYPE_STATION &&
2700 vif->bss_conf.beacon_int < 16) {
2702 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2703 sta->addr, vif->bss_conf.beacon_int);
2710 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2711 IWL_MVM_TDLS_STA_COUNT ||
2712 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2713 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2718 ret = iwl_mvm_add_sta(mvm, vif, sta);
2719 if (sta->tdls && ret == 0) {
2720 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2721 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2722 NL80211_TDLS_SETUP);
2724 } else if (old_state == IEEE80211_STA_NONE &&
2725 new_state == IEEE80211_STA_AUTH) {
2727 * EBS may be disabled due to previous failures reported by FW.
2728 * Reset EBS status here assuming environment has been changed.
2730 mvm->last_ebs_successful = true;
2731 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2733 } else if (old_state == IEEE80211_STA_AUTH &&
2734 new_state == IEEE80211_STA_ASSOC) {
2735 if (vif->type == NL80211_IFTYPE_AP) {
2736 mvmvif->ap_assoc_sta_count++;
2737 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2740 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band);
2741 ret = iwl_mvm_update_sta(mvm, vif, sta);
2742 } else if (old_state == IEEE80211_STA_ASSOC &&
2743 new_state == IEEE80211_STA_AUTHORIZED) {
2745 /* we don't support TDLS during DCM */
2746 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2747 iwl_mvm_teardown_tdls_peers(mvm);
2750 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2751 NL80211_TDLS_ENABLE_LINK);
2753 /* enable beacon filtering */
2754 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2756 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band);
2759 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2760 new_state == IEEE80211_STA_ASSOC) {
2761 /* disable beacon filtering */
2762 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2764 } else if (old_state == IEEE80211_STA_ASSOC &&
2765 new_state == IEEE80211_STA_AUTH) {
2766 if (vif->type == NL80211_IFTYPE_AP) {
2767 mvmvif->ap_assoc_sta_count--;
2768 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2771 } else if (old_state == IEEE80211_STA_AUTH &&
2772 new_state == IEEE80211_STA_NONE) {
2774 } else if (old_state == IEEE80211_STA_NONE &&
2775 new_state == IEEE80211_STA_NOTEXIST) {
2776 ret = iwl_mvm_rm_sta(mvm, vif, sta);
2778 iwl_mvm_recalc_tdls_state(mvm, vif, false);
2779 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2780 NL80211_TDLS_DISABLE_LINK);
2786 mutex_unlock(&mvm->mutex);
2788 if (sta->tdls && ret == 0) {
2789 if (old_state == IEEE80211_STA_NOTEXIST &&
2790 new_state == IEEE80211_STA_NONE)
2791 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2792 else if (old_state == IEEE80211_STA_NONE &&
2793 new_state == IEEE80211_STA_NOTEXIST)
2794 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2800 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2802 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2804 mvm->rts_threshold = value;
2809 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2810 struct ieee80211_vif *vif,
2811 struct ieee80211_sta *sta, u32 changed)
2813 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2815 if (vif->type == NL80211_IFTYPE_STATION &&
2816 changed & IEEE80211_RC_NSS_CHANGED)
2817 iwl_mvm_sf_update(mvm, vif, false);
2820 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2821 struct ieee80211_vif *vif, u16 ac,
2822 const struct ieee80211_tx_queue_params *params)
2824 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2825 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2827 mvmvif->queue_params[ac] = *params;
2830 * No need to update right away, we'll get BSS_CHANGED_QOS
2831 * The exception is P2P_DEVICE interface which needs immediate update.
2833 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2836 mutex_lock(&mvm->mutex);
2837 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2838 mutex_unlock(&mvm->mutex);
2844 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2845 struct ieee80211_vif *vif,
2848 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2849 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
2850 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
2853 * iwl_mvm_protect_session() reads directly from the device
2854 * (the system time), so make sure it is available.
2856 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2859 if (req_duration > duration)
2860 duration = req_duration;
2862 mutex_lock(&mvm->mutex);
2863 /* Try really hard to protect the session and hear a beacon */
2864 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
2865 mutex_unlock(&mvm->mutex);
2867 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
2870 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2871 struct ieee80211_vif *vif,
2872 struct cfg80211_sched_scan_request *req,
2873 struct ieee80211_scan_ies *ies)
2875 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2879 mutex_lock(&mvm->mutex);
2881 if (!vif->bss_conf.idle) {
2886 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
2889 mutex_unlock(&mvm->mutex);
2893 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2894 struct ieee80211_vif *vif)
2896 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2899 mutex_lock(&mvm->mutex);
2901 /* Due to a race condition, it's possible that mac80211 asks
2902 * us to stop a sched_scan when it's already stopped. This
2903 * can happen, for instance, if we stopped the scan ourselves,
2904 * called ieee80211_sched_scan_stopped() and the userspace called
2905 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
2906 * could run. To handle this, simply return if the scan is
2909 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
2910 mutex_unlock(&mvm->mutex);
2914 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
2915 mutex_unlock(&mvm->mutex);
2916 iwl_mvm_wait_for_async_handlers(mvm);
2921 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2922 enum set_key_cmd cmd,
2923 struct ieee80211_vif *vif,
2924 struct ieee80211_sta *sta,
2925 struct ieee80211_key_conf *key)
2927 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2928 struct iwl_mvm_sta *mvmsta;
2929 struct iwl_mvm_key_pn *ptk_pn;
2930 int keyidx = key->keyidx;
2934 if (iwlwifi_mod_params.swcrypto) {
2935 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2939 switch (key->cipher) {
2940 case WLAN_CIPHER_SUITE_TKIP:
2941 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2942 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2944 case WLAN_CIPHER_SUITE_CCMP:
2945 case WLAN_CIPHER_SUITE_GCMP:
2946 case WLAN_CIPHER_SUITE_GCMP_256:
2947 if (!iwl_mvm_has_new_tx_api(mvm))
2948 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2950 case WLAN_CIPHER_SUITE_AES_CMAC:
2951 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2952 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2953 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
2955 case WLAN_CIPHER_SUITE_WEP40:
2956 case WLAN_CIPHER_SUITE_WEP104:
2957 /* For non-client mode, only use WEP keys for TX as we probably
2958 * don't have a station yet anyway and would then have to keep
2959 * track of the keys, linking them to each of the clients/peers
2960 * as they appear. For now, don't do that, for performance WEP
2961 * offload doesn't really matter much, but we need it for some
2962 * other offload features in client mode.
2964 if (vif->type != NL80211_IFTYPE_STATION)
2968 /* currently FW supports only one optional cipher scheme */
2969 if (hw->n_cipher_schemes &&
2970 hw->cipher_schemes->cipher == key->cipher)
2971 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2976 mutex_lock(&mvm->mutex);
2980 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2981 vif->type == NL80211_IFTYPE_AP) && !sta) {
2983 * GTK on AP interface is a TX-only key, return 0;
2984 * on IBSS they're per-station and because we're lazy
2985 * we don't support them for RX, so do the same.
2986 * CMAC/GMAC in AP/IBSS modes must be done in software.
2988 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2989 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2990 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
2995 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
2996 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
2997 !iwl_mvm_has_new_tx_api(mvm)) {
2998 key->hw_key_idx = STA_KEY_IDX_INVALID;
3003 /* During FW restart, in order to restore the state as it was,
3004 * don't try to reprogram keys we previously failed for.
3006 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3007 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3008 IWL_DEBUG_MAC80211(mvm,
3009 "skip invalid idx key programming during restart\n");
3014 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3015 sta && iwl_mvm_has_new_rx_api(mvm) &&
3016 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3017 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3018 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3019 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3020 struct ieee80211_key_seq seq;
3023 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3024 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3025 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3026 mvm->trans->num_rx_queues),
3033 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3034 ieee80211_get_key_rx_seq(key, tid, &seq);
3035 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3036 memcpy(ptk_pn->q[q].pn[tid],
3038 IEEE80211_CCMP_PN_LEN);
3041 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3044 /* in HW restart reuse the index, otherwise request a new one */
3045 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3046 key_offset = key->hw_key_idx;
3048 key_offset = STA_KEY_IDX_INVALID;
3050 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3051 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3053 IWL_WARN(mvm, "set key failed\n");
3055 * can't add key for RX, but we don't need it
3056 * in the device for TX so still return 0
3058 key->hw_key_idx = STA_KEY_IDX_INVALID;
3064 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3069 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3070 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3071 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3072 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3073 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3074 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3075 ptk_pn = rcu_dereference_protected(
3076 mvmsta->ptk_pn[keyidx],
3077 lockdep_is_held(&mvm->mutex));
3078 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3080 kfree_rcu(ptk_pn, rcu_head);
3083 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3084 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3090 mutex_unlock(&mvm->mutex);
3094 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3095 struct ieee80211_vif *vif,
3096 struct ieee80211_key_conf *keyconf,
3097 struct ieee80211_sta *sta,
3098 u32 iv32, u16 *phase1key)
3100 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3102 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3105 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3109 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3110 struct iwl_rx_packet *pkt, void *data)
3112 struct iwl_mvm *mvm =
3113 container_of(notif_wait, struct iwl_mvm, notif_wait);
3114 struct iwl_hs20_roc_res *resp;
3115 int resp_len = iwl_rx_packet_payload_len(pkt);
3116 struct iwl_mvm_time_event_data *te_data = data;
3118 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3121 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3122 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3126 resp = (void *)pkt->data;
3129 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3130 resp->status, resp->event_unique_id);
3132 te_data->uid = le32_to_cpu(resp->event_unique_id);
3133 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3136 spin_lock_bh(&mvm->time_event_lock);
3137 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3138 spin_unlock_bh(&mvm->time_event_lock);
3143 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3144 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3145 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3146 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3147 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3148 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3149 struct ieee80211_channel *channel,
3150 struct ieee80211_vif *vif,
3153 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3154 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3155 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3156 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3157 struct iwl_notification_wait wait_time_event;
3158 u32 dtim_interval = vif->bss_conf.dtim_period *
3159 vif->bss_conf.beacon_int;
3161 struct iwl_hs20_roc_req aux_roc_req = {
3162 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3164 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3165 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3166 /* Set the channel info data */
3167 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3168 PHY_BAND_24 : PHY_BAND_5,
3169 .channel_info.channel = channel->hw_value,
3170 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3171 /* Set the time and duration */
3172 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3175 delay = AUX_ROC_MIN_DELAY;
3176 req_dur = MSEC_TO_TU(duration);
3179 * If we are associated we want the delay time to be at least one
3180 * dtim interval so that the FW can wait until after the DTIM and
3181 * then start the time event, this will potentially allow us to
3182 * remain off-channel for the max duration.
3183 * Since we want to use almost a whole dtim interval we would also
3184 * like the delay to be for 2-3 dtim intervals, in case there are
3185 * other time events with higher priority.
3187 if (vif->bss_conf.assoc) {
3188 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3189 /* We cannot remain off-channel longer than the DTIM interval */
3190 if (dtim_interval <= req_dur) {
3191 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3192 if (req_dur <= AUX_ROC_MIN_DURATION)
3193 req_dur = dtim_interval -
3194 AUX_ROC_MIN_SAFETY_BUFFER;
3198 aux_roc_req.duration = cpu_to_le32(req_dur);
3199 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3202 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3203 channel->hw_value, req_dur, duration, delay,
3205 /* Set the node address */
3206 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3208 lockdep_assert_held(&mvm->mutex);
3210 spin_lock_bh(&mvm->time_event_lock);
3212 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3213 spin_unlock_bh(&mvm->time_event_lock);
3218 te_data->duration = duration;
3219 te_data->id = HOT_SPOT_CMD;
3221 spin_unlock_bh(&mvm->time_event_lock);
3224 * Use a notification wait, which really just processes the
3225 * command response and doesn't wait for anything, in order
3226 * to be able to process the response and get the UID inside
3227 * the RX path. Using CMD_WANT_SKB doesn't work because it
3228 * stores the buffer and then wakes up this thread, by which
3229 * time another notification (that the time event started)
3230 * might already be processed unsuccessfully.
3232 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3233 time_event_response,
3234 ARRAY_SIZE(time_event_response),
3235 iwl_mvm_rx_aux_roc, te_data);
3237 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3241 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3242 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3246 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3247 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3248 /* should never fail */
3253 spin_lock_bh(&mvm->time_event_lock);
3254 iwl_mvm_te_clear_data(mvm, te_data);
3255 spin_unlock_bh(&mvm->time_event_lock);
3261 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3262 struct ieee80211_vif *vif,
3263 struct ieee80211_channel *channel,
3265 enum ieee80211_roc_type type)
3267 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3268 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3269 struct cfg80211_chan_def chandef;
3270 struct iwl_mvm_phy_ctxt *phy_ctxt;
3273 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3277 * Flush the done work, just in case it's still pending, so that
3278 * the work it does can complete and we can accept new frames.
3280 flush_work(&mvm->roc_done_wk);
3282 mutex_lock(&mvm->mutex);
3284 switch (vif->type) {
3285 case NL80211_IFTYPE_STATION:
3286 if (fw_has_capa(&mvm->fw->ucode_capa,
3287 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3288 /* Use aux roc framework (HS20) */
3289 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3293 IWL_ERR(mvm, "hotspot not supported\n");
3296 case NL80211_IFTYPE_P2P_DEVICE:
3300 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3305 for (i = 0; i < NUM_PHY_CTX; i++) {
3306 phy_ctxt = &mvm->phy_ctxts[i];
3307 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3310 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3312 * Unbind the P2P_DEVICE from the current PHY context,
3313 * and if the PHY context is not used remove it.
3315 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3316 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3319 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3321 /* Bind the P2P_DEVICE to the current PHY Context */
3322 mvmvif->phy_ctxt = phy_ctxt;
3324 ret = iwl_mvm_binding_add_vif(mvm, vif);
3325 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3328 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3329 goto schedule_time_event;
3333 /* Need to update the PHY context only if the ROC channel changed */
3334 if (channel == mvmvif->phy_ctxt->channel)
3335 goto schedule_time_event;
3337 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3340 * Change the PHY context configuration as it is currently referenced
3341 * only by the P2P Device MAC
3343 if (mvmvif->phy_ctxt->ref == 1) {
3344 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3350 * The PHY context is shared with other MACs. Need to remove the
3351 * P2P Device from the binding, allocate an new PHY context and
3352 * create a new binding
3354 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3360 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3363 IWL_ERR(mvm, "Failed to change PHY context\n");
3367 /* Unbind the P2P_DEVICE from the current PHY context */
3368 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3369 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3372 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3374 /* Bind the P2P_DEVICE to the new allocated PHY context */
3375 mvmvif->phy_ctxt = phy_ctxt;
3377 ret = iwl_mvm_binding_add_vif(mvm, vif);
3378 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3381 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3384 schedule_time_event:
3385 /* Schedule the time events */
3386 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3389 mutex_unlock(&mvm->mutex);
3390 IWL_DEBUG_MAC80211(mvm, "leave\n");
3394 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3396 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3398 IWL_DEBUG_MAC80211(mvm, "enter\n");
3400 mutex_lock(&mvm->mutex);
3401 iwl_mvm_stop_roc(mvm);
3402 mutex_unlock(&mvm->mutex);
3404 IWL_DEBUG_MAC80211(mvm, "leave\n");
3408 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3409 struct ieee80211_chanctx_conf *ctx)
3411 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3412 struct iwl_mvm_phy_ctxt *phy_ctxt;
3415 lockdep_assert_held(&mvm->mutex);
3417 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3419 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3425 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3426 ctx->rx_chains_static,
3427 ctx->rx_chains_dynamic);
3429 IWL_ERR(mvm, "Failed to add PHY context\n");
3433 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3434 *phy_ctxt_id = phy_ctxt->id;
3439 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3440 struct ieee80211_chanctx_conf *ctx)
3442 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3445 mutex_lock(&mvm->mutex);
3446 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3447 mutex_unlock(&mvm->mutex);
3452 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3453 struct ieee80211_chanctx_conf *ctx)
3455 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3456 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3458 lockdep_assert_held(&mvm->mutex);
3460 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3463 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3464 struct ieee80211_chanctx_conf *ctx)
3466 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3468 mutex_lock(&mvm->mutex);
3469 __iwl_mvm_remove_chanctx(mvm, ctx);
3470 mutex_unlock(&mvm->mutex);
3473 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3474 struct ieee80211_chanctx_conf *ctx,
3477 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3478 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3479 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3481 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3482 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3483 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3484 IEEE80211_CHANCTX_CHANGE_RADAR |
3485 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3486 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3487 phy_ctxt->ref, changed))
3490 mutex_lock(&mvm->mutex);
3492 /* we are only changing the min_width, may be a noop */
3493 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
3494 if (phy_ctxt->width == ctx->min_def.width)
3497 /* we are just toggling between 20_NOHT and 20 */
3498 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
3499 ctx->min_def.width <= NL80211_CHAN_WIDTH_20)
3503 iwl_mvm_bt_coex_vif_change(mvm);
3504 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3505 ctx->rx_chains_static,
3506 ctx->rx_chains_dynamic);
3509 mutex_unlock(&mvm->mutex);
3512 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3513 struct ieee80211_vif *vif,
3514 struct ieee80211_chanctx_conf *ctx,
3515 bool switching_chanctx)
3517 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3518 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3519 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3522 lockdep_assert_held(&mvm->mutex);
3524 mvmvif->phy_ctxt = phy_ctxt;
3526 switch (vif->type) {
3527 case NL80211_IFTYPE_AP:
3528 /* only needed if we're switching chanctx (i.e. during CSA) */
3529 if (switching_chanctx) {
3530 mvmvif->ap_ibss_active = true;
3533 case NL80211_IFTYPE_ADHOC:
3535 * The AP binding flow is handled as part of the start_ap flow
3536 * (in bss_info_changed), similarly for IBSS.
3540 case NL80211_IFTYPE_STATION:
3541 mvmvif->csa_bcn_pending = false;
3543 case NL80211_IFTYPE_MONITOR:
3544 /* always disable PS when a monitor interface is active */
3545 mvmvif->ps_disabled = true;
3552 ret = iwl_mvm_binding_add_vif(mvm, vif);
3557 * Power state must be updated before quotas,
3558 * otherwise fw will complain.
3560 iwl_mvm_power_update_mac(mvm);
3562 /* Setting the quota at this stage is only required for monitor
3563 * interfaces. For the other types, the bss_info changed flow
3564 * will handle quota settings.
3566 if (vif->type == NL80211_IFTYPE_MONITOR) {
3567 mvmvif->monitor_active = true;
3568 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3570 goto out_remove_binding;
3572 ret = iwl_mvm_add_snif_sta(mvm, vif);
3574 goto out_remove_binding;
3578 /* Handle binding during CSA */
3579 if (vif->type == NL80211_IFTYPE_AP) {
3580 iwl_mvm_update_quotas(mvm, false, NULL);
3581 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3584 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3585 u32 duration = 3 * vif->bss_conf.beacon_int;
3587 /* iwl_mvm_protect_session() reads directly from the
3588 * device (the system time), so make sure it is
3591 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3593 goto out_remove_binding;
3595 /* Protect the session to make sure we hear the first
3596 * beacon on the new channel.
3598 mvmvif->csa_bcn_pending = true;
3599 iwl_mvm_protect_session(mvm, vif, duration, duration,
3600 vif->bss_conf.beacon_int / 2,
3603 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3605 iwl_mvm_update_quotas(mvm, false, NULL);
3611 iwl_mvm_binding_remove_vif(mvm, vif);
3612 iwl_mvm_power_update_mac(mvm);
3615 mvmvif->phy_ctxt = NULL;
3618 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3619 struct ieee80211_vif *vif,
3620 struct ieee80211_chanctx_conf *ctx)
3622 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3625 mutex_lock(&mvm->mutex);
3626 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3627 mutex_unlock(&mvm->mutex);
3632 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3633 struct ieee80211_vif *vif,
3634 struct ieee80211_chanctx_conf *ctx,
3635 bool switching_chanctx)
3637 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3638 struct ieee80211_vif *disabled_vif = NULL;
3640 lockdep_assert_held(&mvm->mutex);
3642 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3644 switch (vif->type) {
3645 case NL80211_IFTYPE_ADHOC:
3647 case NL80211_IFTYPE_MONITOR:
3648 mvmvif->monitor_active = false;
3649 mvmvif->ps_disabled = false;
3650 iwl_mvm_rm_snif_sta(mvm, vif);
3652 case NL80211_IFTYPE_AP:
3653 /* This part is triggered only during CSA */
3654 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3657 mvmvif->csa_countdown = false;
3659 /* Set CS bit on all the stations */
3660 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3662 /* Save blocked iface, the timeout is set on the next beacon */
3663 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3665 mvmvif->ap_ibss_active = false;
3667 case NL80211_IFTYPE_STATION:
3668 if (!switching_chanctx)
3673 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3679 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3680 iwl_mvm_binding_remove_vif(mvm, vif);
3683 mvmvif->phy_ctxt = NULL;
3684 iwl_mvm_power_update_mac(mvm);
3687 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3688 struct ieee80211_vif *vif,
3689 struct ieee80211_chanctx_conf *ctx)
3691 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3693 mutex_lock(&mvm->mutex);
3694 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3695 mutex_unlock(&mvm->mutex);
3699 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3700 struct ieee80211_vif_chanctx_switch *vifs)
3704 mutex_lock(&mvm->mutex);
3705 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3706 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3708 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3710 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3714 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3718 "failed to assign new_ctx during channel switch\n");
3722 /* we don't support TDLS during DCM - can be caused by channel switch */
3723 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3724 iwl_mvm_teardown_tdls_peers(mvm);
3729 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3732 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3733 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3737 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3739 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3746 /* things keep failing, better restart the hw */
3747 iwl_mvm_nic_restart(mvm, false);
3750 mutex_unlock(&mvm->mutex);
3756 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3757 struct ieee80211_vif_chanctx_switch *vifs)
3761 mutex_lock(&mvm->mutex);
3762 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3764 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3768 "failed to assign new_ctx during channel switch\n");
3775 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3777 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3784 /* things keep failing, better restart the hw */
3785 iwl_mvm_nic_restart(mvm, false);
3788 mutex_unlock(&mvm->mutex);
3793 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3794 struct ieee80211_vif_chanctx_switch *vifs,
3796 enum ieee80211_chanctx_switch_mode mode)
3798 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3801 /* we only support a single-vif right now */
3806 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3807 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3809 case CHANCTX_SWMODE_REASSIGN_VIF:
3810 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
3820 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
3822 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3824 return mvm->ibss_manager;
3827 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3828 struct ieee80211_sta *sta,
3831 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3832 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3834 if (!mvm_sta || !mvm_sta->vif) {
3835 IWL_ERR(mvm, "Station is not associated to a vif\n");
3839 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3842 #ifdef CONFIG_NL80211_TESTMODE
3843 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3844 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3845 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
3846 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
3849 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3850 struct ieee80211_vif *vif,
3851 void *data, int len)
3853 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3857 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
3862 if (!tb[IWL_MVM_TM_ATTR_CMD])
3865 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3866 case IWL_MVM_TM_CMD_SET_NOA:
3867 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3868 !vif->bss_conf.enable_beacon ||
3869 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3872 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3873 if (noa_duration >= vif->bss_conf.beacon_int)
3876 mvm->noa_duration = noa_duration;
3879 return iwl_mvm_update_quotas(mvm, true, NULL);
3880 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3881 /* must be associated client vif - ignore authorized */
3882 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3883 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3884 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3887 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
3888 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3889 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3895 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3896 struct ieee80211_vif *vif,
3897 void *data, int len)
3899 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3902 mutex_lock(&mvm->mutex);
3903 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3904 mutex_unlock(&mvm->mutex);
3910 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3911 struct ieee80211_vif *vif,
3912 struct ieee80211_channel_switch *chsw)
3914 /* By implementing this operation, we prevent mac80211 from
3915 * starting its own channel switch timer, so that we can call
3916 * ieee80211_chswitch_done() ourselves at the right time
3917 * (which is when the absence time event starts).
3920 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3921 "dummy channel switch op\n");
3924 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3925 struct ieee80211_vif *vif,
3926 struct ieee80211_channel_switch *chsw)
3928 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3929 struct ieee80211_vif *csa_vif;
3930 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3934 mutex_lock(&mvm->mutex);
3936 mvmvif->csa_failed = false;
3938 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
3939 chsw->chandef.center_freq1);
3941 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
3942 ieee80211_vif_to_wdev(vif),
3943 FW_DBG_TRIGGER_CHANNEL_SWITCH);
3945 switch (vif->type) {
3946 case NL80211_IFTYPE_AP:
3948 rcu_dereference_protected(mvm->csa_vif,
3949 lockdep_is_held(&mvm->mutex));
3950 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3951 "Another CSA is already in progress")) {
3956 /* we still didn't unblock tx. prevent new CS meanwhile */
3957 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
3958 lockdep_is_held(&mvm->mutex))) {
3963 rcu_assign_pointer(mvm->csa_vif, vif);
3965 if (WARN_ONCE(mvmvif->csa_countdown,
3966 "Previous CSA countdown didn't complete")) {
3971 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
3974 case NL80211_IFTYPE_STATION:
3975 /* Schedule the time event to a bit before beacon 1,
3976 * to make sure we're in the new channel when the
3977 * GO/AP arrives. In case count <= 1 immediately schedule the
3978 * TE (this might result with some packet loss or connection
3981 if (chsw->count <= 1)
3984 apply_time = chsw->device_timestamp +
3985 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3986 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
3989 iwl_mvm_csa_client_absent(mvm, vif);
3991 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
3993 if (mvmvif->bf_data.bf_enabled) {
3994 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4004 mvmvif->ps_disabled = true;
4006 ret = iwl_mvm_power_update_ps(mvm);
4010 /* we won't be on this channel any longer */
4011 iwl_mvm_teardown_tdls_peers(mvm);
4014 mutex_unlock(&mvm->mutex);
4019 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
4020 struct ieee80211_vif *vif)
4022 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4023 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4026 mutex_lock(&mvm->mutex);
4028 if (mvmvif->csa_failed) {
4029 mvmvif->csa_failed = false;
4034 if (vif->type == NL80211_IFTYPE_STATION) {
4035 struct iwl_mvm_sta *mvmsta;
4037 mvmvif->csa_bcn_pending = false;
4038 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
4041 if (WARN_ON(!mvmsta)) {
4046 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
4048 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4050 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4054 iwl_mvm_stop_session_protection(mvm, vif);
4057 mvmvif->ps_disabled = false;
4059 ret = iwl_mvm_power_update_ps(mvm);
4062 mutex_unlock(&mvm->mutex);
4067 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4071 if (!iwl_mvm_has_new_tx_api(mvm)) {
4073 mutex_lock(&mvm->mutex);
4074 iwl_mvm_flush_tx_path(mvm,
4075 iwl_mvm_flushable_queues(mvm) & queues, 0);
4076 mutex_unlock(&mvm->mutex);
4078 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4083 mutex_lock(&mvm->mutex);
4084 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4085 struct ieee80211_sta *sta;
4087 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4088 lockdep_is_held(&mvm->mutex));
4089 if (IS_ERR_OR_NULL(sta))
4093 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4095 iwl_mvm_wait_sta_queues_empty(mvm,
4096 iwl_mvm_sta_from_mac80211(sta));
4098 mutex_unlock(&mvm->mutex);
4101 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4102 struct ieee80211_vif *vif, u32 queues, bool drop)
4104 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4105 struct iwl_mvm_vif *mvmvif;
4106 struct iwl_mvm_sta *mvmsta;
4107 struct ieee80211_sta *sta;
4112 iwl_mvm_flush_no_vif(mvm, queues, drop);
4116 if (vif->type != NL80211_IFTYPE_STATION)
4119 /* Make sure we're done with the deferred traffic before flushing */
4120 flush_work(&mvm->add_stream_wk);
4122 mutex_lock(&mvm->mutex);
4123 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4125 /* flush the AP-station and all TDLS peers */
4126 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4127 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4128 lockdep_is_held(&mvm->mutex));
4129 if (IS_ERR_OR_NULL(sta))
4132 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4133 if (mvmsta->vif != vif)
4136 /* make sure only TDLS peers or the AP are flushed */
4137 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4140 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4141 IWL_ERR(mvm, "flush request fail\n");
4143 msk |= mvmsta->tfd_queue_msk;
4144 if (iwl_mvm_has_new_tx_api(mvm))
4145 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4149 mutex_unlock(&mvm->mutex);
4151 /* this can take a while, and we may need/want other operations
4152 * to succeed while doing this, so do it without the mutex held
4154 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4155 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4158 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4159 struct survey_info *survey)
4161 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4164 memset(survey, 0, sizeof(*survey));
4166 /* only support global statistics right now */
4170 if (!fw_has_capa(&mvm->fw->ucode_capa,
4171 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4174 mutex_lock(&mvm->mutex);
4176 if (iwl_mvm_firmware_running(mvm)) {
4177 ret = iwl_mvm_request_statistics(mvm, false);
4182 survey->filled = SURVEY_INFO_TIME |
4183 SURVEY_INFO_TIME_RX |
4184 SURVEY_INFO_TIME_TX |
4185 SURVEY_INFO_TIME_SCAN;
4186 survey->time = mvm->accu_radio_stats.on_time_rf +
4187 mvm->radio_stats.on_time_rf;
4188 do_div(survey->time, USEC_PER_MSEC);
4190 survey->time_rx = mvm->accu_radio_stats.rx_time +
4191 mvm->radio_stats.rx_time;
4192 do_div(survey->time_rx, USEC_PER_MSEC);
4194 survey->time_tx = mvm->accu_radio_stats.tx_time +
4195 mvm->radio_stats.tx_time;
4196 do_div(survey->time_tx, USEC_PER_MSEC);
4198 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4199 mvm->radio_stats.on_time_scan;
4200 do_div(survey->time_scan, USEC_PER_MSEC);
4204 mutex_unlock(&mvm->mutex);
4208 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4209 struct ieee80211_vif *vif,
4210 struct ieee80211_sta *sta,
4211 struct station_info *sinfo)
4213 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4214 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4215 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4217 if (mvmsta->avg_energy) {
4218 sinfo->signal_avg = mvmsta->avg_energy;
4219 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
4222 if (!fw_has_capa(&mvm->fw->ucode_capa,
4223 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4226 /* if beacon filtering isn't on mac80211 does it anyway */
4227 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4230 if (!vif->bss_conf.assoc)
4233 mutex_lock(&mvm->mutex);
4235 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4238 if (iwl_mvm_request_statistics(mvm, false))
4241 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4242 mvmvif->beacon_stats.accu_num_beacons;
4243 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX);
4244 if (mvmvif->beacon_stats.avg_signal) {
4245 /* firmware only reports a value after RXing a few beacons */
4246 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4247 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4250 mutex_unlock(&mvm->mutex);
4253 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4254 struct ieee80211_vif *vif,
4255 const struct ieee80211_event *event)
4257 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4259 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4261 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4264 struct iwl_fw_dbg_trigger_tlv *trig;
4265 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4267 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
4270 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
4271 trig_mlme = (void *)trig->data;
4272 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4273 ieee80211_vif_to_wdev(vif), trig))
4276 if (event->u.mlme.data == ASSOC_EVENT) {
4277 if (event->u.mlme.status == MLME_DENIED)
4278 CHECK_MLME_TRIGGER(stop_assoc_denied,
4279 "DENIED ASSOC: reason %d",
4280 event->u.mlme.reason);
4281 else if (event->u.mlme.status == MLME_TIMEOUT)
4282 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4284 } else if (event->u.mlme.data == AUTH_EVENT) {
4285 if (event->u.mlme.status == MLME_DENIED)
4286 CHECK_MLME_TRIGGER(stop_auth_denied,
4287 "DENIED AUTH: reason %d",
4288 event->u.mlme.reason);
4289 else if (event->u.mlme.status == MLME_TIMEOUT)
4290 CHECK_MLME_TRIGGER(stop_auth_timeout,
4292 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4293 CHECK_MLME_TRIGGER(stop_rx_deauth,
4294 "DEAUTH RX %d", event->u.mlme.reason);
4295 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4296 CHECK_MLME_TRIGGER(stop_tx_deauth,
4297 "DEAUTH TX %d", event->u.mlme.reason);
4299 #undef CHECK_MLME_TRIGGER
4302 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4303 struct ieee80211_vif *vif,
4304 const struct ieee80211_event *event)
4306 struct iwl_fw_dbg_trigger_tlv *trig;
4307 struct iwl_fw_dbg_trigger_ba *ba_trig;
4309 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
4312 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
4313 ba_trig = (void *)trig->data;
4314 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4315 ieee80211_vif_to_wdev(vif), trig))
4318 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4321 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4322 "BAR received from %pM, tid %d, ssn %d",
4323 event->u.ba.sta->addr, event->u.ba.tid,
4327 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4328 struct ieee80211_vif *vif,
4329 const struct ieee80211_event *event)
4331 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4333 switch (event->type) {
4335 iwl_mvm_event_mlme_callback(mvm, vif, event);
4338 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4340 case BA_FRAME_TIMEOUT:
4341 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
4349 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4350 struct iwl_mvm_internal_rxq_notif *notif,
4353 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4356 lockdep_assert_held(&mvm->mutex);
4358 if (!iwl_mvm_has_new_rx_api(mvm))
4361 notif->cookie = mvm->queue_sync_cookie;
4364 atomic_set(&mvm->queue_sync_counter,
4365 mvm->trans->num_rx_queues);
4367 /* TODO - remove this when we have RXQ config API */
4368 if (mvm->trans->cfg->device_family == IWL_DEVICE_FAMILY_22000) {
4371 atomic_set(&mvm->queue_sync_counter, 1);
4374 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4376 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4381 ret = wait_event_timeout(mvm->rx_sync_waitq,
4382 atomic_read(&mvm->queue_sync_counter) == 0 ||
4383 iwl_mvm_is_radio_killed(mvm),
4385 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4389 atomic_set(&mvm->queue_sync_counter, 0);
4390 mvm->queue_sync_cookie++;
4393 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4395 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4396 struct iwl_mvm_internal_rxq_notif data = {
4397 .type = IWL_MVM_RXQ_EMPTY,
4401 mutex_lock(&mvm->mutex);
4402 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
4403 mutex_unlock(&mvm->mutex);
4406 const struct ieee80211_ops iwl_mvm_hw_ops = {
4407 .tx = iwl_mvm_mac_tx,
4408 .ampdu_action = iwl_mvm_mac_ampdu_action,
4409 .start = iwl_mvm_mac_start,
4410 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
4411 .stop = iwl_mvm_mac_stop,
4412 .add_interface = iwl_mvm_mac_add_interface,
4413 .remove_interface = iwl_mvm_mac_remove_interface,
4414 .config = iwl_mvm_mac_config,
4415 .prepare_multicast = iwl_mvm_prepare_multicast,
4416 .configure_filter = iwl_mvm_configure_filter,
4417 .config_iface_filter = iwl_mvm_config_iface_filter,
4418 .bss_info_changed = iwl_mvm_bss_info_changed,
4419 .hw_scan = iwl_mvm_mac_hw_scan,
4420 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
4421 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
4422 .sta_state = iwl_mvm_mac_sta_state,
4423 .sta_notify = iwl_mvm_mac_sta_notify,
4424 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
4425 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
4426 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
4427 .sta_rc_update = iwl_mvm_sta_rc_update,
4428 .conf_tx = iwl_mvm_mac_conf_tx,
4429 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
4430 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
4431 .flush = iwl_mvm_mac_flush,
4432 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4433 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
4434 .set_key = iwl_mvm_mac_set_key,
4435 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4436 .remain_on_channel = iwl_mvm_roc,
4437 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
4438 .add_chanctx = iwl_mvm_add_chanctx,
4439 .remove_chanctx = iwl_mvm_remove_chanctx,
4440 .change_chanctx = iwl_mvm_change_chanctx,
4441 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4442 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
4443 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
4445 .start_ap = iwl_mvm_start_ap_ibss,
4446 .stop_ap = iwl_mvm_stop_ap_ibss,
4447 .join_ibss = iwl_mvm_start_ap_ibss,
4448 .leave_ibss = iwl_mvm_stop_ap_ibss,
4450 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4452 .set_tim = iwl_mvm_set_tim,
4454 .channel_switch = iwl_mvm_channel_switch,
4455 .pre_channel_switch = iwl_mvm_pre_channel_switch,
4456 .post_channel_switch = iwl_mvm_post_channel_switch,
4458 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4459 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4460 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4462 .event_callback = iwl_mvm_mac_event_callback,
4464 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4466 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4468 #ifdef CONFIG_PM_SLEEP
4470 .suspend = iwl_mvm_suspend,
4471 .resume = iwl_mvm_resume,
4472 .set_wakeup = iwl_mvm_set_wakeup,
4473 .set_rekey_data = iwl_mvm_set_rekey_data,
4474 #if IS_ENABLED(CONFIG_IPV6)
4475 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4477 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4479 .get_survey = iwl_mvm_mac_get_survey,
4480 .sta_statistics = iwl_mvm_mac_sta_statistics,
4481 #ifdef CONFIG_IWLWIFI_DEBUGFS
4482 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,