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 - 2013 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 - 2013 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 <net/mac80211.h>
72 #include "iwl-op-mode.h"
76 #include "time-event.h"
77 #include "iwl-eeprom-parse.h"
78 #include "fw-api-scan.h"
79 #include "iwl-phy-db.h"
81 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
84 .types = BIT(NL80211_IFTYPE_STATION),
88 .types = BIT(NL80211_IFTYPE_AP) |
89 BIT(NL80211_IFTYPE_P2P_CLIENT) |
90 BIT(NL80211_IFTYPE_P2P_GO),
94 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
98 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
100 .num_different_channels = 1,
102 .limits = iwl_mvm_limits,
103 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
107 #ifdef CONFIG_PM_SLEEP
108 static const struct nl80211_wowlan_tcp_data_token_feature
109 iwl_mvm_wowlan_tcp_token_feature = {
112 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
115 static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
116 .tok = &iwl_mvm_wowlan_tcp_token_feature,
117 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
118 sizeof(struct ethhdr) -
119 sizeof(struct iphdr) -
120 sizeof(struct tcphdr),
121 .data_interval_max = 65535, /* __le16 in API */
122 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
123 sizeof(struct ethhdr) -
124 sizeof(struct iphdr) -
125 sizeof(struct tcphdr),
130 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
134 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
135 for (i = 0; i < NUM_PHY_CTX; i++) {
136 mvm->phy_ctxts[i].id = i;
137 mvm->phy_ctxts[i].ref = 0;
141 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
143 struct ieee80211_hw *hw = mvm->hw;
146 /* Tell mac80211 our characteristics */
147 hw->flags = IEEE80211_HW_SIGNAL_DBM |
148 IEEE80211_HW_SPECTRUM_MGMT |
149 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
150 IEEE80211_HW_QUEUE_CONTROL |
151 IEEE80211_HW_WANT_MONITOR_VIF |
152 IEEE80211_HW_SUPPORTS_PS |
153 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
154 IEEE80211_HW_AMPDU_AGGREGATION |
155 IEEE80211_HW_TIMING_BEACON_ONLY |
156 IEEE80211_HW_CONNECTION_MONITOR |
157 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
158 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
159 IEEE80211_HW_SUPPORTS_UAPSD;
161 hw->queues = IWL_MVM_FIRST_AGG_QUEUE;
162 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
163 hw->rate_control_algorithm = "iwl-mvm-rs";
166 * Enable 11w if advertised by firmware and software crypto
167 * is not enabled (as the firmware will interpret some mgmt
168 * packets, so enabling it with software crypto isn't safe)
170 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
171 !iwlwifi_mod_params.sw_crypto)
172 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
174 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
175 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
176 hw->chanctx_data_size = sizeof(u16);
178 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
179 BIT(NL80211_IFTYPE_P2P_CLIENT) |
180 BIT(NL80211_IFTYPE_AP) |
181 BIT(NL80211_IFTYPE_P2P_GO) |
182 BIT(NL80211_IFTYPE_P2P_DEVICE);
184 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
185 WIPHY_FLAG_DISABLE_BEACON_HINTS |
188 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
189 hw->wiphy->n_iface_combinations =
190 ARRAY_SIZE(iwl_mvm_iface_combinations);
192 hw->wiphy->max_remain_on_channel_duration = 10000;
193 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
194 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
195 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
197 /* Extract MAC address */
198 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
199 hw->wiphy->addresses = mvm->addresses;
200 hw->wiphy->n_addresses = 1;
202 /* Extract additional MAC addresses if available */
203 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
204 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
206 for (i = 1; i < num_mac; i++) {
207 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
209 mvm->addresses[i].addr[5]++;
210 hw->wiphy->n_addresses++;
213 iwl_mvm_reset_phy_ctxts(mvm);
215 /* we create the 802.11 header and a max-length SSID element */
216 hw->wiphy->max_scan_ie_len =
217 mvm->fw->ucode_capa.max_probe_length - 24 - 34;
218 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
220 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
221 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
222 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
223 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
224 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
225 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
227 hw->wiphy->hw_version = mvm->trans->hw_id;
229 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
230 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
232 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
234 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
235 NL80211_FEATURE_P2P_GO_OPPPS;
237 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
239 #ifdef CONFIG_PM_SLEEP
240 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
241 mvm->trans->ops->d3_suspend &&
242 mvm->trans->ops->d3_resume &&
243 device_can_wakeup(mvm->trans->dev)) {
244 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
245 WIPHY_WOWLAN_DISCONNECT |
246 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
247 WIPHY_WOWLAN_RFKILL_RELEASE;
248 if (!iwlwifi_mod_params.sw_crypto)
249 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
250 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
251 WIPHY_WOWLAN_4WAY_HANDSHAKE;
253 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
254 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
255 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
256 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
257 hw->wiphy->wowlan = &mvm->wowlan;
261 ret = iwl_mvm_leds_init(mvm);
265 ret = ieee80211_register_hw(mvm->hw);
267 iwl_mvm_leds_exit(mvm);
272 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
273 struct ieee80211_tx_control *control,
276 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
278 if (iwl_mvm_is_radio_killed(mvm)) {
279 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
283 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
284 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
288 if (iwl_mvm_tx_skb(mvm, skb, control->sta))
293 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
297 ieee80211_free_txskb(hw, skb);
300 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
301 struct ieee80211_vif *vif,
302 enum ieee80211_ampdu_mlme_action action,
303 struct ieee80211_sta *sta, u16 tid,
304 u16 *ssn, u8 buf_size)
306 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
309 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
310 sta->addr, tid, action);
312 if (!(mvm->nvm_data->sku_cap_11n_enable))
315 mutex_lock(&mvm->mutex);
318 case IEEE80211_AMPDU_RX_START:
319 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
323 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
325 case IEEE80211_AMPDU_RX_STOP:
326 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
328 case IEEE80211_AMPDU_TX_START:
329 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
333 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
335 case IEEE80211_AMPDU_TX_STOP_CONT:
336 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
338 case IEEE80211_AMPDU_TX_STOP_FLUSH:
339 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
340 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
342 case IEEE80211_AMPDU_TX_OPERATIONAL:
343 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
350 mutex_unlock(&mvm->mutex);
355 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
356 struct ieee80211_vif *vif)
358 struct iwl_mvm *mvm = data;
359 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
361 mvmvif->uploaded = false;
362 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
364 /* does this make sense at all? */
367 spin_lock_bh(&mvm->time_event_lock);
368 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
369 spin_unlock_bh(&mvm->time_event_lock);
371 mvmvif->phy_ctxt = NULL;
374 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
376 iwl_trans_stop_device(mvm->trans);
377 iwl_trans_stop_hw(mvm->trans, false);
379 mvm->scan_status = IWL_MVM_SCAN_NONE;
381 /* just in case one was running */
382 ieee80211_remain_on_channel_expired(mvm->hw);
384 ieee80211_iterate_active_interfaces_atomic(
385 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
386 iwl_mvm_cleanup_iterator, mvm);
388 mvm->p2p_device_vif = NULL;
390 iwl_mvm_reset_phy_ctxts(mvm);
391 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
392 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
394 ieee80211_wake_queues(mvm->hw);
397 mvm->rx_ba_sessions = 0;
400 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
402 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
405 mutex_lock(&mvm->mutex);
407 /* Clean up some internal and mac80211 state on restart */
408 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
409 iwl_mvm_restart_cleanup(mvm);
411 ret = iwl_mvm_up(mvm);
412 mutex_unlock(&mvm->mutex);
417 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
419 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
422 mutex_lock(&mvm->mutex);
424 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
425 ret = iwl_mvm_update_quotas(mvm, NULL);
427 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
430 mutex_unlock(&mvm->mutex);
433 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
435 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
437 flush_work(&mvm->async_handlers_wk);
439 mutex_lock(&mvm->mutex);
440 /* async_handlers_wk is now blocked */
443 * The work item could be running or queued if the
444 * ROC time event stops just as we get here.
446 cancel_work_sync(&mvm->roc_done_wk);
448 iwl_trans_stop_device(mvm->trans);
449 iwl_trans_stop_hw(mvm->trans, false);
451 iwl_mvm_async_handlers_purge(mvm);
452 /* async_handlers_list is empty and will stay empty: HW is stopped */
454 /* the fw is stopped, the aux sta is dead: clean up driver state */
455 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
457 mutex_unlock(&mvm->mutex);
460 * The worker might have been waiting for the mutex, let it run and
461 * discover that its list is now empty.
463 cancel_work_sync(&mvm->async_handlers_wk);
466 static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac,
467 struct ieee80211_vif *vif)
469 struct iwl_mvm *mvm = data;
472 ret = iwl_mvm_power_disable(mvm, vif);
474 IWL_ERR(mvm, "failed to disable power management\n");
477 static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
478 struct ieee80211_vif *vif)
480 struct iwl_mvm *mvm = data;
482 iwl_mvm_power_update_mode(mvm, vif);
485 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
489 lockdep_assert_held(&mvm->mutex);
491 for (i = 0; i < NUM_PHY_CTX; i++)
492 if (!mvm->phy_ctxts[i].ref)
493 return &mvm->phy_ctxts[i];
495 IWL_ERR(mvm, "No available PHY context\n");
499 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
500 struct ieee80211_vif *vif)
502 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
503 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
507 * Not much to do here. The stack will not allow interface
508 * types or combinations that we didn't advertise, so we
509 * don't really have to check the types.
512 mutex_lock(&mvm->mutex);
514 /* Allocate resources for the MAC context, and add it to the fw */
515 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
520 * TODO: remove this temporary code.
521 * Currently MVM FW supports power management only on single MAC.
522 * If new interface added, disable PM on existing interface.
523 * P2P device is a special case, since it is handled by FW similary to
524 * scan. If P2P deviced is added, PM remains enabled on existing
526 * Note: the method below does not count the new interface being added
529 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
531 if (mvm->vif_count > 1) {
532 IWL_DEBUG_MAC80211(mvm,
533 "Disable power on existing interfaces\n");
534 ieee80211_iterate_active_interfaces_atomic(
536 IEEE80211_IFACE_ITER_NORMAL,
537 iwl_mvm_pm_disable_iterator, mvm);
541 * The AP binding flow can be done only after the beacon
542 * template is configured (which happens only in the mac80211
543 * start_ap() flow), and adding the broadcast station can happen
544 * only after the binding.
545 * In addition, since modifying the MAC before adding a bcast
546 * station is not allowed by the FW, delay the adding of MAC context to
547 * the point where we can also add the bcast station.
548 * In short: there's not much we can do at this point, other than
549 * allocating resources :)
551 if (vif->type == NL80211_IFTYPE_AP) {
552 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
553 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
556 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
560 iwl_mvm_vif_dbgfs_register(mvm, vif);
564 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
569 * Update power state on the new interface. Admittedly, based on
570 * mac80211 logics this power update will disable power management
572 iwl_mvm_power_update_mode(mvm, vif);
574 /* beacon filtering */
575 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
579 if (!mvm->bf_allowed_vif &&
580 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
581 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
582 mvm->bf_allowed_vif = mvmvif;
583 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
584 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
588 * P2P_DEVICE interface does not have a channel context assigned to it,
589 * so a dedicated PHY context is allocated to it and the corresponding
590 * MAC context is bound to it at this stage.
592 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
594 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
595 if (!mvmvif->phy_ctxt) {
600 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
601 ret = iwl_mvm_binding_add_vif(mvm, vif);
605 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
609 /* Save a pointer to p2p device vif, so it can later be used to
610 * update the p2p device MAC when a GO is started/stopped */
611 mvm->p2p_device_vif = vif;
614 iwl_mvm_vif_dbgfs_register(mvm, vif);
618 iwl_mvm_binding_remove_vif(mvm, vif);
620 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
622 if (mvm->bf_allowed_vif == mvmvif) {
623 mvm->bf_allowed_vif = NULL;
624 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
625 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
628 mvmvif->phy_ctxt = NULL;
629 iwl_mvm_mac_ctxt_remove(mvm, vif);
631 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
633 ieee80211_iterate_active_interfaces(
634 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
635 iwl_mvm_power_update_iterator, mvm);
636 iwl_mvm_mac_ctxt_release(mvm, vif);
638 mutex_unlock(&mvm->mutex);
643 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
644 struct ieee80211_vif *vif)
648 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
649 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
650 tfd_msk |= BIT(vif->hw_queue[ac]);
652 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
653 tfd_msk |= BIT(vif->cab_queue);
656 mutex_lock(&mvm->mutex);
657 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
658 mutex_unlock(&mvm->mutex);
661 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
663 * Flush the ROC worker which will flush the OFFCHANNEL queue.
664 * We assume here that all the packets sent to the OFFCHANNEL
665 * queue are sent in ROC session.
667 flush_work(&mvm->roc_done_wk);
670 * By now, all the AC queues are empty. The AGG queues are
671 * empty too. We already got all the Tx responses for all the
672 * packets in the queues. The drain work can have been
673 * triggered. Flush it.
675 flush_work(&mvm->sta_drained_wk);
679 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
680 struct ieee80211_vif *vif)
682 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
683 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
685 iwl_mvm_prepare_mac_removal(mvm, vif);
687 mutex_lock(&mvm->mutex);
689 if (mvm->bf_allowed_vif == mvmvif) {
690 mvm->bf_allowed_vif = NULL;
691 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
692 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
695 iwl_mvm_vif_dbgfs_clean(mvm, vif);
698 * For AP/GO interface, the tear down of the resources allocated to the
699 * interface is be handled as part of the stop_ap flow.
701 if (vif->type == NL80211_IFTYPE_AP) {
702 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
706 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
707 mvm->p2p_device_vif = NULL;
708 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
709 iwl_mvm_binding_remove_vif(mvm, vif);
710 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
711 mvmvif->phy_ctxt = NULL;
715 * TODO: remove this temporary code.
716 * Currently MVM FW supports power management only on single MAC.
717 * Check if only one additional interface remains after removing
718 * current one. Update power mode on the remaining interface.
720 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
722 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
724 if (mvm->vif_count == 1) {
725 ieee80211_iterate_active_interfaces(
726 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
727 iwl_mvm_power_update_iterator, mvm);
730 iwl_mvm_mac_ctxt_remove(mvm, vif);
733 iwl_mvm_mac_ctxt_release(mvm, vif);
734 mutex_unlock(&mvm->mutex);
737 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
740 /* FW is in charge of regulatory enforcement */
741 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
742 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
743 .pwr_restriction = cpu_to_le16(tx_power),
746 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
747 sizeof(reduce_txpwr_cmd),
751 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
756 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
757 unsigned int changed_flags,
758 unsigned int *total_flags,
764 static int iwl_mvm_configure_mcast_filter(struct iwl_mvm *mvm,
765 struct ieee80211_vif *vif)
767 struct iwl_mcast_filter_cmd mcast_filter_cmd = {
771 memcpy(mcast_filter_cmd.bssid, vif->bss_conf.bssid, ETH_ALEN);
773 return iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC,
774 sizeof(mcast_filter_cmd),
778 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
779 struct ieee80211_vif *vif,
780 struct ieee80211_bss_conf *bss_conf,
783 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
786 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
788 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
790 if (changes & BSS_CHANGED_ASSOC) {
791 if (bss_conf->assoc) {
792 /* add quota for this interface */
793 ret = iwl_mvm_update_quotas(mvm, vif);
795 IWL_ERR(mvm, "failed to update quotas\n");
798 iwl_mvm_configure_mcast_filter(mvm, vif);
799 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
800 /* remove AP station now that the MAC is unassoc */
801 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
803 IWL_ERR(mvm, "failed to remove AP station\n");
804 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
805 /* remove quota for this interface */
806 ret = iwl_mvm_update_quotas(mvm, NULL);
808 IWL_ERR(mvm, "failed to update quotas\n");
811 /* reset rssi values */
812 mvmvif->bf_data.ave_beacon_signal = 0;
814 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD)) {
815 /* Workaround for FW bug, otherwise FW disables device
816 * power save upon disassociation
818 ret = iwl_mvm_power_update_mode(mvm, vif);
820 IWL_ERR(mvm, "failed to update power mode\n");
822 iwl_mvm_bt_coex_vif_assoc(mvm, vif);
823 } else if (changes & BSS_CHANGED_BEACON_INFO) {
825 * We received a beacon _after_ association so
826 * remove the session protection.
828 iwl_mvm_remove_time_event(mvm, mvmvif,
829 &mvmvif->time_event_data);
830 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_QOS)) {
831 ret = iwl_mvm_power_update_mode(mvm, vif);
833 IWL_ERR(mvm, "failed to update power mode\n");
835 if (changes & BSS_CHANGED_TXPOWER) {
836 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
838 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
841 if (changes & BSS_CHANGED_CQM) {
842 IWL_DEBUG_MAC80211(mvm, "cqm info_changed");
843 /* reset cqm events tracking */
844 mvmvif->bf_data.last_cqm_event = 0;
845 ret = iwl_mvm_update_beacon_filter(mvm, vif);
847 IWL_ERR(mvm, "failed to update CQM thresholds\n");
851 static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
853 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
854 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
857 mutex_lock(&mvm->mutex);
859 /* Send the beacon template */
860 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
864 /* Add the mac context */
865 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
869 /* Perform the binding */
870 ret = iwl_mvm_binding_add_vif(mvm, vif);
874 mvmvif->ap_active = true;
876 /* Send the bcast station. At this stage the TBTT and DTIM time events
877 * are added and applied to the scheduler */
878 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
882 ret = iwl_mvm_update_quotas(mvm, vif);
886 /* Need to update the P2P Device MAC */
887 if (vif->p2p && mvm->p2p_device_vif)
888 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
890 mutex_unlock(&mvm->mutex);
894 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
896 iwl_mvm_binding_remove_vif(mvm, vif);
898 iwl_mvm_mac_ctxt_remove(mvm, vif);
900 mutex_unlock(&mvm->mutex);
904 static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
906 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
907 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
909 iwl_mvm_prepare_mac_removal(mvm, vif);
911 mutex_lock(&mvm->mutex);
913 mvmvif->ap_active = false;
915 /* Need to update the P2P Device MAC */
916 if (vif->p2p && mvm->p2p_device_vif)
917 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
919 iwl_mvm_update_quotas(mvm, NULL);
920 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
921 iwl_mvm_binding_remove_vif(mvm, vif);
922 iwl_mvm_mac_ctxt_remove(mvm, vif);
924 mutex_unlock(&mvm->mutex);
927 static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm,
928 struct ieee80211_vif *vif,
929 struct ieee80211_bss_conf *bss_conf,
932 /* Need to send a new beacon template to the FW */
933 if (changes & BSS_CHANGED_BEACON) {
934 if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
935 IWL_WARN(mvm, "Failed updating beacon data\n");
939 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
940 struct ieee80211_vif *vif,
941 struct ieee80211_bss_conf *bss_conf,
944 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
946 mutex_lock(&mvm->mutex);
949 case NL80211_IFTYPE_STATION:
950 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
952 case NL80211_IFTYPE_AP:
953 iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes);
956 /* shouldn't happen */
960 mutex_unlock(&mvm->mutex);
963 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
964 struct ieee80211_vif *vif,
965 struct cfg80211_scan_request *req)
967 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
970 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
973 mutex_lock(&mvm->mutex);
975 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
976 ret = iwl_mvm_scan_request(mvm, vif, req);
980 mutex_unlock(&mvm->mutex);
985 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
986 struct ieee80211_vif *vif)
988 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
990 mutex_lock(&mvm->mutex);
992 iwl_mvm_cancel_scan(mvm);
994 mutex_unlock(&mvm->mutex);
998 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
999 struct ieee80211_sta *sta, u16 tid,
1001 enum ieee80211_frame_release_type reason,
1004 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1006 /* TODO: how do we tell the fw to send frames for a specific TID */
1009 * The fw will send EOSP notification when the last frame will be
1012 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
1015 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1016 struct ieee80211_vif *vif,
1017 enum sta_notify_cmd cmd,
1018 struct ieee80211_sta *sta)
1020 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1021 struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
1024 case STA_NOTIFY_SLEEP:
1025 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
1026 ieee80211_sta_block_awake(hw, sta, true);
1028 * The fw updates the STA to be asleep. Tx packets on the Tx
1029 * queues to this station will not be transmitted. The fw will
1030 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1033 case STA_NOTIFY_AWAKE:
1034 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
1036 iwl_mvm_sta_modify_ps_wake(mvm, sta);
1043 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1044 struct ieee80211_vif *vif,
1045 struct ieee80211_sta *sta,
1046 enum ieee80211_sta_state old_state,
1047 enum ieee80211_sta_state new_state)
1049 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1050 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1053 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1054 sta->addr, old_state, new_state);
1056 /* this would be a mac80211 bug ... but don't crash */
1057 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1060 /* if a STA is being removed, reuse its ID */
1061 flush_work(&mvm->sta_drained_wk);
1063 mutex_lock(&mvm->mutex);
1064 if (old_state == IEEE80211_STA_NOTEXIST &&
1065 new_state == IEEE80211_STA_NONE) {
1067 * Firmware bug - it'll crash if the beacon interval is less
1068 * than 16. We can't avoid connecting at all, so refuse the
1069 * station state change, this will cause mac80211 to abandon
1070 * attempts to connect to this AP, and eventually wpa_s will
1071 * blacklist the AP...
1073 if (vif->type == NL80211_IFTYPE_STATION &&
1074 vif->bss_conf.beacon_int < 16) {
1076 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1077 sta->addr, vif->bss_conf.beacon_int);
1081 ret = iwl_mvm_add_sta(mvm, vif, sta);
1082 } else if (old_state == IEEE80211_STA_NONE &&
1083 new_state == IEEE80211_STA_AUTH) {
1085 } else if (old_state == IEEE80211_STA_AUTH &&
1086 new_state == IEEE80211_STA_ASSOC) {
1087 ret = iwl_mvm_update_sta(mvm, vif, sta);
1089 iwl_mvm_rs_rate_init(mvm, sta,
1090 mvmvif->phy_ctxt->channel->band);
1091 } else if (old_state == IEEE80211_STA_ASSOC &&
1092 new_state == IEEE80211_STA_AUTHORIZED) {
1093 /* enable beacon filtering */
1094 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
1096 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1097 new_state == IEEE80211_STA_ASSOC) {
1098 /* disable beacon filtering */
1099 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
1101 } else if (old_state == IEEE80211_STA_ASSOC &&
1102 new_state == IEEE80211_STA_AUTH) {
1104 } else if (old_state == IEEE80211_STA_AUTH &&
1105 new_state == IEEE80211_STA_NONE) {
1107 } else if (old_state == IEEE80211_STA_NONE &&
1108 new_state == IEEE80211_STA_NOTEXIST) {
1109 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1114 mutex_unlock(&mvm->mutex);
1119 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1121 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1123 mvm->rts_threshold = value;
1128 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1129 struct ieee80211_vif *vif, u16 ac,
1130 const struct ieee80211_tx_queue_params *params)
1132 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1133 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1135 mvmvif->queue_params[ac] = *params;
1138 * No need to update right away, we'll get BSS_CHANGED_QOS
1139 * The exception is P2P_DEVICE interface which needs immediate update.
1141 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1144 mutex_lock(&mvm->mutex);
1145 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1146 mutex_unlock(&mvm->mutex);
1152 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1153 struct ieee80211_vif *vif)
1155 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1156 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1157 200 + vif->bss_conf.beacon_int);
1158 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1159 100 + vif->bss_conf.beacon_int);
1161 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1164 mutex_lock(&mvm->mutex);
1165 /* Try really hard to protect the session and hear a beacon */
1166 iwl_mvm_protect_session(mvm, vif, duration, min_duration);
1167 mutex_unlock(&mvm->mutex);
1170 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1171 enum set_key_cmd cmd,
1172 struct ieee80211_vif *vif,
1173 struct ieee80211_sta *sta,
1174 struct ieee80211_key_conf *key)
1176 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1179 if (iwlwifi_mod_params.sw_crypto) {
1180 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1184 switch (key->cipher) {
1185 case WLAN_CIPHER_SUITE_TKIP:
1186 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1188 case WLAN_CIPHER_SUITE_CCMP:
1189 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1191 case WLAN_CIPHER_SUITE_AES_CMAC:
1192 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1194 case WLAN_CIPHER_SUITE_WEP40:
1195 case WLAN_CIPHER_SUITE_WEP104:
1197 * Support for TX only, at least for now, so accept
1198 * the key and do nothing else. Then mac80211 will
1199 * pass it for TX but we don't have to use it for RX.
1206 mutex_lock(&mvm->mutex);
1210 if (vif->type == NL80211_IFTYPE_AP && !sta) {
1211 /* GTK on AP interface is a TX-only key, return 0 */
1213 key->hw_key_idx = STA_KEY_IDX_INVALID;
1217 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1218 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1220 IWL_WARN(mvm, "set key failed\n");
1222 * can't add key for RX, but we don't need it
1223 * in the device for TX so still return 0
1225 key->hw_key_idx = STA_KEY_IDX_INVALID;
1231 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1236 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1237 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1243 mutex_unlock(&mvm->mutex);
1247 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1248 struct ieee80211_vif *vif,
1249 struct ieee80211_key_conf *keyconf,
1250 struct ieee80211_sta *sta,
1251 u32 iv32, u16 *phase1key)
1253 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1255 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1259 static int iwl_mvm_roc(struct ieee80211_hw *hw,
1260 struct ieee80211_vif *vif,
1261 struct ieee80211_channel *channel,
1263 enum ieee80211_roc_type type)
1265 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1266 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1267 struct cfg80211_chan_def chandef;
1268 struct iwl_mvm_phy_ctxt *phy_ctxt;
1271 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1274 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1275 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1279 mutex_lock(&mvm->mutex);
1281 for (i = 0; i < NUM_PHY_CTX; i++) {
1282 phy_ctxt = &mvm->phy_ctxts[i];
1283 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1286 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1288 * Unbind the P2P_DEVICE from the current PHY context,
1289 * and if the PHY context is not used remove it.
1291 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1292 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1295 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1297 /* Bind the P2P_DEVICE to the current PHY Context */
1298 mvmvif->phy_ctxt = phy_ctxt;
1300 ret = iwl_mvm_binding_add_vif(mvm, vif);
1301 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1304 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1305 goto schedule_time_event;
1309 /* Need to update the PHY context only if the ROC channel changed */
1310 if (channel == mvmvif->phy_ctxt->channel)
1311 goto schedule_time_event;
1313 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
1316 * Change the PHY context configuration as it is currently referenced
1317 * only by the P2P Device MAC
1319 if (mvmvif->phy_ctxt->ref == 1) {
1320 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
1326 * The PHY context is shared with other MACs. Need to remove the
1327 * P2P Device from the binding, allocate an new PHY context and
1328 * create a new binding
1330 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1336 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
1339 IWL_ERR(mvm, "Failed to change PHY context\n");
1343 /* Unbind the P2P_DEVICE from the current PHY context */
1344 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1345 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1348 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1350 /* Bind the P2P_DEVICE to the new allocated PHY context */
1351 mvmvif->phy_ctxt = phy_ctxt;
1353 ret = iwl_mvm_binding_add_vif(mvm, vif);
1354 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1357 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1360 schedule_time_event:
1361 /* Schedule the time events */
1362 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
1365 mutex_unlock(&mvm->mutex);
1366 IWL_DEBUG_MAC80211(mvm, "leave\n");
1370 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1372 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1374 IWL_DEBUG_MAC80211(mvm, "enter\n");
1376 mutex_lock(&mvm->mutex);
1377 iwl_mvm_stop_p2p_roc(mvm);
1378 mutex_unlock(&mvm->mutex);
1380 IWL_DEBUG_MAC80211(mvm, "leave\n");
1384 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1385 struct ieee80211_chanctx_conf *ctx)
1387 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1388 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1389 struct iwl_mvm_phy_ctxt *phy_ctxt;
1392 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
1394 mutex_lock(&mvm->mutex);
1395 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1401 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1402 ctx->rx_chains_static,
1403 ctx->rx_chains_dynamic);
1405 IWL_ERR(mvm, "Failed to add PHY context\n");
1409 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
1410 *phy_ctxt_id = phy_ctxt->id;
1412 mutex_unlock(&mvm->mutex);
1416 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
1417 struct ieee80211_chanctx_conf *ctx)
1419 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1420 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1421 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
1423 mutex_lock(&mvm->mutex);
1424 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
1425 mutex_unlock(&mvm->mutex);
1428 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
1429 struct ieee80211_chanctx_conf *ctx,
1432 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1433 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1434 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
1436 if (WARN_ONCE((phy_ctxt->ref > 1) &&
1437 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
1438 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
1439 IEEE80211_CHANCTX_CHANGE_RADAR)),
1440 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1441 phy_ctxt->ref, changed))
1444 mutex_lock(&mvm->mutex);
1445 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1446 ctx->rx_chains_static,
1447 ctx->rx_chains_dynamic);
1448 mutex_unlock(&mvm->mutex);
1451 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
1452 struct ieee80211_vif *vif,
1453 struct ieee80211_chanctx_conf *ctx)
1455 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1456 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1457 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
1458 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1461 mutex_lock(&mvm->mutex);
1463 mvmvif->phy_ctxt = phy_ctxt;
1465 switch (vif->type) {
1466 case NL80211_IFTYPE_AP:
1468 * The AP binding flow is handled as part of the start_ap flow
1469 * (in bss_info_changed).
1473 case NL80211_IFTYPE_STATION:
1474 case NL80211_IFTYPE_ADHOC:
1475 case NL80211_IFTYPE_MONITOR:
1482 ret = iwl_mvm_binding_add_vif(mvm, vif);
1487 * Setting the quota at this stage is only required for monitor
1488 * interfaces. For the other types, the bss_info changed flow
1489 * will handle quota settings.
1491 if (vif->type == NL80211_IFTYPE_MONITOR) {
1492 mvmvif->monitor_active = true;
1493 ret = iwl_mvm_update_quotas(mvm, vif);
1495 goto out_remove_binding;
1501 iwl_mvm_binding_remove_vif(mvm, vif);
1503 mutex_unlock(&mvm->mutex);
1505 mvmvif->phy_ctxt = NULL;
1509 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
1510 struct ieee80211_vif *vif,
1511 struct ieee80211_chanctx_conf *ctx)
1513 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1514 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1516 mutex_lock(&mvm->mutex);
1518 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
1520 if (vif->type == NL80211_IFTYPE_AP)
1523 switch (vif->type) {
1524 case NL80211_IFTYPE_MONITOR:
1525 mvmvif->monitor_active = false;
1526 iwl_mvm_update_quotas(mvm, NULL);
1532 iwl_mvm_binding_remove_vif(mvm, vif);
1534 mvmvif->phy_ctxt = NULL;
1535 mutex_unlock(&mvm->mutex);
1538 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
1539 struct ieee80211_sta *sta,
1542 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1543 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1545 if (!mvm_sta || !mvm_sta->vif) {
1546 IWL_ERR(mvm, "Station is not associated to a vif\n");
1550 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
1553 static void iwl_mvm_mac_rssi_callback(struct ieee80211_hw *hw,
1554 struct ieee80211_vif *vif,
1555 enum ieee80211_rssi_event rssi_event)
1557 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1559 iwl_mvm_bt_rssi_event(mvm, vif, rssi_event);
1562 struct ieee80211_ops iwl_mvm_hw_ops = {
1563 .tx = iwl_mvm_mac_tx,
1564 .ampdu_action = iwl_mvm_mac_ampdu_action,
1565 .start = iwl_mvm_mac_start,
1566 .restart_complete = iwl_mvm_mac_restart_complete,
1567 .stop = iwl_mvm_mac_stop,
1568 .add_interface = iwl_mvm_mac_add_interface,
1569 .remove_interface = iwl_mvm_mac_remove_interface,
1570 .config = iwl_mvm_mac_config,
1571 .configure_filter = iwl_mvm_configure_filter,
1572 .bss_info_changed = iwl_mvm_bss_info_changed,
1573 .hw_scan = iwl_mvm_mac_hw_scan,
1574 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1575 .sta_state = iwl_mvm_mac_sta_state,
1576 .sta_notify = iwl_mvm_mac_sta_notify,
1577 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
1578 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1579 .conf_tx = iwl_mvm_mac_conf_tx,
1580 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
1581 .set_key = iwl_mvm_mac_set_key,
1582 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
1583 .remain_on_channel = iwl_mvm_roc,
1584 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
1585 .rssi_callback = iwl_mvm_mac_rssi_callback,
1587 .add_chanctx = iwl_mvm_add_chanctx,
1588 .remove_chanctx = iwl_mvm_remove_chanctx,
1589 .change_chanctx = iwl_mvm_change_chanctx,
1590 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
1591 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
1593 .start_ap = iwl_mvm_start_ap,
1594 .stop_ap = iwl_mvm_stop_ap,
1596 .set_tim = iwl_mvm_set_tim,
1598 #ifdef CONFIG_PM_SLEEP
1600 .suspend = iwl_mvm_suspend,
1601 .resume = iwl_mvm_resume,
1602 .set_wakeup = iwl_mvm_set_wakeup,
1603 .set_rekey_data = iwl_mvm_set_rekey_data,
1604 #if IS_ENABLED(CONFIG_IPV6)
1605 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
1607 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,