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"
90 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
93 .types = BIT(NL80211_IFTYPE_STATION),
97 .types = BIT(NL80211_IFTYPE_AP) |
98 BIT(NL80211_IFTYPE_P2P_CLIENT) |
99 BIT(NL80211_IFTYPE_P2P_GO),
103 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
107 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
109 .num_different_channels = 2,
111 .limits = iwl_mvm_limits,
112 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
116 #ifdef CONFIG_PM_SLEEP
117 static const struct nl80211_wowlan_tcp_data_token_feature
118 iwl_mvm_wowlan_tcp_token_feature = {
121 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
124 static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
125 .tok = &iwl_mvm_wowlan_tcp_token_feature,
126 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
127 sizeof(struct ethhdr) -
128 sizeof(struct iphdr) -
129 sizeof(struct tcphdr),
130 .data_interval_max = 65535, /* __le16 in API */
131 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
132 sizeof(struct ethhdr) -
133 sizeof(struct iphdr) -
134 sizeof(struct tcphdr),
139 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
141 * Use the reserved field to indicate magic values.
142 * these values will only be used internally by the driver,
143 * and won't make it to the fw (reserved will be 0).
144 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
145 * be the vif's ip address. in case there is not a single
146 * ip address (0, or more than 1), this attribute will
148 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
149 * the LSB bytes of the vif's mac address
152 BC_FILTER_MAGIC_NONE = 0,
157 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
161 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
164 /* frame type - arp, hw type - ethernet */
166 BCAST_FILTER_OFFSET_PAYLOAD_START,
167 .offset = sizeof(rfc1042_header),
168 .val = cpu_to_be32(0x08060001),
169 .mask = cpu_to_be32(0xffffffff),
174 BCAST_FILTER_OFFSET_PAYLOAD_START,
175 .offset = sizeof(rfc1042_header) + 2 +
176 sizeof(struct arphdr) +
177 ETH_ALEN + sizeof(__be32) +
179 .mask = cpu_to_be32(0xffffffff),
180 /* mark it as special field */
181 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
186 /* dhcp offer bcast */
188 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
191 /* udp dest port - 68 (bootp client)*/
192 .offset_type = BCAST_FILTER_OFFSET_IP_END,
193 .offset = offsetof(struct udphdr, dest),
194 .val = cpu_to_be32(0x00440000),
195 .mask = cpu_to_be32(0xffff0000),
198 /* dhcp - lsb bytes of client hw address */
199 .offset_type = BCAST_FILTER_OFFSET_IP_END,
201 .mask = cpu_to_be32(0xffffffff),
202 /* mark it as special field */
203 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
207 /* last filter must be empty */
212 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
214 if (!iwl_mvm_is_d0i3_supported(mvm))
217 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
218 spin_lock_bh(&mvm->refs_lock);
219 mvm->refs[ref_type]++;
220 spin_unlock_bh(&mvm->refs_lock);
221 iwl_trans_ref(mvm->trans);
224 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
226 if (!iwl_mvm_is_d0i3_supported(mvm))
229 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
230 spin_lock_bh(&mvm->refs_lock);
231 WARN_ON(!mvm->refs[ref_type]--);
232 spin_unlock_bh(&mvm->refs_lock);
233 iwl_trans_unref(mvm->trans);
236 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
237 enum iwl_mvm_ref_type except_ref)
241 if (!iwl_mvm_is_d0i3_supported(mvm))
244 spin_lock_bh(&mvm->refs_lock);
245 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
246 if (except_ref == i || !mvm->refs[i])
249 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
251 for (j = 0; j < mvm->refs[i]; j++)
252 iwl_trans_unref(mvm->trans);
255 spin_unlock_bh(&mvm->refs_lock);
258 bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
263 if (!iwl_mvm_is_d0i3_supported(mvm))
266 spin_lock_bh(&mvm->refs_lock);
267 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
273 spin_unlock_bh(&mvm->refs_lock);
278 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
280 iwl_mvm_ref(mvm, ref_type);
282 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
283 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
286 iwl_mvm_unref(mvm, ref_type);
293 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
297 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
298 for (i = 0; i < NUM_PHY_CTX; i++) {
299 mvm->phy_ctxts[i].id = i;
300 mvm->phy_ctxts[i].ref = 0;
304 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
306 struct ieee80211_hw *hw = mvm->hw;
309 /* Tell mac80211 our characteristics */
310 hw->flags = IEEE80211_HW_SIGNAL_DBM |
311 IEEE80211_HW_SPECTRUM_MGMT |
312 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
313 IEEE80211_HW_QUEUE_CONTROL |
314 IEEE80211_HW_WANT_MONITOR_VIF |
315 IEEE80211_HW_SUPPORTS_PS |
316 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
317 IEEE80211_HW_AMPDU_AGGREGATION |
318 IEEE80211_HW_TIMING_BEACON_ONLY |
319 IEEE80211_HW_CONNECTION_MONITOR |
320 IEEE80211_HW_CHANCTX_STA_CSA |
321 IEEE80211_HW_SUPPORTS_CLONED_SKBS;
323 hw->queues = mvm->first_agg_queue;
324 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
325 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
326 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
327 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
328 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
329 hw->rate_control_algorithm = "iwl-mvm-rs";
330 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
331 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
334 * Enable 11w if advertised by firmware and software crypto
335 * is not enabled (as the firmware will interpret some mgmt
336 * packets, so enabling it with software crypto isn't safe)
338 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
339 !iwlwifi_mod_params.sw_crypto)
340 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
342 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN ||
343 mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) {
344 hw->flags |= IEEE80211_SINGLE_HW_SCAN_ON_ALL_BANDS;
345 hw->wiphy->features |=
346 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
347 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
350 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
351 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
352 hw->chanctx_data_size = sizeof(u16);
354 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
355 BIT(NL80211_IFTYPE_P2P_CLIENT) |
356 BIT(NL80211_IFTYPE_AP) |
357 BIT(NL80211_IFTYPE_P2P_GO) |
358 BIT(NL80211_IFTYPE_P2P_DEVICE) |
359 BIT(NL80211_IFTYPE_ADHOC);
361 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
362 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
363 REGULATORY_DISABLE_BEACON_HINTS;
365 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
366 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
368 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
370 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
371 hw->wiphy->n_iface_combinations =
372 ARRAY_SIZE(iwl_mvm_iface_combinations);
374 hw->wiphy->max_remain_on_channel_duration = 10000;
375 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
376 /* we can compensate an offset of up to 3 channels = 15 MHz */
377 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
379 /* Extract MAC address */
380 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
381 hw->wiphy->addresses = mvm->addresses;
382 hw->wiphy->n_addresses = 1;
384 /* Extract additional MAC addresses if available */
385 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
386 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
388 for (i = 1; i < num_mac; i++) {
389 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
391 mvm->addresses[i].addr[5]++;
392 hw->wiphy->n_addresses++;
395 iwl_mvm_reset_phy_ctxts(mvm);
397 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm, false);
399 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
401 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
402 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
403 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
404 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
405 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
406 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
408 hw->wiphy->hw_version = mvm->trans->hw_id;
410 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
411 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
413 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
415 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 10) {
416 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
417 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
418 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
419 /* we create the 802.11 header and zero length SSID IE. */
420 hw->wiphy->max_sched_scan_ie_len =
421 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
424 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
425 NL80211_FEATURE_LOW_PRIORITY_SCAN |
426 NL80211_FEATURE_P2P_GO_OPPPS |
427 NL80211_FEATURE_DYNAMIC_SMPS |
428 NL80211_FEATURE_STATIC_SMPS |
429 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
431 if (mvm->fw->ucode_capa.capa[0] &
432 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)
433 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
434 if (mvm->fw->ucode_capa.capa[0] &
435 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)
436 hw->wiphy->features |= NL80211_FEATURE_QUIET;
438 if (mvm->fw->ucode_capa.capa[0] &
439 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)
440 hw->wiphy->features |=
441 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
443 if (mvm->fw->ucode_capa.capa[0] &
444 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)
445 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
447 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
449 /* currently FW API supports only one optional cipher scheme */
450 if (mvm->fw->cs[0].cipher) {
451 mvm->hw->n_cipher_schemes = 1;
452 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
455 #ifdef CONFIG_PM_SLEEP
456 if (iwl_mvm_is_d0i3_supported(mvm) &&
457 device_can_wakeup(mvm->trans->dev)) {
458 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
459 hw->wiphy->wowlan = &mvm->wowlan;
462 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
463 mvm->trans->ops->d3_suspend &&
464 mvm->trans->ops->d3_resume &&
465 device_can_wakeup(mvm->trans->dev)) {
466 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
467 WIPHY_WOWLAN_DISCONNECT |
468 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
469 WIPHY_WOWLAN_RFKILL_RELEASE |
470 WIPHY_WOWLAN_NET_DETECT;
471 if (!iwlwifi_mod_params.sw_crypto)
472 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
473 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
474 WIPHY_WOWLAN_4WAY_HANDSHAKE;
476 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
477 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
478 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
479 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
480 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
481 hw->wiphy->wowlan = &mvm->wowlan;
485 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
486 /* assign default bcast filtering configuration */
487 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
490 ret = iwl_mvm_leds_init(mvm);
494 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_TDLS_SUPPORT) {
495 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
496 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
499 if (mvm->fw->ucode_capa.capa[0] &
500 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH) {
501 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
502 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
505 ret = ieee80211_register_hw(mvm->hw);
507 iwl_mvm_leds_exit(mvm);
512 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
513 struct ieee80211_sta *sta,
516 struct iwl_mvm_sta *mvmsta;
520 * double check the IN_D0I3 flag both before and after
521 * taking the spinlock, in order to prevent taking
522 * the spinlock when not needed.
524 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
527 spin_lock(&mvm->d0i3_tx_lock);
529 * testing the flag again ensures the skb dequeue
530 * loop (on d0i3 exit) hasn't run yet.
532 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
535 mvmsta = iwl_mvm_sta_from_mac80211(sta);
536 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
537 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
540 __skb_queue_tail(&mvm->d0i3_tx, skb);
541 ieee80211_stop_queues(mvm->hw);
544 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
545 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
549 spin_unlock(&mvm->d0i3_tx_lock);
553 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
554 struct ieee80211_tx_control *control,
557 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
558 struct ieee80211_sta *sta = control->sta;
559 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
560 struct ieee80211_hdr *hdr = (void *)skb->data;
562 if (iwl_mvm_is_radio_killed(mvm)) {
563 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
567 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
568 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
569 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
572 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
573 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
574 ieee80211_is_mgmt(hdr->frame_control) &&
575 !ieee80211_is_deauth(hdr->frame_control) &&
576 !ieee80211_is_disassoc(hdr->frame_control) &&
577 !ieee80211_is_action(hdr->frame_control)))
581 if (iwl_mvm_defer_tx(mvm, sta, skb))
583 if (iwl_mvm_tx_skb(mvm, skb, sta))
588 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
592 ieee80211_free_txskb(hw, skb);
595 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
597 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
602 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
604 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
606 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
609 /* enabled by default */
613 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
614 struct ieee80211_vif *vif,
615 enum ieee80211_ampdu_mlme_action action,
616 struct ieee80211_sta *sta, u16 tid,
617 u16 *ssn, u8 buf_size)
619 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
621 bool tx_agg_ref = false;
623 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
624 sta->addr, tid, action);
626 if (!(mvm->nvm_data->sku_cap_11n_enable))
629 /* return from D0i3 before starting a new Tx aggregation */
631 case IEEE80211_AMPDU_TX_START:
632 case IEEE80211_AMPDU_TX_STOP_CONT:
633 case IEEE80211_AMPDU_TX_STOP_FLUSH:
634 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
635 case IEEE80211_AMPDU_TX_OPERATIONAL:
637 * for tx start, wait synchronously until D0i3 exit to
638 * get the correct sequence number for the tid.
639 * additionally, some other ampdu actions use direct
640 * target access, which is not handled automatically
641 * by the trans layer (unlike commands), so wait for
642 * d0i3 exit in these cases as well.
644 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
654 mutex_lock(&mvm->mutex);
657 case IEEE80211_AMPDU_RX_START:
658 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
662 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
664 case IEEE80211_AMPDU_RX_STOP:
665 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
667 case IEEE80211_AMPDU_TX_START:
668 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
672 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
674 case IEEE80211_AMPDU_TX_STOP_CONT:
675 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
677 case IEEE80211_AMPDU_TX_STOP_FLUSH:
678 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
679 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
681 case IEEE80211_AMPDU_TX_OPERATIONAL:
682 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
689 mutex_unlock(&mvm->mutex);
692 * If the tid is marked as started, we won't use it for offloaded
693 * traffic on the next D0i3 entry. It's safe to unref.
696 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
701 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
702 struct ieee80211_vif *vif)
704 struct iwl_mvm *mvm = data;
705 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
707 mvmvif->uploaded = false;
708 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
710 /* does this make sense at all? */
713 spin_lock_bh(&mvm->time_event_lock);
714 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
715 spin_unlock_bh(&mvm->time_event_lock);
717 mvmvif->phy_ctxt = NULL;
718 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
721 static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
722 const void *data, size_t datalen)
724 const struct iwl_mvm_dump_ptrs *dump_ptrs = data;
726 ssize_t bytes_read_trans;
728 if (offset < dump_ptrs->op_mode_len) {
729 bytes_read = min_t(ssize_t, count,
730 dump_ptrs->op_mode_len - offset);
731 memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset,
733 offset += bytes_read;
742 if (!dump_ptrs->trans_ptr)
745 offset -= dump_ptrs->op_mode_len;
746 bytes_read_trans = min_t(ssize_t, count,
747 dump_ptrs->trans_ptr->len - offset);
748 memcpy(buffer + bytes_read,
749 (u8 *)dump_ptrs->trans_ptr->data + offset,
752 return bytes_read + bytes_read_trans;
755 static void iwl_mvm_free_coredump(const void *data)
757 const struct iwl_mvm_dump_ptrs *fw_error_dump = data;
759 vfree(fw_error_dump->op_mode_ptr);
760 vfree(fw_error_dump->trans_ptr);
761 kfree(fw_error_dump);
764 void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
766 struct iwl_fw_error_dump_file *dump_file;
767 struct iwl_fw_error_dump_data *dump_data;
768 struct iwl_fw_error_dump_info *dump_info;
769 struct iwl_fw_error_dump_mem *dump_mem;
770 struct iwl_mvm_dump_ptrs *fw_error_dump;
771 u32 sram_len, sram_ofs;
772 u32 file_len, rxf_len;
775 u32 smem_len = mvm->cfg->smem_len;
777 lockdep_assert_held(&mvm->mutex);
779 /* W/A for 8000 HW family A-step */
780 if (mvm->cfg->smem_len &&
781 mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
782 CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_A_STEP)
785 fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
789 /* SRAM - include stack CCM if driver knows the values for it */
790 if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
791 const struct fw_img *img;
793 img = &mvm->fw->img[mvm->cur_ucode];
794 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
795 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
797 sram_ofs = mvm->cfg->dccm_offset;
798 sram_len = mvm->cfg->dccm_len;
801 /* reading buffer size */
802 reg_val = iwl_trans_read_prph(mvm->trans, RXF_SIZE_ADDR);
803 rxf_len = (reg_val & RXF_SIZE_BYTE_CNT_MSK) >> RXF_SIZE_BYTE_CND_POS;
805 /* the register holds the value divided by 128 */
806 rxf_len = rxf_len << 7;
808 file_len = sizeof(*dump_file) +
809 sizeof(*dump_data) * 3 +
810 sram_len + sizeof(*dump_mem) +
814 /* Make room for the SMEM, if it exists */
816 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
818 dump_file = vzalloc(file_len);
820 kfree(fw_error_dump);
824 fw_error_dump->op_mode_ptr = dump_file;
826 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
827 dump_data = (void *)dump_file->data;
829 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
830 dump_data->len = cpu_to_le32(sizeof(*dump_info));
831 dump_info = (void *) dump_data->data;
832 dump_info->device_family =
833 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
834 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
835 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
836 dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
837 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
838 sizeof(dump_info->fw_human_readable));
839 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
840 sizeof(dump_info->dev_human_readable));
841 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
842 sizeof(dump_info->bus_human_readable));
844 dump_data = iwl_fw_error_next_data(dump_data);
845 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
846 dump_data->len = cpu_to_le32(rxf_len);
848 if (iwl_trans_grab_nic_access(mvm->trans, false, &flags)) {
849 u32 *rxf = (void *)dump_data->data;
852 for (i = 0; i < (rxf_len / sizeof(u32)); i++) {
853 iwl_trans_write_prph(mvm->trans,
854 RXF_LD_FENCE_OFFSET_ADDR,
856 rxf[i] = iwl_trans_read_prph(mvm->trans,
857 RXF_FIFO_RD_FENCE_ADDR);
859 iwl_trans_release_nic_access(mvm->trans, &flags);
862 dump_data = iwl_fw_error_next_data(dump_data);
863 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
864 dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
865 dump_mem = (void *)dump_data->data;
866 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
867 dump_mem->offset = cpu_to_le32(sram_ofs);
868 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
872 dump_data = iwl_fw_error_next_data(dump_data);
873 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
874 dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
875 dump_mem = (void *)dump_data->data;
876 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
877 dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
878 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
879 dump_mem->data, smem_len);
882 fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans);
883 fw_error_dump->op_mode_len = file_len;
884 if (fw_error_dump->trans_ptr)
885 file_len += fw_error_dump->trans_ptr->len;
886 dump_file->file_len = cpu_to_le32(file_len);
888 dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
889 GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
892 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
894 /* clear the D3 reconfig, we only need it to avoid dumping a
895 * firmware coredump on reconfiguration, we shouldn't do that
896 * on D3->D0 transition
898 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status))
899 iwl_mvm_fw_error_dump(mvm);
901 /* cleanup all stale references (scan, roc), but keep the
902 * ucode_down ref until reconfig is complete
904 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
906 iwl_trans_stop_device(mvm->trans);
908 mvm->scan_status = IWL_MVM_SCAN_NONE;
909 mvm->ps_disabled = false;
910 mvm->calibrating = false;
912 /* just in case one was running */
913 ieee80211_remain_on_channel_expired(mvm->hw);
915 ieee80211_iterate_active_interfaces_atomic(
916 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
917 iwl_mvm_cleanup_iterator, mvm);
919 mvm->p2p_device_vif = NULL;
920 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
922 iwl_mvm_reset_phy_ctxts(mvm);
923 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
924 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
925 memset(mvm->tfd_drained, 0, sizeof(mvm->tfd_drained));
926 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
927 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
928 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
929 memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
930 memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk));
931 memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk));
933 ieee80211_wake_queues(mvm->hw);
935 /* clear any stale d0i3 state */
936 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
939 mvm->rx_ba_sessions = 0;
942 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
946 lockdep_assert_held(&mvm->mutex);
948 /* Clean up some internal and mac80211 state on restart */
949 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
950 iwl_mvm_restart_cleanup(mvm);
952 ret = iwl_mvm_up(mvm);
954 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
955 /* Something went wrong - we need to finish some cleanup
956 * that normally iwl_mvm_mac_restart_complete() below
959 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
960 iwl_mvm_d0i3_enable_tx(mvm, NULL);
966 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
968 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
971 /* Some hw restart cleanups must not hold the mutex */
972 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
974 * Make sure we are out of d0i3. This is needed
975 * to make sure the reference accounting is correct
976 * (and there is no stale d0i3_exit_work).
978 wait_event_timeout(mvm->d0i3_exit_waitq,
979 !test_bit(IWL_MVM_STATUS_IN_D0I3,
984 mutex_lock(&mvm->mutex);
985 ret = __iwl_mvm_mac_start(mvm);
986 mutex_unlock(&mvm->mutex);
991 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
995 mutex_lock(&mvm->mutex);
997 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
998 iwl_mvm_d0i3_enable_tx(mvm, NULL);
999 ret = iwl_mvm_update_quotas(mvm, NULL);
1001 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1004 /* allow transport/FW low power modes */
1005 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1008 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1009 * of packets the FW sent out, so we must reconnect.
1011 iwl_mvm_teardown_tdls_peers(mvm);
1013 mutex_unlock(&mvm->mutex);
1016 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1020 if (!iwl_mvm_is_d0i3_supported(mvm))
1023 mutex_lock(&mvm->d0i3_suspend_mutex);
1024 __clear_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags);
1025 exit_now = __test_and_clear_bit(D0I3_PENDING_WAKEUP,
1026 &mvm->d0i3_suspend_flags);
1027 mutex_unlock(&mvm->d0i3_suspend_mutex);
1030 IWL_DEBUG_RPM(mvm, "Run deferred d0i3 exit\n");
1031 _iwl_mvm_exit_d0i3(mvm);
1034 if (mvm->trans->d0i3_mode == IWL_D0I3_MODE_ON_SUSPEND)
1035 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
1036 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1039 WARN_ONCE(1, "D0i3 exit on resume timed out\n");
1043 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1044 enum ieee80211_reconfig_type reconfig_type)
1046 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1048 switch (reconfig_type) {
1049 case IEEE80211_RECONFIG_TYPE_RESTART:
1050 iwl_mvm_restart_complete(mvm);
1052 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1053 iwl_mvm_resume_complete(mvm);
1058 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1060 lockdep_assert_held(&mvm->mutex);
1063 * Disallow low power states when the FW is down by taking
1064 * the UCODE_DOWN ref. in case of ongoing hw restart the
1065 * ref is already taken, so don't take it again.
1067 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1068 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1070 /* async_handlers_wk is now blocked */
1073 * The work item could be running or queued if the
1074 * ROC time event stops just as we get here.
1076 cancel_work_sync(&mvm->roc_done_wk);
1078 iwl_trans_stop_device(mvm->trans);
1080 iwl_mvm_async_handlers_purge(mvm);
1081 /* async_handlers_list is empty and will stay empty: HW is stopped */
1083 /* the fw is stopped, the aux sta is dead: clean up driver state */
1084 iwl_mvm_del_aux_sta(mvm);
1087 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1088 * won't be called in this case).
1090 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1092 mvm->ucode_loaded = false;
1095 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1097 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1099 flush_work(&mvm->d0i3_exit_work);
1100 flush_work(&mvm->async_handlers_wk);
1101 flush_work(&mvm->fw_error_dump_wk);
1103 mutex_lock(&mvm->mutex);
1104 __iwl_mvm_mac_stop(mvm);
1105 mutex_unlock(&mvm->mutex);
1108 * The worker might have been waiting for the mutex, let it run and
1109 * discover that its list is now empty.
1111 cancel_work_sync(&mvm->async_handlers_wk);
1114 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1118 lockdep_assert_held(&mvm->mutex);
1120 for (i = 0; i < NUM_PHY_CTX; i++)
1121 if (!mvm->phy_ctxts[i].ref)
1122 return &mvm->phy_ctxts[i];
1124 IWL_ERR(mvm, "No available PHY context\n");
1128 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1131 /* FW is in charge of regulatory enforcement */
1132 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
1133 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
1134 .pwr_restriction = cpu_to_le16(tx_power),
1137 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
1138 sizeof(reduce_txpwr_cmd),
1142 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1143 struct ieee80211_vif *vif)
1145 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1146 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1150 * make sure D0i3 exit is completed, otherwise a target access
1151 * during tx queue configuration could be done when still in
1154 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1159 * Not much to do here. The stack will not allow interface
1160 * types or combinations that we didn't advertise, so we
1161 * don't really have to check the types.
1164 mutex_lock(&mvm->mutex);
1166 /* Allocate resources for the MAC context, and add it to the fw */
1167 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1171 /* Counting number of interfaces is needed for legacy PM */
1172 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1176 * The AP binding flow can be done only after the beacon
1177 * template is configured (which happens only in the mac80211
1178 * start_ap() flow), and adding the broadcast station can happen
1179 * only after the binding.
1180 * In addition, since modifying the MAC before adding a bcast
1181 * station is not allowed by the FW, delay the adding of MAC context to
1182 * the point where we can also add the bcast station.
1183 * In short: there's not much we can do at this point, other than
1184 * allocating resources :)
1186 if (vif->type == NL80211_IFTYPE_AP ||
1187 vif->type == NL80211_IFTYPE_ADHOC) {
1188 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1190 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1194 iwl_mvm_vif_dbgfs_register(mvm, vif);
1198 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1202 ret = iwl_mvm_power_update_mac(mvm);
1206 /* beacon filtering */
1207 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1209 goto out_remove_mac;
1211 if (!mvm->bf_allowed_vif &&
1212 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1213 mvm->bf_allowed_vif = mvmvif;
1214 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1215 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1216 if (mvm->fw->ucode_capa.flags &
1217 IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT &&
1218 !iwlwifi_mod_params.uapsd_disable)
1219 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
1223 * P2P_DEVICE interface does not have a channel context assigned to it,
1224 * so a dedicated PHY context is allocated to it and the corresponding
1225 * MAC context is bound to it at this stage.
1227 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1229 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1230 if (!mvmvif->phy_ctxt) {
1235 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1236 ret = iwl_mvm_binding_add_vif(mvm, vif);
1240 ret = iwl_mvm_add_bcast_sta(mvm, vif);
1244 /* Save a pointer to p2p device vif, so it can later be used to
1245 * update the p2p device MAC when a GO is started/stopped */
1246 mvm->p2p_device_vif = vif;
1249 iwl_mvm_vif_dbgfs_register(mvm, vif);
1253 iwl_mvm_binding_remove_vif(mvm, vif);
1255 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1257 if (mvm->bf_allowed_vif == mvmvif) {
1258 mvm->bf_allowed_vif = NULL;
1259 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1260 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1263 mvmvif->phy_ctxt = NULL;
1264 iwl_mvm_mac_ctxt_remove(mvm, vif);
1266 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1269 iwl_mvm_mac_ctxt_release(mvm, vif);
1271 mutex_unlock(&mvm->mutex);
1273 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1278 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1279 struct ieee80211_vif *vif)
1281 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif);
1284 mutex_lock(&mvm->mutex);
1285 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
1286 mutex_unlock(&mvm->mutex);
1289 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1291 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1292 * We assume here that all the packets sent to the OFFCHANNEL
1293 * queue are sent in ROC session.
1295 flush_work(&mvm->roc_done_wk);
1298 * By now, all the AC queues are empty. The AGG queues are
1299 * empty too. We already got all the Tx responses for all the
1300 * packets in the queues. The drain work can have been
1301 * triggered. Flush it.
1303 flush_work(&mvm->sta_drained_wk);
1307 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1308 struct ieee80211_vif *vif)
1310 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1311 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1313 iwl_mvm_prepare_mac_removal(mvm, vif);
1315 mutex_lock(&mvm->mutex);
1317 if (mvm->bf_allowed_vif == mvmvif) {
1318 mvm->bf_allowed_vif = NULL;
1319 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1320 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1323 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1326 * For AP/GO interface, the tear down of the resources allocated to the
1327 * interface is be handled as part of the stop_ap flow.
1329 if (vif->type == NL80211_IFTYPE_AP ||
1330 vif->type == NL80211_IFTYPE_ADHOC) {
1331 #ifdef CONFIG_NL80211_TESTMODE
1332 if (vif == mvm->noa_vif) {
1333 mvm->noa_vif = NULL;
1334 mvm->noa_duration = 0;
1337 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1341 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1342 mvm->p2p_device_vif = NULL;
1343 iwl_mvm_rm_bcast_sta(mvm, vif);
1344 iwl_mvm_binding_remove_vif(mvm, vif);
1345 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1346 mvmvif->phy_ctxt = NULL;
1349 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1352 iwl_mvm_power_update_mac(mvm);
1353 iwl_mvm_mac_ctxt_remove(mvm, vif);
1356 iwl_mvm_mac_ctxt_release(mvm, vif);
1357 mutex_unlock(&mvm->mutex);
1360 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1365 struct iwl_mvm_mc_iter_data {
1366 struct iwl_mvm *mvm;
1370 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1371 struct ieee80211_vif *vif)
1373 struct iwl_mvm_mc_iter_data *data = _data;
1374 struct iwl_mvm *mvm = data->mvm;
1375 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1378 /* if we don't have free ports, mcast frames will be dropped */
1379 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1382 if (vif->type != NL80211_IFTYPE_STATION ||
1383 !vif->bss_conf.assoc)
1386 cmd->port_id = data->port_id++;
1387 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1388 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1390 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
1392 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1395 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1397 struct iwl_mvm_mc_iter_data iter_data = {
1401 lockdep_assert_held(&mvm->mutex);
1403 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1406 ieee80211_iterate_active_interfaces_atomic(
1407 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1408 iwl_mvm_mc_iface_iterator, &iter_data);
1411 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1412 struct netdev_hw_addr_list *mc_list)
1414 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1415 struct iwl_mcast_filter_cmd *cmd;
1416 struct netdev_hw_addr *addr;
1421 addr_count = netdev_hw_addr_list_count(mc_list);
1422 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1423 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1427 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1428 cmd = kzalloc(len, GFP_ATOMIC);
1434 return (u64)(unsigned long)cmd;
1437 netdev_hw_addr_list_for_each(addr, mc_list) {
1438 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1439 cmd->count, addr->addr);
1440 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1441 addr->addr, ETH_ALEN);
1445 return (u64)(unsigned long)cmd;
1448 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1449 unsigned int changed_flags,
1450 unsigned int *total_flags,
1453 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1454 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1456 mutex_lock(&mvm->mutex);
1458 /* replace previous configuration */
1459 kfree(mvm->mcast_filter_cmd);
1460 mvm->mcast_filter_cmd = cmd;
1465 iwl_mvm_recalc_multicast(mvm);
1467 mutex_unlock(&mvm->mutex);
1471 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1472 struct iwl_bcast_iter_data {
1473 struct iwl_mvm *mvm;
1474 struct iwl_bcast_filter_cmd *cmd;
1479 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1480 const struct iwl_fw_bcast_filter *in_filter,
1481 struct iwl_fw_bcast_filter *out_filter)
1483 struct iwl_fw_bcast_filter_attr *attr;
1486 memcpy(out_filter, in_filter, sizeof(*out_filter));
1488 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1489 attr = &out_filter->attrs[i];
1494 switch (attr->reserved1) {
1495 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1496 if (vif->bss_conf.arp_addr_cnt != 1) {
1501 attr->val = vif->bss_conf.arp_addr_list[0];
1503 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1504 attr->val = *(__be32 *)&vif->addr[2];
1509 attr->reserved1 = 0;
1510 out_filter->num_attrs++;
1514 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1515 struct ieee80211_vif *vif)
1517 struct iwl_bcast_iter_data *data = _data;
1518 struct iwl_mvm *mvm = data->mvm;
1519 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1520 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1521 struct iwl_fw_bcast_mac *bcast_mac;
1524 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1527 bcast_mac = &cmd->macs[mvmvif->id];
1530 * enable filtering only for associated stations, but not for P2P
1533 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1534 !vif->bss_conf.assoc)
1537 bcast_mac->default_discard = 1;
1539 /* copy all configured filters */
1540 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1542 * Make sure we don't exceed our filters limit.
1543 * if there is still a valid filter to be configured,
1544 * be on the safe side and just allow bcast for this mac.
1546 if (WARN_ON_ONCE(data->current_filter >=
1547 ARRAY_SIZE(cmd->filters))) {
1548 bcast_mac->default_discard = 0;
1549 bcast_mac->attached_filters = 0;
1553 iwl_mvm_set_bcast_filter(vif,
1554 &mvm->bcast_filters[i],
1555 &cmd->filters[data->current_filter]);
1557 /* skip current filter if it contains no attributes */
1558 if (!cmd->filters[data->current_filter].num_attrs)
1561 /* attach the filter to current mac */
1562 bcast_mac->attached_filters |=
1563 cpu_to_le16(BIT(data->current_filter));
1565 data->current_filter++;
1569 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1570 struct iwl_bcast_filter_cmd *cmd)
1572 struct iwl_bcast_iter_data iter_data = {
1577 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1580 memset(cmd, 0, sizeof(*cmd));
1581 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1582 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1584 #ifdef CONFIG_IWLWIFI_DEBUGFS
1585 /* use debugfs filters/macs if override is configured */
1586 if (mvm->dbgfs_bcast_filtering.override) {
1587 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1588 sizeof(cmd->filters));
1589 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1595 /* if no filters are configured, do nothing */
1596 if (!mvm->bcast_filters)
1599 /* configure and attach these filters for each associated sta vif */
1600 ieee80211_iterate_active_interfaces(
1601 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1602 iwl_mvm_bcast_filter_iterator, &iter_data);
1606 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1607 struct ieee80211_vif *vif)
1609 struct iwl_bcast_filter_cmd cmd;
1611 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1614 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1617 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1621 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1622 struct ieee80211_vif *vif)
1628 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1629 struct ieee80211_vif *vif,
1630 struct ieee80211_bss_conf *bss_conf,
1633 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1637 * Re-calculate the tsf id, as the master-slave relations depend on the
1638 * beacon interval, which was not known when the station interface was
1641 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1642 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1645 * If we're not associated yet, take the (new) BSSID before associating
1646 * so the firmware knows. If we're already associated, then use the old
1647 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1648 * branch for disassociation below.
1650 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1651 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1653 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
1655 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1657 /* after sending it once, adopt mac80211 data */
1658 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1659 mvmvif->associated = bss_conf->assoc;
1661 if (changes & BSS_CHANGED_ASSOC) {
1662 if (bss_conf->assoc) {
1663 /* add quota for this interface */
1664 ret = iwl_mvm_update_quotas(mvm, NULL);
1666 IWL_ERR(mvm, "failed to update quotas\n");
1670 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1673 * If we're restarting then the firmware will
1674 * obviously have lost synchronisation with
1675 * the AP. It will attempt to synchronise by
1676 * itself, but we can make it more reliable by
1677 * scheduling a session protection time event.
1679 * The firmware needs to receive a beacon to
1680 * catch up with synchronisation, use 110% of
1681 * the beacon interval.
1683 * Set a large maximum delay to allow for more
1684 * than a single interface.
1686 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1687 iwl_mvm_protect_session(mvm, vif, dur, dur,
1691 iwl_mvm_sf_update(mvm, vif, false);
1692 iwl_mvm_power_vif_assoc(mvm, vif);
1694 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
1695 iwl_mvm_update_smps(mvm, vif,
1696 IWL_MVM_SMPS_REQ_PROT,
1697 IEEE80211_SMPS_DYNAMIC);
1699 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1701 * If update fails - SF might be running in associated
1702 * mode while disassociated - which is forbidden.
1704 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1705 "Failed to update SF upon disassociation\n");
1707 /* remove AP station now that the MAC is unassoc */
1708 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1710 IWL_ERR(mvm, "failed to remove AP station\n");
1712 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1713 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1714 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1715 /* remove quota for this interface */
1716 ret = iwl_mvm_update_quotas(mvm, NULL);
1718 IWL_ERR(mvm, "failed to update quotas\n");
1721 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
1723 /* this will take the cleared BSSID from bss_conf */
1724 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1727 "failed to update MAC %pM (clear after unassoc)\n",
1731 iwl_mvm_recalc_multicast(mvm);
1732 iwl_mvm_configure_bcast_filter(mvm, vif);
1734 /* reset rssi values */
1735 mvmvif->bf_data.ave_beacon_signal = 0;
1737 iwl_mvm_bt_coex_vif_change(mvm);
1738 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1739 IEEE80211_SMPS_AUTOMATIC);
1740 } else if (changes & BSS_CHANGED_BEACON_INFO) {
1742 * We received a beacon _after_ association so
1743 * remove the session protection.
1745 iwl_mvm_remove_time_event(mvm, mvmvif,
1746 &mvmvif->time_event_data);
1749 if (changes & BSS_CHANGED_BEACON_INFO) {
1750 iwl_mvm_sf_update(mvm, vif, false);
1751 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1754 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS)) {
1755 ret = iwl_mvm_power_update_mac(mvm);
1757 IWL_ERR(mvm, "failed to update power mode\n");
1760 if (changes & BSS_CHANGED_TXPOWER) {
1761 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1763 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1766 if (changes & BSS_CHANGED_CQM) {
1767 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
1768 /* reset cqm events tracking */
1769 mvmvif->bf_data.last_cqm_event = 0;
1770 if (mvmvif->bf_data.bf_enabled) {
1771 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1774 "failed to update CQM thresholds\n");
1778 if (changes & BSS_CHANGED_ARP_FILTER) {
1779 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
1780 iwl_mvm_configure_bcast_filter(mvm, vif);
1784 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1785 struct ieee80211_vif *vif)
1787 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1788 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1792 * iwl_mvm_mac_ctxt_add() might read directly from the device
1793 * (the system time), so make sure it is available.
1795 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
1799 mutex_lock(&mvm->mutex);
1801 /* Send the beacon template */
1802 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1807 * Re-calculate the tsf id, as the master-slave relations depend on the
1808 * beacon interval, which was not known when the AP interface was added.
1810 if (vif->type == NL80211_IFTYPE_AP)
1811 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1813 /* Add the mac context */
1814 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1818 /* Perform the binding */
1819 ret = iwl_mvm_binding_add_vif(mvm, vif);
1823 /* Send the bcast station. At this stage the TBTT and DTIM time events
1824 * are added and applied to the scheduler */
1825 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
1829 /* must be set before quota calculations */
1830 mvmvif->ap_ibss_active = true;
1832 /* power updated needs to be done before quotas */
1833 iwl_mvm_power_update_mac(mvm);
1835 ret = iwl_mvm_update_quotas(mvm, NULL);
1837 goto out_quota_failed;
1839 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1840 if (vif->p2p && mvm->p2p_device_vif)
1841 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
1843 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1845 iwl_mvm_bt_coex_vif_change(mvm);
1847 /* we don't support TDLS during DCM */
1848 if (iwl_mvm_phy_ctx_count(mvm) > 1)
1849 iwl_mvm_teardown_tdls_peers(mvm);
1851 mutex_unlock(&mvm->mutex);
1855 iwl_mvm_power_update_mac(mvm);
1856 mvmvif->ap_ibss_active = false;
1857 iwl_mvm_send_rm_bcast_sta(mvm, vif);
1859 iwl_mvm_binding_remove_vif(mvm, vif);
1861 iwl_mvm_mac_ctxt_remove(mvm, vif);
1863 mutex_unlock(&mvm->mutex);
1864 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
1868 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1869 struct ieee80211_vif *vif)
1871 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1872 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1874 iwl_mvm_prepare_mac_removal(mvm, vif);
1876 mutex_lock(&mvm->mutex);
1878 /* Handle AP stop while in CSA */
1879 if (rcu_access_pointer(mvm->csa_vif) == vif) {
1880 iwl_mvm_remove_time_event(mvm, mvmvif,
1881 &mvmvif->time_event_data);
1882 RCU_INIT_POINTER(mvm->csa_vif, NULL);
1885 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
1886 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
1887 mvm->csa_tx_block_bcn_timeout = 0;
1890 mvmvif->ap_ibss_active = false;
1891 mvm->ap_last_beacon_gp2 = 0;
1893 iwl_mvm_bt_coex_vif_change(mvm);
1895 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
1897 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1898 if (vif->p2p && mvm->p2p_device_vif)
1899 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
1901 iwl_mvm_update_quotas(mvm, NULL);
1902 iwl_mvm_send_rm_bcast_sta(mvm, vif);
1903 iwl_mvm_binding_remove_vif(mvm, vif);
1905 iwl_mvm_power_update_mac(mvm);
1907 iwl_mvm_mac_ctxt_remove(mvm, vif);
1909 mutex_unlock(&mvm->mutex);
1913 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1914 struct ieee80211_vif *vif,
1915 struct ieee80211_bss_conf *bss_conf,
1918 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1920 /* Changes will be applied when the AP/IBSS is started */
1921 if (!mvmvif->ap_ibss_active)
1924 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
1925 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
1926 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
1927 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1929 /* Need to send a new beacon template to the FW */
1930 if (changes & BSS_CHANGED_BEACON &&
1931 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1932 IWL_WARN(mvm, "Failed updating beacon data\n");
1934 if (changes & BSS_CHANGED_TXPOWER) {
1935 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1937 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1942 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1943 struct ieee80211_vif *vif,
1944 struct ieee80211_bss_conf *bss_conf,
1947 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1950 * iwl_mvm_bss_info_changed_station() might call
1951 * iwl_mvm_protect_session(), which reads directly from
1952 * the device (the system time), so make sure it is available.
1954 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
1957 mutex_lock(&mvm->mutex);
1959 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
1960 iwl_mvm_scan_offload_stop(mvm, true);
1962 switch (vif->type) {
1963 case NL80211_IFTYPE_STATION:
1964 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1966 case NL80211_IFTYPE_AP:
1967 case NL80211_IFTYPE_ADHOC:
1968 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
1971 /* shouldn't happen */
1975 mutex_unlock(&mvm->mutex);
1976 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
1979 static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm,
1980 enum iwl_scan_status scan_type)
1983 bool wait_for_handlers = false;
1985 mutex_lock(&mvm->mutex);
1987 if (mvm->scan_status != scan_type) {
1989 /* make sure there are no pending notifications */
1990 wait_for_handlers = true;
1994 switch (scan_type) {
1995 case IWL_MVM_SCAN_SCHED:
1996 ret = iwl_mvm_scan_offload_stop(mvm, true);
1998 case IWL_MVM_SCAN_OS:
1999 ret = iwl_mvm_cancel_scan(mvm);
2001 case IWL_MVM_SCAN_NONE:
2010 wait_for_handlers = true;
2012 mutex_unlock(&mvm->mutex);
2014 /* make sure we consume the completion notification */
2015 if (wait_for_handlers)
2016 iwl_mvm_wait_for_async_handlers(mvm);
2020 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2021 struct ieee80211_vif *vif,
2022 struct ieee80211_scan_request *hw_req)
2024 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2025 struct cfg80211_scan_request *req = &hw_req->req;
2028 if (req->n_channels == 0 ||
2029 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
2032 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2033 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_SCHED);
2038 mutex_lock(&mvm->mutex);
2040 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
2045 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
2047 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
2048 ret = iwl_mvm_scan_umac(mvm, vif, hw_req);
2049 else if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
2050 ret = iwl_mvm_unified_scan_lmac(mvm, vif, hw_req);
2052 ret = iwl_mvm_scan_request(mvm, vif, req);
2055 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
2057 mutex_unlock(&mvm->mutex);
2061 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2062 struct ieee80211_vif *vif)
2064 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2066 mutex_lock(&mvm->mutex);
2068 iwl_mvm_cancel_scan(mvm);
2070 mutex_unlock(&mvm->mutex);
2074 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2075 struct ieee80211_sta *sta, u16 tids,
2077 enum ieee80211_frame_release_type reason,
2080 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2082 /* Called when we need to transmit (a) frame(s) from mac80211 */
2084 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2085 tids, more_data, false);
2089 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2090 struct ieee80211_sta *sta, u16 tids,
2092 enum ieee80211_frame_release_type reason,
2095 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2097 /* Called when we need to transmit (a) frame(s) from agg queue */
2099 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2100 tids, more_data, true);
2103 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2104 struct ieee80211_vif *vif,
2105 enum sta_notify_cmd cmd,
2106 struct ieee80211_sta *sta)
2108 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2109 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2113 case STA_NOTIFY_SLEEP:
2114 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
2115 ieee80211_sta_block_awake(hw, sta, true);
2116 spin_lock_bh(&mvmsta->lock);
2117 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2118 struct iwl_mvm_tid_data *tid_data;
2120 tid_data = &mvmsta->tid_data[tid];
2121 if (tid_data->state != IWL_AGG_ON &&
2122 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
2124 if (iwl_mvm_tid_queued(tid_data) == 0)
2126 ieee80211_sta_set_buffered(sta, tid, true);
2128 spin_unlock_bh(&mvmsta->lock);
2130 * The fw updates the STA to be asleep. Tx packets on the Tx
2131 * queues to this station will not be transmitted. The fw will
2132 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2135 case STA_NOTIFY_AWAKE:
2136 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
2138 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2145 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2146 struct ieee80211_vif *vif,
2147 struct ieee80211_sta *sta)
2149 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2150 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2153 * This is called before mac80211 does RCU synchronisation,
2154 * so here we already invalidate our internal RCU-protected
2155 * station pointer. The rest of the code will thus no longer
2156 * be able to find the station this way, and we don't rely
2157 * on further RCU synchronisation after the sta_state()
2158 * callback deleted the station.
2160 mutex_lock(&mvm->mutex);
2161 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2162 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2164 mutex_unlock(&mvm->mutex);
2167 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2168 struct ieee80211_vif *vif,
2169 struct ieee80211_sta *sta,
2170 enum ieee80211_sta_state old_state,
2171 enum ieee80211_sta_state new_state)
2173 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2174 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2177 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2178 sta->addr, old_state, new_state);
2180 /* this would be a mac80211 bug ... but don't crash */
2181 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2184 /* if a STA is being removed, reuse its ID */
2185 flush_work(&mvm->sta_drained_wk);
2187 mutex_lock(&mvm->mutex);
2188 if (old_state == IEEE80211_STA_NOTEXIST &&
2189 new_state == IEEE80211_STA_NONE) {
2191 * Firmware bug - it'll crash if the beacon interval is less
2192 * than 16. We can't avoid connecting at all, so refuse the
2193 * station state change, this will cause mac80211 to abandon
2194 * attempts to connect to this AP, and eventually wpa_s will
2195 * blacklist the AP...
2197 if (vif->type == NL80211_IFTYPE_STATION &&
2198 vif->bss_conf.beacon_int < 16) {
2200 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2201 sta->addr, vif->bss_conf.beacon_int);
2208 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2209 IWL_MVM_TDLS_STA_COUNT ||
2210 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2211 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2216 ret = iwl_mvm_add_sta(mvm, vif, sta);
2217 if (sta->tdls && ret == 0)
2218 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2219 } else if (old_state == IEEE80211_STA_NONE &&
2220 new_state == IEEE80211_STA_AUTH) {
2222 * EBS may be disabled due to previous failures reported by FW.
2223 * Reset EBS status here assuming environment has been changed.
2225 mvm->last_ebs_successful = true;
2227 } else if (old_state == IEEE80211_STA_AUTH &&
2228 new_state == IEEE80211_STA_ASSOC) {
2229 ret = iwl_mvm_update_sta(mvm, vif, sta);
2231 iwl_mvm_rs_rate_init(mvm, sta,
2232 mvmvif->phy_ctxt->channel->band,
2234 } else if (old_state == IEEE80211_STA_ASSOC &&
2235 new_state == IEEE80211_STA_AUTHORIZED) {
2237 /* we don't support TDLS during DCM */
2238 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2239 iwl_mvm_teardown_tdls_peers(mvm);
2241 /* enable beacon filtering */
2242 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2244 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2245 new_state == IEEE80211_STA_ASSOC) {
2246 /* disable beacon filtering */
2247 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2249 } else if (old_state == IEEE80211_STA_ASSOC &&
2250 new_state == IEEE80211_STA_AUTH) {
2252 } else if (old_state == IEEE80211_STA_AUTH &&
2253 new_state == IEEE80211_STA_NONE) {
2255 } else if (old_state == IEEE80211_STA_NONE &&
2256 new_state == IEEE80211_STA_NOTEXIST) {
2257 ret = iwl_mvm_rm_sta(mvm, vif, sta);
2259 iwl_mvm_recalc_tdls_state(mvm, vif, false);
2264 mutex_unlock(&mvm->mutex);
2266 if (sta->tdls && ret == 0) {
2267 if (old_state == IEEE80211_STA_NOTEXIST &&
2268 new_state == IEEE80211_STA_NONE)
2269 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2270 else if (old_state == IEEE80211_STA_NONE &&
2271 new_state == IEEE80211_STA_NOTEXIST)
2272 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2278 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2280 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2282 mvm->rts_threshold = value;
2287 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2288 struct ieee80211_vif *vif,
2289 struct ieee80211_sta *sta, u32 changed)
2291 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2293 if (vif->type == NL80211_IFTYPE_STATION &&
2294 changed & IEEE80211_RC_NSS_CHANGED)
2295 iwl_mvm_sf_update(mvm, vif, false);
2298 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2299 struct ieee80211_vif *vif, u16 ac,
2300 const struct ieee80211_tx_queue_params *params)
2302 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2303 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2305 mvmvif->queue_params[ac] = *params;
2308 * No need to update right away, we'll get BSS_CHANGED_QOS
2309 * The exception is P2P_DEVICE interface which needs immediate update.
2311 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2314 mutex_lock(&mvm->mutex);
2315 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2316 mutex_unlock(&mvm->mutex);
2322 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2323 struct ieee80211_vif *vif)
2325 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2326 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
2327 200 + vif->bss_conf.beacon_int);
2328 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
2329 100 + vif->bss_conf.beacon_int);
2331 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2335 * iwl_mvm_protect_session() reads directly from the device
2336 * (the system time), so make sure it is available.
2338 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2341 mutex_lock(&mvm->mutex);
2342 /* Try really hard to protect the session and hear a beacon */
2343 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
2344 mutex_unlock(&mvm->mutex);
2346 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
2349 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2350 struct ieee80211_vif *vif,
2351 struct cfg80211_sched_scan_request *req,
2352 struct ieee80211_scan_ies *ies)
2354 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2357 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2358 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS);
2363 mutex_lock(&mvm->mutex);
2365 /* Newest FW fixes sched scan while connected on another interface */
2366 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) {
2367 if (!vif->bss_conf.idle) {
2371 } else if (!iwl_mvm_is_idle(mvm)) {
2376 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
2381 ret = iwl_mvm_scan_offload_start(mvm, vif, req, ies);
2383 mvm->scan_status = IWL_MVM_SCAN_NONE;
2386 mutex_unlock(&mvm->mutex);
2390 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2391 struct ieee80211_vif *vif)
2393 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2396 mutex_lock(&mvm->mutex);
2397 ret = iwl_mvm_scan_offload_stop(mvm, false);
2398 mutex_unlock(&mvm->mutex);
2399 iwl_mvm_wait_for_async_handlers(mvm);
2405 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2406 enum set_key_cmd cmd,
2407 struct ieee80211_vif *vif,
2408 struct ieee80211_sta *sta,
2409 struct ieee80211_key_conf *key)
2411 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2414 if (iwlwifi_mod_params.sw_crypto) {
2415 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2419 switch (key->cipher) {
2420 case WLAN_CIPHER_SUITE_TKIP:
2421 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2423 case WLAN_CIPHER_SUITE_CCMP:
2424 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2426 case WLAN_CIPHER_SUITE_AES_CMAC:
2427 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
2429 case WLAN_CIPHER_SUITE_WEP40:
2430 case WLAN_CIPHER_SUITE_WEP104:
2431 /* For non-client mode, only use WEP keys for TX as we probably
2432 * don't have a station yet anyway and would then have to keep
2433 * track of the keys, linking them to each of the clients/peers
2434 * as they appear. For now, don't do that, for performance WEP
2435 * offload doesn't really matter much, but we need it for some
2436 * other offload features in client mode.
2438 if (vif->type != NL80211_IFTYPE_STATION)
2442 /* currently FW supports only one optional cipher scheme */
2443 if (hw->n_cipher_schemes &&
2444 hw->cipher_schemes->cipher == key->cipher)
2445 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2450 mutex_lock(&mvm->mutex);
2454 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2455 vif->type == NL80211_IFTYPE_AP) && !sta) {
2457 * GTK on AP interface is a TX-only key, return 0;
2458 * on IBSS they're per-station and because we're lazy
2459 * we don't support them for RX, so do the same.
2462 key->hw_key_idx = STA_KEY_IDX_INVALID;
2466 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2467 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
2469 IWL_WARN(mvm, "set key failed\n");
2471 * can't add key for RX, but we don't need it
2472 * in the device for TX so still return 0
2474 key->hw_key_idx = STA_KEY_IDX_INVALID;
2480 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2485 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2486 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2492 mutex_unlock(&mvm->mutex);
2496 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2497 struct ieee80211_vif *vif,
2498 struct ieee80211_key_conf *keyconf,
2499 struct ieee80211_sta *sta,
2500 u32 iv32, u16 *phase1key)
2502 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2504 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2507 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2511 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
2512 struct iwl_rx_packet *pkt, void *data)
2514 struct iwl_mvm *mvm =
2515 container_of(notif_wait, struct iwl_mvm, notif_wait);
2516 struct iwl_hs20_roc_res *resp;
2517 int resp_len = iwl_rx_packet_payload_len(pkt);
2518 struct iwl_mvm_time_event_data *te_data = data;
2520 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
2523 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
2524 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
2528 resp = (void *)pkt->data;
2531 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
2532 resp->status, resp->event_unique_id);
2534 te_data->uid = le32_to_cpu(resp->event_unique_id);
2535 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
2538 spin_lock_bh(&mvm->time_event_lock);
2539 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
2540 spin_unlock_bh(&mvm->time_event_lock);
2545 #define AUX_ROC_MAX_DELAY_ON_CHANNEL 5000
2546 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
2547 struct ieee80211_channel *channel,
2548 struct ieee80211_vif *vif,
2551 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
2552 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2553 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
2554 static const u8 time_event_response[] = { HOT_SPOT_CMD };
2555 struct iwl_notification_wait wait_time_event;
2556 struct iwl_hs20_roc_req aux_roc_req = {
2557 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
2559 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
2560 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
2561 /* Set the channel info data */
2562 .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
2563 PHY_BAND_24 : PHY_BAND_5,
2564 .channel_info.channel = channel->hw_value,
2565 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
2566 /* Set the time and duration */
2567 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
2568 .apply_time_max_delay =
2569 cpu_to_le32(MSEC_TO_TU(AUX_ROC_MAX_DELAY_ON_CHANNEL)),
2570 .duration = cpu_to_le32(MSEC_TO_TU(duration)),
2573 /* Set the node address */
2574 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
2576 lockdep_assert_held(&mvm->mutex);
2578 spin_lock_bh(&mvm->time_event_lock);
2580 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
2581 spin_unlock_bh(&mvm->time_event_lock);
2586 te_data->duration = duration;
2587 te_data->id = HOT_SPOT_CMD;
2589 spin_unlock_bh(&mvm->time_event_lock);
2592 * Use a notification wait, which really just processes the
2593 * command response and doesn't wait for anything, in order
2594 * to be able to process the response and get the UID inside
2595 * the RX path. Using CMD_WANT_SKB doesn't work because it
2596 * stores the buffer and then wakes up this thread, by which
2597 * time another notification (that the time event started)
2598 * might already be processed unsuccessfully.
2600 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
2601 time_event_response,
2602 ARRAY_SIZE(time_event_response),
2603 iwl_mvm_rx_aux_roc, te_data);
2605 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
2609 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
2610 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
2614 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
2615 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
2616 /* should never fail */
2621 spin_lock_bh(&mvm->time_event_lock);
2622 iwl_mvm_te_clear_data(mvm, te_data);
2623 spin_unlock_bh(&mvm->time_event_lock);
2629 static int iwl_mvm_roc(struct ieee80211_hw *hw,
2630 struct ieee80211_vif *vif,
2631 struct ieee80211_channel *channel,
2633 enum ieee80211_roc_type type)
2635 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2636 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2637 struct cfg80211_chan_def chandef;
2638 struct iwl_mvm_phy_ctxt *phy_ctxt;
2641 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2644 mutex_lock(&mvm->mutex);
2646 switch (vif->type) {
2647 case NL80211_IFTYPE_STATION:
2648 if (mvm->fw->ucode_capa.capa[0] &
2649 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT) {
2650 /* Use aux roc framework (HS20) */
2651 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
2655 IWL_ERR(mvm, "hotspot not supported\n");
2658 case NL80211_IFTYPE_P2P_DEVICE:
2662 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
2667 for (i = 0; i < NUM_PHY_CTX; i++) {
2668 phy_ctxt = &mvm->phy_ctxts[i];
2669 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2672 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2674 * Unbind the P2P_DEVICE from the current PHY context,
2675 * and if the PHY context is not used remove it.
2677 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2678 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2681 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2683 /* Bind the P2P_DEVICE to the current PHY Context */
2684 mvmvif->phy_ctxt = phy_ctxt;
2686 ret = iwl_mvm_binding_add_vif(mvm, vif);
2687 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2690 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2691 goto schedule_time_event;
2695 /* Need to update the PHY context only if the ROC channel changed */
2696 if (channel == mvmvif->phy_ctxt->channel)
2697 goto schedule_time_event;
2699 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2702 * Change the PHY context configuration as it is currently referenced
2703 * only by the P2P Device MAC
2705 if (mvmvif->phy_ctxt->ref == 1) {
2706 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2712 * The PHY context is shared with other MACs. Need to remove the
2713 * P2P Device from the binding, allocate an new PHY context and
2714 * create a new binding
2716 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2722 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2725 IWL_ERR(mvm, "Failed to change PHY context\n");
2729 /* Unbind the P2P_DEVICE from the current PHY context */
2730 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2731 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2734 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2736 /* Bind the P2P_DEVICE to the new allocated PHY context */
2737 mvmvif->phy_ctxt = phy_ctxt;
2739 ret = iwl_mvm_binding_add_vif(mvm, vif);
2740 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2743 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2746 schedule_time_event:
2747 /* Schedule the time events */
2748 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
2751 mutex_unlock(&mvm->mutex);
2752 IWL_DEBUG_MAC80211(mvm, "leave\n");
2756 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2758 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2760 IWL_DEBUG_MAC80211(mvm, "enter\n");
2762 mutex_lock(&mvm->mutex);
2763 iwl_mvm_stop_roc(mvm);
2764 mutex_unlock(&mvm->mutex);
2766 IWL_DEBUG_MAC80211(mvm, "leave\n");
2770 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
2771 struct ieee80211_chanctx_conf *ctx)
2773 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2774 struct iwl_mvm_phy_ctxt *phy_ctxt;
2777 lockdep_assert_held(&mvm->mutex);
2779 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
2781 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2787 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
2788 ctx->rx_chains_static,
2789 ctx->rx_chains_dynamic);
2791 IWL_ERR(mvm, "Failed to add PHY context\n");
2795 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
2796 *phy_ctxt_id = phy_ctxt->id;
2801 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2802 struct ieee80211_chanctx_conf *ctx)
2804 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2807 mutex_lock(&mvm->mutex);
2808 ret = __iwl_mvm_add_chanctx(mvm, ctx);
2809 mutex_unlock(&mvm->mutex);
2814 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
2815 struct ieee80211_chanctx_conf *ctx)
2817 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2818 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2820 lockdep_assert_held(&mvm->mutex);
2822 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
2825 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2826 struct ieee80211_chanctx_conf *ctx)
2828 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2830 mutex_lock(&mvm->mutex);
2831 __iwl_mvm_remove_chanctx(mvm, ctx);
2832 mutex_unlock(&mvm->mutex);
2835 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2836 struct ieee80211_chanctx_conf *ctx,
2839 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2840 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2841 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2843 if (WARN_ONCE((phy_ctxt->ref > 1) &&
2844 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
2845 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
2846 IEEE80211_CHANCTX_CHANGE_RADAR |
2847 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
2848 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2849 phy_ctxt->ref, changed))
2852 mutex_lock(&mvm->mutex);
2853 iwl_mvm_bt_coex_vif_change(mvm);
2854 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
2855 ctx->rx_chains_static,
2856 ctx->rx_chains_dynamic);
2857 mutex_unlock(&mvm->mutex);
2860 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
2861 struct ieee80211_vif *vif,
2862 struct ieee80211_chanctx_conf *ctx,
2863 bool switching_chanctx)
2865 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2866 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2867 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2870 lockdep_assert_held(&mvm->mutex);
2872 mvmvif->phy_ctxt = phy_ctxt;
2874 switch (vif->type) {
2875 case NL80211_IFTYPE_AP:
2876 /* only needed if we're switching chanctx (i.e. during CSA) */
2877 if (switching_chanctx) {
2878 mvmvif->ap_ibss_active = true;
2881 case NL80211_IFTYPE_ADHOC:
2883 * The AP binding flow is handled as part of the start_ap flow
2884 * (in bss_info_changed), similarly for IBSS.
2888 case NL80211_IFTYPE_STATION:
2890 case NL80211_IFTYPE_MONITOR:
2891 /* always disable PS when a monitor interface is active */
2892 mvmvif->ps_disabled = true;
2899 ret = iwl_mvm_binding_add_vif(mvm, vif);
2904 * Power state must be updated before quotas,
2905 * otherwise fw will complain.
2907 iwl_mvm_power_update_mac(mvm);
2909 /* Setting the quota at this stage is only required for monitor
2910 * interfaces. For the other types, the bss_info changed flow
2911 * will handle quota settings.
2913 if (vif->type == NL80211_IFTYPE_MONITOR) {
2914 mvmvif->monitor_active = true;
2915 ret = iwl_mvm_update_quotas(mvm, NULL);
2917 goto out_remove_binding;
2920 /* Handle binding during CSA */
2921 if (vif->type == NL80211_IFTYPE_AP) {
2922 iwl_mvm_update_quotas(mvm, NULL);
2923 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2926 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
2927 u32 duration = 2 * vif->bss_conf.beacon_int;
2929 /* iwl_mvm_protect_session() reads directly from the
2930 * device (the system time), so make sure it is
2933 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
2935 goto out_remove_binding;
2937 /* Protect the session to make sure we hear the first
2938 * beacon on the new channel.
2940 iwl_mvm_protect_session(mvm, vif, duration, duration,
2941 vif->bss_conf.beacon_int / 2,
2944 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
2946 iwl_mvm_update_quotas(mvm, NULL);
2952 iwl_mvm_binding_remove_vif(mvm, vif);
2953 iwl_mvm_power_update_mac(mvm);
2956 mvmvif->phy_ctxt = NULL;
2959 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
2960 struct ieee80211_vif *vif,
2961 struct ieee80211_chanctx_conf *ctx)
2963 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2966 mutex_lock(&mvm->mutex);
2967 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
2968 mutex_unlock(&mvm->mutex);
2973 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
2974 struct ieee80211_vif *vif,
2975 struct ieee80211_chanctx_conf *ctx,
2976 bool switching_chanctx)
2978 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2979 struct ieee80211_vif *disabled_vif = NULL;
2981 lockdep_assert_held(&mvm->mutex);
2983 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
2985 switch (vif->type) {
2986 case NL80211_IFTYPE_ADHOC:
2988 case NL80211_IFTYPE_MONITOR:
2989 mvmvif->monitor_active = false;
2990 mvmvif->ps_disabled = false;
2992 case NL80211_IFTYPE_AP:
2993 /* This part is triggered only during CSA */
2994 if (!switching_chanctx || !mvmvif->ap_ibss_active)
2997 mvmvif->csa_countdown = false;
2999 /* Set CS bit on all the stations */
3000 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3002 /* Save blocked iface, the timeout is set on the next beacon */
3003 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3005 mvmvif->ap_ibss_active = false;
3007 case NL80211_IFTYPE_STATION:
3008 if (!switching_chanctx)
3013 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3019 iwl_mvm_update_quotas(mvm, disabled_vif);
3020 iwl_mvm_binding_remove_vif(mvm, vif);
3023 mvmvif->phy_ctxt = NULL;
3024 iwl_mvm_power_update_mac(mvm);
3027 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3028 struct ieee80211_vif *vif,
3029 struct ieee80211_chanctx_conf *ctx)
3031 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3033 mutex_lock(&mvm->mutex);
3034 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3035 mutex_unlock(&mvm->mutex);
3039 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3040 struct ieee80211_vif_chanctx_switch *vifs)
3044 mutex_lock(&mvm->mutex);
3045 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3046 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3048 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3050 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3054 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3058 "failed to assign new_ctx during channel switch\n");
3062 /* we don't support TDLS during DCM - can be caused by channel switch */
3063 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3064 iwl_mvm_teardown_tdls_peers(mvm);
3069 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3072 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3073 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3077 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3079 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3086 /* things keep failing, better restart the hw */
3087 iwl_mvm_nic_restart(mvm, false);
3090 mutex_unlock(&mvm->mutex);
3096 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3097 struct ieee80211_vif_chanctx_switch *vifs)
3101 mutex_lock(&mvm->mutex);
3102 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3104 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3108 "failed to assign new_ctx during channel switch\n");
3115 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3117 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3124 /* things keep failing, better restart the hw */
3125 iwl_mvm_nic_restart(mvm, false);
3128 mutex_unlock(&mvm->mutex);
3133 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3134 struct ieee80211_vif_chanctx_switch *vifs,
3136 enum ieee80211_chanctx_switch_mode mode)
3138 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3141 /* we only support a single-vif right now */
3146 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3147 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3149 case CHANCTX_SWMODE_REASSIGN_VIF:
3150 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
3160 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3161 struct ieee80211_sta *sta,
3164 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3165 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3167 if (!mvm_sta || !mvm_sta->vif) {
3168 IWL_ERR(mvm, "Station is not associated to a vif\n");
3172 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3175 #ifdef CONFIG_NL80211_TESTMODE
3176 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3177 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3178 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
3179 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
3182 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3183 struct ieee80211_vif *vif,
3184 void *data, int len)
3186 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3190 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
3194 if (!tb[IWL_MVM_TM_ATTR_CMD])
3197 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3198 case IWL_MVM_TM_CMD_SET_NOA:
3199 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3200 !vif->bss_conf.enable_beacon ||
3201 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3204 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3205 if (noa_duration >= vif->bss_conf.beacon_int)
3208 mvm->noa_duration = noa_duration;
3211 return iwl_mvm_update_quotas(mvm, NULL);
3212 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3213 /* must be associated client vif - ignore authorized */
3214 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3215 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3216 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3219 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
3220 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3221 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3227 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3228 struct ieee80211_vif *vif,
3229 void *data, int len)
3231 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3234 mutex_lock(&mvm->mutex);
3235 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3236 mutex_unlock(&mvm->mutex);
3242 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3243 struct ieee80211_vif *vif,
3244 struct ieee80211_channel_switch *chsw)
3246 /* By implementing this operation, we prevent mac80211 from
3247 * starting its own channel switch timer, so that we can call
3248 * ieee80211_chswitch_done() ourselves at the right time
3249 * (which is when the absence time event starts).
3252 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3253 "dummy channel switch op\n");
3256 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3257 struct ieee80211_vif *vif,
3258 struct ieee80211_channel_switch *chsw)
3260 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3261 struct ieee80211_vif *csa_vif;
3262 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3266 mutex_lock(&mvm->mutex);
3268 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
3269 chsw->chandef.center_freq1);
3271 switch (vif->type) {
3272 case NL80211_IFTYPE_AP:
3274 rcu_dereference_protected(mvm->csa_vif,
3275 lockdep_is_held(&mvm->mutex));
3276 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3277 "Another CSA is already in progress")) {
3282 rcu_assign_pointer(mvm->csa_vif, vif);
3284 if (WARN_ONCE(mvmvif->csa_countdown,
3285 "Previous CSA countdown didn't complete")) {
3291 case NL80211_IFTYPE_STATION:
3292 /* Schedule the time event to a bit before beacon 1,
3293 * to make sure we're in the new channel when the
3296 apply_time = chsw->device_timestamp +
3297 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3298 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
3301 iwl_mvm_csa_client_absent(mvm, vif);
3303 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
3305 if (mvmvif->bf_data.bf_enabled) {
3306 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3316 mvmvif->ps_disabled = true;
3318 ret = iwl_mvm_power_update_ps(mvm);
3322 /* we won't be on this channel any longer */
3323 iwl_mvm_teardown_tdls_peers(mvm);
3326 mutex_unlock(&mvm->mutex);
3331 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
3332 struct ieee80211_vif *vif)
3334 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3335 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3338 mutex_lock(&mvm->mutex);
3340 if (vif->type == NL80211_IFTYPE_STATION) {
3341 struct iwl_mvm_sta *mvmsta;
3343 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
3346 if (WARN_ON(!mvmsta)) {
3351 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
3353 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3355 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3359 iwl_mvm_stop_session_protection(mvm, vif);
3362 mvmvif->ps_disabled = false;
3364 ret = iwl_mvm_power_update_ps(mvm);
3367 mutex_unlock(&mvm->mutex);
3372 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3373 struct ieee80211_vif *vif, u32 queues, bool drop)
3375 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3376 struct iwl_mvm_vif *mvmvif;
3377 struct iwl_mvm_sta *mvmsta;
3378 struct ieee80211_sta *sta;
3382 if (!vif || vif->type != NL80211_IFTYPE_STATION)
3385 mutex_lock(&mvm->mutex);
3386 mvmvif = iwl_mvm_vif_from_mac80211(vif);
3388 /* flush the AP-station and all TDLS peers */
3389 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
3390 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3391 lockdep_is_held(&mvm->mutex));
3392 if (IS_ERR_OR_NULL(sta))
3395 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3396 if (mvmsta->vif != vif)
3399 /* make sure only TDLS peers or the AP are flushed */
3400 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
3402 msk |= mvmsta->tfd_queue_msk;
3406 if (iwl_mvm_flush_tx_path(mvm, msk, true))
3407 IWL_ERR(mvm, "flush request fail\n");
3408 mutex_unlock(&mvm->mutex);
3410 mutex_unlock(&mvm->mutex);
3412 /* this can take a while, and we may need/want other operations
3413 * to succeed while doing this, so do it without the mutex held
3415 iwl_trans_wait_tx_queue_empty(mvm->trans, msk);
3419 const struct ieee80211_ops iwl_mvm_hw_ops = {
3420 .tx = iwl_mvm_mac_tx,
3421 .ampdu_action = iwl_mvm_mac_ampdu_action,
3422 .start = iwl_mvm_mac_start,
3423 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
3424 .stop = iwl_mvm_mac_stop,
3425 .add_interface = iwl_mvm_mac_add_interface,
3426 .remove_interface = iwl_mvm_mac_remove_interface,
3427 .config = iwl_mvm_mac_config,
3428 .prepare_multicast = iwl_mvm_prepare_multicast,
3429 .configure_filter = iwl_mvm_configure_filter,
3430 .bss_info_changed = iwl_mvm_bss_info_changed,
3431 .hw_scan = iwl_mvm_mac_hw_scan,
3432 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
3433 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
3434 .sta_state = iwl_mvm_mac_sta_state,
3435 .sta_notify = iwl_mvm_mac_sta_notify,
3436 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
3437 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
3438 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
3439 .sta_rc_update = iwl_mvm_sta_rc_update,
3440 .conf_tx = iwl_mvm_mac_conf_tx,
3441 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
3442 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
3443 .flush = iwl_mvm_mac_flush,
3444 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
3445 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
3446 .set_key = iwl_mvm_mac_set_key,
3447 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
3448 .remain_on_channel = iwl_mvm_roc,
3449 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
3450 .add_chanctx = iwl_mvm_add_chanctx,
3451 .remove_chanctx = iwl_mvm_remove_chanctx,
3452 .change_chanctx = iwl_mvm_change_chanctx,
3453 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
3454 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
3455 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
3457 .start_ap = iwl_mvm_start_ap_ibss,
3458 .stop_ap = iwl_mvm_stop_ap_ibss,
3459 .join_ibss = iwl_mvm_start_ap_ibss,
3460 .leave_ibss = iwl_mvm_stop_ap_ibss,
3462 .set_tim = iwl_mvm_set_tim,
3464 .channel_switch = iwl_mvm_channel_switch,
3465 .pre_channel_switch = iwl_mvm_pre_channel_switch,
3466 .post_channel_switch = iwl_mvm_post_channel_switch,
3468 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
3469 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
3470 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
3472 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
3474 #ifdef CONFIG_PM_SLEEP
3476 .suspend = iwl_mvm_suspend,
3477 .resume = iwl_mvm_resume,
3478 .set_wakeup = iwl_mvm_set_wakeup,
3479 .set_rekey_data = iwl_mvm_set_rekey_data,
3480 #if IS_ENABLED(CONFIG_IPV6)
3481 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
3483 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,