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>
73 #include "iwl-op-mode.h"
77 #include "time-event.h"
78 #include "iwl-eeprom-parse.h"
79 #include "fw-api-scan.h"
80 #include "iwl-phy-db.h"
83 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
86 .types = BIT(NL80211_IFTYPE_STATION),
90 .types = BIT(NL80211_IFTYPE_AP) |
91 BIT(NL80211_IFTYPE_P2P_CLIENT) |
92 BIT(NL80211_IFTYPE_P2P_GO),
96 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
100 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
102 .num_different_channels = 1,
104 .limits = iwl_mvm_limits,
105 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
109 #ifdef CONFIG_PM_SLEEP
110 static const struct nl80211_wowlan_tcp_data_token_feature
111 iwl_mvm_wowlan_tcp_token_feature = {
114 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
117 static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
118 .tok = &iwl_mvm_wowlan_tcp_token_feature,
119 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
120 sizeof(struct ethhdr) -
121 sizeof(struct iphdr) -
122 sizeof(struct tcphdr),
123 .data_interval_max = 65535, /* __le16 in API */
124 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
125 sizeof(struct ethhdr) -
126 sizeof(struct iphdr) -
127 sizeof(struct tcphdr),
132 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
134 * Use the reserved field to indicate magic values.
135 * these values will only be used internally by the driver,
136 * and won't make it to the fw (reserved will be 0).
137 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
138 * be the vif's ip address. in case there is not a single
139 * ip address (0, or more than 1), this attribute will
141 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
142 * the LSB bytes of the vif's mac address
145 BC_FILTER_MAGIC_NONE = 0,
150 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
154 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
157 /* frame type - arp, hw type - ethernet */
159 BCAST_FILTER_OFFSET_PAYLOAD_START,
160 .offset = sizeof(rfc1042_header),
161 .val = cpu_to_be32(0x08060001),
162 .mask = cpu_to_be32(0xffffffff),
167 BCAST_FILTER_OFFSET_PAYLOAD_START,
168 .offset = sizeof(rfc1042_header) + 2 +
169 sizeof(struct arphdr) +
170 ETH_ALEN + sizeof(__be32) +
172 .mask = cpu_to_be32(0xffffffff),
173 /* mark it as special field */
174 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
179 /* dhcp offer bcast */
181 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
184 /* udp dest port - 68 (bootp client)*/
185 .offset_type = BCAST_FILTER_OFFSET_IP_END,
186 .offset = offsetof(struct udphdr, dest),
187 .val = cpu_to_be32(0x00440000),
188 .mask = cpu_to_be32(0xffff0000),
191 /* dhcp - lsb bytes of client hw address */
192 .offset_type = BCAST_FILTER_OFFSET_IP_END,
194 .mask = cpu_to_be32(0xffffffff),
195 /* mark it as special field */
196 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
200 /* last filter must be empty */
205 void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
207 if (!mvm->trans->cfg->d0i3)
210 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
211 WARN_ON(test_and_set_bit(ref_type, mvm->ref_bitmap));
212 iwl_trans_ref(mvm->trans);
215 void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
217 if (!mvm->trans->cfg->d0i3)
220 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
221 WARN_ON(!test_and_clear_bit(ref_type, mvm->ref_bitmap));
222 iwl_trans_unref(mvm->trans);
226 iwl_mvm_unref_all_except(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref)
230 if (!mvm->trans->cfg->d0i3)
233 for_each_set_bit(i, mvm->ref_bitmap, IWL_MVM_REF_COUNT) {
237 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d\n", i);
238 clear_bit(i, mvm->ref_bitmap);
239 iwl_trans_unref(mvm->trans);
243 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
247 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
248 for (i = 0; i < NUM_PHY_CTX; i++) {
249 mvm->phy_ctxts[i].id = i;
250 mvm->phy_ctxts[i].ref = 0;
254 static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
256 /* we create the 802.11 header and SSID element */
257 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID)
258 return mvm->fw->ucode_capa.max_probe_length - 24 - 2;
259 return mvm->fw->ucode_capa.max_probe_length - 24 - 34;
262 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
264 struct ieee80211_hw *hw = mvm->hw;
267 /* Tell mac80211 our characteristics */
268 hw->flags = IEEE80211_HW_SIGNAL_DBM |
269 IEEE80211_HW_SPECTRUM_MGMT |
270 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
271 IEEE80211_HW_QUEUE_CONTROL |
272 IEEE80211_HW_WANT_MONITOR_VIF |
273 IEEE80211_HW_SUPPORTS_PS |
274 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
275 IEEE80211_HW_AMPDU_AGGREGATION |
276 IEEE80211_HW_TIMING_BEACON_ONLY |
277 IEEE80211_HW_CONNECTION_MONITOR |
278 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
279 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
281 hw->queues = mvm->first_agg_queue;
282 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
283 hw->rate_control_algorithm = "iwl-mvm-rs";
286 * Enable 11w if advertised by firmware and software crypto
287 * is not enabled (as the firmware will interpret some mgmt
288 * packets, so enabling it with software crypto isn't safe)
290 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
291 !iwlwifi_mod_params.sw_crypto)
292 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
294 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT) {
295 hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
296 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
297 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
300 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
301 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
302 hw->chanctx_data_size = sizeof(u16);
304 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
305 BIT(NL80211_IFTYPE_P2P_CLIENT) |
306 BIT(NL80211_IFTYPE_AP) |
307 BIT(NL80211_IFTYPE_P2P_GO) |
308 BIT(NL80211_IFTYPE_P2P_DEVICE);
310 /* IBSS has bugs in older versions */
311 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 8)
312 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
314 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
315 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
316 REGULATORY_DISABLE_BEACON_HINTS;
318 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
319 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
321 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
322 hw->wiphy->n_iface_combinations =
323 ARRAY_SIZE(iwl_mvm_iface_combinations);
325 hw->wiphy->max_remain_on_channel_duration = 10000;
326 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
328 /* Extract MAC address */
329 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
330 hw->wiphy->addresses = mvm->addresses;
331 hw->wiphy->n_addresses = 1;
333 /* Extract additional MAC addresses if available */
334 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
335 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
337 for (i = 1; i < num_mac; i++) {
338 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
340 mvm->addresses[i].addr[5]++;
341 hw->wiphy->n_addresses++;
344 iwl_mvm_reset_phy_ctxts(mvm);
346 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
348 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
350 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
351 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
352 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
353 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
354 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
355 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
357 hw->wiphy->hw_version = mvm->trans->hw_id;
359 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
360 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
362 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
364 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SCHED_SCAN) {
365 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
366 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
367 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
368 /* we create the 802.11 header and zero length SSID IE. */
369 hw->wiphy->max_sched_scan_ie_len =
370 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
373 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
374 NL80211_FEATURE_P2P_GO_OPPPS |
375 NL80211_FEATURE_LOW_PRIORITY_SCAN;
377 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
379 /* currently FW API supports only one optional cipher scheme */
380 if (mvm->fw->cs[0].cipher) {
381 mvm->hw->n_cipher_schemes = 1;
382 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
385 #ifdef CONFIG_PM_SLEEP
386 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
387 mvm->trans->ops->d3_suspend &&
388 mvm->trans->ops->d3_resume &&
389 device_can_wakeup(mvm->trans->dev)) {
390 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
391 WIPHY_WOWLAN_DISCONNECT |
392 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
393 WIPHY_WOWLAN_RFKILL_RELEASE;
394 if (!iwlwifi_mod_params.sw_crypto)
395 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
396 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
397 WIPHY_WOWLAN_4WAY_HANDSHAKE;
399 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
400 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
401 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
402 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
403 hw->wiphy->wowlan = &mvm->wowlan;
407 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
408 /* assign default bcast filtering configuration */
409 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
412 ret = iwl_mvm_leds_init(mvm);
416 ret = ieee80211_register_hw(mvm->hw);
418 iwl_mvm_leds_exit(mvm);
423 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
424 struct ieee80211_tx_control *control,
427 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
428 struct ieee80211_sta *sta = control->sta;
429 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
430 struct ieee80211_hdr *hdr = (void *)skb->data;
432 if (iwl_mvm_is_radio_killed(mvm)) {
433 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
437 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
438 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
441 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
442 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
443 ieee80211_is_mgmt(hdr->frame_control) &&
444 !ieee80211_is_deauth(hdr->frame_control) &&
445 !ieee80211_is_disassoc(hdr->frame_control) &&
446 !ieee80211_is_action(hdr->frame_control)))
450 if (iwl_mvm_tx_skb(mvm, skb, sta))
455 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
459 ieee80211_free_txskb(hw, skb);
462 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
463 struct ieee80211_vif *vif,
464 enum ieee80211_ampdu_mlme_action action,
465 struct ieee80211_sta *sta, u16 tid,
466 u16 *ssn, u8 buf_size)
468 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
471 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
472 sta->addr, tid, action);
474 if (!(mvm->nvm_data->sku_cap_11n_enable))
477 mutex_lock(&mvm->mutex);
480 case IEEE80211_AMPDU_RX_START:
481 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
485 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
487 case IEEE80211_AMPDU_RX_STOP:
488 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
490 case IEEE80211_AMPDU_TX_START:
491 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
495 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
497 case IEEE80211_AMPDU_TX_STOP_CONT:
498 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
500 case IEEE80211_AMPDU_TX_STOP_FLUSH:
501 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
502 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
504 case IEEE80211_AMPDU_TX_OPERATIONAL:
505 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
512 mutex_unlock(&mvm->mutex);
517 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
518 struct ieee80211_vif *vif)
520 struct iwl_mvm *mvm = data;
521 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
523 mvmvif->uploaded = false;
524 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
526 /* does this make sense at all? */
529 spin_lock_bh(&mvm->time_event_lock);
530 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
531 spin_unlock_bh(&mvm->time_event_lock);
533 mvmvif->phy_ctxt = NULL;
536 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
538 iwl_trans_stop_device(mvm->trans);
540 mvm->scan_status = IWL_MVM_SCAN_NONE;
542 /* just in case one was running */
543 ieee80211_remain_on_channel_expired(mvm->hw);
545 ieee80211_iterate_active_interfaces_atomic(
546 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
547 iwl_mvm_cleanup_iterator, mvm);
549 mvm->p2p_device_vif = NULL;
551 iwl_mvm_reset_phy_ctxts(mvm);
552 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
553 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
555 ieee80211_wake_queues(mvm->hw);
557 /* cleanup all stale references (scan, roc), but keep the
558 * ucode_down ref until reconfig is complete */
559 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
562 mvm->rx_ba_sessions = 0;
565 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
567 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
570 mutex_lock(&mvm->mutex);
572 /* Clean up some internal and mac80211 state on restart */
573 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
574 iwl_mvm_restart_cleanup(mvm);
576 ret = iwl_mvm_up(mvm);
577 mutex_unlock(&mvm->mutex);
582 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
584 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
587 mutex_lock(&mvm->mutex);
589 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
590 ret = iwl_mvm_update_quotas(mvm, NULL);
592 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
595 /* allow transport/FW low power modes */
596 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
598 mutex_unlock(&mvm->mutex);
601 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
603 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
605 flush_work(&mvm->async_handlers_wk);
607 mutex_lock(&mvm->mutex);
609 /* disallow low power states when the FW is down */
610 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
612 /* async_handlers_wk is now blocked */
615 * The work item could be running or queued if the
616 * ROC time event stops just as we get here.
618 cancel_work_sync(&mvm->roc_done_wk);
620 iwl_trans_stop_device(mvm->trans);
622 iwl_mvm_async_handlers_purge(mvm);
623 /* async_handlers_list is empty and will stay empty: HW is stopped */
625 /* the fw is stopped, the aux sta is dead: clean up driver state */
626 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
628 mutex_unlock(&mvm->mutex);
631 * The worker might have been waiting for the mutex, let it run and
632 * discover that its list is now empty.
634 cancel_work_sync(&mvm->async_handlers_wk);
637 static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
638 struct ieee80211_vif *vif)
640 struct iwl_mvm *mvm = data;
642 iwl_mvm_power_update_mode(mvm, vif);
645 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
649 lockdep_assert_held(&mvm->mutex);
651 for (i = 0; i < NUM_PHY_CTX; i++)
652 if (!mvm->phy_ctxts[i].ref)
653 return &mvm->phy_ctxts[i];
655 IWL_ERR(mvm, "No available PHY context\n");
659 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
662 /* FW is in charge of regulatory enforcement */
663 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
664 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
665 .pwr_restriction = cpu_to_le16(tx_power),
668 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
669 sizeof(reduce_txpwr_cmd),
673 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
674 struct ieee80211_vif *vif)
676 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
677 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
681 * Not much to do here. The stack will not allow interface
682 * types or combinations that we didn't advertise, so we
683 * don't really have to check the types.
686 mutex_lock(&mvm->mutex);
688 /* Allocate resources for the MAC context, and add it to the fw */
689 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
693 /* Counting number of interfaces is needed for legacy PM */
694 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
698 * The AP binding flow can be done only after the beacon
699 * template is configured (which happens only in the mac80211
700 * start_ap() flow), and adding the broadcast station can happen
701 * only after the binding.
702 * In addition, since modifying the MAC before adding a bcast
703 * station is not allowed by the FW, delay the adding of MAC context to
704 * the point where we can also add the bcast station.
705 * In short: there's not much we can do at this point, other than
706 * allocating resources :)
708 if (vif->type == NL80211_IFTYPE_AP ||
709 vif->type == NL80211_IFTYPE_ADHOC) {
710 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
711 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
714 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
718 iwl_mvm_vif_dbgfs_register(mvm, vif);
722 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
726 iwl_mvm_power_disable(mvm, vif);
728 /* beacon filtering */
729 ret = iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC);
733 if (!mvm->bf_allowed_vif &&
734 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
735 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
736 mvm->bf_allowed_vif = mvmvif;
737 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
738 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
742 * P2P_DEVICE interface does not have a channel context assigned to it,
743 * so a dedicated PHY context is allocated to it and the corresponding
744 * MAC context is bound to it at this stage.
746 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
748 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
749 if (!mvmvif->phy_ctxt) {
754 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
755 ret = iwl_mvm_binding_add_vif(mvm, vif);
759 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
763 /* Save a pointer to p2p device vif, so it can later be used to
764 * update the p2p device MAC when a GO is started/stopped */
765 mvm->p2p_device_vif = vif;
768 iwl_mvm_vif_dbgfs_register(mvm, vif);
772 iwl_mvm_binding_remove_vif(mvm, vif);
774 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
776 if (mvm->bf_allowed_vif == mvmvif) {
777 mvm->bf_allowed_vif = NULL;
778 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
779 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
782 mvmvif->phy_ctxt = NULL;
783 iwl_mvm_mac_ctxt_remove(mvm, vif);
785 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
788 /* TODO: remove this when legacy PM will be discarded */
789 ieee80211_iterate_active_interfaces(
790 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
791 iwl_mvm_power_update_iterator, mvm);
793 iwl_mvm_mac_ctxt_release(mvm, vif);
795 mutex_unlock(&mvm->mutex);
800 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
801 struct ieee80211_vif *vif)
805 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
806 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
807 tfd_msk |= BIT(vif->hw_queue[ac]);
809 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
810 tfd_msk |= BIT(vif->cab_queue);
813 mutex_lock(&mvm->mutex);
814 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
815 mutex_unlock(&mvm->mutex);
818 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
820 * Flush the ROC worker which will flush the OFFCHANNEL queue.
821 * We assume here that all the packets sent to the OFFCHANNEL
822 * queue are sent in ROC session.
824 flush_work(&mvm->roc_done_wk);
827 * By now, all the AC queues are empty. The AGG queues are
828 * empty too. We already got all the Tx responses for all the
829 * packets in the queues. The drain work can have been
830 * triggered. Flush it.
832 flush_work(&mvm->sta_drained_wk);
836 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
837 struct ieee80211_vif *vif)
839 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
840 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
842 iwl_mvm_prepare_mac_removal(mvm, vif);
844 mutex_lock(&mvm->mutex);
846 if (mvm->bf_allowed_vif == mvmvif) {
847 mvm->bf_allowed_vif = NULL;
848 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
849 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
852 iwl_mvm_vif_dbgfs_clean(mvm, vif);
855 * For AP/GO interface, the tear down of the resources allocated to the
856 * interface is be handled as part of the stop_ap flow.
858 if (vif->type == NL80211_IFTYPE_AP ||
859 vif->type == NL80211_IFTYPE_ADHOC) {
860 #ifdef CONFIG_NL80211_TESTMODE
861 if (vif == mvm->noa_vif) {
863 mvm->noa_duration = 0;
866 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
870 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
871 mvm->p2p_device_vif = NULL;
872 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
873 iwl_mvm_binding_remove_vif(mvm, vif);
874 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
875 mvmvif->phy_ctxt = NULL;
878 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
881 /* TODO: remove this when legacy PM will be discarded */
882 ieee80211_iterate_active_interfaces(
883 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
884 iwl_mvm_power_update_iterator, mvm);
886 iwl_mvm_mac_ctxt_remove(mvm, vif);
889 iwl_mvm_mac_ctxt_release(mvm, vif);
890 mutex_unlock(&mvm->mutex);
893 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
898 struct iwl_mvm_mc_iter_data {
903 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
904 struct ieee80211_vif *vif)
906 struct iwl_mvm_mc_iter_data *data = _data;
907 struct iwl_mvm *mvm = data->mvm;
908 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
911 /* if we don't have free ports, mcast frames will be dropped */
912 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
915 if (vif->type != NL80211_IFTYPE_STATION ||
916 !vif->bss_conf.assoc)
919 cmd->port_id = data->port_id++;
920 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
921 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
923 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC, len, cmd);
925 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
928 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
930 struct iwl_mvm_mc_iter_data iter_data = {
934 lockdep_assert_held(&mvm->mutex);
936 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
939 ieee80211_iterate_active_interfaces(
940 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
941 iwl_mvm_mc_iface_iterator, &iter_data);
944 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
945 struct netdev_hw_addr_list *mc_list)
947 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
948 struct iwl_mcast_filter_cmd *cmd;
949 struct netdev_hw_addr *addr;
950 int addr_count = netdev_hw_addr_list_count(mc_list);
951 bool pass_all = false;
954 if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) {
959 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
960 cmd = kzalloc(len, GFP_ATOMIC);
966 return (u64)(unsigned long)cmd;
969 netdev_hw_addr_list_for_each(addr, mc_list) {
970 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
971 cmd->count, addr->addr);
972 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
973 addr->addr, ETH_ALEN);
977 return (u64)(unsigned long)cmd;
980 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
981 unsigned int changed_flags,
982 unsigned int *total_flags,
985 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
986 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
988 mutex_lock(&mvm->mutex);
990 /* replace previous configuration */
991 kfree(mvm->mcast_filter_cmd);
992 mvm->mcast_filter_cmd = cmd;
997 iwl_mvm_recalc_multicast(mvm);
999 mutex_unlock(&mvm->mutex);
1003 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1004 struct iwl_bcast_iter_data {
1005 struct iwl_mvm *mvm;
1006 struct iwl_bcast_filter_cmd *cmd;
1011 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1012 const struct iwl_fw_bcast_filter *in_filter,
1013 struct iwl_fw_bcast_filter *out_filter)
1015 struct iwl_fw_bcast_filter_attr *attr;
1018 memcpy(out_filter, in_filter, sizeof(*out_filter));
1020 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1021 attr = &out_filter->attrs[i];
1026 switch (attr->reserved1) {
1027 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1028 if (vif->bss_conf.arp_addr_cnt != 1) {
1033 attr->val = vif->bss_conf.arp_addr_list[0];
1035 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1036 attr->val = *(__be32 *)&vif->addr[2];
1041 attr->reserved1 = 0;
1042 out_filter->num_attrs++;
1046 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1047 struct ieee80211_vif *vif)
1049 struct iwl_bcast_iter_data *data = _data;
1050 struct iwl_mvm *mvm = data->mvm;
1051 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1052 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1053 struct iwl_fw_bcast_mac *bcast_mac;
1056 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1059 bcast_mac = &cmd->macs[mvmvif->id];
1061 /* enable filtering only for associated stations */
1062 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc)
1065 bcast_mac->default_discard = 1;
1067 /* copy all configured filters */
1068 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1070 * Make sure we don't exceed our filters limit.
1071 * if there is still a valid filter to be configured,
1072 * be on the safe side and just allow bcast for this mac.
1074 if (WARN_ON_ONCE(data->current_filter >=
1075 ARRAY_SIZE(cmd->filters))) {
1076 bcast_mac->default_discard = 0;
1077 bcast_mac->attached_filters = 0;
1081 iwl_mvm_set_bcast_filter(vif,
1082 &mvm->bcast_filters[i],
1083 &cmd->filters[data->current_filter]);
1085 /* skip current filter if it contains no attributes */
1086 if (!cmd->filters[data->current_filter].num_attrs)
1089 /* attach the filter to current mac */
1090 bcast_mac->attached_filters |=
1091 cpu_to_le16(BIT(data->current_filter));
1093 data->current_filter++;
1097 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1098 struct iwl_bcast_filter_cmd *cmd)
1100 struct iwl_bcast_iter_data iter_data = {
1105 memset(cmd, 0, sizeof(*cmd));
1106 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1107 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1109 #ifdef CONFIG_IWLWIFI_DEBUGFS
1110 /* use debugfs filters/macs if override is configured */
1111 if (mvm->dbgfs_bcast_filtering.override) {
1112 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1113 sizeof(cmd->filters));
1114 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1120 /* if no filters are configured, do nothing */
1121 if (!mvm->bcast_filters)
1124 /* configure and attach these filters for each associated sta vif */
1125 ieee80211_iterate_active_interfaces(
1126 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1127 iwl_mvm_bcast_filter_iterator, &iter_data);
1131 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1132 struct ieee80211_vif *vif)
1134 struct iwl_bcast_filter_cmd cmd;
1136 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1139 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1142 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, CMD_SYNC,
1146 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1147 struct ieee80211_vif *vif)
1153 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1154 struct ieee80211_vif *vif,
1155 struct ieee80211_bss_conf *bss_conf,
1158 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1162 * Re-calculate the tsf id, as the master-slave relations depend on the
1163 * beacon interval, which was not known when the station interface was
1166 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1167 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1169 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1171 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1173 if (changes & BSS_CHANGED_ASSOC) {
1174 if (bss_conf->assoc) {
1175 /* add quota for this interface */
1176 ret = iwl_mvm_update_quotas(mvm, vif);
1178 IWL_ERR(mvm, "failed to update quotas\n");
1182 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1185 * If we're restarting then the firmware will
1186 * obviously have lost synchronisation with
1187 * the AP. It will attempt to synchronise by
1188 * itself, but we can make it more reliable by
1189 * scheduling a session protection time event.
1191 * The firmware needs to receive a beacon to
1192 * catch up with synchronisation, use 110% of
1193 * the beacon interval.
1195 * Set a large maximum delay to allow for more
1196 * than a single interface.
1198 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1199 iwl_mvm_protect_session(mvm, vif, dur, dur,
1203 iwl_mvm_sf_update(mvm, vif, false);
1204 iwl_mvm_power_vif_assoc(mvm, vif);
1206 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
1207 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1209 * If update fails - SF might be running in associated
1210 * mode while disassociated - which is forbidden.
1212 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1213 "Failed to update SF upon disassociation\n");
1215 /* remove AP station now that the MAC is unassoc */
1216 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1218 IWL_ERR(mvm, "failed to remove AP station\n");
1219 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1220 /* remove quota for this interface */
1221 ret = iwl_mvm_update_quotas(mvm, NULL);
1223 IWL_ERR(mvm, "failed to update quotas\n");
1226 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
1229 iwl_mvm_recalc_multicast(mvm);
1230 iwl_mvm_configure_bcast_filter(mvm, vif);
1232 /* reset rssi values */
1233 mvmvif->bf_data.ave_beacon_signal = 0;
1235 if (!(mvm->fw->ucode_capa.flags &
1236 IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT)) {
1237 /* Workaround for FW bug, otherwise FW disables device
1238 * power save upon disassociation
1240 ret = iwl_mvm_power_update_mode(mvm, vif);
1242 IWL_ERR(mvm, "failed to update power mode\n");
1244 iwl_mvm_bt_coex_vif_change(mvm);
1245 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1246 IEEE80211_SMPS_AUTOMATIC);
1247 } else if (changes & BSS_CHANGED_BEACON_INFO) {
1249 * We received a beacon _after_ association so
1250 * remove the session protection.
1252 iwl_mvm_remove_time_event(mvm, mvmvif,
1253 &mvmvif->time_event_data);
1254 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS |
1256 ret = iwl_mvm_power_update_mode(mvm, vif);
1258 IWL_ERR(mvm, "failed to update power mode\n");
1260 if (changes & BSS_CHANGED_TXPOWER) {
1261 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1263 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1266 if (changes & BSS_CHANGED_CQM) {
1267 IWL_DEBUG_MAC80211(mvm, "cqm info_changed");
1268 /* reset cqm events tracking */
1269 mvmvif->bf_data.last_cqm_event = 0;
1270 ret = iwl_mvm_update_beacon_filter(mvm, vif, false, CMD_SYNC);
1272 IWL_ERR(mvm, "failed to update CQM thresholds\n");
1275 if (changes & BSS_CHANGED_ARP_FILTER) {
1276 IWL_DEBUG_MAC80211(mvm, "arp filter changed");
1277 iwl_mvm_configure_bcast_filter(mvm, vif);
1281 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1282 struct ieee80211_vif *vif)
1284 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1285 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1288 mutex_lock(&mvm->mutex);
1290 /* Send the beacon template */
1291 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1296 * Re-calculate the tsf id, as the master-slave relations depend on the
1297 * beacon interval, which was not known when the AP interface was added.
1299 if (vif->type == NL80211_IFTYPE_AP)
1300 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1302 /* Add the mac context */
1303 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1307 /* Perform the binding */
1308 ret = iwl_mvm_binding_add_vif(mvm, vif);
1312 mvmvif->ap_ibss_active = true;
1314 /* Send the bcast station. At this stage the TBTT and DTIM time events
1315 * are added and applied to the scheduler */
1316 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
1320 /* must be set before quota calculations */
1321 mvmvif->ap_ibss_active = true;
1323 /* power updated needs to be done before quotas */
1324 mvm->bound_vif_cnt++;
1325 iwl_mvm_power_update_binding(mvm, vif, true);
1327 ret = iwl_mvm_update_quotas(mvm, vif);
1329 goto out_quota_failed;
1331 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1332 if (vif->p2p && mvm->p2p_device_vif)
1333 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1335 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1337 iwl_mvm_bt_coex_vif_change(mvm);
1339 mutex_unlock(&mvm->mutex);
1343 mvm->bound_vif_cnt--;
1344 iwl_mvm_power_update_binding(mvm, vif, false);
1345 mvmvif->ap_ibss_active = false;
1346 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1348 iwl_mvm_binding_remove_vif(mvm, vif);
1350 iwl_mvm_mac_ctxt_remove(mvm, vif);
1352 mutex_unlock(&mvm->mutex);
1356 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1357 struct ieee80211_vif *vif)
1359 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1360 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1362 iwl_mvm_prepare_mac_removal(mvm, vif);
1364 mutex_lock(&mvm->mutex);
1366 mvmvif->ap_ibss_active = false;
1368 iwl_mvm_bt_coex_vif_change(mvm);
1370 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
1372 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1373 if (vif->p2p && mvm->p2p_device_vif)
1374 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
1376 iwl_mvm_update_quotas(mvm, NULL);
1377 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1378 iwl_mvm_binding_remove_vif(mvm, vif);
1380 mvm->bound_vif_cnt--;
1381 iwl_mvm_power_update_binding(mvm, vif, false);
1383 iwl_mvm_mac_ctxt_remove(mvm, vif);
1385 mutex_unlock(&mvm->mutex);
1389 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1390 struct ieee80211_vif *vif,
1391 struct ieee80211_bss_conf *bss_conf,
1394 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1395 enum ieee80211_bss_change ht_change = BSS_CHANGED_ERP_CTS_PROT |
1397 BSS_CHANGED_BANDWIDTH;
1400 /* Changes will be applied when the AP/IBSS is started */
1401 if (!mvmvif->ap_ibss_active)
1404 if (changes & ht_change) {
1405 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1407 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1410 /* Need to send a new beacon template to the FW */
1411 if (changes & BSS_CHANGED_BEACON) {
1412 if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1413 IWL_WARN(mvm, "Failed updating beacon data\n");
1417 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1418 struct ieee80211_vif *vif,
1419 struct ieee80211_bss_conf *bss_conf,
1422 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1424 mutex_lock(&mvm->mutex);
1426 switch (vif->type) {
1427 case NL80211_IFTYPE_STATION:
1428 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1430 case NL80211_IFTYPE_AP:
1431 case NL80211_IFTYPE_ADHOC:
1432 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
1435 /* shouldn't happen */
1439 mutex_unlock(&mvm->mutex);
1442 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1443 struct ieee80211_vif *vif,
1444 struct cfg80211_scan_request *req)
1446 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1449 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
1452 mutex_lock(&mvm->mutex);
1454 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
1459 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1461 ret = iwl_mvm_scan_request(mvm, vif, req);
1463 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1465 mutex_unlock(&mvm->mutex);
1470 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1471 struct ieee80211_vif *vif)
1473 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1475 mutex_lock(&mvm->mutex);
1477 iwl_mvm_cancel_scan(mvm);
1479 mutex_unlock(&mvm->mutex);
1483 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
1484 struct ieee80211_sta *sta, u16 tids,
1486 enum ieee80211_frame_release_type reason,
1489 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1491 /* Called when we need to transmit (a) frame(s) from mac80211 */
1493 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1494 tids, more_data, false);
1498 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
1499 struct ieee80211_sta *sta, u16 tids,
1501 enum ieee80211_frame_release_type reason,
1504 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1506 /* Called when we need to transmit (a) frame(s) from agg queue */
1508 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1509 tids, more_data, true);
1512 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1513 struct ieee80211_vif *vif,
1514 enum sta_notify_cmd cmd,
1515 struct ieee80211_sta *sta)
1517 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1518 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1522 case STA_NOTIFY_SLEEP:
1523 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
1524 ieee80211_sta_block_awake(hw, sta, true);
1525 spin_lock_bh(&mvmsta->lock);
1526 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1527 struct iwl_mvm_tid_data *tid_data;
1529 tid_data = &mvmsta->tid_data[tid];
1530 if (tid_data->state != IWL_AGG_ON &&
1531 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
1533 if (iwl_mvm_tid_queued(tid_data) == 0)
1535 ieee80211_sta_set_buffered(sta, tid, true);
1537 spin_unlock_bh(&mvmsta->lock);
1539 * The fw updates the STA to be asleep. Tx packets on the Tx
1540 * queues to this station will not be transmitted. The fw will
1541 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1544 case STA_NOTIFY_AWAKE:
1545 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
1547 iwl_mvm_sta_modify_ps_wake(mvm, sta);
1554 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
1555 struct ieee80211_vif *vif,
1556 struct ieee80211_sta *sta)
1558 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1559 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1562 * This is called before mac80211 does RCU synchronisation,
1563 * so here we already invalidate our internal RCU-protected
1564 * station pointer. The rest of the code will thus no longer
1565 * be able to find the station this way, and we don't rely
1566 * on further RCU synchronisation after the sta_state()
1567 * callback deleted the station.
1569 mutex_lock(&mvm->mutex);
1570 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
1571 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1573 mutex_unlock(&mvm->mutex);
1576 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1577 struct ieee80211_vif *vif,
1578 struct ieee80211_sta *sta,
1579 enum ieee80211_sta_state old_state,
1580 enum ieee80211_sta_state new_state)
1582 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1583 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1586 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1587 sta->addr, old_state, new_state);
1589 /* this would be a mac80211 bug ... but don't crash */
1590 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1593 /* if a STA is being removed, reuse its ID */
1594 flush_work(&mvm->sta_drained_wk);
1596 mutex_lock(&mvm->mutex);
1597 if (old_state == IEEE80211_STA_NOTEXIST &&
1598 new_state == IEEE80211_STA_NONE) {
1600 * Firmware bug - it'll crash if the beacon interval is less
1601 * than 16. We can't avoid connecting at all, so refuse the
1602 * station state change, this will cause mac80211 to abandon
1603 * attempts to connect to this AP, and eventually wpa_s will
1604 * blacklist the AP...
1606 if (vif->type == NL80211_IFTYPE_STATION &&
1607 vif->bss_conf.beacon_int < 16) {
1609 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1610 sta->addr, vif->bss_conf.beacon_int);
1614 ret = iwl_mvm_add_sta(mvm, vif, sta);
1615 } else if (old_state == IEEE80211_STA_NONE &&
1616 new_state == IEEE80211_STA_AUTH) {
1618 } else if (old_state == IEEE80211_STA_AUTH &&
1619 new_state == IEEE80211_STA_ASSOC) {
1620 ret = iwl_mvm_update_sta(mvm, vif, sta);
1622 iwl_mvm_rs_rate_init(mvm, sta,
1623 mvmvif->phy_ctxt->channel->band,
1625 } else if (old_state == IEEE80211_STA_ASSOC &&
1626 new_state == IEEE80211_STA_AUTHORIZED) {
1627 /* enable beacon filtering */
1628 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, CMD_SYNC));
1630 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1631 new_state == IEEE80211_STA_ASSOC) {
1632 /* disable beacon filtering */
1633 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC));
1635 } else if (old_state == IEEE80211_STA_ASSOC &&
1636 new_state == IEEE80211_STA_AUTH) {
1638 } else if (old_state == IEEE80211_STA_AUTH &&
1639 new_state == IEEE80211_STA_NONE) {
1641 } else if (old_state == IEEE80211_STA_NONE &&
1642 new_state == IEEE80211_STA_NOTEXIST) {
1643 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1648 mutex_unlock(&mvm->mutex);
1653 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1655 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1657 mvm->rts_threshold = value;
1662 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
1663 struct ieee80211_vif *vif,
1664 struct ieee80211_sta *sta, u32 changed)
1666 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1668 if (vif->type == NL80211_IFTYPE_STATION &&
1669 changed & IEEE80211_RC_NSS_CHANGED)
1670 iwl_mvm_sf_update(mvm, vif, false);
1673 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1674 struct ieee80211_vif *vif, u16 ac,
1675 const struct ieee80211_tx_queue_params *params)
1677 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1678 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1680 mvmvif->queue_params[ac] = *params;
1683 * No need to update right away, we'll get BSS_CHANGED_QOS
1684 * The exception is P2P_DEVICE interface which needs immediate update.
1686 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1689 mutex_lock(&mvm->mutex);
1690 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1691 mutex_unlock(&mvm->mutex);
1697 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1698 struct ieee80211_vif *vif)
1700 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1701 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1702 200 + vif->bss_conf.beacon_int);
1703 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1704 100 + vif->bss_conf.beacon_int);
1706 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1709 mutex_lock(&mvm->mutex);
1710 /* Try really hard to protect the session and hear a beacon */
1711 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
1712 mutex_unlock(&mvm->mutex);
1715 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
1716 struct ieee80211_vif *vif,
1717 struct cfg80211_sched_scan_request *req,
1718 struct ieee80211_sched_scan_ies *ies)
1720 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1723 mutex_lock(&mvm->mutex);
1725 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
1727 "SCHED SCAN request during internal scan - abort\n");
1732 mvm->scan_status = IWL_MVM_SCAN_SCHED;
1734 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
1738 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1742 ret = iwl_mvm_sched_scan_start(mvm, req);
1746 mvm->scan_status = IWL_MVM_SCAN_NONE;
1748 mutex_unlock(&mvm->mutex);
1752 static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
1753 struct ieee80211_vif *vif)
1755 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1757 mutex_lock(&mvm->mutex);
1758 iwl_mvm_sched_scan_stop(mvm);
1759 mutex_unlock(&mvm->mutex);
1762 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1763 enum set_key_cmd cmd,
1764 struct ieee80211_vif *vif,
1765 struct ieee80211_sta *sta,
1766 struct ieee80211_key_conf *key)
1768 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1771 if (iwlwifi_mod_params.sw_crypto) {
1772 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1776 switch (key->cipher) {
1777 case WLAN_CIPHER_SUITE_TKIP:
1778 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1780 case WLAN_CIPHER_SUITE_CCMP:
1781 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1783 case WLAN_CIPHER_SUITE_AES_CMAC:
1784 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1786 case WLAN_CIPHER_SUITE_WEP40:
1787 case WLAN_CIPHER_SUITE_WEP104:
1789 * Support for TX only, at least for now, so accept
1790 * the key and do nothing else. Then mac80211 will
1791 * pass it for TX but we don't have to use it for RX.
1795 /* currently FW supports only one optional cipher scheme */
1796 if (hw->n_cipher_schemes &&
1797 hw->cipher_schemes->cipher == key->cipher)
1798 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
1803 mutex_lock(&mvm->mutex);
1807 if ((vif->type == NL80211_IFTYPE_ADHOC ||
1808 vif->type == NL80211_IFTYPE_AP) && !sta) {
1810 * GTK on AP interface is a TX-only key, return 0;
1811 * on IBSS they're per-station and because we're lazy
1812 * we don't support them for RX, so do the same.
1815 key->hw_key_idx = STA_KEY_IDX_INVALID;
1819 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1820 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1822 IWL_WARN(mvm, "set key failed\n");
1824 * can't add key for RX, but we don't need it
1825 * in the device for TX so still return 0
1827 key->hw_key_idx = STA_KEY_IDX_INVALID;
1833 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1838 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1839 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1845 mutex_unlock(&mvm->mutex);
1849 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1850 struct ieee80211_vif *vif,
1851 struct ieee80211_key_conf *keyconf,
1852 struct ieee80211_sta *sta,
1853 u32 iv32, u16 *phase1key)
1855 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1857 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
1860 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1864 static int iwl_mvm_roc(struct ieee80211_hw *hw,
1865 struct ieee80211_vif *vif,
1866 struct ieee80211_channel *channel,
1868 enum ieee80211_roc_type type)
1870 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1871 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1872 struct cfg80211_chan_def chandef;
1873 struct iwl_mvm_phy_ctxt *phy_ctxt;
1876 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1879 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1880 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1884 mutex_lock(&mvm->mutex);
1886 for (i = 0; i < NUM_PHY_CTX; i++) {
1887 phy_ctxt = &mvm->phy_ctxts[i];
1888 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1891 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1893 * Unbind the P2P_DEVICE from the current PHY context,
1894 * and if the PHY context is not used remove it.
1896 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1897 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1900 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1902 /* Bind the P2P_DEVICE to the current PHY Context */
1903 mvmvif->phy_ctxt = phy_ctxt;
1905 ret = iwl_mvm_binding_add_vif(mvm, vif);
1906 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1909 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1910 goto schedule_time_event;
1914 /* Need to update the PHY context only if the ROC channel changed */
1915 if (channel == mvmvif->phy_ctxt->channel)
1916 goto schedule_time_event;
1918 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
1921 * Change the PHY context configuration as it is currently referenced
1922 * only by the P2P Device MAC
1924 if (mvmvif->phy_ctxt->ref == 1) {
1925 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
1931 * The PHY context is shared with other MACs. Need to remove the
1932 * P2P Device from the binding, allocate an new PHY context and
1933 * create a new binding
1935 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1941 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
1944 IWL_ERR(mvm, "Failed to change PHY context\n");
1948 /* Unbind the P2P_DEVICE from the current PHY context */
1949 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1950 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1953 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1955 /* Bind the P2P_DEVICE to the new allocated PHY context */
1956 mvmvif->phy_ctxt = phy_ctxt;
1958 ret = iwl_mvm_binding_add_vif(mvm, vif);
1959 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1962 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1965 schedule_time_event:
1966 /* Schedule the time events */
1967 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
1970 mutex_unlock(&mvm->mutex);
1971 IWL_DEBUG_MAC80211(mvm, "leave\n");
1975 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1977 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1979 IWL_DEBUG_MAC80211(mvm, "enter\n");
1981 mutex_lock(&mvm->mutex);
1982 iwl_mvm_stop_p2p_roc(mvm);
1983 mutex_unlock(&mvm->mutex);
1985 IWL_DEBUG_MAC80211(mvm, "leave\n");
1989 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1990 struct ieee80211_chanctx_conf *ctx)
1992 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1993 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1994 struct iwl_mvm_phy_ctxt *phy_ctxt;
1997 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
1999 mutex_lock(&mvm->mutex);
2000 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2006 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
2007 ctx->rx_chains_static,
2008 ctx->rx_chains_dynamic);
2010 IWL_ERR(mvm, "Failed to add PHY context\n");
2014 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
2015 *phy_ctxt_id = phy_ctxt->id;
2017 mutex_unlock(&mvm->mutex);
2021 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2022 struct ieee80211_chanctx_conf *ctx)
2024 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2025 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2026 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2028 mutex_lock(&mvm->mutex);
2029 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
2030 mutex_unlock(&mvm->mutex);
2033 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2034 struct ieee80211_chanctx_conf *ctx,
2037 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2038 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2039 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2041 if (WARN_ONCE((phy_ctxt->ref > 1) &&
2042 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
2043 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
2044 IEEE80211_CHANCTX_CHANGE_RADAR |
2045 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
2046 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2047 phy_ctxt->ref, changed))
2050 mutex_lock(&mvm->mutex);
2051 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
2052 ctx->rx_chains_static,
2053 ctx->rx_chains_dynamic);
2054 iwl_mvm_bt_coex_vif_change(mvm);
2055 mutex_unlock(&mvm->mutex);
2058 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
2059 struct ieee80211_vif *vif,
2060 struct ieee80211_chanctx_conf *ctx)
2062 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2063 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2064 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2065 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2068 mutex_lock(&mvm->mutex);
2070 mvmvif->phy_ctxt = phy_ctxt;
2072 switch (vif->type) {
2073 case NL80211_IFTYPE_AP:
2074 case NL80211_IFTYPE_ADHOC:
2076 * The AP binding flow is handled as part of the start_ap flow
2077 * (in bss_info_changed), similarly for IBSS.
2081 case NL80211_IFTYPE_STATION:
2082 case NL80211_IFTYPE_MONITOR:
2089 ret = iwl_mvm_binding_add_vif(mvm, vif);
2094 * Power state must be updated before quotas,
2095 * otherwise fw will complain.
2097 mvm->bound_vif_cnt++;
2098 iwl_mvm_power_update_binding(mvm, vif, true);
2100 /* Setting the quota at this stage is only required for monitor
2101 * interfaces. For the other types, the bss_info changed flow
2102 * will handle quota settings.
2104 if (vif->type == NL80211_IFTYPE_MONITOR) {
2105 mvmvif->monitor_active = true;
2106 ret = iwl_mvm_update_quotas(mvm, vif);
2108 goto out_remove_binding;
2114 iwl_mvm_binding_remove_vif(mvm, vif);
2115 mvm->bound_vif_cnt--;
2116 iwl_mvm_power_update_binding(mvm, vif, false);
2118 mutex_unlock(&mvm->mutex);
2120 mvmvif->phy_ctxt = NULL;
2124 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
2125 struct ieee80211_vif *vif,
2126 struct ieee80211_chanctx_conf *ctx)
2128 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2129 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2131 mutex_lock(&mvm->mutex);
2133 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
2135 switch (vif->type) {
2136 case NL80211_IFTYPE_AP:
2137 case NL80211_IFTYPE_ADHOC:
2139 case NL80211_IFTYPE_MONITOR:
2140 mvmvif->monitor_active = false;
2141 iwl_mvm_update_quotas(mvm, NULL);
2147 iwl_mvm_binding_remove_vif(mvm, vif);
2148 mvm->bound_vif_cnt--;
2149 iwl_mvm_power_update_binding(mvm, vif, false);
2152 mvmvif->phy_ctxt = NULL;
2153 mutex_unlock(&mvm->mutex);
2156 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
2157 struct ieee80211_sta *sta,
2160 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2161 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
2163 if (!mvm_sta || !mvm_sta->vif) {
2164 IWL_ERR(mvm, "Station is not associated to a vif\n");
2168 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
2171 #ifdef CONFIG_NL80211_TESTMODE
2172 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
2173 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
2174 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
2175 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
2178 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
2179 struct ieee80211_vif *vif,
2180 void *data, int len)
2182 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
2186 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
2190 if (!tb[IWL_MVM_TM_ATTR_CMD])
2193 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
2194 case IWL_MVM_TM_CMD_SET_NOA:
2195 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
2196 !vif->bss_conf.enable_beacon ||
2197 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
2200 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
2201 if (noa_duration >= vif->bss_conf.beacon_int)
2204 mvm->noa_duration = noa_duration;
2207 return iwl_mvm_update_quotas(mvm, NULL);
2208 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
2209 /* must be associated client vif - ignore authorized */
2210 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
2211 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
2212 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
2215 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
2216 return iwl_mvm_enable_beacon_filter(mvm, vif,
2218 return iwl_mvm_disable_beacon_filter(mvm, vif, CMD_SYNC);
2224 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
2225 struct ieee80211_vif *vif,
2226 void *data, int len)
2228 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2231 mutex_lock(&mvm->mutex);
2232 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
2233 mutex_unlock(&mvm->mutex);
2239 struct ieee80211_ops iwl_mvm_hw_ops = {
2240 .tx = iwl_mvm_mac_tx,
2241 .ampdu_action = iwl_mvm_mac_ampdu_action,
2242 .start = iwl_mvm_mac_start,
2243 .restart_complete = iwl_mvm_mac_restart_complete,
2244 .stop = iwl_mvm_mac_stop,
2245 .add_interface = iwl_mvm_mac_add_interface,
2246 .remove_interface = iwl_mvm_mac_remove_interface,
2247 .config = iwl_mvm_mac_config,
2248 .prepare_multicast = iwl_mvm_prepare_multicast,
2249 .configure_filter = iwl_mvm_configure_filter,
2250 .bss_info_changed = iwl_mvm_bss_info_changed,
2251 .hw_scan = iwl_mvm_mac_hw_scan,
2252 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
2253 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
2254 .sta_state = iwl_mvm_mac_sta_state,
2255 .sta_notify = iwl_mvm_mac_sta_notify,
2256 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
2257 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
2258 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
2259 .sta_rc_update = iwl_mvm_sta_rc_update,
2260 .conf_tx = iwl_mvm_mac_conf_tx,
2261 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
2262 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
2263 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
2264 .set_key = iwl_mvm_mac_set_key,
2265 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
2266 .remain_on_channel = iwl_mvm_roc,
2267 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
2268 .add_chanctx = iwl_mvm_add_chanctx,
2269 .remove_chanctx = iwl_mvm_remove_chanctx,
2270 .change_chanctx = iwl_mvm_change_chanctx,
2271 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
2272 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
2274 .start_ap = iwl_mvm_start_ap_ibss,
2275 .stop_ap = iwl_mvm_stop_ap_ibss,
2276 .join_ibss = iwl_mvm_start_ap_ibss,
2277 .leave_ibss = iwl_mvm_stop_ap_ibss,
2279 .set_tim = iwl_mvm_set_tim,
2281 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
2283 #ifdef CONFIG_PM_SLEEP
2285 .suspend = iwl_mvm_suspend,
2286 .resume = iwl_mvm_resume,
2287 .set_wakeup = iwl_mvm_set_wakeup,
2288 .set_rekey_data = iwl_mvm_set_rekey_data,
2289 #if IS_ENABLED(CONFIG_IPV6)
2290 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
2292 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,