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;
160 hw->queues = IWL_MVM_FIRST_AGG_QUEUE;
161 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
162 hw->rate_control_algorithm = "iwl-mvm-rs";
165 * Enable 11w if advertised by firmware and software crypto
166 * is not enabled (as the firmware will interpret some mgmt
167 * packets, so enabling it with software crypto isn't safe)
169 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
170 !iwlwifi_mod_params.sw_crypto)
171 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
173 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
174 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
175 hw->chanctx_data_size = sizeof(u16);
177 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
178 BIT(NL80211_IFTYPE_P2P_CLIENT) |
179 BIT(NL80211_IFTYPE_AP) |
180 BIT(NL80211_IFTYPE_P2P_GO) |
181 BIT(NL80211_IFTYPE_P2P_DEVICE);
183 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
184 WIPHY_FLAG_DISABLE_BEACON_HINTS |
187 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
188 hw->wiphy->n_iface_combinations =
189 ARRAY_SIZE(iwl_mvm_iface_combinations);
191 hw->wiphy->max_remain_on_channel_duration = 10000;
192 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
194 /* Extract MAC address */
195 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
196 hw->wiphy->addresses = mvm->addresses;
197 hw->wiphy->n_addresses = 1;
199 /* Extract additional MAC addresses if available */
200 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
201 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
203 for (i = 1; i < num_mac; i++) {
204 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
206 mvm->addresses[i].addr[5]++;
207 hw->wiphy->n_addresses++;
210 iwl_mvm_reset_phy_ctxts(mvm);
212 /* we create the 802.11 header and a max-length SSID element */
213 hw->wiphy->max_scan_ie_len =
214 mvm->fw->ucode_capa.max_probe_length - 24 - 34;
215 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
217 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
218 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
219 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
220 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
221 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
222 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
224 hw->wiphy->hw_version = mvm->trans->hw_id;
226 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
227 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
229 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
231 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
232 NL80211_FEATURE_P2P_GO_OPPPS;
234 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
236 #ifdef CONFIG_PM_SLEEP
237 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
238 mvm->trans->ops->d3_suspend &&
239 mvm->trans->ops->d3_resume &&
240 device_can_wakeup(mvm->trans->dev)) {
241 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
242 WIPHY_WOWLAN_DISCONNECT |
243 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
244 WIPHY_WOWLAN_RFKILL_RELEASE;
245 if (!iwlwifi_mod_params.sw_crypto)
246 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
247 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
248 WIPHY_WOWLAN_4WAY_HANDSHAKE;
250 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
251 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
252 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
253 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
254 hw->wiphy->wowlan = &mvm->wowlan;
258 ret = iwl_mvm_leds_init(mvm);
262 ret = ieee80211_register_hw(mvm->hw);
264 iwl_mvm_leds_exit(mvm);
269 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
270 struct ieee80211_tx_control *control,
273 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
275 if (iwl_mvm_is_radio_killed(mvm)) {
276 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
280 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
281 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
285 if (iwl_mvm_tx_skb(mvm, skb, control->sta))
290 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
294 ieee80211_free_txskb(hw, skb);
297 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
298 struct ieee80211_vif *vif,
299 enum ieee80211_ampdu_mlme_action action,
300 struct ieee80211_sta *sta, u16 tid,
301 u16 *ssn, u8 buf_size)
303 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
306 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
307 sta->addr, tid, action);
309 if (!(mvm->nvm_data->sku_cap_11n_enable))
312 mutex_lock(&mvm->mutex);
315 case IEEE80211_AMPDU_RX_START:
316 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
320 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
322 case IEEE80211_AMPDU_RX_STOP:
323 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
325 case IEEE80211_AMPDU_TX_START:
326 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
330 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
332 case IEEE80211_AMPDU_TX_STOP_CONT:
333 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
335 case IEEE80211_AMPDU_TX_STOP_FLUSH:
336 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
337 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
339 case IEEE80211_AMPDU_TX_OPERATIONAL:
340 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
347 mutex_unlock(&mvm->mutex);
352 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
353 struct ieee80211_vif *vif)
355 struct iwl_mvm *mvm = data;
356 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
358 mvmvif->uploaded = false;
359 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
361 /* does this make sense at all? */
364 spin_lock_bh(&mvm->time_event_lock);
365 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
366 spin_unlock_bh(&mvm->time_event_lock);
368 mvmvif->phy_ctxt = NULL;
371 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
373 iwl_trans_stop_device(mvm->trans);
374 iwl_trans_stop_hw(mvm->trans, false);
376 mvm->scan_status = IWL_MVM_SCAN_NONE;
378 /* just in case one was running */
379 ieee80211_remain_on_channel_expired(mvm->hw);
381 ieee80211_iterate_active_interfaces_atomic(
382 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
383 iwl_mvm_cleanup_iterator, mvm);
385 mvm->p2p_device_vif = NULL;
387 iwl_mvm_reset_phy_ctxts(mvm);
388 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
389 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
391 ieee80211_wake_queues(mvm->hw);
394 mvm->rx_ba_sessions = 0;
397 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
399 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
402 mutex_lock(&mvm->mutex);
404 /* Clean up some internal and mac80211 state on restart */
405 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
406 iwl_mvm_restart_cleanup(mvm);
408 ret = iwl_mvm_up(mvm);
409 mutex_unlock(&mvm->mutex);
414 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
416 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
419 mutex_lock(&mvm->mutex);
421 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
422 ret = iwl_mvm_update_quotas(mvm, NULL);
424 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
427 mutex_unlock(&mvm->mutex);
430 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
432 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
434 flush_work(&mvm->async_handlers_wk);
436 mutex_lock(&mvm->mutex);
437 /* async_handlers_wk is now blocked */
440 * The work item could be running or queued if the
441 * ROC time event stops just as we get here.
443 cancel_work_sync(&mvm->roc_done_wk);
445 iwl_trans_stop_device(mvm->trans);
446 iwl_trans_stop_hw(mvm->trans, false);
448 iwl_mvm_async_handlers_purge(mvm);
449 /* async_handlers_list is empty and will stay empty: HW is stopped */
451 /* the fw is stopped, the aux sta is dead: clean up driver state */
452 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
454 mutex_unlock(&mvm->mutex);
457 * The worker might have been waiting for the mutex, let it run and
458 * discover that its list is now empty.
460 cancel_work_sync(&mvm->async_handlers_wk);
463 static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac,
464 struct ieee80211_vif *vif)
466 struct iwl_mvm *mvm = data;
469 ret = iwl_mvm_power_disable(mvm, vif);
471 IWL_ERR(mvm, "failed to disable power management\n");
474 static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
475 struct ieee80211_vif *vif)
477 struct iwl_mvm *mvm = data;
479 iwl_mvm_power_update_mode(mvm, vif);
482 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
486 lockdep_assert_held(&mvm->mutex);
488 for (i = 0; i < NUM_PHY_CTX; i++)
489 if (!mvm->phy_ctxts[i].ref)
490 return &mvm->phy_ctxts[i];
492 IWL_ERR(mvm, "No available PHY context\n");
496 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
497 struct ieee80211_vif *vif)
499 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
500 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
504 * Not much to do here. The stack will not allow interface
505 * types or combinations that we didn't advertise, so we
506 * don't really have to check the types.
509 mutex_lock(&mvm->mutex);
511 /* Allocate resources for the MAC context, and add it the the fw */
512 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
517 * TODO: remove this temporary code.
518 * Currently MVM FW supports power management only on single MAC.
519 * If new interface added, disable PM on existing interface.
520 * P2P device is a special case, since it is handled by FW similary to
521 * scan. If P2P deviced is added, PM remains enabled on existing
523 * Note: the method below does not count the new interface being added
526 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
528 if (mvm->vif_count > 1) {
529 IWL_DEBUG_MAC80211(mvm,
530 "Disable power on existing interfaces\n");
531 ieee80211_iterate_active_interfaces_atomic(
533 IEEE80211_IFACE_ITER_NORMAL,
534 iwl_mvm_pm_disable_iterator, mvm);
538 * The AP binding flow can be done only after the beacon
539 * template is configured (which happens only in the mac80211
540 * start_ap() flow), and adding the broadcast station can happen
541 * only after the binding.
542 * In addition, since modifying the MAC before adding a bcast
543 * station is not allowed by the FW, delay the adding of MAC context to
544 * the point where we can also add the bcast station.
545 * In short: there's not much we can do at this point, other than
546 * allocating resources :)
548 if (vif->type == NL80211_IFTYPE_AP) {
549 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
550 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
553 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
557 iwl_mvm_vif_dbgfs_register(mvm, vif);
561 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
566 * Update power state on the new interface. Admittedly, based on
567 * mac80211 logics this power update will disable power management
569 iwl_mvm_power_update_mode(mvm, vif);
571 /* beacon filtering */
572 if (!mvm->bf_allowed_vif &&
573 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
574 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
575 mvm->bf_allowed_vif = mvmvif;
576 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER;
579 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
584 * P2P_DEVICE interface does not have a channel context assigned to it,
585 * so a dedicated PHY context is allocated to it and the corresponding
586 * MAC context is bound to it at this stage.
588 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
590 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
591 if (!mvmvif->phy_ctxt) {
596 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
597 ret = iwl_mvm_binding_add_vif(mvm, vif);
601 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
605 /* Save a pointer to p2p device vif, so it can later be used to
606 * update the p2p device MAC when a GO is started/stopped */
607 mvm->p2p_device_vif = vif;
610 iwl_mvm_vif_dbgfs_register(mvm, vif);
614 iwl_mvm_binding_remove_vif(mvm, vif);
616 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
618 mvmvif->phy_ctxt = NULL;
619 iwl_mvm_mac_ctxt_remove(mvm, vif);
621 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
623 ieee80211_iterate_active_interfaces(
624 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
625 iwl_mvm_power_update_iterator, mvm);
626 iwl_mvm_mac_ctxt_release(mvm, vif);
628 mutex_unlock(&mvm->mutex);
633 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
634 struct ieee80211_vif *vif)
638 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
639 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
640 tfd_msk |= BIT(vif->hw_queue[ac]);
642 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
643 tfd_msk |= BIT(vif->cab_queue);
646 mutex_lock(&mvm->mutex);
647 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
648 mutex_unlock(&mvm->mutex);
651 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
653 * Flush the ROC worker which will flush the OFFCHANNEL queue.
654 * We assume here that all the packets sent to the OFFCHANNEL
655 * queue are sent in ROC session.
657 flush_work(&mvm->roc_done_wk);
660 * By now, all the AC queues are empty. The AGG queues are
661 * empty too. We already got all the Tx responses for all the
662 * packets in the queues. The drain work can have been
663 * triggered. Flush it.
665 flush_work(&mvm->sta_drained_wk);
669 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
670 struct ieee80211_vif *vif)
672 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
673 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
675 iwl_mvm_prepare_mac_removal(mvm, vif);
677 mutex_lock(&mvm->mutex);
679 if (mvm->bf_allowed_vif == mvmvif) {
680 mvm->bf_allowed_vif = NULL;
681 vif->driver_flags &= ~IEEE80211_VIF_BEACON_FILTER;
684 iwl_mvm_vif_dbgfs_clean(mvm, vif);
687 * For AP/GO interface, the tear down of the resources allocated to the
688 * interface is be handled as part of the stop_ap flow.
690 if (vif->type == NL80211_IFTYPE_AP) {
691 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
695 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
696 mvm->p2p_device_vif = NULL;
697 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
698 iwl_mvm_binding_remove_vif(mvm, vif);
699 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
700 mvmvif->phy_ctxt = NULL;
704 * TODO: remove this temporary code.
705 * Currently MVM FW supports power management only on single MAC.
706 * Check if only one additional interface remains after removing
707 * current one. Update power mode on the remaining interface.
709 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
711 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
713 if (mvm->vif_count == 1) {
714 ieee80211_iterate_active_interfaces(
715 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
716 iwl_mvm_power_update_iterator, mvm);
719 iwl_mvm_mac_ctxt_remove(mvm, vif);
722 iwl_mvm_mac_ctxt_release(mvm, vif);
723 mutex_unlock(&mvm->mutex);
726 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
729 /* FW is in charge of regulatory enforcement */
730 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
731 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
732 .pwr_restriction = cpu_to_le16(tx_power),
735 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
736 sizeof(reduce_txpwr_cmd),
740 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
745 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
746 unsigned int changed_flags,
747 unsigned int *total_flags,
753 static int iwl_mvm_configure_mcast_filter(struct iwl_mvm *mvm,
754 struct ieee80211_vif *vif)
756 struct iwl_mcast_filter_cmd mcast_filter_cmd = {
760 memcpy(mcast_filter_cmd.bssid, vif->bss_conf.bssid, ETH_ALEN);
762 return iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC,
763 sizeof(mcast_filter_cmd),
767 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
768 struct ieee80211_vif *vif,
769 struct ieee80211_bss_conf *bss_conf,
772 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
775 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
777 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
779 if (changes & BSS_CHANGED_ASSOC) {
780 if (bss_conf->assoc) {
781 /* add quota for this interface */
782 ret = iwl_mvm_update_quotas(mvm, vif);
784 IWL_ERR(mvm, "failed to update quotas\n");
787 iwl_mvm_configure_mcast_filter(mvm, vif);
788 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
789 /* remove AP station now that the MAC is unassoc */
790 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
792 IWL_ERR(mvm, "failed to remove AP station\n");
793 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
794 /* remove quota for this interface */
795 ret = iwl_mvm_update_quotas(mvm, NULL);
797 IWL_ERR(mvm, "failed to update quotas\n");
799 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD)) {
800 /* Workaround for FW bug, otherwise FW disables device
801 * power save upon disassociation
803 ret = iwl_mvm_power_update_mode(mvm, vif);
805 IWL_ERR(mvm, "failed to update power mode\n");
807 iwl_mvm_bt_coex_vif_assoc(mvm, vif);
808 } else if (changes & BSS_CHANGED_BEACON_INFO) {
810 * We received a beacon _after_ association so
811 * remove the session protection.
813 iwl_mvm_remove_time_event(mvm, mvmvif,
814 &mvmvif->time_event_data);
815 } else if (changes & BSS_CHANGED_PS) {
816 ret = iwl_mvm_power_update_mode(mvm, vif);
818 IWL_ERR(mvm, "failed to update power mode\n");
820 if (changes & BSS_CHANGED_TXPOWER) {
821 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
823 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
827 static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
829 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
830 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
833 mutex_lock(&mvm->mutex);
835 /* Send the beacon template */
836 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
840 /* Add the mac context */
841 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
845 /* Perform the binding */
846 ret = iwl_mvm_binding_add_vif(mvm, vif);
850 mvmvif->ap_active = true;
852 /* Send the bcast station. At this stage the TBTT and DTIM time events
853 * are added and applied to the scheduler */
854 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
858 ret = iwl_mvm_update_quotas(mvm, vif);
862 /* Need to update the P2P Device MAC */
863 if (vif->p2p && mvm->p2p_device_vif)
864 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
866 mutex_unlock(&mvm->mutex);
870 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
872 iwl_mvm_binding_remove_vif(mvm, vif);
874 iwl_mvm_mac_ctxt_remove(mvm, vif);
876 mutex_unlock(&mvm->mutex);
880 static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
882 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
883 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
885 iwl_mvm_prepare_mac_removal(mvm, vif);
887 mutex_lock(&mvm->mutex);
889 mvmvif->ap_active = false;
891 /* Need to update the P2P Device MAC */
892 if (vif->p2p && mvm->p2p_device_vif)
893 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif);
895 iwl_mvm_update_quotas(mvm, NULL);
896 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
897 iwl_mvm_binding_remove_vif(mvm, vif);
898 iwl_mvm_mac_ctxt_remove(mvm, vif);
900 mutex_unlock(&mvm->mutex);
903 static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm,
904 struct ieee80211_vif *vif,
905 struct ieee80211_bss_conf *bss_conf,
908 /* Need to send a new beacon template to the FW */
909 if (changes & BSS_CHANGED_BEACON) {
910 if (iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
911 IWL_WARN(mvm, "Failed updating beacon data\n");
915 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
916 struct ieee80211_vif *vif,
917 struct ieee80211_bss_conf *bss_conf,
920 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
922 mutex_lock(&mvm->mutex);
925 case NL80211_IFTYPE_STATION:
926 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
928 case NL80211_IFTYPE_AP:
929 iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes);
932 /* shouldn't happen */
936 mutex_unlock(&mvm->mutex);
939 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
940 struct ieee80211_vif *vif,
941 struct cfg80211_scan_request *req)
943 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
946 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
949 mutex_lock(&mvm->mutex);
951 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
952 ret = iwl_mvm_scan_request(mvm, vif, req);
956 mutex_unlock(&mvm->mutex);
961 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
962 struct ieee80211_vif *vif)
964 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
966 mutex_lock(&mvm->mutex);
968 iwl_mvm_cancel_scan(mvm);
970 mutex_unlock(&mvm->mutex);
974 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
975 struct ieee80211_sta *sta, u16 tid,
977 enum ieee80211_frame_release_type reason,
980 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
982 /* TODO: how do we tell the fw to send frames for a specific TID */
985 * The fw will send EOSP notification when the last frame will be
988 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
991 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
992 struct ieee80211_vif *vif,
993 enum sta_notify_cmd cmd,
994 struct ieee80211_sta *sta)
996 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
997 struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
1000 case STA_NOTIFY_SLEEP:
1001 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
1002 ieee80211_sta_block_awake(hw, sta, true);
1004 * The fw updates the STA to be asleep. Tx packets on the Tx
1005 * queues to this station will not be transmitted. The fw will
1006 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1009 case STA_NOTIFY_AWAKE:
1010 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
1012 iwl_mvm_sta_modify_ps_wake(mvm, sta);
1019 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1020 struct ieee80211_vif *vif,
1021 struct ieee80211_sta *sta,
1022 enum ieee80211_sta_state old_state,
1023 enum ieee80211_sta_state new_state)
1025 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1026 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1029 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1030 sta->addr, old_state, new_state);
1032 /* this would be a mac80211 bug ... but don't crash */
1033 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1036 /* if a STA is being removed, reuse its ID */
1037 flush_work(&mvm->sta_drained_wk);
1039 mutex_lock(&mvm->mutex);
1040 if (old_state == IEEE80211_STA_NOTEXIST &&
1041 new_state == IEEE80211_STA_NONE) {
1043 * Firmware bug - it'll crash if the beacon interval is less
1044 * than 16. We can't avoid connecting at all, so refuse the
1045 * station state change, this will cause mac80211 to abandon
1046 * attempts to connect to this AP, and eventually wpa_s will
1047 * blacklist the AP...
1049 if (vif->type == NL80211_IFTYPE_STATION &&
1050 vif->bss_conf.beacon_int < 16) {
1052 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1053 sta->addr, vif->bss_conf.beacon_int);
1057 ret = iwl_mvm_add_sta(mvm, vif, sta);
1058 } else if (old_state == IEEE80211_STA_NONE &&
1059 new_state == IEEE80211_STA_AUTH) {
1061 } else if (old_state == IEEE80211_STA_AUTH &&
1062 new_state == IEEE80211_STA_ASSOC) {
1063 ret = iwl_mvm_update_sta(mvm, vif, sta);
1065 iwl_mvm_rs_rate_init(mvm, sta,
1066 mvmvif->phy_ctxt->channel->band);
1067 } else if (old_state == IEEE80211_STA_ASSOC &&
1068 new_state == IEEE80211_STA_AUTHORIZED) {
1069 /* enable beacon filtering */
1070 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
1072 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1073 new_state == IEEE80211_STA_ASSOC) {
1074 /* disable beacon filtering */
1075 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
1077 } else if (old_state == IEEE80211_STA_ASSOC &&
1078 new_state == IEEE80211_STA_AUTH) {
1080 } else if (old_state == IEEE80211_STA_AUTH &&
1081 new_state == IEEE80211_STA_NONE) {
1083 } else if (old_state == IEEE80211_STA_NONE &&
1084 new_state == IEEE80211_STA_NOTEXIST) {
1085 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1090 mutex_unlock(&mvm->mutex);
1095 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1097 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1099 mvm->rts_threshold = value;
1104 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1105 struct ieee80211_vif *vif, u16 ac,
1106 const struct ieee80211_tx_queue_params *params)
1108 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1109 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1111 mvmvif->queue_params[ac] = *params;
1114 * No need to update right away, we'll get BSS_CHANGED_QOS
1115 * The exception is P2P_DEVICE interface which needs immediate update.
1117 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1120 mutex_lock(&mvm->mutex);
1121 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1122 mutex_unlock(&mvm->mutex);
1128 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1129 struct ieee80211_vif *vif)
1131 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1132 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1133 200 + vif->bss_conf.beacon_int);
1134 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1135 100 + vif->bss_conf.beacon_int);
1137 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1140 mutex_lock(&mvm->mutex);
1141 /* Try really hard to protect the session and hear a beacon */
1142 iwl_mvm_protect_session(mvm, vif, duration, min_duration);
1143 mutex_unlock(&mvm->mutex);
1146 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
1147 enum set_key_cmd cmd,
1148 struct ieee80211_vif *vif,
1149 struct ieee80211_sta *sta,
1150 struct ieee80211_key_conf *key)
1152 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1155 if (iwlwifi_mod_params.sw_crypto) {
1156 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1160 switch (key->cipher) {
1161 case WLAN_CIPHER_SUITE_TKIP:
1162 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1164 case WLAN_CIPHER_SUITE_CCMP:
1165 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1167 case WLAN_CIPHER_SUITE_AES_CMAC:
1168 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1170 case WLAN_CIPHER_SUITE_WEP40:
1171 case WLAN_CIPHER_SUITE_WEP104:
1173 * Support for TX only, at least for now, so accept
1174 * the key and do nothing else. Then mac80211 will
1175 * pass it for TX but we don't have to use it for RX.
1182 mutex_lock(&mvm->mutex);
1186 if (vif->type == NL80211_IFTYPE_AP && !sta) {
1187 /* GTK on AP interface is a TX-only key, return 0 */
1189 key->hw_key_idx = STA_KEY_IDX_INVALID;
1193 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1194 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1196 IWL_WARN(mvm, "set key failed\n");
1198 * can't add key for RX, but we don't need it
1199 * in the device for TX so still return 0
1201 key->hw_key_idx = STA_KEY_IDX_INVALID;
1207 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1212 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1213 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1219 mutex_unlock(&mvm->mutex);
1223 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
1224 struct ieee80211_vif *vif,
1225 struct ieee80211_key_conf *keyconf,
1226 struct ieee80211_sta *sta,
1227 u32 iv32, u16 *phase1key)
1229 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1231 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1235 static int iwl_mvm_roc(struct ieee80211_hw *hw,
1236 struct ieee80211_vif *vif,
1237 struct ieee80211_channel *channel,
1239 enum ieee80211_roc_type type)
1241 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1242 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1243 struct cfg80211_chan_def chandef;
1244 struct iwl_mvm_phy_ctxt *phy_ctxt;
1247 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1250 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1251 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1255 mutex_lock(&mvm->mutex);
1257 for (i = 0; i < NUM_PHY_CTX; i++) {
1258 phy_ctxt = &mvm->phy_ctxts[i];
1259 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
1262 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1264 * Unbind the P2P_DEVICE from the current PHY context,
1265 * and if the PHY context is not used remove it.
1267 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1268 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1271 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1273 /* Bind the P2P_DEVICE to the current PHY Context */
1274 mvmvif->phy_ctxt = phy_ctxt;
1276 ret = iwl_mvm_binding_add_vif(mvm, vif);
1277 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1280 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1281 goto schedule_time_event;
1285 /* Need to update the PHY context only if the ROC channel changed */
1286 if (channel == mvmvif->phy_ctxt->channel)
1287 goto schedule_time_event;
1289 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
1292 * Change the PHY context configuration as it is currently referenced
1293 * only by the P2P Device MAC
1295 if (mvmvif->phy_ctxt->ref == 1) {
1296 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
1302 * The PHY context is shared with other MACs. Need to remove the
1303 * P2P Device from the binding, allocate an new PHY context and
1304 * create a new binding
1306 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1312 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
1315 IWL_ERR(mvm, "Failed to change PHY context\n");
1319 /* Unbind the P2P_DEVICE from the current PHY context */
1320 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1321 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1324 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1326 /* Bind the P2P_DEVICE to the new allocated PHY context */
1327 mvmvif->phy_ctxt = phy_ctxt;
1329 ret = iwl_mvm_binding_add_vif(mvm, vif);
1330 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1333 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1336 schedule_time_event:
1337 /* Schedule the time events */
1338 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
1341 mutex_unlock(&mvm->mutex);
1342 IWL_DEBUG_MAC80211(mvm, "leave\n");
1346 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1348 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1350 IWL_DEBUG_MAC80211(mvm, "enter\n");
1352 mutex_lock(&mvm->mutex);
1353 iwl_mvm_stop_p2p_roc(mvm);
1354 mutex_unlock(&mvm->mutex);
1356 IWL_DEBUG_MAC80211(mvm, "leave\n");
1360 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1361 struct ieee80211_chanctx_conf *ctx)
1363 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1364 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1365 struct iwl_mvm_phy_ctxt *phy_ctxt;
1368 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
1370 mutex_lock(&mvm->mutex);
1371 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1377 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1378 ctx->rx_chains_static,
1379 ctx->rx_chains_dynamic);
1381 IWL_ERR(mvm, "Failed to add PHY context\n");
1385 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
1386 *phy_ctxt_id = phy_ctxt->id;
1388 mutex_unlock(&mvm->mutex);
1392 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
1393 struct ieee80211_chanctx_conf *ctx)
1395 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1396 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1397 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
1399 mutex_lock(&mvm->mutex);
1400 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
1401 mutex_unlock(&mvm->mutex);
1404 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
1405 struct ieee80211_chanctx_conf *ctx,
1408 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1409 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1410 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
1412 if (WARN_ONCE((phy_ctxt->ref > 1) &&
1413 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
1414 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
1415 IEEE80211_CHANCTX_CHANGE_RADAR)),
1416 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1417 phy_ctxt->ref, changed))
1420 mutex_lock(&mvm->mutex);
1421 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1422 ctx->rx_chains_static,
1423 ctx->rx_chains_dynamic);
1424 mutex_unlock(&mvm->mutex);
1427 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
1428 struct ieee80211_vif *vif,
1429 struct ieee80211_chanctx_conf *ctx)
1431 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1432 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1433 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
1434 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1437 mutex_lock(&mvm->mutex);
1439 mvmvif->phy_ctxt = phy_ctxt;
1441 switch (vif->type) {
1442 case NL80211_IFTYPE_AP:
1444 * The AP binding flow is handled as part of the start_ap flow
1445 * (in bss_info_changed).
1449 case NL80211_IFTYPE_STATION:
1450 case NL80211_IFTYPE_ADHOC:
1451 case NL80211_IFTYPE_MONITOR:
1458 ret = iwl_mvm_binding_add_vif(mvm, vif);
1463 * Setting the quota at this stage is only required for monitor
1464 * interfaces. For the other types, the bss_info changed flow
1465 * will handle quota settings.
1467 if (vif->type == NL80211_IFTYPE_MONITOR) {
1468 mvmvif->monitor_active = true;
1469 ret = iwl_mvm_update_quotas(mvm, vif);
1471 goto out_remove_binding;
1477 iwl_mvm_binding_remove_vif(mvm, vif);
1479 mutex_unlock(&mvm->mutex);
1481 mvmvif->phy_ctxt = NULL;
1485 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
1486 struct ieee80211_vif *vif,
1487 struct ieee80211_chanctx_conf *ctx)
1489 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1490 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1492 mutex_lock(&mvm->mutex);
1494 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
1496 if (vif->type == NL80211_IFTYPE_AP)
1499 switch (vif->type) {
1500 case NL80211_IFTYPE_MONITOR:
1501 mvmvif->monitor_active = false;
1502 iwl_mvm_update_quotas(mvm, NULL);
1508 iwl_mvm_binding_remove_vif(mvm, vif);
1510 mvmvif->phy_ctxt = NULL;
1511 mutex_unlock(&mvm->mutex);
1514 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
1515 struct ieee80211_sta *sta,
1518 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1519 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1521 if (!mvm_sta || !mvm_sta->vif) {
1522 IWL_ERR(mvm, "Station is not associated to a vif\n");
1526 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
1529 static void iwl_mvm_mac_rssi_callback(struct ieee80211_hw *hw,
1530 struct ieee80211_vif *vif,
1531 enum ieee80211_rssi_event rssi_event)
1533 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1535 iwl_mvm_bt_rssi_event(mvm, vif, rssi_event);
1538 struct ieee80211_ops iwl_mvm_hw_ops = {
1539 .tx = iwl_mvm_mac_tx,
1540 .ampdu_action = iwl_mvm_mac_ampdu_action,
1541 .start = iwl_mvm_mac_start,
1542 .restart_complete = iwl_mvm_mac_restart_complete,
1543 .stop = iwl_mvm_mac_stop,
1544 .add_interface = iwl_mvm_mac_add_interface,
1545 .remove_interface = iwl_mvm_mac_remove_interface,
1546 .config = iwl_mvm_mac_config,
1547 .configure_filter = iwl_mvm_configure_filter,
1548 .bss_info_changed = iwl_mvm_bss_info_changed,
1549 .hw_scan = iwl_mvm_mac_hw_scan,
1550 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1551 .sta_state = iwl_mvm_mac_sta_state,
1552 .sta_notify = iwl_mvm_mac_sta_notify,
1553 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
1554 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1555 .conf_tx = iwl_mvm_mac_conf_tx,
1556 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
1557 .set_key = iwl_mvm_mac_set_key,
1558 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
1559 .remain_on_channel = iwl_mvm_roc,
1560 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
1561 .rssi_callback = iwl_mvm_mac_rssi_callback,
1563 .add_chanctx = iwl_mvm_add_chanctx,
1564 .remove_chanctx = iwl_mvm_remove_chanctx,
1565 .change_chanctx = iwl_mvm_change_chanctx,
1566 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
1567 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
1569 .start_ap = iwl_mvm_start_ap,
1570 .stop_ap = iwl_mvm_stop_ap,
1572 .set_tim = iwl_mvm_set_tim,
1574 #ifdef CONFIG_PM_SLEEP
1576 .suspend = iwl_mvm_suspend,
1577 .resume = iwl_mvm_resume,
1578 .set_wakeup = iwl_mvm_set_wakeup,
1579 .set_rekey_data = iwl_mvm_set_rekey_data,
1580 #if IS_ENABLED(CONFIG_IPV6)
1581 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
1583 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,