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 if ((mvm->fw->ucode_capa.capa[0] &
409 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
410 (mvm->fw->ucode_capa.api[0] &
411 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
412 hw->wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap.cap |=
413 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
416 hw->wiphy->hw_version = mvm->trans->hw_id;
418 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
419 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
421 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
423 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 10) {
424 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
425 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
426 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
427 /* we create the 802.11 header and zero length SSID IE. */
428 hw->wiphy->max_sched_scan_ie_len =
429 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
432 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
433 NL80211_FEATURE_LOW_PRIORITY_SCAN |
434 NL80211_FEATURE_P2P_GO_OPPPS |
435 NL80211_FEATURE_DYNAMIC_SMPS |
436 NL80211_FEATURE_STATIC_SMPS |
437 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
439 if (mvm->fw->ucode_capa.capa[0] &
440 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)
441 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
442 if (mvm->fw->ucode_capa.capa[0] &
443 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)
444 hw->wiphy->features |= NL80211_FEATURE_QUIET;
446 if (mvm->fw->ucode_capa.capa[0] &
447 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)
448 hw->wiphy->features |=
449 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
451 if (mvm->fw->ucode_capa.capa[0] &
452 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)
453 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
455 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
457 /* currently FW API supports only one optional cipher scheme */
458 if (mvm->fw->cs[0].cipher) {
459 mvm->hw->n_cipher_schemes = 1;
460 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
463 #ifdef CONFIG_PM_SLEEP
464 if (iwl_mvm_is_d0i3_supported(mvm) &&
465 device_can_wakeup(mvm->trans->dev)) {
466 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
467 hw->wiphy->wowlan = &mvm->wowlan;
470 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
471 mvm->trans->ops->d3_suspend &&
472 mvm->trans->ops->d3_resume &&
473 device_can_wakeup(mvm->trans->dev)) {
474 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
475 WIPHY_WOWLAN_DISCONNECT |
476 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
477 WIPHY_WOWLAN_RFKILL_RELEASE |
478 WIPHY_WOWLAN_NET_DETECT;
479 if (!iwlwifi_mod_params.sw_crypto)
480 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
481 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
482 WIPHY_WOWLAN_4WAY_HANDSHAKE;
484 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
485 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
486 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
487 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
488 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
489 hw->wiphy->wowlan = &mvm->wowlan;
493 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
494 /* assign default bcast filtering configuration */
495 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
498 ret = iwl_mvm_leds_init(mvm);
502 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_TDLS_SUPPORT) {
503 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
504 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
507 if (mvm->fw->ucode_capa.capa[0] &
508 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH) {
509 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
510 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
513 ret = ieee80211_register_hw(mvm->hw);
515 iwl_mvm_leds_exit(mvm);
520 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
521 struct ieee80211_sta *sta,
524 struct iwl_mvm_sta *mvmsta;
528 * double check the IN_D0I3 flag both before and after
529 * taking the spinlock, in order to prevent taking
530 * the spinlock when not needed.
532 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
535 spin_lock(&mvm->d0i3_tx_lock);
537 * testing the flag again ensures the skb dequeue
538 * loop (on d0i3 exit) hasn't run yet.
540 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
543 mvmsta = iwl_mvm_sta_from_mac80211(sta);
544 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
545 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
548 __skb_queue_tail(&mvm->d0i3_tx, skb);
549 ieee80211_stop_queues(mvm->hw);
552 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
553 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
557 spin_unlock(&mvm->d0i3_tx_lock);
561 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
562 struct ieee80211_tx_control *control,
565 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
566 struct ieee80211_sta *sta = control->sta;
567 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
568 struct ieee80211_hdr *hdr = (void *)skb->data;
570 if (iwl_mvm_is_radio_killed(mvm)) {
571 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
575 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
576 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
577 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
580 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
581 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
582 ieee80211_is_mgmt(hdr->frame_control) &&
583 !ieee80211_is_deauth(hdr->frame_control) &&
584 !ieee80211_is_disassoc(hdr->frame_control) &&
585 !ieee80211_is_action(hdr->frame_control)))
589 if (iwl_mvm_defer_tx(mvm, sta, skb))
591 if (iwl_mvm_tx_skb(mvm, skb, sta))
596 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
600 ieee80211_free_txskb(hw, skb);
603 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
605 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
610 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
612 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
614 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
617 /* enabled by default */
621 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
622 struct ieee80211_vif *vif,
623 enum ieee80211_ampdu_mlme_action action,
624 struct ieee80211_sta *sta, u16 tid,
625 u16 *ssn, u8 buf_size)
627 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
629 bool tx_agg_ref = false;
631 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
632 sta->addr, tid, action);
634 if (!(mvm->nvm_data->sku_cap_11n_enable))
637 /* return from D0i3 before starting a new Tx aggregation */
639 case IEEE80211_AMPDU_TX_START:
640 case IEEE80211_AMPDU_TX_STOP_CONT:
641 case IEEE80211_AMPDU_TX_STOP_FLUSH:
642 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
643 case IEEE80211_AMPDU_TX_OPERATIONAL:
645 * for tx start, wait synchronously until D0i3 exit to
646 * get the correct sequence number for the tid.
647 * additionally, some other ampdu actions use direct
648 * target access, which is not handled automatically
649 * by the trans layer (unlike commands), so wait for
650 * d0i3 exit in these cases as well.
652 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
662 mutex_lock(&mvm->mutex);
665 case IEEE80211_AMPDU_RX_START:
666 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
670 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
672 case IEEE80211_AMPDU_RX_STOP:
673 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
675 case IEEE80211_AMPDU_TX_START:
676 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
680 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
682 case IEEE80211_AMPDU_TX_STOP_CONT:
683 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
685 case IEEE80211_AMPDU_TX_STOP_FLUSH:
686 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
687 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
689 case IEEE80211_AMPDU_TX_OPERATIONAL:
690 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
697 mutex_unlock(&mvm->mutex);
700 * If the tid is marked as started, we won't use it for offloaded
701 * traffic on the next D0i3 entry. It's safe to unref.
704 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
709 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
710 struct ieee80211_vif *vif)
712 struct iwl_mvm *mvm = data;
713 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
715 mvmvif->uploaded = false;
716 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
718 spin_lock_bh(&mvm->time_event_lock);
719 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
720 spin_unlock_bh(&mvm->time_event_lock);
722 mvmvif->phy_ctxt = NULL;
723 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
726 static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
727 const void *data, size_t datalen)
729 const struct iwl_mvm_dump_ptrs *dump_ptrs = data;
731 ssize_t bytes_read_trans;
733 if (offset < dump_ptrs->op_mode_len) {
734 bytes_read = min_t(ssize_t, count,
735 dump_ptrs->op_mode_len - offset);
736 memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset,
738 offset += bytes_read;
747 if (!dump_ptrs->trans_ptr)
750 offset -= dump_ptrs->op_mode_len;
751 bytes_read_trans = min_t(ssize_t, count,
752 dump_ptrs->trans_ptr->len - offset);
753 memcpy(buffer + bytes_read,
754 (u8 *)dump_ptrs->trans_ptr->data + offset,
757 return bytes_read + bytes_read_trans;
760 static void iwl_mvm_free_coredump(const void *data)
762 const struct iwl_mvm_dump_ptrs *fw_error_dump = data;
764 vfree(fw_error_dump->op_mode_ptr);
765 vfree(fw_error_dump->trans_ptr);
766 kfree(fw_error_dump);
769 static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm,
770 struct iwl_fw_error_dump_data **dump_data)
772 struct iwl_fw_error_dump_fifo *fifo_hdr;
778 if (!iwl_trans_grab_nic_access(mvm->trans, false, &flags))
781 /* Pull RXF data from all RXFs */
782 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) {
784 * Keep aside the additional offset that might be needed for
787 u32 offset_diff = RXF_DIFF_FROM_PREV * i;
789 fifo_hdr = (void *)(*dump_data)->data;
790 fifo_data = (void *)fifo_hdr->data;
791 fifo_len = mvm->shared_mem_cfg.rxfifo_size[i];
793 /* No need to try to read the data if the length is 0 */
797 /* Add a TLV for the RXF */
798 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
799 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
801 fifo_hdr->fifo_num = cpu_to_le32(i);
802 fifo_hdr->available_bytes =
803 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
807 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
811 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
814 fifo_hdr->fence_ptr =
815 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
818 fifo_hdr->fence_mode =
819 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
824 iwl_trans_write_prph(mvm->trans,
825 RXF_SET_FENCE_MODE + offset_diff, 0x1);
826 /* Set fence pointer to the same place like WR pointer */
827 iwl_trans_write_prph(mvm->trans,
828 RXF_LD_WR2FENCE + offset_diff, 0x1);
829 /* Set fence offset */
830 iwl_trans_write_prph(mvm->trans,
831 RXF_LD_FENCE_OFFSET_ADDR + offset_diff,
835 fifo_len /= sizeof(u32); /* Size in DWORDS */
836 for (j = 0; j < fifo_len; j++)
837 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
838 RXF_FIFO_RD_FENCE_INC +
840 *dump_data = iwl_fw_error_next_data(*dump_data);
843 /* Pull TXF data from all TXFs */
844 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++) {
845 /* Mark the number of TXF we're pulling now */
846 iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i);
848 fifo_hdr = (void *)(*dump_data)->data;
849 fifo_data = (void *)fifo_hdr->data;
850 fifo_len = mvm->shared_mem_cfg.txfifo_size[i];
852 /* No need to try to read the data if the length is 0 */
856 /* Add a TLV for the FIFO */
857 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF);
858 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
860 fifo_hdr->fifo_num = cpu_to_le32(i);
861 fifo_hdr->available_bytes =
862 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
865 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
868 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
870 fifo_hdr->fence_ptr =
871 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
873 fifo_hdr->fence_mode =
874 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
877 /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */
878 iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR,
881 /* Dummy-read to advance the read pointer to the head */
882 iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA);
885 fifo_len /= sizeof(u32); /* Size in DWORDS */
886 for (j = 0; j < fifo_len; j++)
887 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
888 TXF_READ_MODIFY_DATA);
889 *dump_data = iwl_fw_error_next_data(*dump_data);
892 iwl_trans_release_nic_access(mvm->trans, &flags);
895 void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
897 struct iwl_fw_error_dump_file *dump_file;
898 struct iwl_fw_error_dump_data *dump_data;
899 struct iwl_fw_error_dump_info *dump_info;
900 struct iwl_fw_error_dump_mem *dump_mem;
901 struct iwl_mvm_dump_ptrs *fw_error_dump;
902 u32 sram_len, sram_ofs;
903 u32 file_len, fifo_data_len = 0;
904 u32 smem_len = mvm->cfg->smem_len;
905 u32 sram2_len = mvm->cfg->dccm2_len;
907 lockdep_assert_held(&mvm->mutex);
909 /* W/A for 8000 HW family A-step */
910 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
911 CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_A_STEP) {
919 fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
923 /* SRAM - include stack CCM if driver knows the values for it */
924 if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
925 const struct fw_img *img;
927 img = &mvm->fw->img[mvm->cur_ucode];
928 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
929 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
931 sram_ofs = mvm->cfg->dccm_offset;
932 sram_len = mvm->cfg->dccm_len;
935 /* reading RXF/TXF sizes */
936 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
937 struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->shared_mem_cfg;
943 for (i = 0; i < ARRAY_SIZE(mem_cfg->rxfifo_size); i++) {
944 if (!mem_cfg->rxfifo_size[i])
947 /* Add header info */
948 fifo_data_len += mem_cfg->rxfifo_size[i] +
950 sizeof(struct iwl_fw_error_dump_fifo);
953 for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) {
954 if (!mem_cfg->txfifo_size[i])
957 /* Add header info */
958 fifo_data_len += mem_cfg->txfifo_size[i] +
960 sizeof(struct iwl_fw_error_dump_fifo);
964 file_len = sizeof(*dump_file) +
965 sizeof(*dump_data) * 2 +
966 sram_len + sizeof(*dump_mem) +
970 /* Make room for the SMEM, if it exists */
972 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
974 /* Make room for the secondary SRAM, if it exists */
976 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
978 dump_file = vzalloc(file_len);
980 kfree(fw_error_dump);
984 fw_error_dump->op_mode_ptr = dump_file;
986 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
987 dump_data = (void *)dump_file->data;
989 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
990 dump_data->len = cpu_to_le32(sizeof(*dump_info));
991 dump_info = (void *) dump_data->data;
992 dump_info->device_family =
993 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
994 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
995 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
996 dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
997 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
998 sizeof(dump_info->fw_human_readable));
999 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
1000 sizeof(dump_info->dev_human_readable));
1001 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
1002 sizeof(dump_info->bus_human_readable));
1004 dump_data = iwl_fw_error_next_data(dump_data);
1005 /* We only dump the FIFOs if the FW is in error state */
1006 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status))
1007 iwl_mvm_dump_fifos(mvm, &dump_data);
1009 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1010 dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
1011 dump_mem = (void *)dump_data->data;
1012 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1013 dump_mem->offset = cpu_to_le32(sram_ofs);
1014 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
1018 dump_data = iwl_fw_error_next_data(dump_data);
1019 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1020 dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
1021 dump_mem = (void *)dump_data->data;
1022 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
1023 dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
1024 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
1025 dump_mem->data, smem_len);
1029 dump_data = iwl_fw_error_next_data(dump_data);
1030 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1031 dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
1032 dump_mem = (void *)dump_data->data;
1033 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1034 dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
1035 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
1036 dump_mem->data, sram2_len);
1039 fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans);
1040 fw_error_dump->op_mode_len = file_len;
1041 if (fw_error_dump->trans_ptr)
1042 file_len += fw_error_dump->trans_ptr->len;
1043 dump_file->file_len = cpu_to_le32(file_len);
1045 dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
1046 GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
1049 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1051 /* clear the D3 reconfig, we only need it to avoid dumping a
1052 * firmware coredump on reconfiguration, we shouldn't do that
1053 * on D3->D0 transition
1055 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status))
1056 iwl_mvm_fw_error_dump(mvm);
1058 /* cleanup all stale references (scan, roc), but keep the
1059 * ucode_down ref until reconfig is complete
1061 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1063 iwl_trans_stop_device(mvm->trans);
1065 mvm->scan_status = IWL_MVM_SCAN_NONE;
1066 mvm->ps_disabled = false;
1067 mvm->calibrating = false;
1069 /* just in case one was running */
1070 ieee80211_remain_on_channel_expired(mvm->hw);
1072 ieee80211_iterate_active_interfaces_atomic(
1073 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1074 iwl_mvm_cleanup_iterator, mvm);
1076 mvm->p2p_device_vif = NULL;
1077 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1079 iwl_mvm_reset_phy_ctxts(mvm);
1080 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1081 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
1082 memset(mvm->tfd_drained, 0, sizeof(mvm->tfd_drained));
1083 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1084 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
1085 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1086 memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
1087 memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk));
1088 memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk));
1090 ieee80211_wake_queues(mvm->hw);
1092 /* clear any stale d0i3 state */
1093 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1096 mvm->rx_ba_sessions = 0;
1099 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1103 lockdep_assert_held(&mvm->mutex);
1105 /* Clean up some internal and mac80211 state on restart */
1106 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1107 iwl_mvm_restart_cleanup(mvm);
1109 ret = iwl_mvm_up(mvm);
1111 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1112 /* Something went wrong - we need to finish some cleanup
1113 * that normally iwl_mvm_mac_restart_complete() below
1116 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1117 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1123 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1125 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1128 /* Some hw restart cleanups must not hold the mutex */
1129 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1131 * Make sure we are out of d0i3. This is needed
1132 * to make sure the reference accounting is correct
1133 * (and there is no stale d0i3_exit_work).
1135 wait_event_timeout(mvm->d0i3_exit_waitq,
1136 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1141 mutex_lock(&mvm->mutex);
1142 ret = __iwl_mvm_mac_start(mvm);
1143 mutex_unlock(&mvm->mutex);
1148 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1152 mutex_lock(&mvm->mutex);
1154 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1155 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1156 ret = iwl_mvm_update_quotas(mvm, NULL);
1158 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1161 /* allow transport/FW low power modes */
1162 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1165 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1166 * of packets the FW sent out, so we must reconnect.
1168 iwl_mvm_teardown_tdls_peers(mvm);
1170 mutex_unlock(&mvm->mutex);
1173 static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1177 if (!iwl_mvm_is_d0i3_supported(mvm))
1180 mutex_lock(&mvm->d0i3_suspend_mutex);
1181 __clear_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags);
1182 exit_now = __test_and_clear_bit(D0I3_PENDING_WAKEUP,
1183 &mvm->d0i3_suspend_flags);
1184 mutex_unlock(&mvm->d0i3_suspend_mutex);
1187 IWL_DEBUG_RPM(mvm, "Run deferred d0i3 exit\n");
1188 _iwl_mvm_exit_d0i3(mvm);
1191 if (mvm->trans->d0i3_mode == IWL_D0I3_MODE_ON_SUSPEND)
1192 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
1193 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1196 WARN_ONCE(1, "D0i3 exit on resume timed out\n");
1200 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1201 enum ieee80211_reconfig_type reconfig_type)
1203 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1205 switch (reconfig_type) {
1206 case IEEE80211_RECONFIG_TYPE_RESTART:
1207 iwl_mvm_restart_complete(mvm);
1209 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1210 iwl_mvm_resume_complete(mvm);
1215 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1217 lockdep_assert_held(&mvm->mutex);
1220 * Disallow low power states when the FW is down by taking
1221 * the UCODE_DOWN ref. in case of ongoing hw restart the
1222 * ref is already taken, so don't take it again.
1224 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1225 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
1227 /* async_handlers_wk is now blocked */
1230 * The work item could be running or queued if the
1231 * ROC time event stops just as we get here.
1233 cancel_work_sync(&mvm->roc_done_wk);
1235 iwl_trans_stop_device(mvm->trans);
1237 iwl_mvm_async_handlers_purge(mvm);
1238 /* async_handlers_list is empty and will stay empty: HW is stopped */
1240 /* the fw is stopped, the aux sta is dead: clean up driver state */
1241 iwl_mvm_del_aux_sta(mvm);
1244 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1245 * won't be called in this case).
1247 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1249 mvm->ucode_loaded = false;
1252 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1254 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1256 flush_work(&mvm->d0i3_exit_work);
1257 flush_work(&mvm->async_handlers_wk);
1258 flush_work(&mvm->fw_error_dump_wk);
1260 mutex_lock(&mvm->mutex);
1261 __iwl_mvm_mac_stop(mvm);
1262 mutex_unlock(&mvm->mutex);
1265 * The worker might have been waiting for the mutex, let it run and
1266 * discover that its list is now empty.
1268 cancel_work_sync(&mvm->async_handlers_wk);
1271 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1275 lockdep_assert_held(&mvm->mutex);
1277 for (i = 0; i < NUM_PHY_CTX; i++)
1278 if (!mvm->phy_ctxts[i].ref)
1279 return &mvm->phy_ctxts[i];
1281 IWL_ERR(mvm, "No available PHY context\n");
1285 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1288 /* FW is in charge of regulatory enforcement */
1289 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
1290 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
1291 .pwr_restriction = cpu_to_le16(tx_power),
1294 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
1295 sizeof(reduce_txpwr_cmd),
1299 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1300 struct ieee80211_vif *vif)
1302 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1303 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1307 * make sure D0i3 exit is completed, otherwise a target access
1308 * during tx queue configuration could be done when still in
1311 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1316 * Not much to do here. The stack will not allow interface
1317 * types or combinations that we didn't advertise, so we
1318 * don't really have to check the types.
1321 mutex_lock(&mvm->mutex);
1323 /* Allocate resources for the MAC context, and add it to the fw */
1324 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1328 /* Counting number of interfaces is needed for legacy PM */
1329 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1333 * The AP binding flow can be done only after the beacon
1334 * template is configured (which happens only in the mac80211
1335 * start_ap() flow), and adding the broadcast station can happen
1336 * only after the binding.
1337 * In addition, since modifying the MAC before adding a bcast
1338 * station is not allowed by the FW, delay the adding of MAC context to
1339 * the point where we can also add the bcast station.
1340 * In short: there's not much we can do at this point, other than
1341 * allocating resources :)
1343 if (vif->type == NL80211_IFTYPE_AP ||
1344 vif->type == NL80211_IFTYPE_ADHOC) {
1345 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1347 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1351 iwl_mvm_vif_dbgfs_register(mvm, vif);
1355 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1359 ret = iwl_mvm_power_update_mac(mvm);
1361 goto out_remove_mac;
1363 /* beacon filtering */
1364 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1366 goto out_remove_mac;
1368 if (!mvm->bf_allowed_vif &&
1369 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1370 mvm->bf_allowed_vif = mvmvif;
1371 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1372 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1376 * P2P_DEVICE interface does not have a channel context assigned to it,
1377 * so a dedicated PHY context is allocated to it and the corresponding
1378 * MAC context is bound to it at this stage.
1380 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1382 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1383 if (!mvmvif->phy_ctxt) {
1388 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1389 ret = iwl_mvm_binding_add_vif(mvm, vif);
1393 ret = iwl_mvm_add_bcast_sta(mvm, vif);
1397 /* Save a pointer to p2p device vif, so it can later be used to
1398 * update the p2p device MAC when a GO is started/stopped */
1399 mvm->p2p_device_vif = vif;
1402 iwl_mvm_vif_dbgfs_register(mvm, vif);
1406 iwl_mvm_binding_remove_vif(mvm, vif);
1408 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1410 if (mvm->bf_allowed_vif == mvmvif) {
1411 mvm->bf_allowed_vif = NULL;
1412 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1413 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1416 mvmvif->phy_ctxt = NULL;
1417 iwl_mvm_mac_ctxt_remove(mvm, vif);
1419 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1422 iwl_mvm_mac_ctxt_release(mvm, vif);
1424 mutex_unlock(&mvm->mutex);
1426 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1431 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1432 struct ieee80211_vif *vif)
1434 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif);
1437 mutex_lock(&mvm->mutex);
1438 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
1439 mutex_unlock(&mvm->mutex);
1442 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1444 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1445 * We assume here that all the packets sent to the OFFCHANNEL
1446 * queue are sent in ROC session.
1448 flush_work(&mvm->roc_done_wk);
1451 * By now, all the AC queues are empty. The AGG queues are
1452 * empty too. We already got all the Tx responses for all the
1453 * packets in the queues. The drain work can have been
1454 * triggered. Flush it.
1456 flush_work(&mvm->sta_drained_wk);
1460 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1461 struct ieee80211_vif *vif)
1463 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1464 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1466 iwl_mvm_prepare_mac_removal(mvm, vif);
1468 mutex_lock(&mvm->mutex);
1470 if (mvm->bf_allowed_vif == mvmvif) {
1471 mvm->bf_allowed_vif = NULL;
1472 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1473 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1476 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1479 * For AP/GO interface, the tear down of the resources allocated to the
1480 * interface is be handled as part of the stop_ap flow.
1482 if (vif->type == NL80211_IFTYPE_AP ||
1483 vif->type == NL80211_IFTYPE_ADHOC) {
1484 #ifdef CONFIG_NL80211_TESTMODE
1485 if (vif == mvm->noa_vif) {
1486 mvm->noa_vif = NULL;
1487 mvm->noa_duration = 0;
1490 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1494 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1495 mvm->p2p_device_vif = NULL;
1496 iwl_mvm_rm_bcast_sta(mvm, vif);
1497 iwl_mvm_binding_remove_vif(mvm, vif);
1498 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1499 mvmvif->phy_ctxt = NULL;
1502 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1505 iwl_mvm_power_update_mac(mvm);
1506 iwl_mvm_mac_ctxt_remove(mvm, vif);
1509 iwl_mvm_mac_ctxt_release(mvm, vif);
1510 mutex_unlock(&mvm->mutex);
1513 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1518 struct iwl_mvm_mc_iter_data {
1519 struct iwl_mvm *mvm;
1523 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1524 struct ieee80211_vif *vif)
1526 struct iwl_mvm_mc_iter_data *data = _data;
1527 struct iwl_mvm *mvm = data->mvm;
1528 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1531 /* if we don't have free ports, mcast frames will be dropped */
1532 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1535 if (vif->type != NL80211_IFTYPE_STATION ||
1536 !vif->bss_conf.assoc)
1539 cmd->port_id = data->port_id++;
1540 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1541 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1543 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
1545 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1548 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1550 struct iwl_mvm_mc_iter_data iter_data = {
1554 lockdep_assert_held(&mvm->mutex);
1556 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1559 ieee80211_iterate_active_interfaces_atomic(
1560 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1561 iwl_mvm_mc_iface_iterator, &iter_data);
1564 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1565 struct netdev_hw_addr_list *mc_list)
1567 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1568 struct iwl_mcast_filter_cmd *cmd;
1569 struct netdev_hw_addr *addr;
1574 addr_count = netdev_hw_addr_list_count(mc_list);
1575 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1576 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1580 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1581 cmd = kzalloc(len, GFP_ATOMIC);
1587 return (u64)(unsigned long)cmd;
1590 netdev_hw_addr_list_for_each(addr, mc_list) {
1591 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1592 cmd->count, addr->addr);
1593 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1594 addr->addr, ETH_ALEN);
1598 return (u64)(unsigned long)cmd;
1601 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1602 unsigned int changed_flags,
1603 unsigned int *total_flags,
1606 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1607 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1609 mutex_lock(&mvm->mutex);
1611 /* replace previous configuration */
1612 kfree(mvm->mcast_filter_cmd);
1613 mvm->mcast_filter_cmd = cmd;
1618 iwl_mvm_recalc_multicast(mvm);
1620 mutex_unlock(&mvm->mutex);
1624 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1625 struct iwl_bcast_iter_data {
1626 struct iwl_mvm *mvm;
1627 struct iwl_bcast_filter_cmd *cmd;
1632 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1633 const struct iwl_fw_bcast_filter *in_filter,
1634 struct iwl_fw_bcast_filter *out_filter)
1636 struct iwl_fw_bcast_filter_attr *attr;
1639 memcpy(out_filter, in_filter, sizeof(*out_filter));
1641 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1642 attr = &out_filter->attrs[i];
1647 switch (attr->reserved1) {
1648 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1649 if (vif->bss_conf.arp_addr_cnt != 1) {
1654 attr->val = vif->bss_conf.arp_addr_list[0];
1656 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1657 attr->val = *(__be32 *)&vif->addr[2];
1662 attr->reserved1 = 0;
1663 out_filter->num_attrs++;
1667 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1668 struct ieee80211_vif *vif)
1670 struct iwl_bcast_iter_data *data = _data;
1671 struct iwl_mvm *mvm = data->mvm;
1672 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1673 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1674 struct iwl_fw_bcast_mac *bcast_mac;
1677 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1680 bcast_mac = &cmd->macs[mvmvif->id];
1683 * enable filtering only for associated stations, but not for P2P
1686 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1687 !vif->bss_conf.assoc)
1690 bcast_mac->default_discard = 1;
1692 /* copy all configured filters */
1693 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1695 * Make sure we don't exceed our filters limit.
1696 * if there is still a valid filter to be configured,
1697 * be on the safe side and just allow bcast for this mac.
1699 if (WARN_ON_ONCE(data->current_filter >=
1700 ARRAY_SIZE(cmd->filters))) {
1701 bcast_mac->default_discard = 0;
1702 bcast_mac->attached_filters = 0;
1706 iwl_mvm_set_bcast_filter(vif,
1707 &mvm->bcast_filters[i],
1708 &cmd->filters[data->current_filter]);
1710 /* skip current filter if it contains no attributes */
1711 if (!cmd->filters[data->current_filter].num_attrs)
1714 /* attach the filter to current mac */
1715 bcast_mac->attached_filters |=
1716 cpu_to_le16(BIT(data->current_filter));
1718 data->current_filter++;
1722 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1723 struct iwl_bcast_filter_cmd *cmd)
1725 struct iwl_bcast_iter_data iter_data = {
1730 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1733 memset(cmd, 0, sizeof(*cmd));
1734 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1735 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1737 #ifdef CONFIG_IWLWIFI_DEBUGFS
1738 /* use debugfs filters/macs if override is configured */
1739 if (mvm->dbgfs_bcast_filtering.override) {
1740 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1741 sizeof(cmd->filters));
1742 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1748 /* if no filters are configured, do nothing */
1749 if (!mvm->bcast_filters)
1752 /* configure and attach these filters for each associated sta vif */
1753 ieee80211_iterate_active_interfaces(
1754 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1755 iwl_mvm_bcast_filter_iterator, &iter_data);
1759 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1760 struct ieee80211_vif *vif)
1762 struct iwl_bcast_filter_cmd cmd;
1764 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1767 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1770 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1774 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1775 struct ieee80211_vif *vif)
1781 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1782 struct ieee80211_vif *vif,
1783 struct ieee80211_bss_conf *bss_conf,
1786 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1790 * Re-calculate the tsf id, as the master-slave relations depend on the
1791 * beacon interval, which was not known when the station interface was
1794 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1795 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1798 * If we're not associated yet, take the (new) BSSID before associating
1799 * so the firmware knows. If we're already associated, then use the old
1800 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1801 * branch for disassociation below.
1803 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1804 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1806 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
1808 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1810 /* after sending it once, adopt mac80211 data */
1811 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1812 mvmvif->associated = bss_conf->assoc;
1814 if (changes & BSS_CHANGED_ASSOC) {
1815 if (bss_conf->assoc) {
1816 /* add quota for this interface */
1817 ret = iwl_mvm_update_quotas(mvm, NULL);
1819 IWL_ERR(mvm, "failed to update quotas\n");
1823 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1826 * If we're restarting then the firmware will
1827 * obviously have lost synchronisation with
1828 * the AP. It will attempt to synchronise by
1829 * itself, but we can make it more reliable by
1830 * scheduling a session protection time event.
1832 * The firmware needs to receive a beacon to
1833 * catch up with synchronisation, use 110% of
1834 * the beacon interval.
1836 * Set a large maximum delay to allow for more
1837 * than a single interface.
1839 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1840 iwl_mvm_protect_session(mvm, vif, dur, dur,
1844 iwl_mvm_sf_update(mvm, vif, false);
1845 iwl_mvm_power_vif_assoc(mvm, vif);
1847 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
1848 iwl_mvm_update_smps(mvm, vif,
1849 IWL_MVM_SMPS_REQ_PROT,
1850 IEEE80211_SMPS_DYNAMIC);
1852 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1854 * If update fails - SF might be running in associated
1855 * mode while disassociated - which is forbidden.
1857 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1858 "Failed to update SF upon disassociation\n");
1860 /* remove AP station now that the MAC is unassoc */
1861 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1863 IWL_ERR(mvm, "failed to remove AP station\n");
1865 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1866 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1867 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1868 /* remove quota for this interface */
1869 ret = iwl_mvm_update_quotas(mvm, NULL);
1871 IWL_ERR(mvm, "failed to update quotas\n");
1874 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
1876 /* this will take the cleared BSSID from bss_conf */
1877 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1880 "failed to update MAC %pM (clear after unassoc)\n",
1884 iwl_mvm_recalc_multicast(mvm);
1885 iwl_mvm_configure_bcast_filter(mvm, vif);
1887 /* reset rssi values */
1888 mvmvif->bf_data.ave_beacon_signal = 0;
1890 iwl_mvm_bt_coex_vif_change(mvm);
1891 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1892 IEEE80211_SMPS_AUTOMATIC);
1893 } else if (changes & BSS_CHANGED_BEACON_INFO) {
1895 * We received a beacon _after_ association so
1896 * remove the session protection.
1898 iwl_mvm_remove_time_event(mvm, mvmvif,
1899 &mvmvif->time_event_data);
1902 if (changes & BSS_CHANGED_BEACON_INFO) {
1903 iwl_mvm_sf_update(mvm, vif, false);
1904 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1907 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS)) {
1908 ret = iwl_mvm_power_update_mac(mvm);
1910 IWL_ERR(mvm, "failed to update power mode\n");
1913 if (changes & BSS_CHANGED_TXPOWER) {
1914 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1916 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1919 if (changes & BSS_CHANGED_CQM) {
1920 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
1921 /* reset cqm events tracking */
1922 mvmvif->bf_data.last_cqm_event = 0;
1923 if (mvmvif->bf_data.bf_enabled) {
1924 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1927 "failed to update CQM thresholds\n");
1931 if (changes & BSS_CHANGED_ARP_FILTER) {
1932 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
1933 iwl_mvm_configure_bcast_filter(mvm, vif);
1937 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1938 struct ieee80211_vif *vif)
1940 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1941 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1945 * iwl_mvm_mac_ctxt_add() might read directly from the device
1946 * (the system time), so make sure it is available.
1948 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
1952 mutex_lock(&mvm->mutex);
1954 /* Send the beacon template */
1955 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1960 * Re-calculate the tsf id, as the master-slave relations depend on the
1961 * beacon interval, which was not known when the AP interface was added.
1963 if (vif->type == NL80211_IFTYPE_AP)
1964 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1966 /* Add the mac context */
1967 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1971 /* Perform the binding */
1972 ret = iwl_mvm_binding_add_vif(mvm, vif);
1976 /* Send the bcast station. At this stage the TBTT and DTIM time events
1977 * are added and applied to the scheduler */
1978 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
1982 /* must be set before quota calculations */
1983 mvmvif->ap_ibss_active = true;
1985 /* power updated needs to be done before quotas */
1986 iwl_mvm_power_update_mac(mvm);
1988 ret = iwl_mvm_update_quotas(mvm, NULL);
1990 goto out_quota_failed;
1992 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1993 if (vif->p2p && mvm->p2p_device_vif)
1994 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
1996 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1998 iwl_mvm_bt_coex_vif_change(mvm);
2000 /* we don't support TDLS during DCM */
2001 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2002 iwl_mvm_teardown_tdls_peers(mvm);
2004 mutex_unlock(&mvm->mutex);
2008 iwl_mvm_power_update_mac(mvm);
2009 mvmvif->ap_ibss_active = false;
2010 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2012 iwl_mvm_binding_remove_vif(mvm, vif);
2014 iwl_mvm_mac_ctxt_remove(mvm, vif);
2016 mutex_unlock(&mvm->mutex);
2017 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
2021 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2022 struct ieee80211_vif *vif)
2024 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2025 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2027 iwl_mvm_prepare_mac_removal(mvm, vif);
2029 mutex_lock(&mvm->mutex);
2031 /* Handle AP stop while in CSA */
2032 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2033 iwl_mvm_remove_time_event(mvm, mvmvif,
2034 &mvmvif->time_event_data);
2035 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2038 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2039 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2040 mvm->csa_tx_block_bcn_timeout = 0;
2043 mvmvif->ap_ibss_active = false;
2044 mvm->ap_last_beacon_gp2 = 0;
2046 iwl_mvm_bt_coex_vif_change(mvm);
2048 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2050 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2051 if (vif->p2p && mvm->p2p_device_vif)
2052 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2054 iwl_mvm_update_quotas(mvm, NULL);
2055 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2056 iwl_mvm_binding_remove_vif(mvm, vif);
2058 iwl_mvm_power_update_mac(mvm);
2060 iwl_mvm_mac_ctxt_remove(mvm, vif);
2062 mutex_unlock(&mvm->mutex);
2066 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2067 struct ieee80211_vif *vif,
2068 struct ieee80211_bss_conf *bss_conf,
2071 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2073 /* Changes will be applied when the AP/IBSS is started */
2074 if (!mvmvif->ap_ibss_active)
2077 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2078 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2079 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2080 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2082 /* Need to send a new beacon template to the FW */
2083 if (changes & BSS_CHANGED_BEACON &&
2084 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2085 IWL_WARN(mvm, "Failed updating beacon data\n");
2087 if (changes & BSS_CHANGED_TXPOWER) {
2088 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2090 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2095 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2096 struct ieee80211_vif *vif,
2097 struct ieee80211_bss_conf *bss_conf,
2100 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2103 * iwl_mvm_bss_info_changed_station() might call
2104 * iwl_mvm_protect_session(), which reads directly from
2105 * the device (the system time), so make sure it is available.
2107 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2110 mutex_lock(&mvm->mutex);
2112 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2113 iwl_mvm_scan_offload_stop(mvm, true);
2115 switch (vif->type) {
2116 case NL80211_IFTYPE_STATION:
2117 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2119 case NL80211_IFTYPE_AP:
2120 case NL80211_IFTYPE_ADHOC:
2121 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2124 /* shouldn't happen */
2128 mutex_unlock(&mvm->mutex);
2129 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
2132 static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm,
2133 enum iwl_scan_status scan_type)
2136 bool wait_for_handlers = false;
2138 mutex_lock(&mvm->mutex);
2140 if (mvm->scan_status != scan_type) {
2142 /* make sure there are no pending notifications */
2143 wait_for_handlers = true;
2147 switch (scan_type) {
2148 case IWL_MVM_SCAN_SCHED:
2149 ret = iwl_mvm_scan_offload_stop(mvm, true);
2151 case IWL_MVM_SCAN_OS:
2152 ret = iwl_mvm_cancel_scan(mvm);
2154 case IWL_MVM_SCAN_NONE:
2163 wait_for_handlers = true;
2165 mutex_unlock(&mvm->mutex);
2167 /* make sure we consume the completion notification */
2168 if (wait_for_handlers)
2169 iwl_mvm_wait_for_async_handlers(mvm);
2173 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2174 struct ieee80211_vif *vif,
2175 struct ieee80211_scan_request *hw_req)
2177 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2178 struct cfg80211_scan_request *req = &hw_req->req;
2181 if (req->n_channels == 0 ||
2182 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
2185 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2186 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_SCHED);
2191 mutex_lock(&mvm->mutex);
2193 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
2198 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
2200 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
2201 ret = iwl_mvm_scan_umac(mvm, vif, hw_req);
2202 else if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
2203 ret = iwl_mvm_unified_scan_lmac(mvm, vif, hw_req);
2205 ret = iwl_mvm_scan_request(mvm, vif, req);
2208 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
2210 mutex_unlock(&mvm->mutex);
2214 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2215 struct ieee80211_vif *vif)
2217 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2219 mutex_lock(&mvm->mutex);
2221 /* Due to a race condition, it's possible that mac80211 asks
2222 * us to stop a hw_scan when it's already stopped. This can
2223 * happen, for instance, if we stopped the scan ourselves,
2224 * called ieee80211_scan_completed() and the userspace called
2225 * cancel scan scan before ieee80211_scan_work() could run.
2226 * To handle that, simply return if the scan is not running.
2228 /* FIXME: for now, we ignore this race for UMAC scans, since
2229 * they don't set the scan_status.
2231 if ((mvm->scan_status == IWL_MVM_SCAN_OS) ||
2232 (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2233 iwl_mvm_cancel_scan(mvm);
2235 mutex_unlock(&mvm->mutex);
2239 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2240 struct ieee80211_sta *sta, u16 tids,
2242 enum ieee80211_frame_release_type reason,
2245 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2247 /* Called when we need to transmit (a) frame(s) from mac80211 */
2249 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2250 tids, more_data, false);
2254 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2255 struct ieee80211_sta *sta, u16 tids,
2257 enum ieee80211_frame_release_type reason,
2260 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2262 /* Called when we need to transmit (a) frame(s) from agg queue */
2264 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2265 tids, more_data, true);
2268 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2269 struct ieee80211_vif *vif,
2270 enum sta_notify_cmd cmd,
2271 struct ieee80211_sta *sta)
2273 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2274 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2278 case STA_NOTIFY_SLEEP:
2279 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
2280 ieee80211_sta_block_awake(hw, sta, true);
2281 spin_lock_bh(&mvmsta->lock);
2282 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2283 struct iwl_mvm_tid_data *tid_data;
2285 tid_data = &mvmsta->tid_data[tid];
2286 if (tid_data->state != IWL_AGG_ON &&
2287 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
2289 if (iwl_mvm_tid_queued(tid_data) == 0)
2291 ieee80211_sta_set_buffered(sta, tid, true);
2293 spin_unlock_bh(&mvmsta->lock);
2295 * The fw updates the STA to be asleep. Tx packets on the Tx
2296 * queues to this station will not be transmitted. The fw will
2297 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2300 case STA_NOTIFY_AWAKE:
2301 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
2303 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2310 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2311 struct ieee80211_vif *vif,
2312 struct ieee80211_sta *sta)
2314 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2315 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2318 * This is called before mac80211 does RCU synchronisation,
2319 * so here we already invalidate our internal RCU-protected
2320 * station pointer. The rest of the code will thus no longer
2321 * be able to find the station this way, and we don't rely
2322 * on further RCU synchronisation after the sta_state()
2323 * callback deleted the station.
2325 mutex_lock(&mvm->mutex);
2326 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2327 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2329 mutex_unlock(&mvm->mutex);
2332 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2335 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2338 if (iwlwifi_mod_params.uapsd_disable) {
2339 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2343 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2346 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2347 struct ieee80211_vif *vif,
2348 struct ieee80211_sta *sta,
2349 enum ieee80211_sta_state old_state,
2350 enum ieee80211_sta_state new_state)
2352 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2353 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2356 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2357 sta->addr, old_state, new_state);
2359 /* this would be a mac80211 bug ... but don't crash */
2360 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2363 /* if a STA is being removed, reuse its ID */
2364 flush_work(&mvm->sta_drained_wk);
2366 mutex_lock(&mvm->mutex);
2367 if (old_state == IEEE80211_STA_NOTEXIST &&
2368 new_state == IEEE80211_STA_NONE) {
2370 * Firmware bug - it'll crash if the beacon interval is less
2371 * than 16. We can't avoid connecting at all, so refuse the
2372 * station state change, this will cause mac80211 to abandon
2373 * attempts to connect to this AP, and eventually wpa_s will
2374 * blacklist the AP...
2376 if (vif->type == NL80211_IFTYPE_STATION &&
2377 vif->bss_conf.beacon_int < 16) {
2379 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2380 sta->addr, vif->bss_conf.beacon_int);
2387 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2388 IWL_MVM_TDLS_STA_COUNT ||
2389 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2390 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2395 ret = iwl_mvm_add_sta(mvm, vif, sta);
2396 if (sta->tdls && ret == 0)
2397 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2398 } else if (old_state == IEEE80211_STA_NONE &&
2399 new_state == IEEE80211_STA_AUTH) {
2401 * EBS may be disabled due to previous failures reported by FW.
2402 * Reset EBS status here assuming environment has been changed.
2404 mvm->last_ebs_successful = true;
2405 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
2407 } else if (old_state == IEEE80211_STA_AUTH &&
2408 new_state == IEEE80211_STA_ASSOC) {
2409 ret = iwl_mvm_update_sta(mvm, vif, sta);
2411 iwl_mvm_rs_rate_init(mvm, sta,
2412 mvmvif->phy_ctxt->channel->band,
2414 } else if (old_state == IEEE80211_STA_ASSOC &&
2415 new_state == IEEE80211_STA_AUTHORIZED) {
2417 /* we don't support TDLS during DCM */
2418 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2419 iwl_mvm_teardown_tdls_peers(mvm);
2421 /* enable beacon filtering */
2422 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2424 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2425 new_state == IEEE80211_STA_ASSOC) {
2426 /* disable beacon filtering */
2427 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2429 } else if (old_state == IEEE80211_STA_ASSOC &&
2430 new_state == IEEE80211_STA_AUTH) {
2432 } else if (old_state == IEEE80211_STA_AUTH &&
2433 new_state == IEEE80211_STA_NONE) {
2435 } else if (old_state == IEEE80211_STA_NONE &&
2436 new_state == IEEE80211_STA_NOTEXIST) {
2437 ret = iwl_mvm_rm_sta(mvm, vif, sta);
2439 iwl_mvm_recalc_tdls_state(mvm, vif, false);
2444 mutex_unlock(&mvm->mutex);
2446 if (sta->tdls && ret == 0) {
2447 if (old_state == IEEE80211_STA_NOTEXIST &&
2448 new_state == IEEE80211_STA_NONE)
2449 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2450 else if (old_state == IEEE80211_STA_NONE &&
2451 new_state == IEEE80211_STA_NOTEXIST)
2452 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2458 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2460 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2462 mvm->rts_threshold = value;
2467 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2468 struct ieee80211_vif *vif,
2469 struct ieee80211_sta *sta, u32 changed)
2471 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2473 if (vif->type == NL80211_IFTYPE_STATION &&
2474 changed & IEEE80211_RC_NSS_CHANGED)
2475 iwl_mvm_sf_update(mvm, vif, false);
2478 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2479 struct ieee80211_vif *vif, u16 ac,
2480 const struct ieee80211_tx_queue_params *params)
2482 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2483 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2485 mvmvif->queue_params[ac] = *params;
2488 * No need to update right away, we'll get BSS_CHANGED_QOS
2489 * The exception is P2P_DEVICE interface which needs immediate update.
2491 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2494 mutex_lock(&mvm->mutex);
2495 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2496 mutex_unlock(&mvm->mutex);
2502 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2503 struct ieee80211_vif *vif)
2505 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2506 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
2507 200 + vif->bss_conf.beacon_int);
2508 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
2509 100 + vif->bss_conf.beacon_int);
2511 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2515 * iwl_mvm_protect_session() reads directly from the device
2516 * (the system time), so make sure it is available.
2518 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2521 mutex_lock(&mvm->mutex);
2522 /* Try really hard to protect the session and hear a beacon */
2523 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
2524 mutex_unlock(&mvm->mutex);
2526 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
2529 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2530 struct ieee80211_vif *vif,
2531 struct cfg80211_sched_scan_request *req,
2532 struct ieee80211_scan_ies *ies)
2534 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2537 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2538 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS);
2543 mutex_lock(&mvm->mutex);
2545 /* Newest FW fixes sched scan while connected on another interface */
2546 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) {
2547 if (!vif->bss_conf.idle) {
2551 } else if (!iwl_mvm_is_idle(mvm)) {
2556 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
2561 ret = iwl_mvm_scan_offload_start(mvm, vif, req, ies);
2563 mvm->scan_status = IWL_MVM_SCAN_NONE;
2566 mutex_unlock(&mvm->mutex);
2570 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2571 struct ieee80211_vif *vif)
2573 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2576 mutex_lock(&mvm->mutex);
2578 /* Due to a race condition, it's possible that mac80211 asks
2579 * us to stop a sched_scan when it's already stopped. This
2580 * can happen, for instance, if we stopped the scan ourselves,
2581 * called ieee80211_sched_scan_stopped() and the userspace called
2582 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
2583 * could run. To handle this, simply return if the scan is
2586 /* FIXME: for now, we ignore this race for UMAC scans, since
2587 * they don't set the scan_status.
2589 if (mvm->scan_status != IWL_MVM_SCAN_SCHED &&
2590 !(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2591 mutex_unlock(&mvm->mutex);
2595 ret = iwl_mvm_scan_offload_stop(mvm, false);
2596 mutex_unlock(&mvm->mutex);
2597 iwl_mvm_wait_for_async_handlers(mvm);
2602 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2603 enum set_key_cmd cmd,
2604 struct ieee80211_vif *vif,
2605 struct ieee80211_sta *sta,
2606 struct ieee80211_key_conf *key)
2608 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2611 if (iwlwifi_mod_params.sw_crypto) {
2612 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2616 switch (key->cipher) {
2617 case WLAN_CIPHER_SUITE_TKIP:
2618 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2620 case WLAN_CIPHER_SUITE_CCMP:
2621 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2623 case WLAN_CIPHER_SUITE_AES_CMAC:
2624 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
2626 case WLAN_CIPHER_SUITE_WEP40:
2627 case WLAN_CIPHER_SUITE_WEP104:
2628 /* For non-client mode, only use WEP keys for TX as we probably
2629 * don't have a station yet anyway and would then have to keep
2630 * track of the keys, linking them to each of the clients/peers
2631 * as they appear. For now, don't do that, for performance WEP
2632 * offload doesn't really matter much, but we need it for some
2633 * other offload features in client mode.
2635 if (vif->type != NL80211_IFTYPE_STATION)
2639 /* currently FW supports only one optional cipher scheme */
2640 if (hw->n_cipher_schemes &&
2641 hw->cipher_schemes->cipher == key->cipher)
2642 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2647 mutex_lock(&mvm->mutex);
2651 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2652 vif->type == NL80211_IFTYPE_AP) && !sta) {
2654 * GTK on AP interface is a TX-only key, return 0;
2655 * on IBSS they're per-station and because we're lazy
2656 * we don't support them for RX, so do the same.
2659 key->hw_key_idx = STA_KEY_IDX_INVALID;
2663 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2664 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
2666 IWL_WARN(mvm, "set key failed\n");
2668 * can't add key for RX, but we don't need it
2669 * in the device for TX so still return 0
2671 key->hw_key_idx = STA_KEY_IDX_INVALID;
2677 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2682 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2683 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2689 mutex_unlock(&mvm->mutex);
2693 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2694 struct ieee80211_vif *vif,
2695 struct ieee80211_key_conf *keyconf,
2696 struct ieee80211_sta *sta,
2697 u32 iv32, u16 *phase1key)
2699 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2701 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2704 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2708 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
2709 struct iwl_rx_packet *pkt, void *data)
2711 struct iwl_mvm *mvm =
2712 container_of(notif_wait, struct iwl_mvm, notif_wait);
2713 struct iwl_hs20_roc_res *resp;
2714 int resp_len = iwl_rx_packet_payload_len(pkt);
2715 struct iwl_mvm_time_event_data *te_data = data;
2717 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
2720 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
2721 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
2725 resp = (void *)pkt->data;
2728 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
2729 resp->status, resp->event_unique_id);
2731 te_data->uid = le32_to_cpu(resp->event_unique_id);
2732 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
2735 spin_lock_bh(&mvm->time_event_lock);
2736 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
2737 spin_unlock_bh(&mvm->time_event_lock);
2742 #define AUX_ROC_MAX_DELAY_ON_CHANNEL 5000
2743 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
2744 struct ieee80211_channel *channel,
2745 struct ieee80211_vif *vif,
2748 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
2749 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2750 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
2751 static const u8 time_event_response[] = { HOT_SPOT_CMD };
2752 struct iwl_notification_wait wait_time_event;
2753 struct iwl_hs20_roc_req aux_roc_req = {
2754 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
2756 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
2757 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
2758 /* Set the channel info data */
2759 .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
2760 PHY_BAND_24 : PHY_BAND_5,
2761 .channel_info.channel = channel->hw_value,
2762 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
2763 /* Set the time and duration */
2764 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
2765 .apply_time_max_delay =
2766 cpu_to_le32(MSEC_TO_TU(AUX_ROC_MAX_DELAY_ON_CHANNEL)),
2767 .duration = cpu_to_le32(MSEC_TO_TU(duration)),
2770 /* Set the node address */
2771 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
2773 lockdep_assert_held(&mvm->mutex);
2775 spin_lock_bh(&mvm->time_event_lock);
2777 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
2778 spin_unlock_bh(&mvm->time_event_lock);
2783 te_data->duration = duration;
2784 te_data->id = HOT_SPOT_CMD;
2786 spin_unlock_bh(&mvm->time_event_lock);
2789 * Use a notification wait, which really just processes the
2790 * command response and doesn't wait for anything, in order
2791 * to be able to process the response and get the UID inside
2792 * the RX path. Using CMD_WANT_SKB doesn't work because it
2793 * stores the buffer and then wakes up this thread, by which
2794 * time another notification (that the time event started)
2795 * might already be processed unsuccessfully.
2797 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
2798 time_event_response,
2799 ARRAY_SIZE(time_event_response),
2800 iwl_mvm_rx_aux_roc, te_data);
2802 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
2806 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
2807 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
2811 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
2812 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
2813 /* should never fail */
2818 spin_lock_bh(&mvm->time_event_lock);
2819 iwl_mvm_te_clear_data(mvm, te_data);
2820 spin_unlock_bh(&mvm->time_event_lock);
2826 static int iwl_mvm_roc(struct ieee80211_hw *hw,
2827 struct ieee80211_vif *vif,
2828 struct ieee80211_channel *channel,
2830 enum ieee80211_roc_type type)
2832 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2833 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2834 struct cfg80211_chan_def chandef;
2835 struct iwl_mvm_phy_ctxt *phy_ctxt;
2838 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2841 mutex_lock(&mvm->mutex);
2843 switch (vif->type) {
2844 case NL80211_IFTYPE_STATION:
2845 if (mvm->fw->ucode_capa.capa[0] &
2846 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT) {
2847 /* Use aux roc framework (HS20) */
2848 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
2852 IWL_ERR(mvm, "hotspot not supported\n");
2855 case NL80211_IFTYPE_P2P_DEVICE:
2859 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
2864 for (i = 0; i < NUM_PHY_CTX; i++) {
2865 phy_ctxt = &mvm->phy_ctxts[i];
2866 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2869 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2871 * Unbind the P2P_DEVICE from the current PHY context,
2872 * and if the PHY context is not used remove it.
2874 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2875 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2878 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2880 /* Bind the P2P_DEVICE to the current PHY Context */
2881 mvmvif->phy_ctxt = phy_ctxt;
2883 ret = iwl_mvm_binding_add_vif(mvm, vif);
2884 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2887 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2888 goto schedule_time_event;
2892 /* Need to update the PHY context only if the ROC channel changed */
2893 if (channel == mvmvif->phy_ctxt->channel)
2894 goto schedule_time_event;
2896 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2899 * Change the PHY context configuration as it is currently referenced
2900 * only by the P2P Device MAC
2902 if (mvmvif->phy_ctxt->ref == 1) {
2903 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2909 * The PHY context is shared with other MACs. Need to remove the
2910 * P2P Device from the binding, allocate an new PHY context and
2911 * create a new binding
2913 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2919 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2922 IWL_ERR(mvm, "Failed to change PHY context\n");
2926 /* Unbind the P2P_DEVICE from the current PHY context */
2927 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2928 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2931 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2933 /* Bind the P2P_DEVICE to the new allocated PHY context */
2934 mvmvif->phy_ctxt = phy_ctxt;
2936 ret = iwl_mvm_binding_add_vif(mvm, vif);
2937 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2940 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2943 schedule_time_event:
2944 /* Schedule the time events */
2945 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
2948 mutex_unlock(&mvm->mutex);
2949 IWL_DEBUG_MAC80211(mvm, "leave\n");
2953 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2955 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2957 IWL_DEBUG_MAC80211(mvm, "enter\n");
2959 mutex_lock(&mvm->mutex);
2960 iwl_mvm_stop_roc(mvm);
2961 mutex_unlock(&mvm->mutex);
2963 IWL_DEBUG_MAC80211(mvm, "leave\n");
2967 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
2968 struct ieee80211_chanctx_conf *ctx)
2970 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2971 struct iwl_mvm_phy_ctxt *phy_ctxt;
2974 lockdep_assert_held(&mvm->mutex);
2976 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
2978 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2984 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
2985 ctx->rx_chains_static,
2986 ctx->rx_chains_dynamic);
2988 IWL_ERR(mvm, "Failed to add PHY context\n");
2992 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
2993 *phy_ctxt_id = phy_ctxt->id;
2998 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2999 struct ieee80211_chanctx_conf *ctx)
3001 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3004 mutex_lock(&mvm->mutex);
3005 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3006 mutex_unlock(&mvm->mutex);
3011 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3012 struct ieee80211_chanctx_conf *ctx)
3014 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3015 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3017 lockdep_assert_held(&mvm->mutex);
3019 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3022 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3023 struct ieee80211_chanctx_conf *ctx)
3025 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3027 mutex_lock(&mvm->mutex);
3028 __iwl_mvm_remove_chanctx(mvm, ctx);
3029 mutex_unlock(&mvm->mutex);
3032 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3033 struct ieee80211_chanctx_conf *ctx,
3036 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3037 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3038 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3040 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3041 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3042 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
3043 IEEE80211_CHANCTX_CHANGE_RADAR |
3044 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
3045 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3046 phy_ctxt->ref, changed))
3049 mutex_lock(&mvm->mutex);
3050 iwl_mvm_bt_coex_vif_change(mvm);
3051 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
3052 ctx->rx_chains_static,
3053 ctx->rx_chains_dynamic);
3054 mutex_unlock(&mvm->mutex);
3057 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3058 struct ieee80211_vif *vif,
3059 struct ieee80211_chanctx_conf *ctx,
3060 bool switching_chanctx)
3062 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3063 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3064 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3067 lockdep_assert_held(&mvm->mutex);
3069 mvmvif->phy_ctxt = phy_ctxt;
3071 switch (vif->type) {
3072 case NL80211_IFTYPE_AP:
3073 /* only needed if we're switching chanctx (i.e. during CSA) */
3074 if (switching_chanctx) {
3075 mvmvif->ap_ibss_active = true;
3078 case NL80211_IFTYPE_ADHOC:
3080 * The AP binding flow is handled as part of the start_ap flow
3081 * (in bss_info_changed), similarly for IBSS.
3085 case NL80211_IFTYPE_STATION:
3087 case NL80211_IFTYPE_MONITOR:
3088 /* always disable PS when a monitor interface is active */
3089 mvmvif->ps_disabled = true;
3096 ret = iwl_mvm_binding_add_vif(mvm, vif);
3101 * Power state must be updated before quotas,
3102 * otherwise fw will complain.
3104 iwl_mvm_power_update_mac(mvm);
3106 /* Setting the quota at this stage is only required for monitor
3107 * interfaces. For the other types, the bss_info changed flow
3108 * will handle quota settings.
3110 if (vif->type == NL80211_IFTYPE_MONITOR) {
3111 mvmvif->monitor_active = true;
3112 ret = iwl_mvm_update_quotas(mvm, NULL);
3114 goto out_remove_binding;
3117 /* Handle binding during CSA */
3118 if (vif->type == NL80211_IFTYPE_AP) {
3119 iwl_mvm_update_quotas(mvm, NULL);
3120 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3123 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
3124 u32 duration = 2 * vif->bss_conf.beacon_int;
3126 /* iwl_mvm_protect_session() reads directly from the
3127 * device (the system time), so make sure it is
3130 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3132 goto out_remove_binding;
3134 /* Protect the session to make sure we hear the first
3135 * beacon on the new channel.
3137 iwl_mvm_protect_session(mvm, vif, duration, duration,
3138 vif->bss_conf.beacon_int / 2,
3141 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3143 iwl_mvm_update_quotas(mvm, NULL);
3149 iwl_mvm_binding_remove_vif(mvm, vif);
3150 iwl_mvm_power_update_mac(mvm);
3153 mvmvif->phy_ctxt = NULL;
3156 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3157 struct ieee80211_vif *vif,
3158 struct ieee80211_chanctx_conf *ctx)
3160 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3163 mutex_lock(&mvm->mutex);
3164 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
3165 mutex_unlock(&mvm->mutex);
3170 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3171 struct ieee80211_vif *vif,
3172 struct ieee80211_chanctx_conf *ctx,
3173 bool switching_chanctx)
3175 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3176 struct ieee80211_vif *disabled_vif = NULL;
3178 lockdep_assert_held(&mvm->mutex);
3180 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3182 switch (vif->type) {
3183 case NL80211_IFTYPE_ADHOC:
3185 case NL80211_IFTYPE_MONITOR:
3186 mvmvif->monitor_active = false;
3187 mvmvif->ps_disabled = false;
3189 case NL80211_IFTYPE_AP:
3190 /* This part is triggered only during CSA */
3191 if (!switching_chanctx || !mvmvif->ap_ibss_active)
3194 mvmvif->csa_countdown = false;
3196 /* Set CS bit on all the stations */
3197 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3199 /* Save blocked iface, the timeout is set on the next beacon */
3200 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3202 mvmvif->ap_ibss_active = false;
3204 case NL80211_IFTYPE_STATION:
3205 if (!switching_chanctx)
3210 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
3216 iwl_mvm_update_quotas(mvm, disabled_vif);
3217 iwl_mvm_binding_remove_vif(mvm, vif);
3220 mvmvif->phy_ctxt = NULL;
3221 iwl_mvm_power_update_mac(mvm);
3224 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3225 struct ieee80211_vif *vif,
3226 struct ieee80211_chanctx_conf *ctx)
3228 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3230 mutex_lock(&mvm->mutex);
3231 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
3232 mutex_unlock(&mvm->mutex);
3236 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3237 struct ieee80211_vif_chanctx_switch *vifs)
3241 mutex_lock(&mvm->mutex);
3242 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3243 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3245 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3247 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3251 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3255 "failed to assign new_ctx during channel switch\n");
3259 /* we don't support TDLS during DCM - can be caused by channel switch */
3260 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3261 iwl_mvm_teardown_tdls_peers(mvm);
3266 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3269 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
3270 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3274 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3276 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3283 /* things keep failing, better restart the hw */
3284 iwl_mvm_nic_restart(mvm, false);
3287 mutex_unlock(&mvm->mutex);
3293 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3294 struct ieee80211_vif_chanctx_switch *vifs)
3298 mutex_lock(&mvm->mutex);
3299 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3301 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3305 "failed to assign new_ctx during channel switch\n");
3312 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3314 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3321 /* things keep failing, better restart the hw */
3322 iwl_mvm_nic_restart(mvm, false);
3325 mutex_unlock(&mvm->mutex);
3330 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3331 struct ieee80211_vif_chanctx_switch *vifs,
3333 enum ieee80211_chanctx_switch_mode mode)
3335 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3338 /* we only support a single-vif right now */
3343 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3344 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3346 case CHANCTX_SWMODE_REASSIGN_VIF:
3347 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
3357 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3358 struct ieee80211_sta *sta,
3361 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3362 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3364 if (!mvm_sta || !mvm_sta->vif) {
3365 IWL_ERR(mvm, "Station is not associated to a vif\n");
3369 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3372 #ifdef CONFIG_NL80211_TESTMODE
3373 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3374 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3375 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
3376 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
3379 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3380 struct ieee80211_vif *vif,
3381 void *data, int len)
3383 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3387 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
3391 if (!tb[IWL_MVM_TM_ATTR_CMD])
3394 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3395 case IWL_MVM_TM_CMD_SET_NOA:
3396 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3397 !vif->bss_conf.enable_beacon ||
3398 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3401 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3402 if (noa_duration >= vif->bss_conf.beacon_int)
3405 mvm->noa_duration = noa_duration;
3408 return iwl_mvm_update_quotas(mvm, NULL);
3409 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3410 /* must be associated client vif - ignore authorized */
3411 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3412 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3413 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3416 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
3417 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3418 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3424 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3425 struct ieee80211_vif *vif,
3426 void *data, int len)
3428 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3431 mutex_lock(&mvm->mutex);
3432 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3433 mutex_unlock(&mvm->mutex);
3439 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3440 struct ieee80211_vif *vif,
3441 struct ieee80211_channel_switch *chsw)
3443 /* By implementing this operation, we prevent mac80211 from
3444 * starting its own channel switch timer, so that we can call
3445 * ieee80211_chswitch_done() ourselves at the right time
3446 * (which is when the absence time event starts).
3449 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3450 "dummy channel switch op\n");
3453 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3454 struct ieee80211_vif *vif,
3455 struct ieee80211_channel_switch *chsw)
3457 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3458 struct ieee80211_vif *csa_vif;
3459 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3463 mutex_lock(&mvm->mutex);
3465 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
3466 chsw->chandef.center_freq1);
3468 switch (vif->type) {
3469 case NL80211_IFTYPE_AP:
3471 rcu_dereference_protected(mvm->csa_vif,
3472 lockdep_is_held(&mvm->mutex));
3473 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3474 "Another CSA is already in progress")) {
3479 rcu_assign_pointer(mvm->csa_vif, vif);
3481 if (WARN_ONCE(mvmvif->csa_countdown,
3482 "Previous CSA countdown didn't complete")) {
3488 case NL80211_IFTYPE_STATION:
3489 /* Schedule the time event to a bit before beacon 1,
3490 * to make sure we're in the new channel when the
3493 apply_time = chsw->device_timestamp +
3494 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3495 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
3498 iwl_mvm_csa_client_absent(mvm, vif);
3500 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
3502 if (mvmvif->bf_data.bf_enabled) {
3503 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3513 mvmvif->ps_disabled = true;
3515 ret = iwl_mvm_power_update_ps(mvm);
3519 /* we won't be on this channel any longer */
3520 iwl_mvm_teardown_tdls_peers(mvm);
3523 mutex_unlock(&mvm->mutex);
3528 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
3529 struct ieee80211_vif *vif)
3531 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3532 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3535 mutex_lock(&mvm->mutex);
3537 if (vif->type == NL80211_IFTYPE_STATION) {
3538 struct iwl_mvm_sta *mvmsta;
3540 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
3543 if (WARN_ON(!mvmsta)) {
3548 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
3550 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3552 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3556 iwl_mvm_stop_session_protection(mvm, vif);
3559 mvmvif->ps_disabled = false;
3561 ret = iwl_mvm_power_update_ps(mvm);
3564 mutex_unlock(&mvm->mutex);
3569 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3570 struct ieee80211_vif *vif, u32 queues, bool drop)
3572 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3573 struct iwl_mvm_vif *mvmvif;
3574 struct iwl_mvm_sta *mvmsta;
3575 struct ieee80211_sta *sta;
3579 if (!vif || vif->type != NL80211_IFTYPE_STATION)
3582 mutex_lock(&mvm->mutex);
3583 mvmvif = iwl_mvm_vif_from_mac80211(vif);
3585 /* flush the AP-station and all TDLS peers */
3586 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
3587 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3588 lockdep_is_held(&mvm->mutex));
3589 if (IS_ERR_OR_NULL(sta))
3592 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3593 if (mvmsta->vif != vif)
3596 /* make sure only TDLS peers or the AP are flushed */
3597 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
3599 msk |= mvmsta->tfd_queue_msk;
3603 if (iwl_mvm_flush_tx_path(mvm, msk, true))
3604 IWL_ERR(mvm, "flush request fail\n");
3605 mutex_unlock(&mvm->mutex);
3607 mutex_unlock(&mvm->mutex);
3609 /* this can take a while, and we may need/want other operations
3610 * to succeed while doing this, so do it without the mutex held
3612 iwl_trans_wait_tx_queue_empty(mvm->trans, msk);
3616 const struct ieee80211_ops iwl_mvm_hw_ops = {
3617 .tx = iwl_mvm_mac_tx,
3618 .ampdu_action = iwl_mvm_mac_ampdu_action,
3619 .start = iwl_mvm_mac_start,
3620 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
3621 .stop = iwl_mvm_mac_stop,
3622 .add_interface = iwl_mvm_mac_add_interface,
3623 .remove_interface = iwl_mvm_mac_remove_interface,
3624 .config = iwl_mvm_mac_config,
3625 .prepare_multicast = iwl_mvm_prepare_multicast,
3626 .configure_filter = iwl_mvm_configure_filter,
3627 .bss_info_changed = iwl_mvm_bss_info_changed,
3628 .hw_scan = iwl_mvm_mac_hw_scan,
3629 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
3630 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
3631 .sta_state = iwl_mvm_mac_sta_state,
3632 .sta_notify = iwl_mvm_mac_sta_notify,
3633 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
3634 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
3635 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
3636 .sta_rc_update = iwl_mvm_sta_rc_update,
3637 .conf_tx = iwl_mvm_mac_conf_tx,
3638 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
3639 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
3640 .flush = iwl_mvm_mac_flush,
3641 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
3642 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
3643 .set_key = iwl_mvm_mac_set_key,
3644 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
3645 .remain_on_channel = iwl_mvm_roc,
3646 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
3647 .add_chanctx = iwl_mvm_add_chanctx,
3648 .remove_chanctx = iwl_mvm_remove_chanctx,
3649 .change_chanctx = iwl_mvm_change_chanctx,
3650 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
3651 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
3652 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
3654 .start_ap = iwl_mvm_start_ap_ibss,
3655 .stop_ap = iwl_mvm_stop_ap_ibss,
3656 .join_ibss = iwl_mvm_start_ap_ibss,
3657 .leave_ibss = iwl_mvm_stop_ap_ibss,
3659 .set_tim = iwl_mvm_set_tim,
3661 .channel_switch = iwl_mvm_channel_switch,
3662 .pre_channel_switch = iwl_mvm_pre_channel_switch,
3663 .post_channel_switch = iwl_mvm_post_channel_switch,
3665 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
3666 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
3667 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
3669 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
3671 #ifdef CONFIG_PM_SLEEP
3673 .suspend = iwl_mvm_suspend,
3674 .resume = iwl_mvm_resume,
3675 .set_wakeup = iwl_mvm_set_wakeup,
3676 .set_rekey_data = iwl_mvm_set_rekey_data,
3677 #if IS_ENABLED(CONFIG_IPV6)
3678 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
3680 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,