iwlwifi: mvm: use the firmware to get the temperature during CT kill
[linux-2.6/btrfs-unstable.git] / drivers / net / wireless / iwlwifi / mvm / mac80211.c
blob5c33d2d154888dbba4ef1ceaa1e1ebf925537bda
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.
6 * GPL LICENSE SUMMARY
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,
23 * USA
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
32 * BSD LICENSE
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
40 * are met:
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
47 * distribution.
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>
70 #include <linux/ip.h>
71 #include <linux/if_arp.h>
72 #include <net/mac80211.h>
73 #include <net/ieee80211_radiotap.h>
74 #include <net/tcp.h>
76 #include "iwl-op-mode.h"
77 #include "iwl-io.h"
78 #include "mvm.h"
79 #include "sta.h"
80 #include "time-event.h"
81 #include "iwl-eeprom-parse.h"
82 #include "fw-api-scan.h"
83 #include "iwl-phy-db.h"
84 #include "testmode.h"
85 #include "iwl-fw-error-dump.h"
86 #include "iwl-prph.h"
88 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
90 .max = 1,
91 .types = BIT(NL80211_IFTYPE_STATION),
94 .max = 1,
95 .types = BIT(NL80211_IFTYPE_AP) |
96 BIT(NL80211_IFTYPE_P2P_CLIENT) |
97 BIT(NL80211_IFTYPE_P2P_GO),
100 .max = 1,
101 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
105 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
107 .num_different_channels = 1,
108 .max_interfaces = 3,
109 .limits = iwl_mvm_limits,
110 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
114 #ifdef CONFIG_PM_SLEEP
115 static const struct nl80211_wowlan_tcp_data_token_feature
116 iwl_mvm_wowlan_tcp_token_feature = {
117 .min_len = 0,
118 .max_len = 255,
119 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
122 static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
123 .tok = &iwl_mvm_wowlan_tcp_token_feature,
124 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
125 sizeof(struct ethhdr) -
126 sizeof(struct iphdr) -
127 sizeof(struct tcphdr),
128 .data_interval_max = 65535, /* __le16 in API */
129 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
130 sizeof(struct ethhdr) -
131 sizeof(struct iphdr) -
132 sizeof(struct tcphdr),
133 .seq = true,
135 #endif
137 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
139 * Use the reserved field to indicate magic values.
140 * these values will only be used internally by the driver,
141 * and won't make it to the fw (reserved will be 0).
142 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
143 * be the vif's ip address. in case there is not a single
144 * ip address (0, or more than 1), this attribute will
145 * be skipped.
146 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
147 * the LSB bytes of the vif's mac address
149 enum {
150 BC_FILTER_MAGIC_NONE = 0,
151 BC_FILTER_MAGIC_IP,
152 BC_FILTER_MAGIC_MAC,
155 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
157 /* arp */
158 .discard = 0,
159 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
160 .attrs = {
162 /* frame type - arp, hw type - ethernet */
163 .offset_type =
164 BCAST_FILTER_OFFSET_PAYLOAD_START,
165 .offset = sizeof(rfc1042_header),
166 .val = cpu_to_be32(0x08060001),
167 .mask = cpu_to_be32(0xffffffff),
170 /* arp dest ip */
171 .offset_type =
172 BCAST_FILTER_OFFSET_PAYLOAD_START,
173 .offset = sizeof(rfc1042_header) + 2 +
174 sizeof(struct arphdr) +
175 ETH_ALEN + sizeof(__be32) +
176 ETH_ALEN,
177 .mask = cpu_to_be32(0xffffffff),
178 /* mark it as special field */
179 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
184 /* dhcp offer bcast */
185 .discard = 0,
186 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
187 .attrs = {
189 /* udp dest port - 68 (bootp client)*/
190 .offset_type = BCAST_FILTER_OFFSET_IP_END,
191 .offset = offsetof(struct udphdr, dest),
192 .val = cpu_to_be32(0x00440000),
193 .mask = cpu_to_be32(0xffff0000),
196 /* dhcp - lsb bytes of client hw address */
197 .offset_type = BCAST_FILTER_OFFSET_IP_END,
198 .offset = 38,
199 .mask = cpu_to_be32(0xffffffff),
200 /* mark it as special field */
201 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
205 /* last filter must be empty */
208 #endif
210 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
212 if (!iwl_mvm_is_d0i3_supported(mvm))
213 return;
215 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
216 spin_lock_bh(&mvm->refs_lock);
217 mvm->refs[ref_type]++;
218 spin_unlock_bh(&mvm->refs_lock);
219 iwl_trans_ref(mvm->trans);
222 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
224 if (!iwl_mvm_is_d0i3_supported(mvm))
225 return;
227 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
228 spin_lock_bh(&mvm->refs_lock);
229 WARN_ON(!mvm->refs[ref_type]--);
230 spin_unlock_bh(&mvm->refs_lock);
231 iwl_trans_unref(mvm->trans);
234 static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
235 enum iwl_mvm_ref_type except_ref)
237 int i, j;
239 if (!iwl_mvm_is_d0i3_supported(mvm))
240 return;
242 spin_lock_bh(&mvm->refs_lock);
243 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
244 if (except_ref == i || !mvm->refs[i])
245 continue;
247 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
248 i, mvm->refs[i]);
249 for (j = 0; j < mvm->refs[i]; j++)
250 iwl_trans_unref(mvm->trans);
251 mvm->refs[i] = 0;
253 spin_unlock_bh(&mvm->refs_lock);
256 int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
258 iwl_mvm_ref(mvm, ref_type);
260 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
261 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
262 HZ)) {
263 WARN_ON_ONCE(1);
264 iwl_mvm_unref(mvm, ref_type);
265 return -EIO;
268 return 0;
271 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
273 int i;
275 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
276 for (i = 0; i < NUM_PHY_CTX; i++) {
277 mvm->phy_ctxts[i].id = i;
278 mvm->phy_ctxts[i].ref = 0;
282 static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
284 /* we create the 802.11 header and SSID element */
285 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID)
286 return mvm->fw->ucode_capa.max_probe_length - 24 - 2;
287 return mvm->fw->ucode_capa.max_probe_length - 24 - 34;
290 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
292 struct ieee80211_hw *hw = mvm->hw;
293 int num_mac, ret, i;
295 /* Tell mac80211 our characteristics */
296 hw->flags = IEEE80211_HW_SIGNAL_DBM |
297 IEEE80211_HW_SPECTRUM_MGMT |
298 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
299 IEEE80211_HW_QUEUE_CONTROL |
300 IEEE80211_HW_WANT_MONITOR_VIF |
301 IEEE80211_HW_SUPPORTS_PS |
302 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
303 IEEE80211_HW_AMPDU_AGGREGATION |
304 IEEE80211_HW_TIMING_BEACON_ONLY |
305 IEEE80211_HW_CONNECTION_MONITOR |
306 IEEE80211_HW_CHANCTX_STA_CSA |
307 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
308 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
310 hw->queues = mvm->first_agg_queue;
311 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
312 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
313 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
314 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC;
315 hw->rate_control_algorithm = "iwl-mvm-rs";
318 * Enable 11w if advertised by firmware and software crypto
319 * is not enabled (as the firmware will interpret some mgmt
320 * packets, so enabling it with software crypto isn't safe)
322 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
323 !iwlwifi_mod_params.sw_crypto)
324 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
326 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT &&
327 IWL_UCODE_API(mvm->fw->ucode_ver) >= 9 &&
328 !iwlwifi_mod_params.uapsd_disable) {
329 hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
330 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
331 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
334 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
335 hw->flags |= IEEE80211_SINGLE_HW_SCAN_ON_ALL_BANDS;
337 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
338 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
339 hw->chanctx_data_size = sizeof(u16);
341 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
342 BIT(NL80211_IFTYPE_P2P_CLIENT) |
343 BIT(NL80211_IFTYPE_AP) |
344 BIT(NL80211_IFTYPE_P2P_GO) |
345 BIT(NL80211_IFTYPE_P2P_DEVICE) |
346 BIT(NL80211_IFTYPE_ADHOC);
348 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
349 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
350 REGULATORY_DISABLE_BEACON_HINTS;
352 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
353 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
355 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_CSA_FLOW)
356 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
358 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
359 hw->wiphy->n_iface_combinations =
360 ARRAY_SIZE(iwl_mvm_iface_combinations);
362 hw->wiphy->max_remain_on_channel_duration = 10000;
363 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
365 /* Extract MAC address */
366 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
367 hw->wiphy->addresses = mvm->addresses;
368 hw->wiphy->n_addresses = 1;
370 /* Extract additional MAC addresses if available */
371 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
372 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
374 for (i = 1; i < num_mac; i++) {
375 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
376 ETH_ALEN);
377 mvm->addresses[i].addr[5]++;
378 hw->wiphy->n_addresses++;
381 iwl_mvm_reset_phy_ctxts(mvm);
383 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
385 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
387 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
388 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
389 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
390 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
391 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
392 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
394 hw->wiphy->hw_version = mvm->trans->hw_id;
396 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
397 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
398 else
399 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
401 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 10) {
402 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
403 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
404 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
405 /* we create the 802.11 header and zero length SSID IE. */
406 hw->wiphy->max_sched_scan_ie_len =
407 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
410 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
411 NL80211_FEATURE_LOW_PRIORITY_SCAN |
412 NL80211_FEATURE_P2P_GO_OPPPS;
414 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
416 /* currently FW API supports only one optional cipher scheme */
417 if (mvm->fw->cs[0].cipher) {
418 mvm->hw->n_cipher_schemes = 1;
419 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
422 #ifdef CONFIG_PM_SLEEP
423 if (iwl_mvm_is_d0i3_supported(mvm) &&
424 device_can_wakeup(mvm->trans->dev)) {
425 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
426 hw->wiphy->wowlan = &mvm->wowlan;
427 } else if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
428 mvm->trans->ops->d3_suspend &&
429 mvm->trans->ops->d3_resume &&
430 device_can_wakeup(mvm->trans->dev)) {
431 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
432 WIPHY_WOWLAN_DISCONNECT |
433 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
434 WIPHY_WOWLAN_RFKILL_RELEASE;
435 if (!iwlwifi_mod_params.sw_crypto)
436 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
437 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
438 WIPHY_WOWLAN_4WAY_HANDSHAKE;
440 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
441 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
442 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
443 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
444 hw->wiphy->wowlan = &mvm->wowlan;
446 #endif
448 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
449 /* assign default bcast filtering configuration */
450 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
451 #endif
453 ret = iwl_mvm_leds_init(mvm);
454 if (ret)
455 return ret;
457 ret = ieee80211_register_hw(mvm->hw);
458 if (ret)
459 iwl_mvm_leds_exit(mvm);
461 return ret;
464 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
465 struct ieee80211_sta *sta,
466 struct sk_buff *skb)
468 struct iwl_mvm_sta *mvmsta;
469 bool defer = false;
472 * double check the IN_D0I3 flag both before and after
473 * taking the spinlock, in order to prevent taking
474 * the spinlock when not needed.
476 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
477 return false;
479 spin_lock(&mvm->d0i3_tx_lock);
481 * testing the flag again ensures the skb dequeue
482 * loop (on d0i3 exit) hasn't run yet.
484 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
485 goto out;
487 mvmsta = iwl_mvm_sta_from_mac80211(sta);
488 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
489 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
490 goto out;
492 __skb_queue_tail(&mvm->d0i3_tx, skb);
493 ieee80211_stop_queues(mvm->hw);
495 /* trigger wakeup */
496 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
497 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
499 defer = true;
500 out:
501 spin_unlock(&mvm->d0i3_tx_lock);
502 return defer;
505 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
506 struct ieee80211_tx_control *control,
507 struct sk_buff *skb)
509 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
510 struct ieee80211_sta *sta = control->sta;
511 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
512 struct ieee80211_hdr *hdr = (void *)skb->data;
514 if (iwl_mvm_is_radio_killed(mvm)) {
515 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
516 goto drop;
519 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
520 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
521 goto drop;
523 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
524 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
525 ieee80211_is_mgmt(hdr->frame_control) &&
526 !ieee80211_is_deauth(hdr->frame_control) &&
527 !ieee80211_is_disassoc(hdr->frame_control) &&
528 !ieee80211_is_action(hdr->frame_control)))
529 sta = NULL;
531 if (sta) {
532 if (iwl_mvm_defer_tx(mvm, sta, skb))
533 return;
534 if (iwl_mvm_tx_skb(mvm, skb, sta))
535 goto drop;
536 return;
539 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
540 goto drop;
541 return;
542 drop:
543 ieee80211_free_txskb(hw, skb);
546 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
548 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
549 return false;
550 return true;
553 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
555 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
556 return false;
557 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
558 return true;
560 /* enabled by default */
561 return true;
564 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
565 struct ieee80211_vif *vif,
566 enum ieee80211_ampdu_mlme_action action,
567 struct ieee80211_sta *sta, u16 tid,
568 u16 *ssn, u8 buf_size)
570 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
571 int ret;
572 bool tx_agg_ref = false;
574 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
575 sta->addr, tid, action);
577 if (!(mvm->nvm_data->sku_cap_11n_enable))
578 return -EACCES;
580 /* return from D0i3 before starting a new Tx aggregation */
581 switch (action) {
582 case IEEE80211_AMPDU_TX_START:
583 case IEEE80211_AMPDU_TX_STOP_CONT:
584 case IEEE80211_AMPDU_TX_STOP_FLUSH:
585 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
586 case IEEE80211_AMPDU_TX_OPERATIONAL:
588 * for tx start, wait synchronously until D0i3 exit to
589 * get the correct sequence number for the tid.
590 * additionally, some other ampdu actions use direct
591 * target access, which is not handled automatically
592 * by the trans layer (unlike commands), so wait for
593 * d0i3 exit in these cases as well.
595 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
596 if (ret)
597 return ret;
599 tx_agg_ref = true;
600 break;
601 default:
602 break;
605 mutex_lock(&mvm->mutex);
607 switch (action) {
608 case IEEE80211_AMPDU_RX_START:
609 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
610 ret = -EINVAL;
611 break;
613 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
614 break;
615 case IEEE80211_AMPDU_RX_STOP:
616 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
617 break;
618 case IEEE80211_AMPDU_TX_START:
619 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
620 ret = -EINVAL;
621 break;
623 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
624 break;
625 case IEEE80211_AMPDU_TX_STOP_CONT:
626 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
627 break;
628 case IEEE80211_AMPDU_TX_STOP_FLUSH:
629 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
630 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
631 break;
632 case IEEE80211_AMPDU_TX_OPERATIONAL:
633 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
634 break;
635 default:
636 WARN_ON_ONCE(1);
637 ret = -EINVAL;
638 break;
640 mutex_unlock(&mvm->mutex);
643 * If the tid is marked as started, we won't use it for offloaded
644 * traffic on the next D0i3 entry. It's safe to unref.
646 if (tx_agg_ref)
647 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
649 return ret;
652 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
653 struct ieee80211_vif *vif)
655 struct iwl_mvm *mvm = data;
656 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
658 mvmvif->uploaded = false;
659 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
661 /* does this make sense at all? */
662 mvmvif->color++;
664 spin_lock_bh(&mvm->time_event_lock);
665 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
666 spin_unlock_bh(&mvm->time_event_lock);
668 mvmvif->phy_ctxt = NULL;
669 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
672 #ifdef CONFIG_IWLWIFI_DEBUGFS
673 static void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
675 struct iwl_fw_error_dump_file *dump_file;
676 struct iwl_fw_error_dump_data *dump_data;
677 struct iwl_fw_error_dump_info *dump_info;
678 struct iwl_mvm_dump_ptrs *fw_error_dump;
679 const struct fw_img *img;
680 u32 sram_len, sram_ofs;
681 u32 file_len, rxf_len;
682 unsigned long flags;
683 int reg_val;
685 lockdep_assert_held(&mvm->mutex);
687 if (mvm->fw_error_dump)
688 return;
690 fw_error_dump = kzalloc(sizeof(*mvm->fw_error_dump), GFP_KERNEL);
691 if (!fw_error_dump)
692 return;
694 img = &mvm->fw->img[mvm->cur_ucode];
695 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
696 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
698 /* reading buffer size */
699 reg_val = iwl_trans_read_prph(mvm->trans, RXF_SIZE_ADDR);
700 rxf_len = (reg_val & RXF_SIZE_BYTE_CNT_MSK) >> RXF_SIZE_BYTE_CND_POS;
702 /* the register holds the value divided by 128 */
703 rxf_len = rxf_len << 7;
705 file_len = sizeof(*dump_file) +
706 sizeof(*dump_data) * 3 +
707 sram_len +
708 rxf_len +
709 sizeof(*dump_info);
711 dump_file = vzalloc(file_len);
712 if (!dump_file) {
713 kfree(fw_error_dump);
714 return;
717 fw_error_dump->op_mode_ptr = dump_file;
719 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
720 dump_data = (void *)dump_file->data;
722 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
723 dump_data->len = cpu_to_le32(sizeof(*dump_info));
724 dump_info = (void *) dump_data->data;
725 dump_info->device_family =
726 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
727 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
728 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
729 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
730 sizeof(dump_info->fw_human_readable));
731 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
732 sizeof(dump_info->dev_human_readable));
733 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
734 sizeof(dump_info->bus_human_readable));
736 dump_data = iwl_fw_error_next_data(dump_data);
737 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
738 dump_data->len = cpu_to_le32(rxf_len);
740 if (iwl_trans_grab_nic_access(mvm->trans, false, &flags)) {
741 u32 *rxf = (void *)dump_data->data;
742 int i;
744 for (i = 0; i < (rxf_len / sizeof(u32)); i++) {
745 iwl_trans_write_prph(mvm->trans,
746 RXF_LD_FENCE_OFFSET_ADDR,
747 i * sizeof(u32));
748 rxf[i] = iwl_trans_read_prph(mvm->trans,
749 RXF_FIFO_RD_FENCE_ADDR);
751 iwl_trans_release_nic_access(mvm->trans, &flags);
754 dump_data = iwl_fw_error_next_data(dump_data);
755 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_SRAM);
756 dump_data->len = cpu_to_le32(sram_len);
757 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_data->data,
758 sram_len);
760 fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans);
761 fw_error_dump->op_mode_len = file_len;
762 if (fw_error_dump->trans_ptr)
763 file_len += fw_error_dump->trans_ptr->len;
764 dump_file->file_len = cpu_to_le32(file_len);
765 mvm->fw_error_dump = fw_error_dump;
767 #endif
769 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
771 #ifdef CONFIG_IWLWIFI_DEBUGFS
772 static char *env[] = { "DRIVER=iwlwifi", "EVENT=error_dump", NULL };
774 iwl_mvm_fw_error_dump(mvm);
776 /* notify the userspace about the error we had */
777 kobject_uevent_env(&mvm->hw->wiphy->dev.kobj, KOBJ_CHANGE, env);
778 #endif
780 iwl_trans_stop_device(mvm->trans);
782 mvm->scan_status = IWL_MVM_SCAN_NONE;
783 mvm->ps_disabled = false;
785 /* just in case one was running */
786 ieee80211_remain_on_channel_expired(mvm->hw);
788 ieee80211_iterate_active_interfaces_atomic(
789 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
790 iwl_mvm_cleanup_iterator, mvm);
792 mvm->p2p_device_vif = NULL;
793 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
795 iwl_mvm_reset_phy_ctxts(mvm);
796 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
797 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
798 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
799 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
800 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
801 memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
802 memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk));
803 memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk));
805 ieee80211_wake_queues(mvm->hw);
807 /* cleanup all stale references (scan, roc), but keep the
808 * ucode_down ref until reconfig is complete */
809 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
811 /* clear any stale d0i3 state */
812 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
814 mvm->vif_count = 0;
815 mvm->rx_ba_sessions = 0;
818 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
820 int ret;
822 lockdep_assert_held(&mvm->mutex);
824 /* Clean up some internal and mac80211 state on restart */
825 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
826 iwl_mvm_restart_cleanup(mvm);
828 ret = iwl_mvm_up(mvm);
830 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
831 /* Something went wrong - we need to finish some cleanup
832 * that normally iwl_mvm_mac_restart_complete() below
833 * would do.
835 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
836 iwl_mvm_d0i3_enable_tx(mvm, NULL);
839 return ret;
842 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
844 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
845 int ret;
847 mutex_lock(&mvm->mutex);
848 ret = __iwl_mvm_mac_start(mvm);
849 mutex_unlock(&mvm->mutex);
851 return ret;
854 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
856 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
857 int ret;
859 mutex_lock(&mvm->mutex);
861 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
862 iwl_mvm_d0i3_enable_tx(mvm, NULL);
863 ret = iwl_mvm_update_quotas(mvm, NULL);
864 if (ret)
865 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
866 ret);
868 /* allow transport/FW low power modes */
869 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
871 mutex_unlock(&mvm->mutex);
874 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
876 lockdep_assert_held(&mvm->mutex);
878 /* disallow low power states when the FW is down */
879 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
881 /* async_handlers_wk is now blocked */
884 * The work item could be running or queued if the
885 * ROC time event stops just as we get here.
887 cancel_work_sync(&mvm->roc_done_wk);
889 iwl_trans_stop_device(mvm->trans);
891 iwl_mvm_async_handlers_purge(mvm);
892 /* async_handlers_list is empty and will stay empty: HW is stopped */
894 /* the fw is stopped, the aux sta is dead: clean up driver state */
895 iwl_mvm_del_aux_sta(mvm);
897 mvm->ucode_loaded = false;
900 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
902 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
904 flush_work(&mvm->d0i3_exit_work);
905 flush_work(&mvm->async_handlers_wk);
907 mutex_lock(&mvm->mutex);
908 __iwl_mvm_mac_stop(mvm);
909 mutex_unlock(&mvm->mutex);
912 * The worker might have been waiting for the mutex, let it run and
913 * discover that its list is now empty.
915 cancel_work_sync(&mvm->async_handlers_wk);
918 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
920 u16 i;
922 lockdep_assert_held(&mvm->mutex);
924 for (i = 0; i < NUM_PHY_CTX; i++)
925 if (!mvm->phy_ctxts[i].ref)
926 return &mvm->phy_ctxts[i];
928 IWL_ERR(mvm, "No available PHY context\n");
929 return NULL;
932 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
933 s8 tx_power)
935 /* FW is in charge of regulatory enforcement */
936 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
937 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
938 .pwr_restriction = cpu_to_le16(tx_power),
941 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
942 sizeof(reduce_txpwr_cmd),
943 &reduce_txpwr_cmd);
946 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
947 struct ieee80211_vif *vif)
949 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
950 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
951 int ret;
954 * make sure D0i3 exit is completed, otherwise a target access
955 * during tx queue configuration could be done when still in
956 * D0i3 state.
958 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
959 if (ret)
960 return ret;
963 * Not much to do here. The stack will not allow interface
964 * types or combinations that we didn't advertise, so we
965 * don't really have to check the types.
968 mutex_lock(&mvm->mutex);
970 /* Allocate resources for the MAC context, and add it to the fw */
971 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
972 if (ret)
973 goto out_unlock;
975 /* Counting number of interfaces is needed for legacy PM */
976 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
977 mvm->vif_count++;
980 * The AP binding flow can be done only after the beacon
981 * template is configured (which happens only in the mac80211
982 * start_ap() flow), and adding the broadcast station can happen
983 * only after the binding.
984 * In addition, since modifying the MAC before adding a bcast
985 * station is not allowed by the FW, delay the adding of MAC context to
986 * the point where we can also add the bcast station.
987 * In short: there's not much we can do at this point, other than
988 * allocating resources :)
990 if (vif->type == NL80211_IFTYPE_AP ||
991 vif->type == NL80211_IFTYPE_ADHOC) {
992 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
993 if (ret) {
994 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
995 goto out_release;
998 iwl_mvm_vif_dbgfs_register(mvm, vif);
999 goto out_unlock;
1002 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1003 if (ret)
1004 goto out_release;
1006 ret = iwl_mvm_power_update_mac(mvm);
1007 if (ret)
1008 goto out_release;
1010 /* beacon filtering */
1011 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1012 if (ret)
1013 goto out_remove_mac;
1015 if (!mvm->bf_allowed_vif &&
1016 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1017 mvm->bf_allowed_vif = mvmvif;
1018 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1019 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1023 * P2P_DEVICE interface does not have a channel context assigned to it,
1024 * so a dedicated PHY context is allocated to it and the corresponding
1025 * MAC context is bound to it at this stage.
1027 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1029 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1030 if (!mvmvif->phy_ctxt) {
1031 ret = -ENOSPC;
1032 goto out_free_bf;
1035 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1036 ret = iwl_mvm_binding_add_vif(mvm, vif);
1037 if (ret)
1038 goto out_unref_phy;
1040 ret = iwl_mvm_add_bcast_sta(mvm, vif);
1041 if (ret)
1042 goto out_unbind;
1044 /* Save a pointer to p2p device vif, so it can later be used to
1045 * update the p2p device MAC when a GO is started/stopped */
1046 mvm->p2p_device_vif = vif;
1049 iwl_mvm_vif_dbgfs_register(mvm, vif);
1050 goto out_unlock;
1052 out_unbind:
1053 iwl_mvm_binding_remove_vif(mvm, vif);
1054 out_unref_phy:
1055 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1056 out_free_bf:
1057 if (mvm->bf_allowed_vif == mvmvif) {
1058 mvm->bf_allowed_vif = NULL;
1059 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1060 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1062 out_remove_mac:
1063 mvmvif->phy_ctxt = NULL;
1064 iwl_mvm_mac_ctxt_remove(mvm, vif);
1065 out_release:
1066 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1067 mvm->vif_count--;
1069 iwl_mvm_mac_ctxt_release(mvm, vif);
1070 out_unlock:
1071 mutex_unlock(&mvm->mutex);
1073 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1075 return ret;
1078 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1079 struct ieee80211_vif *vif)
1081 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(mvm, vif);
1083 if (tfd_msk) {
1084 mutex_lock(&mvm->mutex);
1085 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
1086 mutex_unlock(&mvm->mutex);
1089 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1091 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1092 * We assume here that all the packets sent to the OFFCHANNEL
1093 * queue are sent in ROC session.
1095 flush_work(&mvm->roc_done_wk);
1096 } else {
1098 * By now, all the AC queues are empty. The AGG queues are
1099 * empty too. We already got all the Tx responses for all the
1100 * packets in the queues. The drain work can have been
1101 * triggered. Flush it.
1103 flush_work(&mvm->sta_drained_wk);
1107 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1108 struct ieee80211_vif *vif)
1110 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1111 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1113 iwl_mvm_prepare_mac_removal(mvm, vif);
1115 mutex_lock(&mvm->mutex);
1117 if (mvm->bf_allowed_vif == mvmvif) {
1118 mvm->bf_allowed_vif = NULL;
1119 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1120 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1123 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1126 * For AP/GO interface, the tear down of the resources allocated to the
1127 * interface is be handled as part of the stop_ap flow.
1129 if (vif->type == NL80211_IFTYPE_AP ||
1130 vif->type == NL80211_IFTYPE_ADHOC) {
1131 #ifdef CONFIG_NL80211_TESTMODE
1132 if (vif == mvm->noa_vif) {
1133 mvm->noa_vif = NULL;
1134 mvm->noa_duration = 0;
1136 #endif
1137 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1138 goto out_release;
1141 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1142 mvm->p2p_device_vif = NULL;
1143 iwl_mvm_rm_bcast_sta(mvm, vif);
1144 iwl_mvm_binding_remove_vif(mvm, vif);
1145 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1146 mvmvif->phy_ctxt = NULL;
1149 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1150 mvm->vif_count--;
1152 iwl_mvm_power_update_mac(mvm);
1153 iwl_mvm_mac_ctxt_remove(mvm, vif);
1155 out_release:
1156 iwl_mvm_mac_ctxt_release(mvm, vif);
1157 mutex_unlock(&mvm->mutex);
1160 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1162 return 0;
1165 struct iwl_mvm_mc_iter_data {
1166 struct iwl_mvm *mvm;
1167 int port_id;
1170 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1171 struct ieee80211_vif *vif)
1173 struct iwl_mvm_mc_iter_data *data = _data;
1174 struct iwl_mvm *mvm = data->mvm;
1175 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1176 int ret, len;
1178 /* if we don't have free ports, mcast frames will be dropped */
1179 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1180 return;
1182 if (vif->type != NL80211_IFTYPE_STATION ||
1183 !vif->bss_conf.assoc)
1184 return;
1186 cmd->port_id = data->port_id++;
1187 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1188 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1190 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
1191 if (ret)
1192 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1195 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1197 struct iwl_mvm_mc_iter_data iter_data = {
1198 .mvm = mvm,
1201 lockdep_assert_held(&mvm->mutex);
1203 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1204 return;
1206 ieee80211_iterate_active_interfaces_atomic(
1207 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1208 iwl_mvm_mc_iface_iterator, &iter_data);
1211 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1212 struct netdev_hw_addr_list *mc_list)
1214 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1215 struct iwl_mcast_filter_cmd *cmd;
1216 struct netdev_hw_addr *addr;
1217 int addr_count;
1218 bool pass_all;
1219 int len;
1221 addr_count = netdev_hw_addr_list_count(mc_list);
1222 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1223 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1224 if (pass_all)
1225 addr_count = 0;
1227 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1228 cmd = kzalloc(len, GFP_ATOMIC);
1229 if (!cmd)
1230 return 0;
1232 if (pass_all) {
1233 cmd->pass_all = 1;
1234 return (u64)(unsigned long)cmd;
1237 netdev_hw_addr_list_for_each(addr, mc_list) {
1238 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1239 cmd->count, addr->addr);
1240 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1241 addr->addr, ETH_ALEN);
1242 cmd->count++;
1245 return (u64)(unsigned long)cmd;
1248 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1249 unsigned int changed_flags,
1250 unsigned int *total_flags,
1251 u64 multicast)
1253 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1254 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1256 mutex_lock(&mvm->mutex);
1258 /* replace previous configuration */
1259 kfree(mvm->mcast_filter_cmd);
1260 mvm->mcast_filter_cmd = cmd;
1262 if (!cmd)
1263 goto out;
1265 iwl_mvm_recalc_multicast(mvm);
1266 out:
1267 mutex_unlock(&mvm->mutex);
1268 *total_flags = 0;
1271 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1272 struct iwl_bcast_iter_data {
1273 struct iwl_mvm *mvm;
1274 struct iwl_bcast_filter_cmd *cmd;
1275 u8 current_filter;
1278 static void
1279 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1280 const struct iwl_fw_bcast_filter *in_filter,
1281 struct iwl_fw_bcast_filter *out_filter)
1283 struct iwl_fw_bcast_filter_attr *attr;
1284 int i;
1286 memcpy(out_filter, in_filter, sizeof(*out_filter));
1288 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1289 attr = &out_filter->attrs[i];
1291 if (!attr->mask)
1292 break;
1294 switch (attr->reserved1) {
1295 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1296 if (vif->bss_conf.arp_addr_cnt != 1) {
1297 attr->mask = 0;
1298 continue;
1301 attr->val = vif->bss_conf.arp_addr_list[0];
1302 break;
1303 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1304 attr->val = *(__be32 *)&vif->addr[2];
1305 break;
1306 default:
1307 break;
1309 attr->reserved1 = 0;
1310 out_filter->num_attrs++;
1314 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1315 struct ieee80211_vif *vif)
1317 struct iwl_bcast_iter_data *data = _data;
1318 struct iwl_mvm *mvm = data->mvm;
1319 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1320 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1321 struct iwl_fw_bcast_mac *bcast_mac;
1322 int i;
1324 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1325 return;
1327 bcast_mac = &cmd->macs[mvmvif->id];
1330 * enable filtering only for associated stations, but not for P2P
1331 * Clients
1333 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1334 !vif->bss_conf.assoc)
1335 return;
1337 bcast_mac->default_discard = 1;
1339 /* copy all configured filters */
1340 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1342 * Make sure we don't exceed our filters limit.
1343 * if there is still a valid filter to be configured,
1344 * be on the safe side and just allow bcast for this mac.
1346 if (WARN_ON_ONCE(data->current_filter >=
1347 ARRAY_SIZE(cmd->filters))) {
1348 bcast_mac->default_discard = 0;
1349 bcast_mac->attached_filters = 0;
1350 break;
1353 iwl_mvm_set_bcast_filter(vif,
1354 &mvm->bcast_filters[i],
1355 &cmd->filters[data->current_filter]);
1357 /* skip current filter if it contains no attributes */
1358 if (!cmd->filters[data->current_filter].num_attrs)
1359 continue;
1361 /* attach the filter to current mac */
1362 bcast_mac->attached_filters |=
1363 cpu_to_le16(BIT(data->current_filter));
1365 data->current_filter++;
1369 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1370 struct iwl_bcast_filter_cmd *cmd)
1372 struct iwl_bcast_iter_data iter_data = {
1373 .mvm = mvm,
1374 .cmd = cmd,
1377 memset(cmd, 0, sizeof(*cmd));
1378 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1379 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1381 #ifdef CONFIG_IWLWIFI_DEBUGFS
1382 /* use debugfs filters/macs if override is configured */
1383 if (mvm->dbgfs_bcast_filtering.override) {
1384 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1385 sizeof(cmd->filters));
1386 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1387 sizeof(cmd->macs));
1388 return true;
1390 #endif
1392 /* if no filters are configured, do nothing */
1393 if (!mvm->bcast_filters)
1394 return false;
1396 /* configure and attach these filters for each associated sta vif */
1397 ieee80211_iterate_active_interfaces(
1398 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1399 iwl_mvm_bcast_filter_iterator, &iter_data);
1401 return true;
1403 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1404 struct ieee80211_vif *vif)
1406 struct iwl_bcast_filter_cmd cmd;
1408 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1409 return 0;
1411 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1412 return 0;
1414 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1415 sizeof(cmd), &cmd);
1417 #else
1418 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1419 struct ieee80211_vif *vif)
1421 return 0;
1423 #endif
1425 static void iwl_mvm_teardown_tdls_peers(struct iwl_mvm *mvm)
1427 struct ieee80211_sta *sta;
1428 struct iwl_mvm_sta *mvmsta;
1429 int i;
1431 lockdep_assert_held(&mvm->mutex);
1433 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
1434 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
1435 lockdep_is_held(&mvm->mutex));
1436 if (!sta || IS_ERR(sta) || !sta->tdls)
1437 continue;
1439 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1440 ieee80211_tdls_oper_request(mvmsta->vif, sta->addr,
1441 NL80211_TDLS_TEARDOWN,
1442 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED,
1443 GFP_KERNEL);
1447 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1448 struct ieee80211_vif *vif,
1449 struct ieee80211_bss_conf *bss_conf,
1450 u32 changes)
1452 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1453 int ret;
1456 * Re-calculate the tsf id, as the master-slave relations depend on the
1457 * beacon interval, which was not known when the station interface was
1458 * added.
1460 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1461 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1464 * If we're not associated yet, take the (new) BSSID before associating
1465 * so the firmware knows. If we're already associated, then use the old
1466 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1467 * branch for disassociation below.
1469 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1470 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1472 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
1473 if (ret)
1474 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1476 /* after sending it once, adopt mac80211 data */
1477 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1478 mvmvif->associated = bss_conf->assoc;
1480 if (changes & BSS_CHANGED_ASSOC) {
1481 if (bss_conf->assoc) {
1482 /* add quota for this interface */
1483 ret = iwl_mvm_update_quotas(mvm, NULL);
1484 if (ret) {
1485 IWL_ERR(mvm, "failed to update quotas\n");
1486 return;
1489 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1490 &mvm->status)) {
1492 * If we're restarting then the firmware will
1493 * obviously have lost synchronisation with
1494 * the AP. It will attempt to synchronise by
1495 * itself, but we can make it more reliable by
1496 * scheduling a session protection time event.
1498 * The firmware needs to receive a beacon to
1499 * catch up with synchronisation, use 110% of
1500 * the beacon interval.
1502 * Set a large maximum delay to allow for more
1503 * than a single interface.
1505 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1506 iwl_mvm_protect_session(mvm, vif, dur, dur,
1507 5 * dur, false);
1510 iwl_mvm_sf_update(mvm, vif, false);
1511 iwl_mvm_power_vif_assoc(mvm, vif);
1512 if (vif->p2p) {
1513 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
1514 iwl_mvm_update_smps(mvm, vif,
1515 IWL_MVM_SMPS_REQ_PROT,
1516 IEEE80211_SMPS_DYNAMIC);
1518 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1520 * If update fails - SF might be running in associated
1521 * mode while disassociated - which is forbidden.
1523 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1524 "Failed to update SF upon disassociation\n");
1526 /* remove AP station now that the MAC is unassoc */
1527 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1528 if (ret)
1529 IWL_ERR(mvm, "failed to remove AP station\n");
1531 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1532 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1533 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1534 /* remove quota for this interface */
1535 ret = iwl_mvm_update_quotas(mvm, NULL);
1536 if (ret)
1537 IWL_ERR(mvm, "failed to update quotas\n");
1539 if (vif->p2p)
1540 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
1542 /* this will take the cleared BSSID from bss_conf */
1543 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1544 if (ret)
1545 IWL_ERR(mvm,
1546 "failed to update MAC %pM (clear after unassoc)\n",
1547 vif->addr);
1550 iwl_mvm_recalc_multicast(mvm);
1551 iwl_mvm_configure_bcast_filter(mvm, vif);
1553 /* reset rssi values */
1554 mvmvif->bf_data.ave_beacon_signal = 0;
1556 iwl_mvm_bt_coex_vif_change(mvm);
1557 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1558 IEEE80211_SMPS_AUTOMATIC);
1559 } else if (changes & BSS_CHANGED_BEACON_INFO) {
1561 * We received a beacon _after_ association so
1562 * remove the session protection.
1564 iwl_mvm_remove_time_event(mvm, mvmvif,
1565 &mvmvif->time_event_data);
1568 if (changes & BSS_CHANGED_BEACON_INFO) {
1569 iwl_mvm_sf_update(mvm, vif, false);
1570 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1573 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS)) {
1574 ret = iwl_mvm_power_update_mac(mvm);
1575 if (ret)
1576 IWL_ERR(mvm, "failed to update power mode\n");
1579 if (changes & BSS_CHANGED_TXPOWER) {
1580 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1581 bss_conf->txpower);
1582 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1585 if (changes & BSS_CHANGED_CQM) {
1586 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
1587 /* reset cqm events tracking */
1588 mvmvif->bf_data.last_cqm_event = 0;
1589 if (mvmvif->bf_data.bf_enabled) {
1590 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1591 if (ret)
1592 IWL_ERR(mvm,
1593 "failed to update CQM thresholds\n");
1597 if (changes & BSS_CHANGED_ARP_FILTER) {
1598 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
1599 iwl_mvm_configure_bcast_filter(mvm, vif);
1603 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1604 struct ieee80211_vif *vif)
1606 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1607 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1608 int ret;
1611 * iwl_mvm_mac_ctxt_add() might read directly from the device
1612 * (the system time), so make sure it is available.
1614 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
1615 if (ret)
1616 return ret;
1618 mutex_lock(&mvm->mutex);
1620 /* Send the beacon template */
1621 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1622 if (ret)
1623 goto out_unlock;
1626 * Re-calculate the tsf id, as the master-slave relations depend on the
1627 * beacon interval, which was not known when the AP interface was added.
1629 if (vif->type == NL80211_IFTYPE_AP)
1630 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1632 /* Add the mac context */
1633 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1634 if (ret)
1635 goto out_unlock;
1637 /* Perform the binding */
1638 ret = iwl_mvm_binding_add_vif(mvm, vif);
1639 if (ret)
1640 goto out_remove;
1642 /* Send the bcast station. At this stage the TBTT and DTIM time events
1643 * are added and applied to the scheduler */
1644 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
1645 if (ret)
1646 goto out_unbind;
1648 /* must be set before quota calculations */
1649 mvmvif->ap_ibss_active = true;
1651 /* power updated needs to be done before quotas */
1652 iwl_mvm_power_update_mac(mvm);
1654 ret = iwl_mvm_update_quotas(mvm, NULL);
1655 if (ret)
1656 goto out_quota_failed;
1658 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1659 if (vif->p2p && mvm->p2p_device_vif)
1660 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
1662 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1664 iwl_mvm_bt_coex_vif_change(mvm);
1666 /* we don't support TDLS during DCM */
1667 if (iwl_mvm_phy_ctx_count(mvm) > 1)
1668 iwl_mvm_teardown_tdls_peers(mvm);
1670 mutex_unlock(&mvm->mutex);
1671 return 0;
1673 out_quota_failed:
1674 iwl_mvm_power_update_mac(mvm);
1675 mvmvif->ap_ibss_active = false;
1676 iwl_mvm_send_rm_bcast_sta(mvm, vif);
1677 out_unbind:
1678 iwl_mvm_binding_remove_vif(mvm, vif);
1679 out_remove:
1680 iwl_mvm_mac_ctxt_remove(mvm, vif);
1681 out_unlock:
1682 mutex_unlock(&mvm->mutex);
1683 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
1684 return ret;
1687 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1688 struct ieee80211_vif *vif)
1690 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1691 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1693 iwl_mvm_prepare_mac_removal(mvm, vif);
1695 mutex_lock(&mvm->mutex);
1697 /* Handle AP stop while in CSA */
1698 if (rcu_access_pointer(mvm->csa_vif) == vif) {
1699 iwl_mvm_remove_time_event(mvm, mvmvif,
1700 &mvmvif->time_event_data);
1701 RCU_INIT_POINTER(mvm->csa_vif, NULL);
1704 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
1705 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
1706 mvm->csa_tx_block_bcn_timeout = 0;
1709 mvmvif->ap_ibss_active = false;
1710 mvm->ap_last_beacon_gp2 = 0;
1712 iwl_mvm_bt_coex_vif_change(mvm);
1714 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
1716 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1717 if (vif->p2p && mvm->p2p_device_vif)
1718 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
1720 iwl_mvm_update_quotas(mvm, NULL);
1721 iwl_mvm_send_rm_bcast_sta(mvm, vif);
1722 iwl_mvm_binding_remove_vif(mvm, vif);
1724 iwl_mvm_power_update_mac(mvm);
1726 iwl_mvm_mac_ctxt_remove(mvm, vif);
1728 mutex_unlock(&mvm->mutex);
1731 static void
1732 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1733 struct ieee80211_vif *vif,
1734 struct ieee80211_bss_conf *bss_conf,
1735 u32 changes)
1737 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1739 /* Changes will be applied when the AP/IBSS is started */
1740 if (!mvmvif->ap_ibss_active)
1741 return;
1743 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
1744 BSS_CHANGED_BANDWIDTH) &&
1745 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
1746 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1748 /* Need to send a new beacon template to the FW */
1749 if (changes & BSS_CHANGED_BEACON &&
1750 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1751 IWL_WARN(mvm, "Failed updating beacon data\n");
1754 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1755 struct ieee80211_vif *vif,
1756 struct ieee80211_bss_conf *bss_conf,
1757 u32 changes)
1759 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1762 * iwl_mvm_bss_info_changed_station() might call
1763 * iwl_mvm_protect_session(), which reads directly from
1764 * the device (the system time), so make sure it is available.
1766 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
1767 return;
1769 mutex_lock(&mvm->mutex);
1771 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
1772 iwl_mvm_scan_offload_stop(mvm, true);
1774 switch (vif->type) {
1775 case NL80211_IFTYPE_STATION:
1776 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1777 break;
1778 case NL80211_IFTYPE_AP:
1779 case NL80211_IFTYPE_ADHOC:
1780 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
1781 break;
1782 default:
1783 /* shouldn't happen */
1784 WARN_ON_ONCE(1);
1787 mutex_unlock(&mvm->mutex);
1788 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
1791 static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm,
1792 enum iwl_scan_status scan_type)
1794 int ret;
1795 bool wait_for_handlers = false;
1797 mutex_lock(&mvm->mutex);
1799 if (mvm->scan_status != scan_type) {
1800 ret = 0;
1801 /* make sure there are no pending notifications */
1802 wait_for_handlers = true;
1803 goto out;
1806 switch (scan_type) {
1807 case IWL_MVM_SCAN_SCHED:
1808 ret = iwl_mvm_scan_offload_stop(mvm, true);
1809 break;
1810 case IWL_MVM_SCAN_OS:
1811 ret = iwl_mvm_cancel_scan(mvm);
1812 break;
1813 case IWL_MVM_SCAN_NONE:
1814 default:
1815 WARN_ON_ONCE(1);
1816 ret = -EINVAL;
1817 break;
1819 if (ret)
1820 goto out;
1822 wait_for_handlers = true;
1823 out:
1824 mutex_unlock(&mvm->mutex);
1826 /* make sure we consume the completion notification */
1827 if (wait_for_handlers)
1828 iwl_mvm_wait_for_async_handlers(mvm);
1830 return ret;
1832 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1833 struct ieee80211_vif *vif,
1834 struct ieee80211_scan_request *hw_req)
1836 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1837 struct cfg80211_scan_request *req = &hw_req->req;
1838 int ret;
1840 if (req->n_channels == 0 ||
1841 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
1842 return -EINVAL;
1844 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_SCHED);
1845 if (ret)
1846 return ret;
1848 mutex_lock(&mvm->mutex);
1850 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
1851 ret = -EBUSY;
1852 goto out;
1855 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1857 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
1858 ret = iwl_mvm_unified_scan_lmac(mvm, vif, hw_req);
1859 else
1860 ret = iwl_mvm_scan_request(mvm, vif, req);
1862 if (ret)
1863 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1864 out:
1865 mutex_unlock(&mvm->mutex);
1866 return ret;
1869 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1870 struct ieee80211_vif *vif)
1872 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1874 mutex_lock(&mvm->mutex);
1876 iwl_mvm_cancel_scan(mvm);
1878 mutex_unlock(&mvm->mutex);
1881 static void
1882 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
1883 struct ieee80211_sta *sta, u16 tids,
1884 int num_frames,
1885 enum ieee80211_frame_release_type reason,
1886 bool more_data)
1888 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1890 /* Called when we need to transmit (a) frame(s) from mac80211 */
1892 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1893 tids, more_data, false);
1896 static void
1897 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
1898 struct ieee80211_sta *sta, u16 tids,
1899 int num_frames,
1900 enum ieee80211_frame_release_type reason,
1901 bool more_data)
1903 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1905 /* Called when we need to transmit (a) frame(s) from agg queue */
1907 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1908 tids, more_data, true);
1911 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1912 struct ieee80211_vif *vif,
1913 enum sta_notify_cmd cmd,
1914 struct ieee80211_sta *sta)
1916 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1917 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1918 int tid;
1920 switch (cmd) {
1921 case STA_NOTIFY_SLEEP:
1922 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
1923 ieee80211_sta_block_awake(hw, sta, true);
1924 spin_lock_bh(&mvmsta->lock);
1925 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1926 struct iwl_mvm_tid_data *tid_data;
1928 tid_data = &mvmsta->tid_data[tid];
1929 if (tid_data->state != IWL_AGG_ON &&
1930 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
1931 continue;
1932 if (iwl_mvm_tid_queued(tid_data) == 0)
1933 continue;
1934 ieee80211_sta_set_buffered(sta, tid, true);
1936 spin_unlock_bh(&mvmsta->lock);
1938 * The fw updates the STA to be asleep. Tx packets on the Tx
1939 * queues to this station will not be transmitted. The fw will
1940 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1942 break;
1943 case STA_NOTIFY_AWAKE:
1944 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
1945 break;
1946 iwl_mvm_sta_modify_ps_wake(mvm, sta);
1947 break;
1948 default:
1949 break;
1953 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
1954 struct ieee80211_vif *vif,
1955 struct ieee80211_sta *sta)
1957 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1958 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1961 * This is called before mac80211 does RCU synchronisation,
1962 * so here we already invalidate our internal RCU-protected
1963 * station pointer. The rest of the code will thus no longer
1964 * be able to find the station this way, and we don't rely
1965 * on further RCU synchronisation after the sta_state()
1966 * callback deleted the station.
1968 mutex_lock(&mvm->mutex);
1969 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
1970 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1971 ERR_PTR(-ENOENT));
1972 mutex_unlock(&mvm->mutex);
1975 int iwl_mvm_tdls_sta_count(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1977 struct ieee80211_sta *sta;
1978 struct iwl_mvm_sta *mvmsta;
1979 int count = 0;
1980 int i;
1982 lockdep_assert_held(&mvm->mutex);
1984 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
1985 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
1986 lockdep_is_held(&mvm->mutex));
1987 if (!sta || IS_ERR(sta) || !sta->tdls)
1988 continue;
1990 if (vif) {
1991 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1992 if (mvmsta->vif != vif)
1993 continue;
1996 count++;
1999 return count;
2002 static void iwl_mvm_recalc_tdls_state(struct iwl_mvm *mvm,
2003 struct ieee80211_vif *vif,
2004 bool sta_added)
2006 int tdls_sta_cnt = iwl_mvm_tdls_sta_count(mvm, vif);
2009 * Disable ps when the first TDLS sta is added and re-enable it
2010 * when the last TDLS sta is removed
2012 if ((tdls_sta_cnt == 1 && sta_added) ||
2013 (tdls_sta_cnt == 0 && !sta_added))
2014 iwl_mvm_power_update_mac(mvm);
2017 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2018 struct ieee80211_vif *vif,
2019 struct ieee80211_sta *sta,
2020 enum ieee80211_sta_state old_state,
2021 enum ieee80211_sta_state new_state)
2023 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2024 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2025 int ret;
2027 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2028 sta->addr, old_state, new_state);
2030 /* this would be a mac80211 bug ... but don't crash */
2031 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2032 return -EINVAL;
2034 /* if a STA is being removed, reuse its ID */
2035 flush_work(&mvm->sta_drained_wk);
2037 mutex_lock(&mvm->mutex);
2038 if (old_state == IEEE80211_STA_NOTEXIST &&
2039 new_state == IEEE80211_STA_NONE) {
2041 * Firmware bug - it'll crash if the beacon interval is less
2042 * than 16. We can't avoid connecting at all, so refuse the
2043 * station state change, this will cause mac80211 to abandon
2044 * attempts to connect to this AP, and eventually wpa_s will
2045 * blacklist the AP...
2047 if (vif->type == NL80211_IFTYPE_STATION &&
2048 vif->bss_conf.beacon_int < 16) {
2049 IWL_ERR(mvm,
2050 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2051 sta->addr, vif->bss_conf.beacon_int);
2052 ret = -EINVAL;
2053 goto out_unlock;
2056 if (sta->tdls &&
2057 (vif->p2p ||
2058 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2059 IWL_MVM_TDLS_STA_COUNT ||
2060 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2061 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2062 ret = -EBUSY;
2063 goto out_unlock;
2066 ret = iwl_mvm_add_sta(mvm, vif, sta);
2067 if (sta->tdls && ret == 0)
2068 iwl_mvm_recalc_tdls_state(mvm, vif, true);
2069 } else if (old_state == IEEE80211_STA_NONE &&
2070 new_state == IEEE80211_STA_AUTH) {
2072 * EBS may be disabled due to previous failures reported by FW.
2073 * Reset EBS status here assuming environment has been changed.
2075 mvm->last_ebs_successful = true;
2076 ret = 0;
2077 } else if (old_state == IEEE80211_STA_AUTH &&
2078 new_state == IEEE80211_STA_ASSOC) {
2079 ret = iwl_mvm_update_sta(mvm, vif, sta);
2080 if (ret == 0)
2081 iwl_mvm_rs_rate_init(mvm, sta,
2082 mvmvif->phy_ctxt->channel->band,
2083 true);
2084 } else if (old_state == IEEE80211_STA_ASSOC &&
2085 new_state == IEEE80211_STA_AUTHORIZED) {
2087 /* we don't support TDLS during DCM */
2088 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2089 iwl_mvm_teardown_tdls_peers(mvm);
2091 /* enable beacon filtering */
2092 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2093 ret = 0;
2094 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2095 new_state == IEEE80211_STA_ASSOC) {
2096 /* disable beacon filtering */
2097 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
2098 ret = 0;
2099 } else if (old_state == IEEE80211_STA_ASSOC &&
2100 new_state == IEEE80211_STA_AUTH) {
2101 ret = 0;
2102 } else if (old_state == IEEE80211_STA_AUTH &&
2103 new_state == IEEE80211_STA_NONE) {
2104 ret = 0;
2105 } else if (old_state == IEEE80211_STA_NONE &&
2106 new_state == IEEE80211_STA_NOTEXIST) {
2107 ret = iwl_mvm_rm_sta(mvm, vif, sta);
2108 if (sta->tdls)
2109 iwl_mvm_recalc_tdls_state(mvm, vif, false);
2110 } else {
2111 ret = -EIO;
2113 out_unlock:
2114 mutex_unlock(&mvm->mutex);
2116 return ret;
2119 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2121 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2123 mvm->rts_threshold = value;
2125 return 0;
2128 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2129 struct ieee80211_vif *vif,
2130 struct ieee80211_sta *sta, u32 changed)
2132 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2134 if (vif->type == NL80211_IFTYPE_STATION &&
2135 changed & IEEE80211_RC_NSS_CHANGED)
2136 iwl_mvm_sf_update(mvm, vif, false);
2139 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2140 struct ieee80211_vif *vif, u16 ac,
2141 const struct ieee80211_tx_queue_params *params)
2143 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2144 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2146 mvmvif->queue_params[ac] = *params;
2149 * No need to update right away, we'll get BSS_CHANGED_QOS
2150 * The exception is P2P_DEVICE interface which needs immediate update.
2152 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2153 int ret;
2155 mutex_lock(&mvm->mutex);
2156 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2157 mutex_unlock(&mvm->mutex);
2158 return ret;
2160 return 0;
2163 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2164 struct ieee80211_vif *vif)
2166 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2167 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
2168 200 + vif->bss_conf.beacon_int);
2169 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
2170 100 + vif->bss_conf.beacon_int);
2172 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2173 return;
2176 * iwl_mvm_protect_session() reads directly from the device
2177 * (the system time), so make sure it is available.
2179 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2180 return;
2182 mutex_lock(&mvm->mutex);
2183 /* Try really hard to protect the session and hear a beacon */
2184 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
2185 mutex_unlock(&mvm->mutex);
2187 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
2190 static void iwl_mvm_mac_mgd_protect_tdls_discover(struct ieee80211_hw *hw,
2191 struct ieee80211_vif *vif)
2193 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2194 u32 duration = 2 * vif->bss_conf.dtim_period * vif->bss_conf.beacon_int;
2197 * iwl_mvm_protect_session() reads directly from the device
2198 * (the system time), so make sure it is available.
2200 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_TDLS))
2201 return;
2203 mutex_lock(&mvm->mutex);
2204 /* Protect the session to hear the TDLS setup response on the channel */
2205 iwl_mvm_protect_session(mvm, vif, duration, duration, 100, true);
2206 mutex_unlock(&mvm->mutex);
2208 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_TDLS);
2211 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2212 struct ieee80211_vif *vif,
2213 struct cfg80211_sched_scan_request *req,
2214 struct ieee80211_scan_ies *ies)
2216 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2217 int ret;
2219 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS);
2220 if (ret)
2221 return ret;
2223 mutex_lock(&mvm->mutex);
2225 if (!iwl_mvm_is_idle(mvm)) {
2226 ret = -EBUSY;
2227 goto out;
2230 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
2231 ret = -EBUSY;
2232 goto out;
2235 mvm->scan_status = IWL_MVM_SCAN_SCHED;
2237 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)) {
2238 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
2239 if (ret)
2240 goto err;
2243 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
2244 if (ret)
2245 goto err;
2247 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
2248 ret = iwl_mvm_unified_sched_scan_lmac(mvm, vif, req, ies);
2249 else
2250 ret = iwl_mvm_sched_scan_start(mvm, req);
2252 if (!ret)
2253 goto out;
2254 err:
2255 mvm->scan_status = IWL_MVM_SCAN_NONE;
2256 out:
2257 mutex_unlock(&mvm->mutex);
2258 return ret;
2261 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2262 struct ieee80211_vif *vif)
2264 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2265 int ret;
2267 mutex_lock(&mvm->mutex);
2268 ret = iwl_mvm_scan_offload_stop(mvm, false);
2269 mutex_unlock(&mvm->mutex);
2270 iwl_mvm_wait_for_async_handlers(mvm);
2272 return ret;
2275 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2276 enum set_key_cmd cmd,
2277 struct ieee80211_vif *vif,
2278 struct ieee80211_sta *sta,
2279 struct ieee80211_key_conf *key)
2281 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2282 int ret;
2284 if (iwlwifi_mod_params.sw_crypto) {
2285 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2286 return -EOPNOTSUPP;
2289 switch (key->cipher) {
2290 case WLAN_CIPHER_SUITE_TKIP:
2291 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2292 /* fall-through */
2293 case WLAN_CIPHER_SUITE_CCMP:
2294 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2295 break;
2296 case WLAN_CIPHER_SUITE_AES_CMAC:
2297 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
2298 break;
2299 case WLAN_CIPHER_SUITE_WEP40:
2300 case WLAN_CIPHER_SUITE_WEP104:
2302 * Support for TX only, at least for now, so accept
2303 * the key and do nothing else. Then mac80211 will
2304 * pass it for TX but we don't have to use it for RX.
2306 return 0;
2307 default:
2308 /* currently FW supports only one optional cipher scheme */
2309 if (hw->n_cipher_schemes &&
2310 hw->cipher_schemes->cipher == key->cipher)
2311 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2312 else
2313 return -EOPNOTSUPP;
2316 mutex_lock(&mvm->mutex);
2318 switch (cmd) {
2319 case SET_KEY:
2320 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2321 vif->type == NL80211_IFTYPE_AP) && !sta) {
2323 * GTK on AP interface is a TX-only key, return 0;
2324 * on IBSS they're per-station and because we're lazy
2325 * we don't support them for RX, so do the same.
2327 ret = 0;
2328 key->hw_key_idx = STA_KEY_IDX_INVALID;
2329 break;
2332 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2333 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
2334 if (ret) {
2335 IWL_WARN(mvm, "set key failed\n");
2337 * can't add key for RX, but we don't need it
2338 * in the device for TX so still return 0
2340 key->hw_key_idx = STA_KEY_IDX_INVALID;
2341 ret = 0;
2344 break;
2345 case DISABLE_KEY:
2346 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2347 ret = 0;
2348 break;
2351 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2352 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2353 break;
2354 default:
2355 ret = -EINVAL;
2358 mutex_unlock(&mvm->mutex);
2359 return ret;
2362 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2363 struct ieee80211_vif *vif,
2364 struct ieee80211_key_conf *keyconf,
2365 struct ieee80211_sta *sta,
2366 u32 iv32, u16 *phase1key)
2368 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2370 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2371 return;
2373 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2377 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
2378 struct iwl_rx_packet *pkt, void *data)
2380 struct iwl_mvm *mvm =
2381 container_of(notif_wait, struct iwl_mvm, notif_wait);
2382 struct iwl_hs20_roc_res *resp;
2383 int resp_len = iwl_rx_packet_payload_len(pkt);
2384 struct iwl_mvm_time_event_data *te_data = data;
2386 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
2387 return true;
2389 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
2390 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
2391 return true;
2394 resp = (void *)pkt->data;
2396 IWL_DEBUG_TE(mvm,
2397 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
2398 resp->status, resp->event_unique_id);
2400 te_data->uid = le32_to_cpu(resp->event_unique_id);
2401 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
2402 te_data->uid);
2404 spin_lock_bh(&mvm->time_event_lock);
2405 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
2406 spin_unlock_bh(&mvm->time_event_lock);
2408 return true;
2411 #define AUX_ROC_MAX_DELAY_ON_CHANNEL 5000
2412 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
2413 struct ieee80211_channel *channel,
2414 struct ieee80211_vif *vif,
2415 int duration)
2417 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
2418 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2419 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
2420 static const u8 time_event_response[] = { HOT_SPOT_CMD };
2421 struct iwl_notification_wait wait_time_event;
2422 struct iwl_hs20_roc_req aux_roc_req = {
2423 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
2424 .id_and_color =
2425 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
2426 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
2427 /* Set the channel info data */
2428 .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
2429 PHY_BAND_24 : PHY_BAND_5,
2430 .channel_info.channel = channel->hw_value,
2431 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
2432 /* Set the time and duration */
2433 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
2434 .apply_time_max_delay =
2435 cpu_to_le32(MSEC_TO_TU(AUX_ROC_MAX_DELAY_ON_CHANNEL)),
2436 .duration = cpu_to_le32(MSEC_TO_TU(duration)),
2439 /* Set the node address */
2440 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
2442 te_data->vif = vif;
2443 te_data->duration = duration;
2444 te_data->id = HOT_SPOT_CMD;
2446 lockdep_assert_held(&mvm->mutex);
2448 spin_lock_bh(&mvm->time_event_lock);
2449 list_add_tail(&te_data->list, &mvm->time_event_list);
2450 spin_unlock_bh(&mvm->time_event_lock);
2453 * Use a notification wait, which really just processes the
2454 * command response and doesn't wait for anything, in order
2455 * to be able to process the response and get the UID inside
2456 * the RX path. Using CMD_WANT_SKB doesn't work because it
2457 * stores the buffer and then wakes up this thread, by which
2458 * time another notification (that the time event started)
2459 * might already be processed unsuccessfully.
2461 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
2462 time_event_response,
2463 ARRAY_SIZE(time_event_response),
2464 iwl_mvm_rx_aux_roc, te_data);
2466 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
2467 &aux_roc_req);
2469 if (res) {
2470 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
2471 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
2472 goto out_clear_te;
2475 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
2476 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
2477 /* should never fail */
2478 WARN_ON_ONCE(res);
2480 if (res) {
2481 out_clear_te:
2482 spin_lock_bh(&mvm->time_event_lock);
2483 iwl_mvm_te_clear_data(mvm, te_data);
2484 spin_unlock_bh(&mvm->time_event_lock);
2487 return res;
2490 static int iwl_mvm_roc(struct ieee80211_hw *hw,
2491 struct ieee80211_vif *vif,
2492 struct ieee80211_channel *channel,
2493 int duration,
2494 enum ieee80211_roc_type type)
2496 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2497 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2498 struct cfg80211_chan_def chandef;
2499 struct iwl_mvm_phy_ctxt *phy_ctxt;
2500 int ret, i;
2502 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2503 duration, type);
2505 switch (vif->type) {
2506 case NL80211_IFTYPE_STATION:
2507 /* Use aux roc framework (HS20) */
2508 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
2509 vif, duration);
2510 return ret;
2511 case NL80211_IFTYPE_P2P_DEVICE:
2512 /* handle below */
2513 break;
2514 default:
2515 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
2516 return -EINVAL;
2519 mutex_lock(&mvm->mutex);
2521 for (i = 0; i < NUM_PHY_CTX; i++) {
2522 phy_ctxt = &mvm->phy_ctxts[i];
2523 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2524 continue;
2526 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2528 * Unbind the P2P_DEVICE from the current PHY context,
2529 * and if the PHY context is not used remove it.
2531 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2532 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2533 goto out_unlock;
2535 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2537 /* Bind the P2P_DEVICE to the current PHY Context */
2538 mvmvif->phy_ctxt = phy_ctxt;
2540 ret = iwl_mvm_binding_add_vif(mvm, vif);
2541 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2542 goto out_unlock;
2544 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2545 goto schedule_time_event;
2549 /* Need to update the PHY context only if the ROC channel changed */
2550 if (channel == mvmvif->phy_ctxt->channel)
2551 goto schedule_time_event;
2553 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2556 * Change the PHY context configuration as it is currently referenced
2557 * only by the P2P Device MAC
2559 if (mvmvif->phy_ctxt->ref == 1) {
2560 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2561 &chandef, 1, 1);
2562 if (ret)
2563 goto out_unlock;
2564 } else {
2566 * The PHY context is shared with other MACs. Need to remove the
2567 * P2P Device from the binding, allocate an new PHY context and
2568 * create a new binding
2570 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2571 if (!phy_ctxt) {
2572 ret = -ENOSPC;
2573 goto out_unlock;
2576 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2577 1, 1);
2578 if (ret) {
2579 IWL_ERR(mvm, "Failed to change PHY context\n");
2580 goto out_unlock;
2583 /* Unbind the P2P_DEVICE from the current PHY context */
2584 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2585 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2586 goto out_unlock;
2588 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2590 /* Bind the P2P_DEVICE to the new allocated PHY context */
2591 mvmvif->phy_ctxt = phy_ctxt;
2593 ret = iwl_mvm_binding_add_vif(mvm, vif);
2594 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2595 goto out_unlock;
2597 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2600 schedule_time_event:
2601 /* Schedule the time events */
2602 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
2604 out_unlock:
2605 mutex_unlock(&mvm->mutex);
2606 IWL_DEBUG_MAC80211(mvm, "leave\n");
2607 return ret;
2610 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2612 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2614 IWL_DEBUG_MAC80211(mvm, "enter\n");
2616 mutex_lock(&mvm->mutex);
2617 iwl_mvm_stop_p2p_roc(mvm);
2618 mutex_unlock(&mvm->mutex);
2620 IWL_DEBUG_MAC80211(mvm, "leave\n");
2621 return 0;
2624 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
2625 struct ieee80211_chanctx_conf *ctx)
2627 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2628 struct iwl_mvm_phy_ctxt *phy_ctxt;
2629 int ret;
2631 lockdep_assert_held(&mvm->mutex);
2633 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
2635 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2636 if (!phy_ctxt) {
2637 ret = -ENOSPC;
2638 goto out;
2641 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
2642 ctx->rx_chains_static,
2643 ctx->rx_chains_dynamic);
2644 if (ret) {
2645 IWL_ERR(mvm, "Failed to add PHY context\n");
2646 goto out;
2649 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
2650 *phy_ctxt_id = phy_ctxt->id;
2651 out:
2652 return ret;
2655 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2656 struct ieee80211_chanctx_conf *ctx)
2658 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2659 int ret;
2661 mutex_lock(&mvm->mutex);
2662 ret = __iwl_mvm_add_chanctx(mvm, ctx);
2663 mutex_unlock(&mvm->mutex);
2665 return ret;
2668 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
2669 struct ieee80211_chanctx_conf *ctx)
2671 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2672 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2674 lockdep_assert_held(&mvm->mutex);
2676 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
2679 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2680 struct ieee80211_chanctx_conf *ctx)
2682 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2684 mutex_lock(&mvm->mutex);
2685 __iwl_mvm_remove_chanctx(mvm, ctx);
2686 mutex_unlock(&mvm->mutex);
2689 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2690 struct ieee80211_chanctx_conf *ctx,
2691 u32 changed)
2693 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2694 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2695 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2697 if (WARN_ONCE((phy_ctxt->ref > 1) &&
2698 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
2699 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
2700 IEEE80211_CHANCTX_CHANGE_RADAR |
2701 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
2702 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2703 phy_ctxt->ref, changed))
2704 return;
2706 mutex_lock(&mvm->mutex);
2707 iwl_mvm_bt_coex_vif_change(mvm);
2708 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
2709 ctx->rx_chains_static,
2710 ctx->rx_chains_dynamic);
2711 mutex_unlock(&mvm->mutex);
2714 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
2715 struct ieee80211_vif *vif,
2716 struct ieee80211_chanctx_conf *ctx,
2717 bool switching_chanctx)
2719 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2720 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2721 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2722 int ret;
2724 lockdep_assert_held(&mvm->mutex);
2726 mvmvif->phy_ctxt = phy_ctxt;
2728 switch (vif->type) {
2729 case NL80211_IFTYPE_AP:
2730 /* Unless it's a CSA flow we have nothing to do here */
2731 if (vif->csa_active) {
2732 mvmvif->ap_ibss_active = true;
2733 break;
2735 case NL80211_IFTYPE_ADHOC:
2737 * The AP binding flow is handled as part of the start_ap flow
2738 * (in bss_info_changed), similarly for IBSS.
2740 ret = 0;
2741 goto out;
2742 case NL80211_IFTYPE_STATION:
2743 break;
2744 case NL80211_IFTYPE_MONITOR:
2745 /* always disable PS when a monitor interface is active */
2746 mvmvif->ps_disabled = true;
2747 break;
2748 default:
2749 ret = -EINVAL;
2750 goto out;
2753 ret = iwl_mvm_binding_add_vif(mvm, vif);
2754 if (ret)
2755 goto out;
2758 * Power state must be updated before quotas,
2759 * otherwise fw will complain.
2761 iwl_mvm_power_update_mac(mvm);
2763 /* Setting the quota at this stage is only required for monitor
2764 * interfaces. For the other types, the bss_info changed flow
2765 * will handle quota settings.
2767 if (vif->type == NL80211_IFTYPE_MONITOR) {
2768 mvmvif->monitor_active = true;
2769 ret = iwl_mvm_update_quotas(mvm, NULL);
2770 if (ret)
2771 goto out_remove_binding;
2774 /* Handle binding during CSA */
2775 if ((vif->type == NL80211_IFTYPE_AP) ||
2776 (switching_chanctx && (vif->type == NL80211_IFTYPE_STATION))) {
2777 iwl_mvm_update_quotas(mvm, NULL);
2778 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2781 if (vif->csa_active && vif->type == NL80211_IFTYPE_STATION) {
2782 struct iwl_mvm_sta *mvmsta;
2784 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
2785 mvmvif->ap_sta_id);
2787 if (WARN_ON(!mvmsta))
2788 goto out;
2790 /* TODO: only re-enable after the first beacon */
2791 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
2794 goto out;
2796 out_remove_binding:
2797 iwl_mvm_binding_remove_vif(mvm, vif);
2798 iwl_mvm_power_update_mac(mvm);
2799 out:
2800 if (ret)
2801 mvmvif->phy_ctxt = NULL;
2802 return ret;
2804 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
2805 struct ieee80211_vif *vif,
2806 struct ieee80211_chanctx_conf *ctx)
2808 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2809 int ret;
2811 mutex_lock(&mvm->mutex);
2812 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
2813 mutex_unlock(&mvm->mutex);
2815 return ret;
2818 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
2819 struct ieee80211_vif *vif,
2820 struct ieee80211_chanctx_conf *ctx,
2821 bool switching_chanctx)
2823 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2824 struct ieee80211_vif *disabled_vif = NULL;
2825 struct iwl_mvm_sta *mvmsta;
2827 lockdep_assert_held(&mvm->mutex);
2829 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
2831 switch (vif->type) {
2832 case NL80211_IFTYPE_ADHOC:
2833 goto out;
2834 case NL80211_IFTYPE_MONITOR:
2835 mvmvif->monitor_active = false;
2836 mvmvif->ps_disabled = false;
2837 break;
2838 case NL80211_IFTYPE_AP:
2839 /* This part is triggered only during CSA */
2840 if (!vif->csa_active || !mvmvif->ap_ibss_active)
2841 goto out;
2843 /* Set CS bit on all the stations */
2844 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
2846 /* Save blocked iface, the timeout is set on the next beacon */
2847 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
2849 mvmvif->ap_ibss_active = false;
2850 break;
2851 case NL80211_IFTYPE_STATION:
2852 if (!switching_chanctx)
2853 break;
2855 disabled_vif = vif;
2857 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
2858 mvmvif->ap_sta_id);
2860 if (!WARN_ON(!mvmsta))
2861 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true);
2863 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
2864 break;
2865 default:
2866 break;
2869 iwl_mvm_update_quotas(mvm, disabled_vif);
2870 iwl_mvm_binding_remove_vif(mvm, vif);
2872 out:
2873 mvmvif->phy_ctxt = NULL;
2874 iwl_mvm_power_update_mac(mvm);
2877 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
2878 struct ieee80211_vif *vif,
2879 struct ieee80211_chanctx_conf *ctx)
2881 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2883 mutex_lock(&mvm->mutex);
2884 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
2885 mutex_unlock(&mvm->mutex);
2888 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
2889 struct ieee80211_vif_chanctx_switch *vifs,
2890 int n_vifs,
2891 enum ieee80211_chanctx_switch_mode mode)
2893 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2894 int ret;
2896 /* we only support SWAP_CONTEXTS and with a single-vif right now */
2897 if (mode != CHANCTX_SWMODE_SWAP_CONTEXTS || n_vifs > 1)
2898 return -EOPNOTSUPP;
2900 mutex_lock(&mvm->mutex);
2901 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
2902 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
2904 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
2905 if (ret) {
2906 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
2907 goto out_reassign;
2910 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
2911 true);
2912 if (ret) {
2913 IWL_ERR(mvm,
2914 "failed to assign new_ctx during channel switch\n");
2915 goto out_remove;
2918 /* we don't support TDLS during DCM - can be caused by channel switch */
2919 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2920 iwl_mvm_teardown_tdls_peers(mvm);
2922 goto out;
2924 out_remove:
2925 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
2927 out_reassign:
2928 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx);
2929 if (ret) {
2930 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
2931 goto out_restart;
2934 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
2935 true);
2936 if (ret) {
2937 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
2938 goto out_restart;
2941 goto out;
2943 out_restart:
2944 /* things keep failing, better restart the hw */
2945 iwl_mvm_nic_restart(mvm, false);
2947 out:
2948 mutex_unlock(&mvm->mutex);
2949 return ret;
2952 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
2953 struct ieee80211_sta *sta,
2954 bool set)
2956 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2957 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
2959 if (!mvm_sta || !mvm_sta->vif) {
2960 IWL_ERR(mvm, "Station is not associated to a vif\n");
2961 return -EINVAL;
2964 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
2967 #ifdef CONFIG_NL80211_TESTMODE
2968 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
2969 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
2970 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
2971 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
2974 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
2975 struct ieee80211_vif *vif,
2976 void *data, int len)
2978 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
2979 int err;
2980 u32 noa_duration;
2982 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
2983 if (err)
2984 return err;
2986 if (!tb[IWL_MVM_TM_ATTR_CMD])
2987 return -EINVAL;
2989 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
2990 case IWL_MVM_TM_CMD_SET_NOA:
2991 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
2992 !vif->bss_conf.enable_beacon ||
2993 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
2994 return -EINVAL;
2996 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
2997 if (noa_duration >= vif->bss_conf.beacon_int)
2998 return -EINVAL;
3000 mvm->noa_duration = noa_duration;
3001 mvm->noa_vif = vif;
3003 return iwl_mvm_update_quotas(mvm, NULL);
3004 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3005 /* must be associated client vif - ignore authorized */
3006 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3007 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3008 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3009 return -EINVAL;
3011 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
3012 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3013 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3016 return -EOPNOTSUPP;
3019 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3020 struct ieee80211_vif *vif,
3021 void *data, int len)
3023 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3024 int err;
3026 mutex_lock(&mvm->mutex);
3027 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3028 mutex_unlock(&mvm->mutex);
3030 return err;
3032 #endif
3034 static void iwl_mvm_channel_switch_beacon(struct ieee80211_hw *hw,
3035 struct ieee80211_vif *vif,
3036 struct cfg80211_chan_def *chandef)
3038 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3039 struct ieee80211_vif *csa_vif;
3041 mutex_lock(&mvm->mutex);
3043 csa_vif = rcu_dereference_protected(mvm->csa_vif,
3044 lockdep_is_held(&mvm->mutex));
3045 if (WARN(csa_vif && csa_vif->csa_active,
3046 "Another CSA is already in progress"))
3047 goto out_unlock;
3049 IWL_DEBUG_MAC80211(mvm, "CSA started to freq %d\n",
3050 chandef->center_freq1);
3051 rcu_assign_pointer(mvm->csa_vif, vif);
3053 out_unlock:
3054 mutex_unlock(&mvm->mutex);
3057 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3058 struct ieee80211_vif *vif, u32 queues, bool drop)
3060 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3061 struct iwl_mvm_vif *mvmvif;
3062 struct iwl_mvm_sta *mvmsta;
3064 if (!vif || vif->type != NL80211_IFTYPE_STATION)
3065 return;
3067 mutex_lock(&mvm->mutex);
3068 mvmvif = iwl_mvm_vif_from_mac80211(vif);
3069 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, mvmvif->ap_sta_id);
3071 if (WARN_ON_ONCE(!mvmsta))
3072 goto done;
3074 if (drop) {
3075 if (iwl_mvm_flush_tx_path(mvm, mvmsta->tfd_queue_msk, true))
3076 IWL_ERR(mvm, "flush request fail\n");
3077 } else {
3078 iwl_trans_wait_tx_queue_empty(mvm->trans,
3079 mvmsta->tfd_queue_msk);
3081 done:
3082 mutex_unlock(&mvm->mutex);
3085 const struct ieee80211_ops iwl_mvm_hw_ops = {
3086 .tx = iwl_mvm_mac_tx,
3087 .ampdu_action = iwl_mvm_mac_ampdu_action,
3088 .start = iwl_mvm_mac_start,
3089 .restart_complete = iwl_mvm_mac_restart_complete,
3090 .stop = iwl_mvm_mac_stop,
3091 .add_interface = iwl_mvm_mac_add_interface,
3092 .remove_interface = iwl_mvm_mac_remove_interface,
3093 .config = iwl_mvm_mac_config,
3094 .prepare_multicast = iwl_mvm_prepare_multicast,
3095 .configure_filter = iwl_mvm_configure_filter,
3096 .bss_info_changed = iwl_mvm_bss_info_changed,
3097 .hw_scan = iwl_mvm_mac_hw_scan,
3098 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
3099 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
3100 .sta_state = iwl_mvm_mac_sta_state,
3101 .sta_notify = iwl_mvm_mac_sta_notify,
3102 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
3103 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
3104 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
3105 .sta_rc_update = iwl_mvm_sta_rc_update,
3106 .conf_tx = iwl_mvm_mac_conf_tx,
3107 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
3108 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
3109 .flush = iwl_mvm_mac_flush,
3110 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
3111 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
3112 .set_key = iwl_mvm_mac_set_key,
3113 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
3114 .remain_on_channel = iwl_mvm_roc,
3115 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
3116 .add_chanctx = iwl_mvm_add_chanctx,
3117 .remove_chanctx = iwl_mvm_remove_chanctx,
3118 .change_chanctx = iwl_mvm_change_chanctx,
3119 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
3120 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
3121 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
3123 .start_ap = iwl_mvm_start_ap_ibss,
3124 .stop_ap = iwl_mvm_stop_ap_ibss,
3125 .join_ibss = iwl_mvm_start_ap_ibss,
3126 .leave_ibss = iwl_mvm_stop_ap_ibss,
3128 .set_tim = iwl_mvm_set_tim,
3130 .channel_switch_beacon = iwl_mvm_channel_switch_beacon,
3132 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
3134 #ifdef CONFIG_PM_SLEEP
3135 /* look at d3.c */
3136 .suspend = iwl_mvm_suspend,
3137 .resume = iwl_mvm_resume,
3138 .set_wakeup = iwl_mvm_set_wakeup,
3139 .set_rekey_data = iwl_mvm_set_rekey_data,
3140 #if IS_ENABLED(CONFIG_IPV6)
3141 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
3142 #endif
3143 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
3144 #endif