1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 Intel Deutschland GmbH
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
26 * The full GNU General Public License is included in this distribution
27 * in the file called COPYING.
29 * Contact Information:
30 * Intel Linux Wireless <linuxwifi@intel.com>
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
35 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
36 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
37 * All rights reserved.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
43 * * Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * * Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in
47 * the documentation and/or other materials provided with the
49 * * Neither the name Intel Corporation nor the names of its
50 * contributors may be used to endorse or promote products derived
51 * from this software without specific prior written permission.
53 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
54 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
55 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
56 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
57 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
59 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
63 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 *****************************************************************************/
66 #include <linux/kernel.h>
67 #include <linux/slab.h>
68 #include <linux/skbuff.h>
69 #include <linux/netdevice.h>
70 #include <linux/etherdevice.h>
72 #include <linux/if_arp.h>
73 #include <linux/time.h>
74 #include <net/mac80211.h>
75 #include <net/ieee80211_radiotap.h>
78 #include "iwl-op-mode.h"
82 #include "time-event.h"
83 #include "iwl-eeprom-parse.h"
84 #include "iwl-phy-db.h"
86 #include "iwl-fw-error-dump.h"
88 #include "iwl-nvm-parse.h"
91 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
94 .types = BIT(NL80211_IFTYPE_STATION),
98 .types = BIT(NL80211_IFTYPE_AP) |
99 BIT(NL80211_IFTYPE_P2P_CLIENT) |
100 BIT(NL80211_IFTYPE_P2P_GO),
104 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
108 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
110 .num_different_channels = 2,
112 .limits = iwl_mvm_limits,
113 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
117 #ifdef CONFIG_PM_SLEEP
118 static const struct nl80211_wowlan_tcp_data_token_feature
119 iwl_mvm_wowlan_tcp_token_feature = {
122 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
125 static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
126 .tok = &iwl_mvm_wowlan_tcp_token_feature,
127 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
128 sizeof(struct ethhdr) -
129 sizeof(struct iphdr) -
130 sizeof(struct tcphdr),
131 .data_interval_max = 65535, /* __le16 in API */
132 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
133 sizeof(struct ethhdr) -
134 sizeof(struct iphdr) -
135 sizeof(struct tcphdr),
140 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
142 * Use the reserved field to indicate magic values.
143 * these values will only be used internally by the driver,
144 * and won't make it to the fw (reserved will be 0).
145 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
146 * be the vif's ip address. in case there is not a single
147 * ip address (0, or more than 1), this attribute will
149 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
150 * the LSB bytes of the vif's mac address
153 BC_FILTER_MAGIC_NONE = 0,
158 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
162 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
165 /* frame type - arp, hw type - ethernet */
167 BCAST_FILTER_OFFSET_PAYLOAD_START,
168 .offset = sizeof(rfc1042_header),
169 .val = cpu_to_be32(0x08060001),
170 .mask = cpu_to_be32(0xffffffff),
175 BCAST_FILTER_OFFSET_PAYLOAD_START,
176 .offset = sizeof(rfc1042_header) + 2 +
177 sizeof(struct arphdr) +
178 ETH_ALEN + sizeof(__be32) +
180 .mask = cpu_to_be32(0xffffffff),
181 /* mark it as special field */
182 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
187 /* dhcp offer bcast */
189 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
192 /* udp dest port - 68 (bootp client)*/
193 .offset_type = BCAST_FILTER_OFFSET_IP_END,
194 .offset = offsetof(struct udphdr, dest),
195 .val = cpu_to_be32(0x00440000),
196 .mask = cpu_to_be32(0xffff0000),
199 /* dhcp - lsb bytes of client hw address */
200 .offset_type = BCAST_FILTER_OFFSET_IP_END,
202 .mask = cpu_to_be32(0xffffffff),
203 /* mark it as special field */
204 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
208 /* last filter must be empty */
213 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
215 if (!iwl_mvm_is_d0i3_supported(mvm))
218 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
219 spin_lock_bh(&mvm->refs_lock);
220 mvm->refs[ref_type]++;
221 spin_unlock_bh(&mvm->refs_lock);
222 iwl_trans_ref(mvm->trans);
225 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
227 if (!iwl_mvm_is_d0i3_supported(mvm))
230 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
231 spin_lock_bh(&mvm->refs_lock);
232 if (WARN_ON(!mvm->refs[ref_type])) {
233 spin_unlock_bh(&mvm->refs_lock);
236 mvm->refs[ref_type]--;
237 spin_unlock_bh(&mvm->refs_lock);
238 iwl_trans_unref(mvm->trans);
241 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
242 enum iwl_mvm_ref_type except_ref)
246 if (!iwl_mvm_is_d0i3_supported(mvm))
249 spin_lock_bh(&mvm->refs_lock);
250 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
251 if (except_ref == i || !mvm->refs[i])
254 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
256 for (j = 0; j < mvm->refs[i]; j++)
257 iwl_trans_unref(mvm->trans);
260 spin_unlock_bh(&mvm->refs_lock);
263 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
268 if (!iwl_mvm_is_d0i3_supported(mvm))
271 spin_lock_bh(&mvm->refs_lock);
272 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
278 spin_unlock_bh(&mvm->refs_lock);
283 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
285 iwl_mvm_ref(mvm, ref_type);
287 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
288 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
291 iwl_mvm_unref(mvm, ref_type);
298 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
302 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
303 for (i = 0; i < NUM_PHY_CTX; i++) {
304 mvm->phy_ctxts[i].id = i;
305 mvm->phy_ctxts[i].ref = 0;
309 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
311 enum iwl_mcc_source src_id,
314 struct ieee80211_regdomain *regd = NULL;
315 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
316 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
317 struct iwl_mcc_update_resp *resp;
319 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
321 lockdep_assert_held(&mvm->mutex);
323 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
324 if (IS_ERR_OR_NULL(resp)) {
325 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
326 PTR_ERR_OR_ZERO(resp));
331 u32 status = le32_to_cpu(resp->status);
333 *changed = (status == MCC_RESP_NEW_CHAN_PROFILE ||
334 status == MCC_RESP_ILLEGAL);
337 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
338 __le32_to_cpu(resp->n_channels),
340 __le16_to_cpu(resp->mcc));
341 /* Store the return source id */
342 src_id = resp->source_id;
344 if (IS_ERR_OR_NULL(regd)) {
345 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
346 PTR_ERR_OR_ZERO(regd));
350 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
351 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
352 mvm->lar_regdom_set = true;
353 mvm->mcc_src = src_id;
359 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
362 struct ieee80211_regdomain *regd;
364 if (!iwl_mvm_is_lar_supported(mvm))
367 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
368 if (!IS_ERR_OR_NULL(regd)) {
369 /* only update the regulatory core if changed */
371 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
377 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
380 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
381 iwl_mvm_is_wifi_mcc_supported(mvm) ?
382 MCC_SOURCE_GET_CURRENT :
383 MCC_SOURCE_OLD_FW, changed);
386 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
388 enum iwl_mcc_source used_src;
389 struct ieee80211_regdomain *regd;
392 const struct ieee80211_regdomain *r =
393 rtnl_dereference(mvm->hw->wiphy->regd);
398 /* save the last source in case we overwrite it below */
399 used_src = mvm->mcc_src;
400 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
401 /* Notify the firmware we support wifi location updates */
402 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
403 if (!IS_ERR_OR_NULL(regd))
407 /* Now set our last stored MCC and source */
408 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
410 if (IS_ERR_OR_NULL(regd))
413 /* update cfg80211 if the regdomain was changed */
415 ret = regulatory_set_wiphy_regd_sync_rtnl(mvm->hw->wiphy, regd);
423 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
425 struct ieee80211_hw *hw = mvm->hw;
427 static const u32 mvm_ciphers[] = {
428 WLAN_CIPHER_SUITE_WEP40,
429 WLAN_CIPHER_SUITE_WEP104,
430 WLAN_CIPHER_SUITE_TKIP,
431 WLAN_CIPHER_SUITE_CCMP,
434 /* Tell mac80211 our characteristics */
435 ieee80211_hw_set(hw, SIGNAL_DBM);
436 ieee80211_hw_set(hw, SPECTRUM_MGMT);
437 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
438 ieee80211_hw_set(hw, QUEUE_CONTROL);
439 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
440 ieee80211_hw_set(hw, SUPPORTS_PS);
441 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
442 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
443 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
444 ieee80211_hw_set(hw, CONNECTION_MONITOR);
445 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
446 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
447 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
448 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
449 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
450 if (iwl_mvm_has_new_rx_api(mvm))
451 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
453 if (mvm->trans->num_rx_queues > 1)
454 ieee80211_hw_set(hw, USES_RSS);
456 if (mvm->trans->max_skb_frags)
457 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
459 if (!iwl_mvm_is_dqa_supported(mvm))
460 hw->queues = mvm->first_agg_queue;
462 hw->queues = IEEE80211_MAX_QUEUES;
463 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
464 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
465 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
466 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
467 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
468 hw->rate_control_algorithm = "iwl-mvm-rs";
469 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
470 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
472 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
473 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
474 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
475 hw->wiphy->cipher_suites = mvm->ciphers;
477 if (iwl_mvm_has_new_rx_api(mvm)) {
478 mvm->ciphers[hw->wiphy->n_cipher_suites] =
479 WLAN_CIPHER_SUITE_GCMP;
480 hw->wiphy->n_cipher_suites++;
481 mvm->ciphers[hw->wiphy->n_cipher_suites] =
482 WLAN_CIPHER_SUITE_GCMP_256;
483 hw->wiphy->n_cipher_suites++;
486 /* Enable 11w if software crypto is not enabled (as the
487 * firmware will interpret some mgmt packets, so enabling it
488 * with software crypto isn't safe).
490 if (!iwlwifi_mod_params.sw_crypto) {
491 ieee80211_hw_set(hw, MFP_CAPABLE);
492 mvm->ciphers[hw->wiphy->n_cipher_suites] =
493 WLAN_CIPHER_SUITE_AES_CMAC;
494 hw->wiphy->n_cipher_suites++;
495 if (iwl_mvm_has_new_rx_api(mvm)) {
496 mvm->ciphers[hw->wiphy->n_cipher_suites] =
497 WLAN_CIPHER_SUITE_BIP_GMAC_128;
498 hw->wiphy->n_cipher_suites++;
499 mvm->ciphers[hw->wiphy->n_cipher_suites] =
500 WLAN_CIPHER_SUITE_BIP_GMAC_256;
501 hw->wiphy->n_cipher_suites++;
505 /* currently FW API supports only one optional cipher scheme */
506 if (mvm->fw->cs[0].cipher) {
507 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
508 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
510 mvm->hw->n_cipher_schemes = 1;
512 cs->cipher = le32_to_cpu(fwcs->cipher);
513 cs->iftype = BIT(NL80211_IFTYPE_STATION);
514 cs->hdr_len = fwcs->hdr_len;
515 cs->pn_len = fwcs->pn_len;
516 cs->pn_off = fwcs->pn_off;
517 cs->key_idx_off = fwcs->key_idx_off;
518 cs->key_idx_mask = fwcs->key_idx_mask;
519 cs->key_idx_shift = fwcs->key_idx_shift;
520 cs->mic_len = fwcs->mic_len;
522 mvm->hw->cipher_schemes = mvm->cs;
523 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
524 hw->wiphy->n_cipher_suites++;
527 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
528 hw->wiphy->features |=
529 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
530 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
531 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
533 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
534 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
535 hw->chanctx_data_size = sizeof(u16);
537 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
538 BIT(NL80211_IFTYPE_P2P_CLIENT) |
539 BIT(NL80211_IFTYPE_AP) |
540 BIT(NL80211_IFTYPE_P2P_GO) |
541 BIT(NL80211_IFTYPE_P2P_DEVICE) |
542 BIT(NL80211_IFTYPE_ADHOC);
544 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
545 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
546 if (iwl_mvm_is_lar_supported(mvm))
547 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
549 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
550 REGULATORY_DISABLE_BEACON_HINTS;
552 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
553 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
555 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
556 hw->wiphy->n_iface_combinations =
557 ARRAY_SIZE(iwl_mvm_iface_combinations);
559 hw->wiphy->max_remain_on_channel_duration = 10000;
560 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
561 /* we can compensate an offset of up to 3 channels = 15 MHz */
562 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
564 /* Extract MAC address */
565 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
566 hw->wiphy->addresses = mvm->addresses;
567 hw->wiphy->n_addresses = 1;
569 /* Extract additional MAC addresses if available */
570 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
571 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
573 for (i = 1; i < num_mac; i++) {
574 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
576 mvm->addresses[i].addr[5]++;
577 hw->wiphy->n_addresses++;
580 iwl_mvm_reset_phy_ctxts(mvm);
582 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
584 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
586 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
587 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
588 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
590 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
591 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
593 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
595 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
596 hw->wiphy->bands[NL80211_BAND_2GHZ] =
597 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
598 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
599 hw->wiphy->bands[NL80211_BAND_5GHZ] =
600 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
602 if (fw_has_capa(&mvm->fw->ucode_capa,
603 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
604 fw_has_api(&mvm->fw->ucode_capa,
605 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
606 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
607 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
610 hw->wiphy->hw_version = mvm->trans->hw_id;
612 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
613 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
615 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
617 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
618 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
619 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
620 /* we create the 802.11 header and zero length SSID IE. */
621 hw->wiphy->max_sched_scan_ie_len =
622 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
623 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
624 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
627 * the firmware uses u8 for num of iterations, but 0xff is saved for
628 * infinite loop, so the maximum number of iterations is actually 254.
630 hw->wiphy->max_sched_scan_plan_iterations = 254;
632 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
633 NL80211_FEATURE_LOW_PRIORITY_SCAN |
634 NL80211_FEATURE_P2P_GO_OPPPS |
635 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
636 NL80211_FEATURE_DYNAMIC_SMPS |
637 NL80211_FEATURE_STATIC_SMPS |
638 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
640 if (fw_has_capa(&mvm->fw->ucode_capa,
641 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
642 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
643 if (fw_has_capa(&mvm->fw->ucode_capa,
644 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
645 hw->wiphy->features |= NL80211_FEATURE_QUIET;
647 if (fw_has_capa(&mvm->fw->ucode_capa,
648 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
649 hw->wiphy->features |=
650 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
652 if (fw_has_capa(&mvm->fw->ucode_capa,
653 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
654 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
656 if (fw_has_api(&mvm->fw->ucode_capa,
657 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
658 wiphy_ext_feature_set(hw->wiphy,
659 NL80211_EXT_FEATURE_SCAN_START_TIME);
660 wiphy_ext_feature_set(hw->wiphy,
661 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
662 wiphy_ext_feature_set(hw->wiphy,
663 NL80211_EXT_FEATURE_SET_SCAN_DWELL);
666 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
668 #ifdef CONFIG_PM_SLEEP
669 if (iwl_mvm_is_d0i3_supported(mvm) &&
670 device_can_wakeup(mvm->trans->dev)) {
671 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
672 hw->wiphy->wowlan = &mvm->wowlan;
675 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
676 mvm->trans->ops->d3_suspend &&
677 mvm->trans->ops->d3_resume &&
678 device_can_wakeup(mvm->trans->dev)) {
679 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
680 WIPHY_WOWLAN_DISCONNECT |
681 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
682 WIPHY_WOWLAN_RFKILL_RELEASE |
683 WIPHY_WOWLAN_NET_DETECT;
684 if (!iwlwifi_mod_params.sw_crypto)
685 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
686 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
687 WIPHY_WOWLAN_4WAY_HANDSHAKE;
689 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
690 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
691 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
692 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
693 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
694 hw->wiphy->wowlan = &mvm->wowlan;
698 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
699 /* assign default bcast filtering configuration */
700 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
703 ret = iwl_mvm_leds_init(mvm);
707 if (fw_has_capa(&mvm->fw->ucode_capa,
708 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
709 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
710 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
711 ieee80211_hw_set(hw, TDLS_WIDER_BW);
714 if (fw_has_capa(&mvm->fw->ucode_capa,
715 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
716 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
717 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
720 hw->netdev_features |= mvm->cfg->features;
721 if (!iwl_mvm_is_csum_supported(mvm)) {
722 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
724 /* We may support SW TX CSUM */
725 if (IWL_MVM_SW_TX_CSUM_OFFLOAD)
726 hw->netdev_features |= IWL_TX_CSUM_NETIF_FLAGS;
729 ret = ieee80211_register_hw(mvm->hw);
731 iwl_mvm_leds_exit(mvm);
733 if (mvm->cfg->vht_mu_mimo_supported)
734 wiphy_ext_feature_set(hw->wiphy,
735 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
740 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
741 struct ieee80211_sta *sta,
744 struct iwl_mvm_sta *mvmsta;
748 * double check the IN_D0I3 flag both before and after
749 * taking the spinlock, in order to prevent taking
750 * the spinlock when not needed.
752 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
755 spin_lock(&mvm->d0i3_tx_lock);
757 * testing the flag again ensures the skb dequeue
758 * loop (on d0i3 exit) hasn't run yet.
760 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
763 mvmsta = iwl_mvm_sta_from_mac80211(sta);
764 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
765 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
768 __skb_queue_tail(&mvm->d0i3_tx, skb);
769 ieee80211_stop_queues(mvm->hw);
772 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
773 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
777 spin_unlock(&mvm->d0i3_tx_lock);
781 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
782 struct ieee80211_tx_control *control,
785 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
786 struct ieee80211_sta *sta = control->sta;
787 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
788 struct ieee80211_hdr *hdr = (void *)skb->data;
790 if (iwl_mvm_is_radio_killed(mvm)) {
791 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
795 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
796 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
797 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
800 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
801 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
802 ieee80211_is_mgmt(hdr->frame_control) &&
803 !ieee80211_is_deauth(hdr->frame_control) &&
804 !ieee80211_is_disassoc(hdr->frame_control) &&
805 !ieee80211_is_action(hdr->frame_control)))
808 /* If there is no sta, and it's not offchannel - send through AP */
809 if (info->control.vif->type == NL80211_IFTYPE_STATION &&
810 info->hw_queue != IWL_MVM_OFFCHANNEL_QUEUE && !sta) {
811 struct iwl_mvm_vif *mvmvif =
812 iwl_mvm_vif_from_mac80211(info->control.vif);
813 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
815 if (ap_sta_id < IWL_MVM_STATION_COUNT) {
816 /* mac80211 holds rcu read lock */
817 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
818 if (IS_ERR_OR_NULL(sta))
824 if (iwl_mvm_defer_tx(mvm, sta, skb))
826 if (iwl_mvm_tx_skb(mvm, skb, sta))
831 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
835 ieee80211_free_txskb(hw, skb);
838 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
840 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
845 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
847 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
849 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
852 /* enabled by default */
856 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
858 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
860 iwl_mvm_fw_dbg_collect_trig(_mvm, _trig, _fmt); \
864 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
865 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
866 enum ieee80211_ampdu_mlme_action action)
868 struct iwl_fw_dbg_trigger_tlv *trig;
869 struct iwl_fw_dbg_trigger_ba *ba_trig;
871 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
874 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
875 ba_trig = (void *)trig->data;
877 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
881 case IEEE80211_AMPDU_TX_OPERATIONAL: {
882 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
883 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
885 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
886 "TX AGG START: MAC %pM tid %d ssn %d\n",
887 sta->addr, tid, tid_data->ssn);
890 case IEEE80211_AMPDU_TX_STOP_CONT:
891 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
892 "TX AGG STOP: MAC %pM tid %d\n",
895 case IEEE80211_AMPDU_RX_START:
896 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
897 "RX AGG START: MAC %pM tid %d ssn %d\n",
898 sta->addr, tid, rx_ba_ssn);
900 case IEEE80211_AMPDU_RX_STOP:
901 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
902 "RX AGG STOP: MAC %pM tid %d\n",
910 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
911 struct ieee80211_vif *vif,
912 struct ieee80211_ampdu_params *params)
914 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
916 bool tx_agg_ref = false;
917 struct ieee80211_sta *sta = params->sta;
918 enum ieee80211_ampdu_mlme_action action = params->action;
919 u16 tid = params->tid;
920 u16 *ssn = ¶ms->ssn;
921 u8 buf_size = params->buf_size;
922 bool amsdu = params->amsdu;
923 u16 timeout = params->timeout;
925 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
926 sta->addr, tid, action);
928 if (!(mvm->nvm_data->sku_cap_11n_enable))
931 /* return from D0i3 before starting a new Tx aggregation */
933 case IEEE80211_AMPDU_TX_START:
934 case IEEE80211_AMPDU_TX_STOP_CONT:
935 case IEEE80211_AMPDU_TX_STOP_FLUSH:
936 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
937 case IEEE80211_AMPDU_TX_OPERATIONAL:
939 * for tx start, wait synchronously until D0i3 exit to
940 * get the correct sequence number for the tid.
941 * additionally, some other ampdu actions use direct
942 * target access, which is not handled automatically
943 * by the trans layer (unlike commands), so wait for
944 * d0i3 exit in these cases as well.
946 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
956 mutex_lock(&mvm->mutex);
959 case IEEE80211_AMPDU_RX_START:
960 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
964 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
967 case IEEE80211_AMPDU_RX_STOP:
968 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
971 case IEEE80211_AMPDU_TX_START:
972 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
976 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
978 case IEEE80211_AMPDU_TX_STOP_CONT:
979 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
981 case IEEE80211_AMPDU_TX_STOP_FLUSH:
982 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
983 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
985 case IEEE80211_AMPDU_TX_OPERATIONAL:
986 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
998 if (action == IEEE80211_AMPDU_RX_START)
1001 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1004 mutex_unlock(&mvm->mutex);
1007 * If the tid is marked as started, we won't use it for offloaded
1008 * traffic on the next D0i3 entry. It's safe to unref.
1011 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
1016 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1017 struct ieee80211_vif *vif)
1019 struct iwl_mvm *mvm = data;
1020 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1022 mvmvif->uploaded = false;
1023 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1025 spin_lock_bh(&mvm->time_event_lock);
1026 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1027 spin_unlock_bh(&mvm->time_event_lock);
1029 mvmvif->phy_ctxt = NULL;
1030 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1033 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1035 /* clear the D3 reconfig, we only need it to avoid dumping a
1036 * firmware coredump on reconfiguration, we shouldn't do that
1037 * on D3->D0 transition
1039 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1040 mvm->fw_dump_desc = &iwl_mvm_dump_desc_assert;
1041 iwl_mvm_fw_error_dump(mvm);
1044 /* cleanup all stale references (scan, roc), but keep the
1045 * ucode_down ref until reconfig is complete
1047 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1049 iwl_mvm_stop_device(mvm);
1051 mvm->scan_status = 0;
1052 mvm->ps_disabled = false;
1053 mvm->calibrating = false;
1055 /* just in case one was running */
1056 iwl_mvm_cleanup_roc_te(mvm);
1057 ieee80211_remain_on_channel_expired(mvm->hw);
1060 * cleanup all interfaces, even inactive ones, as some might have
1061 * gone down during the HW restart
1063 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1065 mvm->p2p_device_vif = NULL;
1066 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1068 iwl_mvm_reset_phy_ctxts(mvm);
1069 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1070 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
1071 memset(mvm->sta_deferred_frames, 0, sizeof(mvm->sta_deferred_frames));
1072 memset(mvm->tfd_drained, 0, sizeof(mvm->tfd_drained));
1073 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1074 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1076 ieee80211_wake_queues(mvm->hw);
1078 /* clear any stale d0i3 state */
1079 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1082 mvm->rx_ba_sessions = 0;
1083 mvm->fw_dbg_conf = FW_DBG_INVALID;
1085 /* keep statistics ticking */
1086 iwl_mvm_accu_radio_stats(mvm);
1089 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1093 lockdep_assert_held(&mvm->mutex);
1095 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1096 /* Clean up some internal and mac80211 state on restart */
1097 iwl_mvm_restart_cleanup(mvm);
1099 /* Hold the reference to prevent runtime suspend while
1100 * the start procedure runs. It's a bit confusing
1101 * that the UCODE_DOWN reference is taken, but it just
1102 * means "UCODE is not UP yet". ( TODO: rename this
1105 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1107 ret = iwl_mvm_up(mvm);
1109 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1110 /* Something went wrong - we need to finish some cleanup
1111 * that normally iwl_mvm_mac_restart_complete() below
1114 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1115 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1121 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1123 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1126 /* Some hw restart cleanups must not hold the mutex */
1127 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1129 * Make sure we are out of d0i3. This is needed
1130 * to make sure the reference accounting is correct
1131 * (and there is no stale d0i3_exit_work).
1133 wait_event_timeout(mvm->d0i3_exit_waitq,
1134 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1139 mutex_lock(&mvm->mutex);
1140 ret = __iwl_mvm_mac_start(mvm);
1141 mutex_unlock(&mvm->mutex);
1146 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1150 mutex_lock(&mvm->mutex);
1152 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1153 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1154 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1156 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1159 /* allow transport/FW low power modes */
1160 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1163 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1164 * of packets the FW sent out, so we must reconnect.
1166 iwl_mvm_teardown_tdls_peers(mvm);
1168 mutex_unlock(&mvm->mutex);
1171 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1173 if (iwl_mvm_is_d0i3_supported(mvm) &&
1174 iwl_mvm_enter_d0i3_on_suspend(mvm))
1175 WARN_ONCE(!wait_event_timeout(mvm->d0i3_exit_waitq,
1176 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1179 "D0i3 exit on resume timed out\n");
1183 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1184 enum ieee80211_reconfig_type reconfig_type)
1186 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1188 switch (reconfig_type) {
1189 case IEEE80211_RECONFIG_TYPE_RESTART:
1190 iwl_mvm_restart_complete(mvm);
1192 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1193 iwl_mvm_resume_complete(mvm);
1198 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1200 lockdep_assert_held(&mvm->mutex);
1202 /* firmware counters are obviously reset now, but we shouldn't
1203 * partially track so also clear the fw_reset_accu counters.
1205 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1207 /* async_handlers_wk is now blocked */
1210 * The work item could be running or queued if the
1211 * ROC time event stops just as we get here.
1213 flush_work(&mvm->roc_done_wk);
1215 iwl_mvm_stop_device(mvm);
1217 iwl_mvm_async_handlers_purge(mvm);
1218 /* async_handlers_list is empty and will stay empty: HW is stopped */
1220 /* the fw is stopped, the aux sta is dead: clean up driver state */
1221 iwl_mvm_del_aux_sta(mvm);
1223 iwl_free_fw_paging(mvm);
1226 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1227 * won't be called in this case).
1228 * But make sure to cleanup interfaces that have gone down before/during
1229 * HW restart was requested.
1231 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1232 ieee80211_iterate_interfaces(mvm->hw, 0,
1233 iwl_mvm_cleanup_iterator, mvm);
1235 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1236 * make sure there's nothing left there and warn if any is found.
1238 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1241 for (i = 0; i < mvm->max_scans; i++) {
1242 if (WARN_ONCE(mvm->scan_uid_status[i],
1243 "UMAC scan UID %d status was not cleaned\n",
1245 mvm->scan_uid_status[i] = 0;
1250 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1252 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1254 flush_work(&mvm->d0i3_exit_work);
1255 flush_work(&mvm->async_handlers_wk);
1256 flush_work(&mvm->add_stream_wk);
1257 cancel_delayed_work_sync(&mvm->fw_dump_wk);
1258 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1259 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1260 iwl_mvm_free_fw_dump_desc(mvm);
1262 mutex_lock(&mvm->mutex);
1263 __iwl_mvm_mac_stop(mvm);
1264 mutex_unlock(&mvm->mutex);
1267 * The worker might have been waiting for the mutex, let it run and
1268 * discover that its list is now empty.
1270 cancel_work_sync(&mvm->async_handlers_wk);
1273 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1277 lockdep_assert_held(&mvm->mutex);
1279 for (i = 0; i < NUM_PHY_CTX; i++)
1280 if (!mvm->phy_ctxts[i].ref)
1281 return &mvm->phy_ctxts[i];
1283 IWL_ERR(mvm, "No available PHY context\n");
1287 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1290 struct iwl_dev_tx_power_cmd cmd = {
1291 .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1292 .v3.mac_context_id =
1293 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1294 .v3.pwr_restriction = cpu_to_le16(8 * tx_power),
1296 int len = sizeof(cmd);
1298 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1299 cmd.v3.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1301 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1302 len = sizeof(cmd.v3);
1304 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1307 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1308 struct ieee80211_vif *vif)
1310 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1311 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1317 * make sure D0i3 exit is completed, otherwise a target access
1318 * during tx queue configuration could be done when still in
1321 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1326 * Not much to do here. The stack will not allow interface
1327 * types or combinations that we didn't advertise, so we
1328 * don't really have to check the types.
1331 mutex_lock(&mvm->mutex);
1333 /* make sure that beacon statistics don't go backwards with FW reset */
1334 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1335 mvmvif->beacon_stats.accu_num_beacons +=
1336 mvmvif->beacon_stats.num_beacons;
1338 /* Allocate resources for the MAC context, and add it to the fw */
1339 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1343 /* Counting number of interfaces is needed for legacy PM */
1344 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1348 * The AP binding flow can be done only after the beacon
1349 * template is configured (which happens only in the mac80211
1350 * start_ap() flow), and adding the broadcast station can happen
1351 * only after the binding.
1352 * In addition, since modifying the MAC before adding a bcast
1353 * station is not allowed by the FW, delay the adding of MAC context to
1354 * the point where we can also add the bcast station.
1355 * In short: there's not much we can do at this point, other than
1356 * allocating resources :)
1358 if (vif->type == NL80211_IFTYPE_AP ||
1359 vif->type == NL80211_IFTYPE_ADHOC) {
1360 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1362 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1366 iwl_mvm_vif_dbgfs_register(mvm, vif);
1370 mvmvif->features |= hw->netdev_features;
1372 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1376 ret = iwl_mvm_power_update_mac(mvm);
1378 goto out_remove_mac;
1380 /* beacon filtering */
1381 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1383 goto out_remove_mac;
1385 if (!mvm->bf_allowed_vif &&
1386 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1387 mvm->bf_allowed_vif = mvmvif;
1388 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1389 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1393 * P2P_DEVICE interface does not have a channel context assigned to it,
1394 * so a dedicated PHY context is allocated to it and the corresponding
1395 * MAC context is bound to it at this stage.
1397 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1399 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1400 if (!mvmvif->phy_ctxt) {
1405 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1406 ret = iwl_mvm_binding_add_vif(mvm, vif);
1410 ret = iwl_mvm_add_bcast_sta(mvm, vif);
1414 /* Save a pointer to p2p device vif, so it can later be used to
1415 * update the p2p device MAC when a GO is started/stopped */
1416 mvm->p2p_device_vif = vif;
1419 iwl_mvm_vif_dbgfs_register(mvm, vif);
1423 iwl_mvm_binding_remove_vif(mvm, vif);
1425 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1427 if (mvm->bf_allowed_vif == mvmvif) {
1428 mvm->bf_allowed_vif = NULL;
1429 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1430 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1433 mvmvif->phy_ctxt = NULL;
1434 iwl_mvm_mac_ctxt_remove(mvm, vif);
1436 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1439 iwl_mvm_mac_ctxt_release(mvm, vif);
1441 mutex_unlock(&mvm->mutex);
1443 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1448 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1449 struct ieee80211_vif *vif)
1451 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif);
1455 * mac80211 first removes all the stations of the vif and
1456 * then removes the vif. When it removes a station it also
1457 * flushes the AMPDU session. So by now, all the AMPDU sessions
1458 * of all the stations of this vif are closed, and the queues
1459 * of these AMPDU sessions are properly closed.
1460 * We still need to take care of the shared queues of the vif.
1463 mutex_lock(&mvm->mutex);
1464 iwl_mvm_flush_tx_path(mvm, tfd_msk, 0);
1465 mutex_unlock(&mvm->mutex);
1468 * There are transports that buffer a few frames in the host.
1469 * For these, the flush above isn't enough since while we were
1470 * flushing, the transport might have sent more frames to the
1471 * device. To solve this, wait here until the transport is
1472 * empty. Technically, this could have replaced the flush
1473 * above, but flush is much faster than draining. So flush
1474 * first, and drain to make sure we have no frames in the
1475 * transport anymore.
1476 * If a station still had frames on the shared queues, it is
1477 * already marked as draining, so to complete the draining, we
1478 * just need to wait until the transport is empty.
1480 iwl_trans_wait_tx_queue_empty(mvm->trans, tfd_msk);
1483 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1485 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1486 * We assume here that all the packets sent to the OFFCHANNEL
1487 * queue are sent in ROC session.
1489 flush_work(&mvm->roc_done_wk);
1492 * By now, all the AC queues are empty. The AGG queues are
1493 * empty too. We already got all the Tx responses for all the
1494 * packets in the queues. The drain work can have been
1495 * triggered. Flush it.
1497 flush_work(&mvm->sta_drained_wk);
1501 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1502 struct ieee80211_vif *vif)
1504 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1505 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1507 iwl_mvm_prepare_mac_removal(mvm, vif);
1509 mutex_lock(&mvm->mutex);
1511 if (mvm->bf_allowed_vif == mvmvif) {
1512 mvm->bf_allowed_vif = NULL;
1513 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1514 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1517 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1520 * For AP/GO interface, the tear down of the resources allocated to the
1521 * interface is be handled as part of the stop_ap flow.
1523 if (vif->type == NL80211_IFTYPE_AP ||
1524 vif->type == NL80211_IFTYPE_ADHOC) {
1525 #ifdef CONFIG_NL80211_TESTMODE
1526 if (vif == mvm->noa_vif) {
1527 mvm->noa_vif = NULL;
1528 mvm->noa_duration = 0;
1531 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1535 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1536 mvm->p2p_device_vif = NULL;
1537 iwl_mvm_rm_bcast_sta(mvm, vif);
1538 iwl_mvm_binding_remove_vif(mvm, vif);
1539 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1540 mvmvif->phy_ctxt = NULL;
1543 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1546 iwl_mvm_power_update_mac(mvm);
1547 iwl_mvm_mac_ctxt_remove(mvm, vif);
1550 iwl_mvm_mac_ctxt_release(mvm, vif);
1551 mutex_unlock(&mvm->mutex);
1554 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1559 struct iwl_mvm_mc_iter_data {
1560 struct iwl_mvm *mvm;
1564 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1565 struct ieee80211_vif *vif)
1567 struct iwl_mvm_mc_iter_data *data = _data;
1568 struct iwl_mvm *mvm = data->mvm;
1569 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1570 struct iwl_host_cmd hcmd = {
1571 .id = MCAST_FILTER_CMD,
1573 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1577 /* if we don't have free ports, mcast frames will be dropped */
1578 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1581 if (vif->type != NL80211_IFTYPE_STATION ||
1582 !vif->bss_conf.assoc)
1585 cmd->port_id = data->port_id++;
1586 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1587 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1592 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1594 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1597 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1599 struct iwl_mvm_mc_iter_data iter_data = {
1604 lockdep_assert_held(&mvm->mutex);
1606 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1609 ieee80211_iterate_active_interfaces_atomic(
1610 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1611 iwl_mvm_mc_iface_iterator, &iter_data);
1614 * Send a (synchronous) ech command so that we wait for the
1615 * multiple asynchronous MCAST_FILTER_CMD commands sent by
1616 * the interface iterator. Otherwise, we might get here over
1617 * and over again (by userspace just sending a lot of these)
1618 * and the CPU can send them faster than the firmware can
1620 * Note that the CPU is still faster - but with this we'll
1621 * actually send fewer commands overall because the CPU will
1622 * not schedule the work in mac80211 as frequently if it's
1623 * still running when rescheduled (possibly multiple times).
1625 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1627 IWL_ERR(mvm, "Failed to synchronize multicast groups update\n");
1630 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1631 struct netdev_hw_addr_list *mc_list)
1633 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1634 struct iwl_mcast_filter_cmd *cmd;
1635 struct netdev_hw_addr *addr;
1640 addr_count = netdev_hw_addr_list_count(mc_list);
1641 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1642 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1646 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1647 cmd = kzalloc(len, GFP_ATOMIC);
1653 return (u64)(unsigned long)cmd;
1656 netdev_hw_addr_list_for_each(addr, mc_list) {
1657 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1658 cmd->count, addr->addr);
1659 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1660 addr->addr, ETH_ALEN);
1664 return (u64)(unsigned long)cmd;
1667 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1668 unsigned int changed_flags,
1669 unsigned int *total_flags,
1672 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1673 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1675 mutex_lock(&mvm->mutex);
1677 /* replace previous configuration */
1678 kfree(mvm->mcast_filter_cmd);
1679 mvm->mcast_filter_cmd = cmd;
1684 iwl_mvm_recalc_multicast(mvm);
1686 mutex_unlock(&mvm->mutex);
1690 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1691 struct ieee80211_vif *vif,
1692 unsigned int filter_flags,
1693 unsigned int changed_flags)
1695 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1697 /* We support only filter for probe requests */
1698 if (!(changed_flags & FIF_PROBE_REQ))
1701 /* Supported only for p2p client interfaces */
1702 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1706 mutex_lock(&mvm->mutex);
1707 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1708 mutex_unlock(&mvm->mutex);
1711 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1712 struct iwl_bcast_iter_data {
1713 struct iwl_mvm *mvm;
1714 struct iwl_bcast_filter_cmd *cmd;
1719 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1720 const struct iwl_fw_bcast_filter *in_filter,
1721 struct iwl_fw_bcast_filter *out_filter)
1723 struct iwl_fw_bcast_filter_attr *attr;
1726 memcpy(out_filter, in_filter, sizeof(*out_filter));
1728 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1729 attr = &out_filter->attrs[i];
1734 switch (attr->reserved1) {
1735 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1736 if (vif->bss_conf.arp_addr_cnt != 1) {
1741 attr->val = vif->bss_conf.arp_addr_list[0];
1743 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1744 attr->val = *(__be32 *)&vif->addr[2];
1749 attr->reserved1 = 0;
1750 out_filter->num_attrs++;
1754 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1755 struct ieee80211_vif *vif)
1757 struct iwl_bcast_iter_data *data = _data;
1758 struct iwl_mvm *mvm = data->mvm;
1759 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1760 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1761 struct iwl_fw_bcast_mac *bcast_mac;
1764 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1767 bcast_mac = &cmd->macs[mvmvif->id];
1770 * enable filtering only for associated stations, but not for P2P
1773 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1774 !vif->bss_conf.assoc)
1777 bcast_mac->default_discard = 1;
1779 /* copy all configured filters */
1780 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1782 * Make sure we don't exceed our filters limit.
1783 * if there is still a valid filter to be configured,
1784 * be on the safe side and just allow bcast for this mac.
1786 if (WARN_ON_ONCE(data->current_filter >=
1787 ARRAY_SIZE(cmd->filters))) {
1788 bcast_mac->default_discard = 0;
1789 bcast_mac->attached_filters = 0;
1793 iwl_mvm_set_bcast_filter(vif,
1794 &mvm->bcast_filters[i],
1795 &cmd->filters[data->current_filter]);
1797 /* skip current filter if it contains no attributes */
1798 if (!cmd->filters[data->current_filter].num_attrs)
1801 /* attach the filter to current mac */
1802 bcast_mac->attached_filters |=
1803 cpu_to_le16(BIT(data->current_filter));
1805 data->current_filter++;
1809 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1810 struct iwl_bcast_filter_cmd *cmd)
1812 struct iwl_bcast_iter_data iter_data = {
1817 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1820 memset(cmd, 0, sizeof(*cmd));
1821 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1822 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1824 #ifdef CONFIG_IWLWIFI_DEBUGFS
1825 /* use debugfs filters/macs if override is configured */
1826 if (mvm->dbgfs_bcast_filtering.override) {
1827 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1828 sizeof(cmd->filters));
1829 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1835 /* if no filters are configured, do nothing */
1836 if (!mvm->bcast_filters)
1839 /* configure and attach these filters for each associated sta vif */
1840 ieee80211_iterate_active_interfaces(
1841 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1842 iwl_mvm_bcast_filter_iterator, &iter_data);
1847 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1849 struct iwl_bcast_filter_cmd cmd;
1851 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1854 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1857 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1861 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1867 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1868 struct ieee80211_vif *vif)
1870 struct iwl_mu_group_mgmt_cmd cmd = {};
1872 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1873 WLAN_MEMBERSHIP_LEN);
1874 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1875 WLAN_USER_POSITION_LEN);
1877 return iwl_mvm_send_cmd_pdu(mvm,
1878 WIDE_ID(DATA_PATH_GROUP,
1879 UPDATE_MU_GROUPS_CMD),
1880 0, sizeof(cmd), &cmd);
1883 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1884 struct ieee80211_vif *vif)
1886 if (vif->mu_mimo_owner) {
1887 struct iwl_mu_group_mgmt_notif *notif = _data;
1890 * MU-MIMO Group Id action frame is little endian. We treat
1891 * the data received from firmware as if it came from the
1892 * action frame, so no conversion is needed.
1894 ieee80211_update_mu_groups(vif,
1895 (u8 *)¬if->membership_status,
1896 (u8 *)¬if->user_position);
1900 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1901 struct iwl_rx_cmd_buffer *rxb)
1903 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1904 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1906 ieee80211_iterate_active_interfaces_atomic(
1907 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1908 iwl_mvm_mu_mimo_iface_iterator, notif);
1911 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1912 struct ieee80211_vif *vif,
1913 struct ieee80211_bss_conf *bss_conf,
1916 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1920 * Re-calculate the tsf id, as the master-slave relations depend on the
1921 * beacon interval, which was not known when the station interface was
1924 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1925 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1927 if (changes & BSS_CHANGED_ASSOC && !bss_conf->assoc &&
1929 iwl_mvm_send_lqm_cmd(vif, LQM_CMD_OPERATION_STOP_MEASUREMENT,
1933 * If we're not associated yet, take the (new) BSSID before associating
1934 * so the firmware knows. If we're already associated, then use the old
1935 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1936 * branch for disassociation below.
1938 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1939 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1941 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
1943 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1945 /* after sending it once, adopt mac80211 data */
1946 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1947 mvmvif->associated = bss_conf->assoc;
1949 if (changes & BSS_CHANGED_ASSOC) {
1950 if (bss_conf->assoc) {
1951 /* clear statistics to get clean beacon counter */
1952 iwl_mvm_request_statistics(mvm, true);
1953 memset(&mvmvif->beacon_stats, 0,
1954 sizeof(mvmvif->beacon_stats));
1956 /* add quota for this interface */
1957 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1959 IWL_ERR(mvm, "failed to update quotas\n");
1963 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1966 * If we're restarting then the firmware will
1967 * obviously have lost synchronisation with
1968 * the AP. It will attempt to synchronise by
1969 * itself, but we can make it more reliable by
1970 * scheduling a session protection time event.
1972 * The firmware needs to receive a beacon to
1973 * catch up with synchronisation, use 110% of
1974 * the beacon interval.
1976 * Set a large maximum delay to allow for more
1977 * than a single interface.
1979 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1980 iwl_mvm_protect_session(mvm, vif, dur, dur,
1984 iwl_mvm_sf_update(mvm, vif, false);
1985 iwl_mvm_power_vif_assoc(mvm, vif);
1987 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
1988 iwl_mvm_update_smps(mvm, vif,
1989 IWL_MVM_SMPS_REQ_PROT,
1990 IEEE80211_SMPS_DYNAMIC);
1992 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1994 * If update fails - SF might be running in associated
1995 * mode while disassociated - which is forbidden.
1997 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1998 "Failed to update SF upon disassociation\n");
2000 /* remove AP station now that the MAC is unassoc */
2001 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
2003 IWL_ERR(mvm, "failed to remove AP station\n");
2005 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
2006 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
2007 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
2008 /* remove quota for this interface */
2009 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2011 IWL_ERR(mvm, "failed to update quotas\n");
2014 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
2016 /* this will take the cleared BSSID from bss_conf */
2017 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2020 "failed to update MAC %pM (clear after unassoc)\n",
2025 * The firmware tracks the MU-MIMO group on its own.
2026 * However, on HW restart we should restore this data.
2028 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2029 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2030 ret = iwl_mvm_update_mu_groups(mvm, vif);
2033 "failed to update VHT MU_MIMO groups\n");
2036 iwl_mvm_recalc_multicast(mvm);
2037 iwl_mvm_configure_bcast_filter(mvm);
2039 /* reset rssi values */
2040 mvmvif->bf_data.ave_beacon_signal = 0;
2042 iwl_mvm_bt_coex_vif_change(mvm);
2043 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2044 IEEE80211_SMPS_AUTOMATIC);
2045 if (fw_has_capa(&mvm->fw->ucode_capa,
2046 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2047 iwl_mvm_config_scan(mvm);
2048 } else if (changes & BSS_CHANGED_BEACON_INFO) {
2050 * We received a beacon _after_ association so
2051 * remove the session protection.
2053 iwl_mvm_remove_time_event(mvm, mvmvif,
2054 &mvmvif->time_event_data);
2057 if (changes & BSS_CHANGED_BEACON_INFO) {
2058 iwl_mvm_sf_update(mvm, vif, false);
2059 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2062 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2064 * Send power command on every beacon change,
2065 * because we may have not enabled beacon abort yet.
2067 BSS_CHANGED_BEACON_INFO)) {
2068 ret = iwl_mvm_power_update_mac(mvm);
2070 IWL_ERR(mvm, "failed to update power mode\n");
2073 if (changes & BSS_CHANGED_TXPOWER) {
2074 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2076 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2079 if (changes & BSS_CHANGED_CQM) {
2080 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2081 /* reset cqm events tracking */
2082 mvmvif->bf_data.last_cqm_event = 0;
2083 if (mvmvif->bf_data.bf_enabled) {
2084 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2087 "failed to update CQM thresholds\n");
2091 if (changes & BSS_CHANGED_ARP_FILTER) {
2092 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2093 iwl_mvm_configure_bcast_filter(mvm);
2097 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2098 struct ieee80211_vif *vif)
2100 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2101 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2105 * iwl_mvm_mac_ctxt_add() might read directly from the device
2106 * (the system time), so make sure it is available.
2108 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2112 mutex_lock(&mvm->mutex);
2114 /* Send the beacon template */
2115 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2120 * Re-calculate the tsf id, as the master-slave relations depend on the
2121 * beacon interval, which was not known when the AP interface was added.
2123 if (vif->type == NL80211_IFTYPE_AP)
2124 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2126 mvmvif->ap_assoc_sta_count = 0;
2128 /* Add the mac context */
2129 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2133 /* Perform the binding */
2134 ret = iwl_mvm_binding_add_vif(mvm, vif);
2138 /* Send the bcast station. At this stage the TBTT and DTIM time events
2139 * are added and applied to the scheduler */
2140 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2144 /* must be set before quota calculations */
2145 mvmvif->ap_ibss_active = true;
2147 /* power updated needs to be done before quotas */
2148 iwl_mvm_power_update_mac(mvm);
2150 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2152 goto out_quota_failed;
2154 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2155 if (vif->p2p && mvm->p2p_device_vif)
2156 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2158 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2160 iwl_mvm_bt_coex_vif_change(mvm);
2162 /* we don't support TDLS during DCM */
2163 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2164 iwl_mvm_teardown_tdls_peers(mvm);
2169 iwl_mvm_power_update_mac(mvm);
2170 mvmvif->ap_ibss_active = false;
2171 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2173 iwl_mvm_binding_remove_vif(mvm, vif);
2175 iwl_mvm_mac_ctxt_remove(mvm, vif);
2177 mutex_unlock(&mvm->mutex);
2178 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2182 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2183 struct ieee80211_vif *vif)
2185 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2186 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2188 iwl_mvm_prepare_mac_removal(mvm, vif);
2190 mutex_lock(&mvm->mutex);
2192 /* Handle AP stop while in CSA */
2193 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2194 iwl_mvm_remove_time_event(mvm, mvmvif,
2195 &mvmvif->time_event_data);
2196 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2197 mvmvif->csa_countdown = false;
2200 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2201 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2202 mvm->csa_tx_block_bcn_timeout = 0;
2205 mvmvif->ap_ibss_active = false;
2206 mvm->ap_last_beacon_gp2 = 0;
2208 iwl_mvm_bt_coex_vif_change(mvm);
2210 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2212 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2213 if (vif->p2p && mvm->p2p_device_vif)
2214 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2216 iwl_mvm_update_quotas(mvm, false, NULL);
2217 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2218 iwl_mvm_binding_remove_vif(mvm, vif);
2220 iwl_mvm_power_update_mac(mvm);
2222 iwl_mvm_mac_ctxt_remove(mvm, vif);
2224 mutex_unlock(&mvm->mutex);
2228 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2229 struct ieee80211_vif *vif,
2230 struct ieee80211_bss_conf *bss_conf,
2233 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2235 /* Changes will be applied when the AP/IBSS is started */
2236 if (!mvmvif->ap_ibss_active)
2239 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2240 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2241 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2242 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2244 /* Need to send a new beacon template to the FW */
2245 if (changes & BSS_CHANGED_BEACON &&
2246 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2247 IWL_WARN(mvm, "Failed updating beacon data\n");
2249 if (changes & BSS_CHANGED_TXPOWER) {
2250 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2252 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2256 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2257 struct ieee80211_vif *vif,
2258 struct ieee80211_bss_conf *bss_conf,
2261 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2264 * iwl_mvm_bss_info_changed_station() might call
2265 * iwl_mvm_protect_session(), which reads directly from
2266 * the device (the system time), so make sure it is available.
2268 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2271 mutex_lock(&mvm->mutex);
2273 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2274 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2276 switch (vif->type) {
2277 case NL80211_IFTYPE_STATION:
2278 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2280 case NL80211_IFTYPE_AP:
2281 case NL80211_IFTYPE_ADHOC:
2282 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2284 case NL80211_IFTYPE_MONITOR:
2285 if (changes & BSS_CHANGED_MU_GROUPS)
2286 iwl_mvm_update_mu_groups(mvm, vif);
2289 /* shouldn't happen */
2293 mutex_unlock(&mvm->mutex);
2294 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2297 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2298 struct ieee80211_vif *vif,
2299 struct ieee80211_scan_request *hw_req)
2301 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2304 if (hw_req->req.n_channels == 0 ||
2305 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2308 mutex_lock(&mvm->mutex);
2309 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2310 mutex_unlock(&mvm->mutex);
2315 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2316 struct ieee80211_vif *vif)
2318 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2320 mutex_lock(&mvm->mutex);
2322 /* Due to a race condition, it's possible that mac80211 asks
2323 * us to stop a hw_scan when it's already stopped. This can
2324 * happen, for instance, if we stopped the scan ourselves,
2325 * called ieee80211_scan_completed() and the userspace called
2326 * cancel scan scan before ieee80211_scan_work() could run.
2327 * To handle that, simply return if the scan is not running.
2329 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2330 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2332 mutex_unlock(&mvm->mutex);
2336 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2337 struct ieee80211_sta *sta, u16 tids,
2339 enum ieee80211_frame_release_type reason,
2342 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2344 /* Called when we need to transmit (a) frame(s) from mac80211 */
2346 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2347 tids, more_data, false);
2351 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2352 struct ieee80211_sta *sta, u16 tids,
2354 enum ieee80211_frame_release_type reason,
2357 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2359 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2361 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2362 tids, more_data, true);
2365 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2366 struct ieee80211_vif *vif,
2367 enum sta_notify_cmd cmd,
2368 struct ieee80211_sta *sta)
2370 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2371 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2372 unsigned long txqs = 0, tids = 0;
2375 spin_lock_bh(&mvmsta->lock);
2376 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2377 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2379 if (!iwl_mvm_is_dqa_supported(mvm) &&
2380 tid_data->state != IWL_AGG_ON &&
2381 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
2384 __set_bit(tid_data->txq_id, &txqs);
2386 if (iwl_mvm_tid_queued(tid_data) == 0)
2389 __set_bit(tid, &tids);
2393 case STA_NOTIFY_SLEEP:
2394 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
2395 ieee80211_sta_block_awake(hw, sta, true);
2397 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2398 ieee80211_sta_set_buffered(sta, tid, true);
2401 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2403 * The fw updates the STA to be asleep. Tx packets on the Tx
2404 * queues to this station will not be transmitted. The fw will
2405 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2408 case STA_NOTIFY_AWAKE:
2409 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
2413 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2414 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2419 spin_unlock_bh(&mvmsta->lock);
2422 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2423 struct ieee80211_vif *vif,
2424 struct ieee80211_sta *sta)
2426 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2427 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2430 * This is called before mac80211 does RCU synchronisation,
2431 * so here we already invalidate our internal RCU-protected
2432 * station pointer. The rest of the code will thus no longer
2433 * be able to find the station this way, and we don't rely
2434 * on further RCU synchronisation after the sta_state()
2435 * callback deleted the station.
2437 mutex_lock(&mvm->mutex);
2438 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2439 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2442 mutex_unlock(&mvm->mutex);
2445 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2448 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2451 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2452 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2457 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2458 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2462 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2466 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2467 struct ieee80211_vif *vif, u8 *peer_addr,
2468 enum nl80211_tdls_operation action)
2470 struct iwl_fw_dbg_trigger_tlv *trig;
2471 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2473 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_TDLS))
2476 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_TDLS);
2477 tdls_trig = (void *)trig->data;
2478 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
2481 if (!(tdls_trig->action_bitmap & BIT(action)))
2484 if (tdls_trig->peer_mode &&
2485 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2488 iwl_mvm_fw_dbg_collect_trig(mvm, trig,
2489 "TDLS event occurred, peer %pM, action %d",
2493 static void iwl_mvm_purge_deferred_tx_frames(struct iwl_mvm *mvm,
2494 struct iwl_mvm_sta *mvm_sta)
2496 struct iwl_mvm_tid_data *tid_data;
2497 struct sk_buff *skb;
2500 spin_lock_bh(&mvm_sta->lock);
2501 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
2502 tid_data = &mvm_sta->tid_data[i];
2503 while ((skb = __skb_dequeue(&tid_data->deferred_tx_frames)))
2504 ieee80211_free_txskb(mvm->hw, skb);
2506 spin_unlock_bh(&mvm_sta->lock);
2509 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2510 struct ieee80211_vif *vif,
2511 struct ieee80211_sta *sta,
2512 enum ieee80211_sta_state old_state,
2513 enum ieee80211_sta_state new_state)
2515 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2516 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2519 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2520 sta->addr, old_state, new_state);
2522 /* this would be a mac80211 bug ... but don't crash */
2523 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2526 /* if a STA is being removed, reuse its ID */
2527 flush_work(&mvm->sta_drained_wk);
2530 * If we are in a STA removal flow and in DQA mode:
2532 * This is after the sync_rcu part, so the queues have already been
2533 * flushed. No more TXs on their way in mac80211's path, and no more in
2535 * Also, we won't be getting any new TX frames for this station.
2536 * What we might have are deferred TX frames that need to be taken care
2539 * Drop any still-queued deferred-frame before removing the STA, and
2540 * make sure the worker is no longer handling frames for this STA.
2542 if (old_state == IEEE80211_STA_NONE &&
2543 new_state == IEEE80211_STA_NOTEXIST &&
2544 iwl_mvm_is_dqa_supported(mvm)) {
2545 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2547 iwl_mvm_purge_deferred_tx_frames(mvm, mvm_sta);
2548 flush_work(&mvm->add_stream_wk);
2551 * No need to make sure deferred TX indication is off since the
2552 * worker will already remove it if it was on
2556 mutex_lock(&mvm->mutex);
2557 if (old_state == IEEE80211_STA_NOTEXIST &&
2558 new_state == IEEE80211_STA_NONE) {
2560 * Firmware bug - it'll crash if the beacon interval is less
2561 * than 16. We can't avoid connecting at all, so refuse the
2562 * station state change, this will cause mac80211 to abandon
2563 * attempts to connect to this AP, and eventually wpa_s will
2564 * blacklist the AP...
2566 if (vif->type == NL80211_IFTYPE_STATION &&
2567 vif->bss_conf.beacon_int < 16) {
2569 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2570 sta->addr, vif->bss_conf.beacon_int);
2577 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2578 IWL_MVM_TDLS_STA_COUNT ||
2579 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2580 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2585 ret = iwl_mvm_add_sta(mvm, vif, sta);
2586 if (sta->tdls && ret == 0) {
2587 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2588 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2589 NL80211_TDLS_SETUP);
2591 } else if (old_state == IEEE80211_STA_NONE &&
2592 new_state == IEEE80211_STA_AUTH) {
2594 * EBS may be disabled due to previous failures reported by FW.
2595 * Reset EBS status here assuming environment has been changed.
2597 mvm->last_ebs_successful = true;
2598 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2600 } else if (old_state == IEEE80211_STA_AUTH &&
2601 new_state == IEEE80211_STA_ASSOC) {
2602 if (vif->type == NL80211_IFTYPE_AP) {
2603 mvmvif->ap_assoc_sta_count++;
2604 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2606 ret = iwl_mvm_update_sta(mvm, vif, sta);
2608 iwl_mvm_rs_rate_init(mvm, sta,
2609 mvmvif->phy_ctxt->channel->band,
2611 } else if (old_state == IEEE80211_STA_ASSOC &&
2612 new_state == IEEE80211_STA_AUTHORIZED) {
2614 /* we don't support TDLS during DCM */
2615 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2616 iwl_mvm_teardown_tdls_peers(mvm);
2619 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2620 NL80211_TDLS_ENABLE_LINK);
2622 /* enable beacon filtering */
2623 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2625 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
2629 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2630 new_state == IEEE80211_STA_ASSOC) {
2631 /* disable beacon filtering */
2632 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2634 } else if (old_state == IEEE80211_STA_ASSOC &&
2635 new_state == IEEE80211_STA_AUTH) {
2636 if (vif->type == NL80211_IFTYPE_AP) {
2637 mvmvif->ap_assoc_sta_count--;
2638 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2641 } else if (old_state == IEEE80211_STA_AUTH &&
2642 new_state == IEEE80211_STA_NONE) {
2644 } else if (old_state == IEEE80211_STA_NONE &&
2645 new_state == IEEE80211_STA_NOTEXIST) {
2646 ret = iwl_mvm_rm_sta(mvm, vif, sta);
2648 iwl_mvm_recalc_tdls_state(mvm, vif, false);
2649 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
2650 NL80211_TDLS_DISABLE_LINK);
2656 mutex_unlock(&mvm->mutex);
2658 if (sta->tdls && ret == 0) {
2659 if (old_state == IEEE80211_STA_NOTEXIST &&
2660 new_state == IEEE80211_STA_NONE)
2661 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2662 else if (old_state == IEEE80211_STA_NONE &&
2663 new_state == IEEE80211_STA_NOTEXIST)
2664 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2670 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2672 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2674 mvm->rts_threshold = value;
2679 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2680 struct ieee80211_vif *vif,
2681 struct ieee80211_sta *sta, u32 changed)
2683 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2685 if (vif->type == NL80211_IFTYPE_STATION &&
2686 changed & IEEE80211_RC_NSS_CHANGED)
2687 iwl_mvm_sf_update(mvm, vif, false);
2690 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2691 struct ieee80211_vif *vif, u16 ac,
2692 const struct ieee80211_tx_queue_params *params)
2694 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2695 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2697 mvmvif->queue_params[ac] = *params;
2700 * No need to update right away, we'll get BSS_CHANGED_QOS
2701 * The exception is P2P_DEVICE interface which needs immediate update.
2703 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2706 mutex_lock(&mvm->mutex);
2707 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2708 mutex_unlock(&mvm->mutex);
2714 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2715 struct ieee80211_vif *vif)
2717 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2718 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
2719 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
2721 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2725 * iwl_mvm_protect_session() reads directly from the device
2726 * (the system time), so make sure it is available.
2728 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2731 mutex_lock(&mvm->mutex);
2732 /* Try really hard to protect the session and hear a beacon */
2733 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
2734 mutex_unlock(&mvm->mutex);
2736 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
2739 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2740 struct ieee80211_vif *vif,
2741 struct cfg80211_sched_scan_request *req,
2742 struct ieee80211_scan_ies *ies)
2744 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2748 mutex_lock(&mvm->mutex);
2750 if (!vif->bss_conf.idle) {
2755 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
2758 mutex_unlock(&mvm->mutex);
2762 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2763 struct ieee80211_vif *vif)
2765 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2768 mutex_lock(&mvm->mutex);
2770 /* Due to a race condition, it's possible that mac80211 asks
2771 * us to stop a sched_scan when it's already stopped. This
2772 * can happen, for instance, if we stopped the scan ourselves,
2773 * called ieee80211_sched_scan_stopped() and the userspace called
2774 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
2775 * could run. To handle this, simply return if the scan is
2778 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
2779 mutex_unlock(&mvm->mutex);
2783 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
2784 mutex_unlock(&mvm->mutex);
2785 iwl_mvm_wait_for_async_handlers(mvm);
2790 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2791 enum set_key_cmd cmd,
2792 struct ieee80211_vif *vif,
2793 struct ieee80211_sta *sta,
2794 struct ieee80211_key_conf *key)
2796 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2797 struct iwl_mvm_sta *mvmsta;
2798 struct iwl_mvm_key_pn *ptk_pn;
2799 int keyidx = key->keyidx;
2803 if (iwlwifi_mod_params.sw_crypto) {
2804 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2808 switch (key->cipher) {
2809 case WLAN_CIPHER_SUITE_TKIP:
2810 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2811 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2813 case WLAN_CIPHER_SUITE_CCMP:
2814 case WLAN_CIPHER_SUITE_GCMP:
2815 case WLAN_CIPHER_SUITE_GCMP_256:
2816 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2818 case WLAN_CIPHER_SUITE_AES_CMAC:
2819 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2820 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2821 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
2823 case WLAN_CIPHER_SUITE_WEP40:
2824 case WLAN_CIPHER_SUITE_WEP104:
2825 /* For non-client mode, only use WEP keys for TX as we probably
2826 * don't have a station yet anyway and would then have to keep
2827 * track of the keys, linking them to each of the clients/peers
2828 * as they appear. For now, don't do that, for performance WEP
2829 * offload doesn't really matter much, but we need it for some
2830 * other offload features in client mode.
2832 if (vif->type != NL80211_IFTYPE_STATION)
2836 /* currently FW supports only one optional cipher scheme */
2837 if (hw->n_cipher_schemes &&
2838 hw->cipher_schemes->cipher == key->cipher)
2839 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2844 mutex_lock(&mvm->mutex);
2848 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2849 vif->type == NL80211_IFTYPE_AP) && !sta) {
2851 * GTK on AP interface is a TX-only key, return 0;
2852 * on IBSS they're per-station and because we're lazy
2853 * we don't support them for RX, so do the same.
2854 * CMAC/GMAC in AP/IBSS modes must be done in software.
2856 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2857 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2858 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
2862 key->hw_key_idx = STA_KEY_IDX_INVALID;
2866 /* During FW restart, in order to restore the state as it was,
2867 * don't try to reprogram keys we previously failed for.
2869 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2870 key->hw_key_idx == STA_KEY_IDX_INVALID) {
2871 IWL_DEBUG_MAC80211(mvm,
2872 "skip invalid idx key programming during restart\n");
2877 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2878 sta && iwl_mvm_has_new_rx_api(mvm) &&
2879 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2880 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
2881 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2882 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
2883 struct ieee80211_key_seq seq;
2886 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2887 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
2888 ptk_pn = kzalloc(sizeof(*ptk_pn) +
2889 mvm->trans->num_rx_queues *
2890 sizeof(ptk_pn->q[0]),
2897 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2898 ieee80211_get_key_rx_seq(key, tid, &seq);
2899 for (q = 0; q < mvm->trans->num_rx_queues; q++)
2900 memcpy(ptk_pn->q[q].pn[tid],
2902 IEEE80211_CCMP_PN_LEN);
2905 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
2908 /* in HW restart reuse the index, otherwise request a new one */
2909 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
2910 key_offset = key->hw_key_idx;
2912 key_offset = STA_KEY_IDX_INVALID;
2914 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2915 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
2917 IWL_WARN(mvm, "set key failed\n");
2919 * can't add key for RX, but we don't need it
2920 * in the device for TX so still return 0
2922 key->hw_key_idx = STA_KEY_IDX_INVALID;
2928 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2933 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
2934 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
2935 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
2936 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
2937 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
2938 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2939 ptk_pn = rcu_dereference_protected(
2940 mvmsta->ptk_pn[keyidx],
2941 lockdep_is_held(&mvm->mutex));
2942 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
2944 kfree_rcu(ptk_pn, rcu_head);
2947 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2948 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2954 mutex_unlock(&mvm->mutex);
2958 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2959 struct ieee80211_vif *vif,
2960 struct ieee80211_key_conf *keyconf,
2961 struct ieee80211_sta *sta,
2962 u32 iv32, u16 *phase1key)
2964 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2966 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2969 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2973 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
2974 struct iwl_rx_packet *pkt, void *data)
2976 struct iwl_mvm *mvm =
2977 container_of(notif_wait, struct iwl_mvm, notif_wait);
2978 struct iwl_hs20_roc_res *resp;
2979 int resp_len = iwl_rx_packet_payload_len(pkt);
2980 struct iwl_mvm_time_event_data *te_data = data;
2982 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
2985 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
2986 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
2990 resp = (void *)pkt->data;
2993 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
2994 resp->status, resp->event_unique_id);
2996 te_data->uid = le32_to_cpu(resp->event_unique_id);
2997 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3000 spin_lock_bh(&mvm->time_event_lock);
3001 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3002 spin_unlock_bh(&mvm->time_event_lock);
3007 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3008 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3009 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3010 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3011 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3012 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3013 struct ieee80211_channel *channel,
3014 struct ieee80211_vif *vif,
3017 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
3018 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3019 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3020 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3021 struct iwl_notification_wait wait_time_event;
3022 u32 dtim_interval = vif->bss_conf.dtim_period *
3023 vif->bss_conf.beacon_int;
3025 struct iwl_hs20_roc_req aux_roc_req = {
3026 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3028 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3029 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3030 /* Set the channel info data */
3031 .channel_info.band = (channel->band == NL80211_BAND_2GHZ) ?
3032 PHY_BAND_24 : PHY_BAND_5,
3033 .channel_info.channel = channel->hw_value,
3034 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
3035 /* Set the time and duration */
3036 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
3039 delay = AUX_ROC_MIN_DELAY;
3040 req_dur = MSEC_TO_TU(duration);
3043 * If we are associated we want the delay time to be at least one
3044 * dtim interval so that the FW can wait until after the DTIM and
3045 * then start the time event, this will potentially allow us to
3046 * remain off-channel for the max duration.
3047 * Since we want to use almost a whole dtim interval we would also
3048 * like the delay to be for 2-3 dtim intervals, in case there are
3049 * other time events with higher priority.
3051 if (vif->bss_conf.assoc) {
3052 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3053 /* We cannot remain off-channel longer than the DTIM interval */
3054 if (dtim_interval <= req_dur) {
3055 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3056 if (req_dur <= AUX_ROC_MIN_DURATION)
3057 req_dur = dtim_interval -
3058 AUX_ROC_MIN_SAFETY_BUFFER;
3062 aux_roc_req.duration = cpu_to_le32(req_dur);
3063 aux_roc_req.apply_time_max_delay = cpu_to_le32(delay);
3066 "ROC: Requesting to remain on channel %u for %ums\n",
3067 channel->hw_value, req_dur);
3069 "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3070 duration, delay, dtim_interval);
3072 /* Set the node address */
3073 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
3075 lockdep_assert_held(&mvm->mutex);
3077 spin_lock_bh(&mvm->time_event_lock);
3079 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3080 spin_unlock_bh(&mvm->time_event_lock);
3085 te_data->duration = duration;
3086 te_data->id = HOT_SPOT_CMD;
3088 spin_unlock_bh(&mvm->time_event_lock);
3091 * Use a notification wait, which really just processes the
3092 * command response and doesn't wait for anything, in order
3093 * to be able to process the response and get the UID inside
3094 * the RX path. Using CMD_WANT_SKB doesn't work because it
3095 * stores the buffer and then wakes up this thread, by which
3096 * time another notification (that the time event started)
3097 * might already be processed unsuccessfully.
3099 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3100 time_event_response,
3101 ARRAY_SIZE(time_event_response),
3102 iwl_mvm_rx_aux_roc, te_data);
3104 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
3108 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3109 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3113 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3114 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3115 /* should never fail */
3120 spin_lock_bh(&mvm->time_event_lock);
3121 iwl_mvm_te_clear_data(mvm, te_data);
3122 spin_unlock_bh(&mvm->time_event_lock);
3128 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3129 struct ieee80211_vif *vif,
3130 struct ieee80211_channel *channel,
3132 enum ieee80211_roc_type type)
3134 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3135 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3136 struct cfg80211_chan_def chandef;
3137 struct iwl_mvm_phy_ctxt *phy_ctxt;
3140 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3143 flush_work(&mvm->roc_done_wk);
3145 mutex_lock(&mvm->mutex);
3147 switch (vif->type) {
3148 case NL80211_IFTYPE_STATION:
3149 if (fw_has_capa(&mvm->fw->ucode_capa,
3150 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3151 /* Use aux roc framework (HS20) */
3152 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3156 IWL_ERR(mvm, "hotspot not supported\n");
3159 case NL80211_IFTYPE_P2P_DEVICE:
3163 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3168 for (i = 0; i < NUM_PHY_CTX; i++) {
3169 phy_ctxt = &mvm->phy_ctxts[i];
3170 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3173 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3175 * Unbind the P2P_DEVICE from the current PHY context,
3176 * and if the PHY context is not used remove it.
3178 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3179 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3182 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3184 /* Bind the P2P_DEVICE to the current PHY Context */
3185 mvmvif->phy_ctxt = phy_ctxt;
3187 ret = iwl_mvm_binding_add_vif(mvm, vif);
3188 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3191 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3192 goto schedule_time_event;
3196 /* Need to update the PHY context only if the ROC channel changed */
3197 if (channel == mvmvif->phy_ctxt->channel)
3198 goto schedule_time_event;
3200 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3203 * Change the PHY context configuration as it is currently referenced
3204 * only by the P2P Device MAC
3206 if (mvmvif->phy_ctxt->ref == 1) {
3207 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3213 * The PHY context is shared with other MACs. Need to remove the
3214 * P2P Device from the binding, allocate an new PHY context and
3215 * create a new binding
3217 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3223 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3226 IWL_ERR(mvm, "Failed to change PHY context\n");
3230 /* Unbind the P2P_DEVICE from the current PHY context */
3231 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3232 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3235 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3237 /* Bind the P2P_DEVICE to the new allocated PHY context */
3238 mvmvif->phy_ctxt = phy_ctxt;
3240 ret = iwl_mvm_binding_add_vif(mvm, vif);
3241 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3244 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3247 schedule_time_event:
3248 /* Schedule the time events */
3249 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3252 mutex_unlock(&mvm->mutex);
3253 IWL_DEBUG_MAC80211(mvm, "leave\n");
3257 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3259 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3261 IWL_DEBUG_MAC80211(mvm, "enter\n");
3263 mutex_lock(&mvm->mutex);
3264 iwl_mvm_stop_roc(mvm);
3265 mutex_unlock(&mvm->mutex);
3267 IWL_DEBUG_MAC80211(mvm, "leave\n");
3271 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3272 struct ieee80211_chanctx_conf *ctx)
3274 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3275 struct iwl_mvm_phy_ctxt *phy_ctxt;
3278 lockdep_assert_held(&mvm->mutex);
3280 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3282 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3288 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3289 ctx->rx_chains_static,
3290 ctx->rx_chains_dynamic);
3292 IWL_ERR(mvm, "Failed to add PHY context\n");
3296 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3297 *phy_ctxt_id = phy_ctxt->id;
3302 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3303 struct ieee80211_chanctx_conf *ctx)
3305 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3308 mutex_lock(&mvm->mutex);
3309 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3310 mutex_unlock(&mvm->mutex);
3315 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3316 struct ieee80211_chanctx_conf *ctx)
3318 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3319 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3321 lockdep_assert_held(&mvm->mutex);
3323 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3326 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3327 struct ieee80211_chanctx_conf *ctx)
3329 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3331 mutex_lock(&mvm->mutex);
3332 __iwl_mvm_remove_chanctx(mvm, ctx);
3333 mutex_unlock(&mvm->mutex);
3336 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3337 struct ieee80211_chanctx_conf *ctx,
3340 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3341 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3342 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3344 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3345 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3346 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3347 IEEE80211_CHANCTX_CHANGE_RADAR |
3348 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3349 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3350 phy_ctxt->ref, changed))
3353 mutex_lock(&mvm->mutex);
3354 iwl_mvm_bt_coex_vif_change(mvm);
3355 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3356 ctx->rx_chains_static,
3357 ctx->rx_chains_dynamic);
3358 mutex_unlock(&mvm->mutex);
3361 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3362 struct ieee80211_vif *vif,
3363 struct ieee80211_chanctx_conf *ctx,
3364 bool switching_chanctx)
3366 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3367 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3368 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3371 lockdep_assert_held(&mvm->mutex);
3373 mvmvif->phy_ctxt = phy_ctxt;
3375 switch (vif->type) {
3376 case NL80211_IFTYPE_AP:
3377 /* only needed if we're switching chanctx (i.e. during CSA) */
3378 if (switching_chanctx) {
3379 mvmvif->ap_ibss_active = true;
3382 case NL80211_IFTYPE_ADHOC:
3384 * The AP binding flow is handled as part of the start_ap flow
3385 * (in bss_info_changed), similarly for IBSS.
3389 case NL80211_IFTYPE_STATION:
3391 case NL80211_IFTYPE_MONITOR:
3392 /* always disable PS when a monitor interface is active */
3393 mvmvif->ps_disabled = true;
3400 ret = iwl_mvm_binding_add_vif(mvm, vif);
3405 * Power state must be updated before quotas,
3406 * otherwise fw will complain.
3408 iwl_mvm_power_update_mac(mvm);
3410 /* Setting the quota at this stage is only required for monitor
3411 * interfaces. For the other types, the bss_info changed flow
3412 * will handle quota settings.
3414 if (vif->type == NL80211_IFTYPE_MONITOR) {
3415 mvmvif->monitor_active = true;
3416 ret = iwl_mvm_update_quotas(mvm, false, NULL);
3418 goto out_remove_binding;
3420 ret = iwl_mvm_add_snif_sta(mvm, vif);
3422 goto out_remove_binding;
3426 /* Handle binding during CSA */
3427 if (vif->type == NL80211_IFTYPE_AP) {
3428 iwl_mvm_update_quotas(mvm, false, NULL);
3429 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3432 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3433 u32 duration = 2 * vif->bss_conf.beacon_int;
3435 /* iwl_mvm_protect_session() reads directly from the
3436 * device (the system time), so make sure it is
3439 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3441 goto out_remove_binding;
3443 /* Protect the session to make sure we hear the first
3444 * beacon on the new channel.
3446 iwl_mvm_protect_session(mvm, vif, duration, duration,
3447 vif->bss_conf.beacon_int / 2,
3450 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3452 iwl_mvm_update_quotas(mvm, false, NULL);
3458 iwl_mvm_binding_remove_vif(mvm, vif);
3459 iwl_mvm_power_update_mac(mvm);
3462 mvmvif->phy_ctxt = NULL;
3465 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3466 struct ieee80211_vif *vif,
3467 struct ieee80211_chanctx_conf *ctx)
3469 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3472 mutex_lock(&mvm->mutex);
3473 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3474 mutex_unlock(&mvm->mutex);
3479 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3480 struct ieee80211_vif *vif,
3481 struct ieee80211_chanctx_conf *ctx,
3482 bool switching_chanctx)
3484 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3485 struct ieee80211_vif *disabled_vif = NULL;
3487 lockdep_assert_held(&mvm->mutex);
3489 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3491 switch (vif->type) {
3492 case NL80211_IFTYPE_ADHOC:
3494 case NL80211_IFTYPE_MONITOR:
3495 mvmvif->monitor_active = false;
3496 mvmvif->ps_disabled = false;
3497 iwl_mvm_rm_snif_sta(mvm, vif);
3499 case NL80211_IFTYPE_AP:
3500 /* This part is triggered only during CSA */
3501 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3504 mvmvif->csa_countdown = false;
3506 /* Set CS bit on all the stations */
3507 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3509 /* Save blocked iface, the timeout is set on the next beacon */
3510 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3512 mvmvif->ap_ibss_active = false;
3514 case NL80211_IFTYPE_STATION:
3515 if (!switching_chanctx)
3520 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3526 iwl_mvm_update_quotas(mvm, false, disabled_vif);
3527 iwl_mvm_binding_remove_vif(mvm, vif);
3530 mvmvif->phy_ctxt = NULL;
3531 iwl_mvm_power_update_mac(mvm);
3534 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3535 struct ieee80211_vif *vif,
3536 struct ieee80211_chanctx_conf *ctx)
3538 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3540 mutex_lock(&mvm->mutex);
3541 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3542 mutex_unlock(&mvm->mutex);
3546 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3547 struct ieee80211_vif_chanctx_switch *vifs)
3551 mutex_lock(&mvm->mutex);
3552 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3553 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3555 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3557 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3561 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3565 "failed to assign new_ctx during channel switch\n");
3569 /* we don't support TDLS during DCM - can be caused by channel switch */
3570 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3571 iwl_mvm_teardown_tdls_peers(mvm);
3576 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3579 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3580 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3584 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3586 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3593 /* things keep failing, better restart the hw */
3594 iwl_mvm_nic_restart(mvm, false);
3597 mutex_unlock(&mvm->mutex);
3603 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3604 struct ieee80211_vif_chanctx_switch *vifs)
3608 mutex_lock(&mvm->mutex);
3609 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3611 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3615 "failed to assign new_ctx during channel switch\n");
3622 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3624 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3631 /* things keep failing, better restart the hw */
3632 iwl_mvm_nic_restart(mvm, false);
3635 mutex_unlock(&mvm->mutex);
3640 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3641 struct ieee80211_vif_chanctx_switch *vifs,
3643 enum ieee80211_chanctx_switch_mode mode)
3645 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3648 /* we only support a single-vif right now */
3653 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3654 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3656 case CHANCTX_SWMODE_REASSIGN_VIF:
3657 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
3667 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3668 struct ieee80211_sta *sta,
3671 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3672 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3674 if (!mvm_sta || !mvm_sta->vif) {
3675 IWL_ERR(mvm, "Station is not associated to a vif\n");
3679 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3682 #ifdef CONFIG_NL80211_TESTMODE
3683 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3684 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3685 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
3686 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
3689 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3690 struct ieee80211_vif *vif,
3691 void *data, int len)
3693 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3697 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
3701 if (!tb[IWL_MVM_TM_ATTR_CMD])
3704 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3705 case IWL_MVM_TM_CMD_SET_NOA:
3706 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3707 !vif->bss_conf.enable_beacon ||
3708 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3711 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3712 if (noa_duration >= vif->bss_conf.beacon_int)
3715 mvm->noa_duration = noa_duration;
3718 return iwl_mvm_update_quotas(mvm, false, NULL);
3719 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3720 /* must be associated client vif - ignore authorized */
3721 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3722 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3723 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3726 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
3727 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3728 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3734 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3735 struct ieee80211_vif *vif,
3736 void *data, int len)
3738 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3741 mutex_lock(&mvm->mutex);
3742 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3743 mutex_unlock(&mvm->mutex);
3749 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3750 struct ieee80211_vif *vif,
3751 struct ieee80211_channel_switch *chsw)
3753 /* By implementing this operation, we prevent mac80211 from
3754 * starting its own channel switch timer, so that we can call
3755 * ieee80211_chswitch_done() ourselves at the right time
3756 * (which is when the absence time event starts).
3759 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3760 "dummy channel switch op\n");
3763 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3764 struct ieee80211_vif *vif,
3765 struct ieee80211_channel_switch *chsw)
3767 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3768 struct ieee80211_vif *csa_vif;
3769 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3773 mutex_lock(&mvm->mutex);
3775 mvmvif->csa_failed = false;
3777 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
3778 chsw->chandef.center_freq1);
3780 iwl_fw_dbg_trigger_simple_stop(mvm, vif, FW_DBG_TRIGGER_CHANNEL_SWITCH);
3782 switch (vif->type) {
3783 case NL80211_IFTYPE_AP:
3785 rcu_dereference_protected(mvm->csa_vif,
3786 lockdep_is_held(&mvm->mutex));
3787 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3788 "Another CSA is already in progress")) {
3793 /* we still didn't unblock tx. prevent new CS meanwhile */
3794 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
3795 lockdep_is_held(&mvm->mutex))) {
3800 rcu_assign_pointer(mvm->csa_vif, vif);
3802 if (WARN_ONCE(mvmvif->csa_countdown,
3803 "Previous CSA countdown didn't complete")) {
3808 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
3811 case NL80211_IFTYPE_STATION:
3812 if (mvmvif->lqm_active)
3813 iwl_mvm_send_lqm_cmd(vif,
3814 LQM_CMD_OPERATION_STOP_MEASUREMENT,
3817 /* Schedule the time event to a bit before beacon 1,
3818 * to make sure we're in the new channel when the
3821 apply_time = chsw->device_timestamp +
3822 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3823 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
3826 iwl_mvm_csa_client_absent(mvm, vif);
3828 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
3830 if (mvmvif->bf_data.bf_enabled) {
3831 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3841 mvmvif->ps_disabled = true;
3843 ret = iwl_mvm_power_update_ps(mvm);
3847 /* we won't be on this channel any longer */
3848 iwl_mvm_teardown_tdls_peers(mvm);
3851 mutex_unlock(&mvm->mutex);
3856 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
3857 struct ieee80211_vif *vif)
3859 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3860 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3863 mutex_lock(&mvm->mutex);
3865 if (mvmvif->csa_failed) {
3866 mvmvif->csa_failed = false;
3871 if (vif->type == NL80211_IFTYPE_STATION) {
3872 struct iwl_mvm_sta *mvmsta;
3874 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
3877 if (WARN_ON(!mvmsta)) {
3882 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
3884 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3886 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3890 iwl_mvm_stop_session_protection(mvm, vif);
3893 mvmvif->ps_disabled = false;
3895 ret = iwl_mvm_power_update_ps(mvm);
3898 mutex_unlock(&mvm->mutex);
3903 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3904 struct ieee80211_vif *vif, u32 queues, bool drop)
3906 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3907 struct iwl_mvm_vif *mvmvif;
3908 struct iwl_mvm_sta *mvmsta;
3909 struct ieee80211_sta *sta;
3913 if (!vif || vif->type != NL80211_IFTYPE_STATION)
3916 /* Make sure we're done with the deferred traffic before flushing */
3917 if (iwl_mvm_is_dqa_supported(mvm))
3918 flush_work(&mvm->add_stream_wk);
3920 mutex_lock(&mvm->mutex);
3921 mvmvif = iwl_mvm_vif_from_mac80211(vif);
3923 /* flush the AP-station and all TDLS peers */
3924 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
3925 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3926 lockdep_is_held(&mvm->mutex));
3927 if (IS_ERR_OR_NULL(sta))
3930 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3931 if (mvmsta->vif != vif)
3934 /* make sure only TDLS peers or the AP are flushed */
3935 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
3937 msk |= mvmsta->tfd_queue_msk;
3941 if (iwl_mvm_flush_tx_path(mvm, msk, 0))
3942 IWL_ERR(mvm, "flush request fail\n");
3943 mutex_unlock(&mvm->mutex);
3945 mutex_unlock(&mvm->mutex);
3947 /* this can take a while, and we may need/want other operations
3948 * to succeed while doing this, so do it without the mutex held
3950 iwl_trans_wait_tx_queue_empty(mvm->trans, msk);
3954 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
3955 struct survey_info *survey)
3957 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3960 memset(survey, 0, sizeof(*survey));
3962 /* only support global statistics right now */
3966 if (!fw_has_capa(&mvm->fw->ucode_capa,
3967 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
3970 mutex_lock(&mvm->mutex);
3972 if (mvm->ucode_loaded) {
3973 ret = iwl_mvm_request_statistics(mvm, false);
3978 survey->filled = SURVEY_INFO_TIME |
3979 SURVEY_INFO_TIME_RX |
3980 SURVEY_INFO_TIME_TX |
3981 SURVEY_INFO_TIME_SCAN;
3982 survey->time = mvm->accu_radio_stats.on_time_rf +
3983 mvm->radio_stats.on_time_rf;
3984 do_div(survey->time, USEC_PER_MSEC);
3986 survey->time_rx = mvm->accu_radio_stats.rx_time +
3987 mvm->radio_stats.rx_time;
3988 do_div(survey->time_rx, USEC_PER_MSEC);
3990 survey->time_tx = mvm->accu_radio_stats.tx_time +
3991 mvm->radio_stats.tx_time;
3992 do_div(survey->time_tx, USEC_PER_MSEC);
3994 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
3995 mvm->radio_stats.on_time_scan;
3996 do_div(survey->time_scan, USEC_PER_MSEC);
4000 mutex_unlock(&mvm->mutex);
4004 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4005 struct ieee80211_vif *vif,
4006 struct ieee80211_sta *sta,
4007 struct station_info *sinfo)
4009 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4010 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4011 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4013 if (mvmsta->avg_energy) {
4014 sinfo->signal_avg = mvmsta->avg_energy;
4015 sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL_AVG);
4018 /* if beacon filtering isn't on mac80211 does it anyway */
4019 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4022 if (!vif->bss_conf.assoc)
4025 mutex_lock(&mvm->mutex);
4027 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4030 if (iwl_mvm_request_statistics(mvm, false))
4033 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4034 mvmvif->beacon_stats.accu_num_beacons;
4035 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX);
4036 if (mvmvif->beacon_stats.avg_signal) {
4037 /* firmware only reports a value after RXing a few beacons */
4038 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4039 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4042 mutex_unlock(&mvm->mutex);
4045 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4046 struct ieee80211_vif *vif,
4047 const struct ieee80211_event *event)
4049 #define CHECK_MLME_TRIGGER(_mvm, _trig, _buf, _cnt, _fmt...) \
4051 if ((_cnt) && --(_cnt)) \
4053 iwl_mvm_fw_dbg_collect_trig(_mvm, _trig, _fmt);\
4056 struct iwl_fw_dbg_trigger_tlv *trig;
4057 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4059 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_MLME))
4062 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_MLME);
4063 trig_mlme = (void *)trig->data;
4064 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
4067 if (event->u.mlme.data == ASSOC_EVENT) {
4068 if (event->u.mlme.status == MLME_DENIED)
4069 CHECK_MLME_TRIGGER(mvm, trig, buf,
4070 trig_mlme->stop_assoc_denied,
4071 "DENIED ASSOC: reason %d",
4072 event->u.mlme.reason);
4073 else if (event->u.mlme.status == MLME_TIMEOUT)
4074 CHECK_MLME_TRIGGER(mvm, trig, buf,
4075 trig_mlme->stop_assoc_timeout,
4077 } else if (event->u.mlme.data == AUTH_EVENT) {
4078 if (event->u.mlme.status == MLME_DENIED)
4079 CHECK_MLME_TRIGGER(mvm, trig, buf,
4080 trig_mlme->stop_auth_denied,
4081 "DENIED AUTH: reason %d",
4082 event->u.mlme.reason);
4083 else if (event->u.mlme.status == MLME_TIMEOUT)
4084 CHECK_MLME_TRIGGER(mvm, trig, buf,
4085 trig_mlme->stop_auth_timeout,
4087 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4088 CHECK_MLME_TRIGGER(mvm, trig, buf,
4089 trig_mlme->stop_rx_deauth,
4090 "DEAUTH RX %d", event->u.mlme.reason);
4091 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4092 CHECK_MLME_TRIGGER(mvm, trig, buf,
4093 trig_mlme->stop_tx_deauth,
4094 "DEAUTH TX %d", event->u.mlme.reason);
4096 #undef CHECK_MLME_TRIGGER
4099 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4100 struct ieee80211_vif *vif,
4101 const struct ieee80211_event *event)
4103 struct iwl_fw_dbg_trigger_tlv *trig;
4104 struct iwl_fw_dbg_trigger_ba *ba_trig;
4106 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
4109 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
4110 ba_trig = (void *)trig->data;
4111 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
4114 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
4117 iwl_mvm_fw_dbg_collect_trig(mvm, trig,
4118 "BAR received from %pM, tid %d, ssn %d",
4119 event->u.ba.sta->addr, event->u.ba.tid,
4124 iwl_mvm_event_frame_timeout_callback(struct iwl_mvm *mvm,
4125 struct ieee80211_vif *vif,
4126 const struct ieee80211_event *event)
4128 struct iwl_fw_dbg_trigger_tlv *trig;
4129 struct iwl_fw_dbg_trigger_ba *ba_trig;
4131 if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_BA))
4134 trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_BA);
4135 ba_trig = (void *)trig->data;
4136 if (!iwl_fw_dbg_trigger_check_stop(mvm, vif, trig))
4139 if (!(le16_to_cpu(ba_trig->frame_timeout) & BIT(event->u.ba.tid)))
4142 iwl_mvm_fw_dbg_collect_trig(mvm, trig,
4143 "Frame from %pM timed out, tid %d",
4144 event->u.ba.sta->addr, event->u.ba.tid);
4147 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
4148 struct ieee80211_vif *vif,
4149 const struct ieee80211_event *event)
4151 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4153 switch (event->type) {
4155 iwl_mvm_event_mlme_callback(mvm, vif, event);
4158 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
4160 case BA_FRAME_TIMEOUT:
4161 iwl_mvm_event_frame_timeout_callback(mvm, vif, event);
4168 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
4169 struct iwl_mvm_internal_rxq_notif *notif,
4172 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
4175 lockdep_assert_held(&mvm->mutex);
4177 if (!iwl_mvm_has_new_rx_api(mvm))
4180 notif->cookie = mvm->queue_sync_cookie;
4183 atomic_set(&mvm->queue_sync_counter,
4184 mvm->trans->num_rx_queues);
4186 ret = iwl_mvm_notify_rx_queue(mvm, qmask, (u8 *)notif, size);
4188 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
4193 ret = wait_event_timeout(mvm->rx_sync_waitq,
4194 atomic_read(&mvm->queue_sync_counter) == 0,
4199 atomic_set(&mvm->queue_sync_counter, 0);
4200 mvm->queue_sync_cookie++;
4203 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
4205 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4206 struct iwl_mvm_internal_rxq_notif data = {
4207 .type = IWL_MVM_RXQ_EMPTY,
4211 mutex_lock(&mvm->mutex);
4212 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
4213 mutex_unlock(&mvm->mutex);
4216 const struct ieee80211_ops iwl_mvm_hw_ops = {
4217 .tx = iwl_mvm_mac_tx,
4218 .ampdu_action = iwl_mvm_mac_ampdu_action,
4219 .start = iwl_mvm_mac_start,
4220 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
4221 .stop = iwl_mvm_mac_stop,
4222 .add_interface = iwl_mvm_mac_add_interface,
4223 .remove_interface = iwl_mvm_mac_remove_interface,
4224 .config = iwl_mvm_mac_config,
4225 .prepare_multicast = iwl_mvm_prepare_multicast,
4226 .configure_filter = iwl_mvm_configure_filter,
4227 .config_iface_filter = iwl_mvm_config_iface_filter,
4228 .bss_info_changed = iwl_mvm_bss_info_changed,
4229 .hw_scan = iwl_mvm_mac_hw_scan,
4230 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
4231 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
4232 .sta_state = iwl_mvm_mac_sta_state,
4233 .sta_notify = iwl_mvm_mac_sta_notify,
4234 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
4235 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
4236 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
4237 .sta_rc_update = iwl_mvm_sta_rc_update,
4238 .conf_tx = iwl_mvm_mac_conf_tx,
4239 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
4240 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
4241 .flush = iwl_mvm_mac_flush,
4242 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
4243 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
4244 .set_key = iwl_mvm_mac_set_key,
4245 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
4246 .remain_on_channel = iwl_mvm_roc,
4247 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
4248 .add_chanctx = iwl_mvm_add_chanctx,
4249 .remove_chanctx = iwl_mvm_remove_chanctx,
4250 .change_chanctx = iwl_mvm_change_chanctx,
4251 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
4252 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
4253 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
4255 .start_ap = iwl_mvm_start_ap_ibss,
4256 .stop_ap = iwl_mvm_stop_ap_ibss,
4257 .join_ibss = iwl_mvm_start_ap_ibss,
4258 .leave_ibss = iwl_mvm_stop_ap_ibss,
4260 .set_tim = iwl_mvm_set_tim,
4262 .channel_switch = iwl_mvm_channel_switch,
4263 .pre_channel_switch = iwl_mvm_pre_channel_switch,
4264 .post_channel_switch = iwl_mvm_post_channel_switch,
4266 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
4267 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
4268 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
4270 .event_callback = iwl_mvm_mac_event_callback,
4272 .sync_rx_queues = iwl_mvm_sync_rx_queues,
4274 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
4276 #ifdef CONFIG_PM_SLEEP
4278 .suspend = iwl_mvm_suspend,
4279 .resume = iwl_mvm_resume,
4280 .set_wakeup = iwl_mvm_set_wakeup,
4281 .set_rekey_data = iwl_mvm_set_rekey_data,
4282 #if IS_ENABLED(CONFIG_IPV6)
4283 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
4285 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
4287 .get_survey = iwl_mvm_mac_get_survey,
4288 .sta_statistics = iwl_mvm_mac_sta_statistics,