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;
158 hw->queues = IWL_MVM_FIRST_AGG_QUEUE;
159 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
160 hw->rate_control_algorithm = "iwl-mvm-rs";
163 * Enable 11w if advertised by firmware and software crypto
164 * is not enabled (as the firmware will interpret some mgmt
165 * packets, so enabling it with software crypto isn't safe)
167 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
168 !iwlwifi_mod_params.sw_crypto)
169 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
171 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
172 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
173 hw->chanctx_data_size = sizeof(u16);
175 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
176 BIT(NL80211_IFTYPE_P2P_CLIENT) |
177 BIT(NL80211_IFTYPE_AP) |
178 BIT(NL80211_IFTYPE_P2P_GO) |
179 BIT(NL80211_IFTYPE_P2P_DEVICE);
181 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
182 WIPHY_FLAG_DISABLE_BEACON_HINTS |
185 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
186 hw->wiphy->n_iface_combinations =
187 ARRAY_SIZE(iwl_mvm_iface_combinations);
189 hw->wiphy->max_remain_on_channel_duration = 10000;
190 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
192 /* Extract MAC address */
193 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
194 hw->wiphy->addresses = mvm->addresses;
195 hw->wiphy->n_addresses = 1;
197 /* Extract additional MAC addresses if available */
198 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
199 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
201 for (i = 1; i < num_mac; i++) {
202 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
204 mvm->addresses[i].addr[5]++;
205 hw->wiphy->n_addresses++;
208 iwl_mvm_reset_phy_ctxts(mvm);
210 /* we create the 802.11 header and a max-length SSID element */
211 hw->wiphy->max_scan_ie_len =
212 mvm->fw->ucode_capa.max_probe_length - 24 - 34;
213 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
215 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
216 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
217 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
218 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
219 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
220 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
222 hw->wiphy->hw_version = mvm->trans->hw_id;
224 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
225 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
227 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
229 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
230 NL80211_FEATURE_P2P_GO_OPPPS;
232 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
234 #ifdef CONFIG_PM_SLEEP
235 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
236 mvm->trans->ops->d3_suspend &&
237 mvm->trans->ops->d3_resume &&
238 device_can_wakeup(mvm->trans->dev)) {
239 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
240 WIPHY_WOWLAN_DISCONNECT |
241 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
242 WIPHY_WOWLAN_RFKILL_RELEASE;
243 if (!iwlwifi_mod_params.sw_crypto)
244 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
245 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
246 WIPHY_WOWLAN_4WAY_HANDSHAKE;
248 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
249 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
250 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
251 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
252 hw->wiphy->wowlan = &mvm->wowlan;
256 ret = iwl_mvm_leds_init(mvm);
260 return ieee80211_register_hw(mvm->hw);
263 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
264 struct ieee80211_tx_control *control,
267 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
269 if (iwl_mvm_is_radio_killed(mvm)) {
270 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
274 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
275 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
279 if (iwl_mvm_tx_skb(mvm, skb, control->sta))
284 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
288 ieee80211_free_txskb(hw, skb);
291 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
292 struct ieee80211_vif *vif,
293 enum ieee80211_ampdu_mlme_action action,
294 struct ieee80211_sta *sta, u16 tid,
295 u16 *ssn, u8 buf_size)
297 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
300 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
301 sta->addr, tid, action);
303 if (!(mvm->nvm_data->sku_cap_11n_enable))
306 mutex_lock(&mvm->mutex);
309 case IEEE80211_AMPDU_RX_START:
310 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
314 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
316 case IEEE80211_AMPDU_RX_STOP:
317 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
319 case IEEE80211_AMPDU_TX_START:
320 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
324 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
326 case IEEE80211_AMPDU_TX_STOP_CONT:
327 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
329 case IEEE80211_AMPDU_TX_STOP_FLUSH:
330 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
331 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
333 case IEEE80211_AMPDU_TX_OPERATIONAL:
334 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
341 mutex_unlock(&mvm->mutex);
346 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
347 struct ieee80211_vif *vif)
349 struct iwl_mvm *mvm = data;
350 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
352 mvmvif->uploaded = false;
353 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
355 /* does this make sense at all? */
358 spin_lock_bh(&mvm->time_event_lock);
359 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
360 spin_unlock_bh(&mvm->time_event_lock);
362 mvmvif->phy_ctxt = NULL;
365 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
367 iwl_trans_stop_device(mvm->trans);
368 iwl_trans_stop_hw(mvm->trans, false);
370 mvm->scan_status = IWL_MVM_SCAN_NONE;
372 /* just in case one was running */
373 ieee80211_remain_on_channel_expired(mvm->hw);
375 ieee80211_iterate_active_interfaces_atomic(
376 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
377 iwl_mvm_cleanup_iterator, mvm);
379 mvm->p2p_device_vif = NULL;
381 iwl_mvm_reset_phy_ctxts(mvm);
382 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
383 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
385 ieee80211_wake_queues(mvm->hw);
390 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
392 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
395 mutex_lock(&mvm->mutex);
397 /* Clean up some internal and mac80211 state on restart */
398 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
399 iwl_mvm_restart_cleanup(mvm);
401 ret = iwl_mvm_up(mvm);
402 mutex_unlock(&mvm->mutex);
407 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
409 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
412 mutex_lock(&mvm->mutex);
414 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
415 ret = iwl_mvm_update_quotas(mvm, NULL);
417 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
420 mutex_unlock(&mvm->mutex);
423 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
425 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
427 flush_work(&mvm->async_handlers_wk);
429 mutex_lock(&mvm->mutex);
430 /* async_handlers_wk is now blocked */
433 * The work item could be running or queued if the
434 * ROC time event stops just as we get here.
436 cancel_work_sync(&mvm->roc_done_wk);
438 iwl_trans_stop_device(mvm->trans);
439 iwl_trans_stop_hw(mvm->trans, false);
441 iwl_mvm_async_handlers_purge(mvm);
442 /* async_handlers_list is empty and will stay empty: HW is stopped */
444 /* the fw is stopped, the aux sta is dead: clean up driver state */
445 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
447 mutex_unlock(&mvm->mutex);
450 * The worker might have been waiting for the mutex, let it run and
451 * discover that its list is now empty.
453 cancel_work_sync(&mvm->async_handlers_wk);
456 static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac,
457 struct ieee80211_vif *vif)
459 struct iwl_mvm *mvm = data;
462 ret = iwl_mvm_power_disable(mvm, vif);
464 IWL_ERR(mvm, "failed to disable power management\n");
467 static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
468 struct ieee80211_vif *vif)
470 struct iwl_mvm *mvm = data;
472 iwl_mvm_power_update_mode(mvm, vif);
475 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
479 lockdep_assert_held(&mvm->mutex);
481 for (i = 0; i < NUM_PHY_CTX; i++)
482 if (!mvm->phy_ctxts[i].ref)
483 return &mvm->phy_ctxts[i];
485 IWL_ERR(mvm, "No available PHY context\n");
489 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
490 struct ieee80211_vif *vif)
492 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
493 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
497 * Not much to do here. The stack will not allow interface
498 * types or combinations that we didn't advertise, so we
499 * don't really have to check the types.
502 mutex_lock(&mvm->mutex);
504 /* Allocate resources for the MAC context, and add it the the fw */
505 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
510 * The AP binding flow can be done only after the beacon
511 * template is configured (which happens only in the mac80211
512 * start_ap() flow), and adding the broadcast station can happen
513 * only after the binding.
514 * In addition, since modifying the MAC before adding a bcast
515 * station is not allowed by the FW, delay the adding of MAC context to
516 * the point where we can also add the bcast station.
517 * In short: there's not much we can do at this point, other than
518 * allocating resources :)
520 if (vif->type == NL80211_IFTYPE_AP) {
521 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
522 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
525 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
533 * TODO: remove this temporary code.
534 * Currently MVM FW supports power management only on single MAC.
535 * If new interface added, disable PM on existing interface.
536 * P2P device is a special case, since it is handled by FW similary to
537 * scan. If P2P deviced is added, PM remains enabled on existing
539 * Note: the method below does not count the new interface being added
542 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
544 if (mvm->vif_count > 1) {
545 IWL_DEBUG_MAC80211(mvm,
546 "Disable power on existing interfaces\n");
547 ieee80211_iterate_active_interfaces_atomic(
549 IEEE80211_IFACE_ITER_NORMAL,
550 iwl_mvm_pm_disable_iterator, mvm);
553 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
558 * Update power state on the new interface. Admittedly, based on
559 * mac80211 logics this power update will disable power management
561 iwl_mvm_power_update_mode(mvm, vif);
563 /* beacon filtering */
564 if (!mvm->bf_allowed_vif &&
565 vif->type == NL80211_IFTYPE_STATION && !vif->p2p){
566 mvm->bf_allowed_vif = mvmvif;
567 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
570 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
575 * P2P_DEVICE interface does not have a channel context assigned to it,
576 * so a dedicated PHY context is allocated to it and the corresponding
577 * MAC context is bound to it at this stage.
579 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
581 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
582 if (!mvmvif->phy_ctxt) {
587 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
588 ret = iwl_mvm_binding_add_vif(mvm, vif);
592 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
596 /* Save a pointer to p2p device vif, so it can later be used to
597 * update the p2p device MAC when a GO is started/stopped */
598 mvm->p2p_device_vif = vif;
601 iwl_mvm_vif_dbgfs_register(mvm, vif);
605 iwl_mvm_binding_remove_vif(mvm, vif);
607 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
609 mvmvif->phy_ctxt = NULL;
610 iwl_mvm_mac_ctxt_remove(mvm, vif);
612 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
614 ieee80211_iterate_active_interfaces(
615 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
616 iwl_mvm_power_update_iterator, mvm);
617 iwl_mvm_mac_ctxt_release(mvm, vif);
619 mutex_unlock(&mvm->mutex);
624 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
625 struct ieee80211_vif *vif)
629 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
630 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
631 tfd_msk |= BIT(vif->hw_queue[ac]);
633 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
634 tfd_msk |= BIT(vif->cab_queue);
637 mutex_lock(&mvm->mutex);
638 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
639 mutex_unlock(&mvm->mutex);
642 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
644 * Flush the ROC worker which will flush the OFFCHANNEL queue.
645 * We assume here that all the packets sent to the OFFCHANNEL
646 * queue are sent in ROC session.
648 flush_work(&mvm->roc_done_wk);
651 * By now, all the AC queues are empty. The AGG queues are
652 * empty too. We already got all the Tx responses for all the
653 * packets in the queues. The drain work can have been
654 * triggered. Flush it.
656 flush_work(&mvm->sta_drained_wk);
660 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
661 struct ieee80211_vif *vif)
663 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
664 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
666 iwl_mvm_prepare_mac_removal(mvm, vif);
668 mutex_lock(&mvm->mutex);
670 if (mvm->bf_allowed_vif == mvmvif) {
671 mvm->bf_allowed_vif = NULL;
672 vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
675 iwl_mvm_vif_dbgfs_clean(mvm, vif);
678 * For AP/GO interface, the tear down of the resources allocated to the
679 * interface is be handled as part of the stop_ap flow.
681 if (vif->type == NL80211_IFTYPE_AP) {
682 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
686 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
687 mvm->p2p_device_vif = NULL;
688 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
689 iwl_mvm_binding_remove_vif(mvm, vif);
690 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
691 mvmvif->phy_ctxt = NULL;
695 * TODO: remove this temporary code.
696 * Currently MVM FW supports power management only on single MAC.
697 * Check if only one additional interface remains after removing
698 * current one. Update power mode on the remaining interface.
700 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
702 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
704 if (mvm->vif_count == 1) {
705 ieee80211_iterate_active_interfaces(
706 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
707 iwl_mvm_power_update_iterator, mvm);
710 iwl_mvm_mac_ctxt_remove(mvm, vif);
713 iwl_mvm_mac_ctxt_release(mvm, vif);
714 mutex_unlock(&mvm->mutex);
717 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
722 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
723 unsigned int changed_flags,
724 unsigned int *total_flags,
730 static int iwl_mvm_configure_mcast_filter(struct iwl_mvm *mvm,
731 struct ieee80211_vif *vif)
733 struct iwl_mcast_filter_cmd mcast_filter_cmd = {
737 memcpy(mcast_filter_cmd.bssid, vif->bss_conf.bssid, ETH_ALEN);
739 return iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC,
740 sizeof(mcast_filter_cmd),
744 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
745 struct ieee80211_vif *vif,
746 struct ieee80211_bss_conf *bss_conf,
749 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
752 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
754 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
756 if (changes & BSS_CHANGED_ASSOC) {
757 if (bss_conf->assoc) {
758 /* add quota for this interface */
759 ret = iwl_mvm_update_quotas(mvm, vif);
761 IWL_ERR(mvm, "failed to update quotas\n");
764 iwl_mvm_bt_coex_vif_assoc(mvm, vif);
765 iwl_mvm_configure_mcast_filter(mvm, vif);
766 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
767 /* remove AP station now that the MAC is unassoc */
768 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
770 IWL_ERR(mvm, "failed to remove AP station\n");
771 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
772 /* remove quota for this interface */
773 ret = iwl_mvm_update_quotas(mvm, NULL);
775 IWL_ERR(mvm, "failed to update quotas\n");
777 ret = iwl_mvm_power_update_mode(mvm, vif);
779 IWL_ERR(mvm, "failed to update power mode\n");
780 } else if (changes & BSS_CHANGED_BEACON_INFO) {
782 * We received a beacon _after_ association so
783 * remove the session protection.
785 iwl_mvm_remove_time_event(mvm, mvmvif,
786 &mvmvif->time_event_data);
787 } else if (changes & BSS_CHANGED_PS) {
788 ret = iwl_mvm_power_update_mode(mvm, vif);
790 IWL_ERR(mvm, "failed to update power mode\n");
794 static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
796 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
797 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
800 mutex_lock(&mvm->mutex);
802 /* Send the beacon template */
803 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
807 /* Add the mac context */
808 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
812 /* Perform the binding */
813 ret = iwl_mvm_binding_add_vif(mvm, vif);
817 mvmvif->ap_active = true;
819 /* Send the bcast station. At this stage the TBTT and DTIM time events
820 * are added and applied to the scheduler */
821 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
825 ret = iwl_mvm_update_quotas(mvm, vif);
829 /* Need to update the P2P Device MAC */
830 if (vif->p2p && mvm->p2p_device_vif)
831 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
833 mutex_unlock(&mvm->mutex);
837 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
839 iwl_mvm_binding_remove_vif(mvm, vif);
841 iwl_mvm_mac_ctxt_remove(mvm, vif);
843 mutex_unlock(&mvm->mutex);
847 static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
849 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
850 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
852 iwl_mvm_prepare_mac_removal(mvm, vif);
854 mutex_lock(&mvm->mutex);
856 mvmvif->ap_active = false;
858 /* Need to update the P2P Device MAC */
859 if (vif->p2p && mvm->p2p_device_vif)
860 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
862 iwl_mvm_update_quotas(mvm, NULL);
863 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
864 iwl_mvm_binding_remove_vif(mvm, vif);
865 iwl_mvm_mac_ctxt_remove(mvm, vif);
867 mutex_unlock(&mvm->mutex);
870 static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm,
871 struct ieee80211_vif *vif,
872 struct ieee80211_bss_conf *bss_conf,
875 /* Need to send a new beacon template to the FW */
876 if (changes & BSS_CHANGED_BEACON) {
877 if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
878 IWL_WARN(mvm, "Failed updating beacon data\n");
882 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
883 struct ieee80211_vif *vif,
884 struct ieee80211_bss_conf *bss_conf,
887 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
889 mutex_lock(&mvm->mutex);
892 case NL80211_IFTYPE_STATION:
893 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
895 case NL80211_IFTYPE_AP:
896 iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes);
899 /* shouldn't happen */
903 mutex_unlock(&mvm->mutex);
906 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
907 struct ieee80211_vif *vif,
908 struct cfg80211_scan_request *req)
910 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
913 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
916 mutex_lock(&mvm->mutex);
918 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
919 ret = iwl_mvm_scan_request(mvm, vif, req);
923 mutex_unlock(&mvm->mutex);
928 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
929 struct ieee80211_vif *vif)
931 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
933 mutex_lock(&mvm->mutex);
935 iwl_mvm_cancel_scan(mvm);
937 mutex_unlock(&mvm->mutex);
941 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
942 struct ieee80211_sta *sta, u16 tid,
944 enum ieee80211_frame_release_type reason,
947 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
949 /* TODO: how do we tell the fw to send frames for a specific TID */
952 * The fw will send EOSP notification when the last frame will be
955 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
958 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
959 struct ieee80211_vif *vif,
960 enum sta_notify_cmd cmd,
961 struct ieee80211_sta *sta)
963 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
964 struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
967 case STA_NOTIFY_SLEEP:
968 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
969 ieee80211_sta_block_awake(hw, sta, true);
971 * The fw updates the STA to be asleep. Tx packets on the Tx
972 * queues to this station will not be transmitted. The fw will
973 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
976 case STA_NOTIFY_AWAKE:
977 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
979 iwl_mvm_sta_modify_ps_wake(mvm, sta);
986 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
987 struct ieee80211_vif *vif,
988 struct ieee80211_sta *sta,
989 enum ieee80211_sta_state old_state,
990 enum ieee80211_sta_state new_state)
992 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
993 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
996 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
997 sta->addr, old_state, new_state);
999 /* this would be a mac80211 bug ... but don't crash */
1000 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1003 /* if a STA is being removed, reuse its ID */
1004 flush_work(&mvm->sta_drained_wk);
1006 mutex_lock(&mvm->mutex);
1007 if (old_state == IEEE80211_STA_NOTEXIST &&
1008 new_state == IEEE80211_STA_NONE) {
1009 ret = iwl_mvm_add_sta(mvm, vif, sta);
1010 } else if (old_state == IEEE80211_STA_NONE &&
1011 new_state == IEEE80211_STA_AUTH) {
1013 } else if (old_state == IEEE80211_STA_AUTH &&
1014 new_state == IEEE80211_STA_ASSOC) {
1015 ret = iwl_mvm_update_sta(mvm, vif, sta);
1017 iwl_mvm_rs_rate_init(mvm, sta,
1018 mvmvif->phy_ctxt->channel->band);
1019 } else if (old_state == IEEE80211_STA_ASSOC &&
1020 new_state == IEEE80211_STA_AUTHORIZED) {
1021 /* enable beacon filtering */
1022 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
1024 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1025 new_state == IEEE80211_STA_ASSOC) {
1026 /* disable beacon filtering */
1027 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
1029 } else if (old_state == IEEE80211_STA_ASSOC &&
1030 new_state == IEEE80211_STA_AUTH) {
1032 } else if (old_state == IEEE80211_STA_AUTH &&
1033 new_state == IEEE80211_STA_NONE) {
1035 } else if (old_state == IEEE80211_STA_NONE &&
1036 new_state == IEEE80211_STA_NOTEXIST) {
1037 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1041 mutex_unlock(&mvm->mutex);
1046 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1048 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1050 mvm->rts_threshold = value;
1055 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1056 struct ieee80211_vif *vif, u16 ac,
1057 const struct ieee80211_tx_queue_params *params)
1059 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1060 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1062 mvmvif->queue_params[ac] = *params;
1065 * No need to update right away, we'll get BSS_CHANGED_QOS
1066 * The exception is P2P_DEVICE interface which needs immediate update.
1068 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1071 mutex_lock(&mvm->mutex);
1072 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1073 mutex_unlock(&mvm->mutex);
1079 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1080 struct ieee80211_vif *vif)
1082 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1083 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1084 200 + vif->bss_conf.beacon_int);
1085 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1086 100 + vif->bss_conf.beacon_int);
1088 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1091 mutex_lock(&mvm->mutex);
1092 /* Try really hard to protect the session and hear a beacon */
1093 iwl_mvm_protect_session(mvm, vif, duration, min_duration);
1094 mutex_unlock(&mvm->mutex);
1097 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1098 enum set_key_cmd cmd,
1099 struct ieee80211_vif *vif,
1100 struct ieee80211_sta *sta,
1101 struct ieee80211_key_conf *key)
1103 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1106 if (iwlwifi_mod_params.sw_crypto) {
1107 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1111 switch (key->cipher) {
1112 case WLAN_CIPHER_SUITE_TKIP:
1113 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1115 case WLAN_CIPHER_SUITE_CCMP:
1116 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1118 case WLAN_CIPHER_SUITE_AES_CMAC:
1119 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1121 case WLAN_CIPHER_SUITE_WEP40:
1122 case WLAN_CIPHER_SUITE_WEP104:
1124 * Support for TX only, at least for now, so accept
1125 * the key and do nothing else. Then mac80211 will
1126 * pass it for TX but we don't have to use it for RX.
1133 mutex_lock(&mvm->mutex);
1137 if (vif->type == NL80211_IFTYPE_AP && !sta) {
1138 /* GTK on AP interface is a TX-only key, return 0 */
1140 key->hw_key_idx = STA_KEY_IDX_INVALID;
1144 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1145 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1147 IWL_WARN(mvm, "set key failed\n");
1149 * can't add key for RX, but we don't need it
1150 * in the device for TX so still return 0
1152 key->hw_key_idx = STA_KEY_IDX_INVALID;
1158 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1163 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1164 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1170 mutex_unlock(&mvm->mutex);
1174 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1175 struct ieee80211_vif *vif,
1176 struct ieee80211_key_conf *keyconf,
1177 struct ieee80211_sta *sta,
1178 u32 iv32, u16 *phase1key)
1180 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1182 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1186 static int iwl_mvm_roc(struct ieee80211_hw *hw,
1187 struct ieee80211_vif *vif,
1188 struct ieee80211_channel *channel,
1190 enum ieee80211_roc_type type)
1192 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1193 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1194 struct cfg80211_chan_def chandef;
1195 struct iwl_mvm_phy_ctxt *phy_ctxt;
1198 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1201 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1202 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1206 mutex_lock(&mvm->mutex);
1208 for (i = 0; i < NUM_PHY_CTX; i++) {
1209 phy_ctxt = &mvm->phy_ctxts[i];
1210 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1213 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1215 * Unbind the P2P_DEVICE from the current PHY context,
1216 * and if the PHY context is not used remove it.
1218 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1219 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1222 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1224 /* Bind the P2P_DEVICE to the current PHY Context */
1225 mvmvif->phy_ctxt = phy_ctxt;
1227 ret = iwl_mvm_binding_add_vif(mvm, vif);
1228 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1231 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1232 goto schedule_time_event;
1236 /* Need to update the PHY context only if the ROC channel changed */
1237 if (channel == mvmvif->phy_ctxt->channel)
1238 goto schedule_time_event;
1240 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
1243 * Change the PHY context configuration as it is currently referenced
1244 * only by the P2P Device MAC
1246 if (mvmvif->phy_ctxt->ref == 1) {
1247 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
1253 * The PHY context is shared with other MACs. Need to remove the
1254 * P2P Device from the binding, allocate an new PHY context and
1255 * create a new binding
1257 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1263 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
1266 IWL_ERR(mvm, "Failed to change PHY context\n");
1270 /* Unbind the P2P_DEVICE from the current PHY context */
1271 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1272 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1275 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1277 /* Bind the P2P_DEVICE to the new allocated PHY context */
1278 mvmvif->phy_ctxt = phy_ctxt;
1280 ret = iwl_mvm_binding_add_vif(mvm, vif);
1281 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1284 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1287 schedule_time_event:
1288 /* Schedule the time events */
1289 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
1292 mutex_unlock(&mvm->mutex);
1293 IWL_DEBUG_MAC80211(mvm, "leave\n");
1297 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1299 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1301 IWL_DEBUG_MAC80211(mvm, "enter\n");
1303 mutex_lock(&mvm->mutex);
1304 iwl_mvm_stop_p2p_roc(mvm);
1305 mutex_unlock(&mvm->mutex);
1307 IWL_DEBUG_MAC80211(mvm, "leave\n");
1311 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1312 struct ieee80211_chanctx_conf *ctx)
1314 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1315 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1316 struct iwl_mvm_phy_ctxt *phy_ctxt;
1319 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
1321 mutex_lock(&mvm->mutex);
1322 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1328 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1329 ctx->rx_chains_static,
1330 ctx->rx_chains_dynamic);
1332 IWL_ERR(mvm, "Failed to add PHY context\n");
1336 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
1337 *phy_ctxt_id = phy_ctxt->id;
1339 mutex_unlock(&mvm->mutex);
1343 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
1344 struct ieee80211_chanctx_conf *ctx)
1346 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1347 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1348 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
1350 mutex_lock(&mvm->mutex);
1351 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
1352 mutex_unlock(&mvm->mutex);
1355 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
1356 struct ieee80211_chanctx_conf *ctx,
1359 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1360 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1361 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
1363 if (WARN_ONCE((phy_ctxt->ref > 1) &&
1364 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
1365 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
1366 IEEE80211_CHANCTX_CHANGE_RADAR)),
1367 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1368 phy_ctxt->ref, changed))
1371 mutex_lock(&mvm->mutex);
1372 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1373 ctx->rx_chains_static,
1374 ctx->rx_chains_dynamic);
1375 mutex_unlock(&mvm->mutex);
1378 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
1379 struct ieee80211_vif *vif,
1380 struct ieee80211_chanctx_conf *ctx)
1382 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1383 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1384 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
1385 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1388 mutex_lock(&mvm->mutex);
1390 mvmvif->phy_ctxt = phy_ctxt;
1392 switch (vif->type) {
1393 case NL80211_IFTYPE_AP:
1395 * The AP binding flow is handled as part of the start_ap flow
1396 * (in bss_info_changed).
1400 case NL80211_IFTYPE_STATION:
1401 case NL80211_IFTYPE_ADHOC:
1402 case NL80211_IFTYPE_MONITOR:
1409 ret = iwl_mvm_binding_add_vif(mvm, vif);
1414 * Setting the quota at this stage is only required for monitor
1415 * interfaces. For the other types, the bss_info changed flow
1416 * will handle quota settings.
1418 if (vif->type == NL80211_IFTYPE_MONITOR) {
1419 mvmvif->monitor_active = true;
1420 ret = iwl_mvm_update_quotas(mvm, vif);
1422 goto out_remove_binding;
1428 iwl_mvm_binding_remove_vif(mvm, vif);
1430 mutex_unlock(&mvm->mutex);
1432 mvmvif->phy_ctxt = NULL;
1436 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
1437 struct ieee80211_vif *vif,
1438 struct ieee80211_chanctx_conf *ctx)
1440 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1441 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1443 mutex_lock(&mvm->mutex);
1445 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
1447 if (vif->type == NL80211_IFTYPE_AP)
1450 switch (vif->type) {
1451 case NL80211_IFTYPE_MONITOR:
1452 mvmvif->monitor_active = false;
1453 iwl_mvm_update_quotas(mvm, NULL);
1459 iwl_mvm_binding_remove_vif(mvm, vif);
1461 mvmvif->phy_ctxt = NULL;
1462 mutex_unlock(&mvm->mutex);
1465 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
1466 struct ieee80211_sta *sta,
1469 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1470 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1472 if (!mvm_sta || !mvm_sta->vif) {
1473 IWL_ERR(mvm, "Station is not associated to a vif\n");
1477 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
1480 static void iwl_mvm_mac_rssi_callback(struct ieee80211_hw *hw,
1481 struct ieee80211_vif *vif,
1482 enum ieee80211_rssi_event rssi_event)
1484 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1486 iwl_mvm_bt_rssi_event(mvm, vif, rssi_event);
1489 struct ieee80211_ops iwl_mvm_hw_ops = {
1490 .tx = iwl_mvm_mac_tx,
1491 .ampdu_action = iwl_mvm_mac_ampdu_action,
1492 .start = iwl_mvm_mac_start,
1493 .restart_complete = iwl_mvm_mac_restart_complete,
1494 .stop = iwl_mvm_mac_stop,
1495 .add_interface = iwl_mvm_mac_add_interface,
1496 .remove_interface = iwl_mvm_mac_remove_interface,
1497 .config = iwl_mvm_mac_config,
1498 .configure_filter = iwl_mvm_configure_filter,
1499 .bss_info_changed = iwl_mvm_bss_info_changed,
1500 .hw_scan = iwl_mvm_mac_hw_scan,
1501 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1502 .sta_state = iwl_mvm_mac_sta_state,
1503 .sta_notify = iwl_mvm_mac_sta_notify,
1504 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
1505 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1506 .conf_tx = iwl_mvm_mac_conf_tx,
1507 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
1508 .set_key = iwl_mvm_mac_set_key,
1509 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
1510 .remain_on_channel = iwl_mvm_roc,
1511 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
1512 .rssi_callback = iwl_mvm_mac_rssi_callback,
1514 .add_chanctx = iwl_mvm_add_chanctx,
1515 .remove_chanctx = iwl_mvm_remove_chanctx,
1516 .change_chanctx = iwl_mvm_change_chanctx,
1517 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
1518 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
1520 .start_ap = iwl_mvm_start_ap,
1521 .stop_ap = iwl_mvm_stop_ap,
1523 .set_tim = iwl_mvm_set_tim,
1525 #ifdef CONFIG_PM_SLEEP
1527 .suspend = iwl_mvm_suspend,
1528 .resume = iwl_mvm_resume,
1529 .set_wakeup = iwl_mvm_set_wakeup,
1530 .set_rekey_data = iwl_mvm_set_rekey_data,
1531 #if IS_ENABLED(CONFIG_IPV6)
1532 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
1534 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,