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 return ieee80211_register_hw(mvm
->hw
);
268 static void iwl_mvm_mac_tx(struct ieee80211_hw
*hw
,
269 struct ieee80211_tx_control
*control
,
272 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
274 if (iwl_mvm_is_radio_killed(mvm
)) {
275 IWL_DEBUG_DROP(mvm
, "Dropping - RF/CT KILL\n");
279 if (IEEE80211_SKB_CB(skb
)->hw_queue
== IWL_MVM_OFFCHANNEL_QUEUE
&&
280 !test_bit(IWL_MVM_STATUS_ROC_RUNNING
, &mvm
->status
))
284 if (iwl_mvm_tx_skb(mvm
, skb
, control
->sta
))
289 if (iwl_mvm_tx_skb_non_sta(mvm
, skb
))
293 ieee80211_free_txskb(hw
, skb
);
296 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw
*hw
,
297 struct ieee80211_vif
*vif
,
298 enum ieee80211_ampdu_mlme_action action
,
299 struct ieee80211_sta
*sta
, u16 tid
,
300 u16
*ssn
, u8 buf_size
)
302 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
305 IWL_DEBUG_HT(mvm
, "A-MPDU action on addr %pM tid %d: action %d\n",
306 sta
->addr
, tid
, action
);
308 if (!(mvm
->nvm_data
->sku_cap_11n_enable
))
311 mutex_lock(&mvm
->mutex
);
314 case IEEE80211_AMPDU_RX_START
:
315 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_RXAGG
) {
319 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, *ssn
, true);
321 case IEEE80211_AMPDU_RX_STOP
:
322 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, 0, false);
324 case IEEE80211_AMPDU_TX_START
:
325 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_TXAGG
) {
329 ret
= iwl_mvm_sta_tx_agg_start(mvm
, vif
, sta
, tid
, ssn
);
331 case IEEE80211_AMPDU_TX_STOP_CONT
:
332 ret
= iwl_mvm_sta_tx_agg_stop(mvm
, vif
, sta
, tid
);
334 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
335 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
336 ret
= iwl_mvm_sta_tx_agg_flush(mvm
, vif
, sta
, tid
);
338 case IEEE80211_AMPDU_TX_OPERATIONAL
:
339 ret
= iwl_mvm_sta_tx_agg_oper(mvm
, vif
, sta
, tid
, buf_size
);
346 mutex_unlock(&mvm
->mutex
);
351 static void iwl_mvm_cleanup_iterator(void *data
, u8
*mac
,
352 struct ieee80211_vif
*vif
)
354 struct iwl_mvm
*mvm
= data
;
355 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
357 mvmvif
->uploaded
= false;
358 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
360 /* does this make sense at all? */
363 spin_lock_bh(&mvm
->time_event_lock
);
364 iwl_mvm_te_clear_data(mvm
, &mvmvif
->time_event_data
);
365 spin_unlock_bh(&mvm
->time_event_lock
);
367 mvmvif
->phy_ctxt
= NULL
;
370 static void iwl_mvm_restart_cleanup(struct iwl_mvm
*mvm
)
372 iwl_trans_stop_device(mvm
->trans
);
373 iwl_trans_stop_hw(mvm
->trans
, false);
375 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
377 /* just in case one was running */
378 ieee80211_remain_on_channel_expired(mvm
->hw
);
380 ieee80211_iterate_active_interfaces_atomic(
381 mvm
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
382 iwl_mvm_cleanup_iterator
, mvm
);
384 mvm
->p2p_device_vif
= NULL
;
386 iwl_mvm_reset_phy_ctxts(mvm
);
387 memset(mvm
->fw_key_table
, 0, sizeof(mvm
->fw_key_table
));
388 memset(mvm
->sta_drained
, 0, sizeof(mvm
->sta_drained
));
390 ieee80211_wake_queues(mvm
->hw
);
395 static int iwl_mvm_mac_start(struct ieee80211_hw
*hw
)
397 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
400 mutex_lock(&mvm
->mutex
);
402 /* Clean up some internal and mac80211 state on restart */
403 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
404 iwl_mvm_restart_cleanup(mvm
);
406 ret
= iwl_mvm_up(mvm
);
407 mutex_unlock(&mvm
->mutex
);
412 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw
*hw
)
414 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
417 mutex_lock(&mvm
->mutex
);
419 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
420 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
422 IWL_ERR(mvm
, "Failed to update quotas after restart (%d)\n",
425 mutex_unlock(&mvm
->mutex
);
428 static void iwl_mvm_mac_stop(struct ieee80211_hw
*hw
)
430 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
432 flush_work(&mvm
->async_handlers_wk
);
434 mutex_lock(&mvm
->mutex
);
435 /* async_handlers_wk is now blocked */
438 * The work item could be running or queued if the
439 * ROC time event stops just as we get here.
441 cancel_work_sync(&mvm
->roc_done_wk
);
443 iwl_trans_stop_device(mvm
->trans
);
444 iwl_trans_stop_hw(mvm
->trans
, false);
446 iwl_mvm_async_handlers_purge(mvm
);
447 /* async_handlers_list is empty and will stay empty: HW is stopped */
449 /* the fw is stopped, the aux sta is dead: clean up driver state */
450 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
452 mutex_unlock(&mvm
->mutex
);
455 * The worker might have been waiting for the mutex, let it run and
456 * discover that its list is now empty.
458 cancel_work_sync(&mvm
->async_handlers_wk
);
461 static void iwl_mvm_pm_disable_iterator(void *data
, u8
*mac
,
462 struct ieee80211_vif
*vif
)
464 struct iwl_mvm
*mvm
= data
;
467 ret
= iwl_mvm_power_disable(mvm
, vif
);
469 IWL_ERR(mvm
, "failed to disable power management\n");
472 static void iwl_mvm_power_update_iterator(void *data
, u8
*mac
,
473 struct ieee80211_vif
*vif
)
475 struct iwl_mvm
*mvm
= data
;
477 iwl_mvm_power_update_mode(mvm
, vif
);
480 static struct iwl_mvm_phy_ctxt
*iwl_mvm_get_free_phy_ctxt(struct iwl_mvm
*mvm
)
484 lockdep_assert_held(&mvm
->mutex
);
486 for (i
= 0; i
< NUM_PHY_CTX
; i
++)
487 if (!mvm
->phy_ctxts
[i
].ref
)
488 return &mvm
->phy_ctxts
[i
];
490 IWL_ERR(mvm
, "No available PHY context\n");
494 static int iwl_mvm_mac_add_interface(struct ieee80211_hw
*hw
,
495 struct ieee80211_vif
*vif
)
497 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
498 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
502 * Not much to do here. The stack will not allow interface
503 * types or combinations that we didn't advertise, so we
504 * don't really have to check the types.
507 mutex_lock(&mvm
->mutex
);
509 /* Allocate resources for the MAC context, and add it to the fw */
510 ret
= iwl_mvm_mac_ctxt_init(mvm
, vif
);
515 * The AP binding flow can be done only after the beacon
516 * template is configured (which happens only in the mac80211
517 * start_ap() flow), and adding the broadcast station can happen
518 * only after the binding.
519 * In addition, since modifying the MAC before adding a bcast
520 * station is not allowed by the FW, delay the adding of MAC context to
521 * the point where we can also add the bcast station.
522 * In short: there's not much we can do at this point, other than
523 * allocating resources :)
525 if (vif
->type
== NL80211_IFTYPE_AP
) {
526 u32 qmask
= iwl_mvm_mac_get_queues_mask(mvm
, vif
);
527 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->bcast_sta
,
530 IWL_ERR(mvm
, "Failed to allocate bcast sta\n");
534 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
539 * TODO: remove this temporary code.
540 * Currently MVM FW supports power management only on single MAC.
541 * If new interface added, disable PM on existing interface.
542 * P2P device is a special case, since it is handled by FW similary to
543 * scan. If P2P deviced is added, PM remains enabled on existing
545 * Note: the method below does not count the new interface being added
548 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
550 if (mvm
->vif_count
> 1) {
551 IWL_DEBUG_MAC80211(mvm
,
552 "Disable power on existing interfaces\n");
553 ieee80211_iterate_active_interfaces_atomic(
555 IEEE80211_IFACE_ITER_NORMAL
,
556 iwl_mvm_pm_disable_iterator
, mvm
);
559 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
564 * Update power state on the new interface. Admittedly, based on
565 * mac80211 logics this power update will disable power management
567 iwl_mvm_power_update_mode(mvm
, vif
);
569 /* beacon filtering */
570 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
);
574 if (!mvm
->bf_allowed_vif
&&
575 vif
->type
== NL80211_IFTYPE_STATION
&& !vif
->p2p
&&
576 mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BF_UPDATED
){
577 mvm
->bf_allowed_vif
= mvmvif
;
578 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
;
582 * P2P_DEVICE interface does not have a channel context assigned to it,
583 * so a dedicated PHY context is allocated to it and the corresponding
584 * MAC context is bound to it at this stage.
586 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
588 mvmvif
->phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
589 if (!mvmvif
->phy_ctxt
) {
594 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
595 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
599 ret
= iwl_mvm_add_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
603 /* Save a pointer to p2p device vif, so it can later be used to
604 * update the p2p device MAC when a GO is started/stopped */
605 mvm
->p2p_device_vif
= vif
;
608 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
612 iwl_mvm_binding_remove_vif(mvm
, vif
);
614 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
616 if (mvm
->bf_allowed_vif
== mvmvif
) {
617 mvm
->bf_allowed_vif
= NULL
;
618 vif
->driver_flags
&= ~IEEE80211_VIF_BEACON_FILTER
;
621 mvmvif
->phy_ctxt
= NULL
;
622 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
624 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
626 ieee80211_iterate_active_interfaces(
627 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
628 iwl_mvm_power_update_iterator
, mvm
);
629 iwl_mvm_mac_ctxt_release(mvm
, vif
);
631 mutex_unlock(&mvm
->mutex
);
636 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm
*mvm
,
637 struct ieee80211_vif
*vif
)
641 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
642 if (vif
->hw_queue
[ac
] != IEEE80211_INVAL_HW_QUEUE
)
643 tfd_msk
|= BIT(vif
->hw_queue
[ac
]);
645 if (vif
->cab_queue
!= IEEE80211_INVAL_HW_QUEUE
)
646 tfd_msk
|= BIT(vif
->cab_queue
);
649 mutex_lock(&mvm
->mutex
);
650 iwl_mvm_flush_tx_path(mvm
, tfd_msk
, true);
651 mutex_unlock(&mvm
->mutex
);
654 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
656 * Flush the ROC worker which will flush the OFFCHANNEL queue.
657 * We assume here that all the packets sent to the OFFCHANNEL
658 * queue are sent in ROC session.
660 flush_work(&mvm
->roc_done_wk
);
663 * By now, all the AC queues are empty. The AGG queues are
664 * empty too. We already got all the Tx responses for all the
665 * packets in the queues. The drain work can have been
666 * triggered. Flush it.
668 flush_work(&mvm
->sta_drained_wk
);
672 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw
*hw
,
673 struct ieee80211_vif
*vif
)
675 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
676 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
678 iwl_mvm_prepare_mac_removal(mvm
, vif
);
680 mutex_lock(&mvm
->mutex
);
682 if (mvm
->bf_allowed_vif
== mvmvif
) {
683 mvm
->bf_allowed_vif
= NULL
;
684 vif
->driver_flags
&= ~IEEE80211_VIF_BEACON_FILTER
;
687 iwl_mvm_vif_dbgfs_clean(mvm
, vif
);
690 * For AP/GO interface, the tear down of the resources allocated to the
691 * interface is be handled as part of the stop_ap flow.
693 if (vif
->type
== NL80211_IFTYPE_AP
) {
694 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->bcast_sta
);
698 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
699 mvm
->p2p_device_vif
= NULL
;
700 iwl_mvm_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
701 iwl_mvm_binding_remove_vif(mvm
, vif
);
702 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
703 mvmvif
->phy_ctxt
= NULL
;
707 * TODO: remove this temporary code.
708 * Currently MVM FW supports power management only on single MAC.
709 * Check if only one additional interface remains after removing
710 * current one. Update power mode on the remaining interface.
712 if (mvm
->vif_count
&& vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
714 IWL_DEBUG_MAC80211(mvm
, "Currently %d interfaces active\n",
716 if (mvm
->vif_count
== 1) {
717 ieee80211_iterate_active_interfaces(
718 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
719 iwl_mvm_power_update_iterator
, mvm
);
722 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
725 iwl_mvm_mac_ctxt_release(mvm
, vif
);
726 mutex_unlock(&mvm
->mutex
);
729 static int iwl_mvm_set_tx_power(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
732 /* FW is in charge of regulatory enforcement */
733 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd
= {
734 .mac_context_id
= iwl_mvm_vif_from_mac80211(vif
)->id
,
735 .pwr_restriction
= cpu_to_le16(tx_power
),
738 return iwl_mvm_send_cmd_pdu(mvm
, REDUCE_TX_POWER_CMD
, CMD_SYNC
,
739 sizeof(reduce_txpwr_cmd
),
743 static int iwl_mvm_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
748 static void iwl_mvm_configure_filter(struct ieee80211_hw
*hw
,
749 unsigned int changed_flags
,
750 unsigned int *total_flags
,
756 static int iwl_mvm_configure_mcast_filter(struct iwl_mvm
*mvm
,
757 struct ieee80211_vif
*vif
)
759 struct iwl_mcast_filter_cmd mcast_filter_cmd
= {
763 memcpy(mcast_filter_cmd
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
765 return iwl_mvm_send_cmd_pdu(mvm
, MCAST_FILTER_CMD
, CMD_SYNC
,
766 sizeof(mcast_filter_cmd
),
770 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm
*mvm
,
771 struct ieee80211_vif
*vif
,
772 struct ieee80211_bss_conf
*bss_conf
,
775 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
778 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
780 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
782 if (changes
& BSS_CHANGED_ASSOC
) {
783 if (bss_conf
->assoc
) {
784 /* add quota for this interface */
785 ret
= iwl_mvm_update_quotas(mvm
, vif
);
787 IWL_ERR(mvm
, "failed to update quotas\n");
790 iwl_mvm_configure_mcast_filter(mvm
, vif
);
791 } else if (mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
792 /* remove AP station now that the MAC is unassoc */
793 ret
= iwl_mvm_rm_sta_id(mvm
, vif
, mvmvif
->ap_sta_id
);
795 IWL_ERR(mvm
, "failed to remove AP station\n");
796 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
797 /* remove quota for this interface */
798 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
800 IWL_ERR(mvm
, "failed to update quotas\n");
802 if (!(mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_UAPSD
)) {
803 /* Workaround for FW bug, otherwise FW disables device
804 * power save upon disassociation
806 ret
= iwl_mvm_power_update_mode(mvm
, vif
);
808 IWL_ERR(mvm
, "failed to update power mode\n");
810 iwl_mvm_bt_coex_vif_assoc(mvm
, vif
);
811 } else if (changes
& BSS_CHANGED_BEACON_INFO
) {
813 * We received a beacon _after_ association so
814 * remove the session protection.
816 iwl_mvm_remove_time_event(mvm
, mvmvif
,
817 &mvmvif
->time_event_data
);
818 } else if (changes
& (BSS_CHANGED_PS
| BSS_CHANGED_QOS
)) {
819 ret
= iwl_mvm_power_update_mode(mvm
, vif
);
821 IWL_ERR(mvm
, "failed to update power mode\n");
823 if (changes
& BSS_CHANGED_TXPOWER
) {
824 IWL_DEBUG_CALIB(mvm
, "Changing TX Power to %d\n",
826 iwl_mvm_set_tx_power(mvm
, vif
, bss_conf
->txpower
);
830 static int iwl_mvm_start_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
832 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
833 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
836 mutex_lock(&mvm
->mutex
);
838 /* Send the beacon template */
839 ret
= iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
);
843 /* Add the mac context */
844 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
848 /* Perform the binding */
849 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
853 mvmvif
->ap_active
= true;
855 /* Send the bcast station. At this stage the TBTT and DTIM time events
856 * are added and applied to the scheduler */
857 ret
= iwl_mvm_send_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
861 ret
= iwl_mvm_update_quotas(mvm
, vif
);
865 /* Need to update the P2P Device MAC */
866 if (vif
->p2p
&& mvm
->p2p_device_vif
)
867 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
869 mutex_unlock(&mvm
->mutex
);
873 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
875 iwl_mvm_binding_remove_vif(mvm
, vif
);
877 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
879 mutex_unlock(&mvm
->mutex
);
883 static void iwl_mvm_stop_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
885 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
886 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
888 iwl_mvm_prepare_mac_removal(mvm
, vif
);
890 mutex_lock(&mvm
->mutex
);
892 mvmvif
->ap_active
= false;
894 /* Need to update the P2P Device MAC */
895 if (vif
->p2p
&& mvm
->p2p_device_vif
)
896 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
898 iwl_mvm_update_quotas(mvm
, NULL
);
899 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
900 iwl_mvm_binding_remove_vif(mvm
, vif
);
901 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
903 mutex_unlock(&mvm
->mutex
);
906 static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm
*mvm
,
907 struct ieee80211_vif
*vif
,
908 struct ieee80211_bss_conf
*bss_conf
,
911 /* Need to send a new beacon template to the FW */
912 if (changes
& BSS_CHANGED_BEACON
) {
913 if (iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
))
914 IWL_WARN(mvm
, "Failed updating beacon data\n");
918 static void iwl_mvm_bss_info_changed(struct ieee80211_hw
*hw
,
919 struct ieee80211_vif
*vif
,
920 struct ieee80211_bss_conf
*bss_conf
,
923 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
925 mutex_lock(&mvm
->mutex
);
928 case NL80211_IFTYPE_STATION
:
929 iwl_mvm_bss_info_changed_station(mvm
, vif
, bss_conf
, changes
);
931 case NL80211_IFTYPE_AP
:
932 iwl_mvm_bss_info_changed_ap(mvm
, vif
, bss_conf
, changes
);
935 /* shouldn't happen */
939 mutex_unlock(&mvm
->mutex
);
942 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw
*hw
,
943 struct ieee80211_vif
*vif
,
944 struct cfg80211_scan_request
*req
)
946 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
949 if (req
->n_channels
== 0 || req
->n_channels
> MAX_NUM_SCAN_CHANNELS
)
952 mutex_lock(&mvm
->mutex
);
954 if (mvm
->scan_status
== IWL_MVM_SCAN_NONE
)
955 ret
= iwl_mvm_scan_request(mvm
, vif
, req
);
959 mutex_unlock(&mvm
->mutex
);
964 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw
*hw
,
965 struct ieee80211_vif
*vif
)
967 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
969 mutex_lock(&mvm
->mutex
);
971 iwl_mvm_cancel_scan(mvm
);
973 mutex_unlock(&mvm
->mutex
);
977 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw
*hw
,
978 struct ieee80211_sta
*sta
, u16 tid
,
980 enum ieee80211_frame_release_type reason
,
983 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
985 /* TODO: how do we tell the fw to send frames for a specific TID */
988 * The fw will send EOSP notification when the last frame will be
991 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
);
994 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw
*hw
,
995 struct ieee80211_vif
*vif
,
996 enum sta_notify_cmd cmd
,
997 struct ieee80211_sta
*sta
)
999 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1000 struct iwl_mvm_sta
*mvmsta
= (void *)sta
->drv_priv
;
1003 case STA_NOTIFY_SLEEP
:
1004 if (atomic_read(&mvm
->pending_frames
[mvmsta
->sta_id
]) > 0)
1005 ieee80211_sta_block_awake(hw
, sta
, true);
1007 * The fw updates the STA to be asleep. Tx packets on the Tx
1008 * queues to this station will not be transmitted. The fw will
1009 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1012 case STA_NOTIFY_AWAKE
:
1013 if (WARN_ON(mvmsta
->sta_id
== IWL_MVM_STATION_COUNT
))
1015 iwl_mvm_sta_modify_ps_wake(mvm
, sta
);
1022 static int iwl_mvm_mac_sta_state(struct ieee80211_hw
*hw
,
1023 struct ieee80211_vif
*vif
,
1024 struct ieee80211_sta
*sta
,
1025 enum ieee80211_sta_state old_state
,
1026 enum ieee80211_sta_state new_state
)
1028 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1029 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1032 IWL_DEBUG_MAC80211(mvm
, "station %pM state change %d->%d\n",
1033 sta
->addr
, old_state
, new_state
);
1035 /* this would be a mac80211 bug ... but don't crash */
1036 if (WARN_ON_ONCE(!mvmvif
->phy_ctxt
))
1039 /* if a STA is being removed, reuse its ID */
1040 flush_work(&mvm
->sta_drained_wk
);
1042 mutex_lock(&mvm
->mutex
);
1043 if (old_state
== IEEE80211_STA_NOTEXIST
&&
1044 new_state
== IEEE80211_STA_NONE
) {
1045 ret
= iwl_mvm_add_sta(mvm
, vif
, sta
);
1046 } else if (old_state
== IEEE80211_STA_NONE
&&
1047 new_state
== IEEE80211_STA_AUTH
) {
1049 } else if (old_state
== IEEE80211_STA_AUTH
&&
1050 new_state
== IEEE80211_STA_ASSOC
) {
1051 ret
= iwl_mvm_update_sta(mvm
, vif
, sta
);
1053 iwl_mvm_rs_rate_init(mvm
, sta
,
1054 mvmvif
->phy_ctxt
->channel
->band
);
1055 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1056 new_state
== IEEE80211_STA_AUTHORIZED
) {
1057 /* enable beacon filtering */
1058 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
));
1060 } else if (old_state
== IEEE80211_STA_AUTHORIZED
&&
1061 new_state
== IEEE80211_STA_ASSOC
) {
1062 /* disable beacon filtering */
1063 WARN_ON(iwl_mvm_disable_beacon_filter(mvm
, vif
));
1065 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1066 new_state
== IEEE80211_STA_AUTH
) {
1068 } else if (old_state
== IEEE80211_STA_AUTH
&&
1069 new_state
== IEEE80211_STA_NONE
) {
1071 } else if (old_state
== IEEE80211_STA_NONE
&&
1072 new_state
== IEEE80211_STA_NOTEXIST
) {
1073 ret
= iwl_mvm_rm_sta(mvm
, vif
, sta
);
1077 mutex_unlock(&mvm
->mutex
);
1082 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1084 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1086 mvm
->rts_threshold
= value
;
1091 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw
*hw
,
1092 struct ieee80211_vif
*vif
, u16 ac
,
1093 const struct ieee80211_tx_queue_params
*params
)
1095 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1096 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1098 mvmvif
->queue_params
[ac
] = *params
;
1101 * No need to update right away, we'll get BSS_CHANGED_QOS
1102 * The exception is P2P_DEVICE interface which needs immediate update.
1104 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1107 mutex_lock(&mvm
->mutex
);
1108 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
1109 mutex_unlock(&mvm
->mutex
);
1115 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw
*hw
,
1116 struct ieee80211_vif
*vif
)
1118 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1119 u32 duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS
,
1120 200 + vif
->bss_conf
.beacon_int
);
1121 u32 min_duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS
,
1122 100 + vif
->bss_conf
.beacon_int
);
1124 if (WARN_ON_ONCE(vif
->bss_conf
.assoc
))
1127 mutex_lock(&mvm
->mutex
);
1128 /* Try really hard to protect the session and hear a beacon */
1129 iwl_mvm_protect_session(mvm
, vif
, duration
, min_duration
);
1130 mutex_unlock(&mvm
->mutex
);
1133 static int iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
1134 enum set_key_cmd cmd
,
1135 struct ieee80211_vif
*vif
,
1136 struct ieee80211_sta
*sta
,
1137 struct ieee80211_key_conf
*key
)
1139 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1142 if (iwlwifi_mod_params
.sw_crypto
) {
1143 IWL_DEBUG_MAC80211(mvm
, "leave - hwcrypto disabled\n");
1147 switch (key
->cipher
) {
1148 case WLAN_CIPHER_SUITE_TKIP
:
1149 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1151 case WLAN_CIPHER_SUITE_CCMP
:
1152 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1154 case WLAN_CIPHER_SUITE_AES_CMAC
:
1155 WARN_ON_ONCE(!(hw
->flags
& IEEE80211_HW_MFP_CAPABLE
));
1157 case WLAN_CIPHER_SUITE_WEP40
:
1158 case WLAN_CIPHER_SUITE_WEP104
:
1160 * Support for TX only, at least for now, so accept
1161 * the key and do nothing else. Then mac80211 will
1162 * pass it for TX but we don't have to use it for RX.
1169 mutex_lock(&mvm
->mutex
);
1173 if (vif
->type
== NL80211_IFTYPE_AP
&& !sta
) {
1174 /* GTK on AP interface is a TX-only key, return 0 */
1176 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1180 IWL_DEBUG_MAC80211(mvm
, "set hwcrypto key\n");
1181 ret
= iwl_mvm_set_sta_key(mvm
, vif
, sta
, key
, false);
1183 IWL_WARN(mvm
, "set key failed\n");
1185 * can't add key for RX, but we don't need it
1186 * in the device for TX so still return 0
1188 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1194 if (key
->hw_key_idx
== STA_KEY_IDX_INVALID
) {
1199 IWL_DEBUG_MAC80211(mvm
, "disable hwcrypto key\n");
1200 ret
= iwl_mvm_remove_sta_key(mvm
, vif
, sta
, key
);
1206 mutex_unlock(&mvm
->mutex
);
1210 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw
*hw
,
1211 struct ieee80211_vif
*vif
,
1212 struct ieee80211_key_conf
*keyconf
,
1213 struct ieee80211_sta
*sta
,
1214 u32 iv32
, u16
*phase1key
)
1216 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1218 iwl_mvm_update_tkip_key(mvm
, vif
, keyconf
, sta
, iv32
, phase1key
);
1222 static int iwl_mvm_roc(struct ieee80211_hw
*hw
,
1223 struct ieee80211_vif
*vif
,
1224 struct ieee80211_channel
*channel
,
1226 enum ieee80211_roc_type type
)
1228 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1229 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1230 struct cfg80211_chan_def chandef
;
1231 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1234 IWL_DEBUG_MAC80211(mvm
, "enter (%d, %d, %d)\n", channel
->hw_value
,
1237 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
) {
1238 IWL_ERR(mvm
, "vif isn't a P2P_DEVICE: %d\n", vif
->type
);
1242 mutex_lock(&mvm
->mutex
);
1244 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
1245 phy_ctxt
= &mvm
->phy_ctxts
[i
];
1246 if (phy_ctxt
->ref
== 0 || mvmvif
->phy_ctxt
== phy_ctxt
)
1249 if (phy_ctxt
->ref
&& channel
== phy_ctxt
->channel
) {
1251 * Unbind the P2P_DEVICE from the current PHY context,
1252 * and if the PHY context is not used remove it.
1254 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1255 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1258 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1260 /* Bind the P2P_DEVICE to the current PHY Context */
1261 mvmvif
->phy_ctxt
= phy_ctxt
;
1263 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1264 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1267 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1268 goto schedule_time_event
;
1272 /* Need to update the PHY context only if the ROC channel changed */
1273 if (channel
== mvmvif
->phy_ctxt
->channel
)
1274 goto schedule_time_event
;
1276 cfg80211_chandef_create(&chandef
, channel
, NL80211_CHAN_NO_HT
);
1279 * Change the PHY context configuration as it is currently referenced
1280 * only by the P2P Device MAC
1282 if (mvmvif
->phy_ctxt
->ref
== 1) {
1283 ret
= iwl_mvm_phy_ctxt_changed(mvm
, mvmvif
->phy_ctxt
,
1289 * The PHY context is shared with other MACs. Need to remove the
1290 * P2P Device from the binding, allocate an new PHY context and
1291 * create a new binding
1293 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1299 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &chandef
,
1302 IWL_ERR(mvm
, "Failed to change PHY context\n");
1306 /* Unbind the P2P_DEVICE from the current PHY context */
1307 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1308 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1311 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1313 /* Bind the P2P_DEVICE to the new allocated PHY context */
1314 mvmvif
->phy_ctxt
= phy_ctxt
;
1316 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1317 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1320 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1323 schedule_time_event
:
1324 /* Schedule the time events */
1325 ret
= iwl_mvm_start_p2p_roc(mvm
, vif
, duration
, type
);
1328 mutex_unlock(&mvm
->mutex
);
1329 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1333 static int iwl_mvm_cancel_roc(struct ieee80211_hw
*hw
)
1335 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1337 IWL_DEBUG_MAC80211(mvm
, "enter\n");
1339 mutex_lock(&mvm
->mutex
);
1340 iwl_mvm_stop_p2p_roc(mvm
);
1341 mutex_unlock(&mvm
->mutex
);
1343 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1347 static int iwl_mvm_add_chanctx(struct ieee80211_hw
*hw
,
1348 struct ieee80211_chanctx_conf
*ctx
)
1350 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1351 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1352 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1355 IWL_DEBUG_MAC80211(mvm
, "Add channel context\n");
1357 mutex_lock(&mvm
->mutex
);
1358 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1364 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->def
,
1365 ctx
->rx_chains_static
,
1366 ctx
->rx_chains_dynamic
);
1368 IWL_ERR(mvm
, "Failed to add PHY context\n");
1372 iwl_mvm_phy_ctxt_ref(mvm
, phy_ctxt
);
1373 *phy_ctxt_id
= phy_ctxt
->id
;
1375 mutex_unlock(&mvm
->mutex
);
1379 static void iwl_mvm_remove_chanctx(struct ieee80211_hw
*hw
,
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
];
1386 mutex_lock(&mvm
->mutex
);
1387 iwl_mvm_phy_ctxt_unref(mvm
, phy_ctxt
);
1388 mutex_unlock(&mvm
->mutex
);
1391 static void iwl_mvm_change_chanctx(struct ieee80211_hw
*hw
,
1392 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 if (WARN_ONCE((phy_ctxt
->ref
> 1) &&
1400 (changed
& ~(IEEE80211_CHANCTX_CHANGE_WIDTH
|
1401 IEEE80211_CHANCTX_CHANGE_RX_CHAINS
|
1402 IEEE80211_CHANCTX_CHANGE_RADAR
)),
1403 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1404 phy_ctxt
->ref
, changed
))
1407 mutex_lock(&mvm
->mutex
);
1408 iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->def
,
1409 ctx
->rx_chains_static
,
1410 ctx
->rx_chains_dynamic
);
1411 mutex_unlock(&mvm
->mutex
);
1414 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw
*hw
,
1415 struct ieee80211_vif
*vif
,
1416 struct ieee80211_chanctx_conf
*ctx
)
1418 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1419 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1420 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1421 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1424 mutex_lock(&mvm
->mutex
);
1426 mvmvif
->phy_ctxt
= phy_ctxt
;
1428 switch (vif
->type
) {
1429 case NL80211_IFTYPE_AP
:
1431 * The AP binding flow is handled as part of the start_ap flow
1432 * (in bss_info_changed).
1436 case NL80211_IFTYPE_STATION
:
1437 case NL80211_IFTYPE_ADHOC
:
1438 case NL80211_IFTYPE_MONITOR
:
1445 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1450 * Setting the quota at this stage is only required for monitor
1451 * interfaces. For the other types, the bss_info changed flow
1452 * will handle quota settings.
1454 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
1455 mvmvif
->monitor_active
= true;
1456 ret
= iwl_mvm_update_quotas(mvm
, vif
);
1458 goto out_remove_binding
;
1464 iwl_mvm_binding_remove_vif(mvm
, vif
);
1466 mutex_unlock(&mvm
->mutex
);
1468 mvmvif
->phy_ctxt
= NULL
;
1472 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
1473 struct ieee80211_vif
*vif
,
1474 struct ieee80211_chanctx_conf
*ctx
)
1476 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1477 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1479 mutex_lock(&mvm
->mutex
);
1481 iwl_mvm_remove_time_event(mvm
, mvmvif
, &mvmvif
->time_event_data
);
1483 if (vif
->type
== NL80211_IFTYPE_AP
)
1486 switch (vif
->type
) {
1487 case NL80211_IFTYPE_MONITOR
:
1488 mvmvif
->monitor_active
= false;
1489 iwl_mvm_update_quotas(mvm
, NULL
);
1495 iwl_mvm_binding_remove_vif(mvm
, vif
);
1497 mvmvif
->phy_ctxt
= NULL
;
1498 mutex_unlock(&mvm
->mutex
);
1501 static int iwl_mvm_set_tim(struct ieee80211_hw
*hw
,
1502 struct ieee80211_sta
*sta
,
1505 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1506 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
1508 if (!mvm_sta
|| !mvm_sta
->vif
) {
1509 IWL_ERR(mvm
, "Station is not associated to a vif\n");
1513 return iwl_mvm_mac_ctxt_beacon_changed(mvm
, mvm_sta
->vif
);
1516 static void iwl_mvm_mac_rssi_callback(struct ieee80211_hw
*hw
,
1517 struct ieee80211_vif
*vif
,
1518 enum ieee80211_rssi_event rssi_event
)
1520 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1522 iwl_mvm_bt_rssi_event(mvm
, vif
, rssi_event
);
1525 struct ieee80211_ops iwl_mvm_hw_ops
= {
1526 .tx
= iwl_mvm_mac_tx
,
1527 .ampdu_action
= iwl_mvm_mac_ampdu_action
,
1528 .start
= iwl_mvm_mac_start
,
1529 .restart_complete
= iwl_mvm_mac_restart_complete
,
1530 .stop
= iwl_mvm_mac_stop
,
1531 .add_interface
= iwl_mvm_mac_add_interface
,
1532 .remove_interface
= iwl_mvm_mac_remove_interface
,
1533 .config
= iwl_mvm_mac_config
,
1534 .configure_filter
= iwl_mvm_configure_filter
,
1535 .bss_info_changed
= iwl_mvm_bss_info_changed
,
1536 .hw_scan
= iwl_mvm_mac_hw_scan
,
1537 .cancel_hw_scan
= iwl_mvm_mac_cancel_hw_scan
,
1538 .sta_state
= iwl_mvm_mac_sta_state
,
1539 .sta_notify
= iwl_mvm_mac_sta_notify
,
1540 .allow_buffered_frames
= iwl_mvm_mac_allow_buffered_frames
,
1541 .set_rts_threshold
= iwl_mvm_mac_set_rts_threshold
,
1542 .conf_tx
= iwl_mvm_mac_conf_tx
,
1543 .mgd_prepare_tx
= iwl_mvm_mac_mgd_prepare_tx
,
1544 .set_key
= iwl_mvm_mac_set_key
,
1545 .update_tkip_key
= iwl_mvm_mac_update_tkip_key
,
1546 .remain_on_channel
= iwl_mvm_roc
,
1547 .cancel_remain_on_channel
= iwl_mvm_cancel_roc
,
1548 .rssi_callback
= iwl_mvm_mac_rssi_callback
,
1550 .add_chanctx
= iwl_mvm_add_chanctx
,
1551 .remove_chanctx
= iwl_mvm_remove_chanctx
,
1552 .change_chanctx
= iwl_mvm_change_chanctx
,
1553 .assign_vif_chanctx
= iwl_mvm_assign_vif_chanctx
,
1554 .unassign_vif_chanctx
= iwl_mvm_unassign_vif_chanctx
,
1556 .start_ap
= iwl_mvm_start_ap
,
1557 .stop_ap
= iwl_mvm_stop_ap
,
1559 .set_tim
= iwl_mvm_set_tim
,
1561 #ifdef CONFIG_PM_SLEEP
1563 .suspend
= iwl_mvm_suspend
,
1564 .resume
= iwl_mvm_resume
,
1565 .set_wakeup
= iwl_mvm_set_wakeup
,
1566 .set_rekey_data
= iwl_mvm_set_rekey_data
,
1567 #if IS_ENABLED(CONFIG_IPV6)
1568 .ipv6_addr_change
= iwl_mvm_ipv6_addr_change
,
1570 .set_default_unicast_key
= iwl_mvm_set_default_unicast_key
,