1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11 * Copyright(c) 2018 Intel Corporation
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of version 2 of the GNU General Public License as
15 * published by the Free Software Foundation.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * The full GNU General Public License is included in this distribution
23 * in the file called COPYING.
25 * Contact Information:
27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34 * Copyright(c) 2018 Intel Corporation
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
41 * * Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * * Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in
45 * the documentation and/or other materials provided with the
47 * * Neither the name Intel Corporation nor the names of its
48 * contributors may be used to endorse or promote products derived
49 * from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *****************************************************************************/
64 #include <linux/kernel.h>
65 #include <linux/slab.h>
66 #include <linux/skbuff.h>
67 #include <linux/netdevice.h>
68 #include <linux/etherdevice.h>
70 #include <linux/if_arp.h>
71 #include <linux/time.h>
72 #include <net/mac80211.h>
73 #include <net/ieee80211_radiotap.h>
76 #include "iwl-op-mode.h"
80 #include "time-event.h"
81 #include "iwl-eeprom-parse.h"
82 #include "iwl-phy-db.h"
84 #include "fw/error-dump.h"
86 #include "iwl-nvm-parse.h"
88 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
91 .types = BIT(NL80211_IFTYPE_STATION),
95 .types = BIT(NL80211_IFTYPE_AP) |
96 BIT(NL80211_IFTYPE_P2P_CLIENT) |
97 BIT(NL80211_IFTYPE_P2P_GO),
101 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
105 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
107 .num_different_channels = 2,
109 .limits = iwl_mvm_limits,
110 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
114 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
116 * Use the reserved field to indicate magic values.
117 * these values will only be used internally by the driver,
118 * and won't make it to the fw (reserved will be 0).
119 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
120 * be the vif's ip address. in case there is not a single
121 * ip address (0, or more than 1), this attribute will
123 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
124 * the LSB bytes of the vif's mac address
127 BC_FILTER_MAGIC_NONE = 0,
132 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
136 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
139 /* frame type - arp, hw type - ethernet */
141 BCAST_FILTER_OFFSET_PAYLOAD_START,
142 .offset = sizeof(rfc1042_header),
143 .val = cpu_to_be32(0x08060001),
144 .mask = cpu_to_be32(0xffffffff),
149 BCAST_FILTER_OFFSET_PAYLOAD_START,
150 .offset = sizeof(rfc1042_header) + 2 +
151 sizeof(struct arphdr) +
152 ETH_ALEN + sizeof(__be32) +
154 .mask = cpu_to_be32(0xffffffff),
155 /* mark it as special field */
156 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
161 /* dhcp offer bcast */
163 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
166 /* udp dest port - 68 (bootp client)*/
167 .offset_type = BCAST_FILTER_OFFSET_IP_END,
168 .offset = offsetof(struct udphdr, dest),
169 .val = cpu_to_be32(0x00440000),
170 .mask = cpu_to_be32(0xffff0000),
173 /* dhcp - lsb bytes of client hw address */
174 .offset_type = BCAST_FILTER_OFFSET_IP_END,
176 .mask = cpu_to_be32(0xffffffff),
177 /* mark it as special field */
178 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
182 /* last filter must be empty */
187 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
189 if (!iwl_mvm_is_d0i3_supported(mvm))
192 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
193 spin_lock_bh(&mvm->refs_lock);
194 mvm->refs[ref_type]++;
195 spin_unlock_bh(&mvm->refs_lock);
196 iwl_trans_ref(mvm->trans);
199 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
201 if (!iwl_mvm_is_d0i3_supported(mvm))
204 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
205 spin_lock_bh(&mvm->refs_lock);
206 if (WARN_ON(!mvm->refs[ref_type])) {
207 spin_unlock_bh(&mvm->refs_lock);
210 mvm->refs[ref_type]--;
211 spin_unlock_bh(&mvm->refs_lock);
212 iwl_trans_unref(mvm->trans);
215 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
216 enum iwl_mvm_ref_type except_ref)
220 if (!iwl_mvm_is_d0i3_supported(mvm))
223 spin_lock_bh(&mvm->refs_lock);
224 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
225 if (except_ref == i || !mvm->refs[i])
228 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
230 for (j = 0; j < mvm->refs[i]; j++)
231 iwl_trans_unref(mvm->trans);
234 spin_unlock_bh(&mvm->refs_lock);
237 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
242 if (!iwl_mvm_is_d0i3_supported(mvm))
245 spin_lock_bh(&mvm->refs_lock);
246 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
252 spin_unlock_bh(&mvm->refs_lock);
257 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
259 iwl_mvm_ref(mvm, ref_type);
261 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
262 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
265 iwl_mvm_unref(mvm, ref_type);
272 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
276 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
277 for (i = 0; i < NUM_PHY_CTX; i++) {
278 mvm->phy_ctxts[i].id = i;
279 mvm->phy_ctxts[i].ref = 0;
283 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
285 enum iwl_mcc_source src_id,
288 struct ieee80211_regdomain *regd = NULL;
289 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
290 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
291 struct iwl_mcc_update_resp *resp;
293 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
295 lockdep_assert_held(&mvm->mutex);
297 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
298 if (IS_ERR_OR_NULL(resp)) {
299 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
300 PTR_ERR_OR_ZERO(resp));
305 u32 status = le32_to_cpu(resp->status);
307 *changed = (status == MCC_RESP_NEW_CHAN_PROFILE ||
308 status == MCC_RESP_ILLEGAL);
311 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
312 __le32_to_cpu(resp->n_channels),
314 __le16_to_cpu(resp->mcc),
315 __le16_to_cpu(resp->geo_info));
316 /* Store the return source id */
317 src_id = resp->source_id;
319 if (IS_ERR_OR_NULL(regd)) {
320 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
321 PTR_ERR_OR_ZERO(regd));
325 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
326 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
327 mvm->lar_regdom_set = true;
328 mvm->mcc_src = src_id;
334 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
337 struct ieee80211_regdomain *regd;
339 if (!iwl_mvm_is_lar_supported(mvm))
342 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
343 if (!IS_ERR_OR_NULL(regd)) {
344 /* only update the regulatory core if changed */
346 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
352 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
355 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
356 iwl_mvm_is_wifi_mcc_supported(mvm) ?
357 MCC_SOURCE_GET_CURRENT :
358 MCC_SOURCE_OLD_FW, changed);
361 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
363 enum iwl_mcc_source used_src;
364 struct ieee80211_regdomain *regd;
367 const struct ieee80211_regdomain *r =
368 rtnl_dereference(mvm->hw->wiphy->regd);
373 /* save the last source in case we overwrite it below */
374 used_src = mvm->mcc_src;
375 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
376 /* Notify the firmware we support wifi location updates */
377 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
378 if (!IS_ERR_OR_NULL(regd))
382 /* Now set our last stored MCC and source */
383 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
385 if (IS_ERR_OR_NULL(regd))
388 /* update cfg80211 if the regdomain was changed */
390 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
398 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
400 struct ieee80211_hw *hw = mvm->hw;
402 static const u32 mvm_ciphers[] = {
403 WLAN_CIPHER_SUITE_WEP40,
404 WLAN_CIPHER_SUITE_WEP104,
405 WLAN_CIPHER_SUITE_TKIP,
406 WLAN_CIPHER_SUITE_CCMP,
409 /* Tell mac80211 our characteristics */
410 ieee80211_hw_set(hw, SIGNAL_DBM);
411 ieee80211_hw_set(hw, SPECTRUM_MGMT);
412 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
413 ieee80211_hw_set(hw, QUEUE_CONTROL);
414 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
415 ieee80211_hw_set(hw, SUPPORTS_PS);
416 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
417 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
418 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
419 ieee80211_hw_set(hw, CONNECTION_MONITOR);
420 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
421 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
422 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
423 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
424 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
425 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
427 if (iwl_mvm_has_tlc_offload(mvm)) {
428 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
429 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
432 if (iwl_mvm_has_new_rx_api(mvm))
433 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
435 if (fw_has_capa(&mvm->fw->ucode_capa,
436 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
437 ieee80211_hw_set(hw, AP_LINK_PS);
438 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
440 * we absolutely need this for the new TX API since that comes
441 * with many more queues than the current code can deal with
442 * for station powersave
447 if (mvm->trans->num_rx_queues > 1)
448 ieee80211_hw_set(hw, USES_RSS);
450 if (mvm->trans->max_skb_frags)
451 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
453 hw->queues = IEEE80211_MAX_QUEUES;
454 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
455 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
456 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
457 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
458 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
460 hw->radiotap_timestamp.units_pos =
461 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
462 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
463 /* this is the case for CCK frames, it's better (only 8) for OFDM */
464 hw->radiotap_timestamp.accuracy = 22;
466 if (!iwl_mvm_has_tlc_offload(mvm))
467 hw->rate_control_algorithm = RS_NAME;
469 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
470 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
472 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
473 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
474 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
475 hw->wiphy->cipher_suites = mvm->ciphers;
477 if (iwl_mvm_has_new_rx_api(mvm)) {
478 mvm->ciphers[hw->wiphy->n_cipher_suites] =
479 WLAN_CIPHER_SUITE_GCMP;
480 hw->wiphy->n_cipher_suites++;
481 mvm->ciphers[hw->wiphy->n_cipher_suites] =
482 WLAN_CIPHER_SUITE_GCMP_256;
483 hw->wiphy->n_cipher_suites++;
486 /* Enable 11w if software crypto is not enabled (as the
487 * firmware will interpret some mgmt packets, so enabling it
488 * with software crypto isn't safe).
490 if (!iwlwifi_mod_params.swcrypto) {
491 ieee80211_hw_set(hw, MFP_CAPABLE);
492 mvm->ciphers[hw->wiphy->n_cipher_suites] =
493 WLAN_CIPHER_SUITE_AES_CMAC;
494 hw->wiphy->n_cipher_suites++;
495 if (iwl_mvm_has_new_rx_api(mvm)) {
496 mvm->ciphers[hw->wiphy->n_cipher_suites] =
497 WLAN_CIPHER_SUITE_BIP_GMAC_128;
498 hw->wiphy->n_cipher_suites++;
499 mvm->ciphers[hw->wiphy->n_cipher_suites] =
500 WLAN_CIPHER_SUITE_BIP_GMAC_256;
501 hw->wiphy->n_cipher_suites++;
505 /* currently FW API supports only one optional cipher scheme */
506 if (mvm->fw->cs[0].cipher) {
507 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
508 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
510 mvm->hw->n_cipher_schemes = 1;
512 cs->cipher = le32_to_cpu(fwcs->cipher);
513 cs->iftype = BIT(NL80211_IFTYPE_STATION);
514 cs->hdr_len = fwcs->hdr_len;
515 cs->pn_len = fwcs->pn_len;
516 cs->pn_off = fwcs->pn_off;
517 cs->key_idx_off = fwcs->key_idx_off;
518 cs->key_idx_mask = fwcs->key_idx_mask;
519 cs->key_idx_shift = fwcs->key_idx_shift;
520 cs->mic_len = fwcs->mic_len;
522 mvm->hw->cipher_schemes = mvm->cs;
523 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
524 hw->wiphy->n_cipher_suites++;
527 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
528 hw->wiphy->features |=
529 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
530 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
531 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
533 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
534 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
535 hw->chanctx_data_size = sizeof(u16);
537 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
538 BIT(NL80211_IFTYPE_P2P_CLIENT) |
539 BIT(NL80211_IFTYPE_AP) |
540 BIT(NL80211_IFTYPE_P2P_GO) |
541 BIT(NL80211_IFTYPE_P2P_DEVICE) |
542 BIT(NL80211_IFTYPE_ADHOC);
544 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
545 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
546 if (iwl_mvm_is_lar_supported(mvm))
547 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
549 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
550 REGULATORY_DISABLE_BEACON_HINTS;
552 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
553 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
555 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
556 hw->wiphy->n_iface_combinations =
557 ARRAY_SIZE(iwl_mvm_iface_combinations);
559 hw->wiphy->max_remain_on_channel_duration = 10000;
560 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
562 /* Extract MAC address */
563 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
564 hw->wiphy->addresses = mvm->addresses;
565 hw->wiphy->n_addresses = 1;
567 /* Extract additional MAC addresses if available */
568 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
569 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
571 for (i = 1; i < num_mac; i++) {
572 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
574 mvm->addresses[i].addr[5]++;
575 hw->wiphy->n_addresses++;
578 iwl_mvm_reset_phy_ctxts(mvm);
580 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
582 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
584 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
585 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
586 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
588 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
589 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
591 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
593 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
594 hw->wiphy->bands[NL80211_BAND_2GHZ] =
595 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
596 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
597 hw->wiphy->bands[NL80211_BAND_5GHZ] =
598 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
600 if (fw_has_capa(&mvm->fw->ucode_capa,
601 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
602 fw_has_api(&mvm->fw->ucode_capa,
603 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
604 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
605 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
608 hw->wiphy->hw_version = mvm->trans->hw_id;
610 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
611 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
613 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
615 hw->wiphy->max_sched_scan_reqs = 1;
616 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
617 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
618 /* we create the 802.11 header and zero length SSID IE. */
619 hw->wiphy->max_sched_scan_ie_len =
620 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
621 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
622 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
625 * the firmware uses u8 for num of iterations, but 0xff is saved for
626 * infinite loop, so the maximum number of iterations is actually 254.
628 hw->wiphy->max_sched_scan_plan_iterations = 254;
630 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
631 NL80211_FEATURE_LOW_PRIORITY_SCAN |
632 NL80211_FEATURE_P2P_GO_OPPPS |
633 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
634 NL80211_FEATURE_DYNAMIC_SMPS |
635 NL80211_FEATURE_STATIC_SMPS |
636 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
638 if (fw_has_capa(&mvm->fw->ucode_capa,
639 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
640 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
641 if (fw_has_capa(&mvm->fw->ucode_capa,
642 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
643 hw->wiphy->features |= NL80211_FEATURE_QUIET;
645 if (fw_has_capa(&mvm->fw->ucode_capa,
646 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
647 hw->wiphy->features |=
648 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
650 if (fw_has_capa(&mvm->fw->ucode_capa,
651 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
652 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
654 if (fw_has_api(&mvm->fw->ucode_capa,
655 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
656 wiphy_ext_feature_set(hw->wiphy,
657 NL80211_EXT_FEATURE_SCAN_START_TIME);
658 wiphy_ext_feature_set(hw->wiphy,
659 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
660 wiphy_ext_feature_set(hw->wiphy,
661 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
664 if (iwl_mvm_is_oce_supported(mvm)) {
665 wiphy_ext_feature_set(hw->wiphy,
666 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
667 wiphy_ext_feature_set(hw->wiphy,
668 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
669 wiphy_ext_feature_set(hw->wiphy,
670 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
671 wiphy_ext_feature_set(hw->wiphy,
672 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
675 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
677 #ifdef CONFIG_PM_SLEEP
678 if (iwl_mvm_is_d0i3_supported(mvm) &&
679 device_can_wakeup(mvm->trans->dev)) {
680 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
681 hw->wiphy->wowlan = &mvm->wowlan;
684 if (mvm->fw->img[IWL_UCODE_WOWLAN].num_sec &&
685 mvm->trans->ops->d3_suspend &&
686 mvm->trans->ops->d3_resume &&
687 device_can_wakeup(mvm->trans->dev)) {
688 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
689 WIPHY_WOWLAN_DISCONNECT |
690 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
691 WIPHY_WOWLAN_RFKILL_RELEASE |
692 WIPHY_WOWLAN_NET_DETECT;
693 if (!iwlwifi_mod_params.swcrypto)
694 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
695 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
696 WIPHY_WOWLAN_4WAY_HANDSHAKE;
698 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
699 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
700 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
701 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
702 hw->wiphy->wowlan = &mvm->wowlan;
706 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
707 /* assign default bcast filtering configuration */
708 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
711 ret = iwl_mvm_leds_init(mvm);
715 if (fw_has_capa(&mvm->fw->ucode_capa,
716 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
717 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
718 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
719 ieee80211_hw_set(hw, TDLS_WIDER_BW);
722 if (fw_has_capa(&mvm->fw->ucode_capa,
723 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
724 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
725 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
728 hw->netdev_features |= mvm->cfg->features;
729 if (!iwl_mvm_is_csum_supported(mvm)) {
730 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
732 /* We may support SW TX CSUM */
733 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
734 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
737 ret = ieee80211_register_hw(mvm->hw);
739 iwl_mvm_leds_exit(mvm);
740 mvm->init_status |= IWL_MVM_INIT_STATUS_REG_HW_INIT_COMPLETE;
742 if (mvm->cfg->vht_mu_mimo_supported)
743 wiphy_ext_feature_set(hw->wiphy,
744 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
749 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
750 struct ieee80211_sta *sta,
753 struct iwl_mvm_sta *mvmsta;
757 * double check the IN_D0I3 flag both before and after
758 * taking the spinlock, in order to prevent taking
759 * the spinlock when not needed.
761 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
764 spin_lock(&mvm->d0i3_tx_lock);
766 * testing the flag again ensures the skb dequeue
767 * loop (on d0i3 exit) hasn't run yet.
769 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
772 mvmsta = iwl_mvm_sta_from_mac80211(sta);
773 if (mvmsta->sta_id == IWL_MVM_INVALID_STA ||
774 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
777 __skb_queue_tail(&mvm->d0i3_tx, skb);
778 ieee80211_stop_queues(mvm->hw);
781 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
782 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
786 spin_unlock(&mvm->d0i3_tx_lock);
790 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
791 struct ieee80211_tx_control *control,
794 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
795 struct ieee80211_sta *sta = control->sta;
796 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
797 struct ieee80211_hdr *hdr = (void *)skb->data;
799 if (iwl_mvm_is_radio_killed(mvm)) {
800 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
804 if (info->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
805 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
806 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
809 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
810 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
811 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
812 ieee80211_is_mgmt(hdr->frame_control) &&
813 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
817 if (iwl_mvm_defer_tx(mvm, sta, skb))
819 if (iwl_mvm_tx_skb(mvm, skb, sta))
824 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
828 ieee80211_free_txskb(hw, skb);
831 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
833 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
838 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
840 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
842 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
845 /* enabled by default */
849 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
851 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
853 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
857 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
858 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
859 enum ieee80211_ampdu_mlme_action action)
861 struct iwl_fw_dbg_trigger_tlv *trig;
862 struct iwl_fw_dbg_trigger_ba *ba_trig;
864 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
869 ba_trig = (void *)trig->data;
872 case IEEE80211_AMPDU_TX_OPERATIONAL: {
873 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
874 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
876 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
877 "TX AGG START: MAC %pM tid %d ssn %d\n",
878 sta->addr, tid, tid_data->ssn);
881 case IEEE80211_AMPDU_TX_STOP_CONT:
882 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
883 "TX AGG STOP: MAC %pM tid %d\n",
886 case IEEE80211_AMPDU_RX_START:
887 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
888 "RX AGG START: MAC %pM tid %d ssn %d\n",
889 sta->addr, tid, rx_ba_ssn);
891 case IEEE80211_AMPDU_RX_STOP:
892 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
893 "RX AGG STOP: MAC %pM tid %d\n",
901 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
902 struct ieee80211_vif *vif,
903 struct ieee80211_ampdu_params *params)
905 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
907 bool tx_agg_ref = false;
908 struct ieee80211_sta *sta = params->sta;
909 enum ieee80211_ampdu_mlme_action action = params->action;
910 u16 tid = params->tid;
911 u16 *ssn = ¶ms->ssn;
912 u16 buf_size = params->buf_size;
913 bool amsdu = params->amsdu;
914 u16 timeout = params->timeout;
916 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
917 sta->addr, tid, action);
919 if (!(mvm->nvm_data->sku_cap_11n_enable))
922 /* return from D0i3 before starting a new Tx aggregation */
924 case IEEE80211_AMPDU_TX_START:
925 case IEEE80211_AMPDU_TX_STOP_CONT:
926 case IEEE80211_AMPDU_TX_STOP_FLUSH:
927 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
928 case IEEE80211_AMPDU_TX_OPERATIONAL:
930 * for tx start, wait synchronously until D0i3 exit to
931 * get the correct sequence number for the tid.
932 * additionally, some other ampdu actions use direct
933 * target access, which is not handled automatically
934 * by the trans layer (unlike commands), so wait for
935 * d0i3 exit in these cases as well.
937 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
947 mutex_lock(&mvm->mutex);
950 case IEEE80211_AMPDU_RX_START:
951 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
952 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
953 struct iwl_mvm_vif *mvmvif;
954 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
955 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
957 mdata->opened_rx_ba_sessions = true;
958 mvmvif = iwl_mvm_vif_from_mac80211(vif);
959 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
961 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
965 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
968 case IEEE80211_AMPDU_RX_STOP:
969 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
972 case IEEE80211_AMPDU_TX_START:
973 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
977 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
979 case IEEE80211_AMPDU_TX_STOP_CONT:
980 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
982 case IEEE80211_AMPDU_TX_STOP_FLUSH:
983 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
984 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
986 case IEEE80211_AMPDU_TX_OPERATIONAL:
987 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
999 if (action == IEEE80211_AMPDU_RX_START)
1002 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1005 mutex_unlock(&mvm->mutex);
1008 * If the tid is marked as started, we won't use it for offloaded
1009 * traffic on the next D0i3 entry. It's safe to unref.
1012 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1017 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1018 struct ieee80211_vif *vif)
1020 struct iwl_mvm *mvm = data;
1021 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1023 mvmvif->uploaded = false;
1024 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1026 spin_lock_bh(&mvm->time_event_lock);
1027 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1028 spin_unlock_bh(&mvm->time_event_lock);
1030 mvmvif->phy_ctxt = NULL;
1031 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1032 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
1035 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1037 /* clear the D3 reconfig, we only need it to avoid dumping a
1038 * firmware coredump on reconfiguration, we shouldn't do that
1039 * on D3->D0 transition
1041 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1042 mvm->fwrt.dump.desc = &iwl_dump_desc_assert;
1043 iwl_fw_error_dump(&mvm->fwrt);
1046 /* cleanup all stale references (scan, roc), but keep the
1047 * ucode_down ref until reconfig is complete
1049 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1051 iwl_mvm_stop_device(mvm);
1053 mvm->scan_status = 0;
1054 mvm->ps_disabled = false;
1055 mvm->calibrating = false;
1057 /* just in case one was running */
1058 iwl_mvm_cleanup_roc_te(mvm);
1059 ieee80211_remain_on_channel_expired(mvm->hw);
1062 * cleanup all interfaces, even inactive ones, as some might have
1063 * gone down during the HW restart
1065 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1067 mvm->p2p_device_vif = NULL;
1068 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
1070 iwl_mvm_reset_phy_ctxts(mvm);
1071 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1072 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
1073 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1074 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1076 ieee80211_wake_queues(mvm->hw);
1078 /* clear any stale d0i3 state */
1079 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1082 mvm->rx_ba_sessions = 0;
1083 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1084 mvm->monitor_on = false;
1086 /* keep statistics ticking */
1087 iwl_mvm_accu_radio_stats(mvm);
1090 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1094 lockdep_assert_held(&mvm->mutex);
1096 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1098 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1099 * so later code will - from now on - see that we're doing it.
1101 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1102 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1103 /* Clean up some internal and mac80211 state on restart */
1104 iwl_mvm_restart_cleanup(mvm);
1106 /* Hold the reference to prevent runtime suspend while
1107 * the start procedure runs. It's a bit confusing
1108 * that the UCODE_DOWN reference is taken, but it just
1109 * means "UCODE is not UP yet". ( TODO: rename this
1112 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1114 ret = iwl_mvm_up(mvm);
1116 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1117 /* Something went wrong - we need to finish some cleanup
1118 * that normally iwl_mvm_mac_restart_complete() below
1121 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1123 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1130 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1132 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1135 /* Some hw restart cleanups must not hold the mutex */
1136 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1138 * Make sure we are out of d0i3. This is needed
1139 * to make sure the reference accounting is correct
1140 * (and there is no stale d0i3_exit_work).
1142 wait_event_timeout(mvm->d0i3_exit_waitq,
1143 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1148 mutex_lock(&mvm->mutex);
1149 ret = __iwl_mvm_mac_start(mvm);
1150 mutex_unlock(&mvm->mutex);
1155 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1159 mutex_lock(&mvm->mutex);
1161 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1163 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1165 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1167 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1170 /* allow transport/FW low power modes */
1171 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1174 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1175 * of packets the FW sent out, so we must reconnect.
1177 iwl_mvm_teardown_tdls_peers(mvm);
1179 mutex_unlock(&mvm->mutex);
1182 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1184 if (iwl_mvm_is_d0i3_supported(mvm) &&
1185 iwl_mvm_enter_d0i3_on_suspend(mvm))
1186 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1187 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1190 "D0i3 exit on resume timed out\n");
1194 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1195 enum ieee80211_reconfig_type reconfig_type)
1197 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1199 switch (reconfig_type) {
1200 case IEEE80211_RECONFIG_TYPE_RESTART:
1201 iwl_mvm_restart_complete(mvm);
1203 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1204 iwl_mvm_resume_complete(mvm);
1209 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1211 lockdep_assert_held(&mvm->mutex);
1213 /* firmware counters are obviously reset now, but we shouldn't
1214 * partially track so also clear the fw_reset_accu counters.
1216 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1218 /* async_handlers_wk is now blocked */
1221 * The work item could be running or queued if the
1222 * ROC time event stops just as we get here.
1224 flush_work(&mvm->roc_done_wk);
1226 iwl_mvm_stop_device(mvm);
1228 iwl_mvm_async_handlers_purge(mvm);
1229 /* async_handlers_list is empty and will stay empty: HW is stopped */
1231 /* the fw is stopped, the aux sta is dead: clean up driver state */
1232 iwl_mvm_del_aux_sta(mvm);
1235 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1236 * hw (as restart_complete() won't be called in this case) and mac80211
1237 * won't execute the restart.
1238 * But make sure to cleanup interfaces that have gone down before/during
1239 * HW restart was requested.
1241 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1242 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1244 ieee80211_iterate_interfaces(mvm->hw, 0,
1245 iwl_mvm_cleanup_iterator, mvm);
1247 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1248 * make sure there's nothing left there and warn if any is found.
1250 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1253 for (i = 0; i < mvm->max_scans; i++) {
1254 if (WARN_ONCE(mvm->scan_uid_status[i],
1255 "UMAC scan UID %d status was not cleaned\n",
1257 mvm->scan_uid_status[i] = 0;
1262 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1264 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1266 flush_work(&mvm->d0i3_exit_work);
1267 flush_work(&mvm->async_handlers_wk);
1268 flush_work(&mvm->add_stream_wk);
1271 * Lock and clear the firmware running bit here already, so that
1272 * new commands coming in elsewhere, e.g. from debugfs, will not
1273 * be able to proceed. This is important here because one of those
1274 * debugfs files causes the firmware dump to be triggered, and if we
1275 * don't stop debugfs accesses before canceling that it could be
1276 * retriggered after we flush it but before we've cleared the bit.
1278 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1280 iwl_fw_cancel_dump(&mvm->fwrt);
1281 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1282 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1283 iwl_fw_free_dump_desc(&mvm->fwrt);
1285 mutex_lock(&mvm->mutex);
1286 __iwl_mvm_mac_stop(mvm);
1287 mutex_unlock(&mvm->mutex);
1290 * The worker might have been waiting for the mutex, let it run and
1291 * discover that its list is now empty.
1293 cancel_work_sync(&mvm->async_handlers_wk);
1296 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1300 lockdep_assert_held(&mvm->mutex);
1302 for (i = 0; i < NUM_PHY_CTX; i++)
1303 if (!mvm->phy_ctxts[i].ref)
1304 return &mvm->phy_ctxts[i];
1306 IWL_ERR(mvm, "No available PHY context\n");
1310 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1315 struct iwl_dev_tx_power_cmd v5;
1316 struct iwl_dev_tx_power_cmd_v4 v4;
1318 .v5.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1319 .v5.v3.mac_context_id =
1320 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1321 .v5.v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1324 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1325 cmd.v5.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1327 if (fw_has_api(&mvm->fw->ucode_capa,
1328 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1329 len = sizeof(cmd.v5);
1330 else if (fw_has_capa(&mvm->fw->ucode_capa,
1331 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1332 len = sizeof(cmd.v4);
1334 len = sizeof(cmd.v4.v3);
1336 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1339 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1340 struct ieee80211_vif *vif)
1342 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1343 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1347 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1350 * make sure D0i3 exit is completed, otherwise a target access
1351 * during tx queue configuration could be done when still in
1354 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1359 * Not much to do here. The stack will not allow interface
1360 * types or combinations that we didn't advertise, so we
1361 * don't really have to check the types.
1364 mutex_lock(&mvm->mutex);
1366 /* make sure that beacon statistics don't go backwards with FW reset */
1367 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1368 mvmvif->beacon_stats.accu_num_beacons +=
1369 mvmvif->beacon_stats.num_beacons;
1371 /* Allocate resources for the MAC context, and add it to the fw */
1372 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1376 /* Counting number of interfaces is needed for legacy PM */
1377 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1381 * The AP binding flow can be done only after the beacon
1382 * template is configured (which happens only in the mac80211
1383 * start_ap() flow), and adding the broadcast station can happen
1384 * only after the binding.
1385 * In addition, since modifying the MAC before adding a bcast
1386 * station is not allowed by the FW, delay the adding of MAC context to
1387 * the point where we can also add the bcast station.
1388 * In short: there's not much we can do at this point, other than
1389 * allocating resources :)
1391 if (vif->type == NL80211_IFTYPE_AP ||
1392 vif->type == NL80211_IFTYPE_ADHOC) {
1393 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1395 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1400 * Only queue for this station is the mcast queue,
1401 * which shouldn't be in TFD mask anyway
1403 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1409 iwl_mvm_vif_dbgfs_register(mvm, vif);
1413 mvmvif->features |= hw->netdev_features;
1415 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1419 ret = iwl_mvm_power_update_mac(mvm);
1421 goto out_remove_mac;
1423 /* beacon filtering */
1424 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1426 goto out_remove_mac;
1428 if (!mvm->bf_allowed_vif &&
1429 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1430 mvm->bf_allowed_vif = mvmvif;
1431 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1432 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1436 * P2P_DEVICE interface does not have a channel context assigned to it,
1437 * so a dedicated PHY context is allocated to it and the corresponding
1438 * MAC context is bound to it at this stage.
1440 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1442 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1443 if (!mvmvif->phy_ctxt) {
1448 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1449 ret = iwl_mvm_binding_add_vif(mvm, vif);
1453 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1457 /* Save a pointer to p2p device vif, so it can later be used to
1458 * update the p2p device MAC when a GO is started/stopped */
1459 mvm->p2p_device_vif = vif;
1462 iwl_mvm_tcm_add_vif(mvm, vif);
1464 if (vif->type == NL80211_IFTYPE_MONITOR)
1465 mvm->monitor_on = true;
1467 iwl_mvm_vif_dbgfs_register(mvm, vif);
1471 iwl_mvm_binding_remove_vif(mvm, vif);
1473 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1475 if (mvm->bf_allowed_vif == mvmvif) {
1476 mvm->bf_allowed_vif = NULL;
1477 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1478 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1481 mvmvif->phy_ctxt = NULL;
1482 iwl_mvm_mac_ctxt_remove(mvm, vif);
1484 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1487 mutex_unlock(&mvm->mutex);
1489 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1494 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1495 struct ieee80211_vif *vif)
1497 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1499 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1500 * We assume here that all the packets sent to the OFFCHANNEL
1501 * queue are sent in ROC session.
1503 flush_work(&mvm->roc_done_wk);
1507 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1508 struct ieee80211_vif *vif)
1510 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1511 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1512 struct iwl_probe_resp_data *probe_data;
1514 iwl_mvm_prepare_mac_removal(mvm, vif);
1516 if (!(vif->type == NL80211_IFTYPE_AP ||
1517 vif->type == NL80211_IFTYPE_ADHOC))
1518 iwl_mvm_tcm_rm_vif(mvm, vif);
1520 mutex_lock(&mvm->mutex);
1522 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1523 lockdep_is_held(&mvm->mutex));
1524 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1526 kfree_rcu(probe_data, rcu_head);
1528 if (mvm->bf_allowed_vif == mvmvif) {
1529 mvm->bf_allowed_vif = NULL;
1530 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1531 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1534 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1537 * For AP/GO interface, the tear down of the resources allocated to the
1538 * interface is be handled as part of the stop_ap flow.
1540 if (vif->type == NL80211_IFTYPE_AP ||
1541 vif->type == NL80211_IFTYPE_ADHOC) {
1542 #ifdef CONFIG_NL80211_TESTMODE
1543 if (vif == mvm->noa_vif) {
1544 mvm->noa_vif = NULL;
1545 mvm->noa_duration = 0;
1548 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1549 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1553 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1554 mvm->p2p_device_vif = NULL;
1555 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1556 iwl_mvm_binding_remove_vif(mvm, vif);
1557 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1558 mvmvif->phy_ctxt = NULL;
1561 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1564 iwl_mvm_power_update_mac(mvm);
1565 iwl_mvm_mac_ctxt_remove(mvm, vif);
1567 if (vif->type == NL80211_IFTYPE_MONITOR)
1568 mvm->monitor_on = false;
1571 mutex_unlock(&mvm->mutex);
1574 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1579 struct iwl_mvm_mc_iter_data {
1580 struct iwl_mvm *mvm;
1584 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1585 struct ieee80211_vif *vif)
1587 struct iwl_mvm_mc_iter_data *data = _data;
1588 struct iwl_mvm *mvm = data->mvm;
1589 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1590 struct iwl_host_cmd hcmd = {
1591 .id = MCAST_FILTER_CMD,
1593 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1597 /* if we don't have free ports, mcast frames will be dropped */
1598 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1601 if (vif->type != NL80211_IFTYPE_STATION ||
1602 !vif->bss_conf.assoc)
1605 cmd->port_id = data->port_id++;
1606 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1607 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1612 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1614 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1617 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1619 struct iwl_mvm_mc_iter_data iter_data = {
1623 lockdep_assert_held(&mvm->mutex);
1625 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1628 ieee80211_iterate_active_interfaces_atomic(
1629 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1630 iwl_mvm_mc_iface_iterator, &iter_data);
1633 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1634 struct netdev_hw_addr_list *mc_list)
1636 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1637 struct iwl_mcast_filter_cmd *cmd;
1638 struct netdev_hw_addr *addr;
1643 addr_count = netdev_hw_addr_list_count(mc_list);
1644 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1645 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1649 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1650 cmd = kzalloc(len, GFP_ATOMIC);
1656 return (u64)(unsigned long)cmd;
1659 netdev_hw_addr_list_for_each(addr, mc_list) {
1660 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1661 cmd->count, addr->addr);
1662 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1663 addr->addr, ETH_ALEN);
1667 return (u64)(unsigned long)cmd;
1670 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1671 unsigned int changed_flags,
1672 unsigned int *total_flags,
1675 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1676 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1678 mutex_lock(&mvm->mutex);
1680 /* replace previous configuration */
1681 kfree(mvm->mcast_filter_cmd);
1682 mvm->mcast_filter_cmd = cmd;
1687 if (changed_flags & FIF_ALLMULTI)
1688 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1693 iwl_mvm_recalc_multicast(mvm);
1695 mutex_unlock(&mvm->mutex);
1699 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1700 struct ieee80211_vif *vif,
1701 unsigned int filter_flags,
1702 unsigned int changed_flags)
1704 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1706 /* We support only filter for probe requests */
1707 if (!(changed_flags & FIF_PROBE_REQ))
1710 /* Supported only for p2p client interfaces */
1711 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1715 mutex_lock(&mvm->mutex);
1716 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1717 mutex_unlock(&mvm->mutex);
1720 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1721 struct iwl_bcast_iter_data {
1722 struct iwl_mvm *mvm;
1723 struct iwl_bcast_filter_cmd *cmd;
1728 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1729 const struct iwl_fw_bcast_filter *in_filter,
1730 struct iwl_fw_bcast_filter *out_filter)
1732 struct iwl_fw_bcast_filter_attr *attr;
1735 memcpy(out_filter, in_filter, sizeof(*out_filter));
1737 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1738 attr = &out_filter->attrs[i];
1743 switch (attr->reserved1) {
1744 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1745 if (vif->bss_conf.arp_addr_cnt != 1) {
1750 attr->val = vif->bss_conf.arp_addr_list[0];
1752 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1753 attr->val = *(__be32 *)&vif->addr[2];
1758 attr->reserved1 = 0;
1759 out_filter->num_attrs++;
1763 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1764 struct ieee80211_vif *vif)
1766 struct iwl_bcast_iter_data *data = _data;
1767 struct iwl_mvm *mvm = data->mvm;
1768 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1769 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1770 struct iwl_fw_bcast_mac *bcast_mac;
1773 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1776 bcast_mac = &cmd->macs[mvmvif->id];
1779 * enable filtering only for associated stations, but not for P2P
1782 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1783 !vif->bss_conf.assoc)
1786 bcast_mac->default_discard = 1;
1788 /* copy all configured filters */
1789 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1791 * Make sure we don't exceed our filters limit.
1792 * if there is still a valid filter to be configured,
1793 * be on the safe side and just allow bcast for this mac.
1795 if (WARN_ON_ONCE(data->current_filter >=
1796 ARRAY_SIZE(cmd->filters))) {
1797 bcast_mac->default_discard = 0;
1798 bcast_mac->attached_filters = 0;
1802 iwl_mvm_set_bcast_filter(vif,
1803 &mvm->bcast_filters[i],
1804 &cmd->filters[data->current_filter]);
1806 /* skip current filter if it contains no attributes */
1807 if (!cmd->filters[data->current_filter].num_attrs)
1810 /* attach the filter to current mac */
1811 bcast_mac->attached_filters |=
1812 cpu_to_le16(BIT(data->current_filter));
1814 data->current_filter++;
1818 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1819 struct iwl_bcast_filter_cmd *cmd)
1821 struct iwl_bcast_iter_data iter_data = {
1826 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1829 memset(cmd, 0, sizeof(*cmd));
1830 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1831 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1833 #ifdef CONFIG_IWLWIFI_DEBUGFS
1834 /* use debugfs filters/macs if override is configured */
1835 if (mvm->dbgfs_bcast_filtering.override) {
1836 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1837 sizeof(cmd->filters));
1838 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1844 /* if no filters are configured, do nothing */
1845 if (!mvm->bcast_filters)
1848 /* configure and attach these filters for each associated sta vif */
1849 ieee80211_iterate_active_interfaces(
1850 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1851 iwl_mvm_bcast_filter_iterator, &iter_data);
1856 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1858 struct iwl_bcast_filter_cmd cmd;
1860 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1863 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1866 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1870 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1876 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1877 struct ieee80211_vif *vif)
1879 struct iwl_mu_group_mgmt_cmd cmd = {};
1881 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1882 WLAN_MEMBERSHIP_LEN);
1883 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1884 WLAN_USER_POSITION_LEN);
1886 return iwl_mvm_send_cmd_pdu(mvm,
1887 WIDE_ID(DATA_PATH_GROUP,
1888 UPDATE_MU_GROUPS_CMD),
1889 0, sizeof(cmd), &cmd);
1892 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1893 struct ieee80211_vif *vif)
1895 if (vif->mu_mimo_owner) {
1896 struct iwl_mu_group_mgmt_notif *notif = _data;
1899 * MU-MIMO Group Id action frame is little endian. We treat
1900 * the data received from firmware as if it came from the
1901 * action frame, so no conversion is needed.
1903 ieee80211_update_mu_groups(vif,
1904 (u8 *)¬if->membership_status,
1905 (u8 *)¬if->user_position);
1909 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1910 struct iwl_rx_cmd_buffer *rxb)
1912 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1913 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1915 ieee80211_iterate_active_interfaces_atomic(
1916 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1917 iwl_mvm_mu_mimo_iface_iterator, notif);
1920 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1922 u8 byte_num = ppe_pos_bit / 8;
1923 u8 bit_num = ppe_pos_bit % 8;
1928 return (ppe[byte_num] >> bit_num) &
1929 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1932 * If bit_num > 5, we have to combine bits with next byte.
1933 * Calculate how many bits we need to take from current byte (called
1934 * here "residue_bits"), and add them to bits from next byte.
1937 residue_bits = 8 - bit_num;
1939 res = (ppe[byte_num + 1] &
1940 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1942 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1947 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1948 struct ieee80211_vif *vif, u8 sta_id)
1950 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1951 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
1953 .tid_limit = IWL_MAX_TID_COUNT,
1954 .bss_color = vif->bss_conf.bss_color,
1955 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
1956 .frame_time_rts_th =
1957 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
1959 struct ieee80211_sta *sta;
1965 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
1968 WARN(1, "Can't find STA to configure HE\n");
1972 if (!sta->he_cap.has_he) {
1980 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
1981 IEEE80211_HE_MAC_CAP0_HTC_HE)
1982 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
1983 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
1984 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
1985 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
1986 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
1988 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
1989 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
1990 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
1991 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
1994 sta_ctxt_cmd.htc_flags |=
1995 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
1996 else if (link_adap == 3)
1997 sta_ctxt_cmd.htc_flags |=
1998 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2000 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2001 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2002 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2003 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2004 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2005 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2006 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2008 /* If PPE Thresholds exist, parse them into a FW-familiar format */
2009 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2010 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2011 u8 nss = (sta->he_cap.ppe_thres[0] &
2012 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2013 u8 ru_index_bitmap =
2014 (sta->he_cap.ppe_thres[0] &
2015 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2016 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2017 u8 *ppe = &sta->he_cap.ppe_thres[0];
2018 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2021 * FW currently supports only nss == MAX_HE_SUPP_NSS
2023 * If nss > MAX: we can ignore values we don't support
2024 * If nss < MAX: we can set zeros in other streams
2026 if (nss > MAX_HE_SUPP_NSS) {
2027 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2029 nss = MAX_HE_SUPP_NSS;
2032 for (i = 0; i < nss; i++) {
2033 u8 ru_index_tmp = ru_index_bitmap << 1;
2036 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2038 if (!(ru_index_tmp & 1))
2041 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2042 iwl_mvm_he_get_ppe_val(ppe,
2045 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2046 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2047 iwl_mvm_he_get_ppe_val(ppe,
2050 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2054 flags |= STA_CTXT_HE_PACKET_EXT;
2058 /* Mark MU EDCA as enabled, unless none detected on some AC */
2059 flags |= STA_CTXT_HE_MU_EDCA_CW;
2060 for (i = 0; i < AC_NUM; i++) {
2061 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2062 &mvmvif->queue_params[i].mu_edca_param_rec;
2064 if (!mvmvif->queue_params[i].mu_edca) {
2065 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2069 sta_ctxt_cmd.trig_based_txf[i].cwmin =
2070 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2071 sta_ctxt_cmd.trig_based_txf[i].cwmax =
2072 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2073 sta_ctxt_cmd.trig_based_txf[i].aifsn =
2074 cpu_to_le16(mu_edca->aifsn);
2075 sta_ctxt_cmd.trig_based_txf[i].mu_time =
2076 cpu_to_le16(mu_edca->mu_edca_timer);
2079 if (vif->bss_conf.multi_sta_back_32bit)
2080 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2082 if (vif->bss_conf.ack_enabled)
2083 flags |= STA_CTXT_HE_ACK_ENABLED;
2085 if (vif->bss_conf.uora_exists) {
2086 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2088 sta_ctxt_cmd.rand_alloc_ecwmin =
2089 vif->bss_conf.uora_ocw_range & 0x7;
2090 sta_ctxt_cmd.rand_alloc_ecwmax =
2091 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2094 /* TODO: support Multi BSSID IE */
2096 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2098 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2099 DATA_PATH_GROUP, 0),
2100 0, sizeof(sta_ctxt_cmd), &sta_ctxt_cmd))
2101 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2104 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2105 struct ieee80211_vif *vif,
2106 struct ieee80211_bss_conf *bss_conf,
2109 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2113 * Re-calculate the tsf id, as the master-slave relations depend on the
2114 * beacon interval, which was not known when the station interface was
2117 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2118 if (vif->bss_conf.he_support &&
2119 !iwlwifi_mod_params.disable_11ax)
2120 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2122 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2126 * If we're not associated yet, take the (new) BSSID before associating
2127 * so the firmware knows. If we're already associated, then use the old
2128 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2129 * branch for disassociation below.
2131 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2132 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2134 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2136 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2138 /* after sending it once, adopt mac80211 data */
2139 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2140 mvmvif->associated = bss_conf->assoc;
2142 if (changes & BSS_CHANGED_ASSOC) {
2143 if (bss_conf->assoc) {
2144 /* clear statistics to get clean beacon counter */
2145 iwl_mvm_request_statistics(mvm, true);
2146 memset(&mvmvif->beacon_stats, 0,
2147 sizeof(mvmvif->beacon_stats));
2149 /* add quota for this interface */
2150 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2152 IWL_ERR(mvm, "failed to update quotas\n");
2156 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2159 * If we're restarting then the firmware will
2160 * obviously have lost synchronisation with
2161 * the AP. It will attempt to synchronise by
2162 * itself, but we can make it more reliable by
2163 * scheduling a session protection time event.
2165 * The firmware needs to receive a beacon to
2166 * catch up with synchronisation, use 110% of
2167 * the beacon interval.
2169 * Set a large maximum delay to allow for more
2170 * than a single interface.
2172 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2173 iwl_mvm_protect_session(mvm, vif, dur, dur,
2177 iwl_mvm_sf_update(mvm, vif, false);
2178 iwl_mvm_power_vif_assoc(mvm, vif);
2180 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
2181 iwl_mvm_update_smps(mvm, vif,
2182 IWL_MVM_SMPS_REQ_PROT,
2183 IEEE80211_SMPS_DYNAMIC);
2185 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2187 * If update fails - SF might be running in associated
2188 * mode while disassociated - which is forbidden.
2190 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
2191 "Failed to update SF upon disassociation\n");
2194 * If we get an assert during the connection (after the
2195 * station has been added, but before the vif is set
2196 * to associated), mac80211 will re-add the station and
2197 * then configure the vif. Since the vif is not
2198 * associated, we would remove the station here and
2199 * this would fail the recovery.
2201 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2204 * Remove AP station now that
2205 * the MAC is unassoc
2207 ret = iwl_mvm_rm_sta_id(mvm, vif,
2211 "failed to remove AP station\n");
2213 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2214 mvm->d0i3_ap_sta_id =
2215 IWL_MVM_INVALID_STA;
2216 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2219 /* remove quota for this interface */
2220 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2222 IWL_ERR(mvm, "failed to update quotas\n");
2225 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2227 /* this will take the cleared BSSID from bss_conf */
2228 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2231 "failed to update MAC %pM (clear after unassoc)\n",
2236 * The firmware tracks the MU-MIMO group on its own.
2237 * However, on HW restart we should restore this data.
2239 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2240 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2241 ret = iwl_mvm_update_mu_groups(mvm, vif);
2244 "failed to update VHT MU_MIMO groups\n");
2247 iwl_mvm_recalc_multicast(mvm);
2248 iwl_mvm_configure_bcast_filter(mvm);
2250 /* reset rssi values */
2251 mvmvif->bf_data.ave_beacon_signal = 0;
2253 iwl_mvm_bt_coex_vif_change(mvm);
2254 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2255 IEEE80211_SMPS_AUTOMATIC);
2256 if (fw_has_capa(&mvm->fw->ucode_capa,
2257 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2258 iwl_mvm_config_scan(mvm);
2261 if (changes & BSS_CHANGED_BEACON_INFO) {
2263 * We received a beacon from the associated AP so
2264 * remove the session protection.
2266 iwl_mvm_stop_session_protection(mvm, vif);
2268 iwl_mvm_sf_update(mvm, vif, false);
2269 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2272 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2274 * Send power command on every beacon change,
2275 * because we may have not enabled beacon abort yet.
2277 BSS_CHANGED_BEACON_INFO)) {
2278 ret = iwl_mvm_power_update_mac(mvm);
2280 IWL_ERR(mvm, "failed to update power mode\n");
2283 if (changes & BSS_CHANGED_TXPOWER) {
2284 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2286 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2289 if (changes & BSS_CHANGED_CQM) {
2290 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2291 /* reset cqm events tracking */
2292 mvmvif->bf_data.last_cqm_event = 0;
2293 if (mvmvif->bf_data.bf_enabled) {
2294 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2297 "failed to update CQM thresholds\n");
2301 if (changes & BSS_CHANGED_ARP_FILTER) {
2302 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2303 iwl_mvm_configure_bcast_filter(mvm);
2307 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2308 struct ieee80211_vif *vif)
2310 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2311 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2315 * iwl_mvm_mac_ctxt_add() might read directly from the device
2316 * (the system time), so make sure it is available.
2318 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2322 mutex_lock(&mvm->mutex);
2324 /* Send the beacon template */
2325 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2330 * Re-calculate the tsf id, as the master-slave relations depend on the
2331 * beacon interval, which was not known when the AP interface was added.
2333 if (vif->type == NL80211_IFTYPE_AP)
2334 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2336 mvmvif->ap_assoc_sta_count = 0;
2338 /* Add the mac context */
2339 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2343 /* Perform the binding */
2344 ret = iwl_mvm_binding_add_vif(mvm, vif);
2349 * This is not very nice, but the simplest:
2350 * For older FWs adding the mcast sta before the bcast station may
2351 * cause assert 0x2b00.
2352 * This is fixed in later FW so make the order of removal depend on
2355 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2356 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2360 * Send the bcast station. At this stage the TBTT and DTIM time
2361 * events are added and applied to the scheduler
2363 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2365 iwl_mvm_rm_mcast_sta(mvm, vif);
2370 * Send the bcast station. At this stage the TBTT and DTIM time
2371 * events are added and applied to the scheduler
2373 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2376 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2378 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2383 /* must be set before quota calculations */
2384 mvmvif->ap_ibss_active = true;
2386 /* power updated needs to be done before quotas */
2387 iwl_mvm_power_update_mac(mvm);
2389 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2391 goto out_quota_failed;
2393 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2394 if (vif->p2p && mvm->p2p_device_vif)
2395 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2397 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2399 iwl_mvm_bt_coex_vif_change(mvm);
2401 /* we don't support TDLS during DCM */
2402 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2403 iwl_mvm_teardown_tdls_peers(mvm);
2408 iwl_mvm_power_update_mac(mvm);
2409 mvmvif->ap_ibss_active = false;
2410 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2411 iwl_mvm_rm_mcast_sta(mvm, vif);
2413 iwl_mvm_binding_remove_vif(mvm, vif);
2415 iwl_mvm_mac_ctxt_remove(mvm, vif);
2417 mutex_unlock(&mvm->mutex);
2418 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2422 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2423 struct ieee80211_vif *vif)
2425 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2426 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2428 iwl_mvm_prepare_mac_removal(mvm, vif);
2430 mutex_lock(&mvm->mutex);
2432 /* Handle AP stop while in CSA */
2433 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2434 iwl_mvm_remove_time_event(mvm, mvmvif,
2435 &mvmvif->time_event_data);
2436 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2437 mvmvif->csa_countdown = false;
2440 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2441 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2442 mvm->csa_tx_block_bcn_timeout = 0;
2445 mvmvif->ap_ibss_active = false;
2446 mvm->ap_last_beacon_gp2 = 0;
2448 iwl_mvm_bt_coex_vif_change(mvm);
2450 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2452 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2453 if (vif->p2p && mvm->p2p_device_vif)
2454 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2456 iwl_mvm_update_quotas(mvm, false, NULL);
2459 * This is not very nice, but the simplest:
2460 * For older FWs removing the mcast sta before the bcast station may
2461 * cause assert 0x2b00.
2462 * This is fixed in later FW (which will stop beaconing when removing
2464 * So make the order of removal depend on the TLV
2466 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2467 iwl_mvm_rm_mcast_sta(mvm, vif);
2468 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2469 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2470 iwl_mvm_rm_mcast_sta(mvm, vif);
2471 iwl_mvm_binding_remove_vif(mvm, vif);
2473 iwl_mvm_power_update_mac(mvm);
2475 iwl_mvm_mac_ctxt_remove(mvm, vif);
2477 kfree(mvmvif->ap_wep_key);
2478 mvmvif->ap_wep_key = NULL;
2480 mutex_unlock(&mvm->mutex);
2484 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2485 struct ieee80211_vif *vif,
2486 struct ieee80211_bss_conf *bss_conf,
2489 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2491 /* Changes will be applied when the AP/IBSS is started */
2492 if (!mvmvif->ap_ibss_active)
2495 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2496 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2497 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2498 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2500 /* Need to send a new beacon template to the FW */
2501 if (changes & BSS_CHANGED_BEACON &&
2502 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2503 IWL_WARN(mvm, "Failed updating beacon data\n");
2505 if (changes & BSS_CHANGED_TXPOWER) {
2506 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2508 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2512 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2513 struct ieee80211_vif *vif,
2514 struct ieee80211_bss_conf *bss_conf,
2517 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2520 * iwl_mvm_bss_info_changed_station() might call
2521 * iwl_mvm_protect_session(), which reads directly from
2522 * the device (the system time), so make sure it is available.
2524 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2527 mutex_lock(&mvm->mutex);
2529 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2530 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2532 switch (vif->type) {
2533 case NL80211_IFTYPE_STATION:
2534 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2536 case NL80211_IFTYPE_AP:
2537 case NL80211_IFTYPE_ADHOC:
2538 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2540 case NL80211_IFTYPE_MONITOR:
2541 if (changes & BSS_CHANGED_MU_GROUPS)
2542 iwl_mvm_update_mu_groups(mvm, vif);
2545 /* shouldn't happen */
2549 mutex_unlock(&mvm->mutex);
2550 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2553 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2554 struct ieee80211_vif *vif,
2555 struct ieee80211_scan_request *hw_req)
2557 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2560 if (hw_req->req.n_channels == 0 ||
2561 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2564 mutex_lock(&mvm->mutex);
2565 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2566 mutex_unlock(&mvm->mutex);
2571 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2572 struct ieee80211_vif *vif)
2574 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2576 mutex_lock(&mvm->mutex);
2578 /* Due to a race condition, it's possible that mac80211 asks
2579 * us to stop a hw_scan when it's already stopped. This can
2580 * happen, for instance, if we stopped the scan ourselves,
2581 * called ieee80211_scan_completed() and the userspace called
2582 * cancel scan scan before ieee80211_scan_work() could run.
2583 * To handle that, simply return if the scan is not running.
2585 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2586 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2588 mutex_unlock(&mvm->mutex);
2592 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2593 struct ieee80211_sta *sta, u16 tids,
2595 enum ieee80211_frame_release_type reason,
2598 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2600 /* Called when we need to transmit (a) frame(s) from mac80211 */
2602 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2603 tids, more_data, false);
2607 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2608 struct ieee80211_sta *sta, u16 tids,
2610 enum ieee80211_frame_release_type reason,
2613 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2615 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2617 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2618 tids, more_data, true);
2621 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2622 enum sta_notify_cmd cmd,
2623 struct ieee80211_sta *sta)
2625 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2626 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2627 unsigned long txqs = 0, tids = 0;
2631 * If we have TVQM then we get too high queue numbers - luckily
2632 * we really shouldn't get here with that because such hardware
2633 * should have firmware supporting buffer station offload.
2635 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2638 spin_lock_bh(&mvmsta->lock);
2639 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2640 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2642 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2645 __set_bit(tid_data->txq_id, &txqs);
2647 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2650 __set_bit(tid, &tids);
2654 case STA_NOTIFY_SLEEP:
2655 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2656 ieee80211_sta_set_buffered(sta, tid, true);
2659 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2661 * The fw updates the STA to be asleep. Tx packets on the Tx
2662 * queues to this station will not be transmitted. The fw will
2663 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2666 case STA_NOTIFY_AWAKE:
2667 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2671 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2672 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2677 spin_unlock_bh(&mvmsta->lock);
2680 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2681 struct ieee80211_vif *vif,
2682 enum sta_notify_cmd cmd,
2683 struct ieee80211_sta *sta)
2685 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2688 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2690 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2691 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2692 struct ieee80211_sta *sta;
2693 struct iwl_mvm_sta *mvmsta;
2694 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2696 if (WARN_ON(notif->sta_id >= ARRAY_SIZE(mvm->fw_id_to_mac_id)))
2700 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2701 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2706 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2709 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2714 if (mvmsta->sleeping != sleeping) {
2715 mvmsta->sleeping = sleeping;
2716 __iwl_mvm_mac_sta_notify(mvm->hw,
2717 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2719 ieee80211_sta_ps_transition(sta, sleeping);
2723 switch (notif->type) {
2724 case IWL_MVM_PM_EVENT_AWAKE:
2725 case IWL_MVM_PM_EVENT_ASLEEP:
2727 case IWL_MVM_PM_EVENT_UAPSD:
2728 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2730 case IWL_MVM_PM_EVENT_PS_POLL:
2731 ieee80211_sta_pspoll(sta);
2741 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2742 struct ieee80211_vif *vif,
2743 struct ieee80211_sta *sta)
2745 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2746 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2749 * This is called before mac80211 does RCU synchronisation,
2750 * so here we already invalidate our internal RCU-protected
2751 * station pointer. The rest of the code will thus no longer
2752 * be able to find the station this way, and we don't rely
2753 * on further RCU synchronisation after the sta_state()
2754 * callback deleted the station.
2756 mutex_lock(&mvm->mutex);
2757 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2758 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2761 mutex_unlock(&mvm->mutex);
2764 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2769 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2770 struct iwl_mvm_tcm_mac *mdata;
2772 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2773 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2774 mdata->opened_rx_ba_sessions = false;
2777 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2780 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2781 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2786 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2787 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2791 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2792 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2793 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2798 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2802 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2803 struct ieee80211_vif *vif, u8 *peer_addr,
2804 enum nl80211_tdls_operation action)
2806 struct iwl_fw_dbg_trigger_tlv *trig;
2807 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2809 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
2810 FW_DBG_TRIGGER_TDLS);
2814 tdls_trig = (void *)trig->data;
2816 if (!(tdls_trig->action_bitmap & BIT(action)))
2819 if (tdls_trig->peer_mode &&
2820 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2823 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2824 "TDLS event occurred, peer %pM, action %d",
2828 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2829 struct iwl_mvm_sta *mvm_sta)
2831 struct iwl_mvm_tid_data *tid_data;
2832 struct sk_buff *skb;
2835 spin_lock_bh(&mvm_sta->lock);
2836 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2837 tid_data = &mvm_sta->tid_data[i];
2839 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames))) {
2840 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2843 * The first deferred frame should've stopped the MAC
2844 * queues, so we should never get a second deferred
2845 * frame for the RA/TID.
2847 iwl_mvm_start_mac_queues(mvm, BIT(info->hw_queue));
2848 ieee80211_free_txskb(mvm->hw, skb);
2851 spin_unlock_bh(&mvm_sta->lock);
2854 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2855 struct ieee80211_vif *vif,
2856 struct ieee80211_sta *sta,
2857 enum ieee80211_sta_state old_state,
2858 enum ieee80211_sta_state new_state)
2860 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2861 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2862 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2865 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2866 sta->addr, old_state, new_state);
2868 /* this would be a mac80211 bug ... but don't crash */
2869 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2873 * If we are in a STA removal flow and in DQA mode:
2875 * This is after the sync_rcu part, so the queues have already been
2876 * flushed. No more TXs on their way in mac80211's path, and no more in
2878 * Also, we won't be getting any new TX frames for this station.
2879 * What we might have are deferred TX frames that need to be taken care
2882 * Drop any still-queued deferred-frame before removing the STA, and
2883 * make sure the worker is no longer handling frames for this STA.
2885 if (old_state == IEEE80211_STA_NONE &&
2886 new_state == IEEE80211_STA_NOTEXIST) {
2887 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2888 flush_work(&mvm->add_stream_wk);
2891 * No need to make sure deferred TX indication is off since the
2892 * worker will already remove it if it was on
2896 mutex_lock(&mvm->mutex);
2897 /* track whether or not the station is associated */
2898 mvm_sta->sta_state = new_state;
2900 if (old_state == IEEE80211_STA_NOTEXIST &&
2901 new_state == IEEE80211_STA_NONE) {
2903 * Firmware bug - it'll crash if the beacon interval is less
2904 * than 16. We can't avoid connecting at all, so refuse the
2905 * station state change, this will cause mac80211 to abandon
2906 * attempts to connect to this AP, and eventually wpa_s will
2907 * blacklist the AP...
2909 if (vif->type == NL80211_IFTYPE_STATION &&
2910 vif->bss_conf.beacon_int < 16) {
2912 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2913 sta->addr, vif->bss_conf.beacon_int);
2920 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2921 IWL_MVM_TDLS_STA_COUNT ||
2922 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2923 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2928 ret = iwl_mvm_add_sta(mvm, vif, sta);
2929 if (sta->tdls && ret == 0) {
2930 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2931 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2932 NL80211_TDLS_SETUP);
2934 } else if (old_state == IEEE80211_STA_NONE &&
2935 new_state == IEEE80211_STA_AUTH) {
2937 * EBS may be disabled due to previous failures reported by FW.
2938 * Reset EBS status here assuming environment has been changed.
2940 mvm->last_ebs_successful = true;
2941 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2943 } else if (old_state == IEEE80211_STA_AUTH &&
2944 new_state == IEEE80211_STA_ASSOC) {
2945 if (vif->type == NL80211_IFTYPE_AP) {
2946 mvmvif->ap_assoc_sta_count++;
2947 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2950 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2952 ret = iwl_mvm_update_sta(mvm, vif, sta);
2953 } else if (old_state == IEEE80211_STA_ASSOC &&
2954 new_state == IEEE80211_STA_AUTHORIZED) {
2956 /* we don't support TDLS during DCM */
2957 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2958 iwl_mvm_teardown_tdls_peers(mvm);
2961 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2962 NL80211_TDLS_ENABLE_LINK);
2964 /* enable beacon filtering */
2965 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2967 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2970 /* if wep is used, need to set the key for the station now */
2971 if (vif->type == NL80211_IFTYPE_AP && mvmvif->ap_wep_key)
2972 ret = iwl_mvm_set_sta_key(mvm, vif, sta,
2974 STA_KEY_IDX_INVALID);
2977 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2978 new_state == IEEE80211_STA_ASSOC) {
2979 /* disable beacon filtering */
2980 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2982 } else if (old_state == IEEE80211_STA_ASSOC &&
2983 new_state == IEEE80211_STA_AUTH) {
2984 if (vif->type == NL80211_IFTYPE_AP) {
2985 mvmvif->ap_assoc_sta_count--;
2986 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2989 } else if (old_state == IEEE80211_STA_AUTH &&
2990 new_state == IEEE80211_STA_NONE) {
2992 } else if (old_state == IEEE80211_STA_NONE &&
2993 new_state == IEEE80211_STA_NOTEXIST) {
2994 ret = iwl_mvm_rm_sta(mvm, vif, sta);
2996 iwl_mvm_recalc_tdls_state(mvm, vif, false);
2997 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2998 NL80211_TDLS_DISABLE_LINK);
3004 mutex_unlock(&mvm->mutex);
3006 if (sta->tdls && ret == 0) {
3007 if (old_state == IEEE80211_STA_NOTEXIST &&
3008 new_state == IEEE80211_STA_NONE)
3009 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3010 else if (old_state == IEEE80211_STA_NONE &&
3011 new_state == IEEE80211_STA_NOTEXIST)
3012 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3018 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3020 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3022 mvm->rts_threshold = value;
3027 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3028 struct ieee80211_vif *vif,
3029 struct ieee80211_sta *sta, u32 changed)
3031 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3033 if (vif->type == NL80211_IFTYPE_STATION &&
3034 changed & IEEE80211_RC_NSS_CHANGED)
3035 iwl_mvm_sf_update(mvm, vif, false);
3038 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3039 struct ieee80211_vif *vif, u16 ac,
3040 const struct ieee80211_tx_queue_params *params)
3042 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3043 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3045 mvmvif->queue_params[ac] = *params;
3048 * No need to update right away, we'll get BSS_CHANGED_QOS
3049 * The exception is P2P_DEVICE interface which needs immediate update.
3051 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3054 mutex_lock(&mvm->mutex);
3055 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3056 mutex_unlock(&mvm->mutex);
3062 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3063 struct ieee80211_vif *vif,
3066 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3067 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3068 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3071 * iwl_mvm_protect_session() reads directly from the device
3072 * (the system time), so make sure it is available.
3074 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
3077 if (req_duration > duration)
3078 duration = req_duration;
3080 mutex_lock(&mvm->mutex);
3081 /* Try really hard to protect the session and hear a beacon */
3082 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
3083 mutex_unlock(&mvm->mutex);
3085 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
3088 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3089 struct ieee80211_vif *vif,
3090 struct cfg80211_sched_scan_request *req,
3091 struct ieee80211_scan_ies *ies)
3093 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3097 mutex_lock(&mvm->mutex);
3099 if (!vif->bss_conf.idle) {
3104 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3107 mutex_unlock(&mvm->mutex);
3111 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3112 struct ieee80211_vif *vif)
3114 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3117 mutex_lock(&mvm->mutex);
3119 /* Due to a race condition, it's possible that mac80211 asks
3120 * us to stop a sched_scan when it's already stopped. This
3121 * can happen, for instance, if we stopped the scan ourselves,
3122 * called ieee80211_sched_scan_stopped() and the userspace called
3123 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3124 * could run. To handle this, simply return if the scan is
3127 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3128 mutex_unlock(&mvm->mutex);
3132 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3133 mutex_unlock(&mvm->mutex);
3134 iwl_mvm_wait_for_async_handlers(mvm);
3139 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3140 enum set_key_cmd cmd,
3141 struct ieee80211_vif *vif,
3142 struct ieee80211_sta *sta,
3143 struct ieee80211_key_conf *key)
3145 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3146 struct iwl_mvm_sta *mvmsta;
3147 struct iwl_mvm_key_pn *ptk_pn;
3148 int keyidx = key->keyidx;
3152 if (iwlwifi_mod_params.swcrypto) {
3153 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
3157 switch (key->cipher) {
3158 case WLAN_CIPHER_SUITE_TKIP:
3159 if (!mvm->trans->cfg->gen2) {
3160 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3161 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3162 } else if (vif->type == NL80211_IFTYPE_STATION) {
3163 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3165 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3169 case WLAN_CIPHER_SUITE_CCMP:
3170 case WLAN_CIPHER_SUITE_GCMP:
3171 case WLAN_CIPHER_SUITE_GCMP_256:
3172 if (!iwl_mvm_has_new_tx_api(mvm))
3173 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3175 case WLAN_CIPHER_SUITE_AES_CMAC:
3176 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3177 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3178 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3180 case WLAN_CIPHER_SUITE_WEP40:
3181 case WLAN_CIPHER_SUITE_WEP104:
3182 if (vif->type == NL80211_IFTYPE_AP) {
3183 struct iwl_mvm_vif *mvmvif =
3184 iwl_mvm_vif_from_mac80211(vif);
3186 mvmvif->ap_wep_key = kmemdup(key,
3187 sizeof(*key) + key->keylen,
3189 if (!mvmvif->ap_wep_key)
3193 if (vif->type != NL80211_IFTYPE_STATION)
3197 /* currently FW supports only one optional cipher scheme */
3198 if (hw->n_cipher_schemes &&
3199 hw->cipher_schemes->cipher == key->cipher)
3200 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3205 mutex_lock(&mvm->mutex);
3209 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3210 vif->type == NL80211_IFTYPE_AP) && !sta) {
3212 * GTK on AP interface is a TX-only key, return 0;
3213 * on IBSS they're per-station and because we're lazy
3214 * we don't support them for RX, so do the same.
3215 * CMAC/GMAC in AP/IBSS modes must be done in software.
3217 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3218 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3219 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3224 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3225 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3226 !iwl_mvm_has_new_tx_api(mvm)) {
3227 key->hw_key_idx = STA_KEY_IDX_INVALID;
3232 /* During FW restart, in order to restore the state as it was,
3233 * don't try to reprogram keys we previously failed for.
3235 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3236 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3237 IWL_DEBUG_MAC80211(mvm,
3238 "skip invalid idx key programming during restart\n");
3243 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3244 sta && iwl_mvm_has_new_rx_api(mvm) &&
3245 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3246 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3247 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3248 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3249 struct ieee80211_key_seq seq;
3252 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3253 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3254 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3255 mvm->trans->num_rx_queues),
3262 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3263 ieee80211_get_key_rx_seq(key, tid, &seq);
3264 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3265 memcpy(ptk_pn->q[q].pn[tid],
3267 IEEE80211_CCMP_PN_LEN);
3270 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3273 /* in HW restart reuse the index, otherwise request a new one */
3274 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3275 key_offset = key->hw_key_idx;
3277 key_offset = STA_KEY_IDX_INVALID;
3279 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3280 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3282 IWL_WARN(mvm, "set key failed\n");
3284 * can't add key for RX, but we don't need it
3285 * in the device for TX so still return 0
3287 key->hw_key_idx = STA_KEY_IDX_INVALID;
3293 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3298 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3299 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3300 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3301 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3302 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3303 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3304 ptk_pn = rcu_dereference_protected(
3305 mvmsta->ptk_pn[keyidx],
3306 lockdep_is_held(&mvm->mutex));
3307 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3309 kfree_rcu(ptk_pn, rcu_head);
3312 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3313 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3319 mutex_unlock(&mvm->mutex);
3323 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3324 struct ieee80211_vif *vif,
3325 struct ieee80211_key_conf *keyconf,
3326 struct ieee80211_sta *sta,
3327 u32 iv32, u16 *phase1key)
3329 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3331 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3334 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3338 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3339 struct iwl_rx_packet *pkt, void *data)
3341 struct iwl_mvm *mvm =
3342 container_of(notif_wait, struct iwl_mvm, notif_wait);
3343 struct iwl_hs20_roc_res *resp;
3344 int resp_len = iwl_rx_packet_payload_len(pkt);
3345 struct iwl_mvm_time_event_data *te_data = data;
3347 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3350 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3351 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3355 resp = (void *)pkt->data;
3358 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
3359 resp->status, resp->event_unique_id);
3361 te_data->uid = le32_to_cpu(resp->event_unique_id);
3362 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3365 spin_lock_bh(&mvm->time_event_lock);
3366 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3367 spin_unlock_bh(&mvm->time_event_lock);
3372 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3373 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3374 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3375 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3376 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3377 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3378 struct ieee80211_channel *channel,
3379 struct ieee80211_vif *vif,
3382 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3383 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3384 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3385 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3386 struct iwl_notification_wait wait_time_event;
3387 u32 dtim_interval = vif->bss_conf.dtim_period *
3388 vif->bss_conf.beacon_int;
3390 struct iwl_hs20_roc_req aux_roc_req = {
3391 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3393 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3394 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3395 /* Set the channel info data */
3396 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3397 PHY_BAND_24 : PHY_BAND_5,
3398 .channel_info.channel = channel->hw_value,
3399 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3400 /* Set the time and duration */
3401 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3404 delay = AUX_ROC_MIN_DELAY;
3405 req_dur = MSEC_TO_TU(duration);
3408 * If we are associated we want the delay time to be at least one
3409 * dtim interval so that the FW can wait until after the DTIM and
3410 * then start the time event, this will potentially allow us to
3411 * remain off-channel for the max duration.
3412 * Since we want to use almost a whole dtim interval we would also
3413 * like the delay to be for 2-3 dtim intervals, in case there are
3414 * other time events with higher priority.
3416 if (vif->bss_conf.assoc) {
3417 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3418 /* We cannot remain off-channel longer than the DTIM interval */
3419 if (dtim_interval <= req_dur) {
3420 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3421 if (req_dur <= AUX_ROC_MIN_DURATION)
3422 req_dur = dtim_interval -
3423 AUX_ROC_MIN_SAFETY_BUFFER;
3427 aux_roc_req.duration = cpu_to_le32(req_dur);
3428 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3431 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3432 channel->hw_value, req_dur, duration, delay,
3434 /* Set the node address */
3435 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3437 lockdep_assert_held(&mvm->mutex);
3439 spin_lock_bh(&mvm->time_event_lock);
3441 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3442 spin_unlock_bh(&mvm->time_event_lock);
3447 te_data->duration = duration;
3448 te_data->id = HOT_SPOT_CMD;
3450 spin_unlock_bh(&mvm->time_event_lock);
3453 * Use a notification wait, which really just processes the
3454 * command response and doesn't wait for anything, in order
3455 * to be able to process the response and get the UID inside
3456 * the RX path. Using CMD_WANT_SKB doesn't work because it
3457 * stores the buffer and then wakes up this thread, by which
3458 * time another notification (that the time event started)
3459 * might already be processed unsuccessfully.
3461 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3462 time_event_response,
3463 ARRAY_SIZE(time_event_response),
3464 iwl_mvm_rx_aux_roc, te_data);
3466 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3470 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3471 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3475 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3476 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3477 /* should never fail */
3482 spin_lock_bh(&mvm->time_event_lock);
3483 iwl_mvm_te_clear_data(mvm, te_data);
3484 spin_unlock_bh(&mvm->time_event_lock);
3490 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3491 struct ieee80211_vif *vif,
3492 struct ieee80211_channel *channel,
3494 enum ieee80211_roc_type type)
3496 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3497 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3498 struct cfg80211_chan_def chandef;
3499 struct iwl_mvm_phy_ctxt *phy_ctxt;
3502 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3506 * Flush the done work, just in case it's still pending, so that
3507 * the work it does can complete and we can accept new frames.
3509 flush_work(&mvm->roc_done_wk);
3511 mutex_lock(&mvm->mutex);
3513 switch (vif->type) {
3514 case NL80211_IFTYPE_STATION:
3515 if (fw_has_capa(&mvm->fw->ucode_capa,
3516 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3517 /* Use aux roc framework (HS20) */
3518 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3522 IWL_ERR(mvm, "hotspot not supported\n");
3525 case NL80211_IFTYPE_P2P_DEVICE:
3529 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3534 for (i = 0; i < NUM_PHY_CTX; i++) {
3535 phy_ctxt = &mvm->phy_ctxts[i];
3536 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3539 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3541 * Unbind the P2P_DEVICE from the current PHY context,
3542 * and if the PHY context is not used remove it.
3544 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3545 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3548 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3550 /* Bind the P2P_DEVICE to the current PHY Context */
3551 mvmvif->phy_ctxt = phy_ctxt;
3553 ret = iwl_mvm_binding_add_vif(mvm, vif);
3554 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3557 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3558 goto schedule_time_event;
3562 /* Need to update the PHY context only if the ROC channel changed */
3563 if (channel == mvmvif->phy_ctxt->channel)
3564 goto schedule_time_event;
3566 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3569 * Change the PHY context configuration as it is currently referenced
3570 * only by the P2P Device MAC
3572 if (mvmvif->phy_ctxt->ref == 1) {
3573 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3579 * The PHY context is shared with other MACs. Need to remove the
3580 * P2P Device from the binding, allocate an new PHY context and
3581 * create a new binding
3583 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3589 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3592 IWL_ERR(mvm, "Failed to change PHY context\n");
3596 /* Unbind the P2P_DEVICE from the current PHY context */
3597 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3598 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3601 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3603 /* Bind the P2P_DEVICE to the new allocated PHY context */
3604 mvmvif->phy_ctxt = phy_ctxt;
3606 ret = iwl_mvm_binding_add_vif(mvm, vif);
3607 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3610 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3613 schedule_time_event:
3614 /* Schedule the time events */
3615 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3618 mutex_unlock(&mvm->mutex);
3619 IWL_DEBUG_MAC80211(mvm, "leave\n");
3623 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3625 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3627 IWL_DEBUG_MAC80211(mvm, "enter\n");
3629 mutex_lock(&mvm->mutex);
3630 iwl_mvm_stop_roc(mvm);
3631 mutex_unlock(&mvm->mutex);
3633 IWL_DEBUG_MAC80211(mvm, "leave\n");
3637 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3638 struct ieee80211_chanctx_conf *ctx)
3640 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3641 struct iwl_mvm_phy_ctxt *phy_ctxt;
3644 lockdep_assert_held(&mvm->mutex);
3646 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3648 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3654 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3655 ctx->rx_chains_static,
3656 ctx->rx_chains_dynamic);
3658 IWL_ERR(mvm, "Failed to add PHY context\n");
3662 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3663 *phy_ctxt_id = phy_ctxt->id;
3668 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3669 struct ieee80211_chanctx_conf *ctx)
3671 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3674 mutex_lock(&mvm->mutex);
3675 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3676 mutex_unlock(&mvm->mutex);
3681 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3682 struct ieee80211_chanctx_conf *ctx)
3684 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3685 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3687 lockdep_assert_held(&mvm->mutex);
3689 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3692 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3693 struct ieee80211_chanctx_conf *ctx)
3695 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3697 mutex_lock(&mvm->mutex);
3698 __iwl_mvm_remove_chanctx(mvm, ctx);
3699 mutex_unlock(&mvm->mutex);
3702 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3703 struct ieee80211_chanctx_conf *ctx,
3706 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3707 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3708 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3710 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3711 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3712 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3713 IEEE80211_CHANCTX_CHANGE_RADAR |
3714 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3715 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3716 phy_ctxt->ref, changed))
3719 mutex_lock(&mvm->mutex);
3721 /* we are only changing the min_width, may be a noop */
3722 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
3723 if (phy_ctxt->width == ctx->min_def.width)
3726 /* we are just toggling between 20_NOHT and 20 */
3727 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
3728 ctx->min_def.width <= NL80211_CHAN_WIDTH_20)
3732 iwl_mvm_bt_coex_vif_change(mvm);
3733 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3734 ctx->rx_chains_static,
3735 ctx->rx_chains_dynamic);
3738 mutex_unlock(&mvm->mutex);
3741 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3742 struct ieee80211_vif *vif,
3743 struct ieee80211_chanctx_conf *ctx,
3744 bool switching_chanctx)
3746 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3747 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3748 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3751 lockdep_assert_held(&mvm->mutex);
3753 mvmvif->phy_ctxt = phy_ctxt;
3755 switch (vif->type) {
3756 case NL80211_IFTYPE_AP:
3757 /* only needed if we're switching chanctx (i.e. during CSA) */
3758 if (switching_chanctx) {
3759 mvmvif->ap_ibss_active = true;
3762 case NL80211_IFTYPE_ADHOC:
3764 * The AP binding flow is handled as part of the start_ap flow
3765 * (in bss_info_changed), similarly for IBSS.
3769 case NL80211_IFTYPE_STATION:
3770 mvmvif->csa_bcn_pending = false;
3772 case NL80211_IFTYPE_MONITOR:
3773 /* always disable PS when a monitor interface is active */
3774 mvmvif->ps_disabled = true;
3781 ret = iwl_mvm_binding_add_vif(mvm, vif);
3786 * Power state must be updated before quotas,
3787 * otherwise fw will complain.
3789 iwl_mvm_power_update_mac(mvm);
3791 /* Setting the quota at this stage is only required for monitor
3792 * interfaces. For the other types, the bss_info changed flow
3793 * will handle quota settings.
3795 if (vif->type == NL80211_IFTYPE_MONITOR) {
3796 mvmvif->monitor_active = true;
3797 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3799 goto out_remove_binding;
3801 ret = iwl_mvm_add_snif_sta(mvm, vif);
3803 goto out_remove_binding;
3807 /* Handle binding during CSA */
3808 if (vif->type == NL80211_IFTYPE_AP) {
3809 iwl_mvm_update_quotas(mvm, false, NULL);
3810 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3813 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3814 u32 duration = 3 * vif->bss_conf.beacon_int;
3816 /* iwl_mvm_protect_session() reads directly from the
3817 * device (the system time), so make sure it is
3820 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3822 goto out_remove_binding;
3824 /* Protect the session to make sure we hear the first
3825 * beacon on the new channel.
3827 mvmvif->csa_bcn_pending = true;
3828 iwl_mvm_protect_session(mvm, vif, duration, duration,
3829 vif->bss_conf.beacon_int / 2,
3832 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3834 iwl_mvm_update_quotas(mvm, false, NULL);
3840 iwl_mvm_binding_remove_vif(mvm, vif);
3841 iwl_mvm_power_update_mac(mvm);
3844 mvmvif->phy_ctxt = NULL;
3847 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3848 struct ieee80211_vif *vif,
3849 struct ieee80211_chanctx_conf *ctx)
3851 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3854 mutex_lock(&mvm->mutex);
3855 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3856 mutex_unlock(&mvm->mutex);
3861 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3862 struct ieee80211_vif *vif,
3863 struct ieee80211_chanctx_conf *ctx,
3864 bool switching_chanctx)
3866 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3867 struct ieee80211_vif *disabled_vif = NULL;
3869 lockdep_assert_held(&mvm->mutex);
3871 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3873 switch (vif->type) {
3874 case NL80211_IFTYPE_ADHOC:
3876 case NL80211_IFTYPE_MONITOR:
3877 mvmvif->monitor_active = false;
3878 mvmvif->ps_disabled = false;
3879 iwl_mvm_rm_snif_sta(mvm, vif);
3881 case NL80211_IFTYPE_AP:
3882 /* This part is triggered only during CSA */
3883 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3886 mvmvif->csa_countdown = false;
3888 /* Set CS bit on all the stations */
3889 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3891 /* Save blocked iface, the timeout is set on the next beacon */
3892 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3894 mvmvif->ap_ibss_active = false;
3896 case NL80211_IFTYPE_STATION:
3897 if (!switching_chanctx)
3902 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3908 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3909 iwl_mvm_binding_remove_vif(mvm, vif);
3912 mvmvif->phy_ctxt = NULL;
3913 iwl_mvm_power_update_mac(mvm);
3916 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3917 struct ieee80211_vif *vif,
3918 struct ieee80211_chanctx_conf *ctx)
3920 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3922 mutex_lock(&mvm->mutex);
3923 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3924 mutex_unlock(&mvm->mutex);
3928 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3929 struct ieee80211_vif_chanctx_switch *vifs)
3933 mutex_lock(&mvm->mutex);
3934 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3935 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3937 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3939 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3943 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3947 "failed to assign new_ctx during channel switch\n");
3951 /* we don't support TDLS during DCM - can be caused by channel switch */
3952 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3953 iwl_mvm_teardown_tdls_peers(mvm);
3958 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3961 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3962 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3966 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3968 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3975 /* things keep failing, better restart the hw */
3976 iwl_mvm_nic_restart(mvm, false);
3979 mutex_unlock(&mvm->mutex);
3985 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3986 struct ieee80211_vif_chanctx_switch *vifs)
3990 mutex_lock(&mvm->mutex);
3991 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3993 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3997 "failed to assign new_ctx during channel switch\n");
4004 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4006 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4013 /* things keep failing, better restart the hw */
4014 iwl_mvm_nic_restart(mvm, false);
4017 mutex_unlock(&mvm->mutex);
4022 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4023 struct ieee80211_vif_chanctx_switch *vifs,
4025 enum ieee80211_chanctx_switch_mode mode)
4027 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4030 /* we only support a single-vif right now */
4035 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4036 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4038 case CHANCTX_SWMODE_REASSIGN_VIF:
4039 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4049 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4051 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4053 return mvm->ibss_manager;
4056 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4057 struct ieee80211_sta *sta,
4060 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4061 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4063 if (!mvm_sta || !mvm_sta->vif) {
4064 IWL_ERR(mvm, "Station is not associated to a vif\n");
4068 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4071 #ifdef CONFIG_NL80211_TESTMODE
4072 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4073 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4074 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4075 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4078 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4079 struct ieee80211_vif *vif,
4080 void *data, int len)
4082 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4086 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy,
4091 if (!tb[IWL_MVM_TM_ATTR_CMD])
4094 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4095 case IWL_MVM_TM_CMD_SET_NOA:
4096 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4097 !vif->bss_conf.enable_beacon ||
4098 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4101 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4102 if (noa_duration >= vif->bss_conf.beacon_int)
4105 mvm->noa_duration = noa_duration;
4108 return iwl_mvm_update_quotas(mvm, true, NULL);
4109 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4110 /* must be associated client vif - ignore authorized */
4111 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4112 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4113 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4116 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4117 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4118 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4124 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4125 struct ieee80211_vif *vif,
4126 void *data, int len)
4128 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4131 mutex_lock(&mvm->mutex);
4132 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4133 mutex_unlock(&mvm->mutex);
4139 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4140 struct ieee80211_vif *vif,
4141 struct ieee80211_channel_switch *chsw)
4143 /* By implementing this operation, we prevent mac80211 from
4144 * starting its own channel switch timer, so that we can call
4145 * ieee80211_chswitch_done() ourselves at the right time
4146 * (which is when the absence time event starts).
4149 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4150 "dummy channel switch op\n");
4153 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4154 struct ieee80211_vif *vif,
4155 struct ieee80211_channel_switch *chsw)
4157 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4158 struct ieee80211_vif *csa_vif;
4159 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4163 mutex_lock(&mvm->mutex);
4165 mvmvif->csa_failed = false;
4167 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4168 chsw->chandef.center_freq1);
4170 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4171 ieee80211_vif_to_wdev(vif),
4172 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4174 switch (vif->type) {
4175 case NL80211_IFTYPE_AP:
4177 rcu_dereference_protected(mvm->csa_vif,
4178 lockdep_is_held(&mvm->mutex));
4179 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4180 "Another CSA is already in progress")) {
4185 /* we still didn't unblock tx. prevent new CS meanwhile */
4186 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4187 lockdep_is_held(&mvm->mutex))) {
4192 rcu_assign_pointer(mvm->csa_vif, vif);
4194 if (WARN_ONCE(mvmvif->csa_countdown,
4195 "Previous CSA countdown didn't complete")) {
4200 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4203 case NL80211_IFTYPE_STATION:
4204 /* Schedule the time event to a bit before beacon 1,
4205 * to make sure we're in the new channel when the
4206 * GO/AP arrives. In case count <= 1 immediately schedule the
4207 * TE (this might result with some packet loss or connection
4210 if (chsw->count <= 1)
4213 apply_time = chsw->device_timestamp +
4214 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4215 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4218 iwl_mvm_csa_client_absent(mvm, vif);
4220 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4222 if (mvmvif->bf_data.bf_enabled) {
4223 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4233 mvmvif->ps_disabled = true;
4235 ret = iwl_mvm_power_update_ps(mvm);
4239 /* we won't be on this channel any longer */
4240 iwl_mvm_teardown_tdls_peers(mvm);
4243 mutex_unlock(&mvm->mutex);
4248 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
4249 struct ieee80211_vif *vif)
4251 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4252 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4255 mutex_lock(&mvm->mutex);
4257 if (mvmvif->csa_failed) {
4258 mvmvif->csa_failed = false;
4263 if (vif->type == NL80211_IFTYPE_STATION) {
4264 struct iwl_mvm_sta *mvmsta;
4266 mvmvif->csa_bcn_pending = false;
4267 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
4270 if (WARN_ON(!mvmsta)) {
4275 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
4277 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4279 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4283 iwl_mvm_stop_session_protection(mvm, vif);
4286 mvmvif->ps_disabled = false;
4288 ret = iwl_mvm_power_update_ps(mvm);
4291 mutex_unlock(&mvm->mutex);
4296 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4300 if (!iwl_mvm_has_new_tx_api(mvm)) {
4302 mutex_lock(&mvm->mutex);
4303 iwl_mvm_flush_tx_path(mvm,
4304 iwl_mvm_flushable_queues(mvm) & queues, 0);
4305 mutex_unlock(&mvm->mutex);
4307 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4312 mutex_lock(&mvm->mutex);
4313 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4314 struct ieee80211_sta *sta;
4316 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4317 lockdep_is_held(&mvm->mutex));
4318 if (IS_ERR_OR_NULL(sta))
4322 iwl_mvm_flush_sta_tids(mvm, i, 0xFF, 0);
4324 iwl_mvm_wait_sta_queues_empty(mvm,
4325 iwl_mvm_sta_from_mac80211(sta));
4327 mutex_unlock(&mvm->mutex);
4330 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4331 struct ieee80211_vif *vif, u32 queues, bool drop)
4333 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4334 struct iwl_mvm_vif *mvmvif;
4335 struct iwl_mvm_sta *mvmsta;
4336 struct ieee80211_sta *sta;
4341 iwl_mvm_flush_no_vif(mvm, queues, drop);
4345 if (vif->type != NL80211_IFTYPE_STATION)
4348 /* Make sure we're done with the deferred traffic before flushing */
4349 flush_work(&mvm->add_stream_wk);
4351 mutex_lock(&mvm->mutex);
4352 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4354 /* flush the AP-station and all TDLS peers */
4355 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
4356 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4357 lockdep_is_held(&mvm->mutex));
4358 if (IS_ERR_OR_NULL(sta))
4361 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4362 if (mvmsta->vif != vif)
4365 /* make sure only TDLS peers or the AP are flushed */
4366 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4369 if (iwl_mvm_flush_sta(mvm, mvmsta, false, 0))
4370 IWL_ERR(mvm, "flush request fail\n");
4372 msk |= mvmsta->tfd_queue_msk;
4373 if (iwl_mvm_has_new_tx_api(mvm))
4374 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4378 mutex_unlock(&mvm->mutex);
4380 /* this can take a while, and we may need/want other operations
4381 * to succeed while doing this, so do it without the mutex held
4383 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4384 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4387 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4388 struct survey_info *survey)
4390 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4393 memset(survey, 0, sizeof(*survey));
4395 /* only support global statistics right now */
4399 if (!fw_has_capa(&mvm->fw->ucode_capa,
4400 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4403 mutex_lock(&mvm->mutex);
4405 if (iwl_mvm_firmware_running(mvm)) {
4406 ret = iwl_mvm_request_statistics(mvm, false);
4411 survey->filled = SURVEY_INFO_TIME |
4412 SURVEY_INFO_TIME_RX |
4413 SURVEY_INFO_TIME_TX |
4414 SURVEY_INFO_TIME_SCAN;
4415 survey->time = mvm->accu_radio_stats.on_time_rf +
4416 mvm->radio_stats.on_time_rf;
4417 do_div(survey->time, USEC_PER_MSEC);
4419 survey->time_rx = mvm->accu_radio_stats.rx_time +
4420 mvm->radio_stats.rx_time;
4421 do_div(survey->time_rx, USEC_PER_MSEC);
4423 survey->time_tx = mvm->accu_radio_stats.tx_time +
4424 mvm->radio_stats.tx_time;
4425 do_div(survey->time_tx, USEC_PER_MSEC);
4427 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4428 mvm->radio_stats.on_time_scan;
4429 do_div(survey->time_scan, USEC_PER_MSEC);
4433 mutex_unlock(&mvm->mutex);
4437 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4438 struct ieee80211_vif *vif,
4439 struct ieee80211_sta *sta,
4440 struct station_info *sinfo)
4442 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4443 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4444 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4446 if (mvmsta->avg_energy) {
4447 sinfo->signal_avg = mvmsta->avg_energy;
4448 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4451 /* if beacon filtering isn't on mac80211 does it anyway */
4452 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4455 if (!vif->bss_conf.assoc)
4458 mutex_lock(&mvm->mutex);
4460 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4463 if (iwl_mvm_request_statistics(mvm, false))
4466 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4467 mvmvif->beacon_stats.accu_num_beacons;
4468 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
4469 if (mvmvif->beacon_stats.avg_signal) {
4470 /* firmware only reports a value after RXing a few beacons */
4471 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4472 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4475 mutex_unlock(&mvm->mutex);
4478 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4479 struct ieee80211_vif *vif,
4480 const struct ieee80211_event *event)
4482 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4484 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4486 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4489 struct iwl_fw_dbg_trigger_tlv *trig;
4490 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4492 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
4493 FW_DBG_TRIGGER_MLME);
4497 trig_mlme = (void *)trig->data;
4499 if (event->u.mlme.data == ASSOC_EVENT) {
4500 if (event->u.mlme.status == MLME_DENIED)
4501 CHECK_MLME_TRIGGER(stop_assoc_denied,
4502 "DENIED ASSOC: reason %d",
4503 event->u.mlme.reason);
4504 else if (event->u.mlme.status == MLME_TIMEOUT)
4505 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4507 } else if (event->u.mlme.data == AUTH_EVENT) {
4508 if (event->u.mlme.status == MLME_DENIED)
4509 CHECK_MLME_TRIGGER(stop_auth_denied,
4510 "DENIED AUTH: reason %d",
4511 event->u.mlme.reason);
4512 else if (event->u.mlme.status == MLME_TIMEOUT)
4513 CHECK_MLME_TRIGGER(stop_auth_timeout,
4515 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4516 CHECK_MLME_TRIGGER(stop_rx_deauth,
4517 "DEAUTH RX %d", event->u.mlme.reason);
4518 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4519 CHECK_MLME_TRIGGER(stop_tx_deauth,
4520 "DEAUTH TX %d", event->u.mlme.reason);
4522 #undef CHECK_MLME_TRIGGER
4525 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4526 struct ieee80211_vif *vif,
4527 const struct ieee80211_event *event)
4529 struct iwl_fw_dbg_trigger_tlv *trig;
4530 struct iwl_fw_dbg_trigger_ba *ba_trig;
4532 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
4537 ba_trig = (void *)trig->data;
4539 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4542 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
4543 "BAR received from %pM, tid %d, ssn %d",
4544 event->u.ba.sta->addr, event->u.ba.tid,
4548 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4549 struct ieee80211_vif *vif,
4550 const struct ieee80211_event *event)
4552 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4554 switch (event->type) {
4556 iwl_mvm_event_mlme_callback(mvm, vif, event);
4559 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4561 case BA_FRAME_TIMEOUT:
4562 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
4570 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4571 struct iwl_mvm_internal_rxq_notif *notif,
4574 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4577 lockdep_assert_held(&mvm->mutex);
4579 if (!iwl_mvm_has_new_rx_api(mvm))
4582 notif->cookie = mvm->queue_sync_cookie;
4585 atomic_set(&mvm->queue_sync_counter,
4586 mvm->trans->num_rx_queues);
4588 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4590 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4595 ret = wait_event_timeout(mvm->rx_sync_waitq,
4596 atomic_read(&mvm->queue_sync_counter) == 0 ||
4597 iwl_mvm_is_radio_killed(mvm),
4599 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
4603 atomic_set(&mvm->queue_sync_counter, 0);
4604 mvm->queue_sync_cookie++;
4607 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4609 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4610 struct iwl_mvm_internal_rxq_notif data = {
4611 .type = IWL_MVM_RXQ_EMPTY,
4615 mutex_lock(&mvm->mutex);
4616 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
4617 mutex_unlock(&mvm->mutex);
4620 const struct ieee80211_ops iwl_mvm_hw_ops = {
4621 .tx = iwl_mvm_mac_tx,
4622 .ampdu_action = iwl_mvm_mac_ampdu_action,
4623 .start = iwl_mvm_mac_start,
4624 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
4625 .stop = iwl_mvm_mac_stop,
4626 .add_interface = iwl_mvm_mac_add_interface,
4627 .remove_interface = iwl_mvm_mac_remove_interface,
4628 .config = iwl_mvm_mac_config,
4629 .prepare_multicast = iwl_mvm_prepare_multicast,
4630 .configure_filter = iwl_mvm_configure_filter,
4631 .config_iface_filter = iwl_mvm_config_iface_filter,
4632 .bss_info_changed = iwl_mvm_bss_info_changed,
4633 .hw_scan = iwl_mvm_mac_hw_scan,
4634 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
4635 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
4636 .sta_state = iwl_mvm_mac_sta_state,
4637 .sta_notify = iwl_mvm_mac_sta_notify,
4638 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
4639 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
4640 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
4641 .sta_rc_update = iwl_mvm_sta_rc_update,
4642 .conf_tx = iwl_mvm_mac_conf_tx,
4643 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
4644 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
4645 .flush = iwl_mvm_mac_flush,
4646 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4647 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
4648 .set_key = iwl_mvm_mac_set_key,
4649 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4650 .remain_on_channel = iwl_mvm_roc,
4651 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
4652 .add_chanctx = iwl_mvm_add_chanctx,
4653 .remove_chanctx = iwl_mvm_remove_chanctx,
4654 .change_chanctx = iwl_mvm_change_chanctx,
4655 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4656 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
4657 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
4659 .start_ap = iwl_mvm_start_ap_ibss,
4660 .stop_ap = iwl_mvm_stop_ap_ibss,
4661 .join_ibss = iwl_mvm_start_ap_ibss,
4662 .leave_ibss = iwl_mvm_stop_ap_ibss,
4664 .tx_last_beacon = iwl_mvm_tx_last_beacon,
4666 .set_tim = iwl_mvm_set_tim,
4668 .channel_switch = iwl_mvm_channel_switch,
4669 .pre_channel_switch = iwl_mvm_pre_channel_switch,
4670 .post_channel_switch = iwl_mvm_post_channel_switch,
4672 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4673 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4674 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4676 .event_callback = iwl_mvm_mac_event_callback,
4678 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4680 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4682 #ifdef CONFIG_PM_SLEEP
4684 .suspend = iwl_mvm_suspend,
4685 .resume = iwl_mvm_resume,
4686 .set_wakeup = iwl_mvm_set_wakeup,
4687 .set_rekey_data = iwl_mvm_set_rekey_data,
4688 #if IS_ENABLED(CONFIG_IPV6)
4689 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4691 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4693 .get_survey = iwl_mvm_mac_get_survey,
4694 .sta_statistics = iwl_mvm_mac_sta_statistics,
4695 #ifdef CONFIG_IWLWIFI_DEBUGFS
4696 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,