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
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
26 * The full GNU General Public License is included in this distribution
27 * in the file called COPYING.
29 * Contact Information:
30 * Intel Linux Wireless <linuxwifi@intel.com>
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
35 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
36 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
37 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * * Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in
48 * the documentation and/or other materials provided with the
50 * * Neither the name Intel Corporation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 *****************************************************************************/
67 #include <linux/kernel.h>
68 #include <linux/slab.h>
69 #include <linux/skbuff.h>
70 #include <linux/netdevice.h>
71 #include <linux/etherdevice.h>
73 #include <linux/if_arp.h>
74 #include <linux/time.h>
75 #include <net/mac80211.h>
76 #include <net/ieee80211_radiotap.h>
79 #include "iwl-op-mode.h"
83 #include "time-event.h"
84 #include "iwl-eeprom-parse.h"
85 #include "iwl-phy-db.h"
87 #include "fw/error-dump.h"
89 #include "iwl-nvm-parse.h"
91 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
94 .types = BIT(NL80211_IFTYPE_STATION),
98 .types = BIT(NL80211_IFTYPE_AP) |
99 BIT(NL80211_IFTYPE_P2P_CLIENT) |
100 BIT(NL80211_IFTYPE_P2P_GO),
104 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
108 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
110 .num_different_channels = 2,
112 .limits = iwl_mvm_limits,
113 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
117 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
119 * Use the reserved field to indicate magic values.
120 * these values will only be used internally by the driver,
121 * and won't make it to the fw (reserved will be 0).
122 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
123 * be the vif's ip address. in case there is not a single
124 * ip address (0, or more than 1), this attribute will
126 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
127 * the LSB bytes of the vif's mac address
130 BC_FILTER_MAGIC_NONE = 0,
135 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
139 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
142 /* frame type - arp, hw type - ethernet */
144 BCAST_FILTER_OFFSET_PAYLOAD_START,
145 .offset = sizeof(rfc1042_header),
146 .val = cpu_to_be32(0x08060001),
147 .mask = cpu_to_be32(0xffffffff),
152 BCAST_FILTER_OFFSET_PAYLOAD_START,
153 .offset = sizeof(rfc1042_header) + 2 +
154 sizeof(struct arphdr) +
155 ETH_ALEN + sizeof(__be32) +
157 .mask = cpu_to_be32(0xffffffff),
158 /* mark it as special field */
159 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
164 /* dhcp offer bcast */
166 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
169 /* udp dest port - 68 (bootp client)*/
170 .offset_type = BCAST_FILTER_OFFSET_IP_END,
171 .offset = offsetof(struct udphdr, dest),
172 .val = cpu_to_be32(0x00440000),
173 .mask = cpu_to_be32(0xffff0000),
176 /* dhcp - lsb bytes of client hw address */
177 .offset_type = BCAST_FILTER_OFFSET_IP_END,
179 .mask = cpu_to_be32(0xffffffff),
180 /* mark it as special field */
181 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
185 /* last filter must be empty */
190 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
192 if (!iwl_mvm_is_d0i3_supported(mvm))
195 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
196 spin_lock_bh(&mvm->refs_lock);
197 mvm->refs[ref_type]++;
198 spin_unlock_bh(&mvm->refs_lock);
199 iwl_trans_ref(mvm->trans);
202 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
204 if (!iwl_mvm_is_d0i3_supported(mvm))
207 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
208 spin_lock_bh(&mvm->refs_lock);
209 if (WARN_ON(!mvm->refs[ref_type])) {
210 spin_unlock_bh(&mvm->refs_lock);
213 mvm->refs[ref_type]--;
214 spin_unlock_bh(&mvm->refs_lock);
215 iwl_trans_unref(mvm->trans);
218 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
219 enum iwl_mvm_ref_type except_ref)
223 if (!iwl_mvm_is_d0i3_supported(mvm))
226 spin_lock_bh(&mvm->refs_lock);
227 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
228 if (except_ref == i || !mvm->refs[i])
231 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
233 for (j = 0; j < mvm->refs[i]; j++)
234 iwl_trans_unref(mvm->trans);
237 spin_unlock_bh(&mvm->refs_lock);
240 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
245 if (!iwl_mvm_is_d0i3_supported(mvm))
248 spin_lock_bh(&mvm->refs_lock);
249 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
255 spin_unlock_bh(&mvm->refs_lock);
260 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
262 iwl_mvm_ref(mvm, ref_type);
264 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
265 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
268 iwl_mvm_unref(mvm, ref_type);
275 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
279 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
280 for (i = 0; i < NUM_PHY_CTX; i++) {
281 mvm->phy_ctxts[i].id = i;
282 mvm->phy_ctxts[i].ref = 0;
286 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
288 enum iwl_mcc_source src_id,
291 struct ieee80211_regdomain *regd = NULL;
292 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
293 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
294 struct iwl_mcc_update_resp *resp;
296 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
298 lockdep_assert_held(&mvm->mutex);
300 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
301 if (IS_ERR_OR_NULL(resp)) {
302 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
303 PTR_ERR_OR_ZERO(resp));
308 *changed = (resp->status == MCC_RESP_NEW_CHAN_PROFILE);
310 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
311 __le32_to_cpu(resp->n_channels),
313 __le16_to_cpu(resp->mcc));
314 /* Store the return source id */
315 src_id = resp->source_id;
317 if (IS_ERR_OR_NULL(regd)) {
318 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
319 PTR_ERR_OR_ZERO(regd));
323 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
324 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
325 mvm->lar_regdom_set = true;
326 mvm->mcc_src = src_id;
332 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
335 struct ieee80211_regdomain *regd;
337 if (!iwl_mvm_is_lar_supported(mvm))
340 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
341 if (!IS_ERR_OR_NULL(regd)) {
342 /* only update the regulatory core if changed */
344 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
350 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
353 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
354 iwl_mvm_is_wifi_mcc_supported(mvm) ?
355 MCC_SOURCE_GET_CURRENT :
356 MCC_SOURCE_OLD_FW, changed);
359 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
361 enum iwl_mcc_source used_src;
362 struct ieee80211_regdomain *regd;
365 const struct ieee80211_regdomain *r =
366 rtnl_dereference(mvm->hw->wiphy->regd);
371 /* save the last source in case we overwrite it below */
372 used_src = mvm->mcc_src;
373 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
374 /* Notify the firmware we support wifi location updates */
375 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
376 if (!IS_ERR_OR_NULL(regd))
380 /* Now set our last stored MCC and source */
381 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
383 if (IS_ERR_OR_NULL(regd))
386 /* update cfg80211 if the regdomain was changed */
388 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
396 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
398 struct ieee80211_hw *hw = mvm->hw;
400 static const u32 mvm_ciphers[] = {
401 WLAN_CIPHER_SUITE_WEP40,
402 WLAN_CIPHER_SUITE_WEP104,
403 WLAN_CIPHER_SUITE_TKIP,
404 WLAN_CIPHER_SUITE_CCMP,
407 /* Tell mac80211 our characteristics */
408 ieee80211_hw_set(hw, SIGNAL_DBM);
409 ieee80211_hw_set(hw, SPECTRUM_MGMT);
410 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
411 ieee80211_hw_set(hw, QUEUE_CONTROL);
412 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
413 ieee80211_hw_set(hw, SUPPORTS_PS);
414 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
415 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
416 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
417 ieee80211_hw_set(hw, CONNECTION_MONITOR);
418 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
419 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
420 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
421 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
422 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
423 if (iwl_mvm_has_new_rx_api(mvm))
424 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
426 if (fw_has_capa(&mvm->fw->ucode_capa,
427 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
428 ieee80211_hw_set(hw, AP_LINK_PS);
429 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
431 * we absolutely need this for the new TX API since that comes
432 * with many more queues than the current code can deal with
433 * for station powersave
438 if (mvm->trans->num_rx_queues > 1)
439 ieee80211_hw_set(hw, USES_RSS);
441 if (mvm->trans->max_skb_frags)
442 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
444 hw->queues = IEEE80211_MAX_QUEUES;
445 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
446 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
447 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
448 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
449 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
451 hw->radiotap_timestamp.units_pos =
452 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
453 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
454 /* this is the case for CCK frames, it's better (only 8) for OFDM */
455 hw->radiotap_timestamp.accuracy = 22;
457 hw->rate_control_algorithm = "iwl-mvm-rs";
458 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
459 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
461 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
462 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
463 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
464 hw->wiphy->cipher_suites = mvm->ciphers;
466 if (iwl_mvm_has_new_rx_api(mvm)) {
467 mvm->ciphers[hw->wiphy->n_cipher_suites] =
468 WLAN_CIPHER_SUITE_GCMP;
469 hw->wiphy->n_cipher_suites++;
470 mvm->ciphers[hw->wiphy->n_cipher_suites] =
471 WLAN_CIPHER_SUITE_GCMP_256;
472 hw->wiphy->n_cipher_suites++;
475 /* Enable 11w if software crypto is not enabled (as the
476 * firmware will interpret some mgmt packets, so enabling it
477 * with software crypto isn't safe).
479 if (!iwlwifi_mod_params.swcrypto) {
480 ieee80211_hw_set(hw, MFP_CAPABLE);
481 mvm->ciphers[hw->wiphy->n_cipher_suites] =
482 WLAN_CIPHER_SUITE_AES_CMAC;
483 hw->wiphy->n_cipher_suites++;
484 if (iwl_mvm_has_new_rx_api(mvm)) {
485 mvm->ciphers[hw->wiphy->n_cipher_suites] =
486 WLAN_CIPHER_SUITE_BIP_GMAC_128;
487 hw->wiphy->n_cipher_suites++;
488 mvm->ciphers[hw->wiphy->n_cipher_suites] =
489 WLAN_CIPHER_SUITE_BIP_GMAC_256;
490 hw->wiphy->n_cipher_suites++;
494 /* currently FW API supports only one optional cipher scheme */
495 if (mvm->fw->cs[0].cipher) {
496 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
497 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
499 mvm->hw->n_cipher_schemes = 1;
501 cs->cipher = le32_to_cpu(fwcs->cipher);
502 cs->iftype = BIT(NL80211_IFTYPE_STATION);
503 cs->hdr_len = fwcs->hdr_len;
504 cs->pn_len = fwcs->pn_len;
505 cs->pn_off = fwcs->pn_off;
506 cs->key_idx_off = fwcs->key_idx_off;
507 cs->key_idx_mask = fwcs->key_idx_mask;
508 cs->key_idx_shift = fwcs->key_idx_shift;
509 cs->mic_len = fwcs->mic_len;
511 mvm->hw->cipher_schemes = mvm->cs;
512 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
513 hw->wiphy->n_cipher_suites++;
516 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
517 hw->wiphy->features |=
518 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
519 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
520 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
522 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
523 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
524 hw->chanctx_data_size = sizeof(u16);
526 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
527 BIT(NL80211_IFTYPE_P2P_CLIENT) |
528 BIT(NL80211_IFTYPE_AP) |
529 BIT(NL80211_IFTYPE_P2P_GO) |
530 BIT(NL80211_IFTYPE_P2P_DEVICE) |
531 BIT(NL80211_IFTYPE_ADHOC);
533 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
534 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
535 if (iwl_mvm_is_lar_supported(mvm))
536 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
538 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
539 REGULATORY_DISABLE_BEACON_HINTS;
541 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
542 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
544 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
545 hw->wiphy->n_iface_combinations =
546 ARRAY_SIZE(iwl_mvm_iface_combinations);
548 hw->wiphy->max_remain_on_channel_duration = 10000;
549 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
550 /* we can compensate an offset of up to 3 channels = 15 MHz */
551 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
553 /* Extract MAC address */
554 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
555 hw->wiphy->addresses = mvm->addresses;
556 hw->wiphy->n_addresses = 1;
558 /* Extract additional MAC addresses if available */
559 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
560 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
562 for (i = 1; i < num_mac; i++) {
563 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
565 mvm->addresses[i].addr[5]++;
566 hw->wiphy->n_addresses++;
569 iwl_mvm_reset_phy_ctxts(mvm);
571 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
573 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
575 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
576 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
577 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
579 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
580 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
582 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
584 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
585 hw->wiphy->bands[NL80211_BAND_2GHZ] =
586 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
587 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
588 hw->wiphy->bands[NL80211_BAND_5GHZ] =
589 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
591 if (fw_has_capa(&mvm->fw->ucode_capa,
592 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
593 fw_has_api(&mvm->fw->ucode_capa,
594 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
595 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
596 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
599 hw->wiphy->hw_version = mvm->trans->hw_id;
601 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
602 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
604 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
606 hw->wiphy->max_sched_scan_reqs = 1;
607 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
608 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
609 /* we create the 802.11 header and zero length SSID IE. */
610 hw->wiphy->max_sched_scan_ie_len =
611 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
612 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
613 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
616 * the firmware uses u8 for num of iterations, but 0xff is saved for
617 * infinite loop, so the maximum number of iterations is actually 254.
619 hw->wiphy->max_sched_scan_plan_iterations = 254;
621 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
622 NL80211_FEATURE_LOW_PRIORITY_SCAN |
623 NL80211_FEATURE_P2P_GO_OPPPS |
624 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
625 NL80211_FEATURE_DYNAMIC_SMPS |
626 NL80211_FEATURE_STATIC_SMPS |
627 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
629 if (fw_has_capa(&mvm->fw->ucode_capa,
630 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
631 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
632 if (fw_has_capa(&mvm->fw->ucode_capa,
633 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
634 hw->wiphy->features |= NL80211_FEATURE_QUIET;
636 if (fw_has_capa(&mvm->fw->ucode_capa,
637 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
638 hw->wiphy->features |=
639 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
641 if (fw_has_capa(&mvm->fw->ucode_capa,
642 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
643 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
645 if (fw_has_api(&mvm->fw->ucode_capa,
646 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
647 wiphy_ext_feature_set(hw->wiphy,
648 NL80211_EXT_FEATURE_SCAN_START_TIME);
649 wiphy_ext_feature_set(hw->wiphy,
650 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
651 wiphy_ext_feature_set(hw->wiphy,
652 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
655 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
657 #ifdef CONFIG_PM_SLEEP
658 if (iwl_mvm_is_d0i3_supported(mvm) &&
659 device_can_wakeup(mvm->trans->dev)) {
660 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
661 hw->wiphy->wowlan = &mvm->wowlan;
664 if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
665 mvm->trans->ops->d3_suspend &&
666 mvm->trans->ops->d3_resume &&
667 device_can_wakeup(mvm->trans->dev)) {
668 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
669 WIPHY_WOWLAN_DISCONNECT |
670 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
671 WIPHY_WOWLAN_RFKILL_RELEASE |
672 WIPHY_WOWLAN_NET_DETECT;
673 if (!iwlwifi_mod_params.swcrypto)
674 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
675 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
676 WIPHY_WOWLAN_4WAY_HANDSHAKE;
678 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
679 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
680 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
681 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
682 hw->wiphy->wowlan = &mvm->wowlan;
686 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
687 /* assign default bcast filtering configuration */
688 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
691 ret = iwl_mvm_leds_init(mvm);
695 if (fw_has_capa(&mvm->fw->ucode_capa,
696 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
697 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
698 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
699 ieee80211_hw_set(hw, TDLS_WIDER_BW);
702 if (fw_has_capa(&mvm->fw->ucode_capa,
703 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
704 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
705 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
708 hw->netdev_features |= mvm->cfg->features;
709 if (!iwl_mvm_is_csum_supported(mvm)) {
710 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
712 /* We may support SW TX CSUM */
713 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
714 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
717 ret = ieee80211_register_hw(mvm->hw);
719 iwl_mvm_leds_exit(mvm);
720 mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
722 if (mvm->cfg->vht_mu_mimo_supported)
723 wiphy_ext_feature_set(hw->wiphy,
724 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
729 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
730 struct ieee80211_sta *sta,
733 struct iwl_mvm_sta *mvmsta;
737 * double check the IN_D0I3 flag both before and after
738 * taking the spinlock, in order to prevent taking
739 * the spinlock when not needed.
741 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
744 spin_lock(&mvm->d0i3_tx_lock);
746 * testing the flag again ensures the skb dequeue
747 * loop (on d0i3 exit) hasn't run yet.
749 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
752 mvmsta = iwl_mvm_sta_from_mac80211(sta);
753 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
754 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
757 __skb_queue_tail(&mvm->d0i3_tx, skb);
758 ieee80211_stop_queues(mvm->hw);
761 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
762 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
766 spin_unlock(&mvm->d0i3_tx_lock);
770 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
771 struct ieee80211_tx_control *control,
774 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
775 struct ieee80211_sta *sta = control->sta;
776 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
777 struct ieee80211_hdr *hdr = (void *)skb->data;
779 if (iwl_mvm_is_radio_killed(mvm)) {
780 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
784 if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
785 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
786 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
789 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
790 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
791 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
792 ieee80211_is_mgmt(hdr->frame_control) &&
793 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
797 if (iwl_mvm_defer_tx(mvm, sta, skb))
799 if (iwl_mvm_tx_skb(mvm, skb, sta))
804 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
808 ieee80211_free_txskb(hw, skb);
811 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
813 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
818 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
820 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
822 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
825 /* enabled by default */
829 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
831 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
833 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
837 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
838 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
839 enum ieee80211_ampdu_mlme_action action)
841 struct iwl_fw_dbg_trigger_tlv *trig;
842 struct iwl_fw_dbg_trigger_ba *ba_trig;
844 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
847 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
848 ba_trig = (void *)trig->data;
850 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
851 ieee80211_vif_to_wdev(vif), trig))
855 case IEEE80211_AMPDU_TX_OPERATIONAL: {
856 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
857 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
859 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
860 "TX AGG START: MAC %pM tid %d ssn %d\n",
861 sta->addr, tid, tid_data->ssn);
864 case IEEE80211_AMPDU_TX_STOP_CONT:
865 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
866 "TX AGG STOP: MAC %pM tid %d\n",
869 case IEEE80211_AMPDU_RX_START:
870 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
871 "RX AGG START: MAC %pM tid %d ssn %d\n",
872 sta->addr, tid, rx_ba_ssn);
874 case IEEE80211_AMPDU_RX_STOP:
875 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
876 "RX AGG STOP: MAC %pM tid %d\n",
884 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
885 struct ieee80211_vif *vif,
886 struct ieee80211_ampdu_params *params)
888 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
890 bool tx_agg_ref = false;
891 struct ieee80211_sta *sta = params->sta;
892 enum ieee80211_ampdu_mlme_action action = params->action;
893 u16 tid = params->tid;
894 u16 *ssn = ¶ms->ssn;
895 u8 buf_size = params->buf_size;
896 bool amsdu = params->amsdu;
897 u16 timeout = params->timeout;
899 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
900 sta->addr, tid, action);
902 if (!(mvm->nvm_data->sku_cap_11n_enable))
905 /* return from D0i3 before starting a new Tx aggregation */
907 case IEEE80211_AMPDU_TX_START:
908 case IEEE80211_AMPDU_TX_STOP_CONT:
909 case IEEE80211_AMPDU_TX_STOP_FLUSH:
910 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
911 case IEEE80211_AMPDU_TX_OPERATIONAL:
913 * for tx start, wait synchronously until D0i3 exit to
914 * get the correct sequence number for the tid.
915 * additionally, some other ampdu actions use direct
916 * target access, which is not handled automatically
917 * by the trans layer (unlike commands), so wait for
918 * d0i3 exit in these cases as well.
920 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
930 mutex_lock(&mvm->mutex);
933 case IEEE80211_AMPDU_RX_START:
934 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
938 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
941 case IEEE80211_AMPDU_RX_STOP:
942 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
945 case IEEE80211_AMPDU_TX_START:
946 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
950 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
952 case IEEE80211_AMPDU_TX_STOP_CONT:
953 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
955 case IEEE80211_AMPDU_TX_STOP_FLUSH:
956 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
957 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
959 case IEEE80211_AMPDU_TX_OPERATIONAL:
960 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
972 if (action == IEEE80211_AMPDU_RX_START)
975 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
978 mutex_unlock(&mvm->mutex);
981 * If the tid is marked as started, we won't use it for offloaded
982 * traffic on the next D0i3 entry. It's safe to unref.
985 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
990 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
991 struct ieee80211_vif *vif)
993 struct iwl_mvm *mvm = data;
994 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
996 mvmvif->uploaded = false;
997 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
999 spin_lock_bh(&mvm->time_event_lock);
1000 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1001 spin_unlock_bh(&mvm->time_event_lock);
1003 mvmvif->phy_ctxt = NULL;
1004 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1007 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1009 /* clear the D3 reconfig, we only need it to avoid dumping a
1010 * firmware coredump on reconfiguration, we shouldn't do that
1011 * on D3->D0 transition
1013 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1014 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1015 iwl_fw_error_dump(&mvm->fwrt);
1018 /* cleanup all stale references (scan, roc), but keep the
1019 * ucode_down ref until reconfig is complete
1021 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1023 iwl_mvm_stop_device(mvm);
1025 mvm->scan_status = 0;
1026 mvm->ps_disabled = false;
1027 mvm->calibrating = false;
1029 /* just in case one was running */
1030 iwl_mvm_cleanup_roc_te(mvm);
1031 ieee80211_remain_on_channel_expired(mvm->hw);
1034 * cleanup all interfaces, even inactive ones, as some might have
1035 * gone down during the HW restart
1037 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1039 mvm->p2p_device_vif = NULL;
1040 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1042 iwl_mvm_reset_phy_ctxts(mvm);
1043 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1044 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
1045 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1046 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1048 ieee80211_wake_queues(mvm->hw);
1050 /* clear any stale d0i3 state */
1051 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1054 mvm->rx_ba_sessions = 0;
1055 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1056 mvm->monitor_on = false;
1058 /* keep statistics ticking */
1059 iwl_mvm_accu_radio_stats(mvm);
1062 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1066 lockdep_assert_held(&mvm->mutex);
1068 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1070 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1071 * so later code will - from now on - see that we're doing it.
1073 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1074 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1075 /* Clean up some internal and mac80211 state on restart */
1076 iwl_mvm_restart_cleanup(mvm);
1078 /* Hold the reference to prevent runtime suspend while
1079 * the start procedure runs. It's a bit confusing
1080 * that the UCODE_DOWN reference is taken, but it just
1081 * means "UCODE is not UP yet". ( TODO: rename this
1084 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1086 ret = iwl_mvm_up(mvm);
1088 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1089 /* Something went wrong - we need to finish some cleanup
1090 * that normally iwl_mvm_mac_restart_complete() below
1093 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1094 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1100 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1102 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1105 /* Some hw restart cleanups must not hold the mutex */
1106 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1108 * Make sure we are out of d0i3. This is needed
1109 * to make sure the reference accounting is correct
1110 * (and there is no stale d0i3_exit_work).
1112 wait_event_timeout(mvm->d0i3_exit_waitq,
1113 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1118 mutex_lock(&mvm->mutex);
1119 ret = __iwl_mvm_mac_start(mvm);
1120 mutex_unlock(&mvm->mutex);
1125 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1129 mutex_lock(&mvm->mutex);
1131 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1132 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1133 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1135 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1138 /* allow transport/FW low power modes */
1139 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1142 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1143 * of packets the FW sent out, so we must reconnect.
1145 iwl_mvm_teardown_tdls_peers(mvm);
1147 mutex_unlock(&mvm->mutex);
1150 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1152 if (iwl_mvm_is_d0i3_supported(mvm) &&
1153 iwl_mvm_enter_d0i3_on_suspend(mvm))
1154 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1155 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1158 "D0i3 exit on resume timed out\n");
1162 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1163 enum ieee80211_reconfig_type reconfig_type)
1165 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1167 switch (reconfig_type) {
1168 case IEEE80211_RECONFIG_TYPE_RESTART:
1169 iwl_mvm_restart_complete(mvm);
1171 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1172 iwl_mvm_resume_complete(mvm);
1177 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1179 lockdep_assert_held(&mvm->mutex);
1181 /* firmware counters are obviously reset now, but we shouldn't
1182 * partially track so also clear the fw_reset_accu counters.
1184 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1186 /* async_handlers_wk is now blocked */
1189 * The work item could be running or queued if the
1190 * ROC time event stops just as we get here.
1192 flush_work(&mvm->roc_done_wk);
1194 iwl_mvm_stop_device(mvm);
1196 iwl_mvm_async_handlers_purge(mvm);
1197 /* async_handlers_list is empty and will stay empty: HW is stopped */
1199 /* the fw is stopped, the aux sta is dead: clean up driver state */
1200 iwl_mvm_del_aux_sta(mvm);
1203 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1204 * won't be called in this case).
1205 * But make sure to cleanup interfaces that have gone down before/during
1206 * HW restart was requested.
1208 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1209 ieee80211_iterate_interfaces(mvm->hw, 0,
1210 iwl_mvm_cleanup_iterator, mvm);
1212 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1213 * make sure there's nothing left there and warn if any is found.
1215 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1218 for (i = 0; i < mvm->max_scans; i++) {
1219 if (WARN_ONCE(mvm->scan_uid_status[i],
1220 "UMAC scan UID %d status was not cleaned\n",
1222 mvm->scan_uid_status[i] = 0;
1227 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1229 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1231 flush_work(&mvm->d0i3_exit_work);
1232 flush_work(&mvm->async_handlers_wk);
1233 flush_work(&mvm->add_stream_wk);
1236 * Lock and clear the firmware running bit here already, so that
1237 * new commands coming in elsewhere, e.g. from debugfs, will not
1238 * be able to proceed. This is important here because one of those
1239 * debugfs files causes the firmware dump to be triggered, and if we
1240 * don't stop debugfs accesses before canceling that it could be
1241 * retriggered after we flush it but before we've cleared the bit.
1243 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1245 iwl_fw_cancel_dump(&mvm->fwrt);
1246 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1247 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1248 iwl_fw_free_dump_desc(&mvm->fwrt);
1250 mutex_lock(&mvm->mutex);
1251 __iwl_mvm_mac_stop(mvm);
1252 mutex_unlock(&mvm->mutex);
1255 * The worker might have been waiting for the mutex, let it run and
1256 * discover that its list is now empty.
1258 cancel_work_sync(&mvm->async_handlers_wk);
1261 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1265 lockdep_assert_held(&mvm->mutex);
1267 for (i = 0; i < NUM_PHY_CTX; i++)
1268 if (!mvm->phy_ctxts[i].ref)
1269 return &mvm->phy_ctxts[i];
1271 IWL_ERR(mvm, "No available PHY context\n");
1275 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1278 struct iwl_dev_tx_power_cmd cmd = {
1279 .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1280 .v3.mac_context_id =
1281 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1282 .v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1284 int len = sizeof(cmd);
1286 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1287 cmd.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1289 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1290 len = sizeof(cmd.v3);
1292 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1295 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1296 struct ieee80211_vif *vif)
1298 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1299 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1305 * make sure D0i3 exit is completed, otherwise a target access
1306 * during tx queue configuration could be done when still in
1309 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1314 * Not much to do here. The stack will not allow interface
1315 * types or combinations that we didn't advertise, so we
1316 * don't really have to check the types.
1319 mutex_lock(&mvm->mutex);
1321 /* make sure that beacon statistics don't go backwards with FW reset */
1322 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1323 mvmvif->beacon_stats.accu_num_beacons +=
1324 mvmvif->beacon_stats.num_beacons;
1326 /* Allocate resources for the MAC context, and add it to the fw */
1327 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1331 /* Counting number of interfaces is needed for legacy PM */
1332 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1336 * The AP binding flow can be done only after the beacon
1337 * template is configured (which happens only in the mac80211
1338 * start_ap() flow), and adding the broadcast station can happen
1339 * only after the binding.
1340 * In addition, since modifying the MAC before adding a bcast
1341 * station is not allowed by the FW, delay the adding of MAC context to
1342 * the point where we can also add the bcast station.
1343 * In short: there's not much we can do at this point, other than
1344 * allocating resources :)
1346 if (vif->type == NL80211_IFTYPE_AP ||
1347 vif->type == NL80211_IFTYPE_ADHOC) {
1348 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1350 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1355 * Only queue for this station is the mcast queue,
1356 * which shouldn't be in TFD mask anyway
1358 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1364 iwl_mvm_vif_dbgfs_register(mvm, vif);
1368 mvmvif->features |= hw->netdev_features;
1370 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1374 ret = iwl_mvm_power_update_mac(mvm);
1376 goto out_remove_mac;
1378 /* beacon filtering */
1379 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1381 goto out_remove_mac;
1383 if (!mvm->bf_allowed_vif &&
1384 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1385 mvm->bf_allowed_vif = mvmvif;
1386 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1387 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1391 * P2P_DEVICE interface does not have a channel context assigned to it,
1392 * so a dedicated PHY context is allocated to it and the corresponding
1393 * MAC context is bound to it at this stage.
1395 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1397 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1398 if (!mvmvif->phy_ctxt) {
1403 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1404 ret = iwl_mvm_binding_add_vif(mvm, vif);
1408 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1412 /* Save a pointer to p2p device vif, so it can later be used to
1413 * update the p2p device MAC when a GO is started/stopped */
1414 mvm->p2p_device_vif = vif;
1417 if (vif->type == NL80211_IFTYPE_MONITOR)
1418 mvm->monitor_on = true;
1420 iwl_mvm_vif_dbgfs_register(mvm, vif);
1424 iwl_mvm_binding_remove_vif(mvm, vif);
1426 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1428 if (mvm->bf_allowed_vif == mvmvif) {
1429 mvm->bf_allowed_vif = NULL;
1430 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1431 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1434 mvmvif->phy_ctxt = NULL;
1435 iwl_mvm_mac_ctxt_remove(mvm, vif);
1437 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1440 mutex_unlock(&mvm->mutex);
1442 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1447 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1448 struct ieee80211_vif *vif)
1450 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1452 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1453 * We assume here that all the packets sent to the OFFCHANNEL
1454 * queue are sent in ROC session.
1456 flush_work(&mvm->roc_done_wk);
1460 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1461 struct ieee80211_vif *vif)
1463 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1464 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1466 iwl_mvm_prepare_mac_removal(mvm, vif);
1468 mutex_lock(&mvm->mutex);
1470 if (mvm->bf_allowed_vif == mvmvif) {
1471 mvm->bf_allowed_vif = NULL;
1472 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1473 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1476 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1479 * For AP/GO interface, the tear down of the resources allocated to the
1480 * interface is be handled as part of the stop_ap flow.
1482 if (vif->type == NL80211_IFTYPE_AP ||
1483 vif->type == NL80211_IFTYPE_ADHOC) {
1484 #ifdef CONFIG_NL80211_TESTMODE
1485 if (vif == mvm->noa_vif) {
1486 mvm->noa_vif = NULL;
1487 mvm->noa_duration = 0;
1490 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1491 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1495 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1496 mvm->p2p_device_vif = NULL;
1497 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1498 iwl_mvm_binding_remove_vif(mvm, vif);
1499 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1500 mvmvif->phy_ctxt = NULL;
1503 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1506 iwl_mvm_power_update_mac(mvm);
1507 iwl_mvm_mac_ctxt_remove(mvm, vif);
1509 if (vif->type == NL80211_IFTYPE_MONITOR)
1510 mvm->monitor_on = false;
1513 mutex_unlock(&mvm->mutex);
1516 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1521 struct iwl_mvm_mc_iter_data {
1522 struct iwl_mvm *mvm;
1526 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1527 struct ieee80211_vif *vif)
1529 struct iwl_mvm_mc_iter_data *data = _data;
1530 struct iwl_mvm *mvm = data->mvm;
1531 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1532 struct iwl_host_cmd hcmd = {
1533 .id = MCAST_FILTER_CMD,
1535 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1539 /* if we don't have free ports, mcast frames will be dropped */
1540 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1543 if (vif->type != NL80211_IFTYPE_STATION ||
1544 !vif->bss_conf.assoc)
1547 cmd->port_id = data->port_id++;
1548 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1549 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1554 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1556 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1559 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1561 struct iwl_mvm_mc_iter_data iter_data = {
1565 lockdep_assert_held(&mvm->mutex);
1567 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1570 ieee80211_iterate_active_interfaces_atomic(
1571 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1572 iwl_mvm_mc_iface_iterator, &iter_data);
1575 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1576 struct netdev_hw_addr_list *mc_list)
1578 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1579 struct iwl_mcast_filter_cmd *cmd;
1580 struct netdev_hw_addr *addr;
1585 addr_count = netdev_hw_addr_list_count(mc_list);
1586 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1587 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1591 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1592 cmd = kzalloc(len, GFP_ATOMIC);
1598 return (u64)(unsigned long)cmd;
1601 netdev_hw_addr_list_for_each(addr, mc_list) {
1602 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1603 cmd->count, addr->addr);
1604 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1605 addr->addr, ETH_ALEN);
1609 return (u64)(unsigned long)cmd;
1612 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1613 unsigned int changed_flags,
1614 unsigned int *total_flags,
1617 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1618 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1620 mutex_lock(&mvm->mutex);
1622 /* replace previous configuration */
1623 kfree(mvm->mcast_filter_cmd);
1624 mvm->mcast_filter_cmd = cmd;
1629 if (changed_flags & FIF_ALLMULTI)
1630 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1635 iwl_mvm_recalc_multicast(mvm);
1637 mutex_unlock(&mvm->mutex);
1641 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1642 struct ieee80211_vif *vif,
1643 unsigned int filter_flags,
1644 unsigned int changed_flags)
1646 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1648 /* We support only filter for probe requests */
1649 if (!(changed_flags & FIF_PROBE_REQ))
1652 /* Supported only for p2p client interfaces */
1653 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1657 mutex_lock(&mvm->mutex);
1658 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1659 mutex_unlock(&mvm->mutex);
1662 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1663 struct iwl_bcast_iter_data {
1664 struct iwl_mvm *mvm;
1665 struct iwl_bcast_filter_cmd *cmd;
1670 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1671 const struct iwl_fw_bcast_filter *in_filter,
1672 struct iwl_fw_bcast_filter *out_filter)
1674 struct iwl_fw_bcast_filter_attr *attr;
1677 memcpy(out_filter, in_filter, sizeof(*out_filter));
1679 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1680 attr = &out_filter->attrs[i];
1685 switch (attr->reserved1) {
1686 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1687 if (vif->bss_conf.arp_addr_cnt != 1) {
1692 attr->val = vif->bss_conf.arp_addr_list[0];
1694 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1695 attr->val = *(__be32 *)&vif->addr[2];
1700 attr->reserved1 = 0;
1701 out_filter->num_attrs++;
1705 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1706 struct ieee80211_vif *vif)
1708 struct iwl_bcast_iter_data *data = _data;
1709 struct iwl_mvm *mvm = data->mvm;
1710 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1711 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1712 struct iwl_fw_bcast_mac *bcast_mac;
1715 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1718 bcast_mac = &cmd->macs[mvmvif->id];
1721 * enable filtering only for associated stations, but not for P2P
1724 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1725 !vif->bss_conf.assoc)
1728 bcast_mac->default_discard = 1;
1730 /* copy all configured filters */
1731 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1733 * Make sure we don't exceed our filters limit.
1734 * if there is still a valid filter to be configured,
1735 * be on the safe side and just allow bcast for this mac.
1737 if (WARN_ON_ONCE(data->current_filter >=
1738 ARRAY_SIZE(cmd->filters))) {
1739 bcast_mac->default_discard = 0;
1740 bcast_mac->attached_filters = 0;
1744 iwl_mvm_set_bcast_filter(vif,
1745 &mvm->bcast_filters[i],
1746 &cmd->filters[data->current_filter]);
1748 /* skip current filter if it contains no attributes */
1749 if (!cmd->filters[data->current_filter].num_attrs)
1752 /* attach the filter to current mac */
1753 bcast_mac->attached_filters |=
1754 cpu_to_le16(BIT(data->current_filter));
1756 data->current_filter++;
1760 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1761 struct iwl_bcast_filter_cmd *cmd)
1763 struct iwl_bcast_iter_data iter_data = {
1768 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1771 memset(cmd, 0, sizeof(*cmd));
1772 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1773 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1775 #ifdef CONFIG_IWLWIFI_DEBUGFS
1776 /* use debugfs filters/macs if override is configured */
1777 if (mvm->dbgfs_bcast_filtering.override) {
1778 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1779 sizeof(cmd->filters));
1780 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1786 /* if no filters are configured, do nothing */
1787 if (!mvm->bcast_filters)
1790 /* configure and attach these filters for each associated sta vif */
1791 ieee80211_iterate_active_interfaces(
1792 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1793 iwl_mvm_bcast_filter_iterator, &iter_data);
1798 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1800 struct iwl_bcast_filter_cmd cmd;
1802 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1805 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1808 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1812 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1818 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1819 struct ieee80211_vif *vif)
1821 struct iwl_mu_group_mgmt_cmd cmd = {};
1823 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1824 WLAN_MEMBERSHIP_LEN);
1825 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1826 WLAN_USER_POSITION_LEN);
1828 return iwl_mvm_send_cmd_pdu(mvm,
1829 WIDE_ID(DATA_PATH_GROUP,
1830 UPDATE_MU_GROUPS_CMD),
1831 0, sizeof(cmd), &cmd);
1834 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1835 struct ieee80211_vif *vif)
1837 if (vif->mu_mimo_owner) {
1838 struct iwl_mu_group_mgmt_notif *notif = _data;
1841 * MU-MIMO Group Id action frame is little endian. We treat
1842 * the data received from firmware as if it came from the
1843 * action frame, so no conversion is needed.
1845 ieee80211_update_mu_groups(vif,
1846 (u8 *)¬if->membership_status,
1847 (u8 *)¬if->user_position);
1851 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1852 struct iwl_rx_cmd_buffer *rxb)
1854 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1855 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1857 ieee80211_iterate_active_interfaces_atomic(
1858 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1859 iwl_mvm_mu_mimo_iface_iterator, notif);
1862 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1863 struct ieee80211_vif *vif,
1864 struct ieee80211_bss_conf *bss_conf,
1867 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1871 * Re-calculate the tsf id, as the master-slave relations depend on the
1872 * beacon interval, which was not known when the station interface was
1875 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1876 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1879 * If we're not associated yet, take the (new) BSSID before associating
1880 * so the firmware knows. If we're already associated, then use the old
1881 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1882 * branch for disassociation below.
1884 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1885 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1887 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
1889 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1891 /* after sending it once, adopt mac80211 data */
1892 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1893 mvmvif->associated = bss_conf->assoc;
1895 if (changes & BSS_CHANGED_ASSOC) {
1896 if (bss_conf->assoc) {
1897 /* clear statistics to get clean beacon counter */
1898 iwl_mvm_request_statistics(mvm, true);
1899 memset(&mvmvif->beacon_stats, 0,
1900 sizeof(mvmvif->beacon_stats));
1902 /* add quota for this interface */
1903 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1905 IWL_ERR(mvm, "failed to update quotas\n");
1909 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1912 * If we're restarting then the firmware will
1913 * obviously have lost synchronisation with
1914 * the AP. It will attempt to synchronise by
1915 * itself, but we can make it more reliable by
1916 * scheduling a session protection time event.
1918 * The firmware needs to receive a beacon to
1919 * catch up with synchronisation, use 110% of
1920 * the beacon interval.
1922 * Set a large maximum delay to allow for more
1923 * than a single interface.
1925 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1926 iwl_mvm_protect_session(mvm, vif, dur, dur,
1930 iwl_mvm_sf_update(mvm, vif, false);
1931 iwl_mvm_power_vif_assoc(mvm, vif);
1933 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
1934 iwl_mvm_update_smps(mvm, vif,
1935 IWL_MVM_SMPS_REQ_PROT,
1936 IEEE80211_SMPS_DYNAMIC);
1938 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
1940 * If update fails - SF might be running in associated
1941 * mode while disassociated - which is forbidden.
1943 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1944 "Failed to update SF upon disassociation\n");
1947 * If we get an assert during the connection (after the
1948 * station has been added, but before the vif is set
1949 * to associated), mac80211 will re-add the station and
1950 * then configure the vif. Since the vif is not
1951 * associated, we would remove the station here and
1952 * this would fail the recovery.
1954 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1957 * Remove AP station now that
1958 * the MAC is unassoc
1960 ret = iwl_mvm_rm_sta_id(mvm, vif,
1964 "failed to remove AP station\n");
1966 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1967 mvm->d0i3_ap_sta_id =
1968 IWL_MVM_INVALID_STA;
1969 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1972 /* remove quota for this interface */
1973 ret = iwl_mvm_update_quotas(mvm, false, NULL);
1975 IWL_ERR(mvm, "failed to update quotas\n");
1978 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
1980 /* this will take the cleared BSSID from bss_conf */
1981 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1984 "failed to update MAC %pM (clear after unassoc)\n",
1989 * The firmware tracks the MU-MIMO group on its own.
1990 * However, on HW restart we should restore this data.
1992 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
1993 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
1994 ret = iwl_mvm_update_mu_groups(mvm, vif);
1997 "failed to update VHT MU_MIMO groups\n");
2000 iwl_mvm_recalc_multicast(mvm);
2001 iwl_mvm_configure_bcast_filter(mvm);
2003 /* reset rssi values */
2004 mvmvif->bf_data.ave_beacon_signal = 0;
2006 iwl_mvm_bt_coex_vif_change(mvm);
2007 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2008 IEEE80211_SMPS_AUTOMATIC);
2009 if (fw_has_capa(&mvm->fw->ucode_capa,
2010 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2011 iwl_mvm_config_scan(mvm);
2014 if (changes & BSS_CHANGED_BEACON_INFO) {
2016 * We received a beacon from the associated AP so
2017 * remove the session protection.
2019 iwl_mvm_stop_session_protection(mvm, vif);
2021 iwl_mvm_sf_update(mvm, vif, false);
2022 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2025 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2027 * Send power command on every beacon change,
2028 * because we may have not enabled beacon abort yet.
2030 BSS_CHANGED_BEACON_INFO)) {
2031 ret = iwl_mvm_power_update_mac(mvm);
2033 IWL_ERR(mvm, "failed to update power mode\n");
2036 if (changes & BSS_CHANGED_TXPOWER) {
2037 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2039 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2042 if (changes & BSS_CHANGED_CQM) {
2043 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2044 /* reset cqm events tracking */
2045 mvmvif->bf_data.last_cqm_event = 0;
2046 if (mvmvif->bf_data.bf_enabled) {
2047 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2050 "failed to update CQM thresholds\n");
2054 if (changes & BSS_CHANGED_ARP_FILTER) {
2055 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2056 iwl_mvm_configure_bcast_filter(mvm);
2060 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2061 struct ieee80211_vif *vif)
2063 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2064 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2068 * iwl_mvm_mac_ctxt_add() might read directly from the device
2069 * (the system time), so make sure it is available.
2071 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2075 mutex_lock(&mvm->mutex);
2077 /* Send the beacon template */
2078 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2083 * Re-calculate the tsf id, as the master-slave relations depend on the
2084 * beacon interval, which was not known when the AP interface was added.
2086 if (vif->type == NL80211_IFTYPE_AP)
2087 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2089 mvmvif->ap_assoc_sta_count = 0;
2091 /* Add the mac context */
2092 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2096 /* Perform the binding */
2097 ret = iwl_mvm_binding_add_vif(mvm, vif);
2101 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2105 /* Send the bcast station. At this stage the TBTT and DTIM time events
2106 * are added and applied to the scheduler */
2107 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2111 /* must be set before quota calculations */
2112 mvmvif->ap_ibss_active = true;
2114 /* power updated needs to be done before quotas */
2115 iwl_mvm_power_update_mac(mvm);
2117 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2119 goto out_quota_failed;
2121 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2122 if (vif->p2p && mvm->p2p_device_vif)
2123 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2125 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2127 iwl_mvm_bt_coex_vif_change(mvm);
2129 /* we don't support TDLS during DCM */
2130 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2131 iwl_mvm_teardown_tdls_peers(mvm);
2136 iwl_mvm_power_update_mac(mvm);
2137 mvmvif->ap_ibss_active = false;
2138 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2140 iwl_mvm_rm_mcast_sta(mvm, vif);
2142 iwl_mvm_binding_remove_vif(mvm, vif);
2144 iwl_mvm_mac_ctxt_remove(mvm, vif);
2146 mutex_unlock(&mvm->mutex);
2147 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2151 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2152 struct ieee80211_vif *vif)
2154 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2155 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2157 iwl_mvm_prepare_mac_removal(mvm, vif);
2159 mutex_lock(&mvm->mutex);
2161 /* Handle AP stop while in CSA */
2162 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2163 iwl_mvm_remove_time_event(mvm, mvmvif,
2164 &mvmvif->time_event_data);
2165 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2166 mvmvif->csa_countdown = false;
2169 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2170 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2171 mvm->csa_tx_block_bcn_timeout = 0;
2174 mvmvif->ap_ibss_active = false;
2175 mvm->ap_last_beacon_gp2 = 0;
2177 iwl_mvm_bt_coex_vif_change(mvm);
2179 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2181 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2182 if (vif->p2p && mvm->p2p_device_vif)
2183 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2185 iwl_mvm_update_quotas(mvm, false, NULL);
2188 * This is not very nice, but the simplest:
2189 * For older FWs removing the mcast sta before the bcast station may
2190 * cause assert 0x2b00.
2191 * This is fixed in later FW (which will stop beaconing when removing
2193 * So make the order of removal depend on the TLV
2195 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2196 iwl_mvm_rm_mcast_sta(mvm, vif);
2197 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2198 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2199 iwl_mvm_rm_mcast_sta(mvm, vif);
2200 iwl_mvm_binding_remove_vif(mvm, vif);
2202 iwl_mvm_power_update_mac(mvm);
2204 iwl_mvm_mac_ctxt_remove(mvm, vif);
2206 mutex_unlock(&mvm->mutex);
2210 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2211 struct ieee80211_vif *vif,
2212 struct ieee80211_bss_conf *bss_conf,
2215 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2217 /* Changes will be applied when the AP/IBSS is started */
2218 if (!mvmvif->ap_ibss_active)
2221 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2222 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2223 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2224 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2226 /* Need to send a new beacon template to the FW */
2227 if (changes & BSS_CHANGED_BEACON &&
2228 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2229 IWL_WARN(mvm, "Failed updating beacon data\n");
2231 if (changes & BSS_CHANGED_TXPOWER) {
2232 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2234 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2238 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2239 struct ieee80211_vif *vif,
2240 struct ieee80211_bss_conf *bss_conf,
2243 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2246 * iwl_mvm_bss_info_changed_station() might call
2247 * iwl_mvm_protect_session(), which reads directly from
2248 * the device (the system time), so make sure it is available.
2250 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2253 mutex_lock(&mvm->mutex);
2255 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2256 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2258 switch (vif->type) {
2259 case NL80211_IFTYPE_STATION:
2260 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2262 case NL80211_IFTYPE_AP:
2263 case NL80211_IFTYPE_ADHOC:
2264 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2266 case NL80211_IFTYPE_MONITOR:
2267 if (changes & BSS_CHANGED_MU_GROUPS)
2268 iwl_mvm_update_mu_groups(mvm, vif);
2271 /* shouldn't happen */
2275 mutex_unlock(&mvm->mutex);
2276 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2279 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2280 struct ieee80211_vif *vif,
2281 struct ieee80211_scan_request *hw_req)
2283 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2286 if (hw_req->req.n_channels == 0 ||
2287 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2290 mutex_lock(&mvm->mutex);
2291 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2292 mutex_unlock(&mvm->mutex);
2297 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2298 struct ieee80211_vif *vif)
2300 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2302 mutex_lock(&mvm->mutex);
2304 /* Due to a race condition, it's possible that mac80211 asks
2305 * us to stop a hw_scan when it's already stopped. This can
2306 * happen, for instance, if we stopped the scan ourselves,
2307 * called ieee80211_scan_completed() and the userspace called
2308 * cancel scan scan before ieee80211_scan_work() could run.
2309 * To handle that, simply return if the scan is not running.
2311 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2312 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2314 mutex_unlock(&mvm->mutex);
2318 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2319 struct ieee80211_sta *sta, u16 tids,
2321 enum ieee80211_frame_release_type reason,
2324 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2326 /* Called when we need to transmit (a) frame(s) from mac80211 */
2328 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2329 tids, more_data, false);
2333 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2334 struct ieee80211_sta *sta, u16 tids,
2336 enum ieee80211_frame_release_type reason,
2339 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2341 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2343 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2344 tids, more_data, true);
2347 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2348 enum sta_notify_cmd cmd,
2349 struct ieee80211_sta *sta)
2351 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2352 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2353 unsigned long txqs = 0, tids = 0;
2357 * If we have TVQM then we get too high queue numbers - luckily
2358 * we really shouldn't get here with that because such hardware
2359 * should have firmware supporting buffer station offload.
2361 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2364 spin_lock_bh(&mvmsta->lock);
2365 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2366 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2368 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2371 __set_bit(tid_data->txq_id, &txqs);
2373 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2376 __set_bit(tid, &tids);
2380 case STA_NOTIFY_SLEEP:
2381 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2382 ieee80211_sta_set_buffered(sta, tid, true);
2385 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2387 * The fw updates the STA to be asleep. Tx packets on the Tx
2388 * queues to this station will not be transmitted. The fw will
2389 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2392 case STA_NOTIFY_AWAKE:
2393 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2397 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2398 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2403 spin_unlock_bh(&mvmsta->lock);
2406 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2407 struct ieee80211_vif *vif,
2408 enum sta_notify_cmd cmd,
2409 struct ieee80211_sta *sta)
2411 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2414 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2416 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2417 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2418 struct ieee80211_sta *sta;
2419 struct iwl_mvm_sta *mvmsta;
2420 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2422 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2426 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2427 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2432 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2435 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2440 if (mvmsta->sleeping != sleeping) {
2441 mvmsta->sleeping = sleeping;
2442 __iwl_mvm_mac_sta_notify(mvm->hw,
2443 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2445 ieee80211_sta_ps_transition(sta, sleeping);
2449 switch (notif->type) {
2450 case IWL_MVM_PM_EVENT_AWAKE:
2451 case IWL_MVM_PM_EVENT_ASLEEP:
2453 case IWL_MVM_PM_EVENT_UAPSD:
2454 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2456 case IWL_MVM_PM_EVENT_PS_POLL:
2457 ieee80211_sta_pspoll(sta);
2467 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2468 struct ieee80211_vif *vif,
2469 struct ieee80211_sta *sta)
2471 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2472 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2475 * This is called before mac80211 does RCU synchronisation,
2476 * so here we already invalidate our internal RCU-protected
2477 * station pointer. The rest of the code will thus no longer
2478 * be able to find the station this way, and we don't rely
2479 * on further RCU synchronisation after the sta_state()
2480 * callback deleted the station.
2482 mutex_lock(&mvm->mutex);
2483 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2484 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2487 mutex_unlock(&mvm->mutex);
2490 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2493 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2496 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2497 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2502 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2503 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2507 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2511 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2512 struct ieee80211_vif *vif, u8 *peer_addr,
2513 enum nl80211_tdls_operation action)
2515 struct iwl_fw_dbg_trigger_tlv *trig;
2516 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2518 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS))
2521 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS);
2522 tdls_trig = (void *)trig->data;
2523 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
2524 ieee80211_vif_to_wdev(vif), trig))
2527 if (!(tdls_trig->action_bitmap & BIT(action)))
2530 if (tdls_trig->peer_mode &&
2531 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2534 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2535 "TDLS event occurred, peer %pM, action %d",
2539 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2540 struct iwl_mvm_sta *mvm_sta)
2542 struct iwl_mvm_tid_data *tid_data;
2543 struct sk_buff *skb;
2546 spin_lock_bh(&mvm_sta->lock);
2547 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2548 tid_data = &mvm_sta->tid_data[i];
2550 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2551 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2554 * The first deferred frame should've stopped the MAC
2555 * queues, so we should never get a second deferred
2556 * frame for the RA/TID.
2558 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
2559 ieee80211_free_txskb(mvm->hw, skb);
2562 spin_unlock_bh(&mvm_sta->lock);
2565 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2566 struct ieee80211_vif *vif,
2567 struct ieee80211_sta *sta,
2568 enum ieee80211_sta_state old_state,
2569 enum ieee80211_sta_state new_state)
2571 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2572 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2573 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2576 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2577 sta->addr, old_state, new_state);
2579 /* this would be a mac80211 bug ... but don't crash */
2580 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2584 * If we are in a STA removal flow and in DQA mode:
2586 * This is after the sync_rcu part, so the queues have already been
2587 * flushed. No more TXs on their way in mac80211's path, and no more in
2589 * Also, we won't be getting any new TX frames for this station.
2590 * What we might have are deferred TX frames that need to be taken care
2593 * Drop any still-queued deferred-frame before removing the STA, and
2594 * make sure the worker is no longer handling frames for this STA.
2596 if (old_state == IEEE80211_STA_NONE &&
2597 new_state == IEEE80211_STA_NOTEXIST) {
2598 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2599 flush_work(&mvm->add_stream_wk);
2602 * No need to make sure deferred TX indication is off since the
2603 * worker will already remove it if it was on
2607 mutex_lock(&mvm->mutex);
2608 /* track whether or not the station is associated */
2609 mvm_sta->associated = new_state >= IEEE80211_STA_ASSOC;
2611 if (old_state == IEEE80211_STA_NOTEXIST &&
2612 new_state == IEEE80211_STA_NONE) {
2614 * Firmware bug - it'll crash if the beacon interval is less
2615 * than 16. We can't avoid connecting at all, so refuse the
2616 * station state change, this will cause mac80211 to abandon
2617 * attempts to connect to this AP, and eventually wpa_s will
2618 * blacklist the AP...
2620 if (vif->type == NL80211_IFTYPE_STATION &&
2621 vif->bss_conf.beacon_int < 16) {
2623 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2624 sta->addr, vif->bss_conf.beacon_int);
2631 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2632 IWL_MVM_TDLS_STA_COUNT ||
2633 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2634 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2639 ret = iwl_mvm_add_sta(mvm, vif, sta);
2640 if (sta->tdls && ret == 0) {
2641 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2642 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2643 NL80211_TDLS_SETUP);
2645 } else if (old_state == IEEE80211_STA_NONE &&
2646 new_state == IEEE80211_STA_AUTH) {
2648 * EBS may be disabled due to previous failures reported by FW.
2649 * Reset EBS status here assuming environment has been changed.
2651 mvm->last_ebs_successful = true;
2652 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2654 } else if (old_state == IEEE80211_STA_AUTH &&
2655 new_state == IEEE80211_STA_ASSOC) {
2656 if (vif->type == NL80211_IFTYPE_AP) {
2657 mvmvif->ap_assoc_sta_count++;
2658 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2661 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2663 ret = iwl_mvm_update_sta(mvm, vif, sta);
2664 } else if (old_state == IEEE80211_STA_ASSOC &&
2665 new_state == IEEE80211_STA_AUTHORIZED) {
2667 /* we don't support TDLS during DCM */
2668 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2669 iwl_mvm_teardown_tdls_peers(mvm);
2672 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2673 NL80211_TDLS_ENABLE_LINK);
2675 /* enable beacon filtering */
2676 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2678 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2679 new_state == IEEE80211_STA_ASSOC) {
2680 /* disable beacon filtering */
2681 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2683 } else if (old_state == IEEE80211_STA_ASSOC &&
2684 new_state == IEEE80211_STA_AUTH) {
2685 if (vif->type == NL80211_IFTYPE_AP) {
2686 mvmvif->ap_assoc_sta_count--;
2687 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2690 } else if (old_state == IEEE80211_STA_AUTH &&
2691 new_state == IEEE80211_STA_NONE) {
2693 } else if (old_state == IEEE80211_STA_NONE &&
2694 new_state == IEEE80211_STA_NOTEXIST) {
2695 ret = iwl_mvm_rm_sta(mvm, vif, sta);
2697 iwl_mvm_recalc_tdls_state(mvm, vif, false);
2698 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2699 NL80211_TDLS_DISABLE_LINK);
2705 mutex_unlock(&mvm->mutex);
2707 if (sta->tdls && ret == 0) {
2708 if (old_state == IEEE80211_STA_NOTEXIST &&
2709 new_state == IEEE80211_STA_NONE)
2710 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2711 else if (old_state == IEEE80211_STA_NONE &&
2712 new_state == IEEE80211_STA_NOTEXIST)
2713 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2719 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2721 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2723 mvm->rts_threshold = value;
2728 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2729 struct ieee80211_vif *vif,
2730 struct ieee80211_sta *sta, u32 changed)
2732 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2734 if (vif->type == NL80211_IFTYPE_STATION &&
2735 changed & IEEE80211_RC_NSS_CHANGED)
2736 iwl_mvm_sf_update(mvm, vif, false);
2739 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2740 struct ieee80211_vif *vif, u16 ac,
2741 const struct ieee80211_tx_queue_params *params)
2743 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2744 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2746 mvmvif->queue_params[ac] = *params;
2749 * No need to update right away, we'll get BSS_CHANGED_QOS
2750 * The exception is P2P_DEVICE interface which needs immediate update.
2752 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2755 mutex_lock(&mvm->mutex);
2756 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2757 mutex_unlock(&mvm->mutex);
2763 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2764 struct ieee80211_vif *vif)
2766 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2767 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
2768 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
2770 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2774 * iwl_mvm_protect_session() reads directly from the device
2775 * (the system time), so make sure it is available.
2777 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2780 mutex_lock(&mvm->mutex);
2781 /* Try really hard to protect the session and hear a beacon */
2782 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
2783 mutex_unlock(&mvm->mutex);
2785 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
2788 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2789 struct ieee80211_vif *vif,
2790 struct cfg80211_sched_scan_request *req,
2791 struct ieee80211_scan_ies *ies)
2793 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2797 mutex_lock(&mvm->mutex);
2799 if (!vif->bss_conf.idle) {
2804 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
2807 mutex_unlock(&mvm->mutex);
2811 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2812 struct ieee80211_vif *vif)
2814 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2817 mutex_lock(&mvm->mutex);
2819 /* Due to a race condition, it's possible that mac80211 asks
2820 * us to stop a sched_scan when it's already stopped. This
2821 * can happen, for instance, if we stopped the scan ourselves,
2822 * called ieee80211_sched_scan_stopped() and the userspace called
2823 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
2824 * could run. To handle this, simply return if the scan is
2827 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
2828 mutex_unlock(&mvm->mutex);
2832 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
2833 mutex_unlock(&mvm->mutex);
2834 iwl_mvm_wait_for_async_handlers(mvm);
2839 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2840 enum set_key_cmd cmd,
2841 struct ieee80211_vif *vif,
2842 struct ieee80211_sta *sta,
2843 struct ieee80211_key_conf *key)
2845 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2846 struct iwl_mvm_sta *mvmsta;
2847 struct iwl_mvm_key_pn *ptk_pn;
2848 int keyidx = key->keyidx;
2852 if (iwlwifi_mod_params.swcrypto) {
2853 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2857 switch (key->cipher) {
2858 case WLAN_CIPHER_SUITE_TKIP:
2859 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2860 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2862 case WLAN_CIPHER_SUITE_CCMP:
2863 case WLAN_CIPHER_SUITE_GCMP:
2864 case WLAN_CIPHER_SUITE_GCMP_256:
2865 if (!iwl_mvm_has_new_tx_api(mvm))
2866 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2868 case WLAN_CIPHER_SUITE_AES_CMAC:
2869 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2870 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2871 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
2873 case WLAN_CIPHER_SUITE_WEP40:
2874 case WLAN_CIPHER_SUITE_WEP104:
2875 /* For non-client mode, only use WEP keys for TX as we probably
2876 * don't have a station yet anyway and would then have to keep
2877 * track of the keys, linking them to each of the clients/peers
2878 * as they appear. For now, don't do that, for performance WEP
2879 * offload doesn't really matter much, but we need it for some
2880 * other offload features in client mode.
2882 if (vif->type != NL80211_IFTYPE_STATION)
2886 /* currently FW supports only one optional cipher scheme */
2887 if (hw->n_cipher_schemes &&
2888 hw->cipher_schemes->cipher == key->cipher)
2889 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2894 mutex_lock(&mvm->mutex);
2898 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2899 vif->type == NL80211_IFTYPE_AP) && !sta) {
2901 * GTK on AP interface is a TX-only key, return 0;
2902 * on IBSS they're per-station and because we're lazy
2903 * we don't support them for RX, so do the same.
2904 * CMAC/GMAC in AP/IBSS modes must be done in software.
2906 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2907 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2908 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
2913 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
2914 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
2915 !iwl_mvm_has_new_tx_api(mvm)) {
2916 key->hw_key_idx = STA_KEY_IDX_INVALID;
2921 /* During FW restart, in order to restore the state as it was,
2922 * don't try to reprogram keys we previously failed for.
2924 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2925 key->hw_key_idx == STA_KEY_IDX_INVALID) {
2926 IWL_DEBUG_MAC80211(mvm,
2927 "skip invalid idx key programming during restart\n");
2932 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2933 sta && iwl_mvm_has_new_rx_api(mvm) &&
2934 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2935 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
2936 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2937 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
2938 struct ieee80211_key_seq seq;
2941 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2942 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
2943 ptk_pn = kzalloc(sizeof(*ptk_pn) +
2944 mvm->trans->num_rx_queues *
2945 sizeof(ptk_pn->q[0]),
2952 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2953 ieee80211_get_key_rx_seq(key, tid, &seq);
2954 for (q = 0; q < mvm->trans->num_rx_queues; q++)
2955 memcpy(ptk_pn->q[q].pn[tid],
2957 IEEE80211_CCMP_PN_LEN);
2960 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
2963 /* in HW restart reuse the index, otherwise request a new one */
2964 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
2965 key_offset = key->hw_key_idx;
2967 key_offset = STA_KEY_IDX_INVALID;
2969 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2970 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
2972 IWL_WARN(mvm, "set key failed\n");
2974 * can't add key for RX, but we don't need it
2975 * in the device for TX so still return 0
2977 key->hw_key_idx = STA_KEY_IDX_INVALID;
2983 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2988 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
2989 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2990 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
2991 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2992 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
2993 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2994 ptk_pn = rcu_dereference_protected(
2995 mvmsta->ptk_pn[keyidx],
2996 lockdep_is_held(&mvm->mutex));
2997 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
2999 kfree_rcu(ptk_pn, rcu_head);
3002 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3003 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3009 mutex_unlock(&mvm->mutex);
3013 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3014 struct ieee80211_vif *vif,
3015 struct ieee80211_key_conf *keyconf,
3016 struct ieee80211_sta *sta,
3017 u32 iv32, u16 *phase1key)
3019 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3021 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3024 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3028 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3029 struct iwl_rx_packet *pkt, void *data)
3031 struct iwl_mvm *mvm =
3032 container_of(notif_wait, struct iwl_mvm, notif_wait);
3033 struct iwl_hs20_roc_res *resp;
3034 int resp_len = iwl_rx_packet_payload_len(pkt);
3035 struct iwl_mvm_time_event_data *te_data = data;
3037 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3040 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3041 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3045 resp = (void *)pkt->data;
3048 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3049 resp->status, resp->event_unique_id);
3051 te_data->uid = le32_to_cpu(resp->event_unique_id);
3052 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3055 spin_lock_bh(&mvm->time_event_lock);
3056 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3057 spin_unlock_bh(&mvm->time_event_lock);
3062 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3063 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3064 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3065 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3066 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3067 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3068 struct ieee80211_channel *channel,
3069 struct ieee80211_vif *vif,
3072 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3073 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3074 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3075 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3076 struct iwl_notification_wait wait_time_event;
3077 u32 dtim_interval = vif->bss_conf.dtim_period *
3078 vif->bss_conf.beacon_int;
3080 struct iwl_hs20_roc_req aux_roc_req = {
3081 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3083 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3084 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3085 /* Set the channel info data */
3086 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3087 PHY_BAND_24 : PHY_BAND_5,
3088 .channel_info.channel = channel->hw_value,
3089 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3090 /* Set the time and duration */
3091 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3094 delay = AUX_ROC_MIN_DELAY;
3095 req_dur = MSEC_TO_TU(duration);
3098 * If we are associated we want the delay time to be at least one
3099 * dtim interval so that the FW can wait until after the DTIM and
3100 * then start the time event, this will potentially allow us to
3101 * remain off-channel for the max duration.
3102 * Since we want to use almost a whole dtim interval we would also
3103 * like the delay to be for 2-3 dtim intervals, in case there are
3104 * other time events with higher priority.
3106 if (vif->bss_conf.assoc) {
3107 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3108 /* We cannot remain off-channel longer than the DTIM interval */
3109 if (dtim_interval <= req_dur) {
3110 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3111 if (req_dur <= AUX_ROC_MIN_DURATION)
3112 req_dur = dtim_interval -
3113 AUX_ROC_MIN_SAFETY_BUFFER;
3117 aux_roc_req.duration = cpu_to_le32(req_dur);
3118 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3121 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3122 channel->hw_value, req_dur, duration, delay,
3124 /* Set the node address */
3125 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3127 lockdep_assert_held(&mvm->mutex);
3129 spin_lock_bh(&mvm->time_event_lock);
3131 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3132 spin_unlock_bh(&mvm->time_event_lock);
3137 te_data->duration = duration;
3138 te_data->id = HOT_SPOT_CMD;
3140 spin_unlock_bh(&mvm->time_event_lock);
3143 * Use a notification wait, which really just processes the
3144 * command response and doesn't wait for anything, in order
3145 * to be able to process the response and get the UID inside
3146 * the RX path. Using CMD_WANT_SKB doesn't work because it
3147 * stores the buffer and then wakes up this thread, by which
3148 * time another notification (that the time event started)
3149 * might already be processed unsuccessfully.
3151 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3152 time_event_response,
3153 ARRAY_SIZE(time_event_response),
3154 iwl_mvm_rx_aux_roc, te_data);
3156 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3160 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3161 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3165 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3166 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3167 /* should never fail */
3172 spin_lock_bh(&mvm->time_event_lock);
3173 iwl_mvm_te_clear_data(mvm, te_data);
3174 spin_unlock_bh(&mvm->time_event_lock);
3180 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3181 struct ieee80211_vif *vif,
3182 struct ieee80211_channel *channel,
3184 enum ieee80211_roc_type type)
3186 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3187 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3188 struct cfg80211_chan_def chandef;
3189 struct iwl_mvm_phy_ctxt *phy_ctxt;
3192 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3196 * Flush the done work, just in case it's still pending, so that
3197 * the work it does can complete and we can accept new frames.
3199 flush_work(&mvm->roc_done_wk);
3201 mutex_lock(&mvm->mutex);
3203 switch (vif->type) {
3204 case NL80211_IFTYPE_STATION:
3205 if (fw_has_capa(&mvm->fw->ucode_capa,
3206 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3207 /* Use aux roc framework (HS20) */
3208 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3212 IWL_ERR(mvm, "hotspot not supported\n");
3215 case NL80211_IFTYPE_P2P_DEVICE:
3219 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3224 for (i = 0; i < NUM_PHY_CTX; i++) {
3225 phy_ctxt = &mvm->phy_ctxts[i];
3226 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3229 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3231 * Unbind the P2P_DEVICE from the current PHY context,
3232 * and if the PHY context is not used remove it.
3234 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3235 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3238 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3240 /* Bind the P2P_DEVICE to the current PHY Context */
3241 mvmvif->phy_ctxt = phy_ctxt;
3243 ret = iwl_mvm_binding_add_vif(mvm, vif);
3244 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3247 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3248 goto schedule_time_event;
3252 /* Need to update the PHY context only if the ROC channel changed */
3253 if (channel == mvmvif->phy_ctxt->channel)
3254 goto schedule_time_event;
3256 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3259 * Change the PHY context configuration as it is currently referenced
3260 * only by the P2P Device MAC
3262 if (mvmvif->phy_ctxt->ref == 1) {
3263 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3269 * The PHY context is shared with other MACs. Need to remove the
3270 * P2P Device from the binding, allocate an new PHY context and
3271 * create a new binding
3273 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3279 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3282 IWL_ERR(mvm, "Failed to change PHY context\n");
3286 /* Unbind the P2P_DEVICE from the current PHY context */
3287 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3288 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3291 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3293 /* Bind the P2P_DEVICE to the new allocated PHY context */
3294 mvmvif->phy_ctxt = phy_ctxt;
3296 ret = iwl_mvm_binding_add_vif(mvm, vif);
3297 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3300 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3303 schedule_time_event:
3304 /* Schedule the time events */
3305 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3308 mutex_unlock(&mvm->mutex);
3309 IWL_DEBUG_MAC80211(mvm, "leave\n");
3313 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3315 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3317 IWL_DEBUG_MAC80211(mvm, "enter\n");
3319 mutex_lock(&mvm->mutex);
3320 iwl_mvm_stop_roc(mvm);
3321 mutex_unlock(&mvm->mutex);
3323 IWL_DEBUG_MAC80211(mvm, "leave\n");
3327 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3328 struct ieee80211_chanctx_conf *ctx)
3330 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3331 struct iwl_mvm_phy_ctxt *phy_ctxt;
3334 lockdep_assert_held(&mvm->mutex);
3336 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3338 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3344 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3345 ctx->rx_chains_static,
3346 ctx->rx_chains_dynamic);
3348 IWL_ERR(mvm, "Failed to add PHY context\n");
3352 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3353 *phy_ctxt_id = phy_ctxt->id;
3358 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3359 struct ieee80211_chanctx_conf *ctx)
3361 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3364 mutex_lock(&mvm->mutex);
3365 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3366 mutex_unlock(&mvm->mutex);
3371 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3372 struct ieee80211_chanctx_conf *ctx)
3374 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3375 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3377 lockdep_assert_held(&mvm->mutex);
3379 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3382 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3383 struct ieee80211_chanctx_conf *ctx)
3385 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3387 mutex_lock(&mvm->mutex);
3388 __iwl_mvm_remove_chanctx(mvm, ctx);
3389 mutex_unlock(&mvm->mutex);
3392 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3393 struct ieee80211_chanctx_conf *ctx,
3396 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3397 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3398 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3400 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3401 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3402 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3403 IEEE80211_CHANCTX_CHANGE_RADAR |
3404 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3405 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3406 phy_ctxt->ref, changed))
3409 mutex_lock(&mvm->mutex);
3411 /* we are only changing the min_width, may be a noop */
3412 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
3413 if (phy_ctxt->width == ctx->min_def.width)
3416 /* we are just toggling between 20_NOHT and 20 */
3417 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
3418 ctx->min_def.width <= NL80211_CHAN_WIDTH_20)
3422 iwl_mvm_bt_coex_vif_change(mvm);
3423 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3424 ctx->rx_chains_static,
3425 ctx->rx_chains_dynamic);
3428 mutex_unlock(&mvm->mutex);
3431 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3432 struct ieee80211_vif *vif,
3433 struct ieee80211_chanctx_conf *ctx,
3434 bool switching_chanctx)
3436 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3437 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3438 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3441 lockdep_assert_held(&mvm->mutex);
3443 mvmvif->phy_ctxt = phy_ctxt;
3445 switch (vif->type) {
3446 case NL80211_IFTYPE_AP:
3447 /* only needed if we're switching chanctx (i.e. during CSA) */
3448 if (switching_chanctx) {
3449 mvmvif->ap_ibss_active = true;
3452 case NL80211_IFTYPE_ADHOC:
3454 * The AP binding flow is handled as part of the start_ap flow
3455 * (in bss_info_changed), similarly for IBSS.
3459 case NL80211_IFTYPE_STATION:
3461 case NL80211_IFTYPE_MONITOR:
3462 /* always disable PS when a monitor interface is active */
3463 mvmvif->ps_disabled = true;
3470 ret = iwl_mvm_binding_add_vif(mvm, vif);
3475 * Power state must be updated before quotas,
3476 * otherwise fw will complain.
3478 iwl_mvm_power_update_mac(mvm);
3480 /* Setting the quota at this stage is only required for monitor
3481 * interfaces. For the other types, the bss_info changed flow
3482 * will handle quota settings.
3484 if (vif->type == NL80211_IFTYPE_MONITOR) {
3485 mvmvif->monitor_active = true;
3486 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3488 goto out_remove_binding;
3490 ret = iwl_mvm_add_snif_sta(mvm, vif);
3492 goto out_remove_binding;
3496 /* Handle binding during CSA */
3497 if (vif->type == NL80211_IFTYPE_AP) {
3498 iwl_mvm_update_quotas(mvm, false, NULL);
3499 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3502 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3503 u32 duration = 2 * vif->bss_conf.beacon_int;
3505 /* iwl_mvm_protect_session() reads directly from the
3506 * device (the system time), so make sure it is
3509 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3511 goto out_remove_binding;
3513 /* Protect the session to make sure we hear the first
3514 * beacon on the new channel.
3516 iwl_mvm_protect_session(mvm, vif, duration, duration,
3517 vif->bss_conf.beacon_int / 2,
3520 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3522 iwl_mvm_update_quotas(mvm, false, NULL);
3528 iwl_mvm_binding_remove_vif(mvm, vif);
3529 iwl_mvm_power_update_mac(mvm);
3532 mvmvif->phy_ctxt = NULL;
3535 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3536 struct ieee80211_vif *vif,
3537 struct ieee80211_chanctx_conf *ctx)
3539 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3542 mutex_lock(&mvm->mutex);
3543 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3544 mutex_unlock(&mvm->mutex);
3549 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3550 struct ieee80211_vif *vif,
3551 struct ieee80211_chanctx_conf *ctx,
3552 bool switching_chanctx)
3554 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3555 struct ieee80211_vif *disabled_vif = NULL;
3557 lockdep_assert_held(&mvm->mutex);
3559 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3561 switch (vif->type) {
3562 case NL80211_IFTYPE_ADHOC:
3564 case NL80211_IFTYPE_MONITOR:
3565 mvmvif->monitor_active = false;
3566 mvmvif->ps_disabled = false;
3567 iwl_mvm_rm_snif_sta(mvm, vif);
3569 case NL80211_IFTYPE_AP:
3570 /* This part is triggered only during CSA */
3571 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3574 mvmvif->csa_countdown = false;
3576 /* Set CS bit on all the stations */
3577 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3579 /* Save blocked iface, the timeout is set on the next beacon */
3580 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3582 mvmvif->ap_ibss_active = false;
3584 case NL80211_IFTYPE_STATION:
3585 if (!switching_chanctx)
3590 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3596 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3597 iwl_mvm_binding_remove_vif(mvm, vif);
3600 mvmvif->phy_ctxt = NULL;
3601 iwl_mvm_power_update_mac(mvm);
3604 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3605 struct ieee80211_vif *vif,
3606 struct ieee80211_chanctx_conf *ctx)
3608 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3610 mutex_lock(&mvm->mutex);
3611 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3612 mutex_unlock(&mvm->mutex);
3616 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3617 struct ieee80211_vif_chanctx_switch *vifs)
3621 mutex_lock(&mvm->mutex);
3622 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3623 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3625 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3627 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3631 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3635 "failed to assign new_ctx during channel switch\n");
3639 /* we don't support TDLS during DCM - can be caused by channel switch */
3640 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3641 iwl_mvm_teardown_tdls_peers(mvm);
3646 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3649 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3650 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3654 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3656 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3663 /* things keep failing, better restart the hw */
3664 iwl_mvm_nic_restart(mvm, false);
3667 mutex_unlock(&mvm->mutex);
3673 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3674 struct ieee80211_vif_chanctx_switch *vifs)
3678 mutex_lock(&mvm->mutex);
3679 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3681 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3685 "failed to assign new_ctx during channel switch\n");
3692 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3694 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3701 /* things keep failing, better restart the hw */
3702 iwl_mvm_nic_restart(mvm, false);
3705 mutex_unlock(&mvm->mutex);
3710 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3711 struct ieee80211_vif_chanctx_switch *vifs,
3713 enum ieee80211_chanctx_switch_mode mode)
3715 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3718 /* we only support a single-vif right now */
3723 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3724 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3726 case CHANCTX_SWMODE_REASSIGN_VIF:
3727 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
3737 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
3739 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3741 return mvm->ibss_manager;
3744 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3745 struct ieee80211_sta *sta,
3748 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3749 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3751 if (!mvm_sta || !mvm_sta->vif) {
3752 IWL_ERR(mvm, "Station is not associated to a vif\n");
3756 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3759 #ifdef CONFIG_NL80211_TESTMODE
3760 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3761 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3762 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
3763 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
3766 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3767 struct ieee80211_vif *vif,
3768 void *data, int len)
3770 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3774 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
3779 if (!tb[IWL_MVM_TM_ATTR_CMD])
3782 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3783 case IWL_MVM_TM_CMD_SET_NOA:
3784 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3785 !vif->bss_conf.enable_beacon ||
3786 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3789 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3790 if (noa_duration >= vif->bss_conf.beacon_int)
3793 mvm->noa_duration = noa_duration;
3796 return iwl_mvm_update_quotas(mvm, false, NULL);
3797 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3798 /* must be associated client vif - ignore authorized */
3799 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3800 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3801 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3804 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
3805 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3806 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3812 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3813 struct ieee80211_vif *vif,
3814 void *data, int len)
3816 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3819 mutex_lock(&mvm->mutex);
3820 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3821 mutex_unlock(&mvm->mutex);
3827 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3828 struct ieee80211_vif *vif,
3829 struct ieee80211_channel_switch *chsw)
3831 /* By implementing this operation, we prevent mac80211 from
3832 * starting its own channel switch timer, so that we can call
3833 * ieee80211_chswitch_done() ourselves at the right time
3834 * (which is when the absence time event starts).
3837 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3838 "dummy channel switch op\n");
3841 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3842 struct ieee80211_vif *vif,
3843 struct ieee80211_channel_switch *chsw)
3845 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3846 struct ieee80211_vif *csa_vif;
3847 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3851 mutex_lock(&mvm->mutex);
3853 mvmvif->csa_failed = false;
3855 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
3856 chsw->chandef.center_freq1);
3858 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
3859 ieee80211_vif_to_wdev(vif),
3860 FW_DBG_TRIGGER_CHANNEL_SWITCH);
3862 switch (vif->type) {
3863 case NL80211_IFTYPE_AP:
3865 rcu_dereference_protected(mvm->csa_vif,
3866 lockdep_is_held(&mvm->mutex));
3867 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3868 "Another CSA is already in progress")) {
3873 /* we still didn't unblock tx. prevent new CS meanwhile */
3874 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
3875 lockdep_is_held(&mvm->mutex))) {
3880 rcu_assign_pointer(mvm->csa_vif, vif);
3882 if (WARN_ONCE(mvmvif->csa_countdown,
3883 "Previous CSA countdown didn't complete")) {
3888 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
3891 case NL80211_IFTYPE_STATION:
3892 /* Schedule the time event to a bit before beacon 1,
3893 * to make sure we're in the new channel when the
3894 * GO/AP arrives. In case count <= 1 immediately schedule the
3895 * TE (this might result with some packet loss or connection
3898 if (chsw->count <= 1)
3901 apply_time = chsw->device_timestamp +
3902 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3903 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
3906 iwl_mvm_csa_client_absent(mvm, vif);
3908 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
3910 if (mvmvif->bf_data.bf_enabled) {
3911 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3921 mvmvif->ps_disabled = true;
3923 ret = iwl_mvm_power_update_ps(mvm);
3927 /* we won't be on this channel any longer */
3928 iwl_mvm_teardown_tdls_peers(mvm);
3931 mutex_unlock(&mvm->mutex);
3936 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
3937 struct ieee80211_vif *vif)
3939 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3940 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3943 mutex_lock(&mvm->mutex);
3945 if (mvmvif->csa_failed) {
3946 mvmvif->csa_failed = false;
3951 if (vif->type == NL80211_IFTYPE_STATION) {
3952 struct iwl_mvm_sta *mvmsta;
3954 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
3957 if (WARN_ON(!mvmsta)) {
3962 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
3964 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3966 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3970 iwl_mvm_stop_session_protection(mvm, vif);
3973 mvmvif->ps_disabled = false;
3975 ret = iwl_mvm_power_update_ps(mvm);
3978 mutex_unlock(&mvm->mutex);
3983 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
3987 if (!iwl_mvm_has_new_tx_api(mvm)) {
3989 mutex_lock(&mvm->mutex);
3990 iwl_mvm_flush_tx_path(mvm,
3991 iwl_mvm_flushable_queues(mvm) & queues, 0);
3992 mutex_unlock(&mvm->mutex);
3994 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
3999 mutex_lock(&mvm->mutex);
4000 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4001 struct ieee80211_sta *sta;
4003 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4004 lockdep_is_held(&mvm->mutex));
4005 if (IS_ERR_OR_NULL(sta))
4009 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4011 iwl_mvm_wait_sta_queues_empty(mvm,
4012 iwl_mvm_sta_from_mac80211(sta));
4014 mutex_unlock(&mvm->mutex);
4017 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4018 struct ieee80211_vif *vif, u32 queues, bool drop)
4020 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4021 struct iwl_mvm_vif *mvmvif;
4022 struct iwl_mvm_sta *mvmsta;
4023 struct ieee80211_sta *sta;
4028 iwl_mvm_flush_no_vif(mvm, queues, drop);
4032 if (vif->type != NL80211_IFTYPE_STATION)
4035 /* Make sure we're done with the deferred traffic before flushing */
4036 flush_work(&mvm->add_stream_wk);
4038 mutex_lock(&mvm->mutex);
4039 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4041 /* flush the AP-station and all TDLS peers */
4042 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4043 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4044 lockdep_is_held(&mvm->mutex));
4045 if (IS_ERR_OR_NULL(sta))
4048 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4049 if (mvmsta->vif != vif)
4052 /* make sure only TDLS peers or the AP are flushed */
4053 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4056 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4057 IWL_ERR(mvm, "flush request fail\n");
4059 msk |= mvmsta->tfd_queue_msk;
4060 if (iwl_mvm_has_new_tx_api(mvm))
4061 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4065 mutex_unlock(&mvm->mutex);
4067 /* this can take a while, and we may need/want other operations
4068 * to succeed while doing this, so do it without the mutex held
4070 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4071 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4074 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4075 struct survey_info *survey)
4077 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4080 memset(survey, 0, sizeof(*survey));
4082 /* only support global statistics right now */
4086 if (!fw_has_capa(&mvm->fw->ucode_capa,
4087 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4090 mutex_lock(&mvm->mutex);
4092 if (iwl_mvm_firmware_running(mvm)) {
4093 ret = iwl_mvm_request_statistics(mvm, false);
4098 survey->filled = SURVEY_INFO_TIME |
4099 SURVEY_INFO_TIME_RX |
4100 SURVEY_INFO_TIME_TX |
4101 SURVEY_INFO_TIME_SCAN;
4102 survey->time = mvm->accu_radio_stats.on_time_rf +
4103 mvm->radio_stats.on_time_rf;
4104 do_div(survey->time, USEC_PER_MSEC);
4106 survey->time_rx = mvm->accu_radio_stats.rx_time +
4107 mvm->radio_stats.rx_time;
4108 do_div(survey->time_rx, USEC_PER_MSEC);
4110 survey->time_tx = mvm->accu_radio_stats.tx_time +
4111 mvm->radio_stats.tx_time;
4112 do_div(survey->time_tx, USEC_PER_MSEC);
4114 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4115 mvm->radio_stats.on_time_scan;
4116 do_div(survey->time_scan, USEC_PER_MSEC);
4120 mutex_unlock(&mvm->mutex);
4124 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4125 struct ieee80211_vif *vif,
4126 struct ieee80211_sta *sta,
4127 struct station_info *sinfo)
4129 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4130 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4131 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4133 if (mvmsta->avg_energy) {
4134 sinfo->signal_avg = mvmsta->avg_energy;
4135 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
4138 if (!fw_has_capa(&mvm->fw->ucode_capa,
4139 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4142 /* if beacon filtering isn't on mac80211 does it anyway */
4143 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4146 if (!vif->bss_conf.assoc)
4149 mutex_lock(&mvm->mutex);
4151 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4154 if (iwl_mvm_request_statistics(mvm, false))
4157 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4158 mvmvif->beacon_stats.accu_num_beacons;
4159 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX);
4160 if (mvmvif->beacon_stats.avg_signal) {
4161 /* firmware only reports a value after RXing a few beacons */
4162 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4163 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4166 mutex_unlock(&mvm->mutex);
4169 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4170 struct ieee80211_vif *vif,
4171 const struct ieee80211_event *event)
4173 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4175 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4177 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4180 struct iwl_fw_dbg_trigger_tlv *trig;
4181 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4183 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
4186 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
4187 trig_mlme = (void *)trig->data;
4188 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4189 ieee80211_vif_to_wdev(vif), trig))
4192 if (event->u.mlme.data == ASSOC_EVENT) {
4193 if (event->u.mlme.status == MLME_DENIED)
4194 CHECK_MLME_TRIGGER(stop_assoc_denied,
4195 "DENIED ASSOC: reason %d",
4196 event->u.mlme.reason);
4197 else if (event->u.mlme.status == MLME_TIMEOUT)
4198 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4200 } else if (event->u.mlme.data == AUTH_EVENT) {
4201 if (event->u.mlme.status == MLME_DENIED)
4202 CHECK_MLME_TRIGGER(stop_auth_denied,
4203 "DENIED AUTH: reason %d",
4204 event->u.mlme.reason);
4205 else if (event->u.mlme.status == MLME_TIMEOUT)
4206 CHECK_MLME_TRIGGER(stop_auth_timeout,
4208 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4209 CHECK_MLME_TRIGGER(stop_rx_deauth,
4210 "DEAUTH RX %d", event->u.mlme.reason);
4211 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4212 CHECK_MLME_TRIGGER(stop_tx_deauth,
4213 "DEAUTH TX %d", event->u.mlme.reason);
4215 #undef CHECK_MLME_TRIGGER
4218 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4219 struct ieee80211_vif *vif,
4220 const struct ieee80211_event *event)
4222 struct iwl_fw_dbg_trigger_tlv *trig;
4223 struct iwl_fw_dbg_trigger_ba *ba_trig;
4225 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
4228 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
4229 ba_trig = (void *)trig->data;
4230 if (!iwl_fw_dbg_trigger_check_stop(&mvm->fwrt,
4231 ieee80211_vif_to_wdev(vif), trig))
4234 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4237 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4238 "BAR received from %pM, tid %d, ssn %d",
4239 event->u.ba.sta->addr, event->u.ba.tid,
4243 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4244 struct ieee80211_vif *vif,
4245 const struct ieee80211_event *event)
4247 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4249 switch (event->type) {
4251 iwl_mvm_event_mlme_callback(mvm, vif, event);
4254 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4256 case BA_FRAME_TIMEOUT:
4257 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
4265 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4266 struct iwl_mvm_internal_rxq_notif *notif,
4269 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4272 lockdep_assert_held(&mvm->mutex);
4274 if (!iwl_mvm_has_new_rx_api(mvm))
4277 notif->cookie = mvm->queue_sync_cookie;
4280 atomic_set(&mvm->queue_sync_counter,
4281 mvm->trans->num_rx_queues);
4283 /* TODO - remove this when we have RXQ config API */
4284 if (mvm->trans->cfg->device_family == IWL_DEVICE_FAMILY_A000) {
4287 atomic_set(&mvm->queue_sync_counter, 1);
4290 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4292 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4297 ret = wait_event_timeout(mvm->rx_sync_waitq,
4298 atomic_read(&mvm->queue_sync_counter) == 0 ||
4299 iwl_mvm_is_radio_killed(mvm),
4301 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4305 atomic_set(&mvm->queue_sync_counter, 0);
4306 mvm->queue_sync_cookie++;
4309 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4311 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4312 struct iwl_mvm_internal_rxq_notif data = {
4313 .type = IWL_MVM_RXQ_EMPTY,
4317 mutex_lock(&mvm->mutex);
4318 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
4319 mutex_unlock(&mvm->mutex);
4322 const struct ieee80211_ops iwl_mvm_hw_ops = {
4323 .tx = iwl_mvm_mac_tx,
4324 .ampdu_action = iwl_mvm_mac_ampdu_action,
4325 .start = iwl_mvm_mac_start,
4326 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
4327 .stop = iwl_mvm_mac_stop,
4328 .add_interface = iwl_mvm_mac_add_interface,
4329 .remove_interface = iwl_mvm_mac_remove_interface,
4330 .config = iwl_mvm_mac_config,
4331 .prepare_multicast = iwl_mvm_prepare_multicast,
4332 .configure_filter = iwl_mvm_configure_filter,
4333 .config_iface_filter = iwl_mvm_config_iface_filter,
4334 .bss_info_changed = iwl_mvm_bss_info_changed,
4335 .hw_scan = iwl_mvm_mac_hw_scan,
4336 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
4337 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
4338 .sta_state = iwl_mvm_mac_sta_state,
4339 .sta_notify = iwl_mvm_mac_sta_notify,
4340 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
4341 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
4342 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
4343 .sta_rc_update = iwl_mvm_sta_rc_update,
4344 .conf_tx = iwl_mvm_mac_conf_tx,
4345 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
4346 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
4347 .flush = iwl_mvm_mac_flush,
4348 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4349 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
4350 .set_key = iwl_mvm_mac_set_key,
4351 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4352 .remain_on_channel = iwl_mvm_roc,
4353 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
4354 .add_chanctx = iwl_mvm_add_chanctx,
4355 .remove_chanctx = iwl_mvm_remove_chanctx,
4356 .change_chanctx = iwl_mvm_change_chanctx,
4357 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4358 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
4359 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
4361 .start_ap = iwl_mvm_start_ap_ibss,
4362 .stop_ap = iwl_mvm_stop_ap_ibss,
4363 .join_ibss = iwl_mvm_start_ap_ibss,
4364 .leave_ibss = iwl_mvm_stop_ap_ibss,
4366 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4368 .set_tim = iwl_mvm_set_tim,
4370 .channel_switch = iwl_mvm_channel_switch,
4371 .pre_channel_switch = iwl_mvm_pre_channel_switch,
4372 .post_channel_switch = iwl_mvm_post_channel_switch,
4374 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4375 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4376 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4378 .event_callback = iwl_mvm_mac_event_callback,
4380 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4382 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4384 #ifdef CONFIG_PM_SLEEP
4386 .suspend = iwl_mvm_suspend,
4387 .resume = iwl_mvm_resume,
4388 .set_wakeup = iwl_mvm_set_wakeup,
4389 .set_rekey_data = iwl_mvm_set_rekey_data,
4390 #if IS_ENABLED(CONFIG_IPV6)
4391 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4393 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4395 .get_survey = iwl_mvm_mac_get_survey,
4396 .sta_statistics = iwl_mvm_mac_sta_statistics,