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.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 *****************************************************************************/
63 #include <linux/kernel.h>
64 #include <linux/slab.h>
65 #include <linux/skbuff.h>
66 #include <linux/netdevice.h>
67 #include <linux/etherdevice.h>
69 #include <linux/if_arp.h>
70 #include <net/mac80211.h>
71 #include <net/ieee80211_radiotap.h>
74 #include "iwl-op-mode.h"
78 #include "time-event.h"
79 #include "iwl-eeprom-parse.h"
80 #include "fw-api-scan.h"
81 #include "iwl-phy-db.h"
84 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
87 .types = BIT(NL80211_IFTYPE_STATION),
91 .types = BIT(NL80211_IFTYPE_AP) |
92 BIT(NL80211_IFTYPE_P2P_CLIENT) |
93 BIT(NL80211_IFTYPE_P2P_GO),
97 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
101 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
103 .num_different_channels = 1,
105 .limits = iwl_mvm_limits,
106 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
110 #ifdef CONFIG_PM_SLEEP
111 static const struct nl80211_wowlan_tcp_data_token_feature
112 iwl_mvm_wowlan_tcp_token_feature = {
115 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
118 static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
119 .tok = &iwl_mvm_wowlan_tcp_token_feature,
120 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
121 sizeof(struct ethhdr) -
122 sizeof(struct iphdr) -
123 sizeof(struct tcphdr),
124 .data_interval_max = 65535, /* __le16 in API */
125 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
126 sizeof(struct ethhdr) -
127 sizeof(struct iphdr) -
128 sizeof(struct tcphdr),
133 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
135 * Use the reserved field to indicate magic values.
136 * these values will only be used internally by the driver,
137 * and won't make it to the fw (reserved will be 0).
138 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
139 * be the vif's ip address. in case there is not a single
140 * ip address (0, or more than 1), this attribute will
142 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
143 * the LSB bytes of the vif's mac address
146 BC_FILTER_MAGIC_NONE = 0,
151 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
155 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
158 /* frame type - arp, hw type - ethernet */
160 BCAST_FILTER_OFFSET_PAYLOAD_START,
161 .offset = sizeof(rfc1042_header),
162 .val = cpu_to_be32(0x08060001),
163 .mask = cpu_to_be32(0xffffffff),
168 BCAST_FILTER_OFFSET_PAYLOAD_START,
169 .offset = sizeof(rfc1042_header) + 2 +
170 sizeof(struct arphdr) +
171 ETH_ALEN + sizeof(__be32) +
173 .mask = cpu_to_be32(0xffffffff),
174 /* mark it as special field */
175 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
180 /* dhcp offer bcast */
182 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
185 /* udp dest port - 68 (bootp client)*/
186 .offset_type = BCAST_FILTER_OFFSET_IP_END,
187 .offset = offsetof(struct udphdr, dest),
188 .val = cpu_to_be32(0x00440000),
189 .mask = cpu_to_be32(0xffff0000),
192 /* dhcp - lsb bytes of client hw address */
193 .offset_type = BCAST_FILTER_OFFSET_IP_END,
195 .mask = cpu_to_be32(0xffffffff),
196 /* mark it as special field */
197 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
201 /* last filter must be empty */
206 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
208 if (!iwl_mvm_is_d0i3_supported(mvm))
211 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
212 WARN_ON(test_and_set_bit(ref_type, mvm->ref_bitmap));
213 iwl_trans_ref(mvm->trans);
216 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
218 if (!iwl_mvm_is_d0i3_supported(mvm))
221 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
222 WARN_ON(!test_and_clear_bit(ref_type, mvm->ref_bitmap));
223 iwl_trans_unref(mvm->trans);
227 iwl_mvm_unref_all_except(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref)
231 if (!iwl_mvm_is_d0i3_supported(mvm))
234 for_each_set_bit(i, mvm->ref_bitmap, IWL_MVM_REF_COUNT) {
238 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d\n", i);
239 clear_bit(i, mvm->ref_bitmap);
240 iwl_trans_unref(mvm->trans);
244 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
248 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
249 for (i = 0; i < NUM_PHY_CTX; i++) {
250 mvm->phy_ctxts[i].id = i;
251 mvm->phy_ctxts[i].ref = 0;
255 static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
257 /* we create the 802.11 header and SSID element */
258 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID)
259 return mvm->fw->ucode_capa.max_probe_length - 24 - 2;
260 return mvm->fw->ucode_capa.max_probe_length - 24 - 34;
263 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
265 struct ieee80211_hw *hw = mvm->hw;
268 /* Tell mac80211 our characteristics */
269 hw->flags = IEEE80211_HW_SIGNAL_DBM |
270 IEEE80211_HW_SPECTRUM_MGMT |
271 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
272 IEEE80211_HW_QUEUE_CONTROL |
273 IEEE80211_HW_WANT_MONITOR_VIF |
274 IEEE80211_HW_SUPPORTS_PS |
275 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
276 IEEE80211_HW_AMPDU_AGGREGATION |
277 IEEE80211_HW_TIMING_BEACON_ONLY |
278 IEEE80211_HW_CONNECTION_MONITOR |
279 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
280 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
282 hw->queues = mvm->first_agg_queue;
283 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
284 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
285 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
286 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC;
287 hw->rate_control_algorithm = "iwl-mvm-rs";
290 * Enable 11w if advertised by firmware and software crypto
291 * is not enabled (as the firmware will interpret some mgmt
292 * packets, so enabling it with software crypto isn't safe)
294 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
295 !iwlwifi_mod_params.sw_crypto)
296 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
298 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT &&
299 IWL_UCODE_API(mvm->fw->ucode_ver) >= 9 &&
300 !iwlwifi_mod_params.uapsd_disable) {
301 hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
302 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
303 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
306 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
307 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
308 hw->chanctx_data_size = sizeof(u16);
310 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
311 BIT(NL80211_IFTYPE_P2P_CLIENT) |
312 BIT(NL80211_IFTYPE_AP) |
313 BIT(NL80211_IFTYPE_P2P_GO) |
314 BIT(NL80211_IFTYPE_P2P_DEVICE) |
315 BIT(NL80211_IFTYPE_ADHOC);
317 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
318 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
319 REGULATORY_DISABLE_BEACON_HINTS;
321 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
322 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
324 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_CSA_FLOW)
325 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
327 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
328 hw->wiphy->n_iface_combinations =
329 ARRAY_SIZE(iwl_mvm_iface_combinations);
331 hw->wiphy->max_remain_on_channel_duration = 10000;
332 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
334 /* Extract MAC address */
335 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
336 hw->wiphy->addresses = mvm->addresses;
337 hw->wiphy->n_addresses = 1;
339 /* Extract additional MAC addresses if available */
340 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
341 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
343 for (i = 1; i < num_mac; i++) {
344 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
346 mvm->addresses[i].addr[5]++;
347 hw->wiphy->n_addresses++;
350 iwl_mvm_reset_phy_ctxts(mvm);
352 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
354 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
356 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
357 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
358 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
359 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
360 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
361 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
363 hw->wiphy->hw_version = mvm->trans->hw_id;
365 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
366 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
368 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
370 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
371 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
372 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
373 /* we create the 802.11 header and zero length SSID IE. */
374 hw->wiphy->max_sched_scan_ie_len = SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
376 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
377 NL80211_FEATURE_P2P_GO_OPPPS;
379 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
381 /* currently FW API supports only one optional cipher scheme */
382 if (mvm->fw->cs[0].cipher) {
383 mvm->hw->n_cipher_schemes = 1;
384 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
387 #ifdef CONFIG_PM_SLEEP
388 if (iwl_mvm_is_d0i3_supported(mvm) &&
389 device_can_wakeup(mvm->trans->dev)) {
390 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
391 hw->wiphy->wowlan = &mvm->wowlan;
392 } else if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
393 mvm->trans->ops->d3_suspend &&
394 mvm->trans->ops->d3_resume &&
395 device_can_wakeup(mvm->trans->dev)) {
396 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
397 WIPHY_WOWLAN_DISCONNECT |
398 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
399 WIPHY_WOWLAN_RFKILL_RELEASE;
400 if (!iwlwifi_mod_params.sw_crypto)
401 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
402 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
403 WIPHY_WOWLAN_4WAY_HANDSHAKE;
405 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
406 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
407 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
408 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
409 hw->wiphy->wowlan = &mvm->wowlan;
413 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
414 /* assign default bcast filtering configuration */
415 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
418 ret = iwl_mvm_leds_init(mvm);
422 ret = ieee80211_register_hw(mvm->hw);
424 iwl_mvm_leds_exit(mvm);
429 static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
430 struct ieee80211_sta *sta,
433 struct iwl_mvm_sta *mvmsta;
437 * double check the IN_D0I3 flag both before and after
438 * taking the spinlock, in order to prevent taking
439 * the spinlock when not needed.
441 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
444 spin_lock(&mvm->d0i3_tx_lock);
446 * testing the flag again ensures the skb dequeue
447 * loop (on d0i3 exit) hasn't run yet.
449 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
452 mvmsta = iwl_mvm_sta_from_mac80211(sta);
453 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
454 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
457 __skb_queue_tail(&mvm->d0i3_tx, skb);
458 ieee80211_stop_queues(mvm->hw);
461 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
462 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
466 spin_unlock(&mvm->d0i3_tx_lock);
470 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
471 struct ieee80211_tx_control *control,
474 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
475 struct ieee80211_sta *sta = control->sta;
476 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
477 struct ieee80211_hdr *hdr = (void *)skb->data;
479 if (iwl_mvm_is_radio_killed(mvm)) {
480 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
484 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
485 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
488 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
489 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
490 ieee80211_is_mgmt(hdr->frame_control) &&
491 !ieee80211_is_deauth(hdr->frame_control) &&
492 !ieee80211_is_disassoc(hdr->frame_control) &&
493 !ieee80211_is_action(hdr->frame_control)))
497 if (iwl_mvm_defer_tx(mvm, sta, skb))
499 if (iwl_mvm_tx_skb(mvm, skb, sta))
504 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
508 ieee80211_free_txskb(hw, skb);
511 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
513 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
518 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
520 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
522 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
525 /* enabled by default */
529 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
530 struct ieee80211_vif *vif,
531 enum ieee80211_ampdu_mlme_action action,
532 struct ieee80211_sta *sta, u16 tid,
533 u16 *ssn, u8 buf_size)
535 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
537 bool tx_agg_ref = false;
539 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
540 sta->addr, tid, action);
542 if (!(mvm->nvm_data->sku_cap_11n_enable))
545 /* return from D0i3 before starting a new Tx aggregation */
547 case IEEE80211_AMPDU_TX_START:
548 case IEEE80211_AMPDU_TX_STOP_CONT:
549 case IEEE80211_AMPDU_TX_STOP_FLUSH:
550 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
551 case IEEE80211_AMPDU_TX_OPERATIONAL:
552 iwl_mvm_ref(mvm, IWL_MVM_REF_TX_AGG);
556 * for tx start, wait synchronously until D0i3 exit to
557 * get the correct sequence number for the tid.
558 * additionally, some other ampdu actions use direct
559 * target access, which is not handled automatically
560 * by the trans layer (unlike commands), so wait for
561 * d0i3 exit in these cases as well.
563 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
564 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status), HZ)) {
566 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
574 mutex_lock(&mvm->mutex);
577 case IEEE80211_AMPDU_RX_START:
578 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
582 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
584 case IEEE80211_AMPDU_RX_STOP:
585 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
587 case IEEE80211_AMPDU_TX_START:
588 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
592 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
594 case IEEE80211_AMPDU_TX_STOP_CONT:
595 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
597 case IEEE80211_AMPDU_TX_STOP_FLUSH:
598 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
599 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
601 case IEEE80211_AMPDU_TX_OPERATIONAL:
602 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
609 mutex_unlock(&mvm->mutex);
612 * If the tid is marked as started, we won't use it for offloaded
613 * traffic on the next D0i3 entry. It's safe to unref.
616 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
621 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
622 struct ieee80211_vif *vif)
624 struct iwl_mvm *mvm = data;
625 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
627 mvmvif->uploaded = false;
628 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
630 /* does this make sense at all? */
633 spin_lock_bh(&mvm->time_event_lock);
634 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
635 spin_unlock_bh(&mvm->time_event_lock);
637 mvmvif->phy_ctxt = NULL;
640 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
642 #ifdef CONFIG_IWLWIFI_DEBUGFS
643 static char *env[] = { "DRIVER=iwlwifi", "EVENT=error_dump", NULL };
645 iwl_mvm_fw_error_dump(mvm);
647 /* notify the userspace about the error we had */
648 kobject_uevent_env(&mvm->hw->wiphy->dev.kobj, KOBJ_CHANGE, env);
651 iwl_trans_stop_device(mvm->trans);
653 mvm->scan_status = IWL_MVM_SCAN_NONE;
655 /* just in case one was running */
656 ieee80211_remain_on_channel_expired(mvm->hw);
658 ieee80211_iterate_active_interfaces_atomic(
659 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
660 iwl_mvm_cleanup_iterator, mvm);
662 mvm->p2p_device_vif = NULL;
663 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
665 iwl_mvm_reset_phy_ctxts(mvm);
666 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
667 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
669 ieee80211_wake_queues(mvm->hw);
671 /* cleanup all stale references (scan, roc), but keep the
672 * ucode_down ref until reconfig is complete */
673 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
676 mvm->rx_ba_sessions = 0;
679 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
681 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
684 mutex_lock(&mvm->mutex);
686 /* Clean up some internal and mac80211 state on restart */
687 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
688 iwl_mvm_restart_cleanup(mvm);
690 ret = iwl_mvm_up(mvm);
691 mutex_unlock(&mvm->mutex);
696 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
698 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
701 mutex_lock(&mvm->mutex);
703 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
704 iwl_mvm_d0i3_enable_tx(mvm, NULL);
705 ret = iwl_mvm_update_quotas(mvm, NULL);
707 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
710 /* allow transport/FW low power modes */
711 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
713 mutex_unlock(&mvm->mutex);
716 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
718 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
720 flush_work(&mvm->d0i3_exit_work);
721 flush_work(&mvm->async_handlers_wk);
723 mutex_lock(&mvm->mutex);
725 /* disallow low power states when the FW is down */
726 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
728 /* async_handlers_wk is now blocked */
731 * The work item could be running or queued if the
732 * ROC time event stops just as we get here.
734 cancel_work_sync(&mvm->roc_done_wk);
736 iwl_trans_stop_device(mvm->trans);
738 iwl_mvm_async_handlers_purge(mvm);
739 /* async_handlers_list is empty and will stay empty: HW is stopped */
741 /* the fw is stopped, the aux sta is dead: clean up driver state */
742 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
744 mutex_unlock(&mvm->mutex);
747 * The worker might have been waiting for the mutex, let it run and
748 * discover that its list is now empty.
750 cancel_work_sync(&mvm->async_handlers_wk);
753 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
757 lockdep_assert_held(&mvm->mutex);
759 for (i = 0; i < NUM_PHY_CTX; i++)
760 if (!mvm->phy_ctxts[i].ref)
761 return &mvm->phy_ctxts[i];
763 IWL_ERR(mvm, "No available PHY context\n");
767 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
770 /* FW is in charge of regulatory enforcement */
771 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
772 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
773 .pwr_restriction = cpu_to_le16(tx_power),
776 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
777 sizeof(reduce_txpwr_cmd),
781 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
782 struct ieee80211_vif *vif)
784 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
785 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
789 * Not much to do here. The stack will not allow interface
790 * types or combinations that we didn't advertise, so we
791 * don't really have to check the types.
794 mutex_lock(&mvm->mutex);
796 /* Allocate resources for the MAC context, and add it to the fw */
797 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
801 /* Counting number of interfaces is needed for legacy PM */
802 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
806 * The AP binding flow can be done only after the beacon
807 * template is configured (which happens only in the mac80211
808 * start_ap() flow), and adding the broadcast station can happen
809 * only after the binding.
810 * In addition, since modifying the MAC before adding a bcast
811 * station is not allowed by the FW, delay the adding of MAC context to
812 * the point where we can also add the bcast station.
813 * In short: there's not much we can do at this point, other than
814 * allocating resources :)
816 if (vif->type == NL80211_IFTYPE_AP ||
817 vif->type == NL80211_IFTYPE_ADHOC) {
818 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
819 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
821 ieee80211_vif_type_p2p(vif));
823 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
827 iwl_mvm_vif_dbgfs_register(mvm, vif);
831 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
835 ret = iwl_mvm_power_update_mac(mvm, vif);
839 /* beacon filtering */
840 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
844 if (!mvm->bf_allowed_vif &&
845 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
846 mvm->bf_allowed_vif = mvmvif;
847 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
848 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
852 * P2P_DEVICE interface does not have a channel context assigned to it,
853 * so a dedicated PHY context is allocated to it and the corresponding
854 * MAC context is bound to it at this stage.
856 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
858 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
859 if (!mvmvif->phy_ctxt) {
864 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
865 ret = iwl_mvm_binding_add_vif(mvm, vif);
869 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
873 /* Save a pointer to p2p device vif, so it can later be used to
874 * update the p2p device MAC when a GO is started/stopped */
875 mvm->p2p_device_vif = vif;
878 iwl_mvm_vif_dbgfs_register(mvm, vif);
882 iwl_mvm_binding_remove_vif(mvm, vif);
884 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
886 if (mvm->bf_allowed_vif == mvmvif) {
887 mvm->bf_allowed_vif = NULL;
888 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
889 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
892 mvmvif->phy_ctxt = NULL;
893 iwl_mvm_mac_ctxt_remove(mvm, vif);
895 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
898 iwl_mvm_mac_ctxt_release(mvm, vif);
900 mutex_unlock(&mvm->mutex);
905 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
906 struct ieee80211_vif *vif)
910 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
911 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
912 tfd_msk |= BIT(vif->hw_queue[ac]);
914 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
915 tfd_msk |= BIT(vif->cab_queue);
918 mutex_lock(&mvm->mutex);
919 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
920 mutex_unlock(&mvm->mutex);
923 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
925 * Flush the ROC worker which will flush the OFFCHANNEL queue.
926 * We assume here that all the packets sent to the OFFCHANNEL
927 * queue are sent in ROC session.
929 flush_work(&mvm->roc_done_wk);
932 * By now, all the AC queues are empty. The AGG queues are
933 * empty too. We already got all the Tx responses for all the
934 * packets in the queues. The drain work can have been
935 * triggered. Flush it.
937 flush_work(&mvm->sta_drained_wk);
941 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
942 struct ieee80211_vif *vif)
944 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
945 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
947 iwl_mvm_prepare_mac_removal(mvm, vif);
949 mutex_lock(&mvm->mutex);
951 if (mvm->bf_allowed_vif == mvmvif) {
952 mvm->bf_allowed_vif = NULL;
953 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
954 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
957 iwl_mvm_vif_dbgfs_clean(mvm, vif);
960 * For AP/GO interface, the tear down of the resources allocated to the
961 * interface is be handled as part of the stop_ap flow.
963 if (vif->type == NL80211_IFTYPE_AP ||
964 vif->type == NL80211_IFTYPE_ADHOC) {
965 #ifdef CONFIG_NL80211_TESTMODE
966 if (vif == mvm->noa_vif) {
968 mvm->noa_duration = 0;
971 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
975 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
976 mvm->p2p_device_vif = NULL;
977 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
978 iwl_mvm_binding_remove_vif(mvm, vif);
979 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
980 mvmvif->phy_ctxt = NULL;
983 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
986 iwl_mvm_power_update_mac(mvm, vif);
987 iwl_mvm_mac_ctxt_remove(mvm, vif);
990 iwl_mvm_mac_ctxt_release(mvm, vif);
991 mutex_unlock(&mvm->mutex);
994 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
999 struct iwl_mvm_mc_iter_data {
1000 struct iwl_mvm *mvm;
1004 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1005 struct ieee80211_vif *vif)
1007 struct iwl_mvm_mc_iter_data *data = _data;
1008 struct iwl_mvm *mvm = data->mvm;
1009 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1012 /* if we don't have free ports, mcast frames will be dropped */
1013 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1016 if (vif->type != NL80211_IFTYPE_STATION ||
1017 !vif->bss_conf.assoc)
1020 cmd->port_id = data->port_id++;
1021 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1022 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1024 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
1026 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1029 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1031 struct iwl_mvm_mc_iter_data iter_data = {
1035 lockdep_assert_held(&mvm->mutex);
1037 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1040 ieee80211_iterate_active_interfaces_atomic(
1041 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1042 iwl_mvm_mc_iface_iterator, &iter_data);
1045 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1046 struct netdev_hw_addr_list *mc_list)
1048 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1049 struct iwl_mcast_filter_cmd *cmd;
1050 struct netdev_hw_addr *addr;
1051 int addr_count = netdev_hw_addr_list_count(mc_list);
1052 bool pass_all = false;
1055 if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) {
1060 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1061 cmd = kzalloc(len, GFP_ATOMIC);
1067 return (u64)(unsigned long)cmd;
1070 netdev_hw_addr_list_for_each(addr, mc_list) {
1071 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1072 cmd->count, addr->addr);
1073 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1074 addr->addr, ETH_ALEN);
1078 return (u64)(unsigned long)cmd;
1081 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1082 unsigned int changed_flags,
1083 unsigned int *total_flags,
1086 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1087 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1089 mutex_lock(&mvm->mutex);
1091 /* replace previous configuration */
1092 kfree(mvm->mcast_filter_cmd);
1093 mvm->mcast_filter_cmd = cmd;
1098 iwl_mvm_recalc_multicast(mvm);
1100 mutex_unlock(&mvm->mutex);
1104 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1105 struct iwl_bcast_iter_data {
1106 struct iwl_mvm *mvm;
1107 struct iwl_bcast_filter_cmd *cmd;
1112 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1113 const struct iwl_fw_bcast_filter *in_filter,
1114 struct iwl_fw_bcast_filter *out_filter)
1116 struct iwl_fw_bcast_filter_attr *attr;
1119 memcpy(out_filter, in_filter, sizeof(*out_filter));
1121 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1122 attr = &out_filter->attrs[i];
1127 switch (attr->reserved1) {
1128 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1129 if (vif->bss_conf.arp_addr_cnt != 1) {
1134 attr->val = vif->bss_conf.arp_addr_list[0];
1136 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1137 attr->val = *(__be32 *)&vif->addr[2];
1142 attr->reserved1 = 0;
1143 out_filter->num_attrs++;
1147 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1148 struct ieee80211_vif *vif)
1150 struct iwl_bcast_iter_data *data = _data;
1151 struct iwl_mvm *mvm = data->mvm;
1152 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1153 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1154 struct iwl_fw_bcast_mac *bcast_mac;
1157 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1160 bcast_mac = &cmd->macs[mvmvif->id];
1162 /* enable filtering only for associated stations */
1163 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
1166 bcast_mac->default_discard = 1;
1168 /* copy all configured filters */
1169 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1171 * Make sure we don't exceed our filters limit.
1172 * if there is still a valid filter to be configured,
1173 * be on the safe side and just allow bcast for this mac.
1175 if (WARN_ON_ONCE(data->current_filter >=
1176 ARRAY_SIZE(cmd->filters))) {
1177 bcast_mac->default_discard = 0;
1178 bcast_mac->attached_filters = 0;
1182 iwl_mvm_set_bcast_filter(vif,
1183 &mvm->bcast_filters[i],
1184 &cmd->filters[data->current_filter]);
1186 /* skip current filter if it contains no attributes */
1187 if (!cmd->filters[data->current_filter].num_attrs)
1190 /* attach the filter to current mac */
1191 bcast_mac->attached_filters |=
1192 cpu_to_le16(BIT(data->current_filter));
1194 data->current_filter++;
1198 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1199 struct iwl_bcast_filter_cmd *cmd)
1201 struct iwl_bcast_iter_data iter_data = {
1206 memset(cmd, 0, sizeof(*cmd));
1207 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1208 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1210 #ifdef CONFIG_IWLWIFI_DEBUGFS
1211 /* use debugfs filters/macs if override is configured */
1212 if (mvm->dbgfs_bcast_filtering.override) {
1213 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1214 sizeof(cmd->filters));
1215 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1221 /* if no filters are configured, do nothing */
1222 if (!mvm->bcast_filters)
1225 /* configure and attach these filters for each associated sta vif */
1226 ieee80211_iterate_active_interfaces(
1227 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1228 iwl_mvm_bcast_filter_iterator, &iter_data);
1232 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1233 struct ieee80211_vif *vif)
1235 struct iwl_bcast_filter_cmd cmd;
1237 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1240 /* bcast filtering isn't supported for P2P client */
1244 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1247 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1251 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1252 struct ieee80211_vif *vif)
1258 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1259 struct ieee80211_vif *vif,
1260 struct ieee80211_bss_conf *bss_conf,
1263 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1267 * Re-calculate the tsf id, as the master-slave relations depend on the
1268 * beacon interval, which was not known when the station interface was
1271 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1272 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1274 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1276 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1278 if (changes & BSS_CHANGED_ASSOC) {
1279 if (bss_conf->assoc) {
1280 /* add quota for this interface */
1281 ret = iwl_mvm_update_quotas(mvm, vif);
1283 IWL_ERR(mvm, "failed to update quotas\n");
1287 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1290 * If we're restarting then the firmware will
1291 * obviously have lost synchronisation with
1292 * the AP. It will attempt to synchronise by
1293 * itself, but we can make it more reliable by
1294 * scheduling a session protection time event.
1296 * The firmware needs to receive a beacon to
1297 * catch up with synchronisation, use 110% of
1298 * the beacon interval.
1300 * Set a large maximum delay to allow for more
1301 * than a single interface.
1303 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1304 iwl_mvm_protect_session(mvm, vif, dur, dur,
1308 iwl_mvm_sf_update(mvm, vif, false);
1309 iwl_mvm_power_vif_assoc(mvm, vif);
1311 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
1312 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1314 * If update fails - SF might be running in associated
1315 * mode while disassociated - which is forbidden.
1317 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1318 "Failed to update SF upon disassociation\n");
1320 /* remove AP station now that the MAC is unassoc */
1321 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1323 IWL_ERR(mvm, "failed to remove AP station\n");
1325 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1326 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1327 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1328 /* remove quota for this interface */
1329 ret = iwl_mvm_update_quotas(mvm, NULL);
1331 IWL_ERR(mvm, "failed to update quotas\n");
1334 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
1337 iwl_mvm_recalc_multicast(mvm);
1338 iwl_mvm_configure_bcast_filter(mvm, vif);
1340 /* reset rssi values */
1341 mvmvif->bf_data.ave_beacon_signal = 0;
1343 iwl_mvm_bt_coex_vif_change(mvm);
1344 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1345 IEEE80211_SMPS_AUTOMATIC);
1346 } else if (changes & BSS_CHANGED_BEACON_INFO) {
1348 * We received a beacon _after_ association so
1349 * remove the session protection.
1351 iwl_mvm_remove_time_event(mvm, mvmvif,
1352 &mvmvif->time_event_data);
1353 iwl_mvm_sf_update(mvm, vif, false);
1354 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1355 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS |
1357 ret = iwl_mvm_power_update_mac(mvm, vif);
1359 IWL_ERR(mvm, "failed to update power mode\n");
1361 if (changes & BSS_CHANGED_TXPOWER) {
1362 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1364 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1367 if (changes & BSS_CHANGED_CQM) {
1368 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
1369 /* reset cqm events tracking */
1370 mvmvif->bf_data.last_cqm_event = 0;
1371 ret = iwl_mvm_update_beacon_filter(mvm, vif, false, 0);
1373 IWL_ERR(mvm, "failed to update CQM thresholds\n");
1376 if (changes & BSS_CHANGED_ARP_FILTER) {
1377 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
1378 iwl_mvm_configure_bcast_filter(mvm, vif);
1382 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1383 struct ieee80211_vif *vif)
1385 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1386 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1389 mutex_lock(&mvm->mutex);
1391 /* Send the beacon template */
1392 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1397 * Re-calculate the tsf id, as the master-slave relations depend on the
1398 * beacon interval, which was not known when the AP interface was added.
1400 if (vif->type == NL80211_IFTYPE_AP)
1401 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1403 /* Add the mac context */
1404 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1408 /* Perform the binding */
1409 ret = iwl_mvm_binding_add_vif(mvm, vif);
1413 /* Send the bcast station. At this stage the TBTT and DTIM time events
1414 * are added and applied to the scheduler */
1415 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
1419 /* must be set before quota calculations */
1420 mvmvif->ap_ibss_active = true;
1422 /* power updated needs to be done before quotas */
1423 iwl_mvm_power_update_mac(mvm, vif);
1425 ret = iwl_mvm_update_quotas(mvm, vif);
1427 goto out_quota_failed;
1429 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1430 if (vif->p2p && mvm->p2p_device_vif)
1431 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1433 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1435 iwl_mvm_bt_coex_vif_change(mvm);
1437 mutex_unlock(&mvm->mutex);
1441 iwl_mvm_power_update_mac(mvm, vif);
1442 mvmvif->ap_ibss_active = false;
1443 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1445 iwl_mvm_binding_remove_vif(mvm, vif);
1447 iwl_mvm_mac_ctxt_remove(mvm, vif);
1449 mutex_unlock(&mvm->mutex);
1453 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1454 struct ieee80211_vif *vif)
1456 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1457 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1459 iwl_mvm_prepare_mac_removal(mvm, vif);
1461 mutex_lock(&mvm->mutex);
1463 mvmvif->ap_ibss_active = false;
1465 iwl_mvm_bt_coex_vif_change(mvm);
1467 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
1469 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1470 if (vif->p2p && mvm->p2p_device_vif)
1471 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1473 iwl_mvm_update_quotas(mvm, NULL);
1474 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1475 iwl_mvm_binding_remove_vif(mvm, vif);
1477 iwl_mvm_power_update_mac(mvm, vif);
1479 iwl_mvm_mac_ctxt_remove(mvm, vif);
1481 mutex_unlock(&mvm->mutex);
1485 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1486 struct ieee80211_vif *vif,
1487 struct ieee80211_bss_conf *bss_conf,
1490 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1492 /* Changes will be applied when the AP/IBSS is started */
1493 if (!mvmvif->ap_ibss_active)
1496 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
1497 BSS_CHANGED_BANDWIDTH) &&
1498 iwl_mvm_mac_ctxt_changed(mvm, vif))
1499 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1501 /* Need to send a new beacon template to the FW */
1502 if (changes & BSS_CHANGED_BEACON &&
1503 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1504 IWL_WARN(mvm, "Failed updating beacon data\n");
1507 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1508 struct ieee80211_vif *vif,
1509 struct ieee80211_bss_conf *bss_conf,
1512 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1514 mutex_lock(&mvm->mutex);
1516 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
1517 iwl_mvm_sched_scan_stop(mvm, true);
1519 switch (vif->type) {
1520 case NL80211_IFTYPE_STATION:
1521 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1523 case NL80211_IFTYPE_AP:
1524 case NL80211_IFTYPE_ADHOC:
1525 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
1528 /* shouldn't happen */
1532 mutex_unlock(&mvm->mutex);
1535 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1536 struct ieee80211_vif *vif,
1537 struct cfg80211_scan_request *req)
1539 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1542 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
1545 mutex_lock(&mvm->mutex);
1547 switch (mvm->scan_status) {
1548 case IWL_MVM_SCAN_SCHED:
1549 ret = iwl_mvm_sched_scan_stop(mvm, true);
1555 case IWL_MVM_SCAN_NONE:
1562 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1564 ret = iwl_mvm_scan_request(mvm, vif, req);
1566 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1568 mutex_unlock(&mvm->mutex);
1569 /* make sure to flush the Rx handler before the next scan arrives */
1570 iwl_mvm_wait_for_async_handlers(mvm);
1574 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1575 struct ieee80211_vif *vif)
1577 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1579 mutex_lock(&mvm->mutex);
1581 iwl_mvm_cancel_scan(mvm);
1583 mutex_unlock(&mvm->mutex);
1587 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
1588 struct ieee80211_sta *sta, u16 tids,
1590 enum ieee80211_frame_release_type reason,
1593 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1595 /* Called when we need to transmit (a) frame(s) from mac80211 */
1597 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1598 tids, more_data, false);
1602 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
1603 struct ieee80211_sta *sta, u16 tids,
1605 enum ieee80211_frame_release_type reason,
1608 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1610 /* Called when we need to transmit (a) frame(s) from agg queue */
1612 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1613 tids, more_data, true);
1616 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1617 struct ieee80211_vif *vif,
1618 enum sta_notify_cmd cmd,
1619 struct ieee80211_sta *sta)
1621 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1622 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1626 case STA_NOTIFY_SLEEP:
1627 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
1628 ieee80211_sta_block_awake(hw, sta, true);
1629 spin_lock_bh(&mvmsta->lock);
1630 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1631 struct iwl_mvm_tid_data *tid_data;
1633 tid_data = &mvmsta->tid_data[tid];
1634 if (tid_data->state != IWL_AGG_ON &&
1635 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
1637 if (iwl_mvm_tid_queued(tid_data) == 0)
1639 ieee80211_sta_set_buffered(sta, tid, true);
1641 spin_unlock_bh(&mvmsta->lock);
1643 * The fw updates the STA to be asleep. Tx packets on the Tx
1644 * queues to this station will not be transmitted. The fw will
1645 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1648 case STA_NOTIFY_AWAKE:
1649 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
1651 iwl_mvm_sta_modify_ps_wake(mvm, sta);
1658 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
1659 struct ieee80211_vif *vif,
1660 struct ieee80211_sta *sta)
1662 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1663 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1666 * This is called before mac80211 does RCU synchronisation,
1667 * so here we already invalidate our internal RCU-protected
1668 * station pointer. The rest of the code will thus no longer
1669 * be able to find the station this way, and we don't rely
1670 * on further RCU synchronisation after the sta_state()
1671 * callback deleted the station.
1673 mutex_lock(&mvm->mutex);
1674 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
1675 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1677 mutex_unlock(&mvm->mutex);
1680 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1681 struct ieee80211_vif *vif,
1682 struct ieee80211_sta *sta,
1683 enum ieee80211_sta_state old_state,
1684 enum ieee80211_sta_state new_state)
1686 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1687 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1690 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1691 sta->addr, old_state, new_state);
1693 /* this would be a mac80211 bug ... but don't crash */
1694 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1697 /* if a STA is being removed, reuse its ID */
1698 flush_work(&mvm->sta_drained_wk);
1700 mutex_lock(&mvm->mutex);
1701 if (old_state == IEEE80211_STA_NOTEXIST &&
1702 new_state == IEEE80211_STA_NONE) {
1704 * Firmware bug - it'll crash if the beacon interval is less
1705 * than 16. We can't avoid connecting at all, so refuse the
1706 * station state change, this will cause mac80211 to abandon
1707 * attempts to connect to this AP, and eventually wpa_s will
1708 * blacklist the AP...
1710 if (vif->type == NL80211_IFTYPE_STATION &&
1711 vif->bss_conf.beacon_int < 16) {
1713 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1714 sta->addr, vif->bss_conf.beacon_int);
1718 ret = iwl_mvm_add_sta(mvm, vif, sta);
1719 } else if (old_state == IEEE80211_STA_NONE &&
1720 new_state == IEEE80211_STA_AUTH) {
1722 * EBS may be disabled due to previous failures reported by FW.
1723 * Reset EBS status here assuming environment has been changed.
1725 mvm->last_ebs_successful = true;
1727 } else if (old_state == IEEE80211_STA_AUTH &&
1728 new_state == IEEE80211_STA_ASSOC) {
1729 ret = iwl_mvm_update_sta(mvm, vif, sta);
1731 iwl_mvm_rs_rate_init(mvm, sta,
1732 mvmvif->phy_ctxt->channel->band,
1734 } else if (old_state == IEEE80211_STA_ASSOC &&
1735 new_state == IEEE80211_STA_AUTHORIZED) {
1736 /* enable beacon filtering */
1737 if (vif->bss_conf.dtim_period)
1738 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1740 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1741 new_state == IEEE80211_STA_ASSOC) {
1742 /* disable beacon filtering */
1743 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
1745 } else if (old_state == IEEE80211_STA_ASSOC &&
1746 new_state == IEEE80211_STA_AUTH) {
1748 } else if (old_state == IEEE80211_STA_AUTH &&
1749 new_state == IEEE80211_STA_NONE) {
1751 } else if (old_state == IEEE80211_STA_NONE &&
1752 new_state == IEEE80211_STA_NOTEXIST) {
1753 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1758 mutex_unlock(&mvm->mutex);
1763 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1765 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1767 mvm->rts_threshold = value;
1772 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
1773 struct ieee80211_vif *vif,
1774 struct ieee80211_sta *sta, u32 changed)
1776 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1778 if (vif->type == NL80211_IFTYPE_STATION &&
1779 changed & IEEE80211_RC_NSS_CHANGED)
1780 iwl_mvm_sf_update(mvm, vif, false);
1783 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1784 struct ieee80211_vif *vif, u16 ac,
1785 const struct ieee80211_tx_queue_params *params)
1787 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1788 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1790 mvmvif->queue_params[ac] = *params;
1793 * No need to update right away, we'll get BSS_CHANGED_QOS
1794 * The exception is P2P_DEVICE interface which needs immediate update.
1796 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1799 mutex_lock(&mvm->mutex);
1800 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1801 mutex_unlock(&mvm->mutex);
1807 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1808 struct ieee80211_vif *vif)
1810 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1811 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1812 200 + vif->bss_conf.beacon_int);
1813 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1814 100 + vif->bss_conf.beacon_int);
1816 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1819 mutex_lock(&mvm->mutex);
1820 /* Try really hard to protect the session and hear a beacon */
1821 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
1822 mutex_unlock(&mvm->mutex);
1825 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
1826 struct ieee80211_vif *vif,
1827 struct cfg80211_sched_scan_request *req,
1828 struct ieee80211_sched_scan_ies *ies)
1830 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1833 mutex_lock(&mvm->mutex);
1835 if (!iwl_mvm_is_idle(mvm)) {
1840 switch (mvm->scan_status) {
1841 case IWL_MVM_SCAN_OS:
1842 IWL_DEBUG_SCAN(mvm, "Stopping previous scan for sched_scan\n");
1843 ret = iwl_mvm_cancel_scan(mvm);
1850 * iwl_mvm_rx_scan_complete() will be called soon but will
1851 * not reset the scan status as it won't be IWL_MVM_SCAN_OS
1852 * any more since we queue the next scan immediately (below).
1853 * We make sure it is called before the next scan starts by
1854 * flushing the async-handlers work.
1857 case IWL_MVM_SCAN_NONE:
1864 mvm->scan_status = IWL_MVM_SCAN_SCHED;
1866 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
1870 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1874 ret = iwl_mvm_sched_scan_start(mvm, req);
1878 mvm->scan_status = IWL_MVM_SCAN_NONE;
1880 mutex_unlock(&mvm->mutex);
1881 /* make sure to flush the Rx handler before the next scan arrives */
1882 iwl_mvm_wait_for_async_handlers(mvm);
1886 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
1887 struct ieee80211_vif *vif)
1889 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1892 mutex_lock(&mvm->mutex);
1893 ret = iwl_mvm_sched_scan_stop(mvm, false);
1894 mutex_unlock(&mvm->mutex);
1895 iwl_mvm_wait_for_async_handlers(mvm);
1900 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1901 enum set_key_cmd cmd,
1902 struct ieee80211_vif *vif,
1903 struct ieee80211_sta *sta,
1904 struct ieee80211_key_conf *key)
1906 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1909 if (iwlwifi_mod_params.sw_crypto) {
1910 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1914 switch (key->cipher) {
1915 case WLAN_CIPHER_SUITE_TKIP:
1916 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1918 case WLAN_CIPHER_SUITE_CCMP:
1919 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1921 case WLAN_CIPHER_SUITE_AES_CMAC:
1922 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1924 case WLAN_CIPHER_SUITE_WEP40:
1925 case WLAN_CIPHER_SUITE_WEP104:
1927 * Support for TX only, at least for now, so accept
1928 * the key and do nothing else. Then mac80211 will
1929 * pass it for TX but we don't have to use it for RX.
1933 /* currently FW supports only one optional cipher scheme */
1934 if (hw->n_cipher_schemes &&
1935 hw->cipher_schemes->cipher == key->cipher)
1936 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
1941 mutex_lock(&mvm->mutex);
1945 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1946 vif->type == NL80211_IFTYPE_AP) && !sta) {
1948 * GTK on AP interface is a TX-only key, return 0;
1949 * on IBSS they're per-station and because we're lazy
1950 * we don't support them for RX, so do the same.
1953 key->hw_key_idx = STA_KEY_IDX_INVALID;
1957 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1958 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1960 IWL_WARN(mvm, "set key failed\n");
1962 * can't add key for RX, but we don't need it
1963 * in the device for TX so still return 0
1965 key->hw_key_idx = STA_KEY_IDX_INVALID;
1971 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1976 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1977 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1983 mutex_unlock(&mvm->mutex);
1987 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1988 struct ieee80211_vif *vif,
1989 struct ieee80211_key_conf *keyconf,
1990 struct ieee80211_sta *sta,
1991 u32 iv32, u16 *phase1key)
1993 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1995 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
1998 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2002 static int iwl_mvm_roc(struct ieee80211_hw *hw,
2003 struct ieee80211_vif *vif,
2004 struct ieee80211_channel *channel,
2006 enum ieee80211_roc_type type)
2008 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2009 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2010 struct cfg80211_chan_def chandef;
2011 struct iwl_mvm_phy_ctxt *phy_ctxt;
2014 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2017 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
2018 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
2022 mutex_lock(&mvm->mutex);
2024 for (i = 0; i < NUM_PHY_CTX; i++) {
2025 phy_ctxt = &mvm->phy_ctxts[i];
2026 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2029 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2031 * Unbind the P2P_DEVICE from the current PHY context,
2032 * and if the PHY context is not used remove it.
2034 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2035 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2038 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2040 /* Bind the P2P_DEVICE to the current PHY Context */
2041 mvmvif->phy_ctxt = phy_ctxt;
2043 ret = iwl_mvm_binding_add_vif(mvm, vif);
2044 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2047 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2048 goto schedule_time_event;
2052 /* Need to update the PHY context only if the ROC channel changed */
2053 if (channel == mvmvif->phy_ctxt->channel)
2054 goto schedule_time_event;
2056 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
2059 * Change the PHY context configuration as it is currently referenced
2060 * only by the P2P Device MAC
2062 if (mvmvif->phy_ctxt->ref == 1) {
2063 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2069 * The PHY context is shared with other MACs. Need to remove the
2070 * P2P Device from the binding, allocate an new PHY context and
2071 * create a new binding
2073 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2079 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2082 IWL_ERR(mvm, "Failed to change PHY context\n");
2086 /* Unbind the P2P_DEVICE from the current PHY context */
2087 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2088 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2091 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2093 /* Bind the P2P_DEVICE to the new allocated PHY context */
2094 mvmvif->phy_ctxt = phy_ctxt;
2096 ret = iwl_mvm_binding_add_vif(mvm, vif);
2097 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2100 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2103 schedule_time_event:
2104 /* Schedule the time events */
2105 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
2108 mutex_unlock(&mvm->mutex);
2109 IWL_DEBUG_MAC80211(mvm, "leave\n");
2113 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2115 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2117 IWL_DEBUG_MAC80211(mvm, "enter\n");
2119 mutex_lock(&mvm->mutex);
2120 iwl_mvm_stop_p2p_roc(mvm);
2121 mutex_unlock(&mvm->mutex);
2123 IWL_DEBUG_MAC80211(mvm, "leave\n");
2127 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2128 struct ieee80211_chanctx_conf *ctx)
2130 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2131 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2132 struct iwl_mvm_phy_ctxt *phy_ctxt;
2135 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
2137 mutex_lock(&mvm->mutex);
2138 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2144 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
2145 ctx->rx_chains_static,
2146 ctx->rx_chains_dynamic);
2148 IWL_ERR(mvm, "Failed to add PHY context\n");
2152 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
2153 *phy_ctxt_id = phy_ctxt->id;
2155 mutex_unlock(&mvm->mutex);
2159 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2160 struct ieee80211_chanctx_conf *ctx)
2162 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2163 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2164 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2166 mutex_lock(&mvm->mutex);
2167 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
2168 mutex_unlock(&mvm->mutex);
2171 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2172 struct ieee80211_chanctx_conf *ctx,
2175 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2176 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2177 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2179 if (WARN_ONCE((phy_ctxt->ref > 1) &&
2180 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
2181 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
2182 IEEE80211_CHANCTX_CHANGE_RADAR |
2183 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
2184 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2185 phy_ctxt->ref, changed))
2188 mutex_lock(&mvm->mutex);
2189 iwl_mvm_bt_coex_vif_change(mvm);
2190 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
2191 ctx->rx_chains_static,
2192 ctx->rx_chains_dynamic);
2193 mutex_unlock(&mvm->mutex);
2196 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
2197 struct ieee80211_vif *vif,
2198 struct ieee80211_chanctx_conf *ctx)
2200 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2201 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2202 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2203 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2206 mutex_lock(&mvm->mutex);
2208 mvmvif->phy_ctxt = phy_ctxt;
2210 switch (vif->type) {
2211 case NL80211_IFTYPE_AP:
2212 /* Unless it's a CSA flow we have nothing to do here */
2213 if (vif->csa_active) {
2214 mvmvif->ap_ibss_active = true;
2217 case NL80211_IFTYPE_ADHOC:
2219 * The AP binding flow is handled as part of the start_ap flow
2220 * (in bss_info_changed), similarly for IBSS.
2224 case NL80211_IFTYPE_STATION:
2225 case NL80211_IFTYPE_MONITOR:
2232 ret = iwl_mvm_binding_add_vif(mvm, vif);
2237 * Power state must be updated before quotas,
2238 * otherwise fw will complain.
2240 iwl_mvm_power_update_mac(mvm, vif);
2242 /* Setting the quota at this stage is only required for monitor
2243 * interfaces. For the other types, the bss_info changed flow
2244 * will handle quota settings.
2246 if (vif->type == NL80211_IFTYPE_MONITOR) {
2247 mvmvif->monitor_active = true;
2248 ret = iwl_mvm_update_quotas(mvm, vif);
2250 goto out_remove_binding;
2253 /* Handle binding during CSA */
2254 if (vif->type == NL80211_IFTYPE_AP) {
2255 iwl_mvm_update_quotas(mvm, vif);
2256 iwl_mvm_mac_ctxt_changed(mvm, vif);
2262 iwl_mvm_binding_remove_vif(mvm, vif);
2263 iwl_mvm_power_update_mac(mvm, vif);
2265 mutex_unlock(&mvm->mutex);
2267 mvmvif->phy_ctxt = NULL;
2271 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
2272 struct ieee80211_vif *vif,
2273 struct ieee80211_chanctx_conf *ctx)
2275 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2276 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2278 mutex_lock(&mvm->mutex);
2280 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
2282 switch (vif->type) {
2283 case NL80211_IFTYPE_ADHOC:
2285 case NL80211_IFTYPE_MONITOR:
2286 mvmvif->monitor_active = false;
2287 iwl_mvm_update_quotas(mvm, NULL);
2289 case NL80211_IFTYPE_AP:
2290 /* This part is triggered only during CSA */
2291 if (!vif->csa_active || !mvmvif->ap_ibss_active)
2294 mvmvif->ap_ibss_active = false;
2295 iwl_mvm_update_quotas(mvm, NULL);
2296 /*TODO: bt_coex notification here? */
2301 iwl_mvm_binding_remove_vif(mvm, vif);
2302 iwl_mvm_power_update_mac(mvm, vif);
2305 mvmvif->phy_ctxt = NULL;
2306 mutex_unlock(&mvm->mutex);
2309 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
2310 struct ieee80211_sta *sta,
2313 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2314 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
2316 if (!mvm_sta || !mvm_sta->vif) {
2317 IWL_ERR(mvm, "Station is not associated to a vif\n");
2321 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
2324 #ifdef CONFIG_NL80211_TESTMODE
2325 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
2326 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
2327 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
2328 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
2331 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
2332 struct ieee80211_vif *vif,
2333 void *data, int len)
2335 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
2339 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
2343 if (!tb[IWL_MVM_TM_ATTR_CMD])
2346 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
2347 case IWL_MVM_TM_CMD_SET_NOA:
2348 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
2349 !vif->bss_conf.enable_beacon ||
2350 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
2353 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
2354 if (noa_duration >= vif->bss_conf.beacon_int)
2357 mvm->noa_duration = noa_duration;
2360 return iwl_mvm_update_quotas(mvm, NULL);
2361 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
2362 /* must be associated client vif - ignore authorized */
2363 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
2364 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
2365 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
2368 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
2369 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2370 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
2376 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
2377 struct ieee80211_vif *vif,
2378 void *data, int len)
2380 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2383 mutex_lock(&mvm->mutex);
2384 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
2385 mutex_unlock(&mvm->mutex);
2391 static void iwl_mvm_channel_switch_beacon(struct ieee80211_hw *hw,
2392 struct ieee80211_vif *vif,
2393 struct cfg80211_chan_def *chandef)
2395 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2397 mutex_lock(&mvm->mutex);
2398 if (WARN(mvm->csa_vif && mvm->csa_vif->csa_active,
2399 "Another CSA is already in progress"))
2402 IWL_DEBUG_MAC80211(mvm, "CSA started to freq %d\n",
2403 chandef->center_freq1);
2407 mutex_unlock(&mvm->mutex);
2410 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
2411 struct ieee80211_vif *vif, u32 queues, bool drop)
2413 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2414 struct iwl_mvm_vif *mvmvif;
2415 struct iwl_mvm_sta *mvmsta;
2417 if (!vif || vif->type != NL80211_IFTYPE_STATION)
2420 mutex_lock(&mvm->mutex);
2421 mvmvif = iwl_mvm_vif_from_mac80211(vif);
2422 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, mvmvif->ap_sta_id);
2424 if (WARN_ON_ONCE(!mvmsta))
2428 if (iwl_mvm_flush_tx_path(mvm, mvmsta->tfd_queue_msk, true))
2429 IWL_ERR(mvm, "flush request fail\n");
2431 iwl_trans_wait_tx_queue_empty(mvm->trans,
2432 mvmsta->tfd_queue_msk);
2435 mutex_unlock(&mvm->mutex);
2438 const struct ieee80211_ops iwl_mvm_hw_ops = {
2439 .tx = iwl_mvm_mac_tx,
2440 .ampdu_action = iwl_mvm_mac_ampdu_action,
2441 .start = iwl_mvm_mac_start,
2442 .restart_complete = iwl_mvm_mac_restart_complete,
2443 .stop = iwl_mvm_mac_stop,
2444 .add_interface = iwl_mvm_mac_add_interface,
2445 .remove_interface = iwl_mvm_mac_remove_interface,
2446 .config = iwl_mvm_mac_config,
2447 .prepare_multicast = iwl_mvm_prepare_multicast,
2448 .configure_filter = iwl_mvm_configure_filter,
2449 .bss_info_changed = iwl_mvm_bss_info_changed,
2450 .hw_scan = iwl_mvm_mac_hw_scan,
2451 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
2452 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
2453 .sta_state = iwl_mvm_mac_sta_state,
2454 .sta_notify = iwl_mvm_mac_sta_notify,
2455 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
2456 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
2457 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
2458 .sta_rc_update = iwl_mvm_sta_rc_update,
2459 .conf_tx = iwl_mvm_mac_conf_tx,
2460 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
2461 .flush = iwl_mvm_mac_flush,
2462 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
2463 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
2464 .set_key = iwl_mvm_mac_set_key,
2465 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
2466 .remain_on_channel = iwl_mvm_roc,
2467 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
2468 .add_chanctx = iwl_mvm_add_chanctx,
2469 .remove_chanctx = iwl_mvm_remove_chanctx,
2470 .change_chanctx = iwl_mvm_change_chanctx,
2471 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
2472 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
2474 .start_ap = iwl_mvm_start_ap_ibss,
2475 .stop_ap = iwl_mvm_stop_ap_ibss,
2476 .join_ibss = iwl_mvm_start_ap_ibss,
2477 .leave_ibss = iwl_mvm_stop_ap_ibss,
2479 .set_tim = iwl_mvm_set_tim,
2481 .channel_switch_beacon = iwl_mvm_channel_switch_beacon,
2483 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
2485 #ifdef CONFIG_PM_SLEEP
2487 .suspend = iwl_mvm_suspend,
2488 .resume = iwl_mvm_resume,
2489 .set_wakeup = iwl_mvm_set_wakeup,
2490 .set_rekey_data = iwl_mvm_set_rekey_data,
2491 #if IS_ENABLED(CONFIG_IPV6)
2492 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
2494 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,