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_CUSTOM_REGULATORY
|
203 WIPHY_FLAG_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
;
261 mvm
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
263 #ifdef CONFIG_PM_SLEEP
264 if (mvm
->fw
->img
[IWL_UCODE_WOWLAN
].sec
[0].len
&&
265 mvm
->trans
->ops
->d3_suspend
&&
266 mvm
->trans
->ops
->d3_resume
&&
267 device_can_wakeup(mvm
->trans
->dev
)) {
268 mvm
->wowlan
.flags
= WIPHY_WOWLAN_MAGIC_PKT
|
269 WIPHY_WOWLAN_DISCONNECT
|
270 WIPHY_WOWLAN_EAP_IDENTITY_REQ
|
271 WIPHY_WOWLAN_RFKILL_RELEASE
;
272 if (!iwlwifi_mod_params
.sw_crypto
)
273 mvm
->wowlan
.flags
|= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
|
274 WIPHY_WOWLAN_GTK_REKEY_FAILURE
|
275 WIPHY_WOWLAN_4WAY_HANDSHAKE
;
277 mvm
->wowlan
.n_patterns
= IWL_WOWLAN_MAX_PATTERNS
;
278 mvm
->wowlan
.pattern_min_len
= IWL_WOWLAN_MIN_PATTERN_LEN
;
279 mvm
->wowlan
.pattern_max_len
= IWL_WOWLAN_MAX_PATTERN_LEN
;
280 mvm
->wowlan
.tcp
= &iwl_mvm_wowlan_tcp_support
;
281 hw
->wiphy
->wowlan
= &mvm
->wowlan
;
285 ret
= iwl_mvm_leds_init(mvm
);
289 ret
= ieee80211_register_hw(mvm
->hw
);
291 iwl_mvm_leds_exit(mvm
);
296 static void iwl_mvm_mac_tx(struct ieee80211_hw
*hw
,
297 struct ieee80211_tx_control
*control
,
300 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
302 if (iwl_mvm_is_radio_killed(mvm
)) {
303 IWL_DEBUG_DROP(mvm
, "Dropping - RF/CT KILL\n");
307 if (IEEE80211_SKB_CB(skb
)->hw_queue
== IWL_MVM_OFFCHANNEL_QUEUE
&&
308 !test_bit(IWL_MVM_STATUS_ROC_RUNNING
, &mvm
->status
))
312 if (iwl_mvm_tx_skb(mvm
, skb
, control
->sta
))
317 if (iwl_mvm_tx_skb_non_sta(mvm
, skb
))
321 ieee80211_free_txskb(hw
, skb
);
324 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw
*hw
,
325 struct ieee80211_vif
*vif
,
326 enum ieee80211_ampdu_mlme_action action
,
327 struct ieee80211_sta
*sta
, u16 tid
,
328 u16
*ssn
, u8 buf_size
)
330 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
333 IWL_DEBUG_HT(mvm
, "A-MPDU action on addr %pM tid %d: action %d\n",
334 sta
->addr
, tid
, action
);
336 if (!(mvm
->nvm_data
->sku_cap_11n_enable
))
339 mutex_lock(&mvm
->mutex
);
342 case IEEE80211_AMPDU_RX_START
:
343 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_RXAGG
) {
347 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, *ssn
, true);
349 case IEEE80211_AMPDU_RX_STOP
:
350 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, 0, false);
352 case IEEE80211_AMPDU_TX_START
:
353 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_TXAGG
) {
357 ret
= iwl_mvm_sta_tx_agg_start(mvm
, vif
, sta
, tid
, ssn
);
359 case IEEE80211_AMPDU_TX_STOP_CONT
:
360 ret
= iwl_mvm_sta_tx_agg_stop(mvm
, vif
, sta
, tid
);
362 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
363 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
364 ret
= iwl_mvm_sta_tx_agg_flush(mvm
, vif
, sta
, tid
);
366 case IEEE80211_AMPDU_TX_OPERATIONAL
:
367 ret
= iwl_mvm_sta_tx_agg_oper(mvm
, vif
, sta
, tid
, buf_size
);
374 mutex_unlock(&mvm
->mutex
);
379 static void iwl_mvm_cleanup_iterator(void *data
, u8
*mac
,
380 struct ieee80211_vif
*vif
)
382 struct iwl_mvm
*mvm
= data
;
383 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
385 mvmvif
->uploaded
= false;
386 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
388 /* does this make sense at all? */
391 spin_lock_bh(&mvm
->time_event_lock
);
392 iwl_mvm_te_clear_data(mvm
, &mvmvif
->time_event_data
);
393 spin_unlock_bh(&mvm
->time_event_lock
);
395 mvmvif
->phy_ctxt
= NULL
;
398 static void iwl_mvm_restart_cleanup(struct iwl_mvm
*mvm
)
400 iwl_trans_stop_device(mvm
->trans
);
401 iwl_trans_stop_hw(mvm
->trans
, false);
403 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
405 /* just in case one was running */
406 ieee80211_remain_on_channel_expired(mvm
->hw
);
408 ieee80211_iterate_active_interfaces_atomic(
409 mvm
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
410 iwl_mvm_cleanup_iterator
, mvm
);
412 mvm
->p2p_device_vif
= NULL
;
414 iwl_mvm_reset_phy_ctxts(mvm
);
415 memset(mvm
->fw_key_table
, 0, sizeof(mvm
->fw_key_table
));
416 memset(mvm
->sta_drained
, 0, sizeof(mvm
->sta_drained
));
418 ieee80211_wake_queues(mvm
->hw
);
421 mvm
->rx_ba_sessions
= 0;
424 static int iwl_mvm_mac_start(struct ieee80211_hw
*hw
)
426 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
429 mutex_lock(&mvm
->mutex
);
431 /* Clean up some internal and mac80211 state on restart */
432 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
433 iwl_mvm_restart_cleanup(mvm
);
435 ret
= iwl_mvm_up(mvm
);
436 mutex_unlock(&mvm
->mutex
);
441 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw
*hw
)
443 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
446 mutex_lock(&mvm
->mutex
);
448 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
449 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
451 IWL_ERR(mvm
, "Failed to update quotas after restart (%d)\n",
454 mutex_unlock(&mvm
->mutex
);
457 static void iwl_mvm_mac_stop(struct ieee80211_hw
*hw
)
459 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
461 flush_work(&mvm
->async_handlers_wk
);
463 mutex_lock(&mvm
->mutex
);
464 /* async_handlers_wk is now blocked */
467 * The work item could be running or queued if the
468 * ROC time event stops just as we get here.
470 cancel_work_sync(&mvm
->roc_done_wk
);
472 iwl_trans_stop_device(mvm
->trans
);
473 iwl_trans_stop_hw(mvm
->trans
, false);
475 iwl_mvm_async_handlers_purge(mvm
);
476 /* async_handlers_list is empty and will stay empty: HW is stopped */
478 /* the fw is stopped, the aux sta is dead: clean up driver state */
479 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
481 mutex_unlock(&mvm
->mutex
);
484 * The worker might have been waiting for the mutex, let it run and
485 * discover that its list is now empty.
487 cancel_work_sync(&mvm
->async_handlers_wk
);
490 static void iwl_mvm_pm_disable_iterator(void *data
, u8
*mac
,
491 struct ieee80211_vif
*vif
)
493 struct iwl_mvm
*mvm
= data
;
496 ret
= iwl_mvm_power_disable(mvm
, vif
);
498 IWL_ERR(mvm
, "failed to disable power management\n");
501 static void iwl_mvm_power_update_iterator(void *data
, u8
*mac
,
502 struct ieee80211_vif
*vif
)
504 struct iwl_mvm
*mvm
= data
;
506 iwl_mvm_power_update_mode(mvm
, vif
);
509 static struct iwl_mvm_phy_ctxt
*iwl_mvm_get_free_phy_ctxt(struct iwl_mvm
*mvm
)
513 lockdep_assert_held(&mvm
->mutex
);
515 for (i
= 0; i
< NUM_PHY_CTX
; i
++)
516 if (!mvm
->phy_ctxts
[i
].ref
)
517 return &mvm
->phy_ctxts
[i
];
519 IWL_ERR(mvm
, "No available PHY context\n");
523 static int iwl_mvm_mac_add_interface(struct ieee80211_hw
*hw
,
524 struct ieee80211_vif
*vif
)
526 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
527 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
531 * Not much to do here. The stack will not allow interface
532 * types or combinations that we didn't advertise, so we
533 * don't really have to check the types.
536 mutex_lock(&mvm
->mutex
);
538 /* Allocate resources for the MAC context, and add it to the fw */
539 ret
= iwl_mvm_mac_ctxt_init(mvm
, vif
);
544 * TODO: remove this temporary code.
545 * Currently MVM FW supports power management only on single MAC.
546 * If new interface added, disable PM on existing interface.
547 * P2P device is a special case, since it is handled by FW similary to
548 * scan. If P2P deviced is added, PM remains enabled on existing
550 * Note: the method below does not count the new interface being added
553 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
555 if (mvm
->vif_count
> 1) {
556 IWL_DEBUG_MAC80211(mvm
,
557 "Disable power on existing interfaces\n");
558 ieee80211_iterate_active_interfaces_atomic(
560 IEEE80211_IFACE_ITER_NORMAL
,
561 iwl_mvm_pm_disable_iterator
, mvm
);
565 * The AP binding flow can be done only after the beacon
566 * template is configured (which happens only in the mac80211
567 * start_ap() flow), and adding the broadcast station can happen
568 * only after the binding.
569 * In addition, since modifying the MAC before adding a bcast
570 * station is not allowed by the FW, delay the adding of MAC context to
571 * the point where we can also add the bcast station.
572 * In short: there's not much we can do at this point, other than
573 * allocating resources :)
575 if (vif
->type
== NL80211_IFTYPE_AP
||
576 vif
->type
== NL80211_IFTYPE_ADHOC
) {
577 u32 qmask
= iwl_mvm_mac_get_queues_mask(mvm
, vif
);
578 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->bcast_sta
,
581 IWL_ERR(mvm
, "Failed to allocate bcast sta\n");
585 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
589 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
594 * Update power state on the new interface. Admittedly, based on
595 * mac80211 logics this power update will disable power management
597 iwl_mvm_power_update_mode(mvm
, vif
);
599 /* beacon filtering */
600 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
);
604 if (!mvm
->bf_allowed_vif
&&
605 vif
->type
== NL80211_IFTYPE_STATION
&& !vif
->p2p
&&
606 mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BF_UPDATED
){
607 mvm
->bf_allowed_vif
= mvmvif
;
608 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
609 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
613 * P2P_DEVICE interface does not have a channel context assigned to it,
614 * so a dedicated PHY context is allocated to it and the corresponding
615 * MAC context is bound to it at this stage.
617 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
619 mvmvif
->phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
620 if (!mvmvif
->phy_ctxt
) {
625 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
626 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
630 ret
= iwl_mvm_add_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
634 /* Save a pointer to p2p device vif, so it can later be used to
635 * update the p2p device MAC when a GO is started/stopped */
636 mvm
->p2p_device_vif
= vif
;
639 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
643 iwl_mvm_binding_remove_vif(mvm
, vif
);
645 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
647 if (mvm
->bf_allowed_vif
== mvmvif
) {
648 mvm
->bf_allowed_vif
= NULL
;
649 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
650 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
653 mvmvif
->phy_ctxt
= NULL
;
654 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
656 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
658 ieee80211_iterate_active_interfaces(
659 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
660 iwl_mvm_power_update_iterator
, mvm
);
661 iwl_mvm_mac_ctxt_release(mvm
, vif
);
663 mutex_unlock(&mvm
->mutex
);
668 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm
*mvm
,
669 struct ieee80211_vif
*vif
)
673 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
674 if (vif
->hw_queue
[ac
] != IEEE80211_INVAL_HW_QUEUE
)
675 tfd_msk
|= BIT(vif
->hw_queue
[ac
]);
677 if (vif
->cab_queue
!= IEEE80211_INVAL_HW_QUEUE
)
678 tfd_msk
|= BIT(vif
->cab_queue
);
681 mutex_lock(&mvm
->mutex
);
682 iwl_mvm_flush_tx_path(mvm
, tfd_msk
, true);
683 mutex_unlock(&mvm
->mutex
);
686 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
688 * Flush the ROC worker which will flush the OFFCHANNEL queue.
689 * We assume here that all the packets sent to the OFFCHANNEL
690 * queue are sent in ROC session.
692 flush_work(&mvm
->roc_done_wk
);
695 * By now, all the AC queues are empty. The AGG queues are
696 * empty too. We already got all the Tx responses for all the
697 * packets in the queues. The drain work can have been
698 * triggered. Flush it.
700 flush_work(&mvm
->sta_drained_wk
);
704 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw
*hw
,
705 struct ieee80211_vif
*vif
)
707 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
708 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
710 iwl_mvm_prepare_mac_removal(mvm
, vif
);
712 mutex_lock(&mvm
->mutex
);
714 if (mvm
->bf_allowed_vif
== mvmvif
) {
715 mvm
->bf_allowed_vif
= NULL
;
716 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
717 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
720 iwl_mvm_vif_dbgfs_clean(mvm
, vif
);
723 * For AP/GO interface, the tear down of the resources allocated to the
724 * interface is be handled as part of the stop_ap flow.
726 if (vif
->type
== NL80211_IFTYPE_AP
||
727 vif
->type
== NL80211_IFTYPE_ADHOC
) {
728 #ifdef CONFIG_NL80211_TESTMODE
729 if (vif
== mvm
->noa_vif
) {
731 mvm
->noa_duration
= 0;
734 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->bcast_sta
);
738 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
739 mvm
->p2p_device_vif
= NULL
;
740 iwl_mvm_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
741 iwl_mvm_binding_remove_vif(mvm
, vif
);
742 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
743 mvmvif
->phy_ctxt
= NULL
;
747 * TODO: remove this temporary code.
748 * Currently MVM FW supports power management only on single MAC.
749 * Check if only one additional interface remains after removing
750 * current one. Update power mode on the remaining interface.
752 if (mvm
->vif_count
&& vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
754 IWL_DEBUG_MAC80211(mvm
, "Currently %d interfaces active\n",
756 if (mvm
->vif_count
== 1) {
757 ieee80211_iterate_active_interfaces(
758 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
759 iwl_mvm_power_update_iterator
, mvm
);
762 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
765 iwl_mvm_mac_ctxt_release(mvm
, vif
);
766 mutex_unlock(&mvm
->mutex
);
769 static int iwl_mvm_set_tx_power(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
772 /* FW is in charge of regulatory enforcement */
773 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd
= {
774 .mac_context_id
= iwl_mvm_vif_from_mac80211(vif
)->id
,
775 .pwr_restriction
= cpu_to_le16(tx_power
),
778 return iwl_mvm_send_cmd_pdu(mvm
, REDUCE_TX_POWER_CMD
, CMD_SYNC
,
779 sizeof(reduce_txpwr_cmd
),
783 static int iwl_mvm_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
788 static void iwl_mvm_configure_filter(struct ieee80211_hw
*hw
,
789 unsigned int changed_flags
,
790 unsigned int *total_flags
,
796 static int iwl_mvm_configure_mcast_filter(struct iwl_mvm
*mvm
,
797 struct ieee80211_vif
*vif
)
799 struct iwl_mcast_filter_cmd mcast_filter_cmd
= {
803 memcpy(mcast_filter_cmd
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
805 return iwl_mvm_send_cmd_pdu(mvm
, MCAST_FILTER_CMD
, CMD_SYNC
,
806 sizeof(mcast_filter_cmd
),
810 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm
*mvm
,
811 struct ieee80211_vif
*vif
,
812 struct ieee80211_bss_conf
*bss_conf
,
815 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
818 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
820 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
822 if (changes
& BSS_CHANGED_ASSOC
) {
823 if (bss_conf
->assoc
) {
824 /* add quota for this interface */
825 ret
= iwl_mvm_update_quotas(mvm
, vif
);
827 IWL_ERR(mvm
, "failed to update quotas\n");
830 iwl_mvm_configure_mcast_filter(mvm
, vif
);
832 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
,
835 * If we're restarting then the firmware will
836 * obviously have lost synchronisation with
837 * the AP. It will attempt to synchronise by
838 * itself, but we can make it more reliable by
839 * scheduling a session protection time event.
841 * The firmware needs to receive a beacon to
842 * catch up with synchronisation, use 110% of
843 * the beacon interval.
845 * Set a large maximum delay to allow for more
846 * than a single interface.
848 u32 dur
= (11 * vif
->bss_conf
.beacon_int
) / 10;
849 iwl_mvm_protect_session(mvm
, vif
, dur
, dur
,
852 } else if (mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
853 /* remove AP station now that the MAC is unassoc */
854 ret
= iwl_mvm_rm_sta_id(mvm
, vif
, mvmvif
->ap_sta_id
);
856 IWL_ERR(mvm
, "failed to remove AP station\n");
857 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
858 /* remove quota for this interface */
859 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
861 IWL_ERR(mvm
, "failed to update quotas\n");
864 /* reset rssi values */
865 mvmvif
->bf_data
.ave_beacon_signal
= 0;
867 if (!(mvm
->fw
->ucode_capa
.flags
&
868 IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT
)) {
869 /* Workaround for FW bug, otherwise FW disables device
870 * power save upon disassociation
872 ret
= iwl_mvm_power_update_mode(mvm
, vif
);
874 IWL_ERR(mvm
, "failed to update power mode\n");
876 iwl_mvm_bt_coex_vif_change(mvm
);
877 } else if (changes
& BSS_CHANGED_BEACON_INFO
) {
879 * We received a beacon _after_ association so
880 * remove the session protection.
882 iwl_mvm_remove_time_event(mvm
, mvmvif
,
883 &mvmvif
->time_event_data
);
884 } else if (changes
& (BSS_CHANGED_PS
| BSS_CHANGED_QOS
)) {
885 ret
= iwl_mvm_power_update_mode(mvm
, vif
);
887 IWL_ERR(mvm
, "failed to update power mode\n");
889 if (changes
& BSS_CHANGED_TXPOWER
) {
890 IWL_DEBUG_CALIB(mvm
, "Changing TX Power to %d\n",
892 iwl_mvm_set_tx_power(mvm
, vif
, bss_conf
->txpower
);
895 if (changes
& BSS_CHANGED_CQM
) {
896 IWL_DEBUG_MAC80211(mvm
, "cqm info_changed");
897 /* reset cqm events tracking */
898 mvmvif
->bf_data
.last_cqm_event
= 0;
899 ret
= iwl_mvm_update_beacon_filter(mvm
, vif
);
901 IWL_ERR(mvm
, "failed to update CQM thresholds\n");
905 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw
*hw
,
906 struct ieee80211_vif
*vif
)
908 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
909 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
912 mutex_lock(&mvm
->mutex
);
914 /* Send the beacon template */
915 ret
= iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
);
919 /* Add the mac context */
920 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
924 /* Perform the binding */
925 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
929 mvmvif
->ap_ibss_active
= true;
931 /* Send the bcast station. At this stage the TBTT and DTIM time events
932 * are added and applied to the scheduler */
933 ret
= iwl_mvm_send_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
937 ret
= iwl_mvm_update_quotas(mvm
, vif
);
941 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
942 if (vif
->p2p
&& mvm
->p2p_device_vif
)
943 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
945 iwl_mvm_bt_coex_vif_change(mvm
);
947 mutex_unlock(&mvm
->mutex
);
951 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
953 iwl_mvm_binding_remove_vif(mvm
, vif
);
955 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
957 mutex_unlock(&mvm
->mutex
);
961 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw
*hw
,
962 struct ieee80211_vif
*vif
)
964 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
965 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
967 iwl_mvm_prepare_mac_removal(mvm
, vif
);
969 mutex_lock(&mvm
->mutex
);
971 mvmvif
->ap_ibss_active
= false;
973 iwl_mvm_bt_coex_vif_change(mvm
);
975 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
976 if (vif
->p2p
&& mvm
->p2p_device_vif
)
977 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
979 iwl_mvm_update_quotas(mvm
, NULL
);
980 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
981 iwl_mvm_binding_remove_vif(mvm
, vif
);
982 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
984 mutex_unlock(&mvm
->mutex
);
988 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm
*mvm
,
989 struct ieee80211_vif
*vif
,
990 struct ieee80211_bss_conf
*bss_conf
,
993 /* Need to send a new beacon template to the FW */
994 if (changes
& BSS_CHANGED_BEACON
) {
995 if (iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
))
996 IWL_WARN(mvm
, "Failed updating beacon data\n");
1000 static void iwl_mvm_bss_info_changed(struct ieee80211_hw
*hw
,
1001 struct ieee80211_vif
*vif
,
1002 struct ieee80211_bss_conf
*bss_conf
,
1005 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1007 mutex_lock(&mvm
->mutex
);
1009 switch (vif
->type
) {
1010 case NL80211_IFTYPE_STATION
:
1011 iwl_mvm_bss_info_changed_station(mvm
, vif
, bss_conf
, changes
);
1013 case NL80211_IFTYPE_AP
:
1014 case NL80211_IFTYPE_ADHOC
:
1015 iwl_mvm_bss_info_changed_ap_ibss(mvm
, vif
, bss_conf
, changes
);
1018 /* shouldn't happen */
1022 mutex_unlock(&mvm
->mutex
);
1025 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw
*hw
,
1026 struct ieee80211_vif
*vif
,
1027 struct cfg80211_scan_request
*req
)
1029 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1032 if (req
->n_channels
== 0 || req
->n_channels
> MAX_NUM_SCAN_CHANNELS
)
1035 mutex_lock(&mvm
->mutex
);
1037 if (mvm
->scan_status
== IWL_MVM_SCAN_NONE
)
1038 ret
= iwl_mvm_scan_request(mvm
, vif
, req
);
1042 mutex_unlock(&mvm
->mutex
);
1047 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw
*hw
,
1048 struct ieee80211_vif
*vif
)
1050 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1052 mutex_lock(&mvm
->mutex
);
1054 iwl_mvm_cancel_scan(mvm
);
1056 mutex_unlock(&mvm
->mutex
);
1060 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw
*hw
,
1061 struct ieee80211_sta
*sta
, u16 tid
,
1063 enum ieee80211_frame_release_type reason
,
1066 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1068 /* TODO: how do we tell the fw to send frames for a specific TID */
1071 * The fw will send EOSP notification when the last frame will be
1074 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
);
1077 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw
*hw
,
1078 struct ieee80211_vif
*vif
,
1079 enum sta_notify_cmd cmd
,
1080 struct ieee80211_sta
*sta
)
1082 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1083 struct iwl_mvm_sta
*mvmsta
= (void *)sta
->drv_priv
;
1086 case STA_NOTIFY_SLEEP
:
1087 if (atomic_read(&mvm
->pending_frames
[mvmsta
->sta_id
]) > 0)
1088 ieee80211_sta_block_awake(hw
, sta
, true);
1090 * The fw updates the STA to be asleep. Tx packets on the Tx
1091 * queues to this station will not be transmitted. The fw will
1092 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1095 case STA_NOTIFY_AWAKE
:
1096 if (WARN_ON(mvmsta
->sta_id
== IWL_MVM_STATION_COUNT
))
1098 iwl_mvm_sta_modify_ps_wake(mvm
, sta
);
1105 static int iwl_mvm_mac_sta_state(struct ieee80211_hw
*hw
,
1106 struct ieee80211_vif
*vif
,
1107 struct ieee80211_sta
*sta
,
1108 enum ieee80211_sta_state old_state
,
1109 enum ieee80211_sta_state new_state
)
1111 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1112 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1115 IWL_DEBUG_MAC80211(mvm
, "station %pM state change %d->%d\n",
1116 sta
->addr
, old_state
, new_state
);
1118 /* this would be a mac80211 bug ... but don't crash */
1119 if (WARN_ON_ONCE(!mvmvif
->phy_ctxt
))
1122 /* if a STA is being removed, reuse its ID */
1123 flush_work(&mvm
->sta_drained_wk
);
1125 mutex_lock(&mvm
->mutex
);
1126 if (old_state
== IEEE80211_STA_NOTEXIST
&&
1127 new_state
== IEEE80211_STA_NONE
) {
1129 * Firmware bug - it'll crash if the beacon interval is less
1130 * than 16. We can't avoid connecting at all, so refuse the
1131 * station state change, this will cause mac80211 to abandon
1132 * attempts to connect to this AP, and eventually wpa_s will
1133 * blacklist the AP...
1135 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1136 vif
->bss_conf
.beacon_int
< 16) {
1138 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1139 sta
->addr
, vif
->bss_conf
.beacon_int
);
1143 ret
= iwl_mvm_add_sta(mvm
, vif
, sta
);
1144 } else if (old_state
== IEEE80211_STA_NONE
&&
1145 new_state
== IEEE80211_STA_AUTH
) {
1147 } else if (old_state
== IEEE80211_STA_AUTH
&&
1148 new_state
== IEEE80211_STA_ASSOC
) {
1149 ret
= iwl_mvm_update_sta(mvm
, vif
, sta
);
1151 iwl_mvm_rs_rate_init(mvm
, sta
,
1152 mvmvif
->phy_ctxt
->channel
->band
);
1153 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1154 new_state
== IEEE80211_STA_AUTHORIZED
) {
1155 /* enable beacon filtering */
1156 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
));
1158 } else if (old_state
== IEEE80211_STA_AUTHORIZED
&&
1159 new_state
== IEEE80211_STA_ASSOC
) {
1160 /* disable beacon filtering */
1161 WARN_ON(iwl_mvm_disable_beacon_filter(mvm
, vif
));
1163 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1164 new_state
== IEEE80211_STA_AUTH
) {
1166 } else if (old_state
== IEEE80211_STA_AUTH
&&
1167 new_state
== IEEE80211_STA_NONE
) {
1169 } else if (old_state
== IEEE80211_STA_NONE
&&
1170 new_state
== IEEE80211_STA_NOTEXIST
) {
1171 ret
= iwl_mvm_rm_sta(mvm
, vif
, sta
);
1176 mutex_unlock(&mvm
->mutex
);
1181 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1183 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1185 mvm
->rts_threshold
= value
;
1190 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw
*hw
,
1191 struct ieee80211_vif
*vif
, u16 ac
,
1192 const struct ieee80211_tx_queue_params
*params
)
1194 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1195 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1197 mvmvif
->queue_params
[ac
] = *params
;
1200 * No need to update right away, we'll get BSS_CHANGED_QOS
1201 * The exception is P2P_DEVICE interface which needs immediate update.
1203 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1206 mutex_lock(&mvm
->mutex
);
1207 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
1208 mutex_unlock(&mvm
->mutex
);
1214 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw
*hw
,
1215 struct ieee80211_vif
*vif
)
1217 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1218 u32 duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS
,
1219 200 + vif
->bss_conf
.beacon_int
);
1220 u32 min_duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS
,
1221 100 + vif
->bss_conf
.beacon_int
);
1223 if (WARN_ON_ONCE(vif
->bss_conf
.assoc
))
1226 mutex_lock(&mvm
->mutex
);
1227 /* Try really hard to protect the session and hear a beacon */
1228 iwl_mvm_protect_session(mvm
, vif
, duration
, min_duration
, 500);
1229 mutex_unlock(&mvm
->mutex
);
1232 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw
*hw
,
1233 struct ieee80211_vif
*vif
,
1234 struct cfg80211_sched_scan_request
*req
,
1235 struct ieee80211_sched_scan_ies
*ies
)
1237 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1240 mutex_lock(&mvm
->mutex
);
1242 if (mvm
->scan_status
!= IWL_MVM_SCAN_NONE
) {
1244 "SCHED SCAN request during internal scan - abort\n");
1249 mvm
->scan_status
= IWL_MVM_SCAN_SCHED
;
1251 ret
= iwl_mvm_config_sched_scan(mvm
, vif
, req
, ies
);
1255 ret
= iwl_mvm_config_sched_scan_profiles(mvm
, req
);
1259 ret
= iwl_mvm_sched_scan_start(mvm
, req
);
1263 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
1265 mutex_unlock(&mvm
->mutex
);
1269 static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw
*hw
,
1270 struct ieee80211_vif
*vif
)
1272 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1274 mutex_lock(&mvm
->mutex
);
1275 iwl_mvm_sched_scan_stop(mvm
);
1276 mutex_unlock(&mvm
->mutex
);
1279 static int iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
1280 enum set_key_cmd cmd
,
1281 struct ieee80211_vif
*vif
,
1282 struct ieee80211_sta
*sta
,
1283 struct ieee80211_key_conf
*key
)
1285 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1288 if (iwlwifi_mod_params
.sw_crypto
) {
1289 IWL_DEBUG_MAC80211(mvm
, "leave - hwcrypto disabled\n");
1293 switch (key
->cipher
) {
1294 case WLAN_CIPHER_SUITE_TKIP
:
1295 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1297 case WLAN_CIPHER_SUITE_CCMP
:
1298 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1300 case WLAN_CIPHER_SUITE_AES_CMAC
:
1301 WARN_ON_ONCE(!(hw
->flags
& IEEE80211_HW_MFP_CAPABLE
));
1303 case WLAN_CIPHER_SUITE_WEP40
:
1304 case WLAN_CIPHER_SUITE_WEP104
:
1306 * Support for TX only, at least for now, so accept
1307 * the key and do nothing else. Then mac80211 will
1308 * pass it for TX but we don't have to use it for RX.
1315 mutex_lock(&mvm
->mutex
);
1319 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1320 vif
->type
== NL80211_IFTYPE_AP
) && !sta
) {
1322 * GTK on AP interface is a TX-only key, return 0;
1323 * on IBSS they're per-station and because we're lazy
1324 * we don't support them for RX, so do the same.
1327 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1331 IWL_DEBUG_MAC80211(mvm
, "set hwcrypto key\n");
1332 ret
= iwl_mvm_set_sta_key(mvm
, vif
, sta
, key
, false);
1334 IWL_WARN(mvm
, "set key failed\n");
1336 * can't add key for RX, but we don't need it
1337 * in the device for TX so still return 0
1339 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1345 if (key
->hw_key_idx
== STA_KEY_IDX_INVALID
) {
1350 IWL_DEBUG_MAC80211(mvm
, "disable hwcrypto key\n");
1351 ret
= iwl_mvm_remove_sta_key(mvm
, vif
, sta
, key
);
1357 mutex_unlock(&mvm
->mutex
);
1361 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw
*hw
,
1362 struct ieee80211_vif
*vif
,
1363 struct ieee80211_key_conf
*keyconf
,
1364 struct ieee80211_sta
*sta
,
1365 u32 iv32
, u16
*phase1key
)
1367 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1369 if (keyconf
->hw_key_idx
== STA_KEY_IDX_INVALID
)
1372 iwl_mvm_update_tkip_key(mvm
, vif
, keyconf
, sta
, iv32
, phase1key
);
1376 static int iwl_mvm_roc(struct ieee80211_hw
*hw
,
1377 struct ieee80211_vif
*vif
,
1378 struct ieee80211_channel
*channel
,
1380 enum ieee80211_roc_type type
)
1382 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1383 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1384 struct cfg80211_chan_def chandef
;
1385 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1388 IWL_DEBUG_MAC80211(mvm
, "enter (%d, %d, %d)\n", channel
->hw_value
,
1391 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
) {
1392 IWL_ERR(mvm
, "vif isn't a P2P_DEVICE: %d\n", vif
->type
);
1396 mutex_lock(&mvm
->mutex
);
1398 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
1399 phy_ctxt
= &mvm
->phy_ctxts
[i
];
1400 if (phy_ctxt
->ref
== 0 || mvmvif
->phy_ctxt
== phy_ctxt
)
1403 if (phy_ctxt
->ref
&& channel
== phy_ctxt
->channel
) {
1405 * Unbind the P2P_DEVICE from the current PHY context,
1406 * and if the PHY context is not used remove it.
1408 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1409 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1412 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1414 /* Bind the P2P_DEVICE to the current PHY Context */
1415 mvmvif
->phy_ctxt
= phy_ctxt
;
1417 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1418 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1421 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1422 goto schedule_time_event
;
1426 /* Need to update the PHY context only if the ROC channel changed */
1427 if (channel
== mvmvif
->phy_ctxt
->channel
)
1428 goto schedule_time_event
;
1430 cfg80211_chandef_create(&chandef
, channel
, NL80211_CHAN_NO_HT
);
1433 * Change the PHY context configuration as it is currently referenced
1434 * only by the P2P Device MAC
1436 if (mvmvif
->phy_ctxt
->ref
== 1) {
1437 ret
= iwl_mvm_phy_ctxt_changed(mvm
, mvmvif
->phy_ctxt
,
1443 * The PHY context is shared with other MACs. Need to remove the
1444 * P2P Device from the binding, allocate an new PHY context and
1445 * create a new binding
1447 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1453 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &chandef
,
1456 IWL_ERR(mvm
, "Failed to change PHY context\n");
1460 /* Unbind the P2P_DEVICE from the current PHY context */
1461 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1462 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1465 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1467 /* Bind the P2P_DEVICE to the new allocated PHY context */
1468 mvmvif
->phy_ctxt
= phy_ctxt
;
1470 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1471 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1474 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1477 schedule_time_event
:
1478 /* Schedule the time events */
1479 ret
= iwl_mvm_start_p2p_roc(mvm
, vif
, duration
, type
);
1482 mutex_unlock(&mvm
->mutex
);
1483 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1487 static int iwl_mvm_cancel_roc(struct ieee80211_hw
*hw
)
1489 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1491 IWL_DEBUG_MAC80211(mvm
, "enter\n");
1493 mutex_lock(&mvm
->mutex
);
1494 iwl_mvm_stop_p2p_roc(mvm
);
1495 mutex_unlock(&mvm
->mutex
);
1497 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1501 static int iwl_mvm_add_chanctx(struct ieee80211_hw
*hw
,
1502 struct ieee80211_chanctx_conf
*ctx
)
1504 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1505 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1506 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1509 IWL_DEBUG_MAC80211(mvm
, "Add channel context\n");
1511 mutex_lock(&mvm
->mutex
);
1512 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1518 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->def
,
1519 ctx
->rx_chains_static
,
1520 ctx
->rx_chains_dynamic
);
1522 IWL_ERR(mvm
, "Failed to add PHY context\n");
1526 iwl_mvm_phy_ctxt_ref(mvm
, phy_ctxt
);
1527 *phy_ctxt_id
= phy_ctxt
->id
;
1529 mutex_unlock(&mvm
->mutex
);
1533 static void iwl_mvm_remove_chanctx(struct ieee80211_hw
*hw
,
1534 struct ieee80211_chanctx_conf
*ctx
)
1536 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1537 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1538 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1540 mutex_lock(&mvm
->mutex
);
1541 iwl_mvm_phy_ctxt_unref(mvm
, phy_ctxt
);
1542 mutex_unlock(&mvm
->mutex
);
1545 static void iwl_mvm_change_chanctx(struct ieee80211_hw
*hw
,
1546 struct ieee80211_chanctx_conf
*ctx
,
1549 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1550 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1551 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1553 if (WARN_ONCE((phy_ctxt
->ref
> 1) &&
1554 (changed
& ~(IEEE80211_CHANCTX_CHANGE_WIDTH
|
1555 IEEE80211_CHANCTX_CHANGE_RX_CHAINS
|
1556 IEEE80211_CHANCTX_CHANGE_RADAR
)),
1557 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1558 phy_ctxt
->ref
, changed
))
1561 mutex_lock(&mvm
->mutex
);
1562 iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->def
,
1563 ctx
->rx_chains_static
,
1564 ctx
->rx_chains_dynamic
);
1565 iwl_mvm_bt_coex_vif_change(mvm
);
1566 mutex_unlock(&mvm
->mutex
);
1569 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw
*hw
,
1570 struct ieee80211_vif
*vif
,
1571 struct ieee80211_chanctx_conf
*ctx
)
1573 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1574 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1575 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1576 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1579 mutex_lock(&mvm
->mutex
);
1581 mvmvif
->phy_ctxt
= phy_ctxt
;
1583 switch (vif
->type
) {
1584 case NL80211_IFTYPE_AP
:
1585 case NL80211_IFTYPE_ADHOC
:
1587 * The AP binding flow is handled as part of the start_ap flow
1588 * (in bss_info_changed), similarly for IBSS.
1592 case NL80211_IFTYPE_STATION
:
1593 case NL80211_IFTYPE_MONITOR
:
1600 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1605 * Setting the quota at this stage is only required for monitor
1606 * interfaces. For the other types, the bss_info changed flow
1607 * will handle quota settings.
1609 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
1610 mvmvif
->monitor_active
= true;
1611 ret
= iwl_mvm_update_quotas(mvm
, vif
);
1613 goto out_remove_binding
;
1619 iwl_mvm_binding_remove_vif(mvm
, vif
);
1621 mutex_unlock(&mvm
->mutex
);
1623 mvmvif
->phy_ctxt
= NULL
;
1627 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
1628 struct ieee80211_vif
*vif
,
1629 struct ieee80211_chanctx_conf
*ctx
)
1631 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1632 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1634 mutex_lock(&mvm
->mutex
);
1636 iwl_mvm_remove_time_event(mvm
, mvmvif
, &mvmvif
->time_event_data
);
1638 switch (vif
->type
) {
1639 case NL80211_IFTYPE_AP
:
1640 case NL80211_IFTYPE_ADHOC
:
1642 case NL80211_IFTYPE_MONITOR
:
1643 mvmvif
->monitor_active
= false;
1644 iwl_mvm_update_quotas(mvm
, NULL
);
1650 iwl_mvm_binding_remove_vif(mvm
, vif
);
1652 mvmvif
->phy_ctxt
= NULL
;
1653 mutex_unlock(&mvm
->mutex
);
1656 static int iwl_mvm_set_tim(struct ieee80211_hw
*hw
,
1657 struct ieee80211_sta
*sta
,
1660 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1661 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
1663 if (!mvm_sta
|| !mvm_sta
->vif
) {
1664 IWL_ERR(mvm
, "Station is not associated to a vif\n");
1668 return iwl_mvm_mac_ctxt_beacon_changed(mvm
, mvm_sta
->vif
);
1671 #ifdef CONFIG_NL80211_TESTMODE
1672 static const struct nla_policy iwl_mvm_tm_policy
[IWL_MVM_TM_ATTR_MAX
+ 1] = {
1673 [IWL_MVM_TM_ATTR_CMD
] = { .type
= NLA_U32
},
1674 [IWL_MVM_TM_ATTR_NOA_DURATION
] = { .type
= NLA_U32
},
1675 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
] = { .type
= NLA_U32
},
1678 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm
*mvm
,
1679 struct ieee80211_vif
*vif
,
1680 void *data
, int len
)
1682 struct nlattr
*tb
[IWL_MVM_TM_ATTR_MAX
+ 1];
1686 err
= nla_parse(tb
, IWL_MVM_TM_ATTR_MAX
, data
, len
, iwl_mvm_tm_policy
);
1690 if (!tb
[IWL_MVM_TM_ATTR_CMD
])
1693 switch (nla_get_u32(tb
[IWL_MVM_TM_ATTR_CMD
])) {
1694 case IWL_MVM_TM_CMD_SET_NOA
:
1695 if (!vif
|| vif
->type
!= NL80211_IFTYPE_AP
|| !vif
->p2p
||
1696 !vif
->bss_conf
.enable_beacon
||
1697 !tb
[IWL_MVM_TM_ATTR_NOA_DURATION
])
1700 noa_duration
= nla_get_u32(tb
[IWL_MVM_TM_ATTR_NOA_DURATION
]);
1701 if (noa_duration
>= vif
->bss_conf
.beacon_int
)
1704 mvm
->noa_duration
= noa_duration
;
1707 return iwl_mvm_update_quotas(mvm
, NULL
);
1708 case IWL_MVM_TM_CMD_SET_BEACON_FILTER
:
1709 /* must be associated client vif - ignore authorized */
1710 if (!vif
|| vif
->type
!= NL80211_IFTYPE_STATION
||
1711 !vif
->bss_conf
.assoc
|| !vif
->bss_conf
.dtim_period
||
1712 !tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
])
1715 if (nla_get_u32(tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
]))
1716 return iwl_mvm_enable_beacon_filter(mvm
, vif
);
1717 return iwl_mvm_disable_beacon_filter(mvm
, vif
);
1723 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw
*hw
,
1724 struct ieee80211_vif
*vif
,
1725 void *data
, int len
)
1727 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1730 mutex_lock(&mvm
->mutex
);
1731 err
= __iwl_mvm_mac_testmode_cmd(mvm
, vif
, data
, len
);
1732 mutex_unlock(&mvm
->mutex
);
1738 struct ieee80211_ops iwl_mvm_hw_ops
= {
1739 .tx
= iwl_mvm_mac_tx
,
1740 .ampdu_action
= iwl_mvm_mac_ampdu_action
,
1741 .start
= iwl_mvm_mac_start
,
1742 .restart_complete
= iwl_mvm_mac_restart_complete
,
1743 .stop
= iwl_mvm_mac_stop
,
1744 .add_interface
= iwl_mvm_mac_add_interface
,
1745 .remove_interface
= iwl_mvm_mac_remove_interface
,
1746 .config
= iwl_mvm_mac_config
,
1747 .configure_filter
= iwl_mvm_configure_filter
,
1748 .bss_info_changed
= iwl_mvm_bss_info_changed
,
1749 .hw_scan
= iwl_mvm_mac_hw_scan
,
1750 .cancel_hw_scan
= iwl_mvm_mac_cancel_hw_scan
,
1751 .sta_state
= iwl_mvm_mac_sta_state
,
1752 .sta_notify
= iwl_mvm_mac_sta_notify
,
1753 .allow_buffered_frames
= iwl_mvm_mac_allow_buffered_frames
,
1754 .set_rts_threshold
= iwl_mvm_mac_set_rts_threshold
,
1755 .conf_tx
= iwl_mvm_mac_conf_tx
,
1756 .mgd_prepare_tx
= iwl_mvm_mac_mgd_prepare_tx
,
1757 .sched_scan_start
= iwl_mvm_mac_sched_scan_start
,
1758 .sched_scan_stop
= iwl_mvm_mac_sched_scan_stop
,
1759 .set_key
= iwl_mvm_mac_set_key
,
1760 .update_tkip_key
= iwl_mvm_mac_update_tkip_key
,
1761 .remain_on_channel
= iwl_mvm_roc
,
1762 .cancel_remain_on_channel
= iwl_mvm_cancel_roc
,
1763 .add_chanctx
= iwl_mvm_add_chanctx
,
1764 .remove_chanctx
= iwl_mvm_remove_chanctx
,
1765 .change_chanctx
= iwl_mvm_change_chanctx
,
1766 .assign_vif_chanctx
= iwl_mvm_assign_vif_chanctx
,
1767 .unassign_vif_chanctx
= iwl_mvm_unassign_vif_chanctx
,
1769 .start_ap
= iwl_mvm_start_ap_ibss
,
1770 .stop_ap
= iwl_mvm_stop_ap_ibss
,
1771 .join_ibss
= iwl_mvm_start_ap_ibss
,
1772 .leave_ibss
= iwl_mvm_stop_ap_ibss
,
1774 .set_tim
= iwl_mvm_set_tim
,
1776 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd
)
1778 #ifdef CONFIG_PM_SLEEP
1780 .suspend
= iwl_mvm_suspend
,
1781 .resume
= iwl_mvm_resume
,
1782 .set_wakeup
= iwl_mvm_set_wakeup
,
1783 .set_rekey_data
= iwl_mvm_set_rekey_data
,
1784 #if IS_ENABLED(CONFIG_IPV6)
1785 .ipv6_addr_change
= iwl_mvm_ipv6_addr_change
,
1787 .set_default_unicast_key
= iwl_mvm_set_default_unicast_key
,