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"
82 static const struct ieee80211_iface_limit iwl_mvm_limits
[] = {
85 .types
= BIT(NL80211_IFTYPE_STATION
),
89 .types
= BIT(NL80211_IFTYPE_AP
) |
90 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
91 BIT(NL80211_IFTYPE_P2P_GO
),
95 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
99 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations
[] = {
101 .num_different_channels
= 1,
103 .limits
= iwl_mvm_limits
,
104 .n_limits
= ARRAY_SIZE(iwl_mvm_limits
),
108 #ifdef CONFIG_PM_SLEEP
109 static const struct nl80211_wowlan_tcp_data_token_feature
110 iwl_mvm_wowlan_tcp_token_feature
= {
113 .bufsize
= IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS
,
116 static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support
= {
117 .tok
= &iwl_mvm_wowlan_tcp_token_feature
,
118 .data_payload_max
= IWL_WOWLAN_TCP_MAX_PACKET_LEN
-
119 sizeof(struct ethhdr
) -
120 sizeof(struct iphdr
) -
121 sizeof(struct tcphdr
),
122 .data_interval_max
= 65535, /* __le16 in API */
123 .wake_payload_max
= IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN
-
124 sizeof(struct ethhdr
) -
125 sizeof(struct iphdr
) -
126 sizeof(struct tcphdr
),
131 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm
*mvm
)
135 memset(mvm
->phy_ctxts
, 0, sizeof(mvm
->phy_ctxts
));
136 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
137 mvm
->phy_ctxts
[i
].id
= i
;
138 mvm
->phy_ctxts
[i
].ref
= 0;
142 static int iwl_mvm_max_scan_ie_len(struct iwl_mvm
*mvm
)
144 /* we create the 802.11 header and SSID element */
145 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID
)
146 return mvm
->fw
->ucode_capa
.max_probe_length
- 24 - 2;
147 return mvm
->fw
->ucode_capa
.max_probe_length
- 24 - 34;
150 int iwl_mvm_mac_setup_register(struct iwl_mvm
*mvm
)
152 struct ieee80211_hw
*hw
= mvm
->hw
;
155 /* Tell mac80211 our characteristics */
156 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
157 IEEE80211_HW_SPECTRUM_MGMT
|
158 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
159 IEEE80211_HW_QUEUE_CONTROL
|
160 IEEE80211_HW_WANT_MONITOR_VIF
|
161 IEEE80211_HW_SUPPORTS_PS
|
162 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
163 IEEE80211_HW_AMPDU_AGGREGATION
|
164 IEEE80211_HW_TIMING_BEACON_ONLY
|
165 IEEE80211_HW_CONNECTION_MONITOR
|
166 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS
|
167 IEEE80211_HW_SUPPORTS_STATIC_SMPS
|
168 IEEE80211_HW_SUPPORTS_UAPSD
;
170 hw
->queues
= IWL_MVM_FIRST_AGG_QUEUE
;
171 hw
->offchannel_tx_hw_queue
= IWL_MVM_OFFCHANNEL_QUEUE
;
172 hw
->rate_control_algorithm
= "iwl-mvm-rs";
175 * Enable 11w if advertised by firmware and software crypto
176 * is not enabled (as the firmware will interpret some mgmt
177 * packets, so enabling it with software crypto isn't safe)
179 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_MFP
&&
180 !iwlwifi_mod_params
.sw_crypto
)
181 hw
->flags
|= IEEE80211_HW_MFP_CAPABLE
;
183 hw
->sta_data_size
= sizeof(struct iwl_mvm_sta
);
184 hw
->vif_data_size
= sizeof(struct iwl_mvm_vif
);
185 hw
->chanctx_data_size
= sizeof(u16
);
187 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
188 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
189 BIT(NL80211_IFTYPE_AP
) |
190 BIT(NL80211_IFTYPE_P2P_GO
) |
191 BIT(NL80211_IFTYPE_P2P_DEVICE
);
193 hw
->wiphy
->flags
|= WIPHY_FLAG_CUSTOM_REGULATORY
|
194 WIPHY_FLAG_DISABLE_BEACON_HINTS
|
197 hw
->wiphy
->iface_combinations
= iwl_mvm_iface_combinations
;
198 hw
->wiphy
->n_iface_combinations
=
199 ARRAY_SIZE(iwl_mvm_iface_combinations
);
201 hw
->wiphy
->max_remain_on_channel_duration
= 10000;
202 hw
->max_listen_interval
= IWL_CONN_MAX_LISTEN_INTERVAL
;
203 hw
->uapsd_queues
= IWL_UAPSD_AC_INFO
;
204 hw
->uapsd_max_sp_len
= IWL_UAPSD_MAX_SP
;
206 /* Extract MAC address */
207 memcpy(mvm
->addresses
[0].addr
, mvm
->nvm_data
->hw_addr
, ETH_ALEN
);
208 hw
->wiphy
->addresses
= mvm
->addresses
;
209 hw
->wiphy
->n_addresses
= 1;
211 /* Extract additional MAC addresses if available */
212 num_mac
= (mvm
->nvm_data
->n_hw_addrs
> 1) ?
213 min(IWL_MVM_MAX_ADDRESSES
, mvm
->nvm_data
->n_hw_addrs
) : 1;
215 for (i
= 1; i
< num_mac
; i
++) {
216 memcpy(mvm
->addresses
[i
].addr
, mvm
->addresses
[i
-1].addr
,
218 mvm
->addresses
[i
].addr
[5]++;
219 hw
->wiphy
->n_addresses
++;
222 iwl_mvm_reset_phy_ctxts(mvm
);
224 hw
->wiphy
->max_scan_ie_len
= iwl_mvm_max_scan_ie_len(mvm
);
226 hw
->wiphy
->max_scan_ssids
= PROBE_OPTION_MAX
;
228 if (mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
229 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
230 &mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
];
231 if (mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
232 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
233 &mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
];
235 hw
->wiphy
->hw_version
= mvm
->trans
->hw_id
;
237 if (iwlmvm_mod_params
.power_scheme
!= IWL_POWER_SCHEME_CAM
)
238 hw
->wiphy
->flags
|= WIPHY_FLAG_PS_ON_BY_DEFAULT
;
240 hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
242 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_SCHED_SCAN
) {
243 hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_SCHED_SCAN
;
244 hw
->wiphy
->max_sched_scan_ssids
= PROBE_OPTION_MAX
;
245 hw
->wiphy
->max_match_sets
= IWL_SCAN_MAX_PROFILES
;
246 /* we create the 802.11 header and zero length SSID IE. */
247 hw
->wiphy
->max_sched_scan_ie_len
=
248 SCAN_OFFLOAD_PROBE_REQ_SIZE
- 24 - 2;
251 hw
->wiphy
->features
|= NL80211_FEATURE_P2P_GO_CTWIN
|
252 NL80211_FEATURE_P2P_GO_OPPPS
;
254 mvm
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
256 #ifdef CONFIG_PM_SLEEP
257 if (mvm
->fw
->img
[IWL_UCODE_WOWLAN
].sec
[0].len
&&
258 mvm
->trans
->ops
->d3_suspend
&&
259 mvm
->trans
->ops
->d3_resume
&&
260 device_can_wakeup(mvm
->trans
->dev
)) {
261 mvm
->wowlan
.flags
= WIPHY_WOWLAN_MAGIC_PKT
|
262 WIPHY_WOWLAN_DISCONNECT
|
263 WIPHY_WOWLAN_EAP_IDENTITY_REQ
|
264 WIPHY_WOWLAN_RFKILL_RELEASE
;
265 if (!iwlwifi_mod_params
.sw_crypto
)
266 mvm
->wowlan
.flags
|= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
|
267 WIPHY_WOWLAN_GTK_REKEY_FAILURE
|
268 WIPHY_WOWLAN_4WAY_HANDSHAKE
;
270 mvm
->wowlan
.n_patterns
= IWL_WOWLAN_MAX_PATTERNS
;
271 mvm
->wowlan
.pattern_min_len
= IWL_WOWLAN_MIN_PATTERN_LEN
;
272 mvm
->wowlan
.pattern_max_len
= IWL_WOWLAN_MAX_PATTERN_LEN
;
273 mvm
->wowlan
.tcp
= &iwl_mvm_wowlan_tcp_support
;
274 hw
->wiphy
->wowlan
= &mvm
->wowlan
;
278 ret
= iwl_mvm_leds_init(mvm
);
282 ret
= ieee80211_register_hw(mvm
->hw
);
284 iwl_mvm_leds_exit(mvm
);
289 static void iwl_mvm_mac_tx(struct ieee80211_hw
*hw
,
290 struct ieee80211_tx_control
*control
,
293 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
295 if (iwl_mvm_is_radio_killed(mvm
)) {
296 IWL_DEBUG_DROP(mvm
, "Dropping - RF/CT KILL\n");
300 if (IEEE80211_SKB_CB(skb
)->hw_queue
== IWL_MVM_OFFCHANNEL_QUEUE
&&
301 !test_bit(IWL_MVM_STATUS_ROC_RUNNING
, &mvm
->status
))
305 if (iwl_mvm_tx_skb(mvm
, skb
, control
->sta
))
310 if (iwl_mvm_tx_skb_non_sta(mvm
, skb
))
314 ieee80211_free_txskb(hw
, skb
);
317 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw
*hw
,
318 struct ieee80211_vif
*vif
,
319 enum ieee80211_ampdu_mlme_action action
,
320 struct ieee80211_sta
*sta
, u16 tid
,
321 u16
*ssn
, u8 buf_size
)
323 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
326 IWL_DEBUG_HT(mvm
, "A-MPDU action on addr %pM tid %d: action %d\n",
327 sta
->addr
, tid
, action
);
329 if (!(mvm
->nvm_data
->sku_cap_11n_enable
))
332 mutex_lock(&mvm
->mutex
);
335 case IEEE80211_AMPDU_RX_START
:
336 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_RXAGG
) {
340 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, *ssn
, true);
342 case IEEE80211_AMPDU_RX_STOP
:
343 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, 0, false);
345 case IEEE80211_AMPDU_TX_START
:
346 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_TXAGG
) {
350 ret
= iwl_mvm_sta_tx_agg_start(mvm
, vif
, sta
, tid
, ssn
);
352 case IEEE80211_AMPDU_TX_STOP_CONT
:
353 ret
= iwl_mvm_sta_tx_agg_stop(mvm
, vif
, sta
, tid
);
355 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
356 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
357 ret
= iwl_mvm_sta_tx_agg_flush(mvm
, vif
, sta
, tid
);
359 case IEEE80211_AMPDU_TX_OPERATIONAL
:
360 ret
= iwl_mvm_sta_tx_agg_oper(mvm
, vif
, sta
, tid
, buf_size
);
367 mutex_unlock(&mvm
->mutex
);
372 static void iwl_mvm_cleanup_iterator(void *data
, u8
*mac
,
373 struct ieee80211_vif
*vif
)
375 struct iwl_mvm
*mvm
= data
;
376 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
378 mvmvif
->uploaded
= false;
379 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
381 /* does this make sense at all? */
384 spin_lock_bh(&mvm
->time_event_lock
);
385 iwl_mvm_te_clear_data(mvm
, &mvmvif
->time_event_data
);
386 spin_unlock_bh(&mvm
->time_event_lock
);
388 mvmvif
->phy_ctxt
= NULL
;
391 static void iwl_mvm_restart_cleanup(struct iwl_mvm
*mvm
)
393 iwl_trans_stop_device(mvm
->trans
);
394 iwl_trans_stop_hw(mvm
->trans
, false);
396 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
398 /* just in case one was running */
399 ieee80211_remain_on_channel_expired(mvm
->hw
);
401 ieee80211_iterate_active_interfaces_atomic(
402 mvm
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
403 iwl_mvm_cleanup_iterator
, mvm
);
405 mvm
->p2p_device_vif
= NULL
;
407 iwl_mvm_reset_phy_ctxts(mvm
);
408 memset(mvm
->fw_key_table
, 0, sizeof(mvm
->fw_key_table
));
409 memset(mvm
->sta_drained
, 0, sizeof(mvm
->sta_drained
));
411 ieee80211_wake_queues(mvm
->hw
);
414 mvm
->rx_ba_sessions
= 0;
417 static int iwl_mvm_mac_start(struct ieee80211_hw
*hw
)
419 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
422 mutex_lock(&mvm
->mutex
);
424 /* Clean up some internal and mac80211 state on restart */
425 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
426 iwl_mvm_restart_cleanup(mvm
);
428 ret
= iwl_mvm_up(mvm
);
429 mutex_unlock(&mvm
->mutex
);
434 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw
*hw
)
436 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
439 mutex_lock(&mvm
->mutex
);
441 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
442 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
444 IWL_ERR(mvm
, "Failed to update quotas after restart (%d)\n",
447 mutex_unlock(&mvm
->mutex
);
450 static void iwl_mvm_mac_stop(struct ieee80211_hw
*hw
)
452 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
454 flush_work(&mvm
->async_handlers_wk
);
456 mutex_lock(&mvm
->mutex
);
457 /* async_handlers_wk is now blocked */
460 * The work item could be running or queued if the
461 * ROC time event stops just as we get here.
463 cancel_work_sync(&mvm
->roc_done_wk
);
465 iwl_trans_stop_device(mvm
->trans
);
466 iwl_trans_stop_hw(mvm
->trans
, false);
468 iwl_mvm_async_handlers_purge(mvm
);
469 /* async_handlers_list is empty and will stay empty: HW is stopped */
471 /* the fw is stopped, the aux sta is dead: clean up driver state */
472 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
474 mutex_unlock(&mvm
->mutex
);
477 * The worker might have been waiting for the mutex, let it run and
478 * discover that its list is now empty.
480 cancel_work_sync(&mvm
->async_handlers_wk
);
483 static void iwl_mvm_pm_disable_iterator(void *data
, u8
*mac
,
484 struct ieee80211_vif
*vif
)
486 struct iwl_mvm
*mvm
= data
;
489 ret
= iwl_mvm_power_disable(mvm
, vif
);
491 IWL_ERR(mvm
, "failed to disable power management\n");
494 static void iwl_mvm_power_update_iterator(void *data
, u8
*mac
,
495 struct ieee80211_vif
*vif
)
497 struct iwl_mvm
*mvm
= data
;
499 iwl_mvm_power_update_mode(mvm
, vif
);
502 static struct iwl_mvm_phy_ctxt
*iwl_mvm_get_free_phy_ctxt(struct iwl_mvm
*mvm
)
506 lockdep_assert_held(&mvm
->mutex
);
508 for (i
= 0; i
< NUM_PHY_CTX
; i
++)
509 if (!mvm
->phy_ctxts
[i
].ref
)
510 return &mvm
->phy_ctxts
[i
];
512 IWL_ERR(mvm
, "No available PHY context\n");
516 static int iwl_mvm_mac_add_interface(struct ieee80211_hw
*hw
,
517 struct ieee80211_vif
*vif
)
519 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
520 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
524 * Not much to do here. The stack will not allow interface
525 * types or combinations that we didn't advertise, so we
526 * don't really have to check the types.
529 mutex_lock(&mvm
->mutex
);
531 /* Allocate resources for the MAC context, and add it to the fw */
532 ret
= iwl_mvm_mac_ctxt_init(mvm
, vif
);
537 * TODO: remove this temporary code.
538 * Currently MVM FW supports power management only on single MAC.
539 * If new interface added, disable PM on existing interface.
540 * P2P device is a special case, since it is handled by FW similary to
541 * scan. If P2P deviced is added, PM remains enabled on existing
543 * Note: the method below does not count the new interface being added
546 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
548 if (mvm
->vif_count
> 1) {
549 IWL_DEBUG_MAC80211(mvm
,
550 "Disable power on existing interfaces\n");
551 ieee80211_iterate_active_interfaces_atomic(
553 IEEE80211_IFACE_ITER_NORMAL
,
554 iwl_mvm_pm_disable_iterator
, mvm
);
558 * The AP binding flow can be done only after the beacon
559 * template is configured (which happens only in the mac80211
560 * start_ap() flow), and adding the broadcast station can happen
561 * only after the binding.
562 * In addition, since modifying the MAC before adding a bcast
563 * station is not allowed by the FW, delay the adding of MAC context to
564 * the point where we can also add the bcast station.
565 * In short: there's not much we can do at this point, other than
566 * allocating resources :)
568 if (vif
->type
== NL80211_IFTYPE_AP
) {
569 u32 qmask
= iwl_mvm_mac_get_queues_mask(mvm
, vif
);
570 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->bcast_sta
,
573 IWL_ERR(mvm
, "Failed to allocate bcast sta\n");
577 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
581 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
586 * Update power state on the new interface. Admittedly, based on
587 * mac80211 logics this power update will disable power management
589 iwl_mvm_power_update_mode(mvm
, vif
);
591 /* beacon filtering */
592 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
);
596 if (!mvm
->bf_allowed_vif
&&
597 vif
->type
== NL80211_IFTYPE_STATION
&& !vif
->p2p
&&
598 mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BF_UPDATED
){
599 mvm
->bf_allowed_vif
= mvmvif
;
600 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
601 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
605 * P2P_DEVICE interface does not have a channel context assigned to it,
606 * so a dedicated PHY context is allocated to it and the corresponding
607 * MAC context is bound to it at this stage.
609 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
611 mvmvif
->phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
612 if (!mvmvif
->phy_ctxt
) {
617 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
618 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
622 ret
= iwl_mvm_add_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
626 /* Save a pointer to p2p device vif, so it can later be used to
627 * update the p2p device MAC when a GO is started/stopped */
628 mvm
->p2p_device_vif
= vif
;
631 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
635 iwl_mvm_binding_remove_vif(mvm
, vif
);
637 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
639 if (mvm
->bf_allowed_vif
== mvmvif
) {
640 mvm
->bf_allowed_vif
= NULL
;
641 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
642 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
645 mvmvif
->phy_ctxt
= NULL
;
646 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
648 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
650 ieee80211_iterate_active_interfaces(
651 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
652 iwl_mvm_power_update_iterator
, mvm
);
653 iwl_mvm_mac_ctxt_release(mvm
, vif
);
655 mutex_unlock(&mvm
->mutex
);
660 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm
*mvm
,
661 struct ieee80211_vif
*vif
)
665 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
666 if (vif
->hw_queue
[ac
] != IEEE80211_INVAL_HW_QUEUE
)
667 tfd_msk
|= BIT(vif
->hw_queue
[ac
]);
669 if (vif
->cab_queue
!= IEEE80211_INVAL_HW_QUEUE
)
670 tfd_msk
|= BIT(vif
->cab_queue
);
673 mutex_lock(&mvm
->mutex
);
674 iwl_mvm_flush_tx_path(mvm
, tfd_msk
, true);
675 mutex_unlock(&mvm
->mutex
);
678 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
680 * Flush the ROC worker which will flush the OFFCHANNEL queue.
681 * We assume here that all the packets sent to the OFFCHANNEL
682 * queue are sent in ROC session.
684 flush_work(&mvm
->roc_done_wk
);
687 * By now, all the AC queues are empty. The AGG queues are
688 * empty too. We already got all the Tx responses for all the
689 * packets in the queues. The drain work can have been
690 * triggered. Flush it.
692 flush_work(&mvm
->sta_drained_wk
);
696 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw
*hw
,
697 struct ieee80211_vif
*vif
)
699 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
700 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
702 iwl_mvm_prepare_mac_removal(mvm
, vif
);
704 mutex_lock(&mvm
->mutex
);
706 if (mvm
->bf_allowed_vif
== mvmvif
) {
707 mvm
->bf_allowed_vif
= NULL
;
708 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
709 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
712 iwl_mvm_vif_dbgfs_clean(mvm
, vif
);
715 * For AP/GO interface, the tear down of the resources allocated to the
716 * interface is be handled as part of the stop_ap flow.
718 if (vif
->type
== NL80211_IFTYPE_AP
) {
719 #ifdef CONFIG_NL80211_TESTMODE
720 if (vif
== mvm
->noa_vif
) {
722 mvm
->noa_duration
= 0;
725 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->bcast_sta
);
729 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
730 mvm
->p2p_device_vif
= NULL
;
731 iwl_mvm_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
732 iwl_mvm_binding_remove_vif(mvm
, vif
);
733 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
734 mvmvif
->phy_ctxt
= NULL
;
738 * TODO: remove this temporary code.
739 * Currently MVM FW supports power management only on single MAC.
740 * Check if only one additional interface remains after removing
741 * current one. Update power mode on the remaining interface.
743 if (mvm
->vif_count
&& vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
745 IWL_DEBUG_MAC80211(mvm
, "Currently %d interfaces active\n",
747 if (mvm
->vif_count
== 1) {
748 ieee80211_iterate_active_interfaces(
749 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
750 iwl_mvm_power_update_iterator
, mvm
);
753 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
756 iwl_mvm_mac_ctxt_release(mvm
, vif
);
757 mutex_unlock(&mvm
->mutex
);
760 static int iwl_mvm_set_tx_power(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
763 /* FW is in charge of regulatory enforcement */
764 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd
= {
765 .mac_context_id
= iwl_mvm_vif_from_mac80211(vif
)->id
,
766 .pwr_restriction
= cpu_to_le16(tx_power
),
769 return iwl_mvm_send_cmd_pdu(mvm
, REDUCE_TX_POWER_CMD
, CMD_SYNC
,
770 sizeof(reduce_txpwr_cmd
),
774 static int iwl_mvm_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
779 static void iwl_mvm_configure_filter(struct ieee80211_hw
*hw
,
780 unsigned int changed_flags
,
781 unsigned int *total_flags
,
787 static int iwl_mvm_configure_mcast_filter(struct iwl_mvm
*mvm
,
788 struct ieee80211_vif
*vif
)
790 struct iwl_mcast_filter_cmd mcast_filter_cmd
= {
794 memcpy(mcast_filter_cmd
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
796 return iwl_mvm_send_cmd_pdu(mvm
, MCAST_FILTER_CMD
, CMD_SYNC
,
797 sizeof(mcast_filter_cmd
),
801 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm
*mvm
,
802 struct ieee80211_vif
*vif
,
803 struct ieee80211_bss_conf
*bss_conf
,
806 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
809 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
811 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
813 if (changes
& BSS_CHANGED_ASSOC
) {
814 if (bss_conf
->assoc
) {
815 /* add quota for this interface */
816 ret
= iwl_mvm_update_quotas(mvm
, vif
);
818 IWL_ERR(mvm
, "failed to update quotas\n");
821 iwl_mvm_configure_mcast_filter(mvm
, vif
);
823 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
,
826 * If we're restarting then the firmware will
827 * obviously have lost synchronisation with
828 * the AP. It will attempt to synchronise by
829 * itself, but we can make it more reliable by
830 * scheduling a session protection time event.
832 * The firmware needs to receive a beacon to
833 * catch up with synchronisation, use 110% of
834 * the beacon interval.
836 * Set a large maximum delay to allow for more
837 * than a single interface.
839 u32 dur
= (11 * vif
->bss_conf
.beacon_int
) / 10;
840 iwl_mvm_protect_session(mvm
, vif
, dur
, dur
,
843 } else if (mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
844 /* remove AP station now that the MAC is unassoc */
845 ret
= iwl_mvm_rm_sta_id(mvm
, vif
, mvmvif
->ap_sta_id
);
847 IWL_ERR(mvm
, "failed to remove AP station\n");
848 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
849 /* remove quota for this interface */
850 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
852 IWL_ERR(mvm
, "failed to update quotas\n");
855 /* reset rssi values */
856 mvmvif
->bf_data
.ave_beacon_signal
= 0;
858 if (!(mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_UAPSD
)) {
859 /* Workaround for FW bug, otherwise FW disables device
860 * power save upon disassociation
862 ret
= iwl_mvm_power_update_mode(mvm
, vif
);
864 IWL_ERR(mvm
, "failed to update power mode\n");
866 iwl_mvm_bt_coex_vif_assoc(mvm
, vif
);
867 } else if (changes
& BSS_CHANGED_BEACON_INFO
) {
869 * We received a beacon _after_ association so
870 * remove the session protection.
872 iwl_mvm_remove_time_event(mvm
, mvmvif
,
873 &mvmvif
->time_event_data
);
874 } else if (changes
& (BSS_CHANGED_PS
| BSS_CHANGED_QOS
)) {
875 ret
= iwl_mvm_power_update_mode(mvm
, vif
);
877 IWL_ERR(mvm
, "failed to update power mode\n");
879 if (changes
& BSS_CHANGED_TXPOWER
) {
880 IWL_DEBUG_CALIB(mvm
, "Changing TX Power to %d\n",
882 iwl_mvm_set_tx_power(mvm
, vif
, bss_conf
->txpower
);
885 if (changes
& BSS_CHANGED_CQM
) {
886 IWL_DEBUG_MAC80211(mvm
, "cqm info_changed");
887 /* reset cqm events tracking */
888 mvmvif
->bf_data
.last_cqm_event
= 0;
889 ret
= iwl_mvm_update_beacon_filter(mvm
, vif
);
891 IWL_ERR(mvm
, "failed to update CQM thresholds\n");
895 static int iwl_mvm_start_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
897 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
898 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
901 mutex_lock(&mvm
->mutex
);
903 /* Send the beacon template */
904 ret
= iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
);
908 /* Add the mac context */
909 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
913 /* Perform the binding */
914 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
918 mvmvif
->ap_active
= true;
920 /* Send the bcast station. At this stage the TBTT and DTIM time events
921 * are added and applied to the scheduler */
922 ret
= iwl_mvm_send_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
926 ret
= iwl_mvm_update_quotas(mvm
, vif
);
930 /* Need to update the P2P Device MAC */
931 if (vif
->p2p
&& mvm
->p2p_device_vif
)
932 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
934 mutex_unlock(&mvm
->mutex
);
938 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
940 iwl_mvm_binding_remove_vif(mvm
, vif
);
942 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
944 mutex_unlock(&mvm
->mutex
);
948 static void iwl_mvm_stop_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
950 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
951 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
953 iwl_mvm_prepare_mac_removal(mvm
, vif
);
955 mutex_lock(&mvm
->mutex
);
957 mvmvif
->ap_active
= false;
959 /* Need to update the P2P Device MAC */
960 if (vif
->p2p
&& mvm
->p2p_device_vif
)
961 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
963 iwl_mvm_update_quotas(mvm
, NULL
);
964 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
965 iwl_mvm_binding_remove_vif(mvm
, vif
);
966 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
968 mutex_unlock(&mvm
->mutex
);
971 static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm
*mvm
,
972 struct ieee80211_vif
*vif
,
973 struct ieee80211_bss_conf
*bss_conf
,
976 /* Need to send a new beacon template to the FW */
977 if (changes
& BSS_CHANGED_BEACON
) {
978 if (iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
))
979 IWL_WARN(mvm
, "Failed updating beacon data\n");
983 static void iwl_mvm_bss_info_changed(struct ieee80211_hw
*hw
,
984 struct ieee80211_vif
*vif
,
985 struct ieee80211_bss_conf
*bss_conf
,
988 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
990 mutex_lock(&mvm
->mutex
);
993 case NL80211_IFTYPE_STATION
:
994 iwl_mvm_bss_info_changed_station(mvm
, vif
, bss_conf
, changes
);
996 case NL80211_IFTYPE_AP
:
997 iwl_mvm_bss_info_changed_ap(mvm
, vif
, bss_conf
, changes
);
1000 /* shouldn't happen */
1004 mutex_unlock(&mvm
->mutex
);
1007 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw
*hw
,
1008 struct ieee80211_vif
*vif
,
1009 struct cfg80211_scan_request
*req
)
1011 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1014 if (req
->n_channels
== 0 || req
->n_channels
> MAX_NUM_SCAN_CHANNELS
)
1017 mutex_lock(&mvm
->mutex
);
1019 if (mvm
->scan_status
== IWL_MVM_SCAN_NONE
)
1020 ret
= iwl_mvm_scan_request(mvm
, vif
, req
);
1024 mutex_unlock(&mvm
->mutex
);
1029 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw
*hw
,
1030 struct ieee80211_vif
*vif
)
1032 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1034 mutex_lock(&mvm
->mutex
);
1036 iwl_mvm_cancel_scan(mvm
);
1038 mutex_unlock(&mvm
->mutex
);
1042 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw
*hw
,
1043 struct ieee80211_sta
*sta
, u16 tid
,
1045 enum ieee80211_frame_release_type reason
,
1048 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1050 /* TODO: how do we tell the fw to send frames for a specific TID */
1053 * The fw will send EOSP notification when the last frame will be
1056 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
);
1059 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw
*hw
,
1060 struct ieee80211_vif
*vif
,
1061 enum sta_notify_cmd cmd
,
1062 struct ieee80211_sta
*sta
)
1064 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1065 struct iwl_mvm_sta
*mvmsta
= (void *)sta
->drv_priv
;
1068 case STA_NOTIFY_SLEEP
:
1069 if (atomic_read(&mvm
->pending_frames
[mvmsta
->sta_id
]) > 0)
1070 ieee80211_sta_block_awake(hw
, sta
, true);
1072 * The fw updates the STA to be asleep. Tx packets on the Tx
1073 * queues to this station will not be transmitted. The fw will
1074 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1077 case STA_NOTIFY_AWAKE
:
1078 if (WARN_ON(mvmsta
->sta_id
== IWL_MVM_STATION_COUNT
))
1080 iwl_mvm_sta_modify_ps_wake(mvm
, sta
);
1087 static int iwl_mvm_mac_sta_state(struct ieee80211_hw
*hw
,
1088 struct ieee80211_vif
*vif
,
1089 struct ieee80211_sta
*sta
,
1090 enum ieee80211_sta_state old_state
,
1091 enum ieee80211_sta_state new_state
)
1093 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1094 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1097 IWL_DEBUG_MAC80211(mvm
, "station %pM state change %d->%d\n",
1098 sta
->addr
, old_state
, new_state
);
1100 /* this would be a mac80211 bug ... but don't crash */
1101 if (WARN_ON_ONCE(!mvmvif
->phy_ctxt
))
1104 /* if a STA is being removed, reuse its ID */
1105 flush_work(&mvm
->sta_drained_wk
);
1107 mutex_lock(&mvm
->mutex
);
1108 if (old_state
== IEEE80211_STA_NOTEXIST
&&
1109 new_state
== IEEE80211_STA_NONE
) {
1111 * Firmware bug - it'll crash if the beacon interval is less
1112 * than 16. We can't avoid connecting at all, so refuse the
1113 * station state change, this will cause mac80211 to abandon
1114 * attempts to connect to this AP, and eventually wpa_s will
1115 * blacklist the AP...
1117 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1118 vif
->bss_conf
.beacon_int
< 16) {
1120 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1121 sta
->addr
, vif
->bss_conf
.beacon_int
);
1125 ret
= iwl_mvm_add_sta(mvm
, vif
, sta
);
1126 } else if (old_state
== IEEE80211_STA_NONE
&&
1127 new_state
== IEEE80211_STA_AUTH
) {
1129 } else if (old_state
== IEEE80211_STA_AUTH
&&
1130 new_state
== IEEE80211_STA_ASSOC
) {
1131 ret
= iwl_mvm_update_sta(mvm
, vif
, sta
);
1133 iwl_mvm_rs_rate_init(mvm
, sta
,
1134 mvmvif
->phy_ctxt
->channel
->band
);
1135 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1136 new_state
== IEEE80211_STA_AUTHORIZED
) {
1137 /* enable beacon filtering */
1138 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
));
1140 } else if (old_state
== IEEE80211_STA_AUTHORIZED
&&
1141 new_state
== IEEE80211_STA_ASSOC
) {
1142 /* disable beacon filtering */
1143 WARN_ON(iwl_mvm_disable_beacon_filter(mvm
, vif
));
1145 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1146 new_state
== IEEE80211_STA_AUTH
) {
1148 } else if (old_state
== IEEE80211_STA_AUTH
&&
1149 new_state
== IEEE80211_STA_NONE
) {
1151 } else if (old_state
== IEEE80211_STA_NONE
&&
1152 new_state
== IEEE80211_STA_NOTEXIST
) {
1153 ret
= iwl_mvm_rm_sta(mvm
, vif
, sta
);
1158 mutex_unlock(&mvm
->mutex
);
1163 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1165 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1167 mvm
->rts_threshold
= value
;
1172 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw
*hw
,
1173 struct ieee80211_vif
*vif
, u16 ac
,
1174 const struct ieee80211_tx_queue_params
*params
)
1176 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1177 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1179 mvmvif
->queue_params
[ac
] = *params
;
1182 * No need to update right away, we'll get BSS_CHANGED_QOS
1183 * The exception is P2P_DEVICE interface which needs immediate update.
1185 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1188 mutex_lock(&mvm
->mutex
);
1189 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
1190 mutex_unlock(&mvm
->mutex
);
1196 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw
*hw
,
1197 struct ieee80211_vif
*vif
)
1199 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1200 u32 duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS
,
1201 200 + vif
->bss_conf
.beacon_int
);
1202 u32 min_duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS
,
1203 100 + vif
->bss_conf
.beacon_int
);
1205 if (WARN_ON_ONCE(vif
->bss_conf
.assoc
))
1208 mutex_lock(&mvm
->mutex
);
1209 /* Try really hard to protect the session and hear a beacon */
1210 iwl_mvm_protect_session(mvm
, vif
, duration
, min_duration
, 500);
1211 mutex_unlock(&mvm
->mutex
);
1214 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw
*hw
,
1215 struct ieee80211_vif
*vif
,
1216 struct cfg80211_sched_scan_request
*req
,
1217 struct ieee80211_sched_scan_ies
*ies
)
1219 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1222 mutex_lock(&mvm
->mutex
);
1224 if (mvm
->scan_status
!= IWL_MVM_SCAN_NONE
) {
1226 "SCHED SCAN request during internal scan - abort\n");
1231 mvm
->scan_status
= IWL_MVM_SCAN_SCHED
;
1233 ret
= iwl_mvm_config_sched_scan(mvm
, vif
, req
, ies
);
1237 ret
= iwl_mvm_config_sched_scan_profiles(mvm
, req
);
1241 ret
= iwl_mvm_sched_scan_start(mvm
, req
);
1245 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
1247 mutex_unlock(&mvm
->mutex
);
1251 static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw
*hw
,
1252 struct ieee80211_vif
*vif
)
1254 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1256 mutex_lock(&mvm
->mutex
);
1257 iwl_mvm_sched_scan_stop(mvm
);
1258 mutex_unlock(&mvm
->mutex
);
1261 static int iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
1262 enum set_key_cmd cmd
,
1263 struct ieee80211_vif
*vif
,
1264 struct ieee80211_sta
*sta
,
1265 struct ieee80211_key_conf
*key
)
1267 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1270 if (iwlwifi_mod_params
.sw_crypto
) {
1271 IWL_DEBUG_MAC80211(mvm
, "leave - hwcrypto disabled\n");
1275 switch (key
->cipher
) {
1276 case WLAN_CIPHER_SUITE_TKIP
:
1277 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1279 case WLAN_CIPHER_SUITE_CCMP
:
1280 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1282 case WLAN_CIPHER_SUITE_AES_CMAC
:
1283 WARN_ON_ONCE(!(hw
->flags
& IEEE80211_HW_MFP_CAPABLE
));
1285 case WLAN_CIPHER_SUITE_WEP40
:
1286 case WLAN_CIPHER_SUITE_WEP104
:
1288 * Support for TX only, at least for now, so accept
1289 * the key and do nothing else. Then mac80211 will
1290 * pass it for TX but we don't have to use it for RX.
1297 mutex_lock(&mvm
->mutex
);
1301 if (vif
->type
== NL80211_IFTYPE_AP
&& !sta
) {
1302 /* GTK on AP interface is a TX-only key, return 0 */
1304 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1308 IWL_DEBUG_MAC80211(mvm
, "set hwcrypto key\n");
1309 ret
= iwl_mvm_set_sta_key(mvm
, vif
, sta
, key
, false);
1311 IWL_WARN(mvm
, "set key failed\n");
1313 * can't add key for RX, but we don't need it
1314 * in the device for TX so still return 0
1316 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1322 if (key
->hw_key_idx
== STA_KEY_IDX_INVALID
) {
1327 IWL_DEBUG_MAC80211(mvm
, "disable hwcrypto key\n");
1328 ret
= iwl_mvm_remove_sta_key(mvm
, vif
, sta
, key
);
1334 mutex_unlock(&mvm
->mutex
);
1338 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw
*hw
,
1339 struct ieee80211_vif
*vif
,
1340 struct ieee80211_key_conf
*keyconf
,
1341 struct ieee80211_sta
*sta
,
1342 u32 iv32
, u16
*phase1key
)
1344 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1346 iwl_mvm_update_tkip_key(mvm
, vif
, keyconf
, sta
, iv32
, phase1key
);
1350 static int iwl_mvm_roc(struct ieee80211_hw
*hw
,
1351 struct ieee80211_vif
*vif
,
1352 struct ieee80211_channel
*channel
,
1354 enum ieee80211_roc_type type
)
1356 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1357 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1358 struct cfg80211_chan_def chandef
;
1359 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1362 IWL_DEBUG_MAC80211(mvm
, "enter (%d, %d, %d)\n", channel
->hw_value
,
1365 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
) {
1366 IWL_ERR(mvm
, "vif isn't a P2P_DEVICE: %d\n", vif
->type
);
1370 mutex_lock(&mvm
->mutex
);
1372 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
1373 phy_ctxt
= &mvm
->phy_ctxts
[i
];
1374 if (phy_ctxt
->ref
== 0 || mvmvif
->phy_ctxt
== phy_ctxt
)
1377 if (phy_ctxt
->ref
&& channel
== phy_ctxt
->channel
) {
1379 * Unbind the P2P_DEVICE from the current PHY context,
1380 * and if the PHY context is not used remove it.
1382 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1383 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1386 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1388 /* Bind the P2P_DEVICE to the current PHY Context */
1389 mvmvif
->phy_ctxt
= phy_ctxt
;
1391 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1392 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1395 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1396 goto schedule_time_event
;
1400 /* Need to update the PHY context only if the ROC channel changed */
1401 if (channel
== mvmvif
->phy_ctxt
->channel
)
1402 goto schedule_time_event
;
1404 cfg80211_chandef_create(&chandef
, channel
, NL80211_CHAN_NO_HT
);
1407 * Change the PHY context configuration as it is currently referenced
1408 * only by the P2P Device MAC
1410 if (mvmvif
->phy_ctxt
->ref
== 1) {
1411 ret
= iwl_mvm_phy_ctxt_changed(mvm
, mvmvif
->phy_ctxt
,
1417 * The PHY context is shared with other MACs. Need to remove the
1418 * P2P Device from the binding, allocate an new PHY context and
1419 * create a new binding
1421 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1427 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &chandef
,
1430 IWL_ERR(mvm
, "Failed to change PHY context\n");
1434 /* Unbind the P2P_DEVICE from the current PHY context */
1435 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1436 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1439 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1441 /* Bind the P2P_DEVICE to the new allocated PHY context */
1442 mvmvif
->phy_ctxt
= phy_ctxt
;
1444 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1445 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1448 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1451 schedule_time_event
:
1452 /* Schedule the time events */
1453 ret
= iwl_mvm_start_p2p_roc(mvm
, vif
, duration
, type
);
1456 mutex_unlock(&mvm
->mutex
);
1457 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1461 static int iwl_mvm_cancel_roc(struct ieee80211_hw
*hw
)
1463 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1465 IWL_DEBUG_MAC80211(mvm
, "enter\n");
1467 mutex_lock(&mvm
->mutex
);
1468 iwl_mvm_stop_p2p_roc(mvm
);
1469 mutex_unlock(&mvm
->mutex
);
1471 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1475 static int iwl_mvm_add_chanctx(struct ieee80211_hw
*hw
,
1476 struct ieee80211_chanctx_conf
*ctx
)
1478 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1479 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1480 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1483 IWL_DEBUG_MAC80211(mvm
, "Add channel context\n");
1485 mutex_lock(&mvm
->mutex
);
1486 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1492 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->def
,
1493 ctx
->rx_chains_static
,
1494 ctx
->rx_chains_dynamic
);
1496 IWL_ERR(mvm
, "Failed to add PHY context\n");
1500 iwl_mvm_phy_ctxt_ref(mvm
, phy_ctxt
);
1501 *phy_ctxt_id
= phy_ctxt
->id
;
1503 mutex_unlock(&mvm
->mutex
);
1507 static void iwl_mvm_remove_chanctx(struct ieee80211_hw
*hw
,
1508 struct ieee80211_chanctx_conf
*ctx
)
1510 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1511 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1512 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1514 mutex_lock(&mvm
->mutex
);
1515 iwl_mvm_phy_ctxt_unref(mvm
, phy_ctxt
);
1516 mutex_unlock(&mvm
->mutex
);
1519 static void iwl_mvm_change_chanctx(struct ieee80211_hw
*hw
,
1520 struct ieee80211_chanctx_conf
*ctx
,
1523 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1524 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1525 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1527 if (WARN_ONCE((phy_ctxt
->ref
> 1) &&
1528 (changed
& ~(IEEE80211_CHANCTX_CHANGE_WIDTH
|
1529 IEEE80211_CHANCTX_CHANGE_RX_CHAINS
|
1530 IEEE80211_CHANCTX_CHANGE_RADAR
)),
1531 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1532 phy_ctxt
->ref
, changed
))
1535 mutex_lock(&mvm
->mutex
);
1536 iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->def
,
1537 ctx
->rx_chains_static
,
1538 ctx
->rx_chains_dynamic
);
1539 mutex_unlock(&mvm
->mutex
);
1542 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw
*hw
,
1543 struct ieee80211_vif
*vif
,
1544 struct ieee80211_chanctx_conf
*ctx
)
1546 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1547 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1548 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1549 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1552 mutex_lock(&mvm
->mutex
);
1554 mvmvif
->phy_ctxt
= phy_ctxt
;
1556 switch (vif
->type
) {
1557 case NL80211_IFTYPE_AP
:
1559 * The AP binding flow is handled as part of the start_ap flow
1560 * (in bss_info_changed).
1564 case NL80211_IFTYPE_STATION
:
1565 case NL80211_IFTYPE_ADHOC
:
1566 case NL80211_IFTYPE_MONITOR
:
1573 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1578 * Setting the quota at this stage is only required for monitor
1579 * interfaces. For the other types, the bss_info changed flow
1580 * will handle quota settings.
1582 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
1583 mvmvif
->monitor_active
= true;
1584 ret
= iwl_mvm_update_quotas(mvm
, vif
);
1586 goto out_remove_binding
;
1592 iwl_mvm_binding_remove_vif(mvm
, vif
);
1594 mutex_unlock(&mvm
->mutex
);
1596 mvmvif
->phy_ctxt
= NULL
;
1600 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
1601 struct ieee80211_vif
*vif
,
1602 struct ieee80211_chanctx_conf
*ctx
)
1604 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1605 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1607 mutex_lock(&mvm
->mutex
);
1609 iwl_mvm_remove_time_event(mvm
, mvmvif
, &mvmvif
->time_event_data
);
1611 if (vif
->type
== NL80211_IFTYPE_AP
)
1614 switch (vif
->type
) {
1615 case NL80211_IFTYPE_MONITOR
:
1616 mvmvif
->monitor_active
= false;
1617 iwl_mvm_update_quotas(mvm
, NULL
);
1623 iwl_mvm_binding_remove_vif(mvm
, vif
);
1625 mvmvif
->phy_ctxt
= NULL
;
1626 mutex_unlock(&mvm
->mutex
);
1629 static int iwl_mvm_set_tim(struct ieee80211_hw
*hw
,
1630 struct ieee80211_sta
*sta
,
1633 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1634 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
1636 if (!mvm_sta
|| !mvm_sta
->vif
) {
1637 IWL_ERR(mvm
, "Station is not associated to a vif\n");
1641 return iwl_mvm_mac_ctxt_beacon_changed(mvm
, mvm_sta
->vif
);
1644 #ifdef CONFIG_NL80211_TESTMODE
1645 static const struct nla_policy iwl_mvm_tm_policy
[IWL_MVM_TM_ATTR_MAX
+ 1] = {
1646 [IWL_MVM_TM_ATTR_CMD
] = { .type
= NLA_U32
},
1647 [IWL_MVM_TM_ATTR_NOA_DURATION
] = { .type
= NLA_U32
},
1648 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
] = { .type
= NLA_U32
},
1651 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm
*mvm
,
1652 struct ieee80211_vif
*vif
,
1653 void *data
, int len
)
1655 struct nlattr
*tb
[IWL_MVM_TM_ATTR_MAX
+ 1];
1659 err
= nla_parse(tb
, IWL_MVM_TM_ATTR_MAX
, data
, len
, iwl_mvm_tm_policy
);
1663 if (!tb
[IWL_MVM_TM_ATTR_CMD
])
1666 switch (nla_get_u32(tb
[IWL_MVM_TM_ATTR_CMD
])) {
1667 case IWL_MVM_TM_CMD_SET_NOA
:
1668 if (!vif
|| vif
->type
!= NL80211_IFTYPE_AP
|| !vif
->p2p
||
1669 !vif
->bss_conf
.enable_beacon
||
1670 !tb
[IWL_MVM_TM_ATTR_NOA_DURATION
])
1673 noa_duration
= nla_get_u32(tb
[IWL_MVM_TM_ATTR_NOA_DURATION
]);
1674 if (noa_duration
>= vif
->bss_conf
.beacon_int
)
1677 mvm
->noa_duration
= noa_duration
;
1680 return iwl_mvm_update_quotas(mvm
, NULL
);
1681 case IWL_MVM_TM_CMD_SET_BEACON_FILTER
:
1682 /* must be associated client vif - ignore authorized */
1683 if (!vif
|| vif
->type
!= NL80211_IFTYPE_STATION
||
1684 !vif
->bss_conf
.assoc
|| !vif
->bss_conf
.dtim_period
||
1685 !tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
])
1688 if (nla_get_u32(tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
]))
1689 return iwl_mvm_enable_beacon_filter(mvm
, vif
);
1690 return iwl_mvm_disable_beacon_filter(mvm
, vif
);
1696 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw
*hw
,
1697 struct ieee80211_vif
*vif
,
1698 void *data
, int len
)
1700 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1703 mutex_lock(&mvm
->mutex
);
1704 err
= __iwl_mvm_mac_testmode_cmd(mvm
, vif
, data
, len
);
1705 mutex_unlock(&mvm
->mutex
);
1711 struct ieee80211_ops iwl_mvm_hw_ops
= {
1712 .tx
= iwl_mvm_mac_tx
,
1713 .ampdu_action
= iwl_mvm_mac_ampdu_action
,
1714 .start
= iwl_mvm_mac_start
,
1715 .restart_complete
= iwl_mvm_mac_restart_complete
,
1716 .stop
= iwl_mvm_mac_stop
,
1717 .add_interface
= iwl_mvm_mac_add_interface
,
1718 .remove_interface
= iwl_mvm_mac_remove_interface
,
1719 .config
= iwl_mvm_mac_config
,
1720 .configure_filter
= iwl_mvm_configure_filter
,
1721 .bss_info_changed
= iwl_mvm_bss_info_changed
,
1722 .hw_scan
= iwl_mvm_mac_hw_scan
,
1723 .cancel_hw_scan
= iwl_mvm_mac_cancel_hw_scan
,
1724 .sta_state
= iwl_mvm_mac_sta_state
,
1725 .sta_notify
= iwl_mvm_mac_sta_notify
,
1726 .allow_buffered_frames
= iwl_mvm_mac_allow_buffered_frames
,
1727 .set_rts_threshold
= iwl_mvm_mac_set_rts_threshold
,
1728 .conf_tx
= iwl_mvm_mac_conf_tx
,
1729 .mgd_prepare_tx
= iwl_mvm_mac_mgd_prepare_tx
,
1730 .sched_scan_start
= iwl_mvm_mac_sched_scan_start
,
1731 .sched_scan_stop
= iwl_mvm_mac_sched_scan_stop
,
1732 .set_key
= iwl_mvm_mac_set_key
,
1733 .update_tkip_key
= iwl_mvm_mac_update_tkip_key
,
1734 .remain_on_channel
= iwl_mvm_roc
,
1735 .cancel_remain_on_channel
= iwl_mvm_cancel_roc
,
1736 .add_chanctx
= iwl_mvm_add_chanctx
,
1737 .remove_chanctx
= iwl_mvm_remove_chanctx
,
1738 .change_chanctx
= iwl_mvm_change_chanctx
,
1739 .assign_vif_chanctx
= iwl_mvm_assign_vif_chanctx
,
1740 .unassign_vif_chanctx
= iwl_mvm_unassign_vif_chanctx
,
1742 .start_ap
= iwl_mvm_start_ap
,
1743 .stop_ap
= iwl_mvm_stop_ap
,
1745 .set_tim
= iwl_mvm_set_tim
,
1747 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd
)
1749 #ifdef CONFIG_PM_SLEEP
1751 .suspend
= iwl_mvm_suspend
,
1752 .resume
= iwl_mvm_resume
,
1753 .set_wakeup
= iwl_mvm_set_wakeup
,
1754 .set_rekey_data
= iwl_mvm_set_rekey_data
,
1755 #if IS_ENABLED(CONFIG_IPV6)
1756 .ipv6_addr_change
= iwl_mvm_ipv6_addr_change
,
1758 .set_default_unicast_key
= iwl_mvm_set_default_unicast_key
,