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
;
169 hw
->queues
= mvm
->first_agg_queue
;
170 hw
->offchannel_tx_hw_queue
= IWL_MVM_OFFCHANNEL_QUEUE
;
171 hw
->rate_control_algorithm
= "iwl-mvm-rs";
174 * Enable 11w if advertised by firmware and software crypto
175 * is not enabled (as the firmware will interpret some mgmt
176 * packets, so enabling it with software crypto isn't safe)
178 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_MFP
&&
179 !iwlwifi_mod_params
.sw_crypto
)
180 hw
->flags
|= IEEE80211_HW_MFP_CAPABLE
;
182 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT
) {
183 hw
->flags
|= IEEE80211_HW_SUPPORTS_UAPSD
;
184 hw
->uapsd_queues
= IWL_UAPSD_AC_INFO
;
185 hw
->uapsd_max_sp_len
= IWL_UAPSD_MAX_SP
;
188 hw
->sta_data_size
= sizeof(struct iwl_mvm_sta
);
189 hw
->vif_data_size
= sizeof(struct iwl_mvm_vif
);
190 hw
->chanctx_data_size
= sizeof(u16
);
192 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
193 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
194 BIT(NL80211_IFTYPE_AP
) |
195 BIT(NL80211_IFTYPE_P2P_GO
) |
196 BIT(NL80211_IFTYPE_P2P_DEVICE
);
198 /* IBSS has bugs in older versions */
199 if (IWL_UCODE_API(mvm
->fw
->ucode_ver
) >= 8)
200 hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
202 hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
203 hw
->wiphy
->regulatory_flags
|= REGULATORY_CUSTOM_REG
|
204 REGULATORY_DISABLE_BEACON_HINTS
;
206 hw
->wiphy
->iface_combinations
= iwl_mvm_iface_combinations
;
207 hw
->wiphy
->n_iface_combinations
=
208 ARRAY_SIZE(iwl_mvm_iface_combinations
);
210 hw
->wiphy
->max_remain_on_channel_duration
= 10000;
211 hw
->max_listen_interval
= IWL_CONN_MAX_LISTEN_INTERVAL
;
213 /* Extract MAC address */
214 memcpy(mvm
->addresses
[0].addr
, mvm
->nvm_data
->hw_addr
, ETH_ALEN
);
215 hw
->wiphy
->addresses
= mvm
->addresses
;
216 hw
->wiphy
->n_addresses
= 1;
218 /* Extract additional MAC addresses if available */
219 num_mac
= (mvm
->nvm_data
->n_hw_addrs
> 1) ?
220 min(IWL_MVM_MAX_ADDRESSES
, mvm
->nvm_data
->n_hw_addrs
) : 1;
222 for (i
= 1; i
< num_mac
; i
++) {
223 memcpy(mvm
->addresses
[i
].addr
, mvm
->addresses
[i
-1].addr
,
225 mvm
->addresses
[i
].addr
[5]++;
226 hw
->wiphy
->n_addresses
++;
229 iwl_mvm_reset_phy_ctxts(mvm
);
231 hw
->wiphy
->max_scan_ie_len
= iwl_mvm_max_scan_ie_len(mvm
);
233 hw
->wiphy
->max_scan_ssids
= PROBE_OPTION_MAX
;
235 if (mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
236 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
237 &mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
];
238 if (mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
239 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
240 &mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
];
242 hw
->wiphy
->hw_version
= mvm
->trans
->hw_id
;
244 if (iwlmvm_mod_params
.power_scheme
!= IWL_POWER_SCHEME_CAM
)
245 hw
->wiphy
->flags
|= WIPHY_FLAG_PS_ON_BY_DEFAULT
;
247 hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
249 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_SCHED_SCAN
) {
250 hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_SCHED_SCAN
;
251 hw
->wiphy
->max_sched_scan_ssids
= PROBE_OPTION_MAX
;
252 hw
->wiphy
->max_match_sets
= IWL_SCAN_MAX_PROFILES
;
253 /* we create the 802.11 header and zero length SSID IE. */
254 hw
->wiphy
->max_sched_scan_ie_len
=
255 SCAN_OFFLOAD_PROBE_REQ_SIZE
- 24 - 2;
258 hw
->wiphy
->features
|= NL80211_FEATURE_P2P_GO_CTWIN
|
259 NL80211_FEATURE_P2P_GO_OPPPS
|
260 NL80211_FEATURE_LOW_PRIORITY_SCAN
;
262 mvm
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
264 /* currently FW API supports only one optional cipher scheme */
265 if (mvm
->fw
->cs
&& mvm
->fw
->cs
->cipher
) {
266 mvm
->hw
->n_cipher_schemes
= 1;
267 mvm
->hw
->cipher_schemes
= mvm
->fw
->cs
;
270 #ifdef CONFIG_PM_SLEEP
271 if (mvm
->fw
->img
[IWL_UCODE_WOWLAN
].sec
[0].len
&&
272 mvm
->trans
->ops
->d3_suspend
&&
273 mvm
->trans
->ops
->d3_resume
&&
274 device_can_wakeup(mvm
->trans
->dev
)) {
275 mvm
->wowlan
.flags
= WIPHY_WOWLAN_MAGIC_PKT
|
276 WIPHY_WOWLAN_DISCONNECT
|
277 WIPHY_WOWLAN_EAP_IDENTITY_REQ
|
278 WIPHY_WOWLAN_RFKILL_RELEASE
;
279 if (!iwlwifi_mod_params
.sw_crypto
)
280 mvm
->wowlan
.flags
|= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
|
281 WIPHY_WOWLAN_GTK_REKEY_FAILURE
|
282 WIPHY_WOWLAN_4WAY_HANDSHAKE
;
284 mvm
->wowlan
.n_patterns
= IWL_WOWLAN_MAX_PATTERNS
;
285 mvm
->wowlan
.pattern_min_len
= IWL_WOWLAN_MIN_PATTERN_LEN
;
286 mvm
->wowlan
.pattern_max_len
= IWL_WOWLAN_MAX_PATTERN_LEN
;
287 mvm
->wowlan
.tcp
= &iwl_mvm_wowlan_tcp_support
;
288 hw
->wiphy
->wowlan
= &mvm
->wowlan
;
292 ret
= iwl_mvm_leds_init(mvm
);
296 ret
= ieee80211_register_hw(mvm
->hw
);
298 iwl_mvm_leds_exit(mvm
);
303 static void iwl_mvm_mac_tx(struct ieee80211_hw
*hw
,
304 struct ieee80211_tx_control
*control
,
307 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
309 if (iwl_mvm_is_radio_killed(mvm
)) {
310 IWL_DEBUG_DROP(mvm
, "Dropping - RF/CT KILL\n");
314 if (IEEE80211_SKB_CB(skb
)->hw_queue
== IWL_MVM_OFFCHANNEL_QUEUE
&&
315 !test_bit(IWL_MVM_STATUS_ROC_RUNNING
, &mvm
->status
))
319 if (iwl_mvm_tx_skb(mvm
, skb
, control
->sta
))
324 if (iwl_mvm_tx_skb_non_sta(mvm
, skb
))
328 ieee80211_free_txskb(hw
, skb
);
331 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw
*hw
,
332 struct ieee80211_vif
*vif
,
333 enum ieee80211_ampdu_mlme_action action
,
334 struct ieee80211_sta
*sta
, u16 tid
,
335 u16
*ssn
, u8 buf_size
)
337 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
340 IWL_DEBUG_HT(mvm
, "A-MPDU action on addr %pM tid %d: action %d\n",
341 sta
->addr
, tid
, action
);
343 if (!(mvm
->nvm_data
->sku_cap_11n_enable
))
346 mutex_lock(&mvm
->mutex
);
349 case IEEE80211_AMPDU_RX_START
:
350 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_RXAGG
) {
354 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, *ssn
, true);
356 case IEEE80211_AMPDU_RX_STOP
:
357 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, 0, false);
359 case IEEE80211_AMPDU_TX_START
:
360 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_TXAGG
) {
364 ret
= iwl_mvm_sta_tx_agg_start(mvm
, vif
, sta
, tid
, ssn
);
366 case IEEE80211_AMPDU_TX_STOP_CONT
:
367 ret
= iwl_mvm_sta_tx_agg_stop(mvm
, vif
, sta
, tid
);
369 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
370 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
371 ret
= iwl_mvm_sta_tx_agg_flush(mvm
, vif
, sta
, tid
);
373 case IEEE80211_AMPDU_TX_OPERATIONAL
:
374 ret
= iwl_mvm_sta_tx_agg_oper(mvm
, vif
, sta
, tid
, buf_size
);
381 mutex_unlock(&mvm
->mutex
);
386 static void iwl_mvm_cleanup_iterator(void *data
, u8
*mac
,
387 struct ieee80211_vif
*vif
)
389 struct iwl_mvm
*mvm
= data
;
390 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
392 mvmvif
->uploaded
= false;
393 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
395 /* does this make sense at all? */
398 spin_lock_bh(&mvm
->time_event_lock
);
399 iwl_mvm_te_clear_data(mvm
, &mvmvif
->time_event_data
);
400 spin_unlock_bh(&mvm
->time_event_lock
);
402 mvmvif
->phy_ctxt
= NULL
;
405 static void iwl_mvm_restart_cleanup(struct iwl_mvm
*mvm
)
407 iwl_trans_stop_device(mvm
->trans
);
408 iwl_trans_stop_hw(mvm
->trans
, false);
410 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
412 /* just in case one was running */
413 ieee80211_remain_on_channel_expired(mvm
->hw
);
415 ieee80211_iterate_active_interfaces_atomic(
416 mvm
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
417 iwl_mvm_cleanup_iterator
, mvm
);
419 mvm
->p2p_device_vif
= NULL
;
421 iwl_mvm_reset_phy_ctxts(mvm
);
422 memset(mvm
->fw_key_table
, 0, sizeof(mvm
->fw_key_table
));
423 memset(mvm
->sta_drained
, 0, sizeof(mvm
->sta_drained
));
425 ieee80211_wake_queues(mvm
->hw
);
428 mvm
->rx_ba_sessions
= 0;
431 static int iwl_mvm_mac_start(struct ieee80211_hw
*hw
)
433 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
436 mutex_lock(&mvm
->mutex
);
438 /* Clean up some internal and mac80211 state on restart */
439 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
440 iwl_mvm_restart_cleanup(mvm
);
442 ret
= iwl_mvm_up(mvm
);
443 mutex_unlock(&mvm
->mutex
);
448 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw
*hw
)
450 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
453 mutex_lock(&mvm
->mutex
);
455 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
456 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
458 IWL_ERR(mvm
, "Failed to update quotas after restart (%d)\n",
461 mutex_unlock(&mvm
->mutex
);
464 static void iwl_mvm_mac_stop(struct ieee80211_hw
*hw
)
466 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
468 flush_work(&mvm
->async_handlers_wk
);
470 mutex_lock(&mvm
->mutex
);
471 /* async_handlers_wk is now blocked */
474 * The work item could be running or queued if the
475 * ROC time event stops just as we get here.
477 cancel_work_sync(&mvm
->roc_done_wk
);
479 iwl_trans_stop_device(mvm
->trans
);
480 iwl_trans_stop_hw(mvm
->trans
, false);
482 iwl_mvm_async_handlers_purge(mvm
);
483 /* async_handlers_list is empty and will stay empty: HW is stopped */
485 /* the fw is stopped, the aux sta is dead: clean up driver state */
486 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
488 mutex_unlock(&mvm
->mutex
);
491 * The worker might have been waiting for the mutex, let it run and
492 * discover that its list is now empty.
494 cancel_work_sync(&mvm
->async_handlers_wk
);
497 static void iwl_mvm_power_update_iterator(void *data
, u8
*mac
,
498 struct ieee80211_vif
*vif
)
500 struct iwl_mvm
*mvm
= data
;
502 iwl_mvm_power_update_mode(mvm
, vif
);
505 static struct iwl_mvm_phy_ctxt
*iwl_mvm_get_free_phy_ctxt(struct iwl_mvm
*mvm
)
509 lockdep_assert_held(&mvm
->mutex
);
511 for (i
= 0; i
< NUM_PHY_CTX
; i
++)
512 if (!mvm
->phy_ctxts
[i
].ref
)
513 return &mvm
->phy_ctxts
[i
];
515 IWL_ERR(mvm
, "No available PHY context\n");
519 static int iwl_mvm_mac_add_interface(struct ieee80211_hw
*hw
,
520 struct ieee80211_vif
*vif
)
522 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
523 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
527 * Not much to do here. The stack will not allow interface
528 * types or combinations that we didn't advertise, so we
529 * don't really have to check the types.
532 mutex_lock(&mvm
->mutex
);
534 /* Allocate resources for the MAC context, and add it to the fw */
535 ret
= iwl_mvm_mac_ctxt_init(mvm
, vif
);
539 /* Counting number of interfaces is needed for legacy PM */
540 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
544 * The AP binding flow can be done only after the beacon
545 * template is configured (which happens only in the mac80211
546 * start_ap() flow), and adding the broadcast station can happen
547 * only after the binding.
548 * In addition, since modifying the MAC before adding a bcast
549 * station is not allowed by the FW, delay the adding of MAC context to
550 * the point where we can also add the bcast station.
551 * In short: there's not much we can do at this point, other than
552 * allocating resources :)
554 if (vif
->type
== NL80211_IFTYPE_AP
||
555 vif
->type
== NL80211_IFTYPE_ADHOC
) {
556 u32 qmask
= iwl_mvm_mac_get_queues_mask(mvm
, vif
);
557 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->bcast_sta
,
560 IWL_ERR(mvm
, "Failed to allocate bcast sta\n");
564 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
568 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
572 iwl_mvm_power_disable(mvm
, vif
);
574 /* beacon filtering */
575 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
);
579 if (!mvm
->bf_allowed_vif
&&
580 vif
->type
== NL80211_IFTYPE_STATION
&& !vif
->p2p
&&
581 mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BF_UPDATED
){
582 mvm
->bf_allowed_vif
= mvmvif
;
583 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
584 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
588 * P2P_DEVICE interface does not have a channel context assigned to it,
589 * so a dedicated PHY context is allocated to it and the corresponding
590 * MAC context is bound to it at this stage.
592 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
594 mvmvif
->phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
595 if (!mvmvif
->phy_ctxt
) {
600 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
601 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
605 ret
= iwl_mvm_add_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
609 /* Save a pointer to p2p device vif, so it can later be used to
610 * update the p2p device MAC when a GO is started/stopped */
611 mvm
->p2p_device_vif
= vif
;
614 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
618 iwl_mvm_binding_remove_vif(mvm
, vif
);
620 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
622 if (mvm
->bf_allowed_vif
== mvmvif
) {
623 mvm
->bf_allowed_vif
= NULL
;
624 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
625 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
628 mvmvif
->phy_ctxt
= NULL
;
629 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
631 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
634 /* TODO: remove this when legacy PM will be discarded */
635 ieee80211_iterate_active_interfaces(
636 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
637 iwl_mvm_power_update_iterator
, mvm
);
639 iwl_mvm_mac_ctxt_release(mvm
, vif
);
641 mutex_unlock(&mvm
->mutex
);
646 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm
*mvm
,
647 struct ieee80211_vif
*vif
)
651 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
652 if (vif
->hw_queue
[ac
] != IEEE80211_INVAL_HW_QUEUE
)
653 tfd_msk
|= BIT(vif
->hw_queue
[ac
]);
655 if (vif
->cab_queue
!= IEEE80211_INVAL_HW_QUEUE
)
656 tfd_msk
|= BIT(vif
->cab_queue
);
659 mutex_lock(&mvm
->mutex
);
660 iwl_mvm_flush_tx_path(mvm
, tfd_msk
, true);
661 mutex_unlock(&mvm
->mutex
);
664 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
666 * Flush the ROC worker which will flush the OFFCHANNEL queue.
667 * We assume here that all the packets sent to the OFFCHANNEL
668 * queue are sent in ROC session.
670 flush_work(&mvm
->roc_done_wk
);
673 * By now, all the AC queues are empty. The AGG queues are
674 * empty too. We already got all the Tx responses for all the
675 * packets in the queues. The drain work can have been
676 * triggered. Flush it.
678 flush_work(&mvm
->sta_drained_wk
);
682 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw
*hw
,
683 struct ieee80211_vif
*vif
)
685 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
686 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
688 iwl_mvm_prepare_mac_removal(mvm
, vif
);
690 mutex_lock(&mvm
->mutex
);
692 if (mvm
->bf_allowed_vif
== mvmvif
) {
693 mvm
->bf_allowed_vif
= NULL
;
694 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
695 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
698 iwl_mvm_vif_dbgfs_clean(mvm
, vif
);
701 * For AP/GO interface, the tear down of the resources allocated to the
702 * interface is be handled as part of the stop_ap flow.
704 if (vif
->type
== NL80211_IFTYPE_AP
||
705 vif
->type
== NL80211_IFTYPE_ADHOC
) {
706 #ifdef CONFIG_NL80211_TESTMODE
707 if (vif
== mvm
->noa_vif
) {
709 mvm
->noa_duration
= 0;
712 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->bcast_sta
);
716 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
717 mvm
->p2p_device_vif
= NULL
;
718 iwl_mvm_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
719 iwl_mvm_binding_remove_vif(mvm
, vif
);
720 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
721 mvmvif
->phy_ctxt
= NULL
;
724 if (mvm
->vif_count
&& vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
727 /* TODO: remove this when legacy PM will be discarded */
728 ieee80211_iterate_active_interfaces(
729 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
730 iwl_mvm_power_update_iterator
, mvm
);
732 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
735 iwl_mvm_mac_ctxt_release(mvm
, vif
);
736 mutex_unlock(&mvm
->mutex
);
739 static int iwl_mvm_set_tx_power(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
742 /* FW is in charge of regulatory enforcement */
743 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd
= {
744 .mac_context_id
= iwl_mvm_vif_from_mac80211(vif
)->id
,
745 .pwr_restriction
= cpu_to_le16(tx_power
),
748 return iwl_mvm_send_cmd_pdu(mvm
, REDUCE_TX_POWER_CMD
, CMD_SYNC
,
749 sizeof(reduce_txpwr_cmd
),
753 static int iwl_mvm_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
758 static void iwl_mvm_configure_filter(struct ieee80211_hw
*hw
,
759 unsigned int changed_flags
,
760 unsigned int *total_flags
,
766 static int iwl_mvm_configure_mcast_filter(struct iwl_mvm
*mvm
,
767 struct ieee80211_vif
*vif
)
769 struct iwl_mcast_filter_cmd mcast_filter_cmd
= {
773 memcpy(mcast_filter_cmd
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
775 return iwl_mvm_send_cmd_pdu(mvm
, MCAST_FILTER_CMD
, CMD_SYNC
,
776 sizeof(mcast_filter_cmd
),
780 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm
*mvm
,
781 struct ieee80211_vif
*vif
,
782 struct ieee80211_bss_conf
*bss_conf
,
785 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
788 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
790 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
792 if (changes
& BSS_CHANGED_ASSOC
) {
793 if (bss_conf
->assoc
) {
794 /* add quota for this interface */
795 ret
= iwl_mvm_update_quotas(mvm
, vif
);
797 IWL_ERR(mvm
, "failed to update quotas\n");
800 iwl_mvm_configure_mcast_filter(mvm
, vif
);
802 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
,
805 * If we're restarting then the firmware will
806 * obviously have lost synchronisation with
807 * the AP. It will attempt to synchronise by
808 * itself, but we can make it more reliable by
809 * scheduling a session protection time event.
811 * The firmware needs to receive a beacon to
812 * catch up with synchronisation, use 110% of
813 * the beacon interval.
815 * Set a large maximum delay to allow for more
816 * than a single interface.
818 u32 dur
= (11 * vif
->bss_conf
.beacon_int
) / 10;
819 iwl_mvm_protect_session(mvm
, vif
, dur
, dur
,
823 iwl_mvm_sf_update(mvm
, vif
, false);
824 iwl_mvm_power_vif_assoc(mvm
, vif
);
825 } else if (mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
827 * If update fails - SF might be running in associated
828 * mode while disassociated - which is forbidden.
830 WARN_ONCE(iwl_mvm_sf_update(mvm
, vif
, false),
831 "Failed to update SF upon disassociation\n");
833 /* remove AP station now that the MAC is unassoc */
834 ret
= iwl_mvm_rm_sta_id(mvm
, vif
, mvmvif
->ap_sta_id
);
836 IWL_ERR(mvm
, "failed to remove AP station\n");
837 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
838 /* remove quota for this interface */
839 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
841 IWL_ERR(mvm
, "failed to update quotas\n");
844 /* reset rssi values */
845 mvmvif
->bf_data
.ave_beacon_signal
= 0;
847 if (!(mvm
->fw
->ucode_capa
.flags
&
848 IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT
)) {
849 /* Workaround for FW bug, otherwise FW disables device
850 * power save upon disassociation
852 ret
= iwl_mvm_power_update_mode(mvm
, vif
);
854 IWL_ERR(mvm
, "failed to update power mode\n");
856 iwl_mvm_bt_coex_vif_change(mvm
);
857 } else if (changes
& BSS_CHANGED_BEACON_INFO
) {
859 * We received a beacon _after_ association so
860 * remove the session protection.
862 iwl_mvm_remove_time_event(mvm
, mvmvif
,
863 &mvmvif
->time_event_data
);
864 } else if (changes
& (BSS_CHANGED_PS
| BSS_CHANGED_QOS
)) {
865 ret
= iwl_mvm_power_update_mode(mvm
, vif
);
867 IWL_ERR(mvm
, "failed to update power mode\n");
869 if (changes
& BSS_CHANGED_TXPOWER
) {
870 IWL_DEBUG_CALIB(mvm
, "Changing TX Power to %d\n",
872 iwl_mvm_set_tx_power(mvm
, vif
, bss_conf
->txpower
);
875 if (changes
& BSS_CHANGED_CQM
) {
876 IWL_DEBUG_MAC80211(mvm
, "cqm info_changed");
877 /* reset cqm events tracking */
878 mvmvif
->bf_data
.last_cqm_event
= 0;
879 ret
= iwl_mvm_update_beacon_filter(mvm
, vif
);
881 IWL_ERR(mvm
, "failed to update CQM thresholds\n");
885 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw
*hw
,
886 struct ieee80211_vif
*vif
)
888 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
889 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
892 mutex_lock(&mvm
->mutex
);
894 /* Send the beacon template */
895 ret
= iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
);
899 /* Add the mac context */
900 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
904 /* Perform the binding */
905 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
909 mvmvif
->ap_ibss_active
= true;
911 /* Send the bcast station. At this stage the TBTT and DTIM time events
912 * are added and applied to the scheduler */
913 ret
= iwl_mvm_send_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
917 ret
= iwl_mvm_update_quotas(mvm
, vif
);
921 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
922 if (vif
->p2p
&& mvm
->p2p_device_vif
)
923 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
925 iwl_mvm_bt_coex_vif_change(mvm
);
927 mutex_unlock(&mvm
->mutex
);
931 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
933 iwl_mvm_binding_remove_vif(mvm
, vif
);
935 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
937 mutex_unlock(&mvm
->mutex
);
941 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw
*hw
,
942 struct ieee80211_vif
*vif
)
944 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
945 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
947 iwl_mvm_prepare_mac_removal(mvm
, vif
);
949 mutex_lock(&mvm
->mutex
);
951 mvmvif
->ap_ibss_active
= false;
953 iwl_mvm_bt_coex_vif_change(mvm
);
955 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
956 if (vif
->p2p
&& mvm
->p2p_device_vif
)
957 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
959 iwl_mvm_update_quotas(mvm
, NULL
);
960 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
961 iwl_mvm_binding_remove_vif(mvm
, vif
);
962 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
964 mutex_unlock(&mvm
->mutex
);
968 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm
*mvm
,
969 struct ieee80211_vif
*vif
,
970 struct ieee80211_bss_conf
*bss_conf
,
973 enum ieee80211_bss_change ht_change
= BSS_CHANGED_ERP_CTS_PROT
|
975 BSS_CHANGED_BANDWIDTH
;
978 if (changes
& ht_change
) {
979 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
981 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
984 /* Need to send a new beacon template to the FW */
985 if (changes
& BSS_CHANGED_BEACON
) {
986 if (iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
))
987 IWL_WARN(mvm
, "Failed updating beacon data\n");
991 static void iwl_mvm_bss_info_changed(struct ieee80211_hw
*hw
,
992 struct ieee80211_vif
*vif
,
993 struct ieee80211_bss_conf
*bss_conf
,
996 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
998 mutex_lock(&mvm
->mutex
);
1000 switch (vif
->type
) {
1001 case NL80211_IFTYPE_STATION
:
1002 iwl_mvm_bss_info_changed_station(mvm
, vif
, bss_conf
, changes
);
1004 case NL80211_IFTYPE_AP
:
1005 case NL80211_IFTYPE_ADHOC
:
1006 iwl_mvm_bss_info_changed_ap_ibss(mvm
, vif
, bss_conf
, changes
);
1009 /* shouldn't happen */
1013 mutex_unlock(&mvm
->mutex
);
1016 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw
*hw
,
1017 struct ieee80211_vif
*vif
,
1018 struct cfg80211_scan_request
*req
)
1020 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1023 if (req
->n_channels
== 0 || req
->n_channels
> MAX_NUM_SCAN_CHANNELS
)
1026 mutex_lock(&mvm
->mutex
);
1028 if (mvm
->scan_status
== IWL_MVM_SCAN_NONE
)
1029 ret
= iwl_mvm_scan_request(mvm
, vif
, req
);
1033 mutex_unlock(&mvm
->mutex
);
1038 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw
*hw
,
1039 struct ieee80211_vif
*vif
)
1041 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1043 mutex_lock(&mvm
->mutex
);
1045 iwl_mvm_cancel_scan(mvm
);
1047 mutex_unlock(&mvm
->mutex
);
1051 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw
*hw
,
1052 struct ieee80211_sta
*sta
, u16 tid
,
1054 enum ieee80211_frame_release_type reason
,
1057 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1059 /* TODO: how do we tell the fw to send frames for a specific TID */
1062 * The fw will send EOSP notification when the last frame will be
1065 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
);
1068 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw
*hw
,
1069 struct ieee80211_vif
*vif
,
1070 enum sta_notify_cmd cmd
,
1071 struct ieee80211_sta
*sta
)
1073 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1074 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1077 case STA_NOTIFY_SLEEP
:
1078 if (atomic_read(&mvm
->pending_frames
[mvmsta
->sta_id
]) > 0)
1079 ieee80211_sta_block_awake(hw
, sta
, true);
1081 * The fw updates the STA to be asleep. Tx packets on the Tx
1082 * queues to this station will not be transmitted. The fw will
1083 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1086 case STA_NOTIFY_AWAKE
:
1087 if (WARN_ON(mvmsta
->sta_id
== IWL_MVM_STATION_COUNT
))
1089 iwl_mvm_sta_modify_ps_wake(mvm
, sta
);
1096 static int iwl_mvm_mac_sta_state(struct ieee80211_hw
*hw
,
1097 struct ieee80211_vif
*vif
,
1098 struct ieee80211_sta
*sta
,
1099 enum ieee80211_sta_state old_state
,
1100 enum ieee80211_sta_state new_state
)
1102 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1103 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1106 IWL_DEBUG_MAC80211(mvm
, "station %pM state change %d->%d\n",
1107 sta
->addr
, old_state
, new_state
);
1109 /* this would be a mac80211 bug ... but don't crash */
1110 if (WARN_ON_ONCE(!mvmvif
->phy_ctxt
))
1113 /* if a STA is being removed, reuse its ID */
1114 flush_work(&mvm
->sta_drained_wk
);
1116 mutex_lock(&mvm
->mutex
);
1117 if (old_state
== IEEE80211_STA_NOTEXIST
&&
1118 new_state
== IEEE80211_STA_NONE
) {
1120 * Firmware bug - it'll crash if the beacon interval is less
1121 * than 16. We can't avoid connecting at all, so refuse the
1122 * station state change, this will cause mac80211 to abandon
1123 * attempts to connect to this AP, and eventually wpa_s will
1124 * blacklist the AP...
1126 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1127 vif
->bss_conf
.beacon_int
< 16) {
1129 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1130 sta
->addr
, vif
->bss_conf
.beacon_int
);
1134 ret
= iwl_mvm_add_sta(mvm
, vif
, sta
);
1135 } else if (old_state
== IEEE80211_STA_NONE
&&
1136 new_state
== IEEE80211_STA_AUTH
) {
1138 } else if (old_state
== IEEE80211_STA_AUTH
&&
1139 new_state
== IEEE80211_STA_ASSOC
) {
1140 ret
= iwl_mvm_update_sta(mvm
, vif
, sta
);
1142 iwl_mvm_rs_rate_init(mvm
, sta
,
1143 mvmvif
->phy_ctxt
->channel
->band
,
1145 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1146 new_state
== IEEE80211_STA_AUTHORIZED
) {
1147 /* enable beacon filtering */
1148 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
));
1150 } else if (old_state
== IEEE80211_STA_AUTHORIZED
&&
1151 new_state
== IEEE80211_STA_ASSOC
) {
1152 /* disable beacon filtering */
1153 WARN_ON(iwl_mvm_disable_beacon_filter(mvm
, vif
));
1155 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1156 new_state
== IEEE80211_STA_AUTH
) {
1158 } else if (old_state
== IEEE80211_STA_AUTH
&&
1159 new_state
== IEEE80211_STA_NONE
) {
1161 } else if (old_state
== IEEE80211_STA_NONE
&&
1162 new_state
== IEEE80211_STA_NOTEXIST
) {
1163 ret
= iwl_mvm_rm_sta(mvm
, vif
, sta
);
1168 mutex_unlock(&mvm
->mutex
);
1173 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1175 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1177 mvm
->rts_threshold
= value
;
1182 static void iwl_mvm_sta_rc_update(struct ieee80211_hw
*hw
,
1183 struct ieee80211_vif
*vif
,
1184 struct ieee80211_sta
*sta
, u32 changed
)
1186 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1188 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1189 changed
& IEEE80211_RC_NSS_CHANGED
)
1190 iwl_mvm_sf_update(mvm
, vif
, false);
1193 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw
*hw
,
1194 struct ieee80211_vif
*vif
, u16 ac
,
1195 const struct ieee80211_tx_queue_params
*params
)
1197 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1198 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1200 mvmvif
->queue_params
[ac
] = *params
;
1203 * No need to update right away, we'll get BSS_CHANGED_QOS
1204 * The exception is P2P_DEVICE interface which needs immediate update.
1206 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1209 mutex_lock(&mvm
->mutex
);
1210 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
1211 mutex_unlock(&mvm
->mutex
);
1217 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw
*hw
,
1218 struct ieee80211_vif
*vif
)
1220 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1221 u32 duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS
,
1222 200 + vif
->bss_conf
.beacon_int
);
1223 u32 min_duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS
,
1224 100 + vif
->bss_conf
.beacon_int
);
1226 if (WARN_ON_ONCE(vif
->bss_conf
.assoc
))
1229 mutex_lock(&mvm
->mutex
);
1230 /* Try really hard to protect the session and hear a beacon */
1231 iwl_mvm_protect_session(mvm
, vif
, duration
, min_duration
, 500);
1232 mutex_unlock(&mvm
->mutex
);
1235 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw
*hw
,
1236 struct ieee80211_vif
*vif
,
1237 struct cfg80211_sched_scan_request
*req
,
1238 struct ieee80211_sched_scan_ies
*ies
)
1240 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1243 mutex_lock(&mvm
->mutex
);
1245 if (mvm
->scan_status
!= IWL_MVM_SCAN_NONE
) {
1247 "SCHED SCAN request during internal scan - abort\n");
1252 mvm
->scan_status
= IWL_MVM_SCAN_SCHED
;
1254 ret
= iwl_mvm_config_sched_scan(mvm
, vif
, req
, ies
);
1258 ret
= iwl_mvm_config_sched_scan_profiles(mvm
, req
);
1262 ret
= iwl_mvm_sched_scan_start(mvm
, req
);
1266 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
1268 mutex_unlock(&mvm
->mutex
);
1272 static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw
*hw
,
1273 struct ieee80211_vif
*vif
)
1275 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1277 mutex_lock(&mvm
->mutex
);
1278 iwl_mvm_sched_scan_stop(mvm
);
1279 mutex_unlock(&mvm
->mutex
);
1282 static int iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
1283 enum set_key_cmd cmd
,
1284 struct ieee80211_vif
*vif
,
1285 struct ieee80211_sta
*sta
,
1286 struct ieee80211_key_conf
*key
)
1288 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1291 if (iwlwifi_mod_params
.sw_crypto
) {
1292 IWL_DEBUG_MAC80211(mvm
, "leave - hwcrypto disabled\n");
1296 switch (key
->cipher
) {
1297 case WLAN_CIPHER_SUITE_TKIP
:
1298 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1300 case WLAN_CIPHER_SUITE_CCMP
:
1301 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1303 case WLAN_CIPHER_SUITE_AES_CMAC
:
1304 WARN_ON_ONCE(!(hw
->flags
& IEEE80211_HW_MFP_CAPABLE
));
1306 case WLAN_CIPHER_SUITE_WEP40
:
1307 case WLAN_CIPHER_SUITE_WEP104
:
1309 * Support for TX only, at least for now, so accept
1310 * the key and do nothing else. Then mac80211 will
1311 * pass it for TX but we don't have to use it for RX.
1315 /* currently FW supports only one optional cipher scheme */
1316 if (hw
->n_cipher_schemes
&&
1317 hw
->cipher_schemes
->cipher
== key
->cipher
)
1318 key
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
1323 mutex_lock(&mvm
->mutex
);
1327 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1328 vif
->type
== NL80211_IFTYPE_AP
) && !sta
) {
1330 * GTK on AP interface is a TX-only key, return 0;
1331 * on IBSS they're per-station and because we're lazy
1332 * we don't support them for RX, so do the same.
1335 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1339 IWL_DEBUG_MAC80211(mvm
, "set hwcrypto key\n");
1340 ret
= iwl_mvm_set_sta_key(mvm
, vif
, sta
, key
, false);
1342 IWL_WARN(mvm
, "set key failed\n");
1344 * can't add key for RX, but we don't need it
1345 * in the device for TX so still return 0
1347 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1353 if (key
->hw_key_idx
== STA_KEY_IDX_INVALID
) {
1358 IWL_DEBUG_MAC80211(mvm
, "disable hwcrypto key\n");
1359 ret
= iwl_mvm_remove_sta_key(mvm
, vif
, sta
, key
);
1365 mutex_unlock(&mvm
->mutex
);
1369 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw
*hw
,
1370 struct ieee80211_vif
*vif
,
1371 struct ieee80211_key_conf
*keyconf
,
1372 struct ieee80211_sta
*sta
,
1373 u32 iv32
, u16
*phase1key
)
1375 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1377 if (keyconf
->hw_key_idx
== STA_KEY_IDX_INVALID
)
1380 iwl_mvm_update_tkip_key(mvm
, vif
, keyconf
, sta
, iv32
, phase1key
);
1384 static int iwl_mvm_roc(struct ieee80211_hw
*hw
,
1385 struct ieee80211_vif
*vif
,
1386 struct ieee80211_channel
*channel
,
1388 enum ieee80211_roc_type type
)
1390 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1391 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1392 struct cfg80211_chan_def chandef
;
1393 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1396 IWL_DEBUG_MAC80211(mvm
, "enter (%d, %d, %d)\n", channel
->hw_value
,
1399 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
) {
1400 IWL_ERR(mvm
, "vif isn't a P2P_DEVICE: %d\n", vif
->type
);
1404 mutex_lock(&mvm
->mutex
);
1406 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
1407 phy_ctxt
= &mvm
->phy_ctxts
[i
];
1408 if (phy_ctxt
->ref
== 0 || mvmvif
->phy_ctxt
== phy_ctxt
)
1411 if (phy_ctxt
->ref
&& channel
== phy_ctxt
->channel
) {
1413 * Unbind the P2P_DEVICE from the current PHY context,
1414 * and if the PHY context is not used remove it.
1416 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1417 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1420 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1422 /* Bind the P2P_DEVICE to the current PHY Context */
1423 mvmvif
->phy_ctxt
= phy_ctxt
;
1425 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1426 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1429 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1430 goto schedule_time_event
;
1434 /* Need to update the PHY context only if the ROC channel changed */
1435 if (channel
== mvmvif
->phy_ctxt
->channel
)
1436 goto schedule_time_event
;
1438 cfg80211_chandef_create(&chandef
, channel
, NL80211_CHAN_NO_HT
);
1441 * Change the PHY context configuration as it is currently referenced
1442 * only by the P2P Device MAC
1444 if (mvmvif
->phy_ctxt
->ref
== 1) {
1445 ret
= iwl_mvm_phy_ctxt_changed(mvm
, mvmvif
->phy_ctxt
,
1451 * The PHY context is shared with other MACs. Need to remove the
1452 * P2P Device from the binding, allocate an new PHY context and
1453 * create a new binding
1455 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1461 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &chandef
,
1464 IWL_ERR(mvm
, "Failed to change PHY context\n");
1468 /* Unbind the P2P_DEVICE from the current PHY context */
1469 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1470 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1473 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1475 /* Bind the P2P_DEVICE to the new allocated PHY context */
1476 mvmvif
->phy_ctxt
= phy_ctxt
;
1478 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1479 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1482 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1485 schedule_time_event
:
1486 /* Schedule the time events */
1487 ret
= iwl_mvm_start_p2p_roc(mvm
, vif
, duration
, type
);
1490 mutex_unlock(&mvm
->mutex
);
1491 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1495 static int iwl_mvm_cancel_roc(struct ieee80211_hw
*hw
)
1497 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1499 IWL_DEBUG_MAC80211(mvm
, "enter\n");
1501 mutex_lock(&mvm
->mutex
);
1502 iwl_mvm_stop_p2p_roc(mvm
);
1503 mutex_unlock(&mvm
->mutex
);
1505 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1509 static int iwl_mvm_add_chanctx(struct ieee80211_hw
*hw
,
1510 struct ieee80211_chanctx_conf
*ctx
)
1512 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1513 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1514 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1517 IWL_DEBUG_MAC80211(mvm
, "Add channel context\n");
1519 mutex_lock(&mvm
->mutex
);
1520 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1526 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->def
,
1527 ctx
->rx_chains_static
,
1528 ctx
->rx_chains_dynamic
);
1530 IWL_ERR(mvm
, "Failed to add PHY context\n");
1534 iwl_mvm_phy_ctxt_ref(mvm
, phy_ctxt
);
1535 *phy_ctxt_id
= phy_ctxt
->id
;
1537 mutex_unlock(&mvm
->mutex
);
1541 static void iwl_mvm_remove_chanctx(struct ieee80211_hw
*hw
,
1542 struct ieee80211_chanctx_conf
*ctx
)
1544 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1545 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1546 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1548 mutex_lock(&mvm
->mutex
);
1549 iwl_mvm_phy_ctxt_unref(mvm
, phy_ctxt
);
1550 mutex_unlock(&mvm
->mutex
);
1553 static void iwl_mvm_change_chanctx(struct ieee80211_hw
*hw
,
1554 struct ieee80211_chanctx_conf
*ctx
,
1557 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1558 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1559 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1561 if (WARN_ONCE((phy_ctxt
->ref
> 1) &&
1562 (changed
& ~(IEEE80211_CHANCTX_CHANGE_WIDTH
|
1563 IEEE80211_CHANCTX_CHANGE_RX_CHAINS
|
1564 IEEE80211_CHANCTX_CHANGE_RADAR
)),
1565 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1566 phy_ctxt
->ref
, changed
))
1569 mutex_lock(&mvm
->mutex
);
1570 iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->def
,
1571 ctx
->rx_chains_static
,
1572 ctx
->rx_chains_dynamic
);
1573 iwl_mvm_bt_coex_vif_change(mvm
);
1574 mutex_unlock(&mvm
->mutex
);
1577 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw
*hw
,
1578 struct ieee80211_vif
*vif
,
1579 struct ieee80211_chanctx_conf
*ctx
)
1581 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1582 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1583 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1584 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1587 mutex_lock(&mvm
->mutex
);
1589 mvmvif
->phy_ctxt
= phy_ctxt
;
1591 switch (vif
->type
) {
1592 case NL80211_IFTYPE_AP
:
1593 case NL80211_IFTYPE_ADHOC
:
1595 * The AP binding flow is handled as part of the start_ap flow
1596 * (in bss_info_changed), similarly for IBSS.
1600 case NL80211_IFTYPE_STATION
:
1601 case NL80211_IFTYPE_MONITOR
:
1608 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1613 * Setting the quota at this stage is only required for monitor
1614 * interfaces. For the other types, the bss_info changed flow
1615 * will handle quota settings.
1617 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
1618 mvmvif
->monitor_active
= true;
1619 ret
= iwl_mvm_update_quotas(mvm
, vif
);
1621 goto out_remove_binding
;
1624 mvm
->bound_vif_cnt
++;
1625 iwl_mvm_power_update_binding(mvm
, vif
);
1630 iwl_mvm_binding_remove_vif(mvm
, vif
);
1632 mutex_unlock(&mvm
->mutex
);
1634 mvmvif
->phy_ctxt
= NULL
;
1638 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
1639 struct ieee80211_vif
*vif
,
1640 struct ieee80211_chanctx_conf
*ctx
)
1642 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1643 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1645 mutex_lock(&mvm
->mutex
);
1647 iwl_mvm_remove_time_event(mvm
, mvmvif
, &mvmvif
->time_event_data
);
1649 switch (vif
->type
) {
1650 case NL80211_IFTYPE_AP
:
1651 case NL80211_IFTYPE_ADHOC
:
1653 case NL80211_IFTYPE_MONITOR
:
1654 mvmvif
->monitor_active
= false;
1655 iwl_mvm_update_quotas(mvm
, NULL
);
1661 iwl_mvm_binding_remove_vif(mvm
, vif
);
1663 mvmvif
->phy_ctxt
= NULL
;
1664 mvm
->bound_vif_cnt
--;
1665 iwl_mvm_power_update_binding(mvm
, vif
);
1667 mutex_unlock(&mvm
->mutex
);
1670 static int iwl_mvm_set_tim(struct ieee80211_hw
*hw
,
1671 struct ieee80211_sta
*sta
,
1674 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1675 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
1677 if (!mvm_sta
|| !mvm_sta
->vif
) {
1678 IWL_ERR(mvm
, "Station is not associated to a vif\n");
1682 return iwl_mvm_mac_ctxt_beacon_changed(mvm
, mvm_sta
->vif
);
1685 #ifdef CONFIG_NL80211_TESTMODE
1686 static const struct nla_policy iwl_mvm_tm_policy
[IWL_MVM_TM_ATTR_MAX
+ 1] = {
1687 [IWL_MVM_TM_ATTR_CMD
] = { .type
= NLA_U32
},
1688 [IWL_MVM_TM_ATTR_NOA_DURATION
] = { .type
= NLA_U32
},
1689 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
] = { .type
= NLA_U32
},
1692 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm
*mvm
,
1693 struct ieee80211_vif
*vif
,
1694 void *data
, int len
)
1696 struct nlattr
*tb
[IWL_MVM_TM_ATTR_MAX
+ 1];
1700 err
= nla_parse(tb
, IWL_MVM_TM_ATTR_MAX
, data
, len
, iwl_mvm_tm_policy
);
1704 if (!tb
[IWL_MVM_TM_ATTR_CMD
])
1707 switch (nla_get_u32(tb
[IWL_MVM_TM_ATTR_CMD
])) {
1708 case IWL_MVM_TM_CMD_SET_NOA
:
1709 if (!vif
|| vif
->type
!= NL80211_IFTYPE_AP
|| !vif
->p2p
||
1710 !vif
->bss_conf
.enable_beacon
||
1711 !tb
[IWL_MVM_TM_ATTR_NOA_DURATION
])
1714 noa_duration
= nla_get_u32(tb
[IWL_MVM_TM_ATTR_NOA_DURATION
]);
1715 if (noa_duration
>= vif
->bss_conf
.beacon_int
)
1718 mvm
->noa_duration
= noa_duration
;
1721 return iwl_mvm_update_quotas(mvm
, NULL
);
1722 case IWL_MVM_TM_CMD_SET_BEACON_FILTER
:
1723 /* must be associated client vif - ignore authorized */
1724 if (!vif
|| vif
->type
!= NL80211_IFTYPE_STATION
||
1725 !vif
->bss_conf
.assoc
|| !vif
->bss_conf
.dtim_period
||
1726 !tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
])
1729 if (nla_get_u32(tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
]))
1730 return iwl_mvm_enable_beacon_filter(mvm
, vif
);
1731 return iwl_mvm_disable_beacon_filter(mvm
, vif
);
1737 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw
*hw
,
1738 struct ieee80211_vif
*vif
,
1739 void *data
, int len
)
1741 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1744 mutex_lock(&mvm
->mutex
);
1745 err
= __iwl_mvm_mac_testmode_cmd(mvm
, vif
, data
, len
);
1746 mutex_unlock(&mvm
->mutex
);
1752 struct ieee80211_ops iwl_mvm_hw_ops
= {
1753 .tx
= iwl_mvm_mac_tx
,
1754 .ampdu_action
= iwl_mvm_mac_ampdu_action
,
1755 .start
= iwl_mvm_mac_start
,
1756 .restart_complete
= iwl_mvm_mac_restart_complete
,
1757 .stop
= iwl_mvm_mac_stop
,
1758 .add_interface
= iwl_mvm_mac_add_interface
,
1759 .remove_interface
= iwl_mvm_mac_remove_interface
,
1760 .config
= iwl_mvm_mac_config
,
1761 .configure_filter
= iwl_mvm_configure_filter
,
1762 .bss_info_changed
= iwl_mvm_bss_info_changed
,
1763 .hw_scan
= iwl_mvm_mac_hw_scan
,
1764 .cancel_hw_scan
= iwl_mvm_mac_cancel_hw_scan
,
1765 .sta_state
= iwl_mvm_mac_sta_state
,
1766 .sta_notify
= iwl_mvm_mac_sta_notify
,
1767 .allow_buffered_frames
= iwl_mvm_mac_allow_buffered_frames
,
1768 .set_rts_threshold
= iwl_mvm_mac_set_rts_threshold
,
1769 .sta_rc_update
= iwl_mvm_sta_rc_update
,
1770 .conf_tx
= iwl_mvm_mac_conf_tx
,
1771 .mgd_prepare_tx
= iwl_mvm_mac_mgd_prepare_tx
,
1772 .sched_scan_start
= iwl_mvm_mac_sched_scan_start
,
1773 .sched_scan_stop
= iwl_mvm_mac_sched_scan_stop
,
1774 .set_key
= iwl_mvm_mac_set_key
,
1775 .update_tkip_key
= iwl_mvm_mac_update_tkip_key
,
1776 .remain_on_channel
= iwl_mvm_roc
,
1777 .cancel_remain_on_channel
= iwl_mvm_cancel_roc
,
1778 .add_chanctx
= iwl_mvm_add_chanctx
,
1779 .remove_chanctx
= iwl_mvm_remove_chanctx
,
1780 .change_chanctx
= iwl_mvm_change_chanctx
,
1781 .assign_vif_chanctx
= iwl_mvm_assign_vif_chanctx
,
1782 .unassign_vif_chanctx
= iwl_mvm_unassign_vif_chanctx
,
1784 .start_ap
= iwl_mvm_start_ap_ibss
,
1785 .stop_ap
= iwl_mvm_stop_ap_ibss
,
1786 .join_ibss
= iwl_mvm_start_ap_ibss
,
1787 .leave_ibss
= iwl_mvm_stop_ap_ibss
,
1789 .set_tim
= iwl_mvm_set_tim
,
1791 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd
)
1793 #ifdef CONFIG_PM_SLEEP
1795 .suspend
= iwl_mvm_suspend
,
1796 .resume
= iwl_mvm_resume
,
1797 .set_wakeup
= iwl_mvm_set_wakeup
,
1798 .set_rekey_data
= iwl_mvm_set_rekey_data
,
1799 #if IS_ENABLED(CONFIG_IPV6)
1800 .ipv6_addr_change
= iwl_mvm_ipv6_addr_change
,
1802 .set_default_unicast_key
= iwl_mvm_set_default_unicast_key
,