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_PM_SLEEP
119 static const struct nl80211_wowlan_tcp_data_token_feature
120 iwl_mvm_wowlan_tcp_token_feature = {
123 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
126 static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
127 .tok = &iwl_mvm_wowlan_tcp_token_feature,
128 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
129 sizeof(struct ethhdr) -
130 sizeof(struct iphdr) -
131 sizeof(struct tcphdr),
132 .data_interval_max = 65535, /* __le16 in API */
133 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
134 sizeof(struct ethhdr) -
135 sizeof(struct iphdr) -
136 sizeof(struct tcphdr),
141 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
143 * Use the reserved field to indicate magic values.
144 * these values will only be used internally by the driver,
145 * and won't make it to the fw (reserved will be 0).
146 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
147 * be the vif's ip address. in case there is not a single
148 * ip address (0, or more than 1), this attribute will
150 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
151 * the LSB bytes of the vif's mac address
154 BC_FILTER_MAGIC_NONE = 0,
159 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
163 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
166 /* frame type - arp, hw type - ethernet */
168 BCAST_FILTER_OFFSET_PAYLOAD_START,
169 .offset = sizeof(rfc1042_header),
170 .val = cpu_to_be32(0x08060001),
171 .mask = cpu_to_be32(0xffffffff),
176 BCAST_FILTER_OFFSET_PAYLOAD_START,
177 .offset = sizeof(rfc1042_header) + 2 +
178 sizeof(struct arphdr) +
179 ETH_ALEN + sizeof(__be32) +
181 .mask = cpu_to_be32(0xffffffff),
182 /* mark it as special field */
183 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
188 /* dhcp offer bcast */
190 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
193 /* udp dest port - 68 (bootp client)*/
194 .offset_type = BCAST_FILTER_OFFSET_IP_END,
195 .offset = offsetof(struct udphdr, dest),
196 .val = cpu_to_be32(0x00440000),
197 .mask = cpu_to_be32(0xffff0000),
200 /* dhcp - lsb bytes of client hw address */
201 .offset_type = BCAST_FILTER_OFFSET_IP_END,
203 .mask = cpu_to_be32(0xffffffff),
204 /* mark it as special field */
205 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
209 /* last filter must be empty */
214 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
216 if (!iwl_mvm_is_d0i3_supported(mvm))
219 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
220 spin_lock_bh(&mvm->refs_lock);
221 mvm->refs[ref_type]++;
222 spin_unlock_bh(&mvm->refs_lock);
223 iwl_trans_ref(mvm->trans);
226 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
228 if (!iwl_mvm_is_d0i3_supported(mvm))
231 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
232 spin_lock_bh(&mvm->refs_lock);
233 if (WARN_ON(!mvm->refs[ref_type])) {
234 spin_unlock_bh(&mvm->refs_lock);
237 mvm->refs[ref_type]--;
238 spin_unlock_bh(&mvm->refs_lock);
239 iwl_trans_unref(mvm->trans);
242 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
243 enum iwl_mvm_ref_type except_ref)
247 if (!iwl_mvm_is_d0i3_supported(mvm))
250 spin_lock_bh(&mvm->refs_lock);
251 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
252 if (except_ref == i || !mvm->refs[i])
255 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
257 for (j = 0; j < mvm->refs[i]; j++)
258 iwl_trans_unref(mvm->trans);
261 spin_unlock_bh(&mvm->refs_lock);
264 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
269 if (!iwl_mvm_is_d0i3_supported(mvm))
272 spin_lock_bh(&mvm->refs_lock);
273 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
279 spin_unlock_bh(&mvm->refs_lock);
284 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
286 iwl_mvm_ref(mvm, ref_type);
288 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
289 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
292 iwl_mvm_unref(mvm, ref_type);
299 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
303 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
304 for (i = 0; i < NUM_PHY_CTX; i++) {
305 mvm->phy_ctxts[i].id = i;
306 mvm->phy_ctxts[i].ref = 0;
310 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
312 enum iwl_mcc_source src_id,
315 struct ieee80211_regdomain *regd = NULL;
316 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
317 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
318 struct iwl_mcc_update_resp *resp;
320 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
322 lockdep_assert_held(&mvm->mutex);
324 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
325 if (IS_ERR_OR_NULL(resp)) {
326 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
327 PTR_ERR_OR_ZERO(resp));
332 u32 status = le32_to_cpu(resp->status);
334 *changed = (status == MCC_RESP_NEW_CHAN_PROFILE ||
335 status == MCC_RESP_ILLEGAL);
338 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
339 __le32_to_cpu(resp->n_channels),
341 __le16_to_cpu(resp->mcc));
342 /* Store the return source id */
343 src_id = resp->source_id;
345 if (IS_ERR_OR_NULL(regd)) {
346 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
347 PTR_ERR_OR_ZERO(regd));
351 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
352 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
353 mvm->lar_regdom_set = true;
354 mvm->mcc_src = src_id;
360 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
363 struct ieee80211_regdomain *regd;
365 if (!iwl_mvm_is_lar_supported(mvm))
368 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
369 if (!IS_ERR_OR_NULL(regd)) {
370 /* only update the regulatory core if changed */
372 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
378 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
381 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
382 iwl_mvm_is_wifi_mcc_supported(mvm) ?
383 MCC_SOURCE_GET_CURRENT :
384 MCC_SOURCE_OLD_FW, changed);
387 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
389 enum iwl_mcc_source used_src;
390 struct ieee80211_regdomain *regd;
393 const struct ieee80211_regdomain *r =
394 rtnl_dereference(mvm->hw->wiphy->regd);
399 /* save the last source in case we overwrite it below */
400 used_src = mvm->mcc_src;
401 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
402 /* Notify the firmware we support wifi location updates */
403 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
404 if (!IS_ERR_OR_NULL(regd))
408 /* Now set our last stored MCC and source */
409 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
411 if (IS_ERR_OR_NULL(regd))
414 /* update cfg80211 if the regdomain was changed */
416 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
424 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
426 struct ieee80211_hw *hw = mvm->hw;
428 static const u32 mvm_ciphers[] = {
429 WLAN_CIPHER_SUITE_WEP40,
430 WLAN_CIPHER_SUITE_WEP104,
431 WLAN_CIPHER_SUITE_TKIP,
432 WLAN_CIPHER_SUITE_CCMP,
435 /* Tell mac80211 our characteristics */
436 ieee80211_hw_set(hw, SIGNAL_DBM);
437 ieee80211_hw_set(hw, SPECTRUM_MGMT);
438 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
439 ieee80211_hw_set(hw, QUEUE_CONTROL);
440 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
441 ieee80211_hw_set(hw, SUPPORTS_PS);
442 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
443 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
444 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
445 ieee80211_hw_set(hw, CONNECTION_MONITOR);
446 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
447 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
448 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
449 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
450 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
451 if (iwl_mvm_has_new_rx_api(mvm))
452 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
454 if (fw_has_capa(&mvm->fw->ucode_capa,
455 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
456 ieee80211_hw_set(hw, AP_LINK_PS);
457 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
459 * we absolutely need this for the new TX API since that comes
460 * with many more queues than the current code can deal with
461 * for station powersave
466 if (mvm->trans->num_rx_queues > 1)
467 ieee80211_hw_set(hw, USES_RSS);
469 if (mvm->trans->max_skb_frags)
470 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
472 hw->queues = IEEE80211_MAX_QUEUES;
473 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
474 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
475 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
476 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
477 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
479 hw->radiotap_timestamp.units_pos =
480 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
481 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
482 /* this is the case for CCK frames, it's better (only 8) for OFDM */
483 hw->radiotap_timestamp.accuracy = 22;
485 hw->rate_control_algorithm = "iwl-mvm-rs";
486 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
487 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
489 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
490 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
491 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
492 hw->wiphy->cipher_suites = mvm->ciphers;
494 if (iwl_mvm_has_new_rx_api(mvm)) {
495 mvm->ciphers[hw->wiphy->n_cipher_suites] =
496 WLAN_CIPHER_SUITE_GCMP;
497 hw->wiphy->n_cipher_suites++;
498 mvm->ciphers[hw->wiphy->n_cipher_suites] =
499 WLAN_CIPHER_SUITE_GCMP_256;
500 hw->wiphy->n_cipher_suites++;
503 /* Enable 11w if software crypto is not enabled (as the
504 * firmware will interpret some mgmt packets, so enabling it
505 * with software crypto isn't safe).
507 if (!iwlwifi_mod_params.swcrypto) {
508 ieee80211_hw_set(hw, MFP_CAPABLE);
509 mvm->ciphers[hw->wiphy->n_cipher_suites] =
510 WLAN_CIPHER_SUITE_AES_CMAC;
511 hw->wiphy->n_cipher_suites++;
512 if (iwl_mvm_has_new_rx_api(mvm)) {
513 mvm->ciphers[hw->wiphy->n_cipher_suites] =
514 WLAN_CIPHER_SUITE_BIP_GMAC_128;
515 hw->wiphy->n_cipher_suites++;
516 mvm->ciphers[hw->wiphy->n_cipher_suites] =
517 WLAN_CIPHER_SUITE_BIP_GMAC_256;
518 hw->wiphy->n_cipher_suites++;
522 /* currently FW API supports only one optional cipher scheme */
523 if (mvm->fw->cs[0].cipher) {
524 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
525 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
527 mvm->hw->n_cipher_schemes = 1;
529 cs->cipher = le32_to_cpu(fwcs->cipher);
530 cs->iftype = BIT(NL80211_IFTYPE_STATION);
531 cs->hdr_len = fwcs->hdr_len;
532 cs->pn_len = fwcs->pn_len;
533 cs->pn_off = fwcs->pn_off;
534 cs->key_idx_off = fwcs->key_idx_off;
535 cs->key_idx_mask = fwcs->key_idx_mask;
536 cs->key_idx_shift = fwcs->key_idx_shift;
537 cs->mic_len = fwcs->mic_len;
539 mvm->hw->cipher_schemes = mvm->cs;
540 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
541 hw->wiphy->n_cipher_suites++;
544 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
545 hw->wiphy->features |=
546 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
547 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
548 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
550 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
551 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
552 hw->chanctx_data_size = sizeof(u16);
554 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
555 BIT(NL80211_IFTYPE_P2P_CLIENT) |
556 BIT(NL80211_IFTYPE_AP) |
557 BIT(NL80211_IFTYPE_P2P_GO) |
558 BIT(NL80211_IFTYPE_P2P_DEVICE) |
559 BIT(NL80211_IFTYPE_ADHOC);
561 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
562 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
563 if (iwl_mvm_is_lar_supported(mvm))
564 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
566 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
567 REGULATORY_DISABLE_BEACON_HINTS;
569 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
570 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
572 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
573 hw->wiphy->n_iface_combinations =
574 ARRAY_SIZE(iwl_mvm_iface_combinations);
576 hw->wiphy->max_remain_on_channel_duration = 10000;
577 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
578 /* we can compensate an offset of up to 3 channels = 15 MHz */
579 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
581 /* Extract MAC address */
582 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
583 hw->wiphy->addresses = mvm->addresses;
584 hw->wiphy->n_addresses = 1;
586 /* Extract additional MAC addresses if available */
587 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
588 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
590 for (i = 1; i < num_mac; i++) {
591 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
593 mvm->addresses[i].addr[5]++;
594 hw->wiphy->n_addresses++;
597 iwl_mvm_reset_phy_ctxts(mvm);
599 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
601 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
603 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
604 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
605 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
607 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
608 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
610 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
612 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
613 hw->wiphy->bands[NL80211_BAND_2GHZ] =
614 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
615 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
616 hw->wiphy->bands[NL80211_BAND_5GHZ] =
617 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
619 if (fw_has_capa(&mvm->fw->ucode_capa,
620 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
621 fw_has_api(&mvm->fw->ucode_capa,
622 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
623 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
624 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
627 hw->wiphy->hw_version = mvm->trans->hw_id;
629 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
630 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
632 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
634 hw->wiphy->max_sched_scan_reqs = 1;
635 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
636 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
637 /* we create the 802.11 header and zero length SSID IE. */
638 hw->wiphy->max_sched_scan_ie_len =
639 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
640 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
641 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
644 * the firmware uses u8 for num of iterations, but 0xff is saved for
645 * infinite loop, so the maximum number of iterations is actually 254.
647 hw->wiphy->max_sched_scan_plan_iterations = 254;
649 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
650 NL80211_FEATURE_LOW_PRIORITY_SCAN |
651 NL80211_FEATURE_P2P_GO_OPPPS |
652 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
653 NL80211_FEATURE_DYNAMIC_SMPS |
654 NL80211_FEATURE_STATIC_SMPS |
655 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
657 if (fw_has_capa(&mvm->fw->ucode_capa,
658 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
659 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
660 if (fw_has_capa(&mvm->fw->ucode_capa,
661 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
662 hw->wiphy->features |= NL80211_FEATURE_QUIET;
664 if (fw_has_capa(&mvm->fw->ucode_capa,
665 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
666 hw->wiphy->features |=
667 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
669 if (fw_has_capa(&mvm->fw->ucode_capa,
670 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
671 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
673 if (fw_has_api(&mvm->fw->ucode_capa,
674 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
675 wiphy_ext_feature_set(hw->wiphy,
676 NL80211_EXT_FEATURE_SCAN_START_TIME);
677 wiphy_ext_feature_set(hw->wiphy,
678 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
679 wiphy_ext_feature_set(hw->wiphy,
680 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
683 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
685 #ifdef CONFIG_PM_SLEEP
686 if (iwl_mvm_is_d0i3_supported(mvm) &&
687 device_can_wakeup(mvm->trans->dev)) {
688 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
689 hw->wiphy->wowlan = &mvm->wowlan;
692 if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
693 mvm->trans->ops->d3_suspend &&
694 mvm->trans->ops->d3_resume &&
695 device_can_wakeup(mvm->trans->dev)) {
696 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
697 WIPHY_WOWLAN_DISCONNECT |
698 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
699 WIPHY_WOWLAN_RFKILL_RELEASE |
700 WIPHY_WOWLAN_NET_DETECT;
701 if (!iwlwifi_mod_params.swcrypto)
702 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
703 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
704 WIPHY_WOWLAN_4WAY_HANDSHAKE;
706 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
707 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
708 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
709 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
710 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
711 hw->wiphy->wowlan = &mvm->wowlan;
715 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
716 /* assign default bcast filtering configuration */
717 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
720 ret = iwl_mvm_leds_init(mvm);
724 if (fw_has_capa(&mvm->fw->ucode_capa,
725 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
726 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
727 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
728 ieee80211_hw_set(hw, TDLS_WIDER_BW);
731 if (fw_has_capa(&mvm->fw->ucode_capa,
732 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
733 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
734 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
737 hw->netdev_features |= mvm->cfg->features;
738 if (!iwl_mvm_is_csum_supported(mvm)) {
739 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
741 /* We may support SW TX CSUM */
742 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
743 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
746 ret = ieee80211_register_hw(mvm->hw);
748 iwl_mvm_leds_exit(mvm);
749 mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
751 if (mvm->cfg->vht_mu_mimo_supported)
752 wiphy_ext_feature_set(hw->wiphy,
753 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
758 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
759 struct ieee80211_sta *sta,
762 struct iwl_mvm_sta *mvmsta;
766 * double check the IN_D0I3 flag both before and after
767 * taking the spinlock, in order to prevent taking
768 * the spinlock when not needed.
770 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
773 spin_lock(&mvm->d0i3_tx_lock);
775 * testing the flag again ensures the skb dequeue
776 * loop (on d0i3 exit) hasn't run yet.
778 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
781 mvmsta = iwl_mvm_sta_from_mac80211(sta);
782 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
783 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
786 __skb_queue_tail(&mvm->d0i3_tx, skb);
787 ieee80211_stop_queues(mvm->hw);
790 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
791 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
795 spin_unlock(&mvm->d0i3_tx_lock);
799 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
800 struct ieee80211_tx_control *control,
803 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
804 struct ieee80211_sta *sta = control->sta;
805 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
806 struct ieee80211_hdr *hdr = (void *)skb->data;
808 if (iwl_mvm_is_radio_killed(mvm)) {
809 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
813 if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
814 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
815 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
818 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
819 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
820 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
821 ieee80211_is_mgmt(hdr->frame_control) &&
822 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
825 /* If there is no sta, and it's not offchannel - send through AP */
826 if (info->control.vif->type == NL80211_IFTYPE_STATION &&
827 info->hw_queue != IWL_MVM_OFFCHANNEL_QUEUE && !sta) {
828 struct iwl_mvm_vif *mvmvif =
829 iwl_mvm_vif_from_mac80211(info->control.vif);
830 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
832 if (ap_sta_id < IWL_MVM_STATION_COUNT) {
833 /* mac80211 holds rcu read lock */
834 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
835 if (IS_ERR_OR_NULL(sta))
841 if (iwl_mvm_defer_tx(mvm, sta, skb))
843 if (iwl_mvm_tx_skb(mvm, skb, sta))
848 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
852 ieee80211_free_txskb(hw, skb);
855 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
857 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
862 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
864 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
866 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
869 /* enabled by default */
873 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
875 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
877 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
881 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
882 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
883 enum ieee80211_ampdu_mlme_action action)
885 struct iwl_fw_dbg_trigger_tlv *trig;
886 struct iwl_fw_dbg_trigger_ba *ba_trig;
888 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
891 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
892 ba_trig = (void *)trig->data;
894 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
895 ieee80211_vif_to_wdev(vif), trig))
899 case IEEE80211_AMPDU_TX_OPERATIONAL: {
900 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
901 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
903 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
904 "TX AGG START: MAC %pM tid %d ssn %d\n",
905 sta->addr, tid, tid_data->ssn);
908 case IEEE80211_AMPDU_TX_STOP_CONT:
909 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
910 "TX AGG STOP: MAC %pM tid %d\n",
913 case IEEE80211_AMPDU_RX_START:
914 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
915 "RX AGG START: MAC %pM tid %d ssn %d\n",
916 sta->addr, tid, rx_ba_ssn);
918 case IEEE80211_AMPDU_RX_STOP:
919 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
920 "RX AGG STOP: MAC %pM tid %d\n",
928 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
929 struct ieee80211_vif *vif,
930 struct ieee80211_ampdu_params *params)
932 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
934 bool tx_agg_ref = false;
935 struct ieee80211_sta *sta = params->sta;
936 enum ieee80211_ampdu_mlme_action action = params->action;
937 u16 tid = params->tid;
938 u16 *ssn = ¶ms->ssn;
939 u8 buf_size = params->buf_size;
940 bool amsdu = params->amsdu;
941 u16 timeout = params->timeout;
943 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
944 sta->addr, tid, action);
946 if (!(mvm->nvm_data->sku_cap_11n_enable))
949 /* return from D0i3 before starting a new Tx aggregation */
951 case IEEE80211_AMPDU_TX_START:
952 case IEEE80211_AMPDU_TX_STOP_CONT:
953 case IEEE80211_AMPDU_TX_STOP_FLUSH:
954 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
955 case IEEE80211_AMPDU_TX_OPERATIONAL:
957 * for tx start, wait synchronously until D0i3 exit to
958 * get the correct sequence number for the tid.
959 * additionally, some other ampdu actions use direct
960 * target access, which is not handled automatically
961 * by the trans layer (unlike commands), so wait for
962 * d0i3 exit in these cases as well.
964 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
974 mutex_lock(&mvm->mutex);
977 case IEEE80211_AMPDU_RX_START:
978 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
982 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
985 case IEEE80211_AMPDU_RX_STOP:
986 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
989 case IEEE80211_AMPDU_TX_START:
990 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
994 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
996 case IEEE80211_AMPDU_TX_STOP_CONT:
997 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
999 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1000 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1001 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
1003 case IEEE80211_AMPDU_TX_OPERATIONAL:
1004 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1016 if (action == IEEE80211_AMPDU_RX_START)
1019 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1022 mutex_unlock(&mvm->mutex);
1025 * If the tid is marked as started, we won't use it for offloaded
1026 * traffic on the next D0i3 entry. It's safe to unref.
1029 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1034 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1035 struct ieee80211_vif *vif)
1037 struct iwl_mvm *mvm = data;
1038 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1040 mvmvif->uploaded = false;
1041 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1043 spin_lock_bh(&mvm->time_event_lock);
1044 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1045 spin_unlock_bh(&mvm->time_event_lock);
1047 mvmvif->phy_ctxt = NULL;
1048 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1051 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1053 /* clear the D3 reconfig, we only need it to avoid dumping a
1054 * firmware coredump on reconfiguration, we shouldn't do that
1055 * on D3->D0 transition
1057 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1058 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1059 iwl_fw_error_dump(&mvm->fwrt);
1062 /* cleanup all stale references (scan, roc), but keep the
1063 * ucode_down ref until reconfig is complete
1065 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1067 iwl_mvm_stop_device(mvm);
1069 mvm->scan_status = 0;
1070 mvm->ps_disabled = false;
1071 mvm->calibrating = false;
1073 /* just in case one was running */
1074 iwl_mvm_cleanup_roc_te(mvm);
1075 ieee80211_remain_on_channel_expired(mvm->hw);
1078 * cleanup all interfaces, even inactive ones, as some might have
1079 * gone down during the HW restart
1081 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1083 mvm->p2p_device_vif = NULL;
1084 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1086 iwl_mvm_reset_phy_ctxts(mvm);
1087 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1088 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
1089 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1090 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1092 ieee80211_wake_queues(mvm->hw);
1094 /* clear any stale d0i3 state */
1095 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1098 mvm->rx_ba_sessions = 0;
1099 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1100 mvm->monitor_on = false;
1102 /* keep statistics ticking */
1103 iwl_mvm_accu_radio_stats(mvm);
1106 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1110 lockdep_assert_held(&mvm->mutex);
1112 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1114 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1115 * so later code will - from now on - see that we're doing it.
1117 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1118 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1119 /* Clean up some internal and mac80211 state on restart */
1120 iwl_mvm_restart_cleanup(mvm);
1122 /* Hold the reference to prevent runtime suspend while
1123 * the start procedure runs. It's a bit confusing
1124 * that the UCODE_DOWN reference is taken, but it just
1125 * means "UCODE is not UP yet". ( TODO: rename this
1128 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1130 ret = iwl_mvm_up(mvm);
1132 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1133 /* Something went wrong - we need to finish some cleanup
1134 * that normally iwl_mvm_mac_restart_complete() below
1137 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1138 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1144 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1146 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1149 /* Some hw restart cleanups must not hold the mutex */
1150 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1152 * Make sure we are out of d0i3. This is needed
1153 * to make sure the reference accounting is correct
1154 * (and there is no stale d0i3_exit_work).
1156 wait_event_timeout(mvm->d0i3_exit_waitq,
1157 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1162 mutex_lock(&mvm->mutex);
1163 ret = __iwl_mvm_mac_start(mvm);
1164 mutex_unlock(&mvm->mutex);
1169 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1173 mutex_lock(&mvm->mutex);
1175 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1176 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1177 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1179 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1182 /* allow transport/FW low power modes */
1183 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1186 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1187 * of packets the FW sent out, so we must reconnect.
1189 iwl_mvm_teardown_tdls_peers(mvm);
1191 mutex_unlock(&mvm->mutex);
1194 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1196 if (iwl_mvm_is_d0i3_supported(mvm) &&
1197 iwl_mvm_enter_d0i3_on_suspend(mvm))
1198 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1199 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1202 "D0i3 exit on resume timed out\n");
1206 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1207 enum ieee80211_reconfig_type reconfig_type)
1209 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1211 switch (reconfig_type) {
1212 case IEEE80211_RECONFIG_TYPE_RESTART:
1213 iwl_mvm_restart_complete(mvm);
1215 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1216 iwl_mvm_resume_complete(mvm);
1221 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1223 lockdep_assert_held(&mvm->mutex);
1225 /* firmware counters are obviously reset now, but we shouldn't
1226 * partially track so also clear the fw_reset_accu counters.
1228 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1230 /* async_handlers_wk is now blocked */
1233 * The work item could be running or queued if the
1234 * ROC time event stops just as we get here.
1236 flush_work(&mvm->roc_done_wk);
1238 iwl_mvm_stop_device(mvm);
1240 iwl_mvm_async_handlers_purge(mvm);
1241 /* async_handlers_list is empty and will stay empty: HW is stopped */
1243 /* the fw is stopped, the aux sta is dead: clean up driver state */
1244 iwl_mvm_del_aux_sta(mvm);
1247 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1248 * hw (as restart_complete() won't be called in this case) and mac80211
1249 * won't execute the restart.
1250 * But make sure to cleanup interfaces that have gone down before/during
1251 * HW restart was requested.
1253 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1254 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1256 ieee80211_iterate_interfaces(mvm->hw, 0,
1257 iwl_mvm_cleanup_iterator, mvm);
1259 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1260 * make sure there's nothing left there and warn if any is found.
1262 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1265 for (i = 0; i < mvm->max_scans; i++) {
1266 if (WARN_ONCE(mvm->scan_uid_status[i],
1267 "UMAC scan UID %d status was not cleaned\n",
1269 mvm->scan_uid_status[i] = 0;
1274 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1276 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1278 flush_work(&mvm->d0i3_exit_work);
1279 flush_work(&mvm->async_handlers_wk);
1280 flush_work(&mvm->add_stream_wk);
1283 * Lock and clear the firmware running bit here already, so that
1284 * new commands coming in elsewhere, e.g. from debugfs, will not
1285 * be able to proceed. This is important here because one of those
1286 * debugfs files causes the firmware dump to be triggered, and if we
1287 * don't stop debugfs accesses before canceling that it could be
1288 * retriggered after we flush it but before we've cleared the bit.
1290 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1292 iwl_fw_cancel_dump(&mvm->fwrt);
1293 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1294 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1295 iwl_fw_free_dump_desc(&mvm->fwrt);
1297 mutex_lock(&mvm->mutex);
1298 __iwl_mvm_mac_stop(mvm);
1299 mutex_unlock(&mvm->mutex);
1302 * The worker might have been waiting for the mutex, let it run and
1303 * discover that its list is now empty.
1305 cancel_work_sync(&mvm->async_handlers_wk);
1308 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1312 lockdep_assert_held(&mvm->mutex);
1314 for (i = 0; i < NUM_PHY_CTX; i++)
1315 if (!mvm->phy_ctxts[i].ref)
1316 return &mvm->phy_ctxts[i];
1318 IWL_ERR(mvm, "No available PHY context\n");
1322 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1325 struct iwl_dev_tx_power_cmd cmd = {
1326 .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1327 .v3.mac_context_id =
1328 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1329 .v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1331 int len = sizeof(cmd);
1333 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1334 cmd.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1336 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1337 len = sizeof(cmd.v3);
1339 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1342 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1343 struct ieee80211_vif *vif)
1345 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1346 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1352 * make sure D0i3 exit is completed, otherwise a target access
1353 * during tx queue configuration could be done when still in
1356 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1361 * Not much to do here. The stack will not allow interface
1362 * types or combinations that we didn't advertise, so we
1363 * don't really have to check the types.
1366 mutex_lock(&mvm->mutex);
1368 /* make sure that beacon statistics don't go backwards with FW reset */
1369 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1370 mvmvif->beacon_stats.accu_num_beacons +=
1371 mvmvif->beacon_stats.num_beacons;
1373 /* Allocate resources for the MAC context, and add it to the fw */
1374 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1378 /* Counting number of interfaces is needed for legacy PM */
1379 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1383 * The AP binding flow can be done only after the beacon
1384 * template is configured (which happens only in the mac80211
1385 * start_ap() flow), and adding the broadcast station can happen
1386 * only after the binding.
1387 * In addition, since modifying the MAC before adding a bcast
1388 * station is not allowed by the FW, delay the adding of MAC context to
1389 * the point where we can also add the bcast station.
1390 * In short: there's not much we can do at this point, other than
1391 * allocating resources :)
1393 if (vif->type == NL80211_IFTYPE_AP ||
1394 vif->type == NL80211_IFTYPE_ADHOC) {
1395 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1397 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1402 * Only queue for this station is the mcast queue,
1403 * which shouldn't be in TFD mask anyway
1405 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1411 iwl_mvm_vif_dbgfs_register(mvm, vif);
1415 mvmvif->features |= hw->netdev_features;
1417 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1421 ret = iwl_mvm_power_update_mac(mvm);
1423 goto out_remove_mac;
1425 /* beacon filtering */
1426 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1428 goto out_remove_mac;
1430 if (!mvm->bf_allowed_vif &&
1431 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1432 mvm->bf_allowed_vif = mvmvif;
1433 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1434 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1438 * P2P_DEVICE interface does not have a channel context assigned to it,
1439 * so a dedicated PHY context is allocated to it and the corresponding
1440 * MAC context is bound to it at this stage.
1442 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1444 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1445 if (!mvmvif->phy_ctxt) {
1450 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1451 ret = iwl_mvm_binding_add_vif(mvm, vif);
1455 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1459 /* Save a pointer to p2p device vif, so it can later be used to
1460 * update the p2p device MAC when a GO is started/stopped */
1461 mvm->p2p_device_vif = vif;
1464 if (vif->type == NL80211_IFTYPE_MONITOR)
1465 mvm->monitor_on = true;
1467 iwl_mvm_vif_dbgfs_register(mvm, vif);
1471 iwl_mvm_binding_remove_vif(mvm, vif);
1473 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1475 if (mvm->bf_allowed_vif == mvmvif) {
1476 mvm->bf_allowed_vif = NULL;
1477 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1478 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1481 mvmvif->phy_ctxt = NULL;
1482 iwl_mvm_mac_ctxt_remove(mvm, vif);
1484 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1487 mutex_unlock(&mvm->mutex);
1489 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1494 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1495 struct ieee80211_vif *vif)
1497 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1499 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1500 * We assume here that all the packets sent to the OFFCHANNEL
1501 * queue are sent in ROC session.
1503 flush_work(&mvm->roc_done_wk);
1507 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1508 struct ieee80211_vif *vif)
1510 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1511 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1513 iwl_mvm_prepare_mac_removal(mvm, vif);
1515 mutex_lock(&mvm->mutex);
1517 if (mvm->bf_allowed_vif == mvmvif) {
1518 mvm->bf_allowed_vif = NULL;
1519 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1520 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1523 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1526 * For AP/GO interface, the tear down of the resources allocated to the
1527 * interface is be handled as part of the stop_ap flow.
1529 if (vif->type == NL80211_IFTYPE_AP ||
1530 vif->type == NL80211_IFTYPE_ADHOC) {
1531 #ifdef CONFIG_NL80211_TESTMODE
1532 if (vif == mvm->noa_vif) {
1533 mvm->noa_vif = NULL;
1534 mvm->noa_duration = 0;
1537 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1538 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1542 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1543 mvm->p2p_device_vif = NULL;
1544 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1545 iwl_mvm_binding_remove_vif(mvm, vif);
1546 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1547 mvmvif->phy_ctxt = NULL;
1550 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1553 iwl_mvm_power_update_mac(mvm);
1554 iwl_mvm_mac_ctxt_remove(mvm, vif);
1556 if (vif->type == NL80211_IFTYPE_MONITOR)
1557 mvm->monitor_on = false;
1560 mutex_unlock(&mvm->mutex);
1563 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1568 struct iwl_mvm_mc_iter_data {
1569 struct iwl_mvm *mvm;
1573 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1574 struct ieee80211_vif *vif)
1576 struct iwl_mvm_mc_iter_data *data = _data;
1577 struct iwl_mvm *mvm = data->mvm;
1578 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1579 struct iwl_host_cmd hcmd = {
1580 .id = MCAST_FILTER_CMD,
1582 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1586 /* if we don't have free ports, mcast frames will be dropped */
1587 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1590 if (vif->type != NL80211_IFTYPE_STATION ||
1591 !vif->bss_conf.assoc)
1594 cmd->port_id = data->port_id++;
1595 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1596 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1601 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1603 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1606 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1608 struct iwl_mvm_mc_iter_data iter_data = {
1612 lockdep_assert_held(&mvm->mutex);
1614 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1617 ieee80211_iterate_active_interfaces_atomic(
1618 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1619 iwl_mvm_mc_iface_iterator, &iter_data);
1622 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1623 struct netdev_hw_addr_list *mc_list)
1625 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1626 struct iwl_mcast_filter_cmd *cmd;
1627 struct netdev_hw_addr *addr;
1632 addr_count = netdev_hw_addr_list_count(mc_list);
1633 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1634 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1638 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1639 cmd = kzalloc(len, GFP_ATOMIC);
1645 return (u64)(unsigned long)cmd;
1648 netdev_hw_addr_list_for_each(addr, mc_list) {
1649 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1650 cmd->count, addr->addr);
1651 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1652 addr->addr, ETH_ALEN);
1656 return (u64)(unsigned long)cmd;
1659 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1660 unsigned int changed_flags,
1661 unsigned int *total_flags,
1664 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1665 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1667 mutex_lock(&mvm->mutex);
1669 /* replace previous configuration */
1670 kfree(mvm->mcast_filter_cmd);
1671 mvm->mcast_filter_cmd = cmd;
1676 if (changed_flags & FIF_ALLMULTI)
1677 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1682 iwl_mvm_recalc_multicast(mvm);
1684 mutex_unlock(&mvm->mutex);
1688 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1689 struct ieee80211_vif *vif,
1690 unsigned int filter_flags,
1691 unsigned int changed_flags)
1693 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1695 /* We support only filter for probe requests */
1696 if (!(changed_flags & FIF_PROBE_REQ))
1699 /* Supported only for p2p client interfaces */
1700 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1704 mutex_lock(&mvm->mutex);
1705 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1706 mutex_unlock(&mvm->mutex);
1709 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1710 struct iwl_bcast_iter_data {
1711 struct iwl_mvm *mvm;
1712 struct iwl_bcast_filter_cmd *cmd;
1717 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1718 const struct iwl_fw_bcast_filter *in_filter,
1719 struct iwl_fw_bcast_filter *out_filter)
1721 struct iwl_fw_bcast_filter_attr *attr;
1724 memcpy(out_filter, in_filter, sizeof(*out_filter));
1726 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1727 attr = &out_filter->attrs[i];
1732 switch (attr->reserved1) {
1733 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1734 if (vif->bss_conf.arp_addr_cnt != 1) {
1739 attr->val = vif->bss_conf.arp_addr_list[0];
1741 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1742 attr->val = *(__be32 *)&vif->addr[2];
1747 attr->reserved1 = 0;
1748 out_filter->num_attrs++;
1752 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1753 struct ieee80211_vif *vif)
1755 struct iwl_bcast_iter_data *data = _data;
1756 struct iwl_mvm *mvm = data->mvm;
1757 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1758 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1759 struct iwl_fw_bcast_mac *bcast_mac;
1762 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1765 bcast_mac = &cmd->macs[mvmvif->id];
1768 * enable filtering only for associated stations, but not for P2P
1771 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1772 !vif->bss_conf.assoc)
1775 bcast_mac->default_discard = 1;
1777 /* copy all configured filters */
1778 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1780 * Make sure we don't exceed our filters limit.
1781 * if there is still a valid filter to be configured,
1782 * be on the safe side and just allow bcast for this mac.
1784 if (WARN_ON_ONCE(data->current_filter >=
1785 ARRAY_SIZE(cmd->filters))) {
1786 bcast_mac->default_discard = 0;
1787 bcast_mac->attached_filters = 0;
1791 iwl_mvm_set_bcast_filter(vif,
1792 &mvm->bcast_filters[i],
1793 &cmd->filters[data->current_filter]);
1795 /* skip current filter if it contains no attributes */
1796 if (!cmd->filters[data->current_filter].num_attrs)
1799 /* attach the filter to current mac */
1800 bcast_mac->attached_filters |=
1801 cpu_to_le16(BIT(data->current_filter));
1803 data->current_filter++;
1807 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1808 struct iwl_bcast_filter_cmd *cmd)
1810 struct iwl_bcast_iter_data iter_data = {
1815 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1818 memset(cmd, 0, sizeof(*cmd));
1819 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1820 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1822 #ifdef CONFIG_IWLWIFI_DEBUGFS
1823 /* use debugfs filters/macs if override is configured */
1824 if (mvm->dbgfs_bcast_filtering.override) {
1825 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1826 sizeof(cmd->filters));
1827 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1833 /* if no filters are configured, do nothing */
1834 if (!mvm->bcast_filters)
1837 /* configure and attach these filters for each associated sta vif */
1838 ieee80211_iterate_active_interfaces(
1839 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1840 iwl_mvm_bcast_filter_iterator, &iter_data);
1845 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1847 struct iwl_bcast_filter_cmd cmd;
1849 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1852 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1855 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1859 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1865 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1866 struct ieee80211_vif *vif)
1868 struct iwl_mu_group_mgmt_cmd cmd = {};
1870 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1871 WLAN_MEMBERSHIP_LEN);
1872 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1873 WLAN_USER_POSITION_LEN);
1875 return iwl_mvm_send_cmd_pdu(mvm,
1876 WIDE_ID(DATA_PATH_GROUP,
1877 UPDATE_MU_GROUPS_CMD),
1878 0, sizeof(cmd), &cmd);
1881 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1882 struct ieee80211_vif *vif)
1884 if (vif->mu_mimo_owner) {
1885 struct iwl_mu_group_mgmt_notif *notif = _data;
1888 * MU-MIMO Group Id action frame is little endian. We treat
1889 * the data received from firmware as if it came from the
1890 * action frame, so no conversion is needed.
1892 ieee80211_update_mu_groups(vif,
1893 (u8 *)¬if->membership_status,
1894 (u8 *)¬if->user_position);
1898 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1899 struct iwl_rx_cmd_buffer *rxb)
1901 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1902 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1904 ieee80211_iterate_active_interfaces_atomic(
1905 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1906 iwl_mvm_mu_mimo_iface_iterator, notif);
1909 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1910 struct ieee80211_vif *vif,
1911 struct ieee80211_bss_conf *bss_conf,
1914 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1918 * Re-calculate the tsf id, as the master-slave relations depend on the
1919 * beacon interval, which was not known when the station interface was
1922 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1923 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1925 if (changes & BSS_CHANGED_ASSOC && !bss_conf->assoc &&
1927 iwl_mvm_send_lqm_cmd(vif, LQM_CMD_OPERATION_STOP_MEASUREMENT,
1931 * If we're not associated yet, take the (new) BSSID before associating
1932 * so the firmware knows. If we're already associated, then use the old
1933 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1934 * branch for disassociation below.
1936 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1937 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1939 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
1941 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1943 /* after sending it once, adopt mac80211 data */
1944 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1945 mvmvif->associated = bss_conf->assoc;
1947 if (changes & BSS_CHANGED_ASSOC) {
1948 if (bss_conf->assoc) {
1949 /* clear statistics to get clean beacon counter */
1950 iwl_mvm_request_statistics(mvm, true);
1951 memset(&mvmvif->beacon_stats, 0,
1952 sizeof(mvmvif->beacon_stats));
1954 /* add quota for this interface */
1955 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1957 IWL_ERR(mvm, "failed to update quotas\n");
1961 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1964 * If we're restarting then the firmware will
1965 * obviously have lost synchronisation with
1966 * the AP. It will attempt to synchronise by
1967 * itself, but we can make it more reliable by
1968 * scheduling a session protection time event.
1970 * The firmware needs to receive a beacon to
1971 * catch up with synchronisation, use 110% of
1972 * the beacon interval.
1974 * Set a large maximum delay to allow for more
1975 * than a single interface.
1977 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1978 iwl_mvm_protect_session(mvm, vif, dur, dur,
1982 iwl_mvm_sf_update(mvm, vif, false);
1983 iwl_mvm_power_vif_assoc(mvm, vif);
1985 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
1986 iwl_mvm_update_smps(mvm, vif,
1987 IWL_MVM_SMPS_REQ_PROT,
1988 IEEE80211_SMPS_DYNAMIC);
1990 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
1992 * If update fails - SF might be running in associated
1993 * mode while disassociated - which is forbidden.
1995 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1996 "Failed to update SF upon disassociation\n");
1999 * If we get an assert during the connection (after the
2000 * station has been added, but before the vif is set
2001 * to associated), mac80211 will re-add the station and
2002 * then configure the vif. Since the vif is not
2003 * associated, we would remove the station here and
2004 * this would fail the recovery.
2006 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2009 * Remove AP station now that
2010 * the MAC is unassoc
2012 ret = iwl_mvm_rm_sta_id(mvm, vif,
2016 "failed to remove AP station\n");
2018 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2019 mvm->d0i3_ap_sta_id =
2020 IWL_MVM_INVALID_STA;
2021 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2024 /* remove quota for this interface */
2025 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2027 IWL_ERR(mvm, "failed to update quotas\n");
2030 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2032 /* this will take the cleared BSSID from bss_conf */
2033 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2036 "failed to update MAC %pM (clear after unassoc)\n",
2041 * The firmware tracks the MU-MIMO group on its own.
2042 * However, on HW restart we should restore this data.
2044 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2045 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2046 ret = iwl_mvm_update_mu_groups(mvm, vif);
2049 "failed to update VHT MU_MIMO groups\n");
2052 iwl_mvm_recalc_multicast(mvm);
2053 iwl_mvm_configure_bcast_filter(mvm);
2055 /* reset rssi values */
2056 mvmvif->bf_data.ave_beacon_signal = 0;
2058 iwl_mvm_bt_coex_vif_change(mvm);
2059 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2060 IEEE80211_SMPS_AUTOMATIC);
2061 if (fw_has_capa(&mvm->fw->ucode_capa,
2062 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2063 iwl_mvm_config_scan(mvm);
2066 if (changes & BSS_CHANGED_BEACON_INFO) {
2068 * We received a beacon from the associated AP so
2069 * remove the session protection.
2071 iwl_mvm_stop_session_protection(mvm, vif);
2073 iwl_mvm_sf_update(mvm, vif, false);
2074 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2077 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2079 * Send power command on every beacon change,
2080 * because we may have not enabled beacon abort yet.
2082 BSS_CHANGED_BEACON_INFO)) {
2083 ret = iwl_mvm_power_update_mac(mvm);
2085 IWL_ERR(mvm, "failed to update power mode\n");
2088 if (changes & BSS_CHANGED_TXPOWER) {
2089 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2091 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2094 if (changes & BSS_CHANGED_CQM) {
2095 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2096 /* reset cqm events tracking */
2097 mvmvif->bf_data.last_cqm_event = 0;
2098 if (mvmvif->bf_data.bf_enabled) {
2099 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2102 "failed to update CQM thresholds\n");
2106 if (changes & BSS_CHANGED_ARP_FILTER) {
2107 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2108 iwl_mvm_configure_bcast_filter(mvm);
2112 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2113 struct ieee80211_vif *vif)
2115 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2116 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2120 * iwl_mvm_mac_ctxt_add() might read directly from the device
2121 * (the system time), so make sure it is available.
2123 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2127 mutex_lock(&mvm->mutex);
2129 /* Send the beacon template */
2130 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2135 * Re-calculate the tsf id, as the master-slave relations depend on the
2136 * beacon interval, which was not known when the AP interface was added.
2138 if (vif->type == NL80211_IFTYPE_AP)
2139 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2141 mvmvif->ap_assoc_sta_count = 0;
2143 /* Add the mac context */
2144 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2148 /* Perform the binding */
2149 ret = iwl_mvm_binding_add_vif(mvm, vif);
2154 * This is not very nice, but the simplest:
2155 * For older FWs adding the mcast sta before the bcast station may
2156 * cause assert 0x2b00.
2157 * This is fixed in later FW so make the order of removal depend on
2160 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2161 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2165 * Send the bcast station. At this stage the TBTT and DTIM time
2166 * events are added and applied to the scheduler
2168 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2170 iwl_mvm_rm_mcast_sta(mvm, vif);
2175 * Send the bcast station. At this stage the TBTT and DTIM time
2176 * events are added and applied to the scheduler
2178 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2181 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2183 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2188 /* must be set before quota calculations */
2189 mvmvif->ap_ibss_active = true;
2191 /* power updated needs to be done before quotas */
2192 iwl_mvm_power_update_mac(mvm);
2194 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2196 goto out_quota_failed;
2198 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2199 if (vif->p2p && mvm->p2p_device_vif)
2200 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2202 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2204 iwl_mvm_bt_coex_vif_change(mvm);
2206 /* we don't support TDLS during DCM */
2207 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2208 iwl_mvm_teardown_tdls_peers(mvm);
2213 iwl_mvm_power_update_mac(mvm);
2214 mvmvif->ap_ibss_active = false;
2215 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2216 iwl_mvm_rm_mcast_sta(mvm, vif);
2218 iwl_mvm_binding_remove_vif(mvm, vif);
2220 iwl_mvm_mac_ctxt_remove(mvm, vif);
2222 mutex_unlock(&mvm->mutex);
2223 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2227 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2228 struct ieee80211_vif *vif)
2230 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2231 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2233 iwl_mvm_prepare_mac_removal(mvm, vif);
2235 mutex_lock(&mvm->mutex);
2237 /* Handle AP stop while in CSA */
2238 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2239 iwl_mvm_remove_time_event(mvm, mvmvif,
2240 &mvmvif->time_event_data);
2241 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2242 mvmvif->csa_countdown = false;
2245 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2246 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2247 mvm->csa_tx_block_bcn_timeout = 0;
2250 mvmvif->ap_ibss_active = false;
2251 mvm->ap_last_beacon_gp2 = 0;
2253 iwl_mvm_bt_coex_vif_change(mvm);
2255 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2257 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2258 if (vif->p2p && mvm->p2p_device_vif)
2259 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2261 iwl_mvm_update_quotas(mvm, false, NULL);
2264 * This is not very nice, but the simplest:
2265 * For older FWs removing the mcast sta before the bcast station may
2266 * cause assert 0x2b00.
2267 * This is fixed in later FW (which will stop beaconing when removing
2269 * So make the order of removal depend on the TLV
2271 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2272 iwl_mvm_rm_mcast_sta(mvm, vif);
2273 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2274 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2275 iwl_mvm_rm_mcast_sta(mvm, vif);
2276 iwl_mvm_binding_remove_vif(mvm, vif);
2278 iwl_mvm_power_update_mac(mvm);
2280 iwl_mvm_mac_ctxt_remove(mvm, vif);
2282 mutex_unlock(&mvm->mutex);
2286 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2287 struct ieee80211_vif *vif,
2288 struct ieee80211_bss_conf *bss_conf,
2291 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2293 /* Changes will be applied when the AP/IBSS is started */
2294 if (!mvmvif->ap_ibss_active)
2297 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2298 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2299 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2300 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2302 /* Need to send a new beacon template to the FW */
2303 if (changes & BSS_CHANGED_BEACON &&
2304 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2305 IWL_WARN(mvm, "Failed updating beacon data\n");
2307 if (changes & BSS_CHANGED_TXPOWER) {
2308 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2310 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2314 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2315 struct ieee80211_vif *vif,
2316 struct ieee80211_bss_conf *bss_conf,
2319 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2322 * iwl_mvm_bss_info_changed_station() might call
2323 * iwl_mvm_protect_session(), which reads directly from
2324 * the device (the system time), so make sure it is available.
2326 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2329 mutex_lock(&mvm->mutex);
2331 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2332 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2334 switch (vif->type) {
2335 case NL80211_IFTYPE_STATION:
2336 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2338 case NL80211_IFTYPE_AP:
2339 case NL80211_IFTYPE_ADHOC:
2340 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2342 case NL80211_IFTYPE_MONITOR:
2343 if (changes & BSS_CHANGED_MU_GROUPS)
2344 iwl_mvm_update_mu_groups(mvm, vif);
2347 /* shouldn't happen */
2351 mutex_unlock(&mvm->mutex);
2352 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2355 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2356 struct ieee80211_vif *vif,
2357 struct ieee80211_scan_request *hw_req)
2359 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2362 if (hw_req->req.n_channels == 0 ||
2363 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2366 mutex_lock(&mvm->mutex);
2367 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2368 mutex_unlock(&mvm->mutex);
2373 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2374 struct ieee80211_vif *vif)
2376 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2378 mutex_lock(&mvm->mutex);
2380 /* Due to a race condition, it's possible that mac80211 asks
2381 * us to stop a hw_scan when it's already stopped. This can
2382 * happen, for instance, if we stopped the scan ourselves,
2383 * called ieee80211_scan_completed() and the userspace called
2384 * cancel scan scan before ieee80211_scan_work() could run.
2385 * To handle that, simply return if the scan is not running.
2387 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2388 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2390 mutex_unlock(&mvm->mutex);
2394 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2395 struct ieee80211_sta *sta, u16 tids,
2397 enum ieee80211_frame_release_type reason,
2400 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2402 /* Called when we need to transmit (a) frame(s) from mac80211 */
2404 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2405 tids, more_data, false);
2409 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2410 struct ieee80211_sta *sta, u16 tids,
2412 enum ieee80211_frame_release_type reason,
2415 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2417 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2419 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2420 tids, more_data, true);
2423 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2424 enum sta_notify_cmd cmd,
2425 struct ieee80211_sta *sta)
2427 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2428 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2429 unsigned long txqs = 0, tids = 0;
2433 * If we have TVQM then we get too high queue numbers - luckily
2434 * we really shouldn't get here with that because such hardware
2435 * should have firmware supporting buffer station offload.
2437 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2440 spin_lock_bh(&mvmsta->lock);
2441 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2442 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2444 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2447 __set_bit(tid_data->txq_id, &txqs);
2449 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2452 __set_bit(tid, &tids);
2456 case STA_NOTIFY_SLEEP:
2457 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2458 ieee80211_sta_set_buffered(sta, tid, true);
2461 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2463 * The fw updates the STA to be asleep. Tx packets on the Tx
2464 * queues to this station will not be transmitted. The fw will
2465 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2468 case STA_NOTIFY_AWAKE:
2469 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2473 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2474 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2479 spin_unlock_bh(&mvmsta->lock);
2482 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2483 struct ieee80211_vif *vif,
2484 enum sta_notify_cmd cmd,
2485 struct ieee80211_sta *sta)
2487 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2490 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2492 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2493 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2494 struct ieee80211_sta *sta;
2495 struct iwl_mvm_sta *mvmsta;
2496 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2498 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2502 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2503 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2508 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2511 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2516 if (mvmsta->sleeping != sleeping) {
2517 mvmsta->sleeping = sleeping;
2518 __iwl_mvm_mac_sta_notify(mvm->hw,
2519 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2521 ieee80211_sta_ps_transition(sta, sleeping);
2525 switch (notif->type) {
2526 case IWL_MVM_PM_EVENT_AWAKE:
2527 case IWL_MVM_PM_EVENT_ASLEEP:
2529 case IWL_MVM_PM_EVENT_UAPSD:
2530 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2532 case IWL_MVM_PM_EVENT_PS_POLL:
2533 ieee80211_sta_pspoll(sta);
2543 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2544 struct ieee80211_vif *vif,
2545 struct ieee80211_sta *sta)
2547 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2548 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2551 * This is called before mac80211 does RCU synchronisation,
2552 * so here we already invalidate our internal RCU-protected
2553 * station pointer. The rest of the code will thus no longer
2554 * be able to find the station this way, and we don't rely
2555 * on further RCU synchronisation after the sta_state()
2556 * callback deleted the station.
2558 mutex_lock(&mvm->mutex);
2559 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2560 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2563 mutex_unlock(&mvm->mutex);
2566 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2569 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2572 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2573 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2578 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2579 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2583 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2587 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2588 struct ieee80211_vif *vif, u8 *peer_addr,
2589 enum nl80211_tdls_operation action)
2591 struct iwl_fw_dbg_trigger_tlv *trig;
2592 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2594 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS))
2597 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS);
2598 tdls_trig = (void *)trig->data;
2599 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
2600 ieee80211_vif_to_wdev(vif), trig))
2603 if (!(tdls_trig->action_bitmap & BIT(action)))
2606 if (tdls_trig->peer_mode &&
2607 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2610 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2611 "TDLS event occurred, peer %pM, action %d",
2615 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2616 struct iwl_mvm_sta *mvm_sta)
2618 struct iwl_mvm_tid_data *tid_data;
2619 struct sk_buff *skb;
2622 spin_lock_bh(&mvm_sta->lock);
2623 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2624 tid_data = &mvm_sta->tid_data[i];
2626 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2627 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2630 * The first deferred frame should've stopped the MAC
2631 * queues, so we should never get a second deferred
2632 * frame for the RA/TID.
2634 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
2635 ieee80211_free_txskb(mvm->hw, skb);
2638 spin_unlock_bh(&mvm_sta->lock);
2641 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2642 struct ieee80211_vif *vif,
2643 struct ieee80211_sta *sta,
2644 enum ieee80211_sta_state old_state,
2645 enum ieee80211_sta_state new_state)
2647 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2648 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2649 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2652 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2653 sta->addr, old_state, new_state);
2655 /* this would be a mac80211 bug ... but don't crash */
2656 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2657 return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL;
2660 * If we are in a STA removal flow and in DQA mode:
2662 * This is after the sync_rcu part, so the queues have already been
2663 * flushed. No more TXs on their way in mac80211's path, and no more in
2665 * Also, we won't be getting any new TX frames for this station.
2666 * What we might have are deferred TX frames that need to be taken care
2669 * Drop any still-queued deferred-frame before removing the STA, and
2670 * make sure the worker is no longer handling frames for this STA.
2672 if (old_state == IEEE80211_STA_NONE &&
2673 new_state == IEEE80211_STA_NOTEXIST) {
2674 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2675 flush_work(&mvm->add_stream_wk);
2678 * No need to make sure deferred TX indication is off since the
2679 * worker will already remove it if it was on
2683 mutex_lock(&mvm->mutex);
2684 /* track whether or not the station is associated */
2685 mvm_sta->associated = new_state >= IEEE80211_STA_ASSOC;
2687 if (old_state == IEEE80211_STA_NOTEXIST &&
2688 new_state == IEEE80211_STA_NONE) {
2690 * Firmware bug - it'll crash if the beacon interval is less
2691 * than 16. We can't avoid connecting at all, so refuse the
2692 * station state change, this will cause mac80211 to abandon
2693 * attempts to connect to this AP, and eventually wpa_s will
2694 * blacklist the AP...
2696 if (vif->type == NL80211_IFTYPE_STATION &&
2697 vif->bss_conf.beacon_int < 16) {
2699 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2700 sta->addr, vif->bss_conf.beacon_int);
2707 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2708 IWL_MVM_TDLS_STA_COUNT ||
2709 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2710 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2715 ret = iwl_mvm_add_sta(mvm, vif, sta);
2716 if (sta->tdls && ret == 0) {
2717 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2718 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2719 NL80211_TDLS_SETUP);
2721 } else if (old_state == IEEE80211_STA_NONE &&
2722 new_state == IEEE80211_STA_AUTH) {
2724 * EBS may be disabled due to previous failures reported by FW.
2725 * Reset EBS status here assuming environment has been changed.
2727 mvm->last_ebs_successful = true;
2728 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2730 } else if (old_state == IEEE80211_STA_AUTH &&
2731 new_state == IEEE80211_STA_ASSOC) {
2732 if (vif->type == NL80211_IFTYPE_AP) {
2733 mvmvif->ap_assoc_sta_count++;
2734 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2737 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2739 ret = iwl_mvm_update_sta(mvm, vif, sta);
2740 } else if (old_state == IEEE80211_STA_ASSOC &&
2741 new_state == IEEE80211_STA_AUTHORIZED) {
2743 /* we don't support TDLS during DCM */
2744 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2745 iwl_mvm_teardown_tdls_peers(mvm);
2748 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2749 NL80211_TDLS_ENABLE_LINK);
2751 /* enable beacon filtering */
2752 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2754 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2758 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2759 new_state == IEEE80211_STA_ASSOC) {
2760 /* disable beacon filtering */
2761 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2763 } else if (old_state == IEEE80211_STA_ASSOC &&
2764 new_state == IEEE80211_STA_AUTH) {
2765 if (vif->type == NL80211_IFTYPE_AP) {
2766 mvmvif->ap_assoc_sta_count--;
2767 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2770 } else if (old_state == IEEE80211_STA_AUTH &&
2771 new_state == IEEE80211_STA_NONE) {
2773 } else if (old_state == IEEE80211_STA_NONE &&
2774 new_state == IEEE80211_STA_NOTEXIST) {
2775 ret = iwl_mvm_rm_sta(mvm, vif, sta);
2777 iwl_mvm_recalc_tdls_state(mvm, vif, false);
2778 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2779 NL80211_TDLS_DISABLE_LINK);
2785 mutex_unlock(&mvm->mutex);
2787 if (sta->tdls && ret == 0) {
2788 if (old_state == IEEE80211_STA_NOTEXIST &&
2789 new_state == IEEE80211_STA_NONE)
2790 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2791 else if (old_state == IEEE80211_STA_NONE &&
2792 new_state == IEEE80211_STA_NOTEXIST)
2793 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2799 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2801 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2803 mvm->rts_threshold = value;
2808 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2809 struct ieee80211_vif *vif,
2810 struct ieee80211_sta *sta, u32 changed)
2812 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2814 if (vif->type == NL80211_IFTYPE_STATION &&
2815 changed & IEEE80211_RC_NSS_CHANGED)
2816 iwl_mvm_sf_update(mvm, vif, false);
2819 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2820 struct ieee80211_vif *vif, u16 ac,
2821 const struct ieee80211_tx_queue_params *params)
2823 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2824 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2826 mvmvif->queue_params[ac] = *params;
2829 * No need to update right away, we'll get BSS_CHANGED_QOS
2830 * The exception is P2P_DEVICE interface which needs immediate update.
2832 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2835 mutex_lock(&mvm->mutex);
2836 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2837 mutex_unlock(&mvm->mutex);
2843 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2844 struct ieee80211_vif *vif)
2846 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2847 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
2848 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
2850 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2854 * iwl_mvm_protect_session() reads directly from the device
2855 * (the system time), so make sure it is available.
2857 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2860 mutex_lock(&mvm->mutex);
2861 /* Try really hard to protect the session and hear a beacon */
2862 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
2863 mutex_unlock(&mvm->mutex);
2865 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
2868 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2869 struct ieee80211_vif *vif,
2870 struct cfg80211_sched_scan_request *req,
2871 struct ieee80211_scan_ies *ies)
2873 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2877 mutex_lock(&mvm->mutex);
2879 if (!vif->bss_conf.idle) {
2884 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
2887 mutex_unlock(&mvm->mutex);
2891 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2892 struct ieee80211_vif *vif)
2894 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2897 mutex_lock(&mvm->mutex);
2899 /* Due to a race condition, it's possible that mac80211 asks
2900 * us to stop a sched_scan when it's already stopped. This
2901 * can happen, for instance, if we stopped the scan ourselves,
2902 * called ieee80211_sched_scan_stopped() and the userspace called
2903 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
2904 * could run. To handle this, simply return if the scan is
2907 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
2908 mutex_unlock(&mvm->mutex);
2912 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
2913 mutex_unlock(&mvm->mutex);
2914 iwl_mvm_wait_for_async_handlers(mvm);
2919 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2920 enum set_key_cmd cmd,
2921 struct ieee80211_vif *vif,
2922 struct ieee80211_sta *sta,
2923 struct ieee80211_key_conf *key)
2925 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2926 struct iwl_mvm_sta *mvmsta;
2927 struct iwl_mvm_key_pn *ptk_pn;
2928 int keyidx = key->keyidx;
2932 if (iwlwifi_mod_params.swcrypto) {
2933 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2937 switch (key->cipher) {
2938 case WLAN_CIPHER_SUITE_TKIP:
2939 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2940 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2942 case WLAN_CIPHER_SUITE_CCMP:
2943 case WLAN_CIPHER_SUITE_GCMP:
2944 case WLAN_CIPHER_SUITE_GCMP_256:
2945 if (!iwl_mvm_has_new_tx_api(mvm))
2946 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2948 case WLAN_CIPHER_SUITE_AES_CMAC:
2949 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2950 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2951 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
2953 case WLAN_CIPHER_SUITE_WEP40:
2954 case WLAN_CIPHER_SUITE_WEP104:
2955 /* For non-client mode, only use WEP keys for TX as we probably
2956 * don't have a station yet anyway and would then have to keep
2957 * track of the keys, linking them to each of the clients/peers
2958 * as they appear. For now, don't do that, for performance WEP
2959 * offload doesn't really matter much, but we need it for some
2960 * other offload features in client mode.
2962 if (vif->type != NL80211_IFTYPE_STATION)
2966 /* currently FW supports only one optional cipher scheme */
2967 if (hw->n_cipher_schemes &&
2968 hw->cipher_schemes->cipher == key->cipher)
2969 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2974 mutex_lock(&mvm->mutex);
2978 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2979 vif->type == NL80211_IFTYPE_AP) && !sta) {
2981 * GTK on AP interface is a TX-only key, return 0;
2982 * on IBSS they're per-station and because we're lazy
2983 * we don't support them for RX, so do the same.
2984 * CMAC/GMAC in AP/IBSS modes must be done in software.
2986 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2987 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2988 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
2993 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
2994 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
2995 !iwl_mvm_has_new_tx_api(mvm)) {
2996 key->hw_key_idx = STA_KEY_IDX_INVALID;
3001 /* During FW restart, in order to restore the state as it was,
3002 * don't try to reprogram keys we previously failed for.
3004 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3005 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3006 IWL_DEBUG_MAC80211(mvm,
3007 "skip invalid idx key programming during restart\n");
3012 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3013 sta && iwl_mvm_has_new_rx_api(mvm) &&
3014 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3015 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3016 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3017 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3018 struct ieee80211_key_seq seq;
3021 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3022 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3023 ptk_pn = kzalloc(sizeof(*ptk_pn) +
3024 mvm->trans->num_rx_queues *
3025 sizeof(ptk_pn->q[0]),
3032 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3033 ieee80211_get_key_rx_seq(key, tid, &seq);
3034 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3035 memcpy(ptk_pn->q[q].pn[tid],
3037 IEEE80211_CCMP_PN_LEN);
3040 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3043 /* in HW restart reuse the index, otherwise request a new one */
3044 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3045 key_offset = key->hw_key_idx;
3047 key_offset = STA_KEY_IDX_INVALID;
3049 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3050 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3052 IWL_WARN(mvm, "set key failed\n");
3054 * can't add key for RX, but we don't need it
3055 * in the device for TX so still return 0
3057 key->hw_key_idx = STA_KEY_IDX_INVALID;
3063 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3068 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3069 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3070 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3071 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3072 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3073 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3074 ptk_pn = rcu_dereference_protected(
3075 mvmsta->ptk_pn[keyidx],
3076 lockdep_is_held(&mvm->mutex));
3077 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3079 kfree_rcu(ptk_pn, rcu_head);
3082 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3083 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3089 mutex_unlock(&mvm->mutex);
3093 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3094 struct ieee80211_vif *vif,
3095 struct ieee80211_key_conf *keyconf,
3096 struct ieee80211_sta *sta,
3097 u32 iv32, u16 *phase1key)
3099 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3101 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3104 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3108 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3109 struct iwl_rx_packet *pkt, void *data)
3111 struct iwl_mvm *mvm =
3112 container_of(notif_wait, struct iwl_mvm, notif_wait);
3113 struct iwl_hs20_roc_res *resp;
3114 int resp_len = iwl_rx_packet_payload_len(pkt);
3115 struct iwl_mvm_time_event_data *te_data = data;
3117 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3120 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3121 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3125 resp = (void *)pkt->data;
3128 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3129 resp->status, resp->event_unique_id);
3131 te_data->uid = le32_to_cpu(resp->event_unique_id);
3132 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3135 spin_lock_bh(&mvm->time_event_lock);
3136 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3137 spin_unlock_bh(&mvm->time_event_lock);
3142 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3143 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3144 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3145 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3146 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3147 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3148 struct ieee80211_channel *channel,
3149 struct ieee80211_vif *vif,
3152 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3153 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3154 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3155 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3156 struct iwl_notification_wait wait_time_event;
3157 u32 dtim_interval = vif->bss_conf.dtim_period *
3158 vif->bss_conf.beacon_int;
3160 struct iwl_hs20_roc_req aux_roc_req = {
3161 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3163 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3164 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3165 /* Set the channel info data */
3166 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3167 PHY_BAND_24 : PHY_BAND_5,
3168 .channel_info.channel = channel->hw_value,
3169 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3170 /* Set the time and duration */
3171 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3174 delay = AUX_ROC_MIN_DELAY;
3175 req_dur = MSEC_TO_TU(duration);
3178 * If we are associated we want the delay time to be at least one
3179 * dtim interval so that the FW can wait until after the DTIM and
3180 * then start the time event, this will potentially allow us to
3181 * remain off-channel for the max duration.
3182 * Since we want to use almost a whole dtim interval we would also
3183 * like the delay to be for 2-3 dtim intervals, in case there are
3184 * other time events with higher priority.
3186 if (vif->bss_conf.assoc) {
3187 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3188 /* We cannot remain off-channel longer than the DTIM interval */
3189 if (dtim_interval <= req_dur) {
3190 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3191 if (req_dur <= AUX_ROC_MIN_DURATION)
3192 req_dur = dtim_interval -
3193 AUX_ROC_MIN_SAFETY_BUFFER;
3197 aux_roc_req.duration = cpu_to_le32(req_dur);
3198 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3201 "ROC: Requesting to remain on channel %u for %ums\n",
3202 channel->hw_value, req_dur);
3204 "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3205 duration, delay, dtim_interval);
3207 /* Set the node address */
3208 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3210 lockdep_assert_held(&mvm->mutex);
3212 spin_lock_bh(&mvm->time_event_lock);
3214 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3215 spin_unlock_bh(&mvm->time_event_lock);
3220 te_data->duration = duration;
3221 te_data->id = HOT_SPOT_CMD;
3223 spin_unlock_bh(&mvm->time_event_lock);
3226 * Use a notification wait, which really just processes the
3227 * command response and doesn't wait for anything, in order
3228 * to be able to process the response and get the UID inside
3229 * the RX path. Using CMD_WANT_SKB doesn't work because it
3230 * stores the buffer and then wakes up this thread, by which
3231 * time another notification (that the time event started)
3232 * might already be processed unsuccessfully.
3234 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3235 time_event_response,
3236 ARRAY_SIZE(time_event_response),
3237 iwl_mvm_rx_aux_roc, te_data);
3239 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3243 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3244 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3248 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3249 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3250 /* should never fail */
3255 spin_lock_bh(&mvm->time_event_lock);
3256 iwl_mvm_te_clear_data(mvm, te_data);
3257 spin_unlock_bh(&mvm->time_event_lock);
3263 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3264 struct ieee80211_vif *vif,
3265 struct ieee80211_channel *channel,
3267 enum ieee80211_roc_type type)
3269 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3270 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3271 struct cfg80211_chan_def chandef;
3272 struct iwl_mvm_phy_ctxt *phy_ctxt;
3273 bool band_change_removal;
3276 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3279 flush_work(&mvm->roc_done_wk);
3281 mutex_lock(&mvm->mutex);
3283 switch (vif->type) {
3284 case NL80211_IFTYPE_STATION:
3285 if (fw_has_capa(&mvm->fw->ucode_capa,
3286 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3287 /* Use aux roc framework (HS20) */
3288 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3292 IWL_ERR(mvm, "hotspot not supported\n");
3295 case NL80211_IFTYPE_P2P_DEVICE:
3299 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3304 for (i = 0; i < NUM_PHY_CTX; i++) {
3305 phy_ctxt = &mvm->phy_ctxts[i];
3306 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3309 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3311 * Unbind the P2P_DEVICE from the current PHY context,
3312 * and if the PHY context is not used remove it.
3314 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3315 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3318 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3320 /* Bind the P2P_DEVICE to the current PHY Context */
3321 mvmvif->phy_ctxt = phy_ctxt;
3323 ret = iwl_mvm_binding_add_vif(mvm, vif);
3324 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3327 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3328 goto schedule_time_event;
3332 /* Need to update the PHY context only if the ROC channel changed */
3333 if (channel == mvmvif->phy_ctxt->channel)
3334 goto schedule_time_event;
3336 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3339 * Check if the remain-on-channel is on a different band and that
3340 * requires context removal, see iwl_mvm_phy_ctxt_changed(). If
3341 * so, we'll need to release and then re-configure here, since we
3342 * must not remove a PHY context that's part of a binding.
3344 band_change_removal =
3345 fw_has_capa(&mvm->fw->ucode_capa,
3346 IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT) &&
3347 mvmvif->phy_ctxt->channel->band != chandef.chan->band;
3349 if (mvmvif->phy_ctxt->ref == 1 && !band_change_removal) {
3351 * Change the PHY context configuration as it is currently
3352 * referenced only by the P2P Device MAC (and we can modify it)
3354 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3360 * The PHY context is shared with other MACs (or we're trying to
3361 * switch bands), so remove the P2P Device from the binding,
3362 * allocate an new PHY context and create a new binding.
3364 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3370 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3373 IWL_ERR(mvm, "Failed to change PHY context\n");
3377 /* Unbind the P2P_DEVICE from the current PHY context */
3378 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3379 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3382 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3384 /* Bind the P2P_DEVICE to the new allocated PHY context */
3385 mvmvif->phy_ctxt = phy_ctxt;
3387 ret = iwl_mvm_binding_add_vif(mvm, vif);
3388 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3391 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3394 schedule_time_event:
3395 /* Schedule the time events */
3396 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3399 mutex_unlock(&mvm->mutex);
3400 IWL_DEBUG_MAC80211(mvm, "leave\n");
3404 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3406 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3408 IWL_DEBUG_MAC80211(mvm, "enter\n");
3410 mutex_lock(&mvm->mutex);
3411 iwl_mvm_stop_roc(mvm);
3412 mutex_unlock(&mvm->mutex);
3414 IWL_DEBUG_MAC80211(mvm, "leave\n");
3418 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3419 struct ieee80211_chanctx_conf *ctx)
3421 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3422 struct iwl_mvm_phy_ctxt *phy_ctxt;
3425 lockdep_assert_held(&mvm->mutex);
3427 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3429 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3435 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3436 ctx->rx_chains_static,
3437 ctx->rx_chains_dynamic);
3439 IWL_ERR(mvm, "Failed to add PHY context\n");
3443 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3444 *phy_ctxt_id = phy_ctxt->id;
3449 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3450 struct ieee80211_chanctx_conf *ctx)
3452 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3455 mutex_lock(&mvm->mutex);
3456 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3457 mutex_unlock(&mvm->mutex);
3462 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3463 struct ieee80211_chanctx_conf *ctx)
3465 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3466 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3468 lockdep_assert_held(&mvm->mutex);
3470 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3473 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3474 struct ieee80211_chanctx_conf *ctx)
3476 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3478 mutex_lock(&mvm->mutex);
3479 __iwl_mvm_remove_chanctx(mvm, ctx);
3480 mutex_unlock(&mvm->mutex);
3483 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3484 struct ieee80211_chanctx_conf *ctx,
3487 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3488 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3489 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3491 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3492 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3493 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3494 IEEE80211_CHANCTX_CHANGE_RADAR |
3495 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3496 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3497 phy_ctxt->ref, changed))
3500 mutex_lock(&mvm->mutex);
3501 iwl_mvm_bt_coex_vif_change(mvm);
3502 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3503 ctx->rx_chains_static,
3504 ctx->rx_chains_dynamic);
3505 mutex_unlock(&mvm->mutex);
3508 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3509 struct ieee80211_vif *vif,
3510 struct ieee80211_chanctx_conf *ctx,
3511 bool switching_chanctx)
3513 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3514 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3515 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3518 lockdep_assert_held(&mvm->mutex);
3520 mvmvif->phy_ctxt = phy_ctxt;
3522 switch (vif->type) {
3523 case NL80211_IFTYPE_AP:
3524 /* only needed if we're switching chanctx (i.e. during CSA) */
3525 if (switching_chanctx) {
3526 mvmvif->ap_ibss_active = true;
3529 case NL80211_IFTYPE_ADHOC:
3531 * The AP binding flow is handled as part of the start_ap flow
3532 * (in bss_info_changed), similarly for IBSS.
3536 case NL80211_IFTYPE_STATION:
3537 mvmvif->csa_bcn_pending = false;
3539 case NL80211_IFTYPE_MONITOR:
3540 /* always disable PS when a monitor interface is active */
3541 mvmvif->ps_disabled = true;
3548 ret = iwl_mvm_binding_add_vif(mvm, vif);
3553 * Power state must be updated before quotas,
3554 * otherwise fw will complain.
3556 iwl_mvm_power_update_mac(mvm);
3558 /* Setting the quota at this stage is only required for monitor
3559 * interfaces. For the other types, the bss_info changed flow
3560 * will handle quota settings.
3562 if (vif->type == NL80211_IFTYPE_MONITOR) {
3563 mvmvif->monitor_active = true;
3564 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3566 goto out_remove_binding;
3568 ret = iwl_mvm_add_snif_sta(mvm, vif);
3570 goto out_remove_binding;
3574 /* Handle binding during CSA */
3575 if (vif->type == NL80211_IFTYPE_AP) {
3576 iwl_mvm_update_quotas(mvm, false, NULL);
3577 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3580 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3581 u32 duration = 3 * vif->bss_conf.beacon_int;
3583 /* iwl_mvm_protect_session() reads directly from the
3584 * device (the system time), so make sure it is
3587 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3589 goto out_remove_binding;
3591 /* Protect the session to make sure we hear the first
3592 * beacon on the new channel.
3594 mvmvif->csa_bcn_pending = true;
3595 iwl_mvm_protect_session(mvm, vif, duration, duration,
3596 vif->bss_conf.beacon_int / 2,
3599 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3601 iwl_mvm_update_quotas(mvm, false, NULL);
3607 iwl_mvm_binding_remove_vif(mvm, vif);
3608 iwl_mvm_power_update_mac(mvm);
3611 mvmvif->phy_ctxt = NULL;
3614 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3615 struct ieee80211_vif *vif,
3616 struct ieee80211_chanctx_conf *ctx)
3618 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3621 mutex_lock(&mvm->mutex);
3622 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3623 mutex_unlock(&mvm->mutex);
3628 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3629 struct ieee80211_vif *vif,
3630 struct ieee80211_chanctx_conf *ctx,
3631 bool switching_chanctx)
3633 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3634 struct ieee80211_vif *disabled_vif = NULL;
3636 lockdep_assert_held(&mvm->mutex);
3638 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3640 switch (vif->type) {
3641 case NL80211_IFTYPE_ADHOC:
3643 case NL80211_IFTYPE_MONITOR:
3644 mvmvif->monitor_active = false;
3645 mvmvif->ps_disabled = false;
3646 iwl_mvm_rm_snif_sta(mvm, vif);
3648 case NL80211_IFTYPE_AP:
3649 /* This part is triggered only during CSA */
3650 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3653 mvmvif->csa_countdown = false;
3655 /* Set CS bit on all the stations */
3656 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3658 /* Save blocked iface, the timeout is set on the next beacon */
3659 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3661 mvmvif->ap_ibss_active = false;
3663 case NL80211_IFTYPE_STATION:
3664 if (!switching_chanctx)
3669 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3675 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3676 iwl_mvm_binding_remove_vif(mvm, vif);
3679 mvmvif->phy_ctxt = NULL;
3680 iwl_mvm_power_update_mac(mvm);
3683 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3684 struct ieee80211_vif *vif,
3685 struct ieee80211_chanctx_conf *ctx)
3687 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3689 mutex_lock(&mvm->mutex);
3690 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3691 mutex_unlock(&mvm->mutex);
3695 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3696 struct ieee80211_vif_chanctx_switch *vifs)
3700 mutex_lock(&mvm->mutex);
3701 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3702 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3704 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3706 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3710 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3714 "failed to assign new_ctx during channel switch\n");
3718 /* we don't support TDLS during DCM - can be caused by channel switch */
3719 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3720 iwl_mvm_teardown_tdls_peers(mvm);
3725 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3728 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3729 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3733 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3735 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3742 /* things keep failing, better restart the hw */
3743 iwl_mvm_nic_restart(mvm, false);
3746 mutex_unlock(&mvm->mutex);
3752 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3753 struct ieee80211_vif_chanctx_switch *vifs)
3757 mutex_lock(&mvm->mutex);
3758 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3760 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3764 "failed to assign new_ctx during channel switch\n");
3771 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3773 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3780 /* things keep failing, better restart the hw */
3781 iwl_mvm_nic_restart(mvm, false);
3784 mutex_unlock(&mvm->mutex);
3789 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3790 struct ieee80211_vif_chanctx_switch *vifs,
3792 enum ieee80211_chanctx_switch_mode mode)
3794 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3797 /* we only support a single-vif right now */
3802 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3803 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3805 case CHANCTX_SWMODE_REASSIGN_VIF:
3806 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
3816 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
3818 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3820 return mvm->ibss_manager;
3823 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3824 struct ieee80211_sta *sta,
3827 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3828 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3830 if (!mvm_sta || !mvm_sta->vif) {
3831 IWL_ERR(mvm, "Station is not associated to a vif\n");
3835 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3838 #ifdef CONFIG_NL80211_TESTMODE
3839 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3840 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3841 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
3842 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
3845 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3846 struct ieee80211_vif *vif,
3847 void *data, int len)
3849 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3853 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
3858 if (!tb[IWL_MVM_TM_ATTR_CMD])
3861 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3862 case IWL_MVM_TM_CMD_SET_NOA:
3863 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3864 !vif->bss_conf.enable_beacon ||
3865 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3868 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3869 if (noa_duration >= vif->bss_conf.beacon_int)
3872 mvm->noa_duration = noa_duration;
3875 return iwl_mvm_update_quotas(mvm, false, NULL);
3876 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3877 /* must be associated client vif - ignore authorized */
3878 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3879 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3880 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3883 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
3884 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3885 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3891 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3892 struct ieee80211_vif *vif,
3893 void *data, int len)
3895 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3898 mutex_lock(&mvm->mutex);
3899 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3900 mutex_unlock(&mvm->mutex);
3906 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3907 struct ieee80211_vif *vif,
3908 struct ieee80211_channel_switch *chsw)
3910 /* By implementing this operation, we prevent mac80211 from
3911 * starting its own channel switch timer, so that we can call
3912 * ieee80211_chswitch_done() ourselves at the right time
3913 * (which is when the absence time event starts).
3916 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3917 "dummy channel switch op\n");
3920 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3921 struct ieee80211_vif *vif,
3922 struct ieee80211_channel_switch *chsw)
3924 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3925 struct ieee80211_vif *csa_vif;
3926 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3930 mutex_lock(&mvm->mutex);
3932 mvmvif->csa_failed = false;
3934 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
3935 chsw->chandef.center_freq1);
3937 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
3938 ieee80211_vif_to_wdev(vif),
3939 FW_DBG_TRIGGER_CHANNEL_SWITCH);
3941 switch (vif->type) {
3942 case NL80211_IFTYPE_AP:
3944 rcu_dereference_protected(mvm->csa_vif,
3945 lockdep_is_held(&mvm->mutex));
3946 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3947 "Another CSA is already in progress")) {
3952 /* we still didn't unblock tx. prevent new CS meanwhile */
3953 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
3954 lockdep_is_held(&mvm->mutex))) {
3959 rcu_assign_pointer(mvm->csa_vif, vif);
3961 if (WARN_ONCE(mvmvif->csa_countdown,
3962 "Previous CSA countdown didn't complete")) {
3967 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
3970 case NL80211_IFTYPE_STATION:
3971 if (mvmvif->lqm_active)
3972 iwl_mvm_send_lqm_cmd(vif,
3973 LQM_CMD_OPERATION_STOP_MEASUREMENT,
3976 /* Schedule the time event to a bit before beacon 1,
3977 * to make sure we're in the new channel when the
3978 * GO/AP arrives. In case count <= 1 immediately schedule the
3979 * TE (this might result with some packet loss or connection
3982 if (chsw->count <= 1)
3985 apply_time = chsw->device_timestamp +
3986 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3987 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
3990 iwl_mvm_csa_client_absent(mvm, vif);
3992 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
3994 if (mvmvif->bf_data.bf_enabled) {
3995 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4005 mvmvif->ps_disabled = true;
4007 ret = iwl_mvm_power_update_ps(mvm);
4011 /* we won't be on this channel any longer */
4012 iwl_mvm_teardown_tdls_peers(mvm);
4015 mutex_unlock(&mvm->mutex);
4020 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
4021 struct ieee80211_vif *vif)
4023 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4024 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4027 mutex_lock(&mvm->mutex);
4029 if (mvmvif->csa_failed) {
4030 mvmvif->csa_failed = false;
4035 if (vif->type == NL80211_IFTYPE_STATION) {
4036 struct iwl_mvm_sta *mvmsta;
4038 mvmvif->csa_bcn_pending = false;
4039 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
4042 if (WARN_ON(!mvmsta)) {
4047 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
4049 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4051 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4055 iwl_mvm_stop_session_protection(mvm, vif);
4058 mvmvif->ps_disabled = false;
4060 ret = iwl_mvm_power_update_ps(mvm);
4063 mutex_unlock(&mvm->mutex);
4068 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4071 if (iwl_mvm_has_new_tx_api(mvm))
4072 /* TODO new tx api */
4074 "Need to implement flush TX queue\n");
4076 iwl_mvm_flush_tx_path(mvm,
4077 iwl_mvm_flushable_queues(mvm) & queues,
4080 if (iwl_mvm_has_new_tx_api(mvm)) {
4081 struct ieee80211_sta *sta;
4084 mutex_lock(&mvm->mutex);
4086 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4087 sta = rcu_dereference_protected(
4088 mvm->fw_id_to_mac_id[i],
4089 lockdep_is_held(&mvm->mutex));
4090 if (IS_ERR_OR_NULL(sta))
4093 iwl_mvm_wait_sta_queues_empty(mvm,
4094 iwl_mvm_sta_from_mac80211(sta));
4097 mutex_unlock(&mvm->mutex);
4099 iwl_trans_wait_tx_queues_empty(mvm->trans,
4105 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4106 struct ieee80211_vif *vif, u32 queues, bool drop)
4108 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4109 struct iwl_mvm_vif *mvmvif;
4110 struct iwl_mvm_sta *mvmsta;
4111 struct ieee80211_sta *sta;
4116 iwl_mvm_flush_no_vif(mvm, queues, drop);
4120 if (vif->type != NL80211_IFTYPE_STATION)
4123 /* Make sure we're done with the deferred traffic before flushing */
4124 flush_work(&mvm->add_stream_wk);
4126 mutex_lock(&mvm->mutex);
4127 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4129 /* flush the AP-station and all TDLS peers */
4130 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4131 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4132 lockdep_is_held(&mvm->mutex));
4133 if (IS_ERR_OR_NULL(sta))
4136 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4137 if (mvmsta->vif != vif)
4140 /* make sure only TDLS peers or the AP are flushed */
4141 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4144 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4145 IWL_ERR(mvm, "flush request fail\n");
4147 msk |= mvmsta->tfd_queue_msk;
4148 if (iwl_mvm_has_new_tx_api(mvm))
4149 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4153 mutex_unlock(&mvm->mutex);
4155 /* this can take a while, and we may need/want other operations
4156 * to succeed while doing this, so do it without the mutex held
4158 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4159 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4162 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4163 struct survey_info *survey)
4165 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4168 memset(survey, 0, sizeof(*survey));
4170 /* only support global statistics right now */
4174 if (!fw_has_capa(&mvm->fw->ucode_capa,
4175 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4178 mutex_lock(&mvm->mutex);
4180 if (iwl_mvm_firmware_running(mvm)) {
4181 ret = iwl_mvm_request_statistics(mvm, false);
4186 survey->filled = SURVEY_INFO_TIME |
4187 SURVEY_INFO_TIME_RX |
4188 SURVEY_INFO_TIME_TX |
4189 SURVEY_INFO_TIME_SCAN;
4190 survey->time = mvm->accu_radio_stats.on_time_rf +
4191 mvm->radio_stats.on_time_rf;
4192 do_div(survey->time, USEC_PER_MSEC);
4194 survey->time_rx = mvm->accu_radio_stats.rx_time +
4195 mvm->radio_stats.rx_time;
4196 do_div(survey->time_rx, USEC_PER_MSEC);
4198 survey->time_tx = mvm->accu_radio_stats.tx_time +
4199 mvm->radio_stats.tx_time;
4200 do_div(survey->time_tx, USEC_PER_MSEC);
4202 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4203 mvm->radio_stats.on_time_scan;
4204 do_div(survey->time_scan, USEC_PER_MSEC);
4208 mutex_unlock(&mvm->mutex);
4212 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4213 struct ieee80211_vif *vif,
4214 struct ieee80211_sta *sta,
4215 struct station_info *sinfo)
4217 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4218 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4219 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4221 if (mvmsta->avg_energy) {
4222 sinfo->signal_avg = mvmsta->avg_energy;
4223 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
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,
4328 iwl_mvm_event_frame_timeout_callback(struct iwl_mvm *mvm,
4329 struct ieee80211_vif *vif,
4330 const struct ieee80211_event *event)
4332 struct iwl_fw_dbg_trigger_tlv *trig;
4333 struct iwl_fw_dbg_trigger_ba *ba_trig;
4335 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
4338 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
4339 ba_trig = (void *)trig->data;
4340 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4341 ieee80211_vif_to_wdev(vif), trig))
4344 if (!(le16_to_cpu(ba_trig->frame_timeout) & BIT(event->u.ba.tid)))
4347 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4348 "Frame from %pM timed out, tid %d",
4349 event->u.ba.sta->addr, event->u.ba.tid);
4352 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4353 struct ieee80211_vif *vif,
4354 const struct ieee80211_event *event)
4356 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4358 switch (event->type) {
4360 iwl_mvm_event_mlme_callback(mvm, vif, event);
4363 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4365 case BA_FRAME_TIMEOUT:
4366 iwl_mvm_event_frame_timeout_callback(mvm, vif, event);
4373 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4374 struct iwl_mvm_internal_rxq_notif *notif,
4377 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4380 lockdep_assert_held(&mvm->mutex);
4382 /* TODO - remove a000 disablement when we have RXQ config API */
4383 if (!iwl_mvm_has_new_rx_api(mvm) ||
4384 mvm->trans->cfg->device_family == IWL_DEVICE_FAMILY_A000)
4387 notif->cookie = mvm->queue_sync_cookie;
4390 atomic_set(&mvm->queue_sync_counter,
4391 mvm->trans->num_rx_queues);
4393 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4395 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4400 ret = wait_event_timeout(mvm->rx_sync_waitq,
4401 atomic_read(&mvm->queue_sync_counter) == 0 ||
4402 iwl_mvm_is_radio_killed(mvm),
4404 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4408 atomic_set(&mvm->queue_sync_counter, 0);
4409 mvm->queue_sync_cookie++;
4412 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4414 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4415 struct iwl_mvm_internal_rxq_notif data = {
4416 .type = IWL_MVM_RXQ_EMPTY,
4420 mutex_lock(&mvm->mutex);
4421 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
4422 mutex_unlock(&mvm->mutex);
4425 const struct ieee80211_ops iwl_mvm_hw_ops = {
4426 .tx = iwl_mvm_mac_tx,
4427 .ampdu_action = iwl_mvm_mac_ampdu_action,
4428 .start = iwl_mvm_mac_start,
4429 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
4430 .stop = iwl_mvm_mac_stop,
4431 .add_interface = iwl_mvm_mac_add_interface,
4432 .remove_interface = iwl_mvm_mac_remove_interface,
4433 .config = iwl_mvm_mac_config,
4434 .prepare_multicast = iwl_mvm_prepare_multicast,
4435 .configure_filter = iwl_mvm_configure_filter,
4436 .config_iface_filter = iwl_mvm_config_iface_filter,
4437 .bss_info_changed = iwl_mvm_bss_info_changed,
4438 .hw_scan = iwl_mvm_mac_hw_scan,
4439 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
4440 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
4441 .sta_state = iwl_mvm_mac_sta_state,
4442 .sta_notify = iwl_mvm_mac_sta_notify,
4443 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
4444 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
4445 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
4446 .sta_rc_update = iwl_mvm_sta_rc_update,
4447 .conf_tx = iwl_mvm_mac_conf_tx,
4448 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
4449 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
4450 .flush = iwl_mvm_mac_flush,
4451 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4452 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
4453 .set_key = iwl_mvm_mac_set_key,
4454 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4455 .remain_on_channel = iwl_mvm_roc,
4456 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
4457 .add_chanctx = iwl_mvm_add_chanctx,
4458 .remove_chanctx = iwl_mvm_remove_chanctx,
4459 .change_chanctx = iwl_mvm_change_chanctx,
4460 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4461 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
4462 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
4464 .start_ap = iwl_mvm_start_ap_ibss,
4465 .stop_ap = iwl_mvm_stop_ap_ibss,
4466 .join_ibss = iwl_mvm_start_ap_ibss,
4467 .leave_ibss = iwl_mvm_stop_ap_ibss,
4469 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4471 .set_tim = iwl_mvm_set_tim,
4473 .channel_switch = iwl_mvm_channel_switch,
4474 .pre_channel_switch = iwl_mvm_pre_channel_switch,
4475 .post_channel_switch = iwl_mvm_post_channel_switch,
4477 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4478 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4479 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4481 .event_callback = iwl_mvm_mac_event_callback,
4483 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4485 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4487 #ifdef CONFIG_PM_SLEEP
4489 .suspend = iwl_mvm_suspend,
4490 .resume = iwl_mvm_resume,
4491 .set_wakeup = iwl_mvm_set_wakeup,
4492 .set_rekey_data = iwl_mvm_set_rekey_data,
4493 #if IS_ENABLED(CONFIG_IPV6)
4494 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4496 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4498 .get_survey = iwl_mvm_mac_get_survey,
4499 .sta_statistics = iwl_mvm_mac_sta_statistics,