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) 2013 - 2015 Intel Mobile Communications GmbH
9 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
10 * Copyright(c) 2012 - 2014, 2018 - 2020 Intel Corporation
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * The full GNU General Public License is included in this distribution
22 * in the file called COPYING.
24 * Contact Information:
25 * Intel Linux Wireless <linuxwifi@intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
31 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
32 * Copyright(c) 2012 - 2014, 2018 - 2020 Intel Corporation
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
39 * * Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * * Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in
43 * the documentation and/or other materials provided with the
45 * * Neither the name Intel Corporation nor the names of its
46 * contributors may be used to endorse or promote products derived
47 * from this software without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
62 #include <linux/kernel.h>
63 #include <linux/slab.h>
64 #include <linux/skbuff.h>
65 #include <linux/netdevice.h>
66 #include <linux/etherdevice.h>
68 #include <linux/if_arp.h>
69 #include <linux/time.h>
70 #include <net/mac80211.h>
71 #include <net/ieee80211_radiotap.h>
74 #include "iwl-op-mode.h"
78 #include "time-event.h"
79 #include "iwl-eeprom-parse.h"
80 #include "iwl-phy-db.h"
82 #include "fw/error-dump.h"
84 #include "iwl-nvm-parse.h"
86 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
89 .types = BIT(NL80211_IFTYPE_STATION),
93 .types = BIT(NL80211_IFTYPE_AP) |
94 BIT(NL80211_IFTYPE_P2P_CLIENT) |
95 BIT(NL80211_IFTYPE_P2P_GO),
99 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
103 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
105 .num_different_channels = 2,
107 .limits = iwl_mvm_limits,
108 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
112 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
114 * Use the reserved field to indicate magic values.
115 * these values will only be used internally by the driver,
116 * and won't make it to the fw (reserved will be 0).
117 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
118 * be the vif's ip address. in case there is not a single
119 * ip address (0, or more than 1), this attribute will
121 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
122 * the LSB bytes of the vif's mac address
125 BC_FILTER_MAGIC_NONE = 0,
130 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
134 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
137 /* frame type - arp, hw type - ethernet */
139 BCAST_FILTER_OFFSET_PAYLOAD_START,
140 .offset = sizeof(rfc1042_header),
141 .val = cpu_to_be32(0x08060001),
142 .mask = cpu_to_be32(0xffffffff),
147 BCAST_FILTER_OFFSET_PAYLOAD_START,
148 .offset = sizeof(rfc1042_header) + 2 +
149 sizeof(struct arphdr) +
150 ETH_ALEN + sizeof(__be32) +
152 .mask = cpu_to_be32(0xffffffff),
153 /* mark it as special field */
154 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
159 /* dhcp offer bcast */
161 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
164 /* udp dest port - 68 (bootp client)*/
165 .offset_type = BCAST_FILTER_OFFSET_IP_END,
166 .offset = offsetof(struct udphdr, dest),
167 .val = cpu_to_be32(0x00440000),
168 .mask = cpu_to_be32(0xffff0000),
171 /* dhcp - lsb bytes of client hw address */
172 .offset_type = BCAST_FILTER_OFFSET_IP_END,
174 .mask = cpu_to_be32(0xffffffff),
175 /* mark it as special field */
176 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
180 /* last filter must be empty */
185 static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa = {
186 .max_peers = IWL_MVM_TOF_MAX_APS,
188 .randomize_mac_addr = 1,
195 .request_civicloc = 1,
197 .non_trigger_based = 1,
198 .max_bursts_exponent = -1, /* all supported */
199 .max_ftms_per_burst = 0, /* no limits */
200 .bandwidths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
201 BIT(NL80211_CHAN_WIDTH_20) |
202 BIT(NL80211_CHAN_WIDTH_40) |
203 BIT(NL80211_CHAN_WIDTH_80),
204 .preambles = BIT(NL80211_PREAMBLE_LEGACY) |
205 BIT(NL80211_PREAMBLE_HT) |
206 BIT(NL80211_PREAMBLE_VHT) |
207 BIT(NL80211_PREAMBLE_HE),
211 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
212 enum set_key_cmd cmd,
213 struct ieee80211_vif *vif,
214 struct ieee80211_sta *sta,
215 struct ieee80211_key_conf *key);
217 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
221 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
222 for (i = 0; i < NUM_PHY_CTX; i++) {
223 mvm->phy_ctxts[i].id = i;
224 mvm->phy_ctxts[i].ref = 0;
228 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
230 enum iwl_mcc_source src_id,
233 struct ieee80211_regdomain *regd = NULL;
234 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
235 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
236 struct iwl_mcc_update_resp *resp;
239 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
241 lockdep_assert_held(&mvm->mutex);
243 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
244 if (IS_ERR_OR_NULL(resp)) {
245 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
246 PTR_ERR_OR_ZERO(resp));
251 u32 status = le32_to_cpu(resp->status);
253 *changed = (status == MCC_RESP_NEW_CHAN_PROFILE ||
254 status == MCC_RESP_ILLEGAL);
256 resp_ver = iwl_fw_lookup_notif_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP,
258 IWL_DEBUG_LAR(mvm, "MCC update response version: %d\n", resp_ver);
260 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
261 __le32_to_cpu(resp->n_channels),
263 __le16_to_cpu(resp->mcc),
264 __le16_to_cpu(resp->geo_info),
265 __le16_to_cpu(resp->cap), resp_ver);
266 /* Store the return source id */
267 src_id = resp->source_id;
269 if (IS_ERR_OR_NULL(regd)) {
270 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
271 PTR_ERR_OR_ZERO(regd));
275 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
276 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
277 mvm->lar_regdom_set = true;
278 mvm->mcc_src = src_id;
284 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
287 struct ieee80211_regdomain *regd;
289 if (!iwl_mvm_is_lar_supported(mvm))
292 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
293 if (!IS_ERR_OR_NULL(regd)) {
294 /* only update the regulatory core if changed */
296 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
302 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
305 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
306 iwl_mvm_is_wifi_mcc_supported(mvm) ?
307 MCC_SOURCE_GET_CURRENT :
308 MCC_SOURCE_OLD_FW, changed);
311 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
313 enum iwl_mcc_source used_src;
314 struct ieee80211_regdomain *regd;
317 const struct ieee80211_regdomain *r =
318 rtnl_dereference(mvm->hw->wiphy->regd);
323 /* save the last source in case we overwrite it below */
324 used_src = mvm->mcc_src;
325 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
326 /* Notify the firmware we support wifi location updates */
327 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
328 if (!IS_ERR_OR_NULL(regd))
332 /* Now set our last stored MCC and source */
333 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
335 if (IS_ERR_OR_NULL(regd))
338 /* update cfg80211 if the regdomain was changed */
340 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
348 static const u8 he_if_types_ext_capa_sta[] = {
349 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
350 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
351 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
352 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
355 static const struct wiphy_iftype_ext_capab he_iftypes_ext_capa[] = {
357 .iftype = NL80211_IFTYPE_STATION,
358 .extended_capabilities = he_if_types_ext_capa_sta,
359 .extended_capabilities_mask = he_if_types_ext_capa_sta,
360 .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta),
365 iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
367 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
368 *tx_ant = iwl_mvm_get_valid_tx_ant(mvm);
369 *rx_ant = iwl_mvm_get_valid_rx_ant(mvm);
373 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
375 struct ieee80211_hw *hw = mvm->hw;
377 static const u32 mvm_ciphers[] = {
378 WLAN_CIPHER_SUITE_WEP40,
379 WLAN_CIPHER_SUITE_WEP104,
380 WLAN_CIPHER_SUITE_TKIP,
381 WLAN_CIPHER_SUITE_CCMP,
383 #ifdef CONFIG_PM_SLEEP
384 bool unified = fw_has_capa(&mvm->fw->ucode_capa,
385 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
388 /* Tell mac80211 our characteristics */
389 ieee80211_hw_set(hw, SIGNAL_DBM);
390 ieee80211_hw_set(hw, SPECTRUM_MGMT);
391 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
392 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
393 ieee80211_hw_set(hw, SUPPORTS_PS);
394 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
395 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
396 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
397 ieee80211_hw_set(hw, CONNECTION_MONITOR);
398 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
399 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
400 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
401 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
402 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
403 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
404 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
405 ieee80211_hw_set(hw, BUFF_MMPDU_TXQ);
406 ieee80211_hw_set(hw, STA_MMPDU_TXQ);
408 * On older devices, enabling TX A-MSDU occasionally leads to
409 * something getting messed up, the command read from the FIFO
410 * gets out of sync and isn't a TX command, so that we have an
413 * It's not clear where the bug is, but since we didn't used to
414 * support A-MSDU until moving the mac80211 iTXQs, just leave it
415 * for older devices. We also don't see this issue on any newer
418 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000)
419 ieee80211_hw_set(hw, TX_AMSDU);
420 ieee80211_hw_set(hw, TX_FRAG_LIST);
422 if (iwl_mvm_has_tlc_offload(mvm)) {
423 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
424 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
427 if (iwl_mvm_has_new_rx_api(mvm))
428 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
430 if (fw_has_capa(&mvm->fw->ucode_capa,
431 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
432 ieee80211_hw_set(hw, AP_LINK_PS);
433 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
435 * we absolutely need this for the new TX API since that comes
436 * with many more queues than the current code can deal with
437 * for station powersave
442 if (mvm->trans->num_rx_queues > 1)
443 ieee80211_hw_set(hw, USES_RSS);
445 if (mvm->trans->max_skb_frags)
446 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
448 hw->queues = IEEE80211_MAX_QUEUES;
449 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
450 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
451 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
452 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
453 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
455 hw->radiotap_timestamp.units_pos =
456 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
457 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
458 /* this is the case for CCK frames, it's better (only 8) for OFDM */
459 hw->radiotap_timestamp.accuracy = 22;
461 if (!iwl_mvm_has_tlc_offload(mvm))
462 hw->rate_control_algorithm = RS_NAME;
464 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
465 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
466 hw->max_tx_fragments = mvm->trans->max_skb_frags;
468 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
469 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
470 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
471 hw->wiphy->cipher_suites = mvm->ciphers;
473 if (iwl_mvm_has_new_rx_api(mvm)) {
474 mvm->ciphers[hw->wiphy->n_cipher_suites] =
475 WLAN_CIPHER_SUITE_GCMP;
476 hw->wiphy->n_cipher_suites++;
477 mvm->ciphers[hw->wiphy->n_cipher_suites] =
478 WLAN_CIPHER_SUITE_GCMP_256;
479 hw->wiphy->n_cipher_suites++;
482 if (iwlwifi_mod_params.swcrypto)
484 "iwlmvm doesn't allow to disable HW crypto, check swcrypto module parameter\n");
485 if (!iwlwifi_mod_params.bt_coex_active)
487 "iwlmvm doesn't allow to disable BT Coex, check bt_coex_active module parameter\n");
489 ieee80211_hw_set(hw, MFP_CAPABLE);
490 mvm->ciphers[hw->wiphy->n_cipher_suites] = WLAN_CIPHER_SUITE_AES_CMAC;
491 hw->wiphy->n_cipher_suites++;
492 if (iwl_mvm_has_new_rx_api(mvm)) {
493 mvm->ciphers[hw->wiphy->n_cipher_suites] =
494 WLAN_CIPHER_SUITE_BIP_GMAC_128;
495 hw->wiphy->n_cipher_suites++;
496 mvm->ciphers[hw->wiphy->n_cipher_suites] =
497 WLAN_CIPHER_SUITE_BIP_GMAC_256;
498 hw->wiphy->n_cipher_suites++;
501 /* currently FW API supports only one optional cipher scheme */
502 if (mvm->fw->cs[0].cipher) {
503 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
504 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
506 mvm->hw->n_cipher_schemes = 1;
508 cs->cipher = le32_to_cpu(fwcs->cipher);
509 cs->iftype = BIT(NL80211_IFTYPE_STATION);
510 cs->hdr_len = fwcs->hdr_len;
511 cs->pn_len = fwcs->pn_len;
512 cs->pn_off = fwcs->pn_off;
513 cs->key_idx_off = fwcs->key_idx_off;
514 cs->key_idx_mask = fwcs->key_idx_mask;
515 cs->key_idx_shift = fwcs->key_idx_shift;
516 cs->mic_len = fwcs->mic_len;
518 mvm->hw->cipher_schemes = mvm->cs;
519 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
520 hw->wiphy->n_cipher_suites++;
523 if (fw_has_capa(&mvm->fw->ucode_capa,
524 IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) {
525 wiphy_ext_feature_set(hw->wiphy,
526 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
527 hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa;
530 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
531 hw->wiphy->features |=
532 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
533 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
534 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
536 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
537 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
538 hw->chanctx_data_size = sizeof(u16);
539 hw->txq_data_size = sizeof(struct iwl_mvm_txq);
541 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
542 BIT(NL80211_IFTYPE_P2P_CLIENT) |
543 BIT(NL80211_IFTYPE_AP) |
544 BIT(NL80211_IFTYPE_P2P_GO) |
545 BIT(NL80211_IFTYPE_P2P_DEVICE) |
546 BIT(NL80211_IFTYPE_ADHOC);
548 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
549 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
551 /* The new Tx API does not allow to pass the key or keyid of a MPDU to
552 * the hw, preventing us to control which key(id) to use per MPDU.
553 * Till that's fixed we can't use Extended Key ID for the newer cards.
555 if (!iwl_mvm_has_new_tx_api(mvm))
556 wiphy_ext_feature_set(hw->wiphy,
557 NL80211_EXT_FEATURE_EXT_KEY_ID);
558 hw->wiphy->features |= NL80211_FEATURE_HT_IBSS;
560 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
561 if (iwl_mvm_is_lar_supported(mvm))
562 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
564 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
565 REGULATORY_DISABLE_BEACON_HINTS;
567 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
568 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
570 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
571 hw->wiphy->n_iface_combinations =
572 ARRAY_SIZE(iwl_mvm_iface_combinations);
574 hw->wiphy->max_remain_on_channel_duration = 10000;
575 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
577 /* Extract MAC address */
578 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
579 hw->wiphy->addresses = mvm->addresses;
580 hw->wiphy->n_addresses = 1;
582 /* Extract additional MAC addresses if available */
583 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
584 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
586 for (i = 1; i < num_mac; i++) {
587 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
589 mvm->addresses[i].addr[5]++;
590 hw->wiphy->n_addresses++;
593 iwl_mvm_reset_phy_ctxts(mvm);
595 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
597 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
599 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
600 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
601 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
603 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
604 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
606 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
608 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
609 hw->wiphy->bands[NL80211_BAND_2GHZ] =
610 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
611 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
612 hw->wiphy->bands[NL80211_BAND_5GHZ] =
613 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
615 if (fw_has_capa(&mvm->fw->ucode_capa,
616 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
617 fw_has_api(&mvm->fw->ucode_capa,
618 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
619 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
620 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
623 hw->wiphy->hw_version = mvm->trans->hw_id;
625 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
626 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
628 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
630 hw->wiphy->max_sched_scan_reqs = 1;
631 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
632 hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw);
633 /* we create the 802.11 header and zero length SSID IE. */
634 hw->wiphy->max_sched_scan_ie_len =
635 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
636 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
637 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
640 * the firmware uses u8 for num of iterations, but 0xff is saved for
641 * infinite loop, so the maximum number of iterations is actually 254.
643 hw->wiphy->max_sched_scan_plan_iterations = 254;
645 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
646 NL80211_FEATURE_LOW_PRIORITY_SCAN |
647 NL80211_FEATURE_P2P_GO_OPPPS |
648 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
649 NL80211_FEATURE_DYNAMIC_SMPS |
650 NL80211_FEATURE_STATIC_SMPS |
651 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
653 if (fw_has_capa(&mvm->fw->ucode_capa,
654 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
655 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
656 if (fw_has_capa(&mvm->fw->ucode_capa,
657 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
658 hw->wiphy->features |= NL80211_FEATURE_QUIET;
660 if (fw_has_capa(&mvm->fw->ucode_capa,
661 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
662 hw->wiphy->features |=
663 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
665 if (fw_has_capa(&mvm->fw->ucode_capa,
666 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
667 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
669 if (iwl_fw_lookup_cmd_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP,
670 WOWLAN_KEK_KCK_MATERIAL,
671 IWL_FW_CMD_VER_UNKNOWN) == 3)
672 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK;
674 if (fw_has_api(&mvm->fw->ucode_capa,
675 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
676 wiphy_ext_feature_set(hw->wiphy,
677 NL80211_EXT_FEATURE_SCAN_START_TIME);
678 wiphy_ext_feature_set(hw->wiphy,
679 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
682 if (iwl_mvm_is_oce_supported(mvm)) {
683 wiphy_ext_feature_set(hw->wiphy,
684 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
685 wiphy_ext_feature_set(hw->wiphy,
686 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
687 wiphy_ext_feature_set(hw->wiphy,
688 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
689 wiphy_ext_feature_set(hw->wiphy,
690 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
693 if (mvm->nvm_data->sku_cap_11ax_enable &&
694 !iwlwifi_mod_params.disable_11ax) {
695 hw->wiphy->iftype_ext_capab = he_iftypes_ext_capa;
696 hw->wiphy->num_iftype_ext_capab =
697 ARRAY_SIZE(he_iftypes_ext_capa);
699 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
700 ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID);
703 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
705 #ifdef CONFIG_PM_SLEEP
706 if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) &&
707 mvm->trans->ops->d3_suspend &&
708 mvm->trans->ops->d3_resume &&
709 device_can_wakeup(mvm->trans->dev)) {
710 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
711 WIPHY_WOWLAN_DISCONNECT |
712 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
713 WIPHY_WOWLAN_RFKILL_RELEASE |
714 WIPHY_WOWLAN_NET_DETECT;
715 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
716 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
717 WIPHY_WOWLAN_4WAY_HANDSHAKE;
719 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
720 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
721 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
722 mvm->wowlan.max_nd_match_sets =
723 iwl_umac_scan_get_max_profiles(mvm->fw);
724 hw->wiphy->wowlan = &mvm->wowlan;
728 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
729 /* assign default bcast filtering configuration */
730 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
733 ret = iwl_mvm_leds_init(mvm);
737 if (fw_has_capa(&mvm->fw->ucode_capa,
738 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
739 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
740 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
741 ieee80211_hw_set(hw, TDLS_WIDER_BW);
744 if (fw_has_capa(&mvm->fw->ucode_capa,
745 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
746 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
747 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
750 hw->netdev_features |= mvm->cfg->features;
751 if (!iwl_mvm_is_csum_supported(mvm)) {
752 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
754 /* We may support SW TX CSUM */
755 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
756 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
759 if (mvm->cfg->vht_mu_mimo_supported)
760 wiphy_ext_feature_set(hw->wiphy,
761 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
763 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT))
764 wiphy_ext_feature_set(hw->wiphy,
765 NL80211_EXT_FEATURE_PROTECTED_TWT);
767 hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm);
768 hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm);
770 ret = ieee80211_register_hw(mvm->hw);
772 iwl_mvm_leds_exit(mvm);
778 static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
779 struct ieee80211_sta *sta)
782 if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0))
785 if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0))
789 ieee80211_free_txskb(mvm->hw, skb);
792 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
793 struct ieee80211_tx_control *control,
796 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
797 struct ieee80211_sta *sta = control->sta;
798 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
799 struct ieee80211_hdr *hdr = (void *)skb->data;
800 bool offchannel = IEEE80211_SKB_CB(skb)->flags &
801 IEEE80211_TX_CTL_TX_OFFCHAN;
803 if (iwl_mvm_is_radio_killed(mvm)) {
804 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
809 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
810 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
813 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
814 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
815 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
816 ieee80211_is_mgmt(hdr->frame_control) &&
817 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
820 /* If there is no sta, and it's not offchannel - send through AP */
821 if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION &&
823 struct iwl_mvm_vif *mvmvif =
824 iwl_mvm_vif_from_mac80211(info->control.vif);
825 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
827 if (ap_sta_id < mvm->fw->ucode_capa.num_stations) {
828 /* mac80211 holds rcu read lock */
829 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
830 if (IS_ERR_OR_NULL(sta))
835 iwl_mvm_tx_skb(mvm, skb, sta);
838 ieee80211_free_txskb(hw, skb);
841 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
843 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
844 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
845 struct sk_buff *skb = NULL;
848 * No need for threads to be pending here, they can leave the first
849 * taker all the work.
851 * mvmtxq->tx_request logic:
853 * If 0, no one is currently TXing, set to 1 to indicate current thread
854 * will now start TX and other threads should quit.
856 * If 1, another thread is currently TXing, set to 2 to indicate to
857 * that thread that there was another request. Since that request may
858 * have raced with the check whether the queue is empty, the TXing
859 * thread should check the queue's status one more time before leaving.
860 * This check is done in order to not leave any TX hanging in the queue
861 * until the next TX invocation (which may not even happen).
863 * If 2, another thread is currently TXing, and it will already double
864 * check the queue, so do nothing.
866 if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2))
871 while (likely(!mvmtxq->stopped &&
872 (mvm->trans->system_pm_mode ==
873 IWL_PLAT_PM_MODE_DISABLED))) {
874 skb = ieee80211_tx_dequeue(hw, txq);
879 "TXQ of sta %pM tid %d is now empty\n",
885 iwl_mvm_tx_skb(mvm, skb, txq->sta);
887 } while (atomic_dec_return(&mvmtxq->tx_request));
891 static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw,
892 struct ieee80211_txq *txq)
894 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
895 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
898 * Please note that racing is handled very carefully here:
899 * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is
900 * deleted afterwards.
901 * This means that if:
902 * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list):
903 * queue is allocated and we can TX.
904 * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list):
905 * a race, should defer the frame.
906 * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list):
907 * need to allocate the queue and defer the frame.
908 * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list):
909 * queue is already scheduled for allocation, no need to allocate,
910 * should defer the frame.
913 /* If the queue is allocated TX and return. */
914 if (!txq->sta || mvmtxq->txq_id != IWL_MVM_INVALID_QUEUE) {
916 * Check that list is empty to avoid a race where txq_id is
917 * already updated, but the queue allocation work wasn't
920 if (unlikely(txq->sta && !list_empty(&mvmtxq->list)))
923 iwl_mvm_mac_itxq_xmit(hw, txq);
927 /* The list is being deleted only after the queue is fully allocated. */
928 if (!list_empty(&mvmtxq->list))
931 list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs);
932 schedule_work(&mvm->add_stream_wk);
935 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
937 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
939 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
943 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
944 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
945 enum ieee80211_ampdu_mlme_action action)
947 struct iwl_fw_dbg_trigger_tlv *trig;
948 struct iwl_fw_dbg_trigger_ba *ba_trig;
950 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
955 ba_trig = (void *)trig->data;
958 case IEEE80211_AMPDU_TX_OPERATIONAL: {
959 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
960 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
962 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
963 "TX AGG START: MAC %pM tid %d ssn %d\n",
964 sta->addr, tid, tid_data->ssn);
967 case IEEE80211_AMPDU_TX_STOP_CONT:
968 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
969 "TX AGG STOP: MAC %pM tid %d\n",
972 case IEEE80211_AMPDU_RX_START:
973 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
974 "RX AGG START: MAC %pM tid %d ssn %d\n",
975 sta->addr, tid, rx_ba_ssn);
977 case IEEE80211_AMPDU_RX_STOP:
978 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
979 "RX AGG STOP: MAC %pM tid %d\n",
987 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
988 struct ieee80211_vif *vif,
989 struct ieee80211_ampdu_params *params)
991 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
993 struct ieee80211_sta *sta = params->sta;
994 enum ieee80211_ampdu_mlme_action action = params->action;
995 u16 tid = params->tid;
996 u16 *ssn = ¶ms->ssn;
997 u16 buf_size = params->buf_size;
998 bool amsdu = params->amsdu;
999 u16 timeout = params->timeout;
1001 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
1002 sta->addr, tid, action);
1004 if (!(mvm->nvm_data->sku_cap_11n_enable))
1007 mutex_lock(&mvm->mutex);
1010 case IEEE80211_AMPDU_RX_START:
1011 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
1012 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
1013 struct iwl_mvm_vif *mvmvif;
1014 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
1015 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
1017 mdata->opened_rx_ba_sessions = true;
1018 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1019 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
1021 if (!iwl_enable_rx_ampdu()) {
1025 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
1028 case IEEE80211_AMPDU_RX_STOP:
1029 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
1032 case IEEE80211_AMPDU_TX_START:
1033 if (!iwl_enable_tx_ampdu()) {
1037 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
1039 case IEEE80211_AMPDU_TX_STOP_CONT:
1040 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
1042 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1043 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1044 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
1046 case IEEE80211_AMPDU_TX_OPERATIONAL:
1047 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1059 if (action == IEEE80211_AMPDU_RX_START)
1062 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1065 mutex_unlock(&mvm->mutex);
1070 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1071 struct ieee80211_vif *vif)
1073 struct iwl_mvm *mvm = data;
1074 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1076 mvmvif->uploaded = false;
1077 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1079 spin_lock_bh(&mvm->time_event_lock);
1080 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1081 spin_unlock_bh(&mvm->time_event_lock);
1083 mvmvif->phy_ctxt = NULL;
1084 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1085 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
1088 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1090 iwl_mvm_stop_device(mvm);
1094 mvm->scan_status = 0;
1095 mvm->ps_disabled = false;
1096 mvm->rfkill_safe_init_done = false;
1098 /* just in case one was running */
1099 iwl_mvm_cleanup_roc_te(mvm);
1100 ieee80211_remain_on_channel_expired(mvm->hw);
1102 iwl_mvm_ftm_restart(mvm);
1105 * cleanup all interfaces, even inactive ones, as some might have
1106 * gone down during the HW restart
1108 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1110 mvm->p2p_device_vif = NULL;
1112 iwl_mvm_reset_phy_ctxts(mvm);
1113 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1114 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1115 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1117 ieee80211_wake_queues(mvm->hw);
1120 mvm->rx_ba_sessions = 0;
1121 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1122 mvm->monitor_on = false;
1124 /* keep statistics ticking */
1125 iwl_mvm_accu_radio_stats(mvm);
1128 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1132 lockdep_assert_held(&mvm->mutex);
1134 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1136 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1137 * so later code will - from now on - see that we're doing it.
1139 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1140 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1141 /* Clean up some internal and mac80211 state on restart */
1142 iwl_mvm_restart_cleanup(mvm);
1144 ret = iwl_mvm_up(mvm);
1146 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT,
1148 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC,
1151 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1152 /* Something went wrong - we need to finish some cleanup
1153 * that normally iwl_mvm_mac_restart_complete() below
1156 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1162 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1164 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1167 mutex_lock(&mvm->mutex);
1168 ret = __iwl_mvm_mac_start(mvm);
1169 mutex_unlock(&mvm->mutex);
1174 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1178 mutex_lock(&mvm->mutex);
1180 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1182 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1184 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1187 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY);
1190 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1191 * of packets the FW sent out, so we must reconnect.
1193 iwl_mvm_teardown_tdls_peers(mvm);
1195 mutex_unlock(&mvm->mutex);
1199 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1200 enum ieee80211_reconfig_type reconfig_type)
1202 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1204 switch (reconfig_type) {
1205 case IEEE80211_RECONFIG_TYPE_RESTART:
1206 iwl_mvm_restart_complete(mvm);
1208 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1213 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1215 lockdep_assert_held(&mvm->mutex);
1217 iwl_mvm_ftm_initiator_smooth_stop(mvm);
1219 /* firmware counters are obviously reset now, but we shouldn't
1220 * partially track so also clear the fw_reset_accu counters.
1222 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1224 /* async_handlers_wk is now blocked */
1226 if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP, ADD_STA, 0) < 12)
1227 iwl_mvm_rm_aux_sta(mvm);
1229 iwl_mvm_stop_device(mvm);
1231 iwl_mvm_async_handlers_purge(mvm);
1232 /* async_handlers_list is empty and will stay empty: HW is stopped */
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->async_handlers_wk);
1267 flush_work(&mvm->add_stream_wk);
1270 * Lock and clear the firmware running bit here already, so that
1271 * new commands coming in elsewhere, e.g. from debugfs, will not
1272 * be able to proceed. This is important here because one of those
1273 * debugfs files causes the firmware dump to be triggered, and if we
1274 * don't stop debugfs accesses before canceling that it could be
1275 * retriggered after we flush it but before we've cleared the bit.
1277 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1279 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1280 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1283 * The work item could be running or queued if the
1284 * ROC time event stops just as we get here.
1286 flush_work(&mvm->roc_done_wk);
1288 mutex_lock(&mvm->mutex);
1289 __iwl_mvm_mac_stop(mvm);
1290 mutex_unlock(&mvm->mutex);
1293 * The worker might have been waiting for the mutex, let it run and
1294 * discover that its list is now empty.
1296 cancel_work_sync(&mvm->async_handlers_wk);
1299 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1303 lockdep_assert_held(&mvm->mutex);
1305 for (i = 0; i < NUM_PHY_CTX; i++)
1306 if (!mvm->phy_ctxts[i].ref)
1307 return &mvm->phy_ctxts[i];
1309 IWL_ERR(mvm, "No available PHY context\n");
1313 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1317 struct iwl_dev_tx_power_cmd cmd = {
1318 .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1319 .common.mac_context_id =
1320 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1321 .common.pwr_restriction = cpu_to_le16(8 * tx_power),
1323 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
1324 REDUCE_TX_POWER_CMD,
1325 IWL_FW_CMD_VER_UNKNOWN);
1327 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1328 cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1331 len = sizeof(cmd.v6);
1332 else if (fw_has_api(&mvm->fw->ucode_capa,
1333 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1334 len = sizeof(cmd.v5);
1335 else if (fw_has_capa(&mvm->fw->ucode_capa,
1336 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1337 len = sizeof(cmd.v4);
1339 len = sizeof(cmd.v3);
1341 /* all structs have the same common part, add it */
1342 len += sizeof(cmd.common);
1344 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1347 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
1348 struct ieee80211_vif *vif)
1350 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1351 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1354 mutex_lock(&mvm->mutex);
1356 if (mvmvif->csa_failed) {
1357 mvmvif->csa_failed = false;
1362 if (vif->type == NL80211_IFTYPE_STATION) {
1363 struct iwl_mvm_sta *mvmsta;
1365 mvmvif->csa_bcn_pending = false;
1366 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
1369 if (WARN_ON(!mvmsta)) {
1374 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
1376 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1378 if (!fw_has_capa(&mvm->fw->ucode_capa,
1379 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
1380 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1384 iwl_mvm_stop_session_protection(mvm, vif);
1388 mvmvif->ps_disabled = false;
1390 ret = iwl_mvm_power_update_ps(mvm);
1393 mutex_unlock(&mvm->mutex);
1398 static void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw,
1399 struct ieee80211_vif *vif)
1401 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1402 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1403 struct iwl_chan_switch_te_cmd cmd = {
1404 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1406 .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE),
1409 IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id);
1411 mutex_lock(&mvm->mutex);
1412 if (!fw_has_capa(&mvm->fw->ucode_capa,
1413 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
1414 iwl_mvm_remove_csa_period(mvm, vif);
1416 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
1417 WIDE_ID(MAC_CONF_GROUP,
1418 CHANNEL_SWITCH_TIME_EVENT_CMD),
1419 0, sizeof(cmd), &cmd));
1420 mutex_unlock(&mvm->mutex);
1422 WARN_ON(iwl_mvm_post_channel_switch(hw, vif));
1425 static void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk)
1427 struct iwl_mvm *mvm;
1428 struct iwl_mvm_vif *mvmvif;
1429 struct ieee80211_vif *vif;
1431 mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work);
1432 vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);
1435 iwl_mvm_abort_channel_switch(mvm->hw, vif);
1436 ieee80211_chswitch_done(vif, false);
1439 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1440 struct ieee80211_vif *vif)
1442 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1443 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1447 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1450 * Not much to do here. The stack will not allow interface
1451 * types or combinations that we didn't advertise, so we
1452 * don't really have to check the types.
1455 mutex_lock(&mvm->mutex);
1457 /* make sure that beacon statistics don't go backwards with FW reset */
1458 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1459 mvmvif->beacon_stats.accu_num_beacons +=
1460 mvmvif->beacon_stats.num_beacons;
1462 /* Allocate resources for the MAC context, and add it to the fw */
1463 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1467 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif);
1469 /* Counting number of interfaces is needed for legacy PM */
1470 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1474 * The AP binding flow can be done only after the beacon
1475 * template is configured (which happens only in the mac80211
1476 * start_ap() flow), and adding the broadcast station can happen
1477 * only after the binding.
1478 * In addition, since modifying the MAC before adding a bcast
1479 * station is not allowed by the FW, delay the adding of MAC context to
1480 * the point where we can also add the bcast station.
1481 * In short: there's not much we can do at this point, other than
1482 * allocating resources :)
1484 if (vif->type == NL80211_IFTYPE_AP ||
1485 vif->type == NL80211_IFTYPE_ADHOC) {
1486 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1488 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1493 * Only queue for this station is the mcast queue,
1494 * which shouldn't be in TFD mask anyway
1496 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1502 iwl_mvm_vif_dbgfs_register(mvm, vif);
1506 mvmvif->features |= hw->netdev_features;
1508 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1512 ret = iwl_mvm_power_update_mac(mvm);
1514 goto out_remove_mac;
1516 /* beacon filtering */
1517 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1519 goto out_remove_mac;
1521 if (!mvm->bf_allowed_vif &&
1522 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1523 mvm->bf_allowed_vif = mvmvif;
1524 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1525 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1529 * P2P_DEVICE interface does not have a channel context assigned to it,
1530 * so a dedicated PHY context is allocated to it and the corresponding
1531 * MAC context is bound to it at this stage.
1533 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1535 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1536 if (!mvmvif->phy_ctxt) {
1541 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1542 ret = iwl_mvm_binding_add_vif(mvm, vif);
1546 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1550 /* Save a pointer to p2p device vif, so it can later be used to
1551 * update the p2p device MAC when a GO is started/stopped */
1552 mvm->p2p_device_vif = vif;
1555 iwl_mvm_tcm_add_vif(mvm, vif);
1556 INIT_DELAYED_WORK(&mvmvif->csa_work,
1557 iwl_mvm_channel_switch_disconnect_wk);
1559 if (vif->type == NL80211_IFTYPE_MONITOR)
1560 mvm->monitor_on = true;
1562 iwl_mvm_vif_dbgfs_register(mvm, vif);
1566 iwl_mvm_binding_remove_vif(mvm, vif);
1568 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1570 if (mvm->bf_allowed_vif == mvmvif) {
1571 mvm->bf_allowed_vif = NULL;
1572 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1573 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1576 mvmvif->phy_ctxt = NULL;
1577 iwl_mvm_mac_ctxt_remove(mvm, vif);
1579 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1582 mutex_unlock(&mvm->mutex);
1587 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1588 struct ieee80211_vif *vif)
1590 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1592 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1593 * We assume here that all the packets sent to the OFFCHANNEL
1594 * queue are sent in ROC session.
1596 flush_work(&mvm->roc_done_wk);
1600 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1601 struct ieee80211_vif *vif)
1603 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1604 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1605 struct iwl_probe_resp_data *probe_data;
1607 iwl_mvm_prepare_mac_removal(mvm, vif);
1609 if (!(vif->type == NL80211_IFTYPE_AP ||
1610 vif->type == NL80211_IFTYPE_ADHOC))
1611 iwl_mvm_tcm_rm_vif(mvm, vif);
1613 mutex_lock(&mvm->mutex);
1615 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1616 lockdep_is_held(&mvm->mutex));
1617 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1619 kfree_rcu(probe_data, rcu_head);
1621 if (mvm->bf_allowed_vif == mvmvif) {
1622 mvm->bf_allowed_vif = NULL;
1623 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1624 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1627 if (vif->bss_conf.ftm_responder)
1628 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
1630 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1633 * For AP/GO interface, the tear down of the resources allocated to the
1634 * interface is be handled as part of the stop_ap flow.
1636 if (vif->type == NL80211_IFTYPE_AP ||
1637 vif->type == NL80211_IFTYPE_ADHOC) {
1638 #ifdef CONFIG_NL80211_TESTMODE
1639 if (vif == mvm->noa_vif) {
1640 mvm->noa_vif = NULL;
1641 mvm->noa_duration = 0;
1644 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1645 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1649 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1650 mvm->p2p_device_vif = NULL;
1651 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1652 iwl_mvm_binding_remove_vif(mvm, vif);
1653 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1654 mvmvif->phy_ctxt = NULL;
1657 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1660 iwl_mvm_power_update_mac(mvm);
1661 iwl_mvm_mac_ctxt_remove(mvm, vif);
1663 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL);
1665 if (vif->type == NL80211_IFTYPE_MONITOR)
1666 mvm->monitor_on = false;
1669 mutex_unlock(&mvm->mutex);
1672 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1677 struct iwl_mvm_mc_iter_data {
1678 struct iwl_mvm *mvm;
1682 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1683 struct ieee80211_vif *vif)
1685 struct iwl_mvm_mc_iter_data *data = _data;
1686 struct iwl_mvm *mvm = data->mvm;
1687 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1688 struct iwl_host_cmd hcmd = {
1689 .id = MCAST_FILTER_CMD,
1691 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1695 /* if we don't have free ports, mcast frames will be dropped */
1696 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1699 if (vif->type != NL80211_IFTYPE_STATION ||
1700 !vif->bss_conf.assoc)
1703 cmd->port_id = data->port_id++;
1704 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1705 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1710 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1712 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1715 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1717 struct iwl_mvm_mc_iter_data iter_data = {
1721 lockdep_assert_held(&mvm->mutex);
1723 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1726 ieee80211_iterate_active_interfaces_atomic(
1727 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1728 iwl_mvm_mc_iface_iterator, &iter_data);
1731 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1732 struct netdev_hw_addr_list *mc_list)
1734 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1735 struct iwl_mcast_filter_cmd *cmd;
1736 struct netdev_hw_addr *addr;
1741 addr_count = netdev_hw_addr_list_count(mc_list);
1742 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1743 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1747 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1748 cmd = kzalloc(len, GFP_ATOMIC);
1754 return (u64)(unsigned long)cmd;
1757 netdev_hw_addr_list_for_each(addr, mc_list) {
1758 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1759 cmd->count, addr->addr);
1760 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1761 addr->addr, ETH_ALEN);
1765 return (u64)(unsigned long)cmd;
1768 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1769 unsigned int changed_flags,
1770 unsigned int *total_flags,
1773 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1774 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1776 mutex_lock(&mvm->mutex);
1778 /* replace previous configuration */
1779 kfree(mvm->mcast_filter_cmd);
1780 mvm->mcast_filter_cmd = cmd;
1785 if (changed_flags & FIF_ALLMULTI)
1786 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1791 iwl_mvm_recalc_multicast(mvm);
1793 mutex_unlock(&mvm->mutex);
1797 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1798 struct ieee80211_vif *vif,
1799 unsigned int filter_flags,
1800 unsigned int changed_flags)
1802 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1804 /* We support only filter for probe requests */
1805 if (!(changed_flags & FIF_PROBE_REQ))
1808 /* Supported only for p2p client interfaces */
1809 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1813 mutex_lock(&mvm->mutex);
1814 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1815 mutex_unlock(&mvm->mutex);
1818 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1819 struct iwl_bcast_iter_data {
1820 struct iwl_mvm *mvm;
1821 struct iwl_bcast_filter_cmd *cmd;
1826 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1827 const struct iwl_fw_bcast_filter *in_filter,
1828 struct iwl_fw_bcast_filter *out_filter)
1830 struct iwl_fw_bcast_filter_attr *attr;
1833 memcpy(out_filter, in_filter, sizeof(*out_filter));
1835 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1836 attr = &out_filter->attrs[i];
1841 switch (attr->reserved1) {
1842 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1843 if (vif->bss_conf.arp_addr_cnt != 1) {
1848 attr->val = vif->bss_conf.arp_addr_list[0];
1850 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1851 attr->val = *(__be32 *)&vif->addr[2];
1856 attr->reserved1 = 0;
1857 out_filter->num_attrs++;
1861 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1862 struct ieee80211_vif *vif)
1864 struct iwl_bcast_iter_data *data = _data;
1865 struct iwl_mvm *mvm = data->mvm;
1866 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1867 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1868 struct iwl_fw_bcast_mac *bcast_mac;
1871 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1874 bcast_mac = &cmd->macs[mvmvif->id];
1877 * enable filtering only for associated stations, but not for P2P
1880 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1881 !vif->bss_conf.assoc)
1884 bcast_mac->default_discard = 1;
1886 /* copy all configured filters */
1887 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1889 * Make sure we don't exceed our filters limit.
1890 * if there is still a valid filter to be configured,
1891 * be on the safe side and just allow bcast for this mac.
1893 if (WARN_ON_ONCE(data->current_filter >=
1894 ARRAY_SIZE(cmd->filters))) {
1895 bcast_mac->default_discard = 0;
1896 bcast_mac->attached_filters = 0;
1900 iwl_mvm_set_bcast_filter(vif,
1901 &mvm->bcast_filters[i],
1902 &cmd->filters[data->current_filter]);
1904 /* skip current filter if it contains no attributes */
1905 if (!cmd->filters[data->current_filter].num_attrs)
1908 /* attach the filter to current mac */
1909 bcast_mac->attached_filters |=
1910 cpu_to_le16(BIT(data->current_filter));
1912 data->current_filter++;
1916 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1917 struct iwl_bcast_filter_cmd *cmd)
1919 struct iwl_bcast_iter_data iter_data = {
1924 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1927 memset(cmd, 0, sizeof(*cmd));
1928 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1929 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1931 #ifdef CONFIG_IWLWIFI_DEBUGFS
1932 /* use debugfs filters/macs if override is configured */
1933 if (mvm->dbgfs_bcast_filtering.override) {
1934 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1935 sizeof(cmd->filters));
1936 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1942 /* if no filters are configured, do nothing */
1943 if (!mvm->bcast_filters)
1946 /* configure and attach these filters for each associated sta vif */
1947 ieee80211_iterate_active_interfaces(
1948 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1949 iwl_mvm_bcast_filter_iterator, &iter_data);
1954 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1956 struct iwl_bcast_filter_cmd cmd;
1958 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1961 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1964 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1968 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1974 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1975 struct ieee80211_vif *vif)
1977 struct iwl_mu_group_mgmt_cmd cmd = {};
1979 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1980 WLAN_MEMBERSHIP_LEN);
1981 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1982 WLAN_USER_POSITION_LEN);
1984 return iwl_mvm_send_cmd_pdu(mvm,
1985 WIDE_ID(DATA_PATH_GROUP,
1986 UPDATE_MU_GROUPS_CMD),
1987 0, sizeof(cmd), &cmd);
1990 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1991 struct ieee80211_vif *vif)
1993 if (vif->mu_mimo_owner) {
1994 struct iwl_mu_group_mgmt_notif *notif = _data;
1997 * MU-MIMO Group Id action frame is little endian. We treat
1998 * the data received from firmware as if it came from the
1999 * action frame, so no conversion is needed.
2001 ieee80211_update_mu_groups(vif,
2002 (u8 *)¬if->membership_status,
2003 (u8 *)¬if->user_position);
2007 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
2008 struct iwl_rx_cmd_buffer *rxb)
2010 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2011 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
2013 ieee80211_iterate_active_interfaces_atomic(
2014 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
2015 iwl_mvm_mu_mimo_iface_iterator, notif);
2018 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
2020 u8 byte_num = ppe_pos_bit / 8;
2021 u8 bit_num = ppe_pos_bit % 8;
2026 return (ppe[byte_num] >> bit_num) &
2027 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
2030 * If bit_num > 5, we have to combine bits with next byte.
2031 * Calculate how many bits we need to take from current byte (called
2032 * here "residue_bits"), and add them to bits from next byte.
2035 residue_bits = 8 - bit_num;
2037 res = (ppe[byte_num + 1] &
2038 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
2040 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
2045 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
2046 struct ieee80211_vif *vif, u8 sta_id)
2048 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2049 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
2051 .tid_limit = IWL_MAX_TID_COUNT,
2052 .bss_color = vif->bss_conf.he_bss_color.color,
2053 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
2054 .frame_time_rts_th =
2055 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
2057 int size = fw_has_api(&mvm->fw->ucode_capa,
2058 IWL_UCODE_TLV_API_MBSSID_HE) ?
2059 sizeof(sta_ctxt_cmd) :
2060 sizeof(struct iwl_he_sta_context_cmd_v1);
2061 struct ieee80211_sta *sta;
2067 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
2068 if (IS_ERR_OR_NULL(sta)) {
2070 WARN(1, "Can't find STA to configure HE\n");
2074 if (!sta->he_cap.has_he) {
2081 /* Block 26-tone RU OFDMA transmissions */
2082 if (mvmvif->he_ru_2mhz_block)
2083 flags |= STA_CTXT_HE_RU_2MHZ_BLOCK;
2086 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
2087 IEEE80211_HE_MAC_CAP0_HTC_HE)
2088 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
2089 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
2090 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2091 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2092 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2094 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
2095 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2096 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
2097 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2100 sta_ctxt_cmd.htc_flags |=
2101 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2102 else if (link_adap == 3)
2103 sta_ctxt_cmd.htc_flags |=
2104 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2106 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2107 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2108 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2109 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2110 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2111 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2112 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2115 * Initialize the PPE thresholds to "None" (7), as described in Table
2116 * 9-262ac of 80211.ax/D3.0.
2118 memset(&sta_ctxt_cmd.pkt_ext, 7, sizeof(sta_ctxt_cmd.pkt_ext));
2120 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2121 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2122 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2123 u8 nss = (sta->he_cap.ppe_thres[0] &
2124 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2125 u8 ru_index_bitmap =
2126 (sta->he_cap.ppe_thres[0] &
2127 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2128 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2129 u8 *ppe = &sta->he_cap.ppe_thres[0];
2130 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2133 * FW currently supports only nss == MAX_HE_SUPP_NSS
2135 * If nss > MAX: we can ignore values we don't support
2136 * If nss < MAX: we can set zeros in other streams
2138 if (nss > MAX_HE_SUPP_NSS) {
2139 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2141 nss = MAX_HE_SUPP_NSS;
2144 for (i = 0; i < nss; i++) {
2145 u8 ru_index_tmp = ru_index_bitmap << 1;
2148 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2150 if (!(ru_index_tmp & 1))
2153 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2154 iwl_mvm_he_get_ppe_val(ppe,
2157 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2158 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2159 iwl_mvm_he_get_ppe_val(ppe,
2162 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2166 flags |= STA_CTXT_HE_PACKET_EXT;
2167 } else if ((sta->he_cap.he_cap_elem.phy_cap_info[9] &
2168 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) !=
2169 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_RESERVED) {
2173 /* Take the PPE thresholds from the nominal padding info */
2174 switch (sta->he_cap.he_cap_elem.phy_cap_info[9] &
2175 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) {
2176 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_0US:
2177 low_th = IWL_HE_PKT_EXT_NONE;
2178 high_th = IWL_HE_PKT_EXT_NONE;
2180 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_8US:
2181 low_th = IWL_HE_PKT_EXT_BPSK;
2182 high_th = IWL_HE_PKT_EXT_NONE;
2184 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US:
2185 low_th = IWL_HE_PKT_EXT_NONE;
2186 high_th = IWL_HE_PKT_EXT_BPSK;
2190 /* Set the PPE thresholds accordingly */
2191 if (low_th >= 0 && high_th >= 0) {
2192 struct iwl_he_pkt_ext *pkt_ext =
2193 (struct iwl_he_pkt_ext *)&sta_ctxt_cmd.pkt_ext;
2195 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
2198 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX;
2200 pkt_ext->pkt_ext_qam_th[i][bw][0] =
2202 pkt_ext->pkt_ext_qam_th[i][bw][1] =
2207 flags |= STA_CTXT_HE_PACKET_EXT;
2211 if (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2212 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP)
2213 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2215 if (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2216 IEEE80211_HE_MAC_CAP2_ACK_EN)
2217 flags |= STA_CTXT_HE_ACK_ENABLED;
2221 /* Mark MU EDCA as enabled, unless none detected on some AC */
2222 flags |= STA_CTXT_HE_MU_EDCA_CW;
2223 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
2224 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2225 &mvmvif->queue_params[i].mu_edca_param_rec;
2226 u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
2228 if (!mvmvif->queue_params[i].mu_edca) {
2229 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2233 sta_ctxt_cmd.trig_based_txf[ac].cwmin =
2234 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2235 sta_ctxt_cmd.trig_based_txf[ac].cwmax =
2236 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2237 sta_ctxt_cmd.trig_based_txf[ac].aifsn =
2238 cpu_to_le16(mu_edca->aifsn);
2239 sta_ctxt_cmd.trig_based_txf[ac].mu_time =
2240 cpu_to_le16(mu_edca->mu_edca_timer);
2244 if (vif->bss_conf.uora_exists) {
2245 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2247 sta_ctxt_cmd.rand_alloc_ecwmin =
2248 vif->bss_conf.uora_ocw_range & 0x7;
2249 sta_ctxt_cmd.rand_alloc_ecwmax =
2250 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2253 if (vif->bss_conf.nontransmitted) {
2254 flags |= STA_CTXT_HE_REF_BSSID_VALID;
2255 ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr,
2256 vif->bss_conf.transmitter_bssid);
2257 sta_ctxt_cmd.max_bssid_indicator =
2258 vif->bss_conf.bssid_indicator;
2259 sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index;
2260 sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap;
2261 sta_ctxt_cmd.profile_periodicity =
2262 vif->bss_conf.profile_periodicity;
2265 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2267 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2268 DATA_PATH_GROUP, 0),
2269 0, size, &sta_ctxt_cmd))
2270 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2273 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2274 struct ieee80211_vif *vif,
2275 struct ieee80211_bss_conf *bss_conf,
2278 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2282 * Re-calculate the tsf id, as the master-slave relations depend on the
2283 * beacon interval, which was not known when the station interface was
2286 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2287 if (vif->bss_conf.he_support &&
2288 !iwlwifi_mod_params.disable_11ax)
2289 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2291 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2294 /* Update MU EDCA params */
2295 if (changes & BSS_CHANGED_QOS && mvmvif->associated &&
2296 bss_conf->assoc && vif->bss_conf.he_support &&
2297 !iwlwifi_mod_params.disable_11ax)
2298 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2301 * If we're not associated yet, take the (new) BSSID before associating
2302 * so the firmware knows. If we're already associated, then use the old
2303 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2304 * branch for disassociation below.
2306 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2307 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2309 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2311 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2313 /* after sending it once, adopt mac80211 data */
2314 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2315 mvmvif->associated = bss_conf->assoc;
2317 if (changes & BSS_CHANGED_ASSOC) {
2318 if (bss_conf->assoc) {
2319 /* clear statistics to get clean beacon counter */
2320 iwl_mvm_request_statistics(mvm, true);
2321 memset(&mvmvif->beacon_stats, 0,
2322 sizeof(mvmvif->beacon_stats));
2324 /* add quota for this interface */
2325 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2327 IWL_ERR(mvm, "failed to update quotas\n");
2331 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2333 !fw_has_capa(&mvm->fw->ucode_capa,
2334 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) {
2336 * If we're restarting then the firmware will
2337 * obviously have lost synchronisation with
2338 * the AP. It will attempt to synchronise by
2339 * itself, but we can make it more reliable by
2340 * scheduling a session protection time event.
2342 * The firmware needs to receive a beacon to
2343 * catch up with synchronisation, use 110% of
2344 * the beacon interval.
2346 * Set a large maximum delay to allow for more
2347 * than a single interface.
2349 * For new firmware versions, rely on the
2350 * firmware. This is relevant for DCM scenarios
2353 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2354 iwl_mvm_protect_session(mvm, vif, dur, dur,
2358 iwl_mvm_sf_update(mvm, vif, false);
2359 iwl_mvm_power_vif_assoc(mvm, vif);
2361 iwl_mvm_update_smps(mvm, vif,
2362 IWL_MVM_SMPS_REQ_PROT,
2363 IEEE80211_SMPS_DYNAMIC);
2365 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2367 * If update fails - SF might be running in associated
2368 * mode while disassociated - which is forbidden.
2370 ret = iwl_mvm_sf_update(mvm, vif, false);
2372 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
2374 "Failed to update SF upon disassociation\n");
2377 * If we get an assert during the connection (after the
2378 * station has been added, but before the vif is set
2379 * to associated), mac80211 will re-add the station and
2380 * then configure the vif. Since the vif is not
2381 * associated, we would remove the station here and
2382 * this would fail the recovery.
2384 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2387 * Remove AP station now that
2388 * the MAC is unassoc
2390 ret = iwl_mvm_rm_sta_id(mvm, vif,
2394 "failed to remove AP station\n");
2396 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2399 /* remove quota for this interface */
2400 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2402 IWL_ERR(mvm, "failed to update quotas\n");
2404 /* this will take the cleared BSSID from bss_conf */
2405 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2408 "failed to update MAC %pM (clear after unassoc)\n",
2413 * The firmware tracks the MU-MIMO group on its own.
2414 * However, on HW restart we should restore this data.
2416 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2417 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2418 ret = iwl_mvm_update_mu_groups(mvm, vif);
2421 "failed to update VHT MU_MIMO groups\n");
2424 iwl_mvm_recalc_multicast(mvm);
2425 iwl_mvm_configure_bcast_filter(mvm);
2427 /* reset rssi values */
2428 mvmvif->bf_data.ave_beacon_signal = 0;
2430 iwl_mvm_bt_coex_vif_change(mvm);
2431 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2432 IEEE80211_SMPS_AUTOMATIC);
2433 if (fw_has_capa(&mvm->fw->ucode_capa,
2434 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2435 iwl_mvm_config_scan(mvm);
2438 if (changes & BSS_CHANGED_BEACON_INFO) {
2440 * We received a beacon from the associated AP so
2441 * remove the session protection.
2442 * A firmware with the new API will remove it automatically.
2444 if (!fw_has_capa(&mvm->fw->ucode_capa,
2445 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD))
2446 iwl_mvm_stop_session_protection(mvm, vif);
2448 iwl_mvm_sf_update(mvm, vif, false);
2449 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2452 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2454 * Send power command on every beacon change,
2455 * because we may have not enabled beacon abort yet.
2457 BSS_CHANGED_BEACON_INFO)) {
2458 ret = iwl_mvm_power_update_mac(mvm);
2460 IWL_ERR(mvm, "failed to update power mode\n");
2463 if (changes & BSS_CHANGED_TXPOWER) {
2464 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2466 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2469 if (changes & BSS_CHANGED_CQM) {
2470 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2471 /* reset cqm events tracking */
2472 mvmvif->bf_data.last_cqm_event = 0;
2473 if (mvmvif->bf_data.bf_enabled) {
2474 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2477 "failed to update CQM thresholds\n");
2481 if (changes & BSS_CHANGED_ARP_FILTER) {
2482 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2483 iwl_mvm_configure_bcast_filter(mvm);
2487 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2488 struct ieee80211_vif *vif)
2490 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2491 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2494 mutex_lock(&mvm->mutex);
2496 /* Send the beacon template */
2497 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2502 * Re-calculate the tsf id, as the master-slave relations depend on the
2503 * beacon interval, which was not known when the AP interface was added.
2505 if (vif->type == NL80211_IFTYPE_AP)
2506 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2508 mvmvif->ap_assoc_sta_count = 0;
2510 /* Add the mac context */
2511 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2515 /* Perform the binding */
2516 ret = iwl_mvm_binding_add_vif(mvm, vif);
2521 * This is not very nice, but the simplest:
2522 * For older FWs adding the mcast sta before the bcast station may
2523 * cause assert 0x2b00.
2524 * This is fixed in later FW so make the order of removal depend on
2527 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2528 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2532 * Send the bcast station. At this stage the TBTT and DTIM time
2533 * events are added and applied to the scheduler
2535 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2537 iwl_mvm_rm_mcast_sta(mvm, vif);
2542 * Send the bcast station. At this stage the TBTT and DTIM time
2543 * events are added and applied to the scheduler
2545 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2548 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2550 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2555 /* must be set before quota calculations */
2556 mvmvif->ap_ibss_active = true;
2558 /* send all the early keys to the device now */
2559 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
2560 struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i];
2565 mvmvif->ap_early_keys[i] = NULL;
2567 ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key);
2569 goto out_quota_failed;
2572 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2573 iwl_mvm_vif_set_low_latency(mvmvif, true,
2574 LOW_LATENCY_VIF_TYPE);
2575 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2578 /* power updated needs to be done before quotas */
2579 iwl_mvm_power_update_mac(mvm);
2581 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2583 goto out_quota_failed;
2585 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2586 if (vif->p2p && mvm->p2p_device_vif)
2587 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2589 iwl_mvm_bt_coex_vif_change(mvm);
2591 /* we don't support TDLS during DCM */
2592 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2593 iwl_mvm_teardown_tdls_peers(mvm);
2595 iwl_mvm_ftm_restart_responder(mvm, vif);
2600 iwl_mvm_power_update_mac(mvm);
2601 mvmvif->ap_ibss_active = false;
2602 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2603 iwl_mvm_rm_mcast_sta(mvm, vif);
2605 iwl_mvm_binding_remove_vif(mvm, vif);
2607 iwl_mvm_mac_ctxt_remove(mvm, vif);
2609 mutex_unlock(&mvm->mutex);
2613 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2614 struct ieee80211_vif *vif)
2616 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2617 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2619 iwl_mvm_prepare_mac_removal(mvm, vif);
2621 mutex_lock(&mvm->mutex);
2623 /* Handle AP stop while in CSA */
2624 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2625 iwl_mvm_remove_time_event(mvm, mvmvif,
2626 &mvmvif->time_event_data);
2627 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2628 mvmvif->csa_countdown = false;
2631 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2632 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2633 mvm->csa_tx_block_bcn_timeout = 0;
2636 mvmvif->ap_ibss_active = false;
2637 mvm->ap_last_beacon_gp2 = 0;
2639 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2640 iwl_mvm_vif_set_low_latency(mvmvif, false,
2641 LOW_LATENCY_VIF_TYPE);
2642 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2645 iwl_mvm_bt_coex_vif_change(mvm);
2647 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2648 if (vif->p2p && mvm->p2p_device_vif)
2649 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2651 iwl_mvm_update_quotas(mvm, false, NULL);
2653 iwl_mvm_ftm_responder_clear(mvm, vif);
2656 * This is not very nice, but the simplest:
2657 * For older FWs removing the mcast sta before the bcast station may
2658 * cause assert 0x2b00.
2659 * This is fixed in later FW (which will stop beaconing when removing
2661 * So make the order of removal depend on the TLV
2663 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2664 iwl_mvm_rm_mcast_sta(mvm, vif);
2665 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2666 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2667 iwl_mvm_rm_mcast_sta(mvm, vif);
2668 iwl_mvm_binding_remove_vif(mvm, vif);
2670 iwl_mvm_power_update_mac(mvm);
2672 iwl_mvm_mac_ctxt_remove(mvm, vif);
2674 mutex_unlock(&mvm->mutex);
2678 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2679 struct ieee80211_vif *vif,
2680 struct ieee80211_bss_conf *bss_conf,
2683 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2685 /* Changes will be applied when the AP/IBSS is started */
2686 if (!mvmvif->ap_ibss_active)
2689 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2690 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2691 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2692 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2694 /* Need to send a new beacon template to the FW */
2695 if (changes & BSS_CHANGED_BEACON &&
2696 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2697 IWL_WARN(mvm, "Failed updating beacon data\n");
2699 if (changes & BSS_CHANGED_TXPOWER) {
2700 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2702 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2705 if (changes & BSS_CHANGED_FTM_RESPONDER) {
2706 int ret = iwl_mvm_ftm_start_responder(mvm, vif);
2709 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
2715 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2716 struct ieee80211_vif *vif,
2717 struct ieee80211_bss_conf *bss_conf,
2720 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2722 mutex_lock(&mvm->mutex);
2724 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2725 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2727 switch (vif->type) {
2728 case NL80211_IFTYPE_STATION:
2729 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2731 case NL80211_IFTYPE_AP:
2732 case NL80211_IFTYPE_ADHOC:
2733 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2735 case NL80211_IFTYPE_MONITOR:
2736 if (changes & BSS_CHANGED_MU_GROUPS)
2737 iwl_mvm_update_mu_groups(mvm, vif);
2740 /* shouldn't happen */
2744 mutex_unlock(&mvm->mutex);
2747 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2748 struct ieee80211_vif *vif,
2749 struct ieee80211_scan_request *hw_req)
2751 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2754 if (hw_req->req.n_channels == 0 ||
2755 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2758 mutex_lock(&mvm->mutex);
2759 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2760 mutex_unlock(&mvm->mutex);
2765 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2766 struct ieee80211_vif *vif)
2768 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2770 mutex_lock(&mvm->mutex);
2772 /* Due to a race condition, it's possible that mac80211 asks
2773 * us to stop a hw_scan when it's already stopped. This can
2774 * happen, for instance, if we stopped the scan ourselves,
2775 * called ieee80211_scan_completed() and the userspace called
2776 * cancel scan scan before ieee80211_scan_work() could run.
2777 * To handle that, simply return if the scan is not running.
2779 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2780 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2782 mutex_unlock(&mvm->mutex);
2786 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2787 struct ieee80211_sta *sta, u16 tids,
2789 enum ieee80211_frame_release_type reason,
2792 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2794 /* Called when we need to transmit (a) frame(s) from mac80211 */
2796 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2797 tids, more_data, false);
2801 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2802 struct ieee80211_sta *sta, u16 tids,
2804 enum ieee80211_frame_release_type reason,
2807 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2809 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2811 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2812 tids, more_data, true);
2815 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2816 enum sta_notify_cmd cmd,
2817 struct ieee80211_sta *sta)
2819 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2820 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2821 unsigned long txqs = 0, tids = 0;
2825 * If we have TVQM then we get too high queue numbers - luckily
2826 * we really shouldn't get here with that because such hardware
2827 * should have firmware supporting buffer station offload.
2829 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2832 spin_lock_bh(&mvmsta->lock);
2833 for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) {
2834 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2836 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2839 __set_bit(tid_data->txq_id, &txqs);
2841 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2844 __set_bit(tid, &tids);
2848 case STA_NOTIFY_SLEEP:
2849 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2850 ieee80211_sta_set_buffered(sta, tid, true);
2853 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2855 * The fw updates the STA to be asleep. Tx packets on the Tx
2856 * queues to this station will not be transmitted. The fw will
2857 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2860 case STA_NOTIFY_AWAKE:
2861 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2865 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2866 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2871 spin_unlock_bh(&mvmsta->lock);
2874 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2875 struct ieee80211_vif *vif,
2876 enum sta_notify_cmd cmd,
2877 struct ieee80211_sta *sta)
2879 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2882 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2884 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2885 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2886 struct ieee80211_sta *sta;
2887 struct iwl_mvm_sta *mvmsta;
2888 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2890 if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations))
2894 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2895 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2900 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2903 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2908 if (mvmsta->sleeping != sleeping) {
2909 mvmsta->sleeping = sleeping;
2910 __iwl_mvm_mac_sta_notify(mvm->hw,
2911 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2913 ieee80211_sta_ps_transition(sta, sleeping);
2917 switch (notif->type) {
2918 case IWL_MVM_PM_EVENT_AWAKE:
2919 case IWL_MVM_PM_EVENT_ASLEEP:
2921 case IWL_MVM_PM_EVENT_UAPSD:
2922 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2924 case IWL_MVM_PM_EVENT_PS_POLL:
2925 ieee80211_sta_pspoll(sta);
2935 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2936 struct ieee80211_vif *vif,
2937 struct ieee80211_sta *sta)
2939 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2940 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2943 * This is called before mac80211 does RCU synchronisation,
2944 * so here we already invalidate our internal RCU-protected
2945 * station pointer. The rest of the code will thus no longer
2946 * be able to find the station this way, and we don't rely
2947 * on further RCU synchronisation after the sta_state()
2948 * callback deleted the station.
2950 mutex_lock(&mvm->mutex);
2951 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2952 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2955 mutex_unlock(&mvm->mutex);
2958 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2963 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2964 struct iwl_mvm_tcm_mac *mdata;
2966 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2967 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2968 mdata->opened_rx_ba_sessions = false;
2971 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2974 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2975 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2980 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2981 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2985 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2986 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2987 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2992 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2996 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2997 struct ieee80211_vif *vif, u8 *peer_addr,
2998 enum nl80211_tdls_operation action)
3000 struct iwl_fw_dbg_trigger_tlv *trig;
3001 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
3003 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
3004 FW_DBG_TRIGGER_TDLS);
3008 tdls_trig = (void *)trig->data;
3010 if (!(tdls_trig->action_bitmap & BIT(action)))
3013 if (tdls_trig->peer_mode &&
3014 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
3017 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
3018 "TDLS event occurred, peer %pM, action %d",
3022 struct iwl_mvm_he_obss_narrow_bw_ru_data {
3026 static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy,
3027 struct cfg80211_bss *bss,
3030 struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data;
3031 const struct element *elem;
3033 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, bss->ies->data,
3036 if (!elem || elem->datalen < 10 ||
3038 WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) {
3039 data->tolerated = false;
3043 static void iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw,
3044 struct ieee80211_vif *vif)
3046 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3047 struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = {
3051 if (!(vif->bss_conf.chandef.chan->flags & IEEE80211_CHAN_RADAR)) {
3052 mvmvif->he_ru_2mhz_block = false;
3056 cfg80211_bss_iter(hw->wiphy, &vif->bss_conf.chandef,
3057 iwl_mvm_check_he_obss_narrow_bw_ru_iter,
3061 * If there is at least one AP on radar channel that cannot
3062 * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
3064 mvmvif->he_ru_2mhz_block = !iter_data.tolerated;
3067 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
3068 struct ieee80211_vif *vif,
3069 struct ieee80211_sta *sta,
3070 enum ieee80211_sta_state old_state,
3071 enum ieee80211_sta_state new_state)
3073 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3074 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3075 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3078 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
3079 sta->addr, old_state, new_state);
3081 /* this would be a mac80211 bug ... but don't crash */
3082 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
3083 return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL;
3086 * If we are in a STA removal flow and in DQA mode:
3088 * This is after the sync_rcu part, so the queues have already been
3089 * flushed. No more TXs on their way in mac80211's path, and no more in
3091 * Also, we won't be getting any new TX frames for this station.
3092 * What we might have are deferred TX frames that need to be taken care
3095 * Drop any still-queued deferred-frame before removing the STA, and
3096 * make sure the worker is no longer handling frames for this STA.
3098 if (old_state == IEEE80211_STA_NONE &&
3099 new_state == IEEE80211_STA_NOTEXIST) {
3100 flush_work(&mvm->add_stream_wk);
3103 * No need to make sure deferred TX indication is off since the
3104 * worker will already remove it if it was on
3108 mutex_lock(&mvm->mutex);
3109 /* track whether or not the station is associated */
3110 mvm_sta->sta_state = new_state;
3112 if (old_state == IEEE80211_STA_NOTEXIST &&
3113 new_state == IEEE80211_STA_NONE) {
3115 * Firmware bug - it'll crash if the beacon interval is less
3116 * than 16. We can't avoid connecting at all, so refuse the
3117 * station state change, this will cause mac80211 to abandon
3118 * attempts to connect to this AP, and eventually wpa_s will
3119 * blacklist the AP...
3121 if (vif->type == NL80211_IFTYPE_STATION &&
3122 vif->bss_conf.beacon_int < 16) {
3124 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
3125 sta->addr, vif->bss_conf.beacon_int);
3130 if (vif->type == NL80211_IFTYPE_STATION)
3131 vif->bss_conf.he_support = sta->he_cap.has_he;
3135 iwl_mvm_tdls_sta_count(mvm, NULL) ==
3136 IWL_MVM_TDLS_STA_COUNT ||
3137 iwl_mvm_phy_ctx_count(mvm) > 1)) {
3138 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
3143 ret = iwl_mvm_add_sta(mvm, vif, sta);
3144 if (sta->tdls && ret == 0) {
3145 iwl_mvm_recalc_tdls_state(mvm, vif, true);
3146 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3147 NL80211_TDLS_SETUP);
3150 sta->max_rc_amsdu_len = 1;
3151 } else if (old_state == IEEE80211_STA_NONE &&
3152 new_state == IEEE80211_STA_AUTH) {
3154 * EBS may be disabled due to previous failures reported by FW.
3155 * Reset EBS status here assuming environment has been changed.
3157 mvm->last_ebs_successful = true;
3158 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
3160 } else if (old_state == IEEE80211_STA_AUTH &&
3161 new_state == IEEE80211_STA_ASSOC) {
3162 if (vif->type == NL80211_IFTYPE_AP) {
3163 vif->bss_conf.he_support = sta->he_cap.has_he;
3164 mvmvif->ap_assoc_sta_count++;
3165 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3166 if (vif->bss_conf.he_support &&
3167 !iwlwifi_mod_params.disable_11ax)
3168 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id);
3169 } else if (vif->type == NL80211_IFTYPE_STATION) {
3170 vif->bss_conf.he_support = sta->he_cap.has_he;
3172 mvmvif->he_ru_2mhz_block = false;
3173 if (sta->he_cap.has_he)
3174 iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif);
3176 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3179 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3181 ret = iwl_mvm_update_sta(mvm, vif, sta);
3182 } else if (old_state == IEEE80211_STA_ASSOC &&
3183 new_state == IEEE80211_STA_AUTHORIZED) {
3186 /* we don't support TDLS during DCM */
3187 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3188 iwl_mvm_teardown_tdls_peers(mvm);
3191 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3192 NL80211_TDLS_ENABLE_LINK);
3194 /* enable beacon filtering */
3195 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
3198 * Now that the station is authorized, i.e., keys were already
3199 * installed, need to indicate to the FW that
3200 * multicast data frames can be forwarded to the driver
3202 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3204 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3206 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3207 new_state == IEEE80211_STA_ASSOC) {
3208 /* Multicast data frames are no longer allowed */
3209 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3211 /* disable beacon filtering */
3212 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3214 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3217 } else if (old_state == IEEE80211_STA_ASSOC &&
3218 new_state == IEEE80211_STA_AUTH) {
3219 if (vif->type == NL80211_IFTYPE_AP) {
3220 mvmvif->ap_assoc_sta_count--;
3221 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3224 } else if (old_state == IEEE80211_STA_AUTH &&
3225 new_state == IEEE80211_STA_NONE) {
3227 } else if (old_state == IEEE80211_STA_NONE &&
3228 new_state == IEEE80211_STA_NOTEXIST) {
3229 ret = iwl_mvm_rm_sta(mvm, vif, sta);
3231 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3232 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3233 NL80211_TDLS_DISABLE_LINK);
3237 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3244 mutex_unlock(&mvm->mutex);
3246 if (sta->tdls && ret == 0) {
3247 if (old_state == IEEE80211_STA_NOTEXIST &&
3248 new_state == IEEE80211_STA_NONE)
3249 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3250 else if (old_state == IEEE80211_STA_NONE &&
3251 new_state == IEEE80211_STA_NOTEXIST)
3252 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3258 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3260 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3262 mvm->rts_threshold = value;
3267 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3268 struct ieee80211_vif *vif,
3269 struct ieee80211_sta *sta, u32 changed)
3271 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3272 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3274 if (changed & (IEEE80211_RC_BW_CHANGED |
3275 IEEE80211_RC_SUPP_RATES_CHANGED |
3276 IEEE80211_RC_NSS_CHANGED))
3277 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3280 if (vif->type == NL80211_IFTYPE_STATION &&
3281 changed & IEEE80211_RC_NSS_CHANGED)
3282 iwl_mvm_sf_update(mvm, vif, false);
3285 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3286 struct ieee80211_vif *vif, u16 ac,
3287 const struct ieee80211_tx_queue_params *params)
3289 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3290 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3292 mvmvif->queue_params[ac] = *params;
3295 * No need to update right away, we'll get BSS_CHANGED_QOS
3296 * The exception is P2P_DEVICE interface which needs immediate update.
3298 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3301 mutex_lock(&mvm->mutex);
3302 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3303 mutex_unlock(&mvm->mutex);
3309 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3310 struct ieee80211_vif *vif,
3313 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3314 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3315 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3317 if (req_duration > duration)
3318 duration = req_duration;
3320 mutex_lock(&mvm->mutex);
3321 /* Try really hard to protect the session and hear a beacon
3322 * The new session protection command allows us to protect the
3323 * session for a much longer time since the firmware will internally
3324 * create two events: a 300TU one with a very high priority that
3325 * won't be fragmented which should be enough for 99% of the cases,
3326 * and another one (which we configure here to be 900TU long) which
3327 * will have a slightly lower priority, but more importantly, can be
3328 * fragmented so that it'll allow other activities to run.
3330 if (fw_has_capa(&mvm->fw->ucode_capa,
3331 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD))
3332 iwl_mvm_schedule_session_protection(mvm, vif, 900,
3333 min_duration, false);
3335 iwl_mvm_protect_session(mvm, vif, duration,
3336 min_duration, 500, false);
3337 mutex_unlock(&mvm->mutex);
3340 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3341 struct ieee80211_vif *vif,
3342 struct cfg80211_sched_scan_request *req,
3343 struct ieee80211_scan_ies *ies)
3345 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3349 mutex_lock(&mvm->mutex);
3351 if (!vif->bss_conf.idle) {
3356 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3359 mutex_unlock(&mvm->mutex);
3363 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3364 struct ieee80211_vif *vif)
3366 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3369 mutex_lock(&mvm->mutex);
3371 /* Due to a race condition, it's possible that mac80211 asks
3372 * us to stop a sched_scan when it's already stopped. This
3373 * can happen, for instance, if we stopped the scan ourselves,
3374 * called ieee80211_sched_scan_stopped() and the userspace called
3375 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3376 * could run. To handle this, simply return if the scan is
3379 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3380 mutex_unlock(&mvm->mutex);
3384 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3385 mutex_unlock(&mvm->mutex);
3386 iwl_mvm_wait_for_async_handlers(mvm);
3391 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3392 enum set_key_cmd cmd,
3393 struct ieee80211_vif *vif,
3394 struct ieee80211_sta *sta,
3395 struct ieee80211_key_conf *key)
3397 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3398 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3399 struct iwl_mvm_sta *mvmsta;
3400 struct iwl_mvm_key_pn *ptk_pn;
3401 int keyidx = key->keyidx;
3405 switch (key->cipher) {
3406 case WLAN_CIPHER_SUITE_TKIP:
3407 if (!mvm->trans->trans_cfg->gen2) {
3408 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3409 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3410 } else if (vif->type == NL80211_IFTYPE_STATION) {
3411 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3413 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3417 case WLAN_CIPHER_SUITE_CCMP:
3418 case WLAN_CIPHER_SUITE_GCMP:
3419 case WLAN_CIPHER_SUITE_GCMP_256:
3420 if (!iwl_mvm_has_new_tx_api(mvm))
3421 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3423 case WLAN_CIPHER_SUITE_AES_CMAC:
3424 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3425 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3426 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3428 case WLAN_CIPHER_SUITE_WEP40:
3429 case WLAN_CIPHER_SUITE_WEP104:
3430 if (vif->type == NL80211_IFTYPE_STATION)
3432 if (iwl_mvm_has_new_tx_api(mvm))
3434 /* support HW crypto on TX */
3437 /* currently FW supports only one optional cipher scheme */
3438 if (hw->n_cipher_schemes &&
3439 hw->cipher_schemes->cipher == key->cipher)
3440 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3447 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3448 vif->type == NL80211_IFTYPE_AP) && !sta) {
3450 * GTK on AP interface is a TX-only key, return 0;
3451 * on IBSS they're per-station and because we're lazy
3452 * we don't support them for RX, so do the same.
3453 * CMAC/GMAC in AP/IBSS modes must be done in software.
3455 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3456 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3457 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) {
3462 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3463 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3464 !iwl_mvm_has_new_tx_api(mvm)) {
3465 key->hw_key_idx = STA_KEY_IDX_INVALID;
3470 if (!mvmvif->ap_ibss_active) {
3472 i < ARRAY_SIZE(mvmvif->ap_early_keys);
3474 if (!mvmvif->ap_early_keys[i]) {
3475 mvmvif->ap_early_keys[i] = key;
3480 if (i >= ARRAY_SIZE(mvmvif->ap_early_keys))
3489 /* During FW restart, in order to restore the state as it was,
3490 * don't try to reprogram keys we previously failed for.
3492 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3493 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3494 IWL_DEBUG_MAC80211(mvm,
3495 "skip invalid idx key programming during restart\n");
3500 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3501 sta && iwl_mvm_has_new_rx_api(mvm) &&
3502 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3503 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3504 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3505 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3506 struct ieee80211_key_seq seq;
3509 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3510 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3511 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3512 mvm->trans->num_rx_queues),
3519 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3520 ieee80211_get_key_rx_seq(key, tid, &seq);
3521 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3522 memcpy(ptk_pn->q[q].pn[tid],
3524 IEEE80211_CCMP_PN_LEN);
3527 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3530 /* in HW restart reuse the index, otherwise request a new one */
3531 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3532 key_offset = key->hw_key_idx;
3534 key_offset = STA_KEY_IDX_INVALID;
3536 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3537 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3539 IWL_WARN(mvm, "set key failed\n");
3540 key->hw_key_idx = STA_KEY_IDX_INVALID;
3542 * can't add key for RX, but we don't need it
3543 * in the device for TX so still return 0,
3544 * unless we have new TX API where we cannot
3545 * put key material into the TX_CMD
3547 if (iwl_mvm_has_new_tx_api(mvm))
3556 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
3557 if (mvmvif->ap_early_keys[i] == key) {
3558 mvmvif->ap_early_keys[i] = NULL;
3563 /* found in pending list - don't do anything else */
3567 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3572 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3573 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3574 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3575 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3576 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3577 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3578 ptk_pn = rcu_dereference_protected(
3579 mvmsta->ptk_pn[keyidx],
3580 lockdep_is_held(&mvm->mutex));
3581 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3583 kfree_rcu(ptk_pn, rcu_head);
3586 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3587 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3596 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3597 enum set_key_cmd cmd,
3598 struct ieee80211_vif *vif,
3599 struct ieee80211_sta *sta,
3600 struct ieee80211_key_conf *key)
3602 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3605 mutex_lock(&mvm->mutex);
3606 ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key);
3607 mutex_unlock(&mvm->mutex);
3612 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3613 struct ieee80211_vif *vif,
3614 struct ieee80211_key_conf *keyconf,
3615 struct ieee80211_sta *sta,
3616 u32 iv32, u16 *phase1key)
3618 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3620 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3623 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3627 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3628 struct iwl_rx_packet *pkt, void *data)
3630 struct iwl_mvm *mvm =
3631 container_of(notif_wait, struct iwl_mvm, notif_wait);
3632 struct iwl_hs20_roc_res *resp;
3633 int resp_len = iwl_rx_packet_payload_len(pkt);
3634 struct iwl_mvm_time_event_data *te_data = data;
3636 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3639 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3640 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3644 resp = (void *)pkt->data;
3647 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
3648 resp->status, resp->event_unique_id);
3650 te_data->uid = le32_to_cpu(resp->event_unique_id);
3651 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3654 spin_lock_bh(&mvm->time_event_lock);
3655 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3656 spin_unlock_bh(&mvm->time_event_lock);
3661 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3662 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3663 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3664 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3665 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3666 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3667 struct ieee80211_channel *channel,
3668 struct ieee80211_vif *vif,
3672 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3673 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3674 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3675 struct iwl_notification_wait wait_time_event;
3676 u32 dtim_interval = vif->bss_conf.dtim_period *
3677 vif->bss_conf.beacon_int;
3679 struct iwl_hs20_roc_req aux_roc_req = {
3680 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3682 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3683 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3685 struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm,
3686 &aux_roc_req.channel_info);
3687 u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm);
3689 /* Set the channel info data */
3690 iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value,
3691 iwl_mvm_phy_band_from_nl80211(channel->band),
3692 PHY_VHT_CHANNEL_MODE20,
3695 /* Set the time and duration */
3696 tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm));
3698 delay = AUX_ROC_MIN_DELAY;
3699 req_dur = MSEC_TO_TU(duration);
3702 * If we are associated we want the delay time to be at least one
3703 * dtim interval so that the FW can wait until after the DTIM and
3704 * then start the time event, this will potentially allow us to
3705 * remain off-channel for the max duration.
3706 * Since we want to use almost a whole dtim interval we would also
3707 * like the delay to be for 2-3 dtim intervals, in case there are
3708 * other time events with higher priority.
3710 if (vif->bss_conf.assoc) {
3711 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3712 /* We cannot remain off-channel longer than the DTIM interval */
3713 if (dtim_interval <= req_dur) {
3714 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3715 if (req_dur <= AUX_ROC_MIN_DURATION)
3716 req_dur = dtim_interval -
3717 AUX_ROC_MIN_SAFETY_BUFFER;
3721 tail->duration = cpu_to_le32(req_dur);
3722 tail->apply_time_max_delay = cpu_to_le32(delay);
3725 "ROC: Requesting to remain on channel %u for %ums\n",
3726 channel->hw_value, req_dur);
3728 "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3729 duration, delay, dtim_interval);
3731 /* Set the node address */
3732 memcpy(tail->node_addr, vif->addr, ETH_ALEN);
3734 lockdep_assert_held(&mvm->mutex);
3736 spin_lock_bh(&mvm->time_event_lock);
3738 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3739 spin_unlock_bh(&mvm->time_event_lock);
3744 te_data->duration = duration;
3745 te_data->id = HOT_SPOT_CMD;
3747 spin_unlock_bh(&mvm->time_event_lock);
3750 * Use a notification wait, which really just processes the
3751 * command response and doesn't wait for anything, in order
3752 * to be able to process the response and get the UID inside
3753 * the RX path. Using CMD_WANT_SKB doesn't work because it
3754 * stores the buffer and then wakes up this thread, by which
3755 * time another notification (that the time event started)
3756 * might already be processed unsuccessfully.
3758 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3759 time_event_response,
3760 ARRAY_SIZE(time_event_response),
3761 iwl_mvm_rx_aux_roc, te_data);
3763 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len,
3767 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3768 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3772 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3773 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3774 /* should never fail */
3779 spin_lock_bh(&mvm->time_event_lock);
3780 iwl_mvm_te_clear_data(mvm, te_data);
3781 spin_unlock_bh(&mvm->time_event_lock);
3787 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3788 struct ieee80211_vif *vif,
3789 struct ieee80211_channel *channel,
3791 enum ieee80211_roc_type type)
3793 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3794 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3795 struct cfg80211_chan_def chandef;
3796 struct iwl_mvm_phy_ctxt *phy_ctxt;
3799 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3803 * Flush the done work, just in case it's still pending, so that
3804 * the work it does can complete and we can accept new frames.
3806 flush_work(&mvm->roc_done_wk);
3808 mutex_lock(&mvm->mutex);
3810 switch (vif->type) {
3811 case NL80211_IFTYPE_STATION:
3812 if (fw_has_capa(&mvm->fw->ucode_capa,
3813 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3814 /* Use aux roc framework (HS20) */
3815 if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
3816 ADD_STA, 0) >= 12) {
3819 lmac_id = iwl_mvm_get_lmac_id(mvm->fw,
3821 ret = iwl_mvm_add_aux_sta(mvm, lmac_id);
3823 "Failed to allocate aux station"))
3826 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3830 IWL_ERR(mvm, "hotspot not supported\n");
3833 case NL80211_IFTYPE_P2P_DEVICE:
3837 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3842 for (i = 0; i < NUM_PHY_CTX; i++) {
3843 phy_ctxt = &mvm->phy_ctxts[i];
3844 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3847 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3849 * Unbind the P2P_DEVICE from the current PHY context,
3850 * and if the PHY context is not used remove it.
3852 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3853 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3856 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3858 /* Bind the P2P_DEVICE to the current PHY Context */
3859 mvmvif->phy_ctxt = phy_ctxt;
3861 ret = iwl_mvm_binding_add_vif(mvm, vif);
3862 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3865 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3866 goto schedule_time_event;
3870 /* Need to update the PHY context only if the ROC channel changed */
3871 if (channel == mvmvif->phy_ctxt->channel)
3872 goto schedule_time_event;
3874 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3877 * Change the PHY context configuration as it is currently referenced
3878 * only by the P2P Device MAC
3880 if (mvmvif->phy_ctxt->ref == 1) {
3881 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3887 * The PHY context is shared with other MACs. Need to remove the
3888 * P2P Device from the binding, allocate an new PHY context and
3889 * create a new binding
3891 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3897 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3900 IWL_ERR(mvm, "Failed to change PHY context\n");
3904 /* Unbind the P2P_DEVICE from the current PHY context */
3905 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3906 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3909 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3911 /* Bind the P2P_DEVICE to the new allocated PHY context */
3912 mvmvif->phy_ctxt = phy_ctxt;
3914 ret = iwl_mvm_binding_add_vif(mvm, vif);
3915 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3918 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3921 schedule_time_event:
3922 /* Schedule the time events */
3923 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3926 mutex_unlock(&mvm->mutex);
3927 IWL_DEBUG_MAC80211(mvm, "leave\n");
3931 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw,
3932 struct ieee80211_vif *vif)
3934 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3936 IWL_DEBUG_MAC80211(mvm, "enter\n");
3938 mutex_lock(&mvm->mutex);
3939 iwl_mvm_stop_roc(mvm, vif);
3940 mutex_unlock(&mvm->mutex);
3942 IWL_DEBUG_MAC80211(mvm, "leave\n");
3946 struct iwl_mvm_ftm_responder_iter_data {
3948 struct ieee80211_chanctx_conf *ctx;
3951 static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac,
3952 struct ieee80211_vif *vif)
3954 struct iwl_mvm_ftm_responder_iter_data *data = _data;
3956 if (rcu_access_pointer(vif->chanctx_conf) == data->ctx &&
3957 vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params)
3958 data->responder = true;
3961 static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm,
3962 struct ieee80211_chanctx_conf *ctx)
3964 struct iwl_mvm_ftm_responder_iter_data data = {
3969 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
3970 IEEE80211_IFACE_ITER_NORMAL,
3971 iwl_mvm_ftm_responder_chanctx_iter,
3973 return data.responder;
3976 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3977 struct ieee80211_chanctx_conf *ctx)
3979 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3980 struct iwl_mvm_phy_ctxt *phy_ctxt;
3981 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
3982 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
3985 lockdep_assert_held(&mvm->mutex);
3987 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3989 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3995 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
3996 ctx->rx_chains_static,
3997 ctx->rx_chains_dynamic);
3999 IWL_ERR(mvm, "Failed to add PHY context\n");
4003 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
4004 *phy_ctxt_id = phy_ctxt->id;
4009 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
4010 struct ieee80211_chanctx_conf *ctx)
4012 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4015 mutex_lock(&mvm->mutex);
4016 ret = __iwl_mvm_add_chanctx(mvm, ctx);
4017 mutex_unlock(&mvm->mutex);
4022 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
4023 struct ieee80211_chanctx_conf *ctx)
4025 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4026 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4028 lockdep_assert_held(&mvm->mutex);
4030 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
4033 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
4034 struct ieee80211_chanctx_conf *ctx)
4036 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4038 mutex_lock(&mvm->mutex);
4039 __iwl_mvm_remove_chanctx(mvm, ctx);
4040 mutex_unlock(&mvm->mutex);
4043 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
4044 struct ieee80211_chanctx_conf *ctx,
4047 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4048 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4049 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4050 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4051 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
4053 if (WARN_ONCE((phy_ctxt->ref > 1) &&
4054 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
4055 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
4056 IEEE80211_CHANCTX_CHANGE_RADAR |
4057 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
4058 "Cannot change PHY. Ref=%d, changed=0x%X\n",
4059 phy_ctxt->ref, changed))
4062 mutex_lock(&mvm->mutex);
4064 /* we are only changing the min_width, may be a noop */
4065 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
4066 if (phy_ctxt->width == def->width)
4069 /* we are just toggling between 20_NOHT and 20 */
4070 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
4071 def->width <= NL80211_CHAN_WIDTH_20)
4075 iwl_mvm_bt_coex_vif_change(mvm);
4076 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4077 ctx->rx_chains_static,
4078 ctx->rx_chains_dynamic);
4081 mutex_unlock(&mvm->mutex);
4084 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
4085 struct ieee80211_vif *vif,
4086 struct ieee80211_chanctx_conf *ctx,
4087 bool switching_chanctx)
4089 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4090 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4091 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4094 lockdep_assert_held(&mvm->mutex);
4096 mvmvif->phy_ctxt = phy_ctxt;
4098 switch (vif->type) {
4099 case NL80211_IFTYPE_AP:
4100 /* only needed if we're switching chanctx (i.e. during CSA) */
4101 if (switching_chanctx) {
4102 mvmvif->ap_ibss_active = true;
4106 case NL80211_IFTYPE_ADHOC:
4108 * The AP binding flow is handled as part of the start_ap flow
4109 * (in bss_info_changed), similarly for IBSS.
4113 case NL80211_IFTYPE_STATION:
4114 mvmvif->csa_bcn_pending = false;
4116 case NL80211_IFTYPE_MONITOR:
4117 /* always disable PS when a monitor interface is active */
4118 mvmvif->ps_disabled = true;
4125 ret = iwl_mvm_binding_add_vif(mvm, vif);
4130 * Power state must be updated before quotas,
4131 * otherwise fw will complain.
4133 iwl_mvm_power_update_mac(mvm);
4135 /* Setting the quota at this stage is only required for monitor
4136 * interfaces. For the other types, the bss_info changed flow
4137 * will handle quota settings.
4139 if (vif->type == NL80211_IFTYPE_MONITOR) {
4140 mvmvif->monitor_active = true;
4141 ret = iwl_mvm_update_quotas(mvm, false, NULL);
4143 goto out_remove_binding;
4145 ret = iwl_mvm_add_snif_sta(mvm, vif);
4147 goto out_remove_binding;
4151 /* Handle binding during CSA */
4152 if (vif->type == NL80211_IFTYPE_AP) {
4153 iwl_mvm_update_quotas(mvm, false, NULL);
4154 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4157 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
4158 mvmvif->csa_bcn_pending = true;
4160 if (!fw_has_capa(&mvm->fw->ucode_capa,
4161 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4162 u32 duration = 3 * vif->bss_conf.beacon_int;
4164 /* Protect the session to make sure we hear the first
4165 * beacon on the new channel.
4167 iwl_mvm_protect_session(mvm, vif, duration, duration,
4168 vif->bss_conf.beacon_int / 2,
4172 iwl_mvm_update_quotas(mvm, false, NULL);
4178 iwl_mvm_binding_remove_vif(mvm, vif);
4179 iwl_mvm_power_update_mac(mvm);
4182 mvmvif->phy_ctxt = NULL;
4185 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
4186 struct ieee80211_vif *vif,
4187 struct ieee80211_chanctx_conf *ctx)
4189 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4192 mutex_lock(&mvm->mutex);
4193 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
4194 mutex_unlock(&mvm->mutex);
4199 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
4200 struct ieee80211_vif *vif,
4201 struct ieee80211_chanctx_conf *ctx,
4202 bool switching_chanctx)
4204 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4205 struct ieee80211_vif *disabled_vif = NULL;
4207 lockdep_assert_held(&mvm->mutex);
4209 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
4211 switch (vif->type) {
4212 case NL80211_IFTYPE_ADHOC:
4214 case NL80211_IFTYPE_MONITOR:
4215 mvmvif->monitor_active = false;
4216 mvmvif->ps_disabled = false;
4217 iwl_mvm_rm_snif_sta(mvm, vif);
4219 case NL80211_IFTYPE_AP:
4220 /* This part is triggered only during CSA */
4221 if (!switching_chanctx || !mvmvif->ap_ibss_active)
4224 mvmvif->csa_countdown = false;
4226 /* Set CS bit on all the stations */
4227 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
4229 /* Save blocked iface, the timeout is set on the next beacon */
4230 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
4232 mvmvif->ap_ibss_active = false;
4234 case NL80211_IFTYPE_STATION:
4235 if (!switching_chanctx)
4240 if (!fw_has_capa(&mvm->fw->ucode_capa,
4241 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
4242 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
4248 iwl_mvm_update_quotas(mvm, false, disabled_vif);
4249 iwl_mvm_binding_remove_vif(mvm, vif);
4252 mvmvif->phy_ctxt = NULL;
4253 iwl_mvm_power_update_mac(mvm);
4256 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
4257 struct ieee80211_vif *vif,
4258 struct ieee80211_chanctx_conf *ctx)
4260 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4262 mutex_lock(&mvm->mutex);
4263 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
4264 mutex_unlock(&mvm->mutex);
4268 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
4269 struct ieee80211_vif_chanctx_switch *vifs)
4273 mutex_lock(&mvm->mutex);
4274 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4275 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
4277 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
4279 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
4283 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4287 "failed to assign new_ctx during channel switch\n");
4291 /* we don't support TDLS during DCM - can be caused by channel switch */
4292 if (iwl_mvm_phy_ctx_count(mvm) > 1)
4293 iwl_mvm_teardown_tdls_peers(mvm);
4298 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
4301 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
4302 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
4306 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4308 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4315 /* things keep failing, better restart the hw */
4316 iwl_mvm_nic_restart(mvm, false);
4319 mutex_unlock(&mvm->mutex);
4325 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
4326 struct ieee80211_vif_chanctx_switch *vifs)
4330 mutex_lock(&mvm->mutex);
4331 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4333 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4337 "failed to assign new_ctx during channel switch\n");
4344 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4346 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4353 /* things keep failing, better restart the hw */
4354 iwl_mvm_nic_restart(mvm, false);
4357 mutex_unlock(&mvm->mutex);
4362 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4363 struct ieee80211_vif_chanctx_switch *vifs,
4365 enum ieee80211_chanctx_switch_mode mode)
4367 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4370 /* we only support a single-vif right now */
4375 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4376 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4378 case CHANCTX_SWMODE_REASSIGN_VIF:
4379 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4389 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4391 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4393 return mvm->ibss_manager;
4396 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4397 struct ieee80211_sta *sta,
4400 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4401 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4403 if (!mvm_sta || !mvm_sta->vif) {
4404 IWL_ERR(mvm, "Station is not associated to a vif\n");
4408 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4411 #ifdef CONFIG_NL80211_TESTMODE
4412 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4413 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4414 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4415 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4418 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4419 struct ieee80211_vif *vif,
4420 void *data, int len)
4422 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4426 err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len,
4427 iwl_mvm_tm_policy, NULL);
4431 if (!tb[IWL_MVM_TM_ATTR_CMD])
4434 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4435 case IWL_MVM_TM_CMD_SET_NOA:
4436 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4437 !vif->bss_conf.enable_beacon ||
4438 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4441 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4442 if (noa_duration >= vif->bss_conf.beacon_int)
4445 mvm->noa_duration = noa_duration;
4448 return iwl_mvm_update_quotas(mvm, true, NULL);
4449 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4450 /* must be associated client vif - ignore authorized */
4451 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4452 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4453 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4456 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4457 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4458 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4464 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4465 struct ieee80211_vif *vif,
4466 void *data, int len)
4468 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4471 mutex_lock(&mvm->mutex);
4472 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4473 mutex_unlock(&mvm->mutex);
4479 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4480 struct ieee80211_vif *vif,
4481 struct ieee80211_channel_switch *chsw)
4483 /* By implementing this operation, we prevent mac80211 from
4484 * starting its own channel switch timer, so that we can call
4485 * ieee80211_chswitch_done() ourselves at the right time
4486 * (which is when the absence time event starts).
4489 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4490 "dummy channel switch op\n");
4493 static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm,
4494 struct ieee80211_vif *vif,
4495 struct ieee80211_channel_switch *chsw)
4497 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4498 struct iwl_chan_switch_te_cmd cmd = {
4499 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4501 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
4502 .tsf = cpu_to_le32(chsw->timestamp),
4503 .cs_count = chsw->count,
4504 .cs_mode = chsw->block_tx,
4507 lockdep_assert_held(&mvm->mutex);
4510 cmd.cs_delayed_bcn_count =
4511 DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int);
4513 return iwl_mvm_send_cmd_pdu(mvm,
4514 WIDE_ID(MAC_CONF_GROUP,
4515 CHANNEL_SWITCH_TIME_EVENT_CMD),
4516 0, sizeof(cmd), &cmd);
4519 static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm,
4520 struct ieee80211_vif *vif,
4521 struct ieee80211_channel_switch *chsw)
4523 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4526 /* Schedule the time event to a bit before beacon 1,
4527 * to make sure we're in the new channel when the
4528 * GO/AP arrives. In case count <= 1 immediately schedule the
4529 * TE (this might result with some packet loss or connection
4532 if (chsw->count <= 1)
4535 apply_time = chsw->device_timestamp +
4536 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4537 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4540 iwl_mvm_csa_client_absent(mvm, vif);
4542 if (mvmvif->bf_data.bf_enabled) {
4543 int ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4549 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4555 #define IWL_MAX_CSA_BLOCK_TX 1500
4556 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4557 struct ieee80211_vif *vif,
4558 struct ieee80211_channel_switch *chsw)
4560 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4561 struct ieee80211_vif *csa_vif;
4562 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4565 mutex_lock(&mvm->mutex);
4567 mvmvif->csa_failed = false;
4569 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4570 chsw->chandef.center_freq1);
4572 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4573 ieee80211_vif_to_wdev(vif),
4574 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4576 switch (vif->type) {
4577 case NL80211_IFTYPE_AP:
4579 rcu_dereference_protected(mvm->csa_vif,
4580 lockdep_is_held(&mvm->mutex));
4581 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4582 "Another CSA is already in progress")) {
4587 /* we still didn't unblock tx. prevent new CS meanwhile */
4588 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4589 lockdep_is_held(&mvm->mutex))) {
4594 rcu_assign_pointer(mvm->csa_vif, vif);
4596 if (WARN_ONCE(mvmvif->csa_countdown,
4597 "Previous CSA countdown didn't complete")) {
4602 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4605 case NL80211_IFTYPE_STATION:
4606 if (chsw->block_tx) {
4608 * In case of undetermined / long time with immediate
4609 * quiet monitor status to gracefully disconnect
4612 chsw->count * vif->bss_conf.beacon_int >
4613 IWL_MAX_CSA_BLOCK_TX)
4614 schedule_delayed_work(&mvmvif->csa_work,
4615 msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX));
4618 if (!fw_has_capa(&mvm->fw->ucode_capa,
4619 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4620 ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw);
4624 iwl_mvm_schedule_client_csa(mvm, vif, chsw);
4627 mvmvif->csa_count = chsw->count;
4628 mvmvif->csa_misbehave = false;
4634 mvmvif->ps_disabled = true;
4636 ret = iwl_mvm_power_update_ps(mvm);
4640 /* we won't be on this channel any longer */
4641 iwl_mvm_teardown_tdls_peers(mvm);
4644 mutex_unlock(&mvm->mutex);
4649 static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw,
4650 struct ieee80211_vif *vif,
4651 struct ieee80211_channel_switch *chsw)
4653 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4654 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4655 struct iwl_chan_switch_te_cmd cmd = {
4656 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4658 .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY),
4659 .tsf = cpu_to_le32(chsw->timestamp),
4660 .cs_count = chsw->count,
4661 .cs_mode = chsw->block_tx,
4664 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY))
4667 if (chsw->count >= mvmvif->csa_count && chsw->block_tx) {
4668 if (mvmvif->csa_misbehave) {
4669 /* Second time, give up on this AP*/
4670 iwl_mvm_abort_channel_switch(hw, vif);
4671 ieee80211_chswitch_done(vif, false);
4672 mvmvif->csa_misbehave = false;
4675 mvmvif->csa_misbehave = true;
4677 mvmvif->csa_count = chsw->count;
4679 IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d\n", mvmvif->id);
4681 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
4682 WIDE_ID(MAC_CONF_GROUP,
4683 CHANNEL_SWITCH_TIME_EVENT_CMD),
4684 CMD_ASYNC, sizeof(cmd), &cmd));
4687 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4691 if (!iwl_mvm_has_new_tx_api(mvm)) {
4693 mutex_lock(&mvm->mutex);
4694 iwl_mvm_flush_tx_path(mvm,
4695 iwl_mvm_flushable_queues(mvm) & queues, 0);
4696 mutex_unlock(&mvm->mutex);
4698 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4703 mutex_lock(&mvm->mutex);
4704 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
4705 struct ieee80211_sta *sta;
4707 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4708 lockdep_is_held(&mvm->mutex));
4709 if (IS_ERR_OR_NULL(sta))
4713 iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF, 0);
4715 iwl_mvm_wait_sta_queues_empty(mvm,
4716 iwl_mvm_sta_from_mac80211(sta));
4718 mutex_unlock(&mvm->mutex);
4721 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4722 struct ieee80211_vif *vif, u32 queues, bool drop)
4724 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4725 struct iwl_mvm_vif *mvmvif;
4726 struct iwl_mvm_sta *mvmsta;
4727 struct ieee80211_sta *sta;
4732 iwl_mvm_flush_no_vif(mvm, queues, drop);
4736 if (vif->type != NL80211_IFTYPE_STATION)
4739 /* Make sure we're done with the deferred traffic before flushing */
4740 flush_work(&mvm->add_stream_wk);
4742 mutex_lock(&mvm->mutex);
4743 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4745 /* flush the AP-station and all TDLS peers */
4746 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
4747 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4748 lockdep_is_held(&mvm->mutex));
4749 if (IS_ERR_OR_NULL(sta))
4752 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4753 if (mvmsta->vif != vif)
4756 /* make sure only TDLS peers or the AP are flushed */
4757 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4760 if (iwl_mvm_flush_sta(mvm, mvmsta, false))
4761 IWL_ERR(mvm, "flush request fail\n");
4763 msk |= mvmsta->tfd_queue_msk;
4764 if (iwl_mvm_has_new_tx_api(mvm))
4765 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4769 mutex_unlock(&mvm->mutex);
4771 /* this can take a while, and we may need/want other operations
4772 * to succeed while doing this, so do it without the mutex held
4774 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4775 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4778 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4779 struct survey_info *survey)
4781 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4784 memset(survey, 0, sizeof(*survey));
4786 /* only support global statistics right now */
4790 if (!fw_has_capa(&mvm->fw->ucode_capa,
4791 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4794 mutex_lock(&mvm->mutex);
4796 if (iwl_mvm_firmware_running(mvm)) {
4797 ret = iwl_mvm_request_statistics(mvm, false);
4802 survey->filled = SURVEY_INFO_TIME |
4803 SURVEY_INFO_TIME_RX |
4804 SURVEY_INFO_TIME_TX |
4805 SURVEY_INFO_TIME_SCAN;
4806 survey->time = mvm->accu_radio_stats.on_time_rf +
4807 mvm->radio_stats.on_time_rf;
4808 do_div(survey->time, USEC_PER_MSEC);
4810 survey->time_rx = mvm->accu_radio_stats.rx_time +
4811 mvm->radio_stats.rx_time;
4812 do_div(survey->time_rx, USEC_PER_MSEC);
4814 survey->time_tx = mvm->accu_radio_stats.tx_time +
4815 mvm->radio_stats.tx_time;
4816 do_div(survey->time_tx, USEC_PER_MSEC);
4818 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4819 mvm->radio_stats.on_time_scan;
4820 do_div(survey->time_scan, USEC_PER_MSEC);
4824 mutex_unlock(&mvm->mutex);
4828 static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo)
4830 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
4831 case RATE_MCS_CHAN_WIDTH_20:
4832 rinfo->bw = RATE_INFO_BW_20;
4834 case RATE_MCS_CHAN_WIDTH_40:
4835 rinfo->bw = RATE_INFO_BW_40;
4837 case RATE_MCS_CHAN_WIDTH_80:
4838 rinfo->bw = RATE_INFO_BW_80;
4840 case RATE_MCS_CHAN_WIDTH_160:
4841 rinfo->bw = RATE_INFO_BW_160;
4845 if (rate_n_flags & RATE_MCS_HT_MSK) {
4846 rinfo->flags |= RATE_INFO_FLAGS_MCS;
4847 rinfo->mcs = u32_get_bits(rate_n_flags, RATE_HT_MCS_INDEX_MSK);
4848 rinfo->nss = u32_get_bits(rate_n_flags,
4849 RATE_HT_MCS_NSS_MSK) + 1;
4850 if (rate_n_flags & RATE_MCS_SGI_MSK)
4851 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
4852 } else if (rate_n_flags & RATE_MCS_VHT_MSK) {
4853 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
4854 rinfo->mcs = u32_get_bits(rate_n_flags,
4855 RATE_VHT_MCS_RATE_CODE_MSK);
4856 rinfo->nss = u32_get_bits(rate_n_flags,
4857 RATE_VHT_MCS_NSS_MSK) + 1;
4858 if (rate_n_flags & RATE_MCS_SGI_MSK)
4859 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
4860 } else if (rate_n_flags & RATE_MCS_HE_MSK) {
4861 u32 gi_ltf = u32_get_bits(rate_n_flags,
4862 RATE_MCS_HE_GI_LTF_MSK);
4864 rinfo->flags |= RATE_INFO_FLAGS_HE_MCS;
4865 rinfo->mcs = u32_get_bits(rate_n_flags,
4866 RATE_VHT_MCS_RATE_CODE_MSK);
4867 rinfo->nss = u32_get_bits(rate_n_flags,
4868 RATE_VHT_MCS_NSS_MSK) + 1;
4870 if (rate_n_flags & RATE_MCS_HE_106T_MSK) {
4871 rinfo->bw = RATE_INFO_BW_HE_RU;
4872 rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106;
4875 switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) {
4876 case RATE_MCS_HE_TYPE_SU:
4877 case RATE_MCS_HE_TYPE_EXT_SU:
4878 if (gi_ltf == 0 || gi_ltf == 1)
4879 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
4880 else if (gi_ltf == 2)
4881 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
4882 else if (rate_n_flags & RATE_MCS_SGI_MSK)
4883 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
4885 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
4887 case RATE_MCS_HE_TYPE_MU:
4888 if (gi_ltf == 0 || gi_ltf == 1)
4889 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
4890 else if (gi_ltf == 2)
4891 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
4893 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
4895 case RATE_MCS_HE_TYPE_TRIG:
4896 if (gi_ltf == 0 || gi_ltf == 1)
4897 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
4899 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
4903 if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK)
4906 switch (u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK)) {
4907 case IWL_RATE_1M_PLCP:
4910 case IWL_RATE_2M_PLCP:
4913 case IWL_RATE_5M_PLCP:
4916 case IWL_RATE_11M_PLCP:
4917 rinfo->legacy = 110;
4919 case IWL_RATE_6M_PLCP:
4922 case IWL_RATE_9M_PLCP:
4925 case IWL_RATE_12M_PLCP:
4926 rinfo->legacy = 120;
4928 case IWL_RATE_18M_PLCP:
4929 rinfo->legacy = 180;
4931 case IWL_RATE_24M_PLCP:
4932 rinfo->legacy = 240;
4934 case IWL_RATE_36M_PLCP:
4935 rinfo->legacy = 360;
4937 case IWL_RATE_48M_PLCP:
4938 rinfo->legacy = 480;
4940 case IWL_RATE_54M_PLCP:
4941 rinfo->legacy = 540;
4947 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4948 struct ieee80211_vif *vif,
4949 struct ieee80211_sta *sta,
4950 struct station_info *sinfo)
4952 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4953 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4954 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4956 if (mvmsta->avg_energy) {
4957 sinfo->signal_avg = -(s8)mvmsta->avg_energy;
4958 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4961 if (iwl_mvm_has_tlc_offload(mvm)) {
4962 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
4964 iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate);
4965 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
4968 /* if beacon filtering isn't on mac80211 does it anyway */
4969 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4972 if (!vif->bss_conf.assoc)
4975 mutex_lock(&mvm->mutex);
4977 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4980 if (iwl_mvm_request_statistics(mvm, false))
4983 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4984 mvmvif->beacon_stats.accu_num_beacons;
4985 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
4986 if (mvmvif->beacon_stats.avg_signal) {
4987 /* firmware only reports a value after RXing a few beacons */
4988 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4989 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4992 mutex_unlock(&mvm->mutex);
4995 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4996 struct ieee80211_vif *vif,
4997 const struct ieee80211_event *event)
4999 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
5001 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
5003 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
5006 struct iwl_fw_dbg_trigger_tlv *trig;
5007 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
5009 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5010 FW_DBG_TRIGGER_MLME);
5014 trig_mlme = (void *)trig->data;
5016 if (event->u.mlme.data == ASSOC_EVENT) {
5017 if (event->u.mlme.status == MLME_DENIED)
5018 CHECK_MLME_TRIGGER(stop_assoc_denied,
5019 "DENIED ASSOC: reason %d",
5020 event->u.mlme.reason);
5021 else if (event->u.mlme.status == MLME_TIMEOUT)
5022 CHECK_MLME_TRIGGER(stop_assoc_timeout,
5024 } else if (event->u.mlme.data == AUTH_EVENT) {
5025 if (event->u.mlme.status == MLME_DENIED)
5026 CHECK_MLME_TRIGGER(stop_auth_denied,
5027 "DENIED AUTH: reason %d",
5028 event->u.mlme.reason);
5029 else if (event->u.mlme.status == MLME_TIMEOUT)
5030 CHECK_MLME_TRIGGER(stop_auth_timeout,
5032 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
5033 CHECK_MLME_TRIGGER(stop_rx_deauth,
5034 "DEAUTH RX %d", event->u.mlme.reason);
5035 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
5036 CHECK_MLME_TRIGGER(stop_tx_deauth,
5037 "DEAUTH TX %d", event->u.mlme.reason);
5039 #undef CHECK_MLME_TRIGGER
5042 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
5043 struct ieee80211_vif *vif,
5044 const struct ieee80211_event *event)
5046 struct iwl_fw_dbg_trigger_tlv *trig;
5047 struct iwl_fw_dbg_trigger_ba *ba_trig;
5049 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5054 ba_trig = (void *)trig->data;
5056 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
5059 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
5060 "BAR received from %pM, tid %d, ssn %d",
5061 event->u.ba.sta->addr, event->u.ba.tid,
5065 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
5066 struct ieee80211_vif *vif,
5067 const struct ieee80211_event *event)
5069 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5071 switch (event->type) {
5073 iwl_mvm_event_mlme_callback(mvm, vif, event);
5076 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
5078 case BA_FRAME_TIMEOUT:
5079 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
5087 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
5088 struct iwl_mvm_internal_rxq_notif *notif,
5091 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
5095 if (!iwl_mvm_has_new_rx_api(mvm))
5099 notif->cookie = mvm->queue_sync_cookie;
5100 atomic_set(&mvm->queue_sync_counter,
5101 mvm->trans->num_rx_queues);
5104 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif,
5105 size, !notif->sync);
5107 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
5112 lockdep_assert_held(&mvm->mutex);
5113 ret = wait_event_timeout(mvm->rx_sync_waitq,
5114 atomic_read(&mvm->queue_sync_counter) == 0 ||
5115 iwl_mvm_is_radio_killed(mvm),
5117 WARN_ON_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm));
5121 atomic_set(&mvm->queue_sync_counter, 0);
5123 mvm->queue_sync_cookie++;
5126 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
5128 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5129 struct iwl_mvm_internal_rxq_notif data = {
5130 .type = IWL_MVM_RXQ_EMPTY,
5134 mutex_lock(&mvm->mutex);
5135 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
5136 mutex_unlock(&mvm->mutex);
5140 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw,
5141 struct ieee80211_vif *vif,
5142 struct cfg80211_ftm_responder_stats *stats)
5144 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5145 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5147 if (vif->p2p || vif->type != NL80211_IFTYPE_AP ||
5148 !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder)
5151 mutex_lock(&mvm->mutex);
5152 *stats = mvm->ftm_resp_stats;
5153 mutex_unlock(&mvm->mutex);
5155 stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) |
5156 BIT(NL80211_FTM_STATS_PARTIAL_NUM) |
5157 BIT(NL80211_FTM_STATS_FAILED_NUM) |
5158 BIT(NL80211_FTM_STATS_ASAP_NUM) |
5159 BIT(NL80211_FTM_STATS_NON_ASAP_NUM) |
5160 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) |
5161 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) |
5162 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) |
5163 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM);
5168 static int iwl_mvm_start_pmsr(struct ieee80211_hw *hw,
5169 struct ieee80211_vif *vif,
5170 struct cfg80211_pmsr_request *request)
5172 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5175 mutex_lock(&mvm->mutex);
5176 ret = iwl_mvm_ftm_start(mvm, vif, request);
5177 mutex_unlock(&mvm->mutex);
5182 static void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw,
5183 struct ieee80211_vif *vif,
5184 struct cfg80211_pmsr_request *request)
5186 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5188 mutex_lock(&mvm->mutex);
5189 iwl_mvm_ftm_abort(mvm, request);
5190 mutex_unlock(&mvm->mutex);
5193 static bool iwl_mvm_can_hw_csum(struct sk_buff *skb)
5195 u8 protocol = ip_hdr(skb)->protocol;
5197 if (!IS_ENABLED(CONFIG_INET))
5200 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
5203 static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw,
5204 struct sk_buff *head,
5205 struct sk_buff *skb)
5207 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5209 /* For now don't aggregate IPv6 in AMSDU */
5210 if (skb->protocol != htons(ETH_P_IP))
5213 if (!iwl_mvm_is_csum_supported(mvm))
5216 return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head);
5219 const struct ieee80211_ops iwl_mvm_hw_ops = {
5220 .tx = iwl_mvm_mac_tx,
5221 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue,
5222 .ampdu_action = iwl_mvm_mac_ampdu_action,
5223 .get_antenna = iwl_mvm_op_get_antenna,
5224 .start = iwl_mvm_mac_start,
5225 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
5226 .stop = iwl_mvm_mac_stop,
5227 .add_interface = iwl_mvm_mac_add_interface,
5228 .remove_interface = iwl_mvm_mac_remove_interface,
5229 .config = iwl_mvm_mac_config,
5230 .prepare_multicast = iwl_mvm_prepare_multicast,
5231 .configure_filter = iwl_mvm_configure_filter,
5232 .config_iface_filter = iwl_mvm_config_iface_filter,
5233 .bss_info_changed = iwl_mvm_bss_info_changed,
5234 .hw_scan = iwl_mvm_mac_hw_scan,
5235 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
5236 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
5237 .sta_state = iwl_mvm_mac_sta_state,
5238 .sta_notify = iwl_mvm_mac_sta_notify,
5239 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
5240 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
5241 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
5242 .sta_rc_update = iwl_mvm_sta_rc_update,
5243 .conf_tx = iwl_mvm_mac_conf_tx,
5244 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
5245 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
5246 .flush = iwl_mvm_mac_flush,
5247 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
5248 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
5249 .set_key = iwl_mvm_mac_set_key,
5250 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
5251 .remain_on_channel = iwl_mvm_roc,
5252 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
5253 .add_chanctx = iwl_mvm_add_chanctx,
5254 .remove_chanctx = iwl_mvm_remove_chanctx,
5255 .change_chanctx = iwl_mvm_change_chanctx,
5256 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
5257 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
5258 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
5260 .start_ap = iwl_mvm_start_ap_ibss,
5261 .stop_ap = iwl_mvm_stop_ap_ibss,
5262 .join_ibss = iwl_mvm_start_ap_ibss,
5263 .leave_ibss = iwl_mvm_stop_ap_ibss,
5265 .tx_last_beacon = iwl_mvm_tx_last_beacon,
5267 .set_tim = iwl_mvm_set_tim,
5269 .channel_switch = iwl_mvm_channel_switch,
5270 .pre_channel_switch = iwl_mvm_pre_channel_switch,
5271 .post_channel_switch = iwl_mvm_post_channel_switch,
5272 .abort_channel_switch = iwl_mvm_abort_channel_switch,
5273 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon,
5275 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
5276 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
5277 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
5279 .event_callback = iwl_mvm_mac_event_callback,
5281 .sync_rx_queues = iwl_mvm_sync_rx_queues,
5283 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
5285 #ifdef CONFIG_PM_SLEEP
5287 .suspend = iwl_mvm_suspend,
5288 .resume = iwl_mvm_resume,
5289 .set_wakeup = iwl_mvm_set_wakeup,
5290 .set_rekey_data = iwl_mvm_set_rekey_data,
5291 #if IS_ENABLED(CONFIG_IPV6)
5292 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
5294 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
5296 .get_survey = iwl_mvm_mac_get_survey,
5297 .sta_statistics = iwl_mvm_mac_sta_statistics,
5298 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats,
5299 .start_pmsr = iwl_mvm_start_pmsr,
5300 .abort_pmsr = iwl_mvm_abort_pmsr,
5302 .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate,
5303 #ifdef CONFIG_IWLWIFI_DEBUGFS
5304 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,