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
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *****************************************************************************/
65 #include <linux/kernel.h>
66 #include <linux/slab.h>
67 #include <linux/skbuff.h>
68 #include <linux/netdevice.h>
69 #include <linux/etherdevice.h>
71 #include <linux/if_arp.h>
72 #include <linux/devcoredump.h>
73 #include <net/mac80211.h>
74 #include <net/ieee80211_radiotap.h>
77 #include "iwl-op-mode.h"
81 #include "time-event.h"
82 #include "iwl-eeprom-parse.h"
83 #include "fw-api-scan.h"
84 #include "iwl-phy-db.h"
86 #include "iwl-fw-error-dump.h"
89 #include "iwl-nvm-parse.h"
91 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
94 .types = BIT(NL80211_IFTYPE_STATION),
98 .types = BIT(NL80211_IFTYPE_AP) |
99 BIT(NL80211_IFTYPE_P2P_CLIENT) |
100 BIT(NL80211_IFTYPE_P2P_GO),
104 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
108 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
110 .num_different_channels = 2,
112 .limits = iwl_mvm_limits,
113 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
117 #ifdef CONFIG_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 WARN_ON(!mvm->refs[ref_type]--);
233 spin_unlock_bh(&mvm->refs_lock);
234 iwl_trans_unref(mvm->trans);
237 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
238 enum iwl_mvm_ref_type except_ref)
242 if (!iwl_mvm_is_d0i3_supported(mvm))
245 spin_lock_bh(&mvm->refs_lock);
246 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
247 if (except_ref == i || !mvm->refs[i])
250 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
252 for (j = 0; j < mvm->refs[i]; j++)
253 iwl_trans_unref(mvm->trans);
256 spin_unlock_bh(&mvm->refs_lock);
259 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
264 if (!iwl_mvm_is_d0i3_supported(mvm))
267 spin_lock_bh(&mvm->refs_lock);
268 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
274 spin_unlock_bh(&mvm->refs_lock);
279 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
281 iwl_mvm_ref(mvm, ref_type);
283 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
284 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
287 iwl_mvm_unref(mvm, ref_type);
294 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
298 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
299 for (i = 0; i < NUM_PHY_CTX; i++) {
300 mvm->phy_ctxts[i].id = i;
301 mvm->phy_ctxts[i].ref = 0;
305 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
308 struct ieee80211_regdomain *regd = NULL;
309 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
310 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
311 struct iwl_mcc_update_resp *resp;
313 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
315 mutex_lock(&mvm->mutex);
317 /* change "99" to "ZZ" for the FW */
318 if (alpha2[0] == '9' && alpha2[1] == '9')
321 resp = iwl_mvm_update_mcc(mvm, alpha2);
322 if (IS_ERR_OR_NULL(resp)) {
323 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
328 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
329 __le32_to_cpu(resp->n_channels),
331 __le16_to_cpu(resp->mcc));
333 if (IS_ERR_OR_NULL(regd)) {
334 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
339 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x)\n",
340 regd->alpha2, regd->alpha2[0], regd->alpha2[1]);
341 mvm->lar_regdom_set = true;
344 mutex_unlock(&mvm->mutex);
348 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
350 struct ieee80211_hw *hw = mvm->hw;
353 /* Tell mac80211 our characteristics */
354 hw->flags = IEEE80211_HW_SIGNAL_DBM |
355 IEEE80211_HW_SPECTRUM_MGMT |
356 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
357 IEEE80211_HW_QUEUE_CONTROL |
358 IEEE80211_HW_WANT_MONITOR_VIF |
359 IEEE80211_HW_SUPPORTS_PS |
360 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
361 IEEE80211_HW_AMPDU_AGGREGATION |
362 IEEE80211_HW_TIMING_BEACON_ONLY |
363 IEEE80211_HW_CONNECTION_MONITOR |
364 IEEE80211_HW_CHANCTX_STA_CSA |
365 IEEE80211_HW_SUPPORTS_CLONED_SKBS;
367 hw->queues = mvm->first_agg_queue;
368 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
369 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
370 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
371 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
372 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
373 hw->rate_control_algorithm = "iwl-mvm-rs";
374 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
375 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
378 * Enable 11w if advertised by firmware and software crypto
379 * is not enabled (as the firmware will interpret some mgmt
380 * packets, so enabling it with software crypto isn't safe)
382 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
383 !iwlwifi_mod_params.sw_crypto)
384 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
386 hw->flags |= IEEE80211_SINGLE_HW_SCAN_ON_ALL_BANDS;
387 hw->wiphy->features |=
388 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
389 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
391 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
392 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
393 hw->chanctx_data_size = sizeof(u16);
395 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
396 BIT(NL80211_IFTYPE_P2P_CLIENT) |
397 BIT(NL80211_IFTYPE_AP) |
398 BIT(NL80211_IFTYPE_P2P_GO) |
399 BIT(NL80211_IFTYPE_P2P_DEVICE) |
400 BIT(NL80211_IFTYPE_ADHOC);
402 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
403 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
404 REGULATORY_DISABLE_BEACON_HINTS;
406 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
407 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
409 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
411 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
412 hw->wiphy->n_iface_combinations =
413 ARRAY_SIZE(iwl_mvm_iface_combinations);
415 hw->wiphy->max_remain_on_channel_duration = 10000;
416 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
417 /* we can compensate an offset of up to 3 channels = 15 MHz */
418 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
420 /* Extract MAC address */
421 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
422 hw->wiphy->addresses = mvm->addresses;
423 hw->wiphy->n_addresses = 1;
425 /* Extract additional MAC addresses if available */
426 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
427 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
429 for (i = 1; i < num_mac; i++) {
430 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
432 mvm->addresses[i].addr[5]++;
433 hw->wiphy->n_addresses++;
436 iwl_mvm_reset_phy_ctxts(mvm);
438 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm, false);
440 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
442 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
443 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
444 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
445 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) {
446 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
447 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
449 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_BEAMFORMER)
450 hw->wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap.cap |=
451 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
454 hw->wiphy->hw_version = mvm->trans->hw_id;
456 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
457 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
459 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
461 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 10) {
462 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
463 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
464 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
465 /* we create the 802.11 header and zero length SSID IE. */
466 hw->wiphy->max_sched_scan_ie_len =
467 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
470 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
471 NL80211_FEATURE_LOW_PRIORITY_SCAN |
472 NL80211_FEATURE_P2P_GO_OPPPS |
473 NL80211_FEATURE_DYNAMIC_SMPS |
474 NL80211_FEATURE_STATIC_SMPS |
475 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
477 if (mvm->fw->ucode_capa.capa[0] &
478 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)
479 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
480 if (mvm->fw->ucode_capa.capa[0] &
481 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)
482 hw->wiphy->features |= NL80211_FEATURE_QUIET;
484 if (mvm->fw->ucode_capa.capa[0] &
485 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)
486 hw->wiphy->features |=
487 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
489 if (mvm->fw->ucode_capa.capa[0] &
490 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)
491 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
493 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
495 /* currently FW API supports only one optional cipher scheme */
496 if (mvm->fw->cs[0].cipher) {
497 mvm->hw->n_cipher_schemes = 1;
498 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
501 #ifdef CONFIG_PM_SLEEP
502 if (iwl_mvm_is_d0i3_supported(mvm) &&
503 device_can_wakeup(mvm->trans->dev)) {
504 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
505 hw->wiphy->wowlan = &mvm->wowlan;
508 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
509 mvm->trans->ops->d3_suspend &&
510 mvm->trans->ops->d3_resume &&
511 device_can_wakeup(mvm->trans->dev)) {
512 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
513 WIPHY_WOWLAN_DISCONNECT |
514 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
515 WIPHY_WOWLAN_RFKILL_RELEASE |
516 WIPHY_WOWLAN_NET_DETECT;
517 if (!iwlwifi_mod_params.sw_crypto)
518 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
519 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
520 WIPHY_WOWLAN_4WAY_HANDSHAKE;
522 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
523 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
524 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
525 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
526 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
527 hw->wiphy->wowlan = &mvm->wowlan;
531 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
532 /* assign default bcast filtering configuration */
533 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
536 ret = iwl_mvm_leds_init(mvm);
540 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_TDLS_SUPPORT) {
541 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
542 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
545 if (mvm->fw->ucode_capa.capa[0] &
546 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH) {
547 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
548 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
551 ret = ieee80211_register_hw(mvm->hw);
553 iwl_mvm_leds_exit(mvm);
558 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
559 struct ieee80211_sta *sta,
562 struct iwl_mvm_sta *mvmsta;
566 * double check the IN_D0I3 flag both before and after
567 * taking the spinlock, in order to prevent taking
568 * the spinlock when not needed.
570 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
573 spin_lock(&mvm->d0i3_tx_lock);
575 * testing the flag again ensures the skb dequeue
576 * loop (on d0i3 exit) hasn't run yet.
578 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
581 mvmsta = iwl_mvm_sta_from_mac80211(sta);
582 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
583 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
586 __skb_queue_tail(&mvm->d0i3_tx, skb);
587 ieee80211_stop_queues(mvm->hw);
590 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
591 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
595 spin_unlock(&mvm->d0i3_tx_lock);
599 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
600 struct ieee80211_tx_control *control,
603 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
604 struct ieee80211_sta *sta = control->sta;
605 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
606 struct ieee80211_hdr *hdr = (void *)skb->data;
608 if (iwl_mvm_is_radio_killed(mvm)) {
609 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
613 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
614 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
615 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
618 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
619 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
620 ieee80211_is_mgmt(hdr->frame_control) &&
621 !ieee80211_is_deauth(hdr->frame_control) &&
622 !ieee80211_is_disassoc(hdr->frame_control) &&
623 !ieee80211_is_action(hdr->frame_control)))
627 if (iwl_mvm_defer_tx(mvm, sta, skb))
629 if (iwl_mvm_tx_skb(mvm, skb, sta))
634 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
638 ieee80211_free_txskb(hw, skb);
641 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
643 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
648 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
650 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
652 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
655 /* enabled by default */
659 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
660 struct ieee80211_vif *vif,
661 enum ieee80211_ampdu_mlme_action action,
662 struct ieee80211_sta *sta, u16 tid,
663 u16 *ssn, u8 buf_size)
665 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
667 bool tx_agg_ref = false;
669 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
670 sta->addr, tid, action);
672 if (!(mvm->nvm_data->sku_cap_11n_enable))
675 /* return from D0i3 before starting a new Tx aggregation */
677 case IEEE80211_AMPDU_TX_START:
678 case IEEE80211_AMPDU_TX_STOP_CONT:
679 case IEEE80211_AMPDU_TX_STOP_FLUSH:
680 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
681 case IEEE80211_AMPDU_TX_OPERATIONAL:
683 * for tx start, wait synchronously until D0i3 exit to
684 * get the correct sequence number for the tid.
685 * additionally, some other ampdu actions use direct
686 * target access, which is not handled automatically
687 * by the trans layer (unlike commands), so wait for
688 * d0i3 exit in these cases as well.
690 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
700 mutex_lock(&mvm->mutex);
703 case IEEE80211_AMPDU_RX_START:
704 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
708 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
710 case IEEE80211_AMPDU_RX_STOP:
711 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
713 case IEEE80211_AMPDU_TX_START:
714 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
718 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
720 case IEEE80211_AMPDU_TX_STOP_CONT:
721 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
723 case IEEE80211_AMPDU_TX_STOP_FLUSH:
724 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
725 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
727 case IEEE80211_AMPDU_TX_OPERATIONAL:
728 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
735 mutex_unlock(&mvm->mutex);
738 * If the tid is marked as started, we won't use it for offloaded
739 * traffic on the next D0i3 entry. It's safe to unref.
742 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
747 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
748 struct ieee80211_vif *vif)
750 struct iwl_mvm *mvm = data;
751 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
753 mvmvif->uploaded = false;
754 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
756 spin_lock_bh(&mvm->time_event_lock);
757 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
758 spin_unlock_bh(&mvm->time_event_lock);
760 mvmvif->phy_ctxt = NULL;
761 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
764 static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
765 const void *data, size_t datalen)
767 const struct iwl_mvm_dump_ptrs *dump_ptrs = data;
769 ssize_t bytes_read_trans;
771 if (offset < dump_ptrs->op_mode_len) {
772 bytes_read = min_t(ssize_t, count,
773 dump_ptrs->op_mode_len - offset);
774 memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset,
776 offset += bytes_read;
785 if (!dump_ptrs->trans_ptr)
788 offset -= dump_ptrs->op_mode_len;
789 bytes_read_trans = min_t(ssize_t, count,
790 dump_ptrs->trans_ptr->len - offset);
791 memcpy(buffer + bytes_read,
792 (u8 *)dump_ptrs->trans_ptr->data + offset,
795 return bytes_read + bytes_read_trans;
798 static void iwl_mvm_free_coredump(const void *data)
800 const struct iwl_mvm_dump_ptrs *fw_error_dump = data;
802 vfree(fw_error_dump->op_mode_ptr);
803 vfree(fw_error_dump->trans_ptr);
804 kfree(fw_error_dump);
807 static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm,
808 struct iwl_fw_error_dump_data **dump_data)
810 struct iwl_fw_error_dump_fifo *fifo_hdr;
816 if (!iwl_trans_grab_nic_access(mvm->trans, false, &flags))
819 /* Pull RXF data from all RXFs */
820 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) {
822 * Keep aside the additional offset that might be needed for
825 u32 offset_diff = RXF_DIFF_FROM_PREV * i;
827 fifo_hdr = (void *)(*dump_data)->data;
828 fifo_data = (void *)fifo_hdr->data;
829 fifo_len = mvm->shared_mem_cfg.rxfifo_size[i];
831 /* No need to try to read the data if the length is 0 */
835 /* Add a TLV for the RXF */
836 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
837 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
839 fifo_hdr->fifo_num = cpu_to_le32(i);
840 fifo_hdr->available_bytes =
841 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
845 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
849 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
852 fifo_hdr->fence_ptr =
853 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
856 fifo_hdr->fence_mode =
857 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
862 iwl_trans_write_prph(mvm->trans,
863 RXF_SET_FENCE_MODE + offset_diff, 0x1);
864 /* Set fence pointer to the same place like WR pointer */
865 iwl_trans_write_prph(mvm->trans,
866 RXF_LD_WR2FENCE + offset_diff, 0x1);
867 /* Set fence offset */
868 iwl_trans_write_prph(mvm->trans,
869 RXF_LD_FENCE_OFFSET_ADDR + offset_diff,
873 fifo_len /= sizeof(u32); /* Size in DWORDS */
874 for (j = 0; j < fifo_len; j++)
875 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
876 RXF_FIFO_RD_FENCE_INC +
878 *dump_data = iwl_fw_error_next_data(*dump_data);
881 /* Pull TXF data from all TXFs */
882 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++) {
883 /* Mark the number of TXF we're pulling now */
884 iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i);
886 fifo_hdr = (void *)(*dump_data)->data;
887 fifo_data = (void *)fifo_hdr->data;
888 fifo_len = mvm->shared_mem_cfg.txfifo_size[i];
890 /* No need to try to read the data if the length is 0 */
894 /* Add a TLV for the FIFO */
895 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF);
896 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
898 fifo_hdr->fifo_num = cpu_to_le32(i);
899 fifo_hdr->available_bytes =
900 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
903 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
906 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
908 fifo_hdr->fence_ptr =
909 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
911 fifo_hdr->fence_mode =
912 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
915 /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */
916 iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR,
919 /* Dummy-read to advance the read pointer to the head */
920 iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA);
923 fifo_len /= sizeof(u32); /* Size in DWORDS */
924 for (j = 0; j < fifo_len; j++)
925 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
926 TXF_READ_MODIFY_DATA);
927 *dump_data = iwl_fw_error_next_data(*dump_data);
930 iwl_trans_release_nic_access(mvm->trans, &flags);
933 void iwl_mvm_free_fw_dump_desc(struct iwl_mvm *mvm)
935 if (mvm->fw_dump_desc == &iwl_mvm_dump_desc_assert ||
939 kfree(mvm->fw_dump_desc);
940 mvm->fw_dump_desc = NULL;
943 void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
945 struct iwl_fw_error_dump_file *dump_file;
946 struct iwl_fw_error_dump_data *dump_data;
947 struct iwl_fw_error_dump_info *dump_info;
948 struct iwl_fw_error_dump_mem *dump_mem;
949 struct iwl_fw_error_dump_trigger_desc *dump_trig;
950 struct iwl_mvm_dump_ptrs *fw_error_dump;
951 u32 sram_len, sram_ofs;
952 u32 file_len, fifo_data_len = 0;
953 u32 smem_len = mvm->cfg->smem_len;
954 u32 sram2_len = mvm->cfg->dccm2_len;
956 lockdep_assert_held(&mvm->mutex);
958 /* W/A for 8000 HW family A-step */
959 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
960 CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_A_STEP) {
968 fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
972 /* SRAM - include stack CCM if driver knows the values for it */
973 if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
974 const struct fw_img *img;
976 img = &mvm->fw->img[mvm->cur_ucode];
977 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
978 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
980 sram_ofs = mvm->cfg->dccm_offset;
981 sram_len = mvm->cfg->dccm_len;
984 /* reading RXF/TXF sizes */
985 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
986 struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->shared_mem_cfg;
992 for (i = 0; i < ARRAY_SIZE(mem_cfg->rxfifo_size); i++) {
993 if (!mem_cfg->rxfifo_size[i])
996 /* Add header info */
997 fifo_data_len += mem_cfg->rxfifo_size[i] +
999 sizeof(struct iwl_fw_error_dump_fifo);
1002 for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) {
1003 if (!mem_cfg->txfifo_size[i])
1006 /* Add header info */
1007 fifo_data_len += mem_cfg->txfifo_size[i] +
1008 sizeof(*dump_data) +
1009 sizeof(struct iwl_fw_error_dump_fifo);
1013 file_len = sizeof(*dump_file) +
1014 sizeof(*dump_data) * 2 +
1015 sram_len + sizeof(*dump_mem) +
1019 if (mvm->fw_dump_desc)
1020 file_len += sizeof(*dump_data) + sizeof(*dump_trig) +
1021 mvm->fw_dump_desc->len;
1023 /* Make room for the SMEM, if it exists */
1025 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
1027 /* Make room for the secondary SRAM, if it exists */
1029 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
1031 dump_file = vzalloc(file_len);
1033 kfree(fw_error_dump);
1034 iwl_mvm_free_fw_dump_desc(mvm);
1038 fw_error_dump->op_mode_ptr = dump_file;
1040 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
1041 dump_data = (void *)dump_file->data;
1043 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
1044 dump_data->len = cpu_to_le32(sizeof(*dump_info));
1045 dump_info = (void *) dump_data->data;
1046 dump_info->device_family =
1047 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
1048 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
1049 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
1050 dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
1051 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
1052 sizeof(dump_info->fw_human_readable));
1053 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
1054 sizeof(dump_info->dev_human_readable));
1055 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
1056 sizeof(dump_info->bus_human_readable));
1058 dump_data = iwl_fw_error_next_data(dump_data);
1059 /* We only dump the FIFOs if the FW is in error state */
1060 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status))
1061 iwl_mvm_dump_fifos(mvm, &dump_data);
1063 if (mvm->fw_dump_desc) {
1064 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_ERROR_INFO);
1065 dump_data->len = cpu_to_le32(sizeof(*dump_trig) +
1066 mvm->fw_dump_desc->len);
1067 dump_trig = (void *)dump_data->data;
1068 memcpy(dump_trig, &mvm->fw_dump_desc->trig_desc,
1069 sizeof(*dump_trig) + mvm->fw_dump_desc->len);
1071 /* now we can free this copy */
1072 iwl_mvm_free_fw_dump_desc(mvm);
1073 dump_data = iwl_fw_error_next_data(dump_data);
1076 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1077 dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
1078 dump_mem = (void *)dump_data->data;
1079 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1080 dump_mem->offset = cpu_to_le32(sram_ofs);
1081 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
1085 dump_data = iwl_fw_error_next_data(dump_data);
1086 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1087 dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
1088 dump_mem = (void *)dump_data->data;
1089 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
1090 dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
1091 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
1092 dump_mem->data, smem_len);
1096 dump_data = iwl_fw_error_next_data(dump_data);
1097 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1098 dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
1099 dump_mem = (void *)dump_data->data;
1100 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1101 dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
1102 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
1103 dump_mem->data, sram2_len);
1106 fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans);
1107 fw_error_dump->op_mode_len = file_len;
1108 if (fw_error_dump->trans_ptr)
1109 file_len += fw_error_dump->trans_ptr->len;
1110 dump_file->file_len = cpu_to_le32(file_len);
1112 dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
1113 GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
1115 clear_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status);
1118 struct iwl_mvm_dump_desc iwl_mvm_dump_desc_assert = {
1120 .type = cpu_to_le32(FW_DBG_TRIGGER_FW_ASSERT),
1124 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1126 /* clear the D3 reconfig, we only need it to avoid dumping a
1127 * firmware coredump on reconfiguration, we shouldn't do that
1128 * on D3->D0 transition
1130 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status)) {
1131 mvm->fw_dump_desc = &iwl_mvm_dump_desc_assert;
1132 iwl_mvm_fw_error_dump(mvm);
1135 /* cleanup all stale references (scan, roc), but keep the
1136 * ucode_down ref until reconfig is complete
1138 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1140 iwl_trans_stop_device(mvm->trans);
1142 mvm->scan_status = IWL_MVM_SCAN_NONE;
1143 mvm->ps_disabled = false;
1144 mvm->calibrating = false;
1146 /* just in case one was running */
1147 ieee80211_remain_on_channel_expired(mvm->hw);
1149 ieee80211_iterate_active_interfaces_atomic(
1150 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1151 iwl_mvm_cleanup_iterator, mvm);
1153 mvm->p2p_device_vif = NULL;
1154 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1156 iwl_mvm_reset_phy_ctxts(mvm);
1157 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1158 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
1159 memset(mvm->tfd_drained, 0, sizeof(mvm->tfd_drained));
1160 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1161 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
1162 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1163 memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
1164 memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk));
1165 memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk));
1167 ieee80211_wake_queues(mvm->hw);
1169 /* clear any stale d0i3 state */
1170 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1173 mvm->rx_ba_sessions = 0;
1174 mvm->fw_dbg_conf = FW_DBG_INVALID;
1176 /* keep statistics ticking */
1177 iwl_mvm_accu_radio_stats(mvm);
1180 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1184 lockdep_assert_held(&mvm->mutex);
1186 /* Clean up some internal and mac80211 state on restart */
1187 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1188 iwl_mvm_restart_cleanup(mvm);
1190 ret = iwl_mvm_up(mvm);
1192 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1193 /* Something went wrong - we need to finish some cleanup
1194 * that normally iwl_mvm_mac_restart_complete() below
1197 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1198 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1204 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1206 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1209 /* Some hw restart cleanups must not hold the mutex */
1210 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1212 * Make sure we are out of d0i3. This is needed
1213 * to make sure the reference accounting is correct
1214 * (and there is no stale d0i3_exit_work).
1216 wait_event_timeout(mvm->d0i3_exit_waitq,
1217 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1222 mutex_lock(&mvm->mutex);
1223 ret = __iwl_mvm_mac_start(mvm);
1224 mutex_unlock(&mvm->mutex);
1229 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1233 mutex_lock(&mvm->mutex);
1235 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1236 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1237 ret = iwl_mvm_update_quotas(mvm, NULL);
1239 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1242 /* allow transport/FW low power modes */
1243 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1246 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1247 * of packets the FW sent out, so we must reconnect.
1249 iwl_mvm_teardown_tdls_peers(mvm);
1251 mutex_unlock(&mvm->mutex);
1254 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1258 if (!iwl_mvm_is_d0i3_supported(mvm))
1261 mutex_lock(&mvm->d0i3_suspend_mutex);
1262 __clear_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags);
1263 exit_now = __test_and_clear_bit(D0I3_PENDING_WAKEUP,
1264 &mvm->d0i3_suspend_flags);
1265 mutex_unlock(&mvm->d0i3_suspend_mutex);
1268 IWL_DEBUG_RPM(mvm, "Run deferred d0i3 exit\n");
1269 _iwl_mvm_exit_d0i3(mvm);
1272 if (mvm->trans->d0i3_mode == IWL_D0I3_MODE_ON_SUSPEND)
1273 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
1274 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1277 WARN_ONCE(1, "D0i3 exit on resume timed out\n");
1281 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1282 enum ieee80211_reconfig_type reconfig_type)
1284 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1286 switch (reconfig_type) {
1287 case IEEE80211_RECONFIG_TYPE_RESTART:
1288 iwl_mvm_restart_complete(mvm);
1290 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1291 iwl_mvm_resume_complete(mvm);
1296 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1298 lockdep_assert_held(&mvm->mutex);
1300 /* firmware counters are obviously reset now, but we shouldn't
1301 * partially track so also clear the fw_reset_accu counters.
1303 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1306 * Disallow low power states when the FW is down by taking
1307 * the UCODE_DOWN ref. in case of ongoing hw restart the
1308 * ref is already taken, so don't take it again.
1310 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1311 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1313 /* async_handlers_wk is now blocked */
1316 * The work item could be running or queued if the
1317 * ROC time event stops just as we get here.
1319 cancel_work_sync(&mvm->roc_done_wk);
1321 iwl_trans_stop_device(mvm->trans);
1323 iwl_mvm_async_handlers_purge(mvm);
1324 /* async_handlers_list is empty and will stay empty: HW is stopped */
1326 /* the fw is stopped, the aux sta is dead: clean up driver state */
1327 iwl_mvm_del_aux_sta(mvm);
1330 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1331 * won't be called in this case).
1333 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1335 mvm->ucode_loaded = false;
1338 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1340 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1342 flush_work(&mvm->d0i3_exit_work);
1343 flush_work(&mvm->async_handlers_wk);
1344 cancel_delayed_work_sync(&mvm->fw_dump_wk);
1345 iwl_mvm_free_fw_dump_desc(mvm);
1347 mutex_lock(&mvm->mutex);
1348 __iwl_mvm_mac_stop(mvm);
1349 mutex_unlock(&mvm->mutex);
1352 * The worker might have been waiting for the mutex, let it run and
1353 * discover that its list is now empty.
1355 cancel_work_sync(&mvm->async_handlers_wk);
1358 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1362 lockdep_assert_held(&mvm->mutex);
1364 for (i = 0; i < NUM_PHY_CTX; i++)
1365 if (!mvm->phy_ctxts[i].ref)
1366 return &mvm->phy_ctxts[i];
1368 IWL_ERR(mvm, "No available PHY context\n");
1372 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1375 /* FW is in charge of regulatory enforcement */
1376 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
1377 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
1378 .pwr_restriction = cpu_to_le16(tx_power),
1381 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
1382 sizeof(reduce_txpwr_cmd),
1386 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1387 struct ieee80211_vif *vif)
1389 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1390 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1396 * make sure D0i3 exit is completed, otherwise a target access
1397 * during tx queue configuration could be done when still in
1400 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1405 * Not much to do here. The stack will not allow interface
1406 * types or combinations that we didn't advertise, so we
1407 * don't really have to check the types.
1410 mutex_lock(&mvm->mutex);
1412 /* make sure that beacon statistics don't go backwards with FW reset */
1413 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1414 mvmvif->beacon_stats.accu_num_beacons +=
1415 mvmvif->beacon_stats.num_beacons;
1417 /* Allocate resources for the MAC context, and add it to the fw */
1418 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1422 /* Counting number of interfaces is needed for legacy PM */
1423 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1427 * The AP binding flow can be done only after the beacon
1428 * template is configured (which happens only in the mac80211
1429 * start_ap() flow), and adding the broadcast station can happen
1430 * only after the binding.
1431 * In addition, since modifying the MAC before adding a bcast
1432 * station is not allowed by the FW, delay the adding of MAC context to
1433 * the point where we can also add the bcast station.
1434 * In short: there's not much we can do at this point, other than
1435 * allocating resources :)
1437 if (vif->type == NL80211_IFTYPE_AP ||
1438 vif->type == NL80211_IFTYPE_ADHOC) {
1439 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1441 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1445 iwl_mvm_vif_dbgfs_register(mvm, vif);
1449 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1453 ret = iwl_mvm_power_update_mac(mvm);
1455 goto out_remove_mac;
1457 /* beacon filtering */
1458 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1460 goto out_remove_mac;
1462 if (!mvm->bf_allowed_vif &&
1463 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1464 mvm->bf_allowed_vif = mvmvif;
1465 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1466 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1470 * P2P_DEVICE interface does not have a channel context assigned to it,
1471 * so a dedicated PHY context is allocated to it and the corresponding
1472 * MAC context is bound to it at this stage.
1474 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1476 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1477 if (!mvmvif->phy_ctxt) {
1482 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1483 ret = iwl_mvm_binding_add_vif(mvm, vif);
1487 ret = iwl_mvm_add_bcast_sta(mvm, vif);
1491 /* Save a pointer to p2p device vif, so it can later be used to
1492 * update the p2p device MAC when a GO is started/stopped */
1493 mvm->p2p_device_vif = vif;
1496 iwl_mvm_vif_dbgfs_register(mvm, vif);
1500 iwl_mvm_binding_remove_vif(mvm, vif);
1502 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1504 if (mvm->bf_allowed_vif == mvmvif) {
1505 mvm->bf_allowed_vif = NULL;
1506 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1507 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1510 mvmvif->phy_ctxt = NULL;
1511 iwl_mvm_mac_ctxt_remove(mvm, vif);
1513 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1516 iwl_mvm_mac_ctxt_release(mvm, vif);
1518 mutex_unlock(&mvm->mutex);
1520 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1525 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1526 struct ieee80211_vif *vif)
1528 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif);
1531 mutex_lock(&mvm->mutex);
1532 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
1533 mutex_unlock(&mvm->mutex);
1536 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1538 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1539 * We assume here that all the packets sent to the OFFCHANNEL
1540 * queue are sent in ROC session.
1542 flush_work(&mvm->roc_done_wk);
1545 * By now, all the AC queues are empty. The AGG queues are
1546 * empty too. We already got all the Tx responses for all the
1547 * packets in the queues. The drain work can have been
1548 * triggered. Flush it.
1550 flush_work(&mvm->sta_drained_wk);
1554 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1555 struct ieee80211_vif *vif)
1557 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1558 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1560 iwl_mvm_prepare_mac_removal(mvm, vif);
1562 mutex_lock(&mvm->mutex);
1564 if (mvm->bf_allowed_vif == mvmvif) {
1565 mvm->bf_allowed_vif = NULL;
1566 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1567 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1570 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1573 * For AP/GO interface, the tear down of the resources allocated to the
1574 * interface is be handled as part of the stop_ap flow.
1576 if (vif->type == NL80211_IFTYPE_AP ||
1577 vif->type == NL80211_IFTYPE_ADHOC) {
1578 #ifdef CONFIG_NL80211_TESTMODE
1579 if (vif == mvm->noa_vif) {
1580 mvm->noa_vif = NULL;
1581 mvm->noa_duration = 0;
1584 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1588 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1589 mvm->p2p_device_vif = NULL;
1590 iwl_mvm_rm_bcast_sta(mvm, vif);
1591 iwl_mvm_binding_remove_vif(mvm, vif);
1592 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1593 mvmvif->phy_ctxt = NULL;
1596 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1599 iwl_mvm_power_update_mac(mvm);
1600 iwl_mvm_mac_ctxt_remove(mvm, vif);
1603 iwl_mvm_mac_ctxt_release(mvm, vif);
1604 mutex_unlock(&mvm->mutex);
1607 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1612 struct iwl_mvm_mc_iter_data {
1613 struct iwl_mvm *mvm;
1617 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1618 struct ieee80211_vif *vif)
1620 struct iwl_mvm_mc_iter_data *data = _data;
1621 struct iwl_mvm *mvm = data->mvm;
1622 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1625 /* if we don't have free ports, mcast frames will be dropped */
1626 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1629 if (vif->type != NL80211_IFTYPE_STATION ||
1630 !vif->bss_conf.assoc)
1633 cmd->port_id = data->port_id++;
1634 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1635 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1637 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
1639 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1642 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1644 struct iwl_mvm_mc_iter_data iter_data = {
1648 lockdep_assert_held(&mvm->mutex);
1650 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1653 ieee80211_iterate_active_interfaces_atomic(
1654 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1655 iwl_mvm_mc_iface_iterator, &iter_data);
1658 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1659 struct netdev_hw_addr_list *mc_list)
1661 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1662 struct iwl_mcast_filter_cmd *cmd;
1663 struct netdev_hw_addr *addr;
1668 addr_count = netdev_hw_addr_list_count(mc_list);
1669 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1670 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1674 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1675 cmd = kzalloc(len, GFP_ATOMIC);
1681 return (u64)(unsigned long)cmd;
1684 netdev_hw_addr_list_for_each(addr, mc_list) {
1685 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1686 cmd->count, addr->addr);
1687 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1688 addr->addr, ETH_ALEN);
1692 return (u64)(unsigned long)cmd;
1695 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1696 unsigned int changed_flags,
1697 unsigned int *total_flags,
1700 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1701 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1703 mutex_lock(&mvm->mutex);
1705 /* replace previous configuration */
1706 kfree(mvm->mcast_filter_cmd);
1707 mvm->mcast_filter_cmd = cmd;
1712 iwl_mvm_recalc_multicast(mvm);
1714 mutex_unlock(&mvm->mutex);
1718 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1719 struct iwl_bcast_iter_data {
1720 struct iwl_mvm *mvm;
1721 struct iwl_bcast_filter_cmd *cmd;
1726 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1727 const struct iwl_fw_bcast_filter *in_filter,
1728 struct iwl_fw_bcast_filter *out_filter)
1730 struct iwl_fw_bcast_filter_attr *attr;
1733 memcpy(out_filter, in_filter, sizeof(*out_filter));
1735 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1736 attr = &out_filter->attrs[i];
1741 switch (attr->reserved1) {
1742 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1743 if (vif->bss_conf.arp_addr_cnt != 1) {
1748 attr->val = vif->bss_conf.arp_addr_list[0];
1750 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1751 attr->val = *(__be32 *)&vif->addr[2];
1756 attr->reserved1 = 0;
1757 out_filter->num_attrs++;
1761 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1762 struct ieee80211_vif *vif)
1764 struct iwl_bcast_iter_data *data = _data;
1765 struct iwl_mvm *mvm = data->mvm;
1766 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1767 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1768 struct iwl_fw_bcast_mac *bcast_mac;
1771 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1774 bcast_mac = &cmd->macs[mvmvif->id];
1777 * enable filtering only for associated stations, but not for P2P
1780 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1781 !vif->bss_conf.assoc)
1784 bcast_mac->default_discard = 1;
1786 /* copy all configured filters */
1787 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1789 * Make sure we don't exceed our filters limit.
1790 * if there is still a valid filter to be configured,
1791 * be on the safe side and just allow bcast for this mac.
1793 if (WARN_ON_ONCE(data->current_filter >=
1794 ARRAY_SIZE(cmd->filters))) {
1795 bcast_mac->default_discard = 0;
1796 bcast_mac->attached_filters = 0;
1800 iwl_mvm_set_bcast_filter(vif,
1801 &mvm->bcast_filters[i],
1802 &cmd->filters[data->current_filter]);
1804 /* skip current filter if it contains no attributes */
1805 if (!cmd->filters[data->current_filter].num_attrs)
1808 /* attach the filter to current mac */
1809 bcast_mac->attached_filters |=
1810 cpu_to_le16(BIT(data->current_filter));
1812 data->current_filter++;
1816 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1817 struct iwl_bcast_filter_cmd *cmd)
1819 struct iwl_bcast_iter_data iter_data = {
1824 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1827 memset(cmd, 0, sizeof(*cmd));
1828 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1829 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1831 #ifdef CONFIG_IWLWIFI_DEBUGFS
1832 /* use debugfs filters/macs if override is configured */
1833 if (mvm->dbgfs_bcast_filtering.override) {
1834 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1835 sizeof(cmd->filters));
1836 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1842 /* if no filters are configured, do nothing */
1843 if (!mvm->bcast_filters)
1846 /* configure and attach these filters for each associated sta vif */
1847 ieee80211_iterate_active_interfaces(
1848 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1849 iwl_mvm_bcast_filter_iterator, &iter_data);
1853 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1854 struct ieee80211_vif *vif)
1856 struct iwl_bcast_filter_cmd cmd;
1858 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1861 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1864 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1868 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1869 struct ieee80211_vif *vif)
1875 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1876 struct ieee80211_vif *vif,
1877 struct ieee80211_bss_conf *bss_conf,
1880 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1884 * Re-calculate the tsf id, as the master-slave relations depend on the
1885 * beacon interval, which was not known when the station interface was
1888 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1889 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1892 * If we're not associated yet, take the (new) BSSID before associating
1893 * so the firmware knows. If we're already associated, then use the old
1894 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1895 * branch for disassociation below.
1897 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1898 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1900 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
1902 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1904 /* after sending it once, adopt mac80211 data */
1905 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1906 mvmvif->associated = bss_conf->assoc;
1908 if (changes & BSS_CHANGED_ASSOC) {
1909 if (bss_conf->assoc) {
1910 /* clear statistics to get clean beacon counter */
1911 iwl_mvm_request_statistics(mvm, true);
1912 memset(&mvmvif->beacon_stats, 0,
1913 sizeof(mvmvif->beacon_stats));
1915 /* add quota for this interface */
1916 ret = iwl_mvm_update_quotas(mvm, NULL);
1918 IWL_ERR(mvm, "failed to update quotas\n");
1922 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1925 * If we're restarting then the firmware will
1926 * obviously have lost synchronisation with
1927 * the AP. It will attempt to synchronise by
1928 * itself, but we can make it more reliable by
1929 * scheduling a session protection time event.
1931 * The firmware needs to receive a beacon to
1932 * catch up with synchronisation, use 110% of
1933 * the beacon interval.
1935 * Set a large maximum delay to allow for more
1936 * than a single interface.
1938 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1939 iwl_mvm_protect_session(mvm, vif, dur, dur,
1943 iwl_mvm_sf_update(mvm, vif, false);
1944 iwl_mvm_power_vif_assoc(mvm, vif);
1946 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
1947 iwl_mvm_update_smps(mvm, vif,
1948 IWL_MVM_SMPS_REQ_PROT,
1949 IEEE80211_SMPS_DYNAMIC);
1951 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1953 * If update fails - SF might be running in associated
1954 * mode while disassociated - which is forbidden.
1956 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1957 "Failed to update SF upon disassociation\n");
1959 /* remove AP station now that the MAC is unassoc */
1960 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1962 IWL_ERR(mvm, "failed to remove AP station\n");
1964 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1965 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1966 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1967 /* remove quota for this interface */
1968 ret = iwl_mvm_update_quotas(mvm, NULL);
1970 IWL_ERR(mvm, "failed to update quotas\n");
1973 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
1975 /* this will take the cleared BSSID from bss_conf */
1976 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1979 "failed to update MAC %pM (clear after unassoc)\n",
1983 iwl_mvm_recalc_multicast(mvm);
1984 iwl_mvm_configure_bcast_filter(mvm, vif);
1986 /* reset rssi values */
1987 mvmvif->bf_data.ave_beacon_signal = 0;
1989 iwl_mvm_bt_coex_vif_change(mvm);
1990 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1991 IEEE80211_SMPS_AUTOMATIC);
1992 } else if (changes & BSS_CHANGED_BEACON_INFO) {
1994 * We received a beacon _after_ association so
1995 * remove the session protection.
1997 iwl_mvm_remove_time_event(mvm, mvmvif,
1998 &mvmvif->time_event_data);
2001 if (changes & BSS_CHANGED_BEACON_INFO) {
2002 iwl_mvm_sf_update(mvm, vif, false);
2003 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2006 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS)) {
2007 ret = iwl_mvm_power_update_mac(mvm);
2009 IWL_ERR(mvm, "failed to update power mode\n");
2012 if (changes & BSS_CHANGED_TXPOWER) {
2013 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2015 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2018 if (changes & BSS_CHANGED_CQM) {
2019 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2020 /* reset cqm events tracking */
2021 mvmvif->bf_data.last_cqm_event = 0;
2022 if (mvmvif->bf_data.bf_enabled) {
2023 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2026 "failed to update CQM thresholds\n");
2030 if (changes & BSS_CHANGED_ARP_FILTER) {
2031 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2032 iwl_mvm_configure_bcast_filter(mvm, vif);
2036 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2037 struct ieee80211_vif *vif)
2039 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2040 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2044 * iwl_mvm_mac_ctxt_add() might read directly from the device
2045 * (the system time), so make sure it is available.
2047 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
2051 mutex_lock(&mvm->mutex);
2053 /* Send the beacon template */
2054 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2059 * Re-calculate the tsf id, as the master-slave relations depend on the
2060 * beacon interval, which was not known when the AP interface was added.
2062 if (vif->type == NL80211_IFTYPE_AP)
2063 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2065 /* Add the mac context */
2066 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2070 /* Perform the binding */
2071 ret = iwl_mvm_binding_add_vif(mvm, vif);
2075 /* Send the bcast station. At this stage the TBTT and DTIM time events
2076 * are added and applied to the scheduler */
2077 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2081 /* must be set before quota calculations */
2082 mvmvif->ap_ibss_active = true;
2084 /* power updated needs to be done before quotas */
2085 iwl_mvm_power_update_mac(mvm);
2087 ret = iwl_mvm_update_quotas(mvm, NULL);
2089 goto out_quota_failed;
2091 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2092 if (vif->p2p && mvm->p2p_device_vif)
2093 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2095 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
2097 iwl_mvm_bt_coex_vif_change(mvm);
2099 /* we don't support TDLS during DCM */
2100 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2101 iwl_mvm_teardown_tdls_peers(mvm);
2103 mutex_unlock(&mvm->mutex);
2107 iwl_mvm_power_update_mac(mvm);
2108 mvmvif->ap_ibss_active = false;
2109 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2111 iwl_mvm_binding_remove_vif(mvm, vif);
2113 iwl_mvm_mac_ctxt_remove(mvm, vif);
2115 mutex_unlock(&mvm->mutex);
2116 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2120 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2121 struct ieee80211_vif *vif)
2123 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2124 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2126 iwl_mvm_prepare_mac_removal(mvm, vif);
2128 mutex_lock(&mvm->mutex);
2130 /* Handle AP stop while in CSA */
2131 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2132 iwl_mvm_remove_time_event(mvm, mvmvif,
2133 &mvmvif->time_event_data);
2134 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2137 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2138 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2139 mvm->csa_tx_block_bcn_timeout = 0;
2142 mvmvif->ap_ibss_active = false;
2143 mvm->ap_last_beacon_gp2 = 0;
2145 iwl_mvm_bt_coex_vif_change(mvm);
2147 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2149 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2150 if (vif->p2p && mvm->p2p_device_vif)
2151 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2153 iwl_mvm_update_quotas(mvm, NULL);
2154 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2155 iwl_mvm_binding_remove_vif(mvm, vif);
2157 iwl_mvm_power_update_mac(mvm);
2159 iwl_mvm_mac_ctxt_remove(mvm, vif);
2161 mutex_unlock(&mvm->mutex);
2165 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2166 struct ieee80211_vif *vif,
2167 struct ieee80211_bss_conf *bss_conf,
2170 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2172 /* Changes will be applied when the AP/IBSS is started */
2173 if (!mvmvif->ap_ibss_active)
2176 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2177 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2178 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2179 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2181 /* Need to send a new beacon template to the FW */
2182 if (changes & BSS_CHANGED_BEACON &&
2183 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2184 IWL_WARN(mvm, "Failed updating beacon data\n");
2186 if (changes & BSS_CHANGED_TXPOWER) {
2187 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2189 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2194 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2195 struct ieee80211_vif *vif,
2196 struct ieee80211_bss_conf *bss_conf,
2199 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2202 * iwl_mvm_bss_info_changed_station() might call
2203 * iwl_mvm_protect_session(), which reads directly from
2204 * the device (the system time), so make sure it is available.
2206 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2209 mutex_lock(&mvm->mutex);
2211 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2212 iwl_mvm_scan_offload_stop(mvm, true);
2214 switch (vif->type) {
2215 case NL80211_IFTYPE_STATION:
2216 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2218 case NL80211_IFTYPE_AP:
2219 case NL80211_IFTYPE_ADHOC:
2220 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2223 /* shouldn't happen */
2227 mutex_unlock(&mvm->mutex);
2228 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2231 static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm,
2232 enum iwl_scan_status scan_type)
2235 bool wait_for_handlers = false;
2237 mutex_lock(&mvm->mutex);
2239 if (mvm->scan_status != scan_type) {
2241 /* make sure there are no pending notifications */
2242 wait_for_handlers = true;
2246 switch (scan_type) {
2247 case IWL_MVM_SCAN_SCHED:
2248 ret = iwl_mvm_scan_offload_stop(mvm, true);
2250 case IWL_MVM_SCAN_OS:
2251 ret = iwl_mvm_cancel_scan(mvm);
2253 case IWL_MVM_SCAN_NONE:
2262 wait_for_handlers = true;
2264 mutex_unlock(&mvm->mutex);
2266 /* make sure we consume the completion notification */
2267 if (wait_for_handlers)
2268 iwl_mvm_wait_for_async_handlers(mvm);
2272 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2273 struct ieee80211_vif *vif,
2274 struct ieee80211_scan_request *hw_req)
2276 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2277 struct cfg80211_scan_request *req = &hw_req->req;
2280 if (req->n_channels == 0 ||
2281 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
2284 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2285 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_SCHED);
2290 mutex_lock(&mvm->mutex);
2292 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
2293 IWL_ERR(mvm, "scan while LAR regdomain is not set\n");
2298 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
2303 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
2305 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
2306 ret = iwl_mvm_scan_umac(mvm, vif, hw_req);
2308 ret = iwl_mvm_unified_scan_lmac(mvm, vif, hw_req);
2311 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
2313 mutex_unlock(&mvm->mutex);
2317 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2318 struct ieee80211_vif *vif)
2320 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2322 mutex_lock(&mvm->mutex);
2324 iwl_mvm_cancel_scan(mvm);
2326 mutex_unlock(&mvm->mutex);
2330 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2331 struct ieee80211_sta *sta, u16 tids,
2333 enum ieee80211_frame_release_type reason,
2336 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2338 /* Called when we need to transmit (a) frame(s) from mac80211 */
2340 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2341 tids, more_data, false);
2345 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2346 struct ieee80211_sta *sta, u16 tids,
2348 enum ieee80211_frame_release_type reason,
2351 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2353 /* Called when we need to transmit (a) frame(s) from agg queue */
2355 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2356 tids, more_data, true);
2359 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2360 struct ieee80211_vif *vif,
2361 enum sta_notify_cmd cmd,
2362 struct ieee80211_sta *sta)
2364 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2365 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2369 case STA_NOTIFY_SLEEP:
2370 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
2371 ieee80211_sta_block_awake(hw, sta, true);
2372 spin_lock_bh(&mvmsta->lock);
2373 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2374 struct iwl_mvm_tid_data *tid_data;
2376 tid_data = &mvmsta->tid_data[tid];
2377 if (tid_data->state != IWL_AGG_ON &&
2378 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
2380 if (iwl_mvm_tid_queued(tid_data) == 0)
2382 ieee80211_sta_set_buffered(sta, tid, true);
2384 spin_unlock_bh(&mvmsta->lock);
2386 * The fw updates the STA to be asleep. Tx packets on the Tx
2387 * queues to this station will not be transmitted. The fw will
2388 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2391 case STA_NOTIFY_AWAKE:
2392 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
2394 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2401 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2402 struct ieee80211_vif *vif,
2403 struct ieee80211_sta *sta)
2405 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2406 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2409 * This is called before mac80211 does RCU synchronisation,
2410 * so here we already invalidate our internal RCU-protected
2411 * station pointer. The rest of the code will thus no longer
2412 * be able to find the station this way, and we don't rely
2413 * on further RCU synchronisation after the sta_state()
2414 * callback deleted the station.
2416 mutex_lock(&mvm->mutex);
2417 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2418 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2420 mutex_unlock(&mvm->mutex);
2423 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2426 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2429 if (iwlwifi_mod_params.uapsd_disable) {
2430 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2434 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2437 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2438 struct ieee80211_vif *vif,
2439 struct ieee80211_sta *sta,
2440 enum ieee80211_sta_state old_state,
2441 enum ieee80211_sta_state new_state)
2443 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2444 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2447 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2448 sta->addr, old_state, new_state);
2450 /* this would be a mac80211 bug ... but don't crash */
2451 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2454 /* if a STA is being removed, reuse its ID */
2455 flush_work(&mvm->sta_drained_wk);
2457 mutex_lock(&mvm->mutex);
2458 if (old_state == IEEE80211_STA_NOTEXIST &&
2459 new_state == IEEE80211_STA_NONE) {
2461 * Firmware bug - it'll crash if the beacon interval is less
2462 * than 16. We can't avoid connecting at all, so refuse the
2463 * station state change, this will cause mac80211 to abandon
2464 * attempts to connect to this AP, and eventually wpa_s will
2465 * blacklist the AP...
2467 if (vif->type == NL80211_IFTYPE_STATION &&
2468 vif->bss_conf.beacon_int < 16) {
2470 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2471 sta->addr, vif->bss_conf.beacon_int);
2478 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2479 IWL_MVM_TDLS_STA_COUNT ||
2480 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2481 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2486 ret = iwl_mvm_add_sta(mvm, vif, sta);
2487 if (sta->tdls && ret == 0)
2488 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2489 } else if (old_state == IEEE80211_STA_NONE &&
2490 new_state == IEEE80211_STA_AUTH) {
2492 * EBS may be disabled due to previous failures reported by FW.
2493 * Reset EBS status here assuming environment has been changed.
2495 mvm->last_ebs_successful = true;
2496 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2498 } else if (old_state == IEEE80211_STA_AUTH &&
2499 new_state == IEEE80211_STA_ASSOC) {
2500 ret = iwl_mvm_update_sta(mvm, vif, sta);
2502 iwl_mvm_rs_rate_init(mvm, sta,
2503 mvmvif->phy_ctxt->channel->band,
2505 } else if (old_state == IEEE80211_STA_ASSOC &&
2506 new_state == IEEE80211_STA_AUTHORIZED) {
2508 /* we don't support TDLS during DCM */
2509 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2510 iwl_mvm_teardown_tdls_peers(mvm);
2512 /* enable beacon filtering */
2513 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2515 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2516 new_state == IEEE80211_STA_ASSOC) {
2517 /* disable beacon filtering */
2518 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2520 } else if (old_state == IEEE80211_STA_ASSOC &&
2521 new_state == IEEE80211_STA_AUTH) {
2523 } else if (old_state == IEEE80211_STA_AUTH &&
2524 new_state == IEEE80211_STA_NONE) {
2526 } else if (old_state == IEEE80211_STA_NONE &&
2527 new_state == IEEE80211_STA_NOTEXIST) {
2528 ret = iwl_mvm_rm_sta(mvm, vif, sta);
2530 iwl_mvm_recalc_tdls_state(mvm, vif, false);
2535 mutex_unlock(&mvm->mutex);
2537 if (sta->tdls && ret == 0) {
2538 if (old_state == IEEE80211_STA_NOTEXIST &&
2539 new_state == IEEE80211_STA_NONE)
2540 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2541 else if (old_state == IEEE80211_STA_NONE &&
2542 new_state == IEEE80211_STA_NOTEXIST)
2543 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2549 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2551 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2553 mvm->rts_threshold = value;
2558 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2559 struct ieee80211_vif *vif,
2560 struct ieee80211_sta *sta, u32 changed)
2562 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2564 if (vif->type == NL80211_IFTYPE_STATION &&
2565 changed & IEEE80211_RC_NSS_CHANGED)
2566 iwl_mvm_sf_update(mvm, vif, false);
2569 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2570 struct ieee80211_vif *vif, u16 ac,
2571 const struct ieee80211_tx_queue_params *params)
2573 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2574 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2576 mvmvif->queue_params[ac] = *params;
2579 * No need to update right away, we'll get BSS_CHANGED_QOS
2580 * The exception is P2P_DEVICE interface which needs immediate update.
2582 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2585 mutex_lock(&mvm->mutex);
2586 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2587 mutex_unlock(&mvm->mutex);
2593 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2594 struct ieee80211_vif *vif)
2596 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2597 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
2598 200 + vif->bss_conf.beacon_int);
2599 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
2600 100 + vif->bss_conf.beacon_int);
2602 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2606 * iwl_mvm_protect_session() reads directly from the device
2607 * (the system time), so make sure it is available.
2609 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2612 mutex_lock(&mvm->mutex);
2613 /* Try really hard to protect the session and hear a beacon */
2614 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
2615 mutex_unlock(&mvm->mutex);
2617 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
2620 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2621 struct ieee80211_vif *vif,
2622 struct cfg80211_sched_scan_request *req,
2623 struct ieee80211_scan_ies *ies)
2625 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2628 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2629 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS);
2634 mutex_lock(&mvm->mutex);
2636 if (iwl_mvm_is_lar_supported(mvm) && !mvm->lar_regdom_set) {
2637 IWL_ERR(mvm, "sched-scan while LAR regdomain is not set\n");
2642 if (!vif->bss_conf.idle) {
2647 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
2652 ret = iwl_mvm_scan_offload_start(mvm, vif, req, ies);
2654 mvm->scan_status = IWL_MVM_SCAN_NONE;
2657 mutex_unlock(&mvm->mutex);
2661 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2662 struct ieee80211_vif *vif)
2664 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2667 mutex_lock(&mvm->mutex);
2668 ret = iwl_mvm_scan_offload_stop(mvm, false);
2669 mutex_unlock(&mvm->mutex);
2670 iwl_mvm_wait_for_async_handlers(mvm);
2676 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2677 enum set_key_cmd cmd,
2678 struct ieee80211_vif *vif,
2679 struct ieee80211_sta *sta,
2680 struct ieee80211_key_conf *key)
2682 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2685 if (iwlwifi_mod_params.sw_crypto) {
2686 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2690 switch (key->cipher) {
2691 case WLAN_CIPHER_SUITE_TKIP:
2692 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2694 case WLAN_CIPHER_SUITE_CCMP:
2695 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2697 case WLAN_CIPHER_SUITE_AES_CMAC:
2698 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
2700 case WLAN_CIPHER_SUITE_WEP40:
2701 case WLAN_CIPHER_SUITE_WEP104:
2702 /* For non-client mode, only use WEP keys for TX as we probably
2703 * don't have a station yet anyway and would then have to keep
2704 * track of the keys, linking them to each of the clients/peers
2705 * as they appear. For now, don't do that, for performance WEP
2706 * offload doesn't really matter much, but we need it for some
2707 * other offload features in client mode.
2709 if (vif->type != NL80211_IFTYPE_STATION)
2713 /* currently FW supports only one optional cipher scheme */
2714 if (hw->n_cipher_schemes &&
2715 hw->cipher_schemes->cipher == key->cipher)
2716 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2721 mutex_lock(&mvm->mutex);
2725 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2726 vif->type == NL80211_IFTYPE_AP) && !sta) {
2728 * GTK on AP interface is a TX-only key, return 0;
2729 * on IBSS they're per-station and because we're lazy
2730 * we don't support them for RX, so do the same.
2733 key->hw_key_idx = STA_KEY_IDX_INVALID;
2737 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2738 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
2740 IWL_WARN(mvm, "set key failed\n");
2742 * can't add key for RX, but we don't need it
2743 * in the device for TX so still return 0
2745 key->hw_key_idx = STA_KEY_IDX_INVALID;
2751 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2756 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2757 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2763 mutex_unlock(&mvm->mutex);
2767 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2768 struct ieee80211_vif *vif,
2769 struct ieee80211_key_conf *keyconf,
2770 struct ieee80211_sta *sta,
2771 u32 iv32, u16 *phase1key)
2773 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2775 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2778 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2782 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
2783 struct iwl_rx_packet *pkt, void *data)
2785 struct iwl_mvm *mvm =
2786 container_of(notif_wait, struct iwl_mvm, notif_wait);
2787 struct iwl_hs20_roc_res *resp;
2788 int resp_len = iwl_rx_packet_payload_len(pkt);
2789 struct iwl_mvm_time_event_data *te_data = data;
2791 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
2794 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
2795 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
2799 resp = (void *)pkt->data;
2802 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
2803 resp->status, resp->event_unique_id);
2805 te_data->uid = le32_to_cpu(resp->event_unique_id);
2806 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
2809 spin_lock_bh(&mvm->time_event_lock);
2810 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
2811 spin_unlock_bh(&mvm->time_event_lock);
2816 #define AUX_ROC_MAX_DELAY_ON_CHANNEL 5000
2817 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
2818 struct ieee80211_channel *channel,
2819 struct ieee80211_vif *vif,
2822 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
2823 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2824 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
2825 static const u8 time_event_response[] = { HOT_SPOT_CMD };
2826 struct iwl_notification_wait wait_time_event;
2827 struct iwl_hs20_roc_req aux_roc_req = {
2828 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
2830 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
2831 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
2832 /* Set the channel info data */
2833 .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
2834 PHY_BAND_24 : PHY_BAND_5,
2835 .channel_info.channel = channel->hw_value,
2836 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
2837 /* Set the time and duration */
2838 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
2839 .apply_time_max_delay =
2840 cpu_to_le32(MSEC_TO_TU(AUX_ROC_MAX_DELAY_ON_CHANNEL)),
2841 .duration = cpu_to_le32(MSEC_TO_TU(duration)),
2844 /* Set the node address */
2845 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
2847 lockdep_assert_held(&mvm->mutex);
2849 spin_lock_bh(&mvm->time_event_lock);
2851 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
2852 spin_unlock_bh(&mvm->time_event_lock);
2857 te_data->duration = duration;
2858 te_data->id = HOT_SPOT_CMD;
2860 spin_unlock_bh(&mvm->time_event_lock);
2863 * Use a notification wait, which really just processes the
2864 * command response and doesn't wait for anything, in order
2865 * to be able to process the response and get the UID inside
2866 * the RX path. Using CMD_WANT_SKB doesn't work because it
2867 * stores the buffer and then wakes up this thread, by which
2868 * time another notification (that the time event started)
2869 * might already be processed unsuccessfully.
2871 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
2872 time_event_response,
2873 ARRAY_SIZE(time_event_response),
2874 iwl_mvm_rx_aux_roc, te_data);
2876 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
2880 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
2881 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
2885 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
2886 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
2887 /* should never fail */
2892 spin_lock_bh(&mvm->time_event_lock);
2893 iwl_mvm_te_clear_data(mvm, te_data);
2894 spin_unlock_bh(&mvm->time_event_lock);
2900 static int iwl_mvm_roc(struct ieee80211_hw *hw,
2901 struct ieee80211_vif *vif,
2902 struct ieee80211_channel *channel,
2904 enum ieee80211_roc_type type)
2906 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2907 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2908 struct cfg80211_chan_def chandef;
2909 struct iwl_mvm_phy_ctxt *phy_ctxt;
2912 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2915 mutex_lock(&mvm->mutex);
2917 switch (vif->type) {
2918 case NL80211_IFTYPE_STATION:
2919 if (mvm->fw->ucode_capa.capa[0] &
2920 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT) {
2921 /* Use aux roc framework (HS20) */
2922 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
2926 IWL_ERR(mvm, "hotspot not supported\n");
2929 case NL80211_IFTYPE_P2P_DEVICE:
2933 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
2938 for (i = 0; i < NUM_PHY_CTX; i++) {
2939 phy_ctxt = &mvm->phy_ctxts[i];
2940 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2943 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2945 * Unbind the P2P_DEVICE from the current PHY context,
2946 * and if the PHY context is not used remove it.
2948 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2949 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2952 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2954 /* Bind the P2P_DEVICE to the current PHY Context */
2955 mvmvif->phy_ctxt = phy_ctxt;
2957 ret = iwl_mvm_binding_add_vif(mvm, vif);
2958 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2961 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2962 goto schedule_time_event;
2966 /* Need to update the PHY context only if the ROC channel changed */
2967 if (channel == mvmvif->phy_ctxt->channel)
2968 goto schedule_time_event;
2970 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2973 * Change the PHY context configuration as it is currently referenced
2974 * only by the P2P Device MAC
2976 if (mvmvif->phy_ctxt->ref == 1) {
2977 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2983 * The PHY context is shared with other MACs. Need to remove the
2984 * P2P Device from the binding, allocate an new PHY context and
2985 * create a new binding
2987 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2993 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2996 IWL_ERR(mvm, "Failed to change PHY context\n");
3000 /* Unbind the P2P_DEVICE from the current PHY context */
3001 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3002 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3005 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3007 /* Bind the P2P_DEVICE to the new allocated PHY context */
3008 mvmvif->phy_ctxt = phy_ctxt;
3010 ret = iwl_mvm_binding_add_vif(mvm, vif);
3011 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3014 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3017 schedule_time_event:
3018 /* Schedule the time events */
3019 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3022 mutex_unlock(&mvm->mutex);
3023 IWL_DEBUG_MAC80211(mvm, "leave\n");
3027 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
3029 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3031 IWL_DEBUG_MAC80211(mvm, "enter\n");
3033 mutex_lock(&mvm->mutex);
3034 iwl_mvm_stop_roc(mvm);
3035 mutex_unlock(&mvm->mutex);
3037 IWL_DEBUG_MAC80211(mvm, "leave\n");
3041 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3042 struct ieee80211_chanctx_conf *ctx)
3044 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3045 struct iwl_mvm_phy_ctxt *phy_ctxt;
3048 lockdep_assert_held(&mvm->mutex);
3050 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3052 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3058 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3059 ctx->rx_chains_static,
3060 ctx->rx_chains_dynamic);
3062 IWL_ERR(mvm, "Failed to add PHY context\n");
3066 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3067 *phy_ctxt_id = phy_ctxt->id;
3072 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3073 struct ieee80211_chanctx_conf *ctx)
3075 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3078 mutex_lock(&mvm->mutex);
3079 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3080 mutex_unlock(&mvm->mutex);
3085 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3086 struct ieee80211_chanctx_conf *ctx)
3088 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3089 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3091 lockdep_assert_held(&mvm->mutex);
3093 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3096 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3097 struct ieee80211_chanctx_conf *ctx)
3099 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3101 mutex_lock(&mvm->mutex);
3102 __iwl_mvm_remove_chanctx(mvm, ctx);
3103 mutex_unlock(&mvm->mutex);
3106 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3107 struct ieee80211_chanctx_conf *ctx,
3110 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3111 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3112 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3114 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3115 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3116 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3117 IEEE80211_CHANCTX_CHANGE_RADAR |
3118 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3119 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3120 phy_ctxt->ref, changed))
3123 mutex_lock(&mvm->mutex);
3124 iwl_mvm_bt_coex_vif_change(mvm);
3125 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3126 ctx->rx_chains_static,
3127 ctx->rx_chains_dynamic);
3128 mutex_unlock(&mvm->mutex);
3131 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3132 struct ieee80211_vif *vif,
3133 struct ieee80211_chanctx_conf *ctx,
3134 bool switching_chanctx)
3136 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3137 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3138 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3141 lockdep_assert_held(&mvm->mutex);
3143 mvmvif->phy_ctxt = phy_ctxt;
3145 switch (vif->type) {
3146 case NL80211_IFTYPE_AP:
3147 /* only needed if we're switching chanctx (i.e. during CSA) */
3148 if (switching_chanctx) {
3149 mvmvif->ap_ibss_active = true;
3152 case NL80211_IFTYPE_ADHOC:
3154 * The AP binding flow is handled as part of the start_ap flow
3155 * (in bss_info_changed), similarly for IBSS.
3159 case NL80211_IFTYPE_STATION:
3161 case NL80211_IFTYPE_MONITOR:
3162 /* always disable PS when a monitor interface is active */
3163 mvmvif->ps_disabled = true;
3170 ret = iwl_mvm_binding_add_vif(mvm, vif);
3175 * Power state must be updated before quotas,
3176 * otherwise fw will complain.
3178 iwl_mvm_power_update_mac(mvm);
3180 /* Setting the quota at this stage is only required for monitor
3181 * interfaces. For the other types, the bss_info changed flow
3182 * will handle quota settings.
3184 if (vif->type == NL80211_IFTYPE_MONITOR) {
3185 mvmvif->monitor_active = true;
3186 ret = iwl_mvm_update_quotas(mvm, NULL);
3188 goto out_remove_binding;
3191 /* Handle binding during CSA */
3192 if (vif->type == NL80211_IFTYPE_AP) {
3193 iwl_mvm_update_quotas(mvm, NULL);
3194 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3197 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3198 u32 duration = 2 * vif->bss_conf.beacon_int;
3200 /* iwl_mvm_protect_session() reads directly from the
3201 * device (the system time), so make sure it is
3204 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3206 goto out_remove_binding;
3208 /* Protect the session to make sure we hear the first
3209 * beacon on the new channel.
3211 iwl_mvm_protect_session(mvm, vif, duration, duration,
3212 vif->bss_conf.beacon_int / 2,
3215 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3217 iwl_mvm_update_quotas(mvm, NULL);
3223 iwl_mvm_binding_remove_vif(mvm, vif);
3224 iwl_mvm_power_update_mac(mvm);
3227 mvmvif->phy_ctxt = NULL;
3230 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3231 struct ieee80211_vif *vif,
3232 struct ieee80211_chanctx_conf *ctx)
3234 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3237 mutex_lock(&mvm->mutex);
3238 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3239 mutex_unlock(&mvm->mutex);
3244 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3245 struct ieee80211_vif *vif,
3246 struct ieee80211_chanctx_conf *ctx,
3247 bool switching_chanctx)
3249 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3250 struct ieee80211_vif *disabled_vif = NULL;
3252 lockdep_assert_held(&mvm->mutex);
3254 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3256 switch (vif->type) {
3257 case NL80211_IFTYPE_ADHOC:
3259 case NL80211_IFTYPE_MONITOR:
3260 mvmvif->monitor_active = false;
3261 mvmvif->ps_disabled = false;
3263 case NL80211_IFTYPE_AP:
3264 /* This part is triggered only during CSA */
3265 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3268 mvmvif->csa_countdown = false;
3270 /* Set CS bit on all the stations */
3271 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3273 /* Save blocked iface, the timeout is set on the next beacon */
3274 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3276 mvmvif->ap_ibss_active = false;
3278 case NL80211_IFTYPE_STATION:
3279 if (!switching_chanctx)
3284 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3290 iwl_mvm_update_quotas(mvm, disabled_vif);
3291 iwl_mvm_binding_remove_vif(mvm, vif);
3294 mvmvif->phy_ctxt = NULL;
3295 iwl_mvm_power_update_mac(mvm);
3298 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3299 struct ieee80211_vif *vif,
3300 struct ieee80211_chanctx_conf *ctx)
3302 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3304 mutex_lock(&mvm->mutex);
3305 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3306 mutex_unlock(&mvm->mutex);
3310 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3311 struct ieee80211_vif_chanctx_switch *vifs)
3315 mutex_lock(&mvm->mutex);
3316 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3317 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3319 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3321 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3325 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3329 "failed to assign new_ctx during channel switch\n");
3333 /* we don't support TDLS during DCM - can be caused by channel switch */
3334 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3335 iwl_mvm_teardown_tdls_peers(mvm);
3340 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3343 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3344 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3348 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3350 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3357 /* things keep failing, better restart the hw */
3358 iwl_mvm_nic_restart(mvm, false);
3361 mutex_unlock(&mvm->mutex);
3367 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3368 struct ieee80211_vif_chanctx_switch *vifs)
3372 mutex_lock(&mvm->mutex);
3373 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3375 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3379 "failed to assign new_ctx during channel switch\n");
3386 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3388 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3395 /* things keep failing, better restart the hw */
3396 iwl_mvm_nic_restart(mvm, false);
3399 mutex_unlock(&mvm->mutex);
3404 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3405 struct ieee80211_vif_chanctx_switch *vifs,
3407 enum ieee80211_chanctx_switch_mode mode)
3409 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3412 /* we only support a single-vif right now */
3417 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3418 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3420 case CHANCTX_SWMODE_REASSIGN_VIF:
3421 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
3431 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3432 struct ieee80211_sta *sta,
3435 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3436 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3438 if (!mvm_sta || !mvm_sta->vif) {
3439 IWL_ERR(mvm, "Station is not associated to a vif\n");
3443 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3446 #ifdef CONFIG_NL80211_TESTMODE
3447 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3448 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3449 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
3450 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
3453 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3454 struct ieee80211_vif *vif,
3455 void *data, int len)
3457 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3461 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
3465 if (!tb[IWL_MVM_TM_ATTR_CMD])
3468 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3469 case IWL_MVM_TM_CMD_SET_NOA:
3470 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3471 !vif->bss_conf.enable_beacon ||
3472 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3475 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3476 if (noa_duration >= vif->bss_conf.beacon_int)
3479 mvm->noa_duration = noa_duration;
3482 return iwl_mvm_update_quotas(mvm, NULL);
3483 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3484 /* must be associated client vif - ignore authorized */
3485 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3486 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3487 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3490 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
3491 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3492 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3498 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3499 struct ieee80211_vif *vif,
3500 void *data, int len)
3502 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3505 mutex_lock(&mvm->mutex);
3506 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3507 mutex_unlock(&mvm->mutex);
3513 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3514 struct ieee80211_vif *vif,
3515 struct ieee80211_channel_switch *chsw)
3517 /* By implementing this operation, we prevent mac80211 from
3518 * starting its own channel switch timer, so that we can call
3519 * ieee80211_chswitch_done() ourselves at the right time
3520 * (which is when the absence time event starts).
3523 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3524 "dummy channel switch op\n");
3527 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3528 struct ieee80211_vif *vif,
3529 struct ieee80211_channel_switch *chsw)
3531 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3532 struct ieee80211_vif *csa_vif;
3533 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3537 mutex_lock(&mvm->mutex);
3539 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
3540 chsw->chandef.center_freq1);
3542 iwl_fw_dbg_trigger_simple_stop(mvm, vif, FW_DBG_TRIGGER_CHANNEL_SWITCH,
3545 switch (vif->type) {
3546 case NL80211_IFTYPE_AP:
3548 rcu_dereference_protected(mvm->csa_vif,
3549 lockdep_is_held(&mvm->mutex));
3550 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3551 "Another CSA is already in progress")) {
3556 rcu_assign_pointer(mvm->csa_vif, vif);
3558 if (WARN_ONCE(mvmvif->csa_countdown,
3559 "Previous CSA countdown didn't complete")) {
3565 case NL80211_IFTYPE_STATION:
3566 /* Schedule the time event to a bit before beacon 1,
3567 * to make sure we're in the new channel when the
3570 apply_time = chsw->device_timestamp +
3571 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3572 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
3575 iwl_mvm_csa_client_absent(mvm, vif);
3577 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
3579 if (mvmvif->bf_data.bf_enabled) {
3580 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3590 mvmvif->ps_disabled = true;
3592 ret = iwl_mvm_power_update_ps(mvm);
3596 /* we won't be on this channel any longer */
3597 iwl_mvm_teardown_tdls_peers(mvm);
3600 mutex_unlock(&mvm->mutex);
3605 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
3606 struct ieee80211_vif *vif)
3608 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3609 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3612 mutex_lock(&mvm->mutex);
3614 if (vif->type == NL80211_IFTYPE_STATION) {
3615 struct iwl_mvm_sta *mvmsta;
3617 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
3620 if (WARN_ON(!mvmsta)) {
3625 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
3627 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3629 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3633 iwl_mvm_stop_session_protection(mvm, vif);
3636 mvmvif->ps_disabled = false;
3638 ret = iwl_mvm_power_update_ps(mvm);
3641 mutex_unlock(&mvm->mutex);
3646 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3647 struct ieee80211_vif *vif, u32 queues, bool drop)
3649 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3650 struct iwl_mvm_vif *mvmvif;
3651 struct iwl_mvm_sta *mvmsta;
3652 struct ieee80211_sta *sta;
3656 if (!vif || vif->type != NL80211_IFTYPE_STATION)
3659 mutex_lock(&mvm->mutex);
3660 mvmvif = iwl_mvm_vif_from_mac80211(vif);
3662 /* flush the AP-station and all TDLS peers */
3663 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
3664 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3665 lockdep_is_held(&mvm->mutex));
3666 if (IS_ERR_OR_NULL(sta))
3669 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3670 if (mvmsta->vif != vif)
3673 /* make sure only TDLS peers or the AP are flushed */
3674 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
3676 msk |= mvmsta->tfd_queue_msk;
3680 if (iwl_mvm_flush_tx_path(mvm, msk, true))
3681 IWL_ERR(mvm, "flush request fail\n");
3682 mutex_unlock(&mvm->mutex);
3684 mutex_unlock(&mvm->mutex);
3686 /* this can take a while, and we may need/want other operations
3687 * to succeed while doing this, so do it without the mutex held
3689 iwl_trans_wait_tx_queue_empty(mvm->trans, msk);
3693 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
3694 struct survey_info *survey)
3696 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3699 memset(survey, 0, sizeof(*survey));
3701 /* only support global statistics right now */
3705 if (!(mvm->fw->ucode_capa.capa[0] &
3706 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
3709 mutex_lock(&mvm->mutex);
3711 if (mvm->ucode_loaded) {
3712 ret = iwl_mvm_request_statistics(mvm, false);
3717 survey->filled = SURVEY_INFO_TIME |
3718 SURVEY_INFO_TIME_RX |
3719 SURVEY_INFO_TIME_TX |
3720 SURVEY_INFO_TIME_SCAN;
3721 survey->time = mvm->accu_radio_stats.on_time_rf +
3722 mvm->radio_stats.on_time_rf;
3723 do_div(survey->time, USEC_PER_MSEC);
3725 survey->time_rx = mvm->accu_radio_stats.rx_time +
3726 mvm->radio_stats.rx_time;
3727 do_div(survey->time_rx, USEC_PER_MSEC);
3729 survey->time_tx = mvm->accu_radio_stats.tx_time +
3730 mvm->radio_stats.tx_time;
3731 do_div(survey->time_tx, USEC_PER_MSEC);
3733 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
3734 mvm->radio_stats.on_time_scan;
3735 do_div(survey->time_scan, USEC_PER_MSEC);
3738 mutex_unlock(&mvm->mutex);
3742 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
3743 struct ieee80211_vif *vif,
3744 struct ieee80211_sta *sta,
3745 struct station_info *sinfo)
3747 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3748 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3749 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3751 if (!(mvm->fw->ucode_capa.capa[0] &
3752 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
3755 /* if beacon filtering isn't on mac80211 does it anyway */
3756 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
3759 if (!vif->bss_conf.assoc)
3762 mutex_lock(&mvm->mutex);
3764 if (mvmvif->ap_sta_id != mvmsta->sta_id)
3767 if (iwl_mvm_request_statistics(mvm, false))
3770 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
3771 mvmvif->beacon_stats.accu_num_beacons;
3772 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_RX);
3773 if (mvmvif->beacon_stats.avg_signal) {
3774 /* firmware only reports a value after RXing a few beacons */
3775 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
3776 sinfo->filled |= BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
3779 mutex_unlock(&mvm->mutex);
3782 const struct ieee80211_ops iwl_mvm_hw_ops = {
3783 .tx = iwl_mvm_mac_tx,
3784 .ampdu_action = iwl_mvm_mac_ampdu_action,
3785 .start = iwl_mvm_mac_start,
3786 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
3787 .stop = iwl_mvm_mac_stop,
3788 .add_interface = iwl_mvm_mac_add_interface,
3789 .remove_interface = iwl_mvm_mac_remove_interface,
3790 .config = iwl_mvm_mac_config,
3791 .prepare_multicast = iwl_mvm_prepare_multicast,
3792 .configure_filter = iwl_mvm_configure_filter,
3793 .bss_info_changed = iwl_mvm_bss_info_changed,
3794 .hw_scan = iwl_mvm_mac_hw_scan,
3795 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
3796 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
3797 .sta_state = iwl_mvm_mac_sta_state,
3798 .sta_notify = iwl_mvm_mac_sta_notify,
3799 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
3800 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
3801 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
3802 .sta_rc_update = iwl_mvm_sta_rc_update,
3803 .conf_tx = iwl_mvm_mac_conf_tx,
3804 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
3805 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
3806 .flush = iwl_mvm_mac_flush,
3807 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
3808 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
3809 .set_key = iwl_mvm_mac_set_key,
3810 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
3811 .remain_on_channel = iwl_mvm_roc,
3812 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
3813 .add_chanctx = iwl_mvm_add_chanctx,
3814 .remove_chanctx = iwl_mvm_remove_chanctx,
3815 .change_chanctx = iwl_mvm_change_chanctx,
3816 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
3817 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
3818 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
3820 .start_ap = iwl_mvm_start_ap_ibss,
3821 .stop_ap = iwl_mvm_stop_ap_ibss,
3822 .join_ibss = iwl_mvm_start_ap_ibss,
3823 .leave_ibss = iwl_mvm_stop_ap_ibss,
3825 .set_tim = iwl_mvm_set_tim,
3827 .channel_switch = iwl_mvm_channel_switch,
3828 .pre_channel_switch = iwl_mvm_pre_channel_switch,
3829 .post_channel_switch = iwl_mvm_post_channel_switch,
3831 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
3832 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
3833 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
3835 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
3837 #ifdef CONFIG_PM_SLEEP
3839 .suspend = iwl_mvm_suspend,
3840 .resume = iwl_mvm_resume,
3841 .set_wakeup = iwl_mvm_set_wakeup,
3842 .set_rekey_data = iwl_mvm_set_rekey_data,
3843 #if IS_ENABLED(CONFIG_IPV6)
3844 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
3846 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
3848 .get_survey = iwl_mvm_mac_get_survey,
3849 .sta_statistics = iwl_mvm_mac_sta_statistics,