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 = {
1613 lockdep_assert_held(&mvm->mutex);
1615 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1618 ieee80211_iterate_active_interfaces_atomic(
1619 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1620 iwl_mvm_mc_iface_iterator, &iter_data);
1623 * Send a (synchronous) ech command so that we wait for the
1624 * multiple asynchronous MCAST_FILTER_CMD commands sent by
1625 * the interface iterator. Otherwise, we might get here over
1626 * and over again (by userspace just sending a lot of these)
1627 * and the CPU can send them faster than the firmware can
1629 * Note that the CPU is still faster - but with this we'll
1630 * actually send fewer commands overall because the CPU will
1631 * not schedule the work in mac80211 as frequently if it's
1632 * still running when rescheduled (possibly multiple times).
1634 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1636 IWL_ERR(mvm, "Failed to synchronize multicast groups update\n");
1639 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1640 struct netdev_hw_addr_list *mc_list)
1642 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1643 struct iwl_mcast_filter_cmd *cmd;
1644 struct netdev_hw_addr *addr;
1649 addr_count = netdev_hw_addr_list_count(mc_list);
1650 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1651 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1655 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1656 cmd = kzalloc(len, GFP_ATOMIC);
1662 return (u64)(unsigned long)cmd;
1665 netdev_hw_addr_list_for_each(addr, mc_list) {
1666 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1667 cmd->count, addr->addr);
1668 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1669 addr->addr, ETH_ALEN);
1673 return (u64)(unsigned long)cmd;
1676 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1677 unsigned int changed_flags,
1678 unsigned int *total_flags,
1681 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1682 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1684 mutex_lock(&mvm->mutex);
1686 /* replace previous configuration */
1687 kfree(mvm->mcast_filter_cmd);
1688 mvm->mcast_filter_cmd = cmd;
1693 if (changed_flags & FIF_ALLMULTI)
1694 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1699 iwl_mvm_recalc_multicast(mvm);
1701 mutex_unlock(&mvm->mutex);
1705 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1706 struct ieee80211_vif *vif,
1707 unsigned int filter_flags,
1708 unsigned int changed_flags)
1710 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1712 /* We support only filter for probe requests */
1713 if (!(changed_flags & FIF_PROBE_REQ))
1716 /* Supported only for p2p client interfaces */
1717 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1721 mutex_lock(&mvm->mutex);
1722 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1723 mutex_unlock(&mvm->mutex);
1726 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1727 struct iwl_bcast_iter_data {
1728 struct iwl_mvm *mvm;
1729 struct iwl_bcast_filter_cmd *cmd;
1734 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1735 const struct iwl_fw_bcast_filter *in_filter,
1736 struct iwl_fw_bcast_filter *out_filter)
1738 struct iwl_fw_bcast_filter_attr *attr;
1741 memcpy(out_filter, in_filter, sizeof(*out_filter));
1743 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1744 attr = &out_filter->attrs[i];
1749 switch (attr->reserved1) {
1750 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1751 if (vif->bss_conf.arp_addr_cnt != 1) {
1756 attr->val = vif->bss_conf.arp_addr_list[0];
1758 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1759 attr->val = *(__be32 *)&vif->addr[2];
1764 attr->reserved1 = 0;
1765 out_filter->num_attrs++;
1769 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1770 struct ieee80211_vif *vif)
1772 struct iwl_bcast_iter_data *data = _data;
1773 struct iwl_mvm *mvm = data->mvm;
1774 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1775 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1776 struct iwl_fw_bcast_mac *bcast_mac;
1779 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1782 bcast_mac = &cmd->macs[mvmvif->id];
1785 * enable filtering only for associated stations, but not for P2P
1788 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1789 !vif->bss_conf.assoc)
1792 bcast_mac->default_discard = 1;
1794 /* copy all configured filters */
1795 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1797 * Make sure we don't exceed our filters limit.
1798 * if there is still a valid filter to be configured,
1799 * be on the safe side and just allow bcast for this mac.
1801 if (WARN_ON_ONCE(data->current_filter >=
1802 ARRAY_SIZE(cmd->filters))) {
1803 bcast_mac->default_discard = 0;
1804 bcast_mac->attached_filters = 0;
1808 iwl_mvm_set_bcast_filter(vif,
1809 &mvm->bcast_filters[i],
1810 &cmd->filters[data->current_filter]);
1812 /* skip current filter if it contains no attributes */
1813 if (!cmd->filters[data->current_filter].num_attrs)
1816 /* attach the filter to current mac */
1817 bcast_mac->attached_filters |=
1818 cpu_to_le16(BIT(data->current_filter));
1820 data->current_filter++;
1824 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1825 struct iwl_bcast_filter_cmd *cmd)
1827 struct iwl_bcast_iter_data iter_data = {
1832 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1835 memset(cmd, 0, sizeof(*cmd));
1836 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1837 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1839 #ifdef CONFIG_IWLWIFI_DEBUGFS
1840 /* use debugfs filters/macs if override is configured */
1841 if (mvm->dbgfs_bcast_filtering.override) {
1842 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1843 sizeof(cmd->filters));
1844 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1850 /* if no filters are configured, do nothing */
1851 if (!mvm->bcast_filters)
1854 /* configure and attach these filters for each associated sta vif */
1855 ieee80211_iterate_active_interfaces(
1856 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1857 iwl_mvm_bcast_filter_iterator, &iter_data);
1862 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1864 struct iwl_bcast_filter_cmd cmd;
1866 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1869 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1872 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1876 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1882 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1883 struct ieee80211_vif *vif)
1885 struct iwl_mu_group_mgmt_cmd cmd = {};
1887 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1888 WLAN_MEMBERSHIP_LEN);
1889 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1890 WLAN_USER_POSITION_LEN);
1892 return iwl_mvm_send_cmd_pdu(mvm,
1893 WIDE_ID(DATA_PATH_GROUP,
1894 UPDATE_MU_GROUPS_CMD),
1895 0, sizeof(cmd), &cmd);
1898 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1899 struct ieee80211_vif *vif)
1901 if (vif->mu_mimo_owner) {
1902 struct iwl_mu_group_mgmt_notif *notif = _data;
1905 * MU-MIMO Group Id action frame is little endian. We treat
1906 * the data received from firmware as if it came from the
1907 * action frame, so no conversion is needed.
1909 ieee80211_update_mu_groups(vif,
1910 (u8 *)¬if->membership_status,
1911 (u8 *)¬if->user_position);
1915 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1916 struct iwl_rx_cmd_buffer *rxb)
1918 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1919 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1921 ieee80211_iterate_active_interfaces_atomic(
1922 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1923 iwl_mvm_mu_mimo_iface_iterator, notif);
1926 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1927 struct ieee80211_vif *vif,
1928 struct ieee80211_bss_conf *bss_conf,
1931 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1935 * Re-calculate the tsf id, as the master-slave relations depend on the
1936 * beacon interval, which was not known when the station interface was
1939 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1940 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1942 if (changes & BSS_CHANGED_ASSOC && !bss_conf->assoc &&
1944 iwl_mvm_send_lqm_cmd(vif, LQM_CMD_OPERATION_STOP_MEASUREMENT,
1948 * If we're not associated yet, take the (new) BSSID before associating
1949 * so the firmware knows. If we're already associated, then use the old
1950 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1951 * branch for disassociation below.
1953 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1954 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1956 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
1958 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1960 /* after sending it once, adopt mac80211 data */
1961 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1962 mvmvif->associated = bss_conf->assoc;
1964 if (changes & BSS_CHANGED_ASSOC) {
1965 if (bss_conf->assoc) {
1966 /* clear statistics to get clean beacon counter */
1967 iwl_mvm_request_statistics(mvm, true);
1968 memset(&mvmvif->beacon_stats, 0,
1969 sizeof(mvmvif->beacon_stats));
1971 /* add quota for this interface */
1972 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1974 IWL_ERR(mvm, "failed to update quotas\n");
1978 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1981 * If we're restarting then the firmware will
1982 * obviously have lost synchronisation with
1983 * the AP. It will attempt to synchronise by
1984 * itself, but we can make it more reliable by
1985 * scheduling a session protection time event.
1987 * The firmware needs to receive a beacon to
1988 * catch up with synchronisation, use 110% of
1989 * the beacon interval.
1991 * Set a large maximum delay to allow for more
1992 * than a single interface.
1994 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1995 iwl_mvm_protect_session(mvm, vif, dur, dur,
1999 iwl_mvm_sf_update(mvm, vif, false);
2000 iwl_mvm_power_vif_assoc(mvm, vif);
2002 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
2003 iwl_mvm_update_smps(mvm, vif,
2004 IWL_MVM_SMPS_REQ_PROT,
2005 IEEE80211_SMPS_DYNAMIC);
2007 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2009 * If update fails - SF might be running in associated
2010 * mode while disassociated - which is forbidden.
2012 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
2013 "Failed to update SF upon disassociation\n");
2016 * If we get an assert during the connection (after the
2017 * station has been added, but before the vif is set
2018 * to associated), mac80211 will re-add the station and
2019 * then configure the vif. Since the vif is not
2020 * associated, we would remove the station here and
2021 * this would fail the recovery.
2023 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2026 * Remove AP station now that
2027 * the MAC is unassoc
2029 ret = iwl_mvm_rm_sta_id(mvm, vif,
2033 "failed to remove AP station\n");
2035 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2036 mvm->d0i3_ap_sta_id =
2037 IWL_MVM_INVALID_STA;
2038 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2041 /* remove quota for this interface */
2042 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2044 IWL_ERR(mvm, "failed to update quotas\n");
2047 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2049 /* this will take the cleared BSSID from bss_conf */
2050 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2053 "failed to update MAC %pM (clear after unassoc)\n",
2058 * The firmware tracks the MU-MIMO group on its own.
2059 * However, on HW restart we should restore this data.
2061 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2062 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2063 ret = iwl_mvm_update_mu_groups(mvm, vif);
2066 "failed to update VHT MU_MIMO groups\n");
2069 iwl_mvm_recalc_multicast(mvm);
2070 iwl_mvm_configure_bcast_filter(mvm);
2072 /* reset rssi values */
2073 mvmvif->bf_data.ave_beacon_signal = 0;
2075 iwl_mvm_bt_coex_vif_change(mvm);
2076 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2077 IEEE80211_SMPS_AUTOMATIC);
2078 if (fw_has_capa(&mvm->fw->ucode_capa,
2079 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2080 iwl_mvm_config_scan(mvm);
2083 if (changes & BSS_CHANGED_BEACON_INFO) {
2085 * We received a beacon from the associated AP so
2086 * remove the session protection.
2088 iwl_mvm_stop_session_protection(mvm, vif);
2090 iwl_mvm_sf_update(mvm, vif, false);
2091 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2094 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2096 * Send power command on every beacon change,
2097 * because we may have not enabled beacon abort yet.
2099 BSS_CHANGED_BEACON_INFO)) {
2100 ret = iwl_mvm_power_update_mac(mvm);
2102 IWL_ERR(mvm, "failed to update power mode\n");
2105 if (changes & BSS_CHANGED_TXPOWER) {
2106 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2108 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2111 if (changes & BSS_CHANGED_CQM) {
2112 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2113 /* reset cqm events tracking */
2114 mvmvif->bf_data.last_cqm_event = 0;
2115 if (mvmvif->bf_data.bf_enabled) {
2116 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2119 "failed to update CQM thresholds\n");
2123 if (changes & BSS_CHANGED_ARP_FILTER) {
2124 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2125 iwl_mvm_configure_bcast_filter(mvm);
2129 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2130 struct ieee80211_vif *vif)
2132 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2133 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2137 * iwl_mvm_mac_ctxt_add() might read directly from the device
2138 * (the system time), so make sure it is available.
2140 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2144 mutex_lock(&mvm->mutex);
2146 /* Send the beacon template */
2147 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2152 * Re-calculate the tsf id, as the master-slave relations depend on the
2153 * beacon interval, which was not known when the AP interface was added.
2155 if (vif->type == NL80211_IFTYPE_AP)
2156 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2158 mvmvif->ap_assoc_sta_count = 0;
2160 /* Add the mac context */
2161 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2165 /* Perform the binding */
2166 ret = iwl_mvm_binding_add_vif(mvm, vif);
2171 * This is not very nice, but the simplest:
2172 * For older FWs adding the mcast sta before the bcast station may
2173 * cause assert 0x2b00.
2174 * This is fixed in later FW so make the order of removal depend on
2177 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2178 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2182 * Send the bcast station. At this stage the TBTT and DTIM time
2183 * events are added and applied to the scheduler
2185 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2187 iwl_mvm_rm_mcast_sta(mvm, vif);
2192 * Send the bcast station. At this stage the TBTT and DTIM time
2193 * events are added and applied to the scheduler
2195 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2198 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2200 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2205 /* must be set before quota calculations */
2206 mvmvif->ap_ibss_active = true;
2208 /* power updated needs to be done before quotas */
2209 iwl_mvm_power_update_mac(mvm);
2211 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2213 goto out_quota_failed;
2215 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2216 if (vif->p2p && mvm->p2p_device_vif)
2217 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2219 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2221 iwl_mvm_bt_coex_vif_change(mvm);
2223 /* we don't support TDLS during DCM */
2224 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2225 iwl_mvm_teardown_tdls_peers(mvm);
2230 iwl_mvm_power_update_mac(mvm);
2231 mvmvif->ap_ibss_active = false;
2232 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2233 iwl_mvm_rm_mcast_sta(mvm, vif);
2235 iwl_mvm_binding_remove_vif(mvm, vif);
2237 iwl_mvm_mac_ctxt_remove(mvm, vif);
2239 mutex_unlock(&mvm->mutex);
2240 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2244 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2245 struct ieee80211_vif *vif)
2247 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2248 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2250 iwl_mvm_prepare_mac_removal(mvm, vif);
2252 mutex_lock(&mvm->mutex);
2254 /* Handle AP stop while in CSA */
2255 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2256 iwl_mvm_remove_time_event(mvm, mvmvif,
2257 &mvmvif->time_event_data);
2258 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2259 mvmvif->csa_countdown = false;
2262 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2263 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2264 mvm->csa_tx_block_bcn_timeout = 0;
2267 mvmvif->ap_ibss_active = false;
2268 mvm->ap_last_beacon_gp2 = 0;
2270 iwl_mvm_bt_coex_vif_change(mvm);
2272 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2274 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2275 if (vif->p2p && mvm->p2p_device_vif)
2276 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2278 iwl_mvm_update_quotas(mvm, false, NULL);
2281 * This is not very nice, but the simplest:
2282 * For older FWs removing the mcast sta before the bcast station may
2283 * cause assert 0x2b00.
2284 * This is fixed in later FW (which will stop beaconing when removing
2286 * So make the order of removal depend on the TLV
2288 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2289 iwl_mvm_rm_mcast_sta(mvm, vif);
2290 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2291 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2292 iwl_mvm_rm_mcast_sta(mvm, vif);
2293 iwl_mvm_binding_remove_vif(mvm, vif);
2295 iwl_mvm_power_update_mac(mvm);
2297 iwl_mvm_mac_ctxt_remove(mvm, vif);
2299 mutex_unlock(&mvm->mutex);
2303 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2304 struct ieee80211_vif *vif,
2305 struct ieee80211_bss_conf *bss_conf,
2308 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2310 /* Changes will be applied when the AP/IBSS is started */
2311 if (!mvmvif->ap_ibss_active)
2314 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2315 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2316 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2317 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2319 /* Need to send a new beacon template to the FW */
2320 if (changes & BSS_CHANGED_BEACON &&
2321 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2322 IWL_WARN(mvm, "Failed updating beacon data\n");
2324 if (changes & BSS_CHANGED_TXPOWER) {
2325 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2327 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2331 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2332 struct ieee80211_vif *vif,
2333 struct ieee80211_bss_conf *bss_conf,
2336 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2339 * iwl_mvm_bss_info_changed_station() might call
2340 * iwl_mvm_protect_session(), which reads directly from
2341 * the device (the system time), so make sure it is available.
2343 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2346 mutex_lock(&mvm->mutex);
2348 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2349 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2351 switch (vif->type) {
2352 case NL80211_IFTYPE_STATION:
2353 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2355 case NL80211_IFTYPE_AP:
2356 case NL80211_IFTYPE_ADHOC:
2357 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2359 case NL80211_IFTYPE_MONITOR:
2360 if (changes & BSS_CHANGED_MU_GROUPS)
2361 iwl_mvm_update_mu_groups(mvm, vif);
2364 /* shouldn't happen */
2368 mutex_unlock(&mvm->mutex);
2369 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2372 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2373 struct ieee80211_vif *vif,
2374 struct ieee80211_scan_request *hw_req)
2376 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2379 if (hw_req->req.n_channels == 0 ||
2380 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2383 mutex_lock(&mvm->mutex);
2384 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2385 mutex_unlock(&mvm->mutex);
2390 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2391 struct ieee80211_vif *vif)
2393 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2395 mutex_lock(&mvm->mutex);
2397 /* Due to a race condition, it's possible that mac80211 asks
2398 * us to stop a hw_scan when it's already stopped. This can
2399 * happen, for instance, if we stopped the scan ourselves,
2400 * called ieee80211_scan_completed() and the userspace called
2401 * cancel scan scan before ieee80211_scan_work() could run.
2402 * To handle that, simply return if the scan is not running.
2404 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2405 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2407 mutex_unlock(&mvm->mutex);
2411 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2412 struct ieee80211_sta *sta, u16 tids,
2414 enum ieee80211_frame_release_type reason,
2417 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2419 /* Called when we need to transmit (a) frame(s) from mac80211 */
2421 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2422 tids, more_data, false);
2426 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2427 struct ieee80211_sta *sta, u16 tids,
2429 enum ieee80211_frame_release_type reason,
2432 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2434 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2436 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2437 tids, more_data, true);
2440 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2441 enum sta_notify_cmd cmd,
2442 struct ieee80211_sta *sta)
2444 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2445 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2446 unsigned long txqs = 0, tids = 0;
2450 * If we have TVQM then we get too high queue numbers - luckily
2451 * we really shouldn't get here with that because such hardware
2452 * should have firmware supporting buffer station offload.
2454 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2457 spin_lock_bh(&mvmsta->lock);
2458 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2459 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2461 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2464 __set_bit(tid_data->txq_id, &txqs);
2466 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2469 __set_bit(tid, &tids);
2473 case STA_NOTIFY_SLEEP:
2474 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2475 ieee80211_sta_set_buffered(sta, tid, true);
2478 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2480 * The fw updates the STA to be asleep. Tx packets on the Tx
2481 * queues to this station will not be transmitted. The fw will
2482 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2485 case STA_NOTIFY_AWAKE:
2486 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2490 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2491 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2496 spin_unlock_bh(&mvmsta->lock);
2499 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2500 struct ieee80211_vif *vif,
2501 enum sta_notify_cmd cmd,
2502 struct ieee80211_sta *sta)
2504 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2507 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2509 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2510 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2511 struct ieee80211_sta *sta;
2512 struct iwl_mvm_sta *mvmsta;
2513 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2515 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2519 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2520 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2525 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2528 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2533 if (mvmsta->sleeping != sleeping) {
2534 mvmsta->sleeping = sleeping;
2535 __iwl_mvm_mac_sta_notify(mvm->hw,
2536 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2538 ieee80211_sta_ps_transition(sta, sleeping);
2542 switch (notif->type) {
2543 case IWL_MVM_PM_EVENT_AWAKE:
2544 case IWL_MVM_PM_EVENT_ASLEEP:
2546 case IWL_MVM_PM_EVENT_UAPSD:
2547 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2549 case IWL_MVM_PM_EVENT_PS_POLL:
2550 ieee80211_sta_pspoll(sta);
2560 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2561 struct ieee80211_vif *vif,
2562 struct ieee80211_sta *sta)
2564 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2565 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2568 * This is called before mac80211 does RCU synchronisation,
2569 * so here we already invalidate our internal RCU-protected
2570 * station pointer. The rest of the code will thus no longer
2571 * be able to find the station this way, and we don't rely
2572 * on further RCU synchronisation after the sta_state()
2573 * callback deleted the station.
2575 mutex_lock(&mvm->mutex);
2576 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2577 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2580 mutex_unlock(&mvm->mutex);
2583 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2586 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2589 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2590 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2595 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2596 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2600 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2604 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2605 struct ieee80211_vif *vif, u8 *peer_addr,
2606 enum nl80211_tdls_operation action)
2608 struct iwl_fw_dbg_trigger_tlv *trig;
2609 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2611 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS))
2614 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS);
2615 tdls_trig = (void *)trig->data;
2616 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
2617 ieee80211_vif_to_wdev(vif), trig))
2620 if (!(tdls_trig->action_bitmap & BIT(action)))
2623 if (tdls_trig->peer_mode &&
2624 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2627 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2628 "TDLS event occurred, peer %pM, action %d",
2632 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2633 struct iwl_mvm_sta *mvm_sta)
2635 struct iwl_mvm_tid_data *tid_data;
2636 struct sk_buff *skb;
2639 spin_lock_bh(&mvm_sta->lock);
2640 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2641 tid_data = &mvm_sta->tid_data[i];
2643 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2644 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2647 * The first deferred frame should've stopped the MAC
2648 * queues, so we should never get a second deferred
2649 * frame for the RA/TID.
2651 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
2652 ieee80211_free_txskb(mvm->hw, skb);
2655 spin_unlock_bh(&mvm_sta->lock);
2658 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2659 struct ieee80211_vif *vif,
2660 struct ieee80211_sta *sta,
2661 enum ieee80211_sta_state old_state,
2662 enum ieee80211_sta_state new_state)
2664 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2665 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2666 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2669 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2670 sta->addr, old_state, new_state);
2672 /* this would be a mac80211 bug ... but don't crash */
2673 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2674 return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL;
2677 * If we are in a STA removal flow and in DQA mode:
2679 * This is after the sync_rcu part, so the queues have already been
2680 * flushed. No more TXs on their way in mac80211's path, and no more in
2682 * Also, we won't be getting any new TX frames for this station.
2683 * What we might have are deferred TX frames that need to be taken care
2686 * Drop any still-queued deferred-frame before removing the STA, and
2687 * make sure the worker is no longer handling frames for this STA.
2689 if (old_state == IEEE80211_STA_NONE &&
2690 new_state == IEEE80211_STA_NOTEXIST) {
2691 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2692 flush_work(&mvm->add_stream_wk);
2695 * No need to make sure deferred TX indication is off since the
2696 * worker will already remove it if it was on
2700 mutex_lock(&mvm->mutex);
2701 /* track whether or not the station is associated */
2702 mvm_sta->associated = new_state >= IEEE80211_STA_ASSOC;
2704 if (old_state == IEEE80211_STA_NOTEXIST &&
2705 new_state == IEEE80211_STA_NONE) {
2707 * Firmware bug - it'll crash if the beacon interval is less
2708 * than 16. We can't avoid connecting at all, so refuse the
2709 * station state change, this will cause mac80211 to abandon
2710 * attempts to connect to this AP, and eventually wpa_s will
2711 * blacklist the AP...
2713 if (vif->type == NL80211_IFTYPE_STATION &&
2714 vif->bss_conf.beacon_int < 16) {
2716 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2717 sta->addr, vif->bss_conf.beacon_int);
2724 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2725 IWL_MVM_TDLS_STA_COUNT ||
2726 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2727 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2732 ret = iwl_mvm_add_sta(mvm, vif, sta);
2733 if (sta->tdls && ret == 0) {
2734 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2735 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2736 NL80211_TDLS_SETUP);
2738 } else if (old_state == IEEE80211_STA_NONE &&
2739 new_state == IEEE80211_STA_AUTH) {
2741 * EBS may be disabled due to previous failures reported by FW.
2742 * Reset EBS status here assuming environment has been changed.
2744 mvm->last_ebs_successful = true;
2745 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2747 } else if (old_state == IEEE80211_STA_AUTH &&
2748 new_state == IEEE80211_STA_ASSOC) {
2749 if (vif->type == NL80211_IFTYPE_AP) {
2750 mvmvif->ap_assoc_sta_count++;
2751 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2754 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2756 ret = iwl_mvm_update_sta(mvm, vif, sta);
2757 } else if (old_state == IEEE80211_STA_ASSOC &&
2758 new_state == IEEE80211_STA_AUTHORIZED) {
2760 /* we don't support TDLS during DCM */
2761 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2762 iwl_mvm_teardown_tdls_peers(mvm);
2765 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2766 NL80211_TDLS_ENABLE_LINK);
2768 /* enable beacon filtering */
2769 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2771 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2775 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2776 new_state == IEEE80211_STA_ASSOC) {
2777 /* disable beacon filtering */
2778 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2780 } else if (old_state == IEEE80211_STA_ASSOC &&
2781 new_state == IEEE80211_STA_AUTH) {
2782 if (vif->type == NL80211_IFTYPE_AP) {
2783 mvmvif->ap_assoc_sta_count--;
2784 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2787 } else if (old_state == IEEE80211_STA_AUTH &&
2788 new_state == IEEE80211_STA_NONE) {
2790 } else if (old_state == IEEE80211_STA_NONE &&
2791 new_state == IEEE80211_STA_NOTEXIST) {
2792 ret = iwl_mvm_rm_sta(mvm, vif, sta);
2794 iwl_mvm_recalc_tdls_state(mvm, vif, false);
2795 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2796 NL80211_TDLS_DISABLE_LINK);
2802 mutex_unlock(&mvm->mutex);
2804 if (sta->tdls && ret == 0) {
2805 if (old_state == IEEE80211_STA_NOTEXIST &&
2806 new_state == IEEE80211_STA_NONE)
2807 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2808 else if (old_state == IEEE80211_STA_NONE &&
2809 new_state == IEEE80211_STA_NOTEXIST)
2810 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2816 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2818 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2820 mvm->rts_threshold = value;
2825 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2826 struct ieee80211_vif *vif,
2827 struct ieee80211_sta *sta, u32 changed)
2829 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2831 if (vif->type == NL80211_IFTYPE_STATION &&
2832 changed & IEEE80211_RC_NSS_CHANGED)
2833 iwl_mvm_sf_update(mvm, vif, false);
2836 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2837 struct ieee80211_vif *vif, u16 ac,
2838 const struct ieee80211_tx_queue_params *params)
2840 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2841 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2843 mvmvif->queue_params[ac] = *params;
2846 * No need to update right away, we'll get BSS_CHANGED_QOS
2847 * The exception is P2P_DEVICE interface which needs immediate update.
2849 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2852 mutex_lock(&mvm->mutex);
2853 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2854 mutex_unlock(&mvm->mutex);
2860 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2861 struct ieee80211_vif *vif)
2863 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2864 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
2865 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
2867 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2871 * iwl_mvm_protect_session() reads directly from the device
2872 * (the system time), so make sure it is available.
2874 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2877 mutex_lock(&mvm->mutex);
2878 /* Try really hard to protect the session and hear a beacon */
2879 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
2880 mutex_unlock(&mvm->mutex);
2882 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
2885 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2886 struct ieee80211_vif *vif,
2887 struct cfg80211_sched_scan_request *req,
2888 struct ieee80211_scan_ies *ies)
2890 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2894 mutex_lock(&mvm->mutex);
2896 if (!vif->bss_conf.idle) {
2901 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
2904 mutex_unlock(&mvm->mutex);
2908 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2909 struct ieee80211_vif *vif)
2911 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2914 mutex_lock(&mvm->mutex);
2916 /* Due to a race condition, it's possible that mac80211 asks
2917 * us to stop a sched_scan when it's already stopped. This
2918 * can happen, for instance, if we stopped the scan ourselves,
2919 * called ieee80211_sched_scan_stopped() and the userspace called
2920 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
2921 * could run. To handle this, simply return if the scan is
2924 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
2925 mutex_unlock(&mvm->mutex);
2929 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
2930 mutex_unlock(&mvm->mutex);
2931 iwl_mvm_wait_for_async_handlers(mvm);
2936 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2937 enum set_key_cmd cmd,
2938 struct ieee80211_vif *vif,
2939 struct ieee80211_sta *sta,
2940 struct ieee80211_key_conf *key)
2942 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2943 struct iwl_mvm_sta *mvmsta;
2944 struct iwl_mvm_key_pn *ptk_pn;
2945 int keyidx = key->keyidx;
2949 if (iwlwifi_mod_params.swcrypto) {
2950 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2954 switch (key->cipher) {
2955 case WLAN_CIPHER_SUITE_TKIP:
2956 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2957 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2959 case WLAN_CIPHER_SUITE_CCMP:
2960 case WLAN_CIPHER_SUITE_GCMP:
2961 case WLAN_CIPHER_SUITE_GCMP_256:
2962 if (!iwl_mvm_has_new_tx_api(mvm))
2963 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2965 case WLAN_CIPHER_SUITE_AES_CMAC:
2966 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2967 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2968 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
2970 case WLAN_CIPHER_SUITE_WEP40:
2971 case WLAN_CIPHER_SUITE_WEP104:
2972 /* For non-client mode, only use WEP keys for TX as we probably
2973 * don't have a station yet anyway and would then have to keep
2974 * track of the keys, linking them to each of the clients/peers
2975 * as they appear. For now, don't do that, for performance WEP
2976 * offload doesn't really matter much, but we need it for some
2977 * other offload features in client mode.
2979 if (vif->type != NL80211_IFTYPE_STATION)
2983 /* currently FW supports only one optional cipher scheme */
2984 if (hw->n_cipher_schemes &&
2985 hw->cipher_schemes->cipher == key->cipher)
2986 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2991 mutex_lock(&mvm->mutex);
2995 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2996 vif->type == NL80211_IFTYPE_AP) && !sta) {
2998 * GTK on AP interface is a TX-only key, return 0;
2999 * on IBSS they're per-station and because we're lazy
3000 * we don't support them for RX, so do the same.
3001 * CMAC/GMAC in AP/IBSS modes must be done in software.
3003 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3004 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3005 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3010 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3011 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3012 !iwl_mvm_has_new_tx_api(mvm)) {
3013 key->hw_key_idx = STA_KEY_IDX_INVALID;
3018 /* During FW restart, in order to restore the state as it was,
3019 * don't try to reprogram keys we previously failed for.
3021 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3022 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3023 IWL_DEBUG_MAC80211(mvm,
3024 "skip invalid idx key programming during restart\n");
3029 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3030 sta && iwl_mvm_has_new_rx_api(mvm) &&
3031 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3032 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3033 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3034 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3035 struct ieee80211_key_seq seq;
3038 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3039 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3040 ptk_pn = kzalloc(sizeof(*ptk_pn) +
3041 mvm->trans->num_rx_queues *
3042 sizeof(ptk_pn->q[0]),
3049 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3050 ieee80211_get_key_rx_seq(key, tid, &seq);
3051 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3052 memcpy(ptk_pn->q[q].pn[tid],
3054 IEEE80211_CCMP_PN_LEN);
3057 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3060 /* in HW restart reuse the index, otherwise request a new one */
3061 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3062 key_offset = key->hw_key_idx;
3064 key_offset = STA_KEY_IDX_INVALID;
3066 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3067 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3069 IWL_WARN(mvm, "set key failed\n");
3071 * can't add key for RX, but we don't need it
3072 * in the device for TX so still return 0
3074 key->hw_key_idx = STA_KEY_IDX_INVALID;
3080 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3085 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3086 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3087 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3088 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3089 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3090 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3091 ptk_pn = rcu_dereference_protected(
3092 mvmsta->ptk_pn[keyidx],
3093 lockdep_is_held(&mvm->mutex));
3094 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3096 kfree_rcu(ptk_pn, rcu_head);
3099 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3100 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3106 mutex_unlock(&mvm->mutex);
3110 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3111 struct ieee80211_vif *vif,
3112 struct ieee80211_key_conf *keyconf,
3113 struct ieee80211_sta *sta,
3114 u32 iv32, u16 *phase1key)
3116 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3118 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3121 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3125 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3126 struct iwl_rx_packet *pkt, void *data)
3128 struct iwl_mvm *mvm =
3129 container_of(notif_wait, struct iwl_mvm, notif_wait);
3130 struct iwl_hs20_roc_res *resp;
3131 int resp_len = iwl_rx_packet_payload_len(pkt);
3132 struct iwl_mvm_time_event_data *te_data = data;
3134 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3137 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3138 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3142 resp = (void *)pkt->data;
3145 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3146 resp->status, resp->event_unique_id);
3148 te_data->uid = le32_to_cpu(resp->event_unique_id);
3149 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3152 spin_lock_bh(&mvm->time_event_lock);
3153 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3154 spin_unlock_bh(&mvm->time_event_lock);
3159 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3160 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3161 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3162 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3163 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3164 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3165 struct ieee80211_channel *channel,
3166 struct ieee80211_vif *vif,
3169 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3170 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3171 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3172 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3173 struct iwl_notification_wait wait_time_event;
3174 u32 dtim_interval = vif->bss_conf.dtim_period *
3175 vif->bss_conf.beacon_int;
3177 struct iwl_hs20_roc_req aux_roc_req = {
3178 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3180 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3181 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3182 /* Set the channel info data */
3183 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3184 PHY_BAND_24 : PHY_BAND_5,
3185 .channel_info.channel = channel->hw_value,
3186 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3187 /* Set the time and duration */
3188 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3191 delay = AUX_ROC_MIN_DELAY;
3192 req_dur = MSEC_TO_TU(duration);
3195 * If we are associated we want the delay time to be at least one
3196 * dtim interval so that the FW can wait until after the DTIM and
3197 * then start the time event, this will potentially allow us to
3198 * remain off-channel for the max duration.
3199 * Since we want to use almost a whole dtim interval we would also
3200 * like the delay to be for 2-3 dtim intervals, in case there are
3201 * other time events with higher priority.
3203 if (vif->bss_conf.assoc) {
3204 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3205 /* We cannot remain off-channel longer than the DTIM interval */
3206 if (dtim_interval <= req_dur) {
3207 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3208 if (req_dur <= AUX_ROC_MIN_DURATION)
3209 req_dur = dtim_interval -
3210 AUX_ROC_MIN_SAFETY_BUFFER;
3214 aux_roc_req.duration = cpu_to_le32(req_dur);
3215 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3218 "ROC: Requesting to remain on channel %u for %ums\n",
3219 channel->hw_value, req_dur);
3221 "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3222 duration, delay, dtim_interval);
3224 /* Set the node address */
3225 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3227 lockdep_assert_held(&mvm->mutex);
3229 spin_lock_bh(&mvm->time_event_lock);
3231 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3232 spin_unlock_bh(&mvm->time_event_lock);
3237 te_data->duration = duration;
3238 te_data->id = HOT_SPOT_CMD;
3240 spin_unlock_bh(&mvm->time_event_lock);
3243 * Use a notification wait, which really just processes the
3244 * command response and doesn't wait for anything, in order
3245 * to be able to process the response and get the UID inside
3246 * the RX path. Using CMD_WANT_SKB doesn't work because it
3247 * stores the buffer and then wakes up this thread, by which
3248 * time another notification (that the time event started)
3249 * might already be processed unsuccessfully.
3251 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3252 time_event_response,
3253 ARRAY_SIZE(time_event_response),
3254 iwl_mvm_rx_aux_roc, te_data);
3256 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3260 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3261 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3265 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3266 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3267 /* should never fail */
3272 spin_lock_bh(&mvm->time_event_lock);
3273 iwl_mvm_te_clear_data(mvm, te_data);
3274 spin_unlock_bh(&mvm->time_event_lock);
3280 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3281 struct ieee80211_vif *vif,
3282 struct ieee80211_channel *channel,
3284 enum ieee80211_roc_type type)
3286 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3287 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3288 struct cfg80211_chan_def chandef;
3289 struct iwl_mvm_phy_ctxt *phy_ctxt;
3290 bool band_change_removal;
3293 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3296 flush_work(&mvm->roc_done_wk);
3298 mutex_lock(&mvm->mutex);
3300 switch (vif->type) {
3301 case NL80211_IFTYPE_STATION:
3302 if (fw_has_capa(&mvm->fw->ucode_capa,
3303 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3304 /* Use aux roc framework (HS20) */
3305 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3309 IWL_ERR(mvm, "hotspot not supported\n");
3312 case NL80211_IFTYPE_P2P_DEVICE:
3316 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3321 for (i = 0; i < NUM_PHY_CTX; i++) {
3322 phy_ctxt = &mvm->phy_ctxts[i];
3323 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3326 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3328 * Unbind the P2P_DEVICE from the current PHY context,
3329 * and if the PHY context is not used remove it.
3331 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3332 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3335 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3337 /* Bind the P2P_DEVICE to the current PHY Context */
3338 mvmvif->phy_ctxt = phy_ctxt;
3340 ret = iwl_mvm_binding_add_vif(mvm, vif);
3341 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3344 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3345 goto schedule_time_event;
3349 /* Need to update the PHY context only if the ROC channel changed */
3350 if (channel == mvmvif->phy_ctxt->channel)
3351 goto schedule_time_event;
3353 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3356 * Check if the remain-on-channel is on a different band and that
3357 * requires context removal, see iwl_mvm_phy_ctxt_changed(). If
3358 * so, we'll need to release and then re-configure here, since we
3359 * must not remove a PHY context that's part of a binding.
3361 band_change_removal =
3362 fw_has_capa(&mvm->fw->ucode_capa,
3363 IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT) &&
3364 mvmvif->phy_ctxt->channel->band != chandef.chan->band;
3366 if (mvmvif->phy_ctxt->ref == 1 && !band_change_removal) {
3368 * Change the PHY context configuration as it is currently
3369 * referenced only by the P2P Device MAC (and we can modify it)
3371 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3377 * The PHY context is shared with other MACs (or we're trying to
3378 * switch bands), so remove the P2P Device from the binding,
3379 * allocate an new PHY context and create a new binding.
3381 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3387 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3390 IWL_ERR(mvm, "Failed to change PHY context\n");
3394 /* Unbind the P2P_DEVICE from the current PHY context */
3395 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3396 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3399 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3401 /* Bind the P2P_DEVICE to the new allocated PHY context */
3402 mvmvif->phy_ctxt = phy_ctxt;
3404 ret = iwl_mvm_binding_add_vif(mvm, vif);
3405 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3408 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3411 schedule_time_event:
3412 /* Schedule the time events */
3413 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3416 mutex_unlock(&mvm->mutex);
3417 IWL_DEBUG_MAC80211(mvm, "leave\n");
3421 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3423 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3425 IWL_DEBUG_MAC80211(mvm, "enter\n");
3427 mutex_lock(&mvm->mutex);
3428 iwl_mvm_stop_roc(mvm);
3429 mutex_unlock(&mvm->mutex);
3431 IWL_DEBUG_MAC80211(mvm, "leave\n");
3435 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3436 struct ieee80211_chanctx_conf *ctx)
3438 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3439 struct iwl_mvm_phy_ctxt *phy_ctxt;
3442 lockdep_assert_held(&mvm->mutex);
3444 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3446 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3452 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3453 ctx->rx_chains_static,
3454 ctx->rx_chains_dynamic);
3456 IWL_ERR(mvm, "Failed to add PHY context\n");
3460 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3461 *phy_ctxt_id = phy_ctxt->id;
3466 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3467 struct ieee80211_chanctx_conf *ctx)
3469 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3472 mutex_lock(&mvm->mutex);
3473 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3474 mutex_unlock(&mvm->mutex);
3479 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3480 struct ieee80211_chanctx_conf *ctx)
3482 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3483 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3485 lockdep_assert_held(&mvm->mutex);
3487 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3490 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3491 struct ieee80211_chanctx_conf *ctx)
3493 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3495 mutex_lock(&mvm->mutex);
3496 __iwl_mvm_remove_chanctx(mvm, ctx);
3497 mutex_unlock(&mvm->mutex);
3500 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3501 struct ieee80211_chanctx_conf *ctx,
3504 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3505 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3506 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3508 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3509 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3510 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3511 IEEE80211_CHANCTX_CHANGE_RADAR |
3512 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3513 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3514 phy_ctxt->ref, changed))
3517 mutex_lock(&mvm->mutex);
3518 iwl_mvm_bt_coex_vif_change(mvm);
3519 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3520 ctx->rx_chains_static,
3521 ctx->rx_chains_dynamic);
3522 mutex_unlock(&mvm->mutex);
3525 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3526 struct ieee80211_vif *vif,
3527 struct ieee80211_chanctx_conf *ctx,
3528 bool switching_chanctx)
3530 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3531 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3532 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3535 lockdep_assert_held(&mvm->mutex);
3537 mvmvif->phy_ctxt = phy_ctxt;
3539 switch (vif->type) {
3540 case NL80211_IFTYPE_AP:
3541 /* only needed if we're switching chanctx (i.e. during CSA) */
3542 if (switching_chanctx) {
3543 mvmvif->ap_ibss_active = true;
3546 case NL80211_IFTYPE_ADHOC:
3548 * The AP binding flow is handled as part of the start_ap flow
3549 * (in bss_info_changed), similarly for IBSS.
3553 case NL80211_IFTYPE_STATION:
3554 mvmvif->csa_bcn_pending = false;
3556 case NL80211_IFTYPE_MONITOR:
3557 /* always disable PS when a monitor interface is active */
3558 mvmvif->ps_disabled = true;
3565 ret = iwl_mvm_binding_add_vif(mvm, vif);
3570 * Power state must be updated before quotas,
3571 * otherwise fw will complain.
3573 iwl_mvm_power_update_mac(mvm);
3575 /* Setting the quota at this stage is only required for monitor
3576 * interfaces. For the other types, the bss_info changed flow
3577 * will handle quota settings.
3579 if (vif->type == NL80211_IFTYPE_MONITOR) {
3580 mvmvif->monitor_active = true;
3581 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3583 goto out_remove_binding;
3585 ret = iwl_mvm_add_snif_sta(mvm, vif);
3587 goto out_remove_binding;
3591 /* Handle binding during CSA */
3592 if (vif->type == NL80211_IFTYPE_AP) {
3593 iwl_mvm_update_quotas(mvm, false, NULL);
3594 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3597 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3598 u32 duration = 3 * vif->bss_conf.beacon_int;
3600 /* iwl_mvm_protect_session() reads directly from the
3601 * device (the system time), so make sure it is
3604 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3606 goto out_remove_binding;
3608 /* Protect the session to make sure we hear the first
3609 * beacon on the new channel.
3611 mvmvif->csa_bcn_pending = true;
3612 iwl_mvm_protect_session(mvm, vif, duration, duration,
3613 vif->bss_conf.beacon_int / 2,
3616 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3618 iwl_mvm_update_quotas(mvm, false, NULL);
3624 iwl_mvm_binding_remove_vif(mvm, vif);
3625 iwl_mvm_power_update_mac(mvm);
3628 mvmvif->phy_ctxt = NULL;
3631 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3632 struct ieee80211_vif *vif,
3633 struct ieee80211_chanctx_conf *ctx)
3635 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3638 mutex_lock(&mvm->mutex);
3639 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3640 mutex_unlock(&mvm->mutex);
3645 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3646 struct ieee80211_vif *vif,
3647 struct ieee80211_chanctx_conf *ctx,
3648 bool switching_chanctx)
3650 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3651 struct ieee80211_vif *disabled_vif = NULL;
3653 lockdep_assert_held(&mvm->mutex);
3655 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3657 switch (vif->type) {
3658 case NL80211_IFTYPE_ADHOC:
3660 case NL80211_IFTYPE_MONITOR:
3661 mvmvif->monitor_active = false;
3662 mvmvif->ps_disabled = false;
3663 iwl_mvm_rm_snif_sta(mvm, vif);
3665 case NL80211_IFTYPE_AP:
3666 /* This part is triggered only during CSA */
3667 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3670 mvmvif->csa_countdown = false;
3672 /* Set CS bit on all the stations */
3673 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3675 /* Save blocked iface, the timeout is set on the next beacon */
3676 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3678 mvmvif->ap_ibss_active = false;
3680 case NL80211_IFTYPE_STATION:
3681 if (!switching_chanctx)
3686 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3692 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3693 iwl_mvm_binding_remove_vif(mvm, vif);
3696 mvmvif->phy_ctxt = NULL;
3697 iwl_mvm_power_update_mac(mvm);
3700 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3701 struct ieee80211_vif *vif,
3702 struct ieee80211_chanctx_conf *ctx)
3704 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3706 mutex_lock(&mvm->mutex);
3707 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3708 mutex_unlock(&mvm->mutex);
3712 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3713 struct ieee80211_vif_chanctx_switch *vifs)
3717 mutex_lock(&mvm->mutex);
3718 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3719 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3721 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3723 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3727 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3731 "failed to assign new_ctx during channel switch\n");
3735 /* we don't support TDLS during DCM - can be caused by channel switch */
3736 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3737 iwl_mvm_teardown_tdls_peers(mvm);
3742 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3745 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3746 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3750 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3752 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3759 /* things keep failing, better restart the hw */
3760 iwl_mvm_nic_restart(mvm, false);
3763 mutex_unlock(&mvm->mutex);
3769 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3770 struct ieee80211_vif_chanctx_switch *vifs)
3774 mutex_lock(&mvm->mutex);
3775 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3777 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3781 "failed to assign new_ctx during channel switch\n");
3788 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3790 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3797 /* things keep failing, better restart the hw */
3798 iwl_mvm_nic_restart(mvm, false);
3801 mutex_unlock(&mvm->mutex);
3806 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3807 struct ieee80211_vif_chanctx_switch *vifs,
3809 enum ieee80211_chanctx_switch_mode mode)
3811 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3814 /* we only support a single-vif right now */
3819 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3820 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3822 case CHANCTX_SWMODE_REASSIGN_VIF:
3823 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
3833 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
3835 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3837 return mvm->ibss_manager;
3840 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3841 struct ieee80211_sta *sta,
3844 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3845 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3847 if (!mvm_sta || !mvm_sta->vif) {
3848 IWL_ERR(mvm, "Station is not associated to a vif\n");
3852 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3855 #ifdef CONFIG_NL80211_TESTMODE
3856 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3857 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3858 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
3859 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
3862 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3863 struct ieee80211_vif *vif,
3864 void *data, int len)
3866 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3870 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
3875 if (!tb[IWL_MVM_TM_ATTR_CMD])
3878 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3879 case IWL_MVM_TM_CMD_SET_NOA:
3880 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3881 !vif->bss_conf.enable_beacon ||
3882 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3885 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3886 if (noa_duration >= vif->bss_conf.beacon_int)
3889 mvm->noa_duration = noa_duration;
3892 return iwl_mvm_update_quotas(mvm, false, NULL);
3893 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3894 /* must be associated client vif - ignore authorized */
3895 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3896 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3897 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3900 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
3901 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3902 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3908 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3909 struct ieee80211_vif *vif,
3910 void *data, int len)
3912 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3915 mutex_lock(&mvm->mutex);
3916 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3917 mutex_unlock(&mvm->mutex);
3923 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3924 struct ieee80211_vif *vif,
3925 struct ieee80211_channel_switch *chsw)
3927 /* By implementing this operation, we prevent mac80211 from
3928 * starting its own channel switch timer, so that we can call
3929 * ieee80211_chswitch_done() ourselves at the right time
3930 * (which is when the absence time event starts).
3933 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3934 "dummy channel switch op\n");
3937 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3938 struct ieee80211_vif *vif,
3939 struct ieee80211_channel_switch *chsw)
3941 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3942 struct ieee80211_vif *csa_vif;
3943 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3947 mutex_lock(&mvm->mutex);
3949 mvmvif->csa_failed = false;
3951 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
3952 chsw->chandef.center_freq1);
3954 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
3955 ieee80211_vif_to_wdev(vif),
3956 FW_DBG_TRIGGER_CHANNEL_SWITCH);
3958 switch (vif->type) {
3959 case NL80211_IFTYPE_AP:
3961 rcu_dereference_protected(mvm->csa_vif,
3962 lockdep_is_held(&mvm->mutex));
3963 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3964 "Another CSA is already in progress")) {
3969 /* we still didn't unblock tx. prevent new CS meanwhile */
3970 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
3971 lockdep_is_held(&mvm->mutex))) {
3976 rcu_assign_pointer(mvm->csa_vif, vif);
3978 if (WARN_ONCE(mvmvif->csa_countdown,
3979 "Previous CSA countdown didn't complete")) {
3984 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
3987 case NL80211_IFTYPE_STATION:
3988 if (mvmvif->lqm_active)
3989 iwl_mvm_send_lqm_cmd(vif,
3990 LQM_CMD_OPERATION_STOP_MEASUREMENT,
3993 /* Schedule the time event to a bit before beacon 1,
3994 * to make sure we're in the new channel when the
3995 * GO/AP arrives. In case count <= 1 immediately schedule the
3996 * TE (this might result with some packet loss or connection
3999 if (chsw->count <= 1)
4002 apply_time = chsw->device_timestamp +
4003 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4004 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4007 iwl_mvm_csa_client_absent(mvm, vif);
4009 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4011 if (mvmvif->bf_data.bf_enabled) {
4012 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4022 mvmvif->ps_disabled = true;
4024 ret = iwl_mvm_power_update_ps(mvm);
4028 /* we won't be on this channel any longer */
4029 iwl_mvm_teardown_tdls_peers(mvm);
4032 mutex_unlock(&mvm->mutex);
4037 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
4038 struct ieee80211_vif *vif)
4040 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4041 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4044 mutex_lock(&mvm->mutex);
4046 if (mvmvif->csa_failed) {
4047 mvmvif->csa_failed = false;
4052 if (vif->type == NL80211_IFTYPE_STATION) {
4053 struct iwl_mvm_sta *mvmsta;
4055 mvmvif->csa_bcn_pending = false;
4056 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
4059 if (WARN_ON(!mvmsta)) {
4064 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
4066 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4068 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4072 iwl_mvm_stop_session_protection(mvm, vif);
4075 mvmvif->ps_disabled = false;
4077 ret = iwl_mvm_power_update_ps(mvm);
4080 mutex_unlock(&mvm->mutex);
4085 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4088 if (iwl_mvm_has_new_tx_api(mvm))
4089 /* TODO new tx api */
4091 "Need to implement flush TX queue\n");
4093 iwl_mvm_flush_tx_path(mvm,
4094 iwl_mvm_flushable_queues(mvm) & queues,
4097 if (iwl_mvm_has_new_tx_api(mvm)) {
4098 struct ieee80211_sta *sta;
4101 mutex_lock(&mvm->mutex);
4103 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4104 sta = rcu_dereference_protected(
4105 mvm->fw_id_to_mac_id[i],
4106 lockdep_is_held(&mvm->mutex));
4107 if (IS_ERR_OR_NULL(sta))
4110 iwl_mvm_wait_sta_queues_empty(mvm,
4111 iwl_mvm_sta_from_mac80211(sta));
4114 mutex_unlock(&mvm->mutex);
4116 iwl_trans_wait_tx_queues_empty(mvm->trans,
4122 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4123 struct ieee80211_vif *vif, u32 queues, bool drop)
4125 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4126 struct iwl_mvm_vif *mvmvif;
4127 struct iwl_mvm_sta *mvmsta;
4128 struct ieee80211_sta *sta;
4133 iwl_mvm_flush_no_vif(mvm, queues, drop);
4137 if (vif->type != NL80211_IFTYPE_STATION)
4140 /* Make sure we're done with the deferred traffic before flushing */
4141 flush_work(&mvm->add_stream_wk);
4143 mutex_lock(&mvm->mutex);
4144 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4146 /* flush the AP-station and all TDLS peers */
4147 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4148 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4149 lockdep_is_held(&mvm->mutex));
4150 if (IS_ERR_OR_NULL(sta))
4153 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4154 if (mvmsta->vif != vif)
4157 /* make sure only TDLS peers or the AP are flushed */
4158 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4161 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4162 IWL_ERR(mvm, "flush request fail\n");
4164 msk |= mvmsta->tfd_queue_msk;
4165 if (iwl_mvm_has_new_tx_api(mvm))
4166 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4170 mutex_unlock(&mvm->mutex);
4172 /* this can take a while, and we may need/want other operations
4173 * to succeed while doing this, so do it without the mutex held
4175 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4176 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4179 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4180 struct survey_info *survey)
4182 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4185 memset(survey, 0, sizeof(*survey));
4187 /* only support global statistics right now */
4191 if (!fw_has_capa(&mvm->fw->ucode_capa,
4192 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4195 mutex_lock(&mvm->mutex);
4197 if (iwl_mvm_firmware_running(mvm)) {
4198 ret = iwl_mvm_request_statistics(mvm, false);
4203 survey->filled = SURVEY_INFO_TIME |
4204 SURVEY_INFO_TIME_RX |
4205 SURVEY_INFO_TIME_TX |
4206 SURVEY_INFO_TIME_SCAN;
4207 survey->time = mvm->accu_radio_stats.on_time_rf +
4208 mvm->radio_stats.on_time_rf;
4209 do_div(survey->time, USEC_PER_MSEC);
4211 survey->time_rx = mvm->accu_radio_stats.rx_time +
4212 mvm->radio_stats.rx_time;
4213 do_div(survey->time_rx, USEC_PER_MSEC);
4215 survey->time_tx = mvm->accu_radio_stats.tx_time +
4216 mvm->radio_stats.tx_time;
4217 do_div(survey->time_tx, USEC_PER_MSEC);
4219 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4220 mvm->radio_stats.on_time_scan;
4221 do_div(survey->time_scan, USEC_PER_MSEC);
4225 mutex_unlock(&mvm->mutex);
4229 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4230 struct ieee80211_vif *vif,
4231 struct ieee80211_sta *sta,
4232 struct station_info *sinfo)
4234 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4235 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4236 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4238 if (mvmsta->avg_energy) {
4239 sinfo->signal_avg = mvmsta->avg_energy;
4240 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
4243 /* if beacon filtering isn't on mac80211 does it anyway */
4244 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4247 if (!vif->bss_conf.assoc)
4250 mutex_lock(&mvm->mutex);
4252 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4255 if (iwl_mvm_request_statistics(mvm, false))
4258 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4259 mvmvif->beacon_stats.accu_num_beacons;
4260 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX);
4261 if (mvmvif->beacon_stats.avg_signal) {
4262 /* firmware only reports a value after RXing a few beacons */
4263 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4264 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4267 mutex_unlock(&mvm->mutex);
4270 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4271 struct ieee80211_vif *vif,
4272 const struct ieee80211_event *event)
4274 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4276 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4278 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4281 struct iwl_fw_dbg_trigger_tlv *trig;
4282 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4284 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
4287 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
4288 trig_mlme = (void *)trig->data;
4289 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4290 ieee80211_vif_to_wdev(vif), trig))
4293 if (event->u.mlme.data == ASSOC_EVENT) {
4294 if (event->u.mlme.status == MLME_DENIED)
4295 CHECK_MLME_TRIGGER(stop_assoc_denied,
4296 "DENIED ASSOC: reason %d",
4297 event->u.mlme.reason);
4298 else if (event->u.mlme.status == MLME_TIMEOUT)
4299 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4301 } else if (event->u.mlme.data == AUTH_EVENT) {
4302 if (event->u.mlme.status == MLME_DENIED)
4303 CHECK_MLME_TRIGGER(stop_auth_denied,
4304 "DENIED AUTH: reason %d",
4305 event->u.mlme.reason);
4306 else if (event->u.mlme.status == MLME_TIMEOUT)
4307 CHECK_MLME_TRIGGER(stop_auth_timeout,
4309 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4310 CHECK_MLME_TRIGGER(stop_rx_deauth,
4311 "DEAUTH RX %d", event->u.mlme.reason);
4312 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4313 CHECK_MLME_TRIGGER(stop_tx_deauth,
4314 "DEAUTH TX %d", event->u.mlme.reason);
4316 #undef CHECK_MLME_TRIGGER
4319 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4320 struct ieee80211_vif *vif,
4321 const struct ieee80211_event *event)
4323 struct iwl_fw_dbg_trigger_tlv *trig;
4324 struct iwl_fw_dbg_trigger_ba *ba_trig;
4326 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
4329 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
4330 ba_trig = (void *)trig->data;
4331 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4332 ieee80211_vif_to_wdev(vif), trig))
4335 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4338 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4339 "BAR received from %pM, tid %d, ssn %d",
4340 event->u.ba.sta->addr, event->u.ba.tid,
4345 iwl_mvm_event_frame_timeout_callback(struct iwl_mvm *mvm,
4346 struct ieee80211_vif *vif,
4347 const struct ieee80211_event *event)
4349 struct iwl_fw_dbg_trigger_tlv *trig;
4350 struct iwl_fw_dbg_trigger_ba *ba_trig;
4352 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
4355 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
4356 ba_trig = (void *)trig->data;
4357 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4358 ieee80211_vif_to_wdev(vif), trig))
4361 if (!(le16_to_cpu(ba_trig->frame_timeout) & BIT(event->u.ba.tid)))
4364 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4365 "Frame from %pM timed out, tid %d",
4366 event->u.ba.sta->addr, event->u.ba.tid);
4369 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4370 struct ieee80211_vif *vif,
4371 const struct ieee80211_event *event)
4373 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4375 switch (event->type) {
4377 iwl_mvm_event_mlme_callback(mvm, vif, event);
4380 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4382 case BA_FRAME_TIMEOUT:
4383 iwl_mvm_event_frame_timeout_callback(mvm, vif, event);
4390 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4391 struct iwl_mvm_internal_rxq_notif *notif,
4394 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4397 lockdep_assert_held(&mvm->mutex);
4399 /* TODO - remove a000 disablement when we have RXQ config API */
4400 if (!iwl_mvm_has_new_rx_api(mvm) ||
4401 mvm->trans->cfg->device_family == IWL_DEVICE_FAMILY_A000)
4404 notif->cookie = mvm->queue_sync_cookie;
4407 atomic_set(&mvm->queue_sync_counter,
4408 mvm->trans->num_rx_queues);
4410 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4412 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4417 ret = wait_event_timeout(mvm->rx_sync_waitq,
4418 atomic_read(&mvm->queue_sync_counter) == 0 ||
4419 iwl_mvm_is_radio_killed(mvm),
4421 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4425 atomic_set(&mvm->queue_sync_counter, 0);
4426 mvm->queue_sync_cookie++;
4429 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4431 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4432 struct iwl_mvm_internal_rxq_notif data = {
4433 .type = IWL_MVM_RXQ_EMPTY,
4437 mutex_lock(&mvm->mutex);
4438 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
4439 mutex_unlock(&mvm->mutex);
4442 const struct ieee80211_ops iwl_mvm_hw_ops = {
4443 .tx = iwl_mvm_mac_tx,
4444 .ampdu_action = iwl_mvm_mac_ampdu_action,
4445 .start = iwl_mvm_mac_start,
4446 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
4447 .stop = iwl_mvm_mac_stop,
4448 .add_interface = iwl_mvm_mac_add_interface,
4449 .remove_interface = iwl_mvm_mac_remove_interface,
4450 .config = iwl_mvm_mac_config,
4451 .prepare_multicast = iwl_mvm_prepare_multicast,
4452 .configure_filter = iwl_mvm_configure_filter,
4453 .config_iface_filter = iwl_mvm_config_iface_filter,
4454 .bss_info_changed = iwl_mvm_bss_info_changed,
4455 .hw_scan = iwl_mvm_mac_hw_scan,
4456 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
4457 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
4458 .sta_state = iwl_mvm_mac_sta_state,
4459 .sta_notify = iwl_mvm_mac_sta_notify,
4460 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
4461 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
4462 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
4463 .sta_rc_update = iwl_mvm_sta_rc_update,
4464 .conf_tx = iwl_mvm_mac_conf_tx,
4465 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
4466 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
4467 .flush = iwl_mvm_mac_flush,
4468 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4469 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
4470 .set_key = iwl_mvm_mac_set_key,
4471 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4472 .remain_on_channel = iwl_mvm_roc,
4473 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
4474 .add_chanctx = iwl_mvm_add_chanctx,
4475 .remove_chanctx = iwl_mvm_remove_chanctx,
4476 .change_chanctx = iwl_mvm_change_chanctx,
4477 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4478 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
4479 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
4481 .start_ap = iwl_mvm_start_ap_ibss,
4482 .stop_ap = iwl_mvm_stop_ap_ibss,
4483 .join_ibss = iwl_mvm_start_ap_ibss,
4484 .leave_ibss = iwl_mvm_stop_ap_ibss,
4486 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4488 .set_tim = iwl_mvm_set_tim,
4490 .channel_switch = iwl_mvm_channel_switch,
4491 .pre_channel_switch = iwl_mvm_pre_channel_switch,
4492 .post_channel_switch = iwl_mvm_post_channel_switch,
4494 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4495 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4496 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4498 .event_callback = iwl_mvm_mac_event_callback,
4500 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4502 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4504 #ifdef CONFIG_PM_SLEEP
4506 .suspend = iwl_mvm_suspend,
4507 .resume = iwl_mvm_resume,
4508 .set_wakeup = iwl_mvm_set_wakeup,
4509 .set_rekey_data = iwl_mvm_set_rekey_data,
4510 #if IS_ENABLED(CONFIG_IPV6)
4511 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4513 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4515 .get_survey = iwl_mvm_mac_get_survey,
4516 .sta_statistics = iwl_mvm_mac_sta_statistics,