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 int iwl_mvm_mac_setup_register(struct iwl_mvm
*mvm
)
144 struct ieee80211_hw
*hw
= mvm
->hw
;
147 /* Tell mac80211 our characteristics */
148 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
149 IEEE80211_HW_SPECTRUM_MGMT
|
150 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
151 IEEE80211_HW_QUEUE_CONTROL
|
152 IEEE80211_HW_WANT_MONITOR_VIF
|
153 IEEE80211_HW_SUPPORTS_PS
|
154 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
155 IEEE80211_HW_AMPDU_AGGREGATION
|
156 IEEE80211_HW_TIMING_BEACON_ONLY
|
157 IEEE80211_HW_CONNECTION_MONITOR
|
158 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS
|
159 IEEE80211_HW_SUPPORTS_STATIC_SMPS
|
160 IEEE80211_HW_SUPPORTS_UAPSD
;
162 hw
->queues
= IWL_MVM_FIRST_AGG_QUEUE
;
163 hw
->offchannel_tx_hw_queue
= IWL_MVM_OFFCHANNEL_QUEUE
;
164 hw
->rate_control_algorithm
= "iwl-mvm-rs";
167 * Enable 11w if advertised by firmware and software crypto
168 * is not enabled (as the firmware will interpret some mgmt
169 * packets, so enabling it with software crypto isn't safe)
171 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_MFP
&&
172 !iwlwifi_mod_params
.sw_crypto
)
173 hw
->flags
|= IEEE80211_HW_MFP_CAPABLE
;
175 hw
->sta_data_size
= sizeof(struct iwl_mvm_sta
);
176 hw
->vif_data_size
= sizeof(struct iwl_mvm_vif
);
177 hw
->chanctx_data_size
= sizeof(u16
);
179 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
180 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
181 BIT(NL80211_IFTYPE_AP
) |
182 BIT(NL80211_IFTYPE_P2P_GO
) |
183 BIT(NL80211_IFTYPE_P2P_DEVICE
);
185 hw
->wiphy
->flags
|= WIPHY_FLAG_CUSTOM_REGULATORY
|
186 WIPHY_FLAG_DISABLE_BEACON_HINTS
|
189 hw
->wiphy
->iface_combinations
= iwl_mvm_iface_combinations
;
190 hw
->wiphy
->n_iface_combinations
=
191 ARRAY_SIZE(iwl_mvm_iface_combinations
);
193 hw
->wiphy
->max_remain_on_channel_duration
= 10000;
194 hw
->max_listen_interval
= IWL_CONN_MAX_LISTEN_INTERVAL
;
195 hw
->uapsd_queues
= IWL_UAPSD_AC_INFO
;
196 hw
->uapsd_max_sp_len
= IWL_UAPSD_MAX_SP
;
198 /* Extract MAC address */
199 memcpy(mvm
->addresses
[0].addr
, mvm
->nvm_data
->hw_addr
, ETH_ALEN
);
200 hw
->wiphy
->addresses
= mvm
->addresses
;
201 hw
->wiphy
->n_addresses
= 1;
203 /* Extract additional MAC addresses if available */
204 num_mac
= (mvm
->nvm_data
->n_hw_addrs
> 1) ?
205 min(IWL_MVM_MAX_ADDRESSES
, mvm
->nvm_data
->n_hw_addrs
) : 1;
207 for (i
= 1; i
< num_mac
; i
++) {
208 memcpy(mvm
->addresses
[i
].addr
, mvm
->addresses
[i
-1].addr
,
210 mvm
->addresses
[i
].addr
[5]++;
211 hw
->wiphy
->n_addresses
++;
214 iwl_mvm_reset_phy_ctxts(mvm
);
216 /* we create the 802.11 header and a max-length SSID element */
217 hw
->wiphy
->max_scan_ie_len
=
218 mvm
->fw
->ucode_capa
.max_probe_length
- 24 - 34;
219 hw
->wiphy
->max_scan_ssids
= PROBE_OPTION_MAX
;
221 if (mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
222 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
223 &mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
];
224 if (mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
225 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
226 &mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
];
228 hw
->wiphy
->hw_version
= mvm
->trans
->hw_id
;
230 if (iwlmvm_mod_params
.power_scheme
!= IWL_POWER_SCHEME_CAM
)
231 hw
->wiphy
->flags
|= WIPHY_FLAG_PS_ON_BY_DEFAULT
;
233 hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
235 hw
->wiphy
->features
|= NL80211_FEATURE_P2P_GO_CTWIN
|
236 NL80211_FEATURE_P2P_GO_OPPPS
;
238 mvm
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
240 #ifdef CONFIG_PM_SLEEP
241 if (mvm
->fw
->img
[IWL_UCODE_WOWLAN
].sec
[0].len
&&
242 mvm
->trans
->ops
->d3_suspend
&&
243 mvm
->trans
->ops
->d3_resume
&&
244 device_can_wakeup(mvm
->trans
->dev
)) {
245 mvm
->wowlan
.flags
= WIPHY_WOWLAN_MAGIC_PKT
|
246 WIPHY_WOWLAN_DISCONNECT
|
247 WIPHY_WOWLAN_EAP_IDENTITY_REQ
|
248 WIPHY_WOWLAN_RFKILL_RELEASE
;
249 if (!iwlwifi_mod_params
.sw_crypto
)
250 mvm
->wowlan
.flags
|= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
|
251 WIPHY_WOWLAN_GTK_REKEY_FAILURE
|
252 WIPHY_WOWLAN_4WAY_HANDSHAKE
;
254 mvm
->wowlan
.n_patterns
= IWL_WOWLAN_MAX_PATTERNS
;
255 mvm
->wowlan
.pattern_min_len
= IWL_WOWLAN_MIN_PATTERN_LEN
;
256 mvm
->wowlan
.pattern_max_len
= IWL_WOWLAN_MAX_PATTERN_LEN
;
257 mvm
->wowlan
.tcp
= &iwl_mvm_wowlan_tcp_support
;
258 hw
->wiphy
->wowlan
= &mvm
->wowlan
;
262 ret
= iwl_mvm_leds_init(mvm
);
266 ret
= ieee80211_register_hw(mvm
->hw
);
268 iwl_mvm_leds_exit(mvm
);
273 static void iwl_mvm_mac_tx(struct ieee80211_hw
*hw
,
274 struct ieee80211_tx_control
*control
,
277 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
279 if (iwl_mvm_is_radio_killed(mvm
)) {
280 IWL_DEBUG_DROP(mvm
, "Dropping - RF/CT KILL\n");
284 if (IEEE80211_SKB_CB(skb
)->hw_queue
== IWL_MVM_OFFCHANNEL_QUEUE
&&
285 !test_bit(IWL_MVM_STATUS_ROC_RUNNING
, &mvm
->status
))
289 if (iwl_mvm_tx_skb(mvm
, skb
, control
->sta
))
294 if (iwl_mvm_tx_skb_non_sta(mvm
, skb
))
298 ieee80211_free_txskb(hw
, skb
);
301 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw
*hw
,
302 struct ieee80211_vif
*vif
,
303 enum ieee80211_ampdu_mlme_action action
,
304 struct ieee80211_sta
*sta
, u16 tid
,
305 u16
*ssn
, u8 buf_size
)
307 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
310 IWL_DEBUG_HT(mvm
, "A-MPDU action on addr %pM tid %d: action %d\n",
311 sta
->addr
, tid
, action
);
313 if (!(mvm
->nvm_data
->sku_cap_11n_enable
))
316 mutex_lock(&mvm
->mutex
);
319 case IEEE80211_AMPDU_RX_START
:
320 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_RXAGG
) {
324 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, *ssn
, true);
326 case IEEE80211_AMPDU_RX_STOP
:
327 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, 0, false);
329 case IEEE80211_AMPDU_TX_START
:
330 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_TXAGG
) {
334 ret
= iwl_mvm_sta_tx_agg_start(mvm
, vif
, sta
, tid
, ssn
);
336 case IEEE80211_AMPDU_TX_STOP_CONT
:
337 ret
= iwl_mvm_sta_tx_agg_stop(mvm
, vif
, sta
, tid
);
339 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
340 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
341 ret
= iwl_mvm_sta_tx_agg_flush(mvm
, vif
, sta
, tid
);
343 case IEEE80211_AMPDU_TX_OPERATIONAL
:
344 ret
= iwl_mvm_sta_tx_agg_oper(mvm
, vif
, sta
, tid
, buf_size
);
351 mutex_unlock(&mvm
->mutex
);
356 static void iwl_mvm_cleanup_iterator(void *data
, u8
*mac
,
357 struct ieee80211_vif
*vif
)
359 struct iwl_mvm
*mvm
= data
;
360 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
362 mvmvif
->uploaded
= false;
363 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
365 /* does this make sense at all? */
368 spin_lock_bh(&mvm
->time_event_lock
);
369 iwl_mvm_te_clear_data(mvm
, &mvmvif
->time_event_data
);
370 spin_unlock_bh(&mvm
->time_event_lock
);
372 mvmvif
->phy_ctxt
= NULL
;
375 static void iwl_mvm_restart_cleanup(struct iwl_mvm
*mvm
)
377 iwl_trans_stop_device(mvm
->trans
);
378 iwl_trans_stop_hw(mvm
->trans
, false);
380 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
382 /* just in case one was running */
383 ieee80211_remain_on_channel_expired(mvm
->hw
);
385 ieee80211_iterate_active_interfaces_atomic(
386 mvm
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
387 iwl_mvm_cleanup_iterator
, mvm
);
389 mvm
->p2p_device_vif
= NULL
;
391 iwl_mvm_reset_phy_ctxts(mvm
);
392 memset(mvm
->fw_key_table
, 0, sizeof(mvm
->fw_key_table
));
393 memset(mvm
->sta_drained
, 0, sizeof(mvm
->sta_drained
));
395 ieee80211_wake_queues(mvm
->hw
);
398 mvm
->rx_ba_sessions
= 0;
401 static int iwl_mvm_mac_start(struct ieee80211_hw
*hw
)
403 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
406 mutex_lock(&mvm
->mutex
);
408 /* Clean up some internal and mac80211 state on restart */
409 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
410 iwl_mvm_restart_cleanup(mvm
);
412 ret
= iwl_mvm_up(mvm
);
413 mutex_unlock(&mvm
->mutex
);
418 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw
*hw
)
420 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
423 mutex_lock(&mvm
->mutex
);
425 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
426 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
428 IWL_ERR(mvm
, "Failed to update quotas after restart (%d)\n",
431 mutex_unlock(&mvm
->mutex
);
434 static void iwl_mvm_mac_stop(struct ieee80211_hw
*hw
)
436 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
438 flush_work(&mvm
->async_handlers_wk
);
440 mutex_lock(&mvm
->mutex
);
441 /* async_handlers_wk is now blocked */
444 * The work item could be running or queued if the
445 * ROC time event stops just as we get here.
447 cancel_work_sync(&mvm
->roc_done_wk
);
449 iwl_trans_stop_device(mvm
->trans
);
450 iwl_trans_stop_hw(mvm
->trans
, false);
452 iwl_mvm_async_handlers_purge(mvm
);
453 /* async_handlers_list is empty and will stay empty: HW is stopped */
455 /* the fw is stopped, the aux sta is dead: clean up driver state */
456 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
458 mutex_unlock(&mvm
->mutex
);
461 * The worker might have been waiting for the mutex, let it run and
462 * discover that its list is now empty.
464 cancel_work_sync(&mvm
->async_handlers_wk
);
467 static void iwl_mvm_pm_disable_iterator(void *data
, u8
*mac
,
468 struct ieee80211_vif
*vif
)
470 struct iwl_mvm
*mvm
= data
;
473 ret
= iwl_mvm_power_disable(mvm
, vif
);
475 IWL_ERR(mvm
, "failed to disable power management\n");
478 static void iwl_mvm_power_update_iterator(void *data
, u8
*mac
,
479 struct ieee80211_vif
*vif
)
481 struct iwl_mvm
*mvm
= data
;
483 iwl_mvm_power_update_mode(mvm
, vif
);
486 static struct iwl_mvm_phy_ctxt
*iwl_mvm_get_free_phy_ctxt(struct iwl_mvm
*mvm
)
490 lockdep_assert_held(&mvm
->mutex
);
492 for (i
= 0; i
< NUM_PHY_CTX
; i
++)
493 if (!mvm
->phy_ctxts
[i
].ref
)
494 return &mvm
->phy_ctxts
[i
];
496 IWL_ERR(mvm
, "No available PHY context\n");
500 static int iwl_mvm_mac_add_interface(struct ieee80211_hw
*hw
,
501 struct ieee80211_vif
*vif
)
503 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
504 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
508 * Not much to do here. The stack will not allow interface
509 * types or combinations that we didn't advertise, so we
510 * don't really have to check the types.
513 mutex_lock(&mvm
->mutex
);
515 /* Allocate resources for the MAC context, and add it to the fw */
516 ret
= iwl_mvm_mac_ctxt_init(mvm
, vif
);
521 * TODO: remove this temporary code.
522 * Currently MVM FW supports power management only on single MAC.
523 * If new interface added, disable PM on existing interface.
524 * P2P device is a special case, since it is handled by FW similary to
525 * scan. If P2P deviced is added, PM remains enabled on existing
527 * Note: the method below does not count the new interface being added
530 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
532 if (mvm
->vif_count
> 1) {
533 IWL_DEBUG_MAC80211(mvm
,
534 "Disable power on existing interfaces\n");
535 ieee80211_iterate_active_interfaces_atomic(
537 IEEE80211_IFACE_ITER_NORMAL
,
538 iwl_mvm_pm_disable_iterator
, mvm
);
542 * The AP binding flow can be done only after the beacon
543 * template is configured (which happens only in the mac80211
544 * start_ap() flow), and adding the broadcast station can happen
545 * only after the binding.
546 * In addition, since modifying the MAC before adding a bcast
547 * station is not allowed by the FW, delay the adding of MAC context to
548 * the point where we can also add the bcast station.
549 * In short: there's not much we can do at this point, other than
550 * allocating resources :)
552 if (vif
->type
== NL80211_IFTYPE_AP
) {
553 u32 qmask
= iwl_mvm_mac_get_queues_mask(mvm
, vif
);
554 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->bcast_sta
,
557 IWL_ERR(mvm
, "Failed to allocate bcast sta\n");
561 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
565 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
570 * Update power state on the new interface. Admittedly, based on
571 * mac80211 logics this power update will disable power management
573 iwl_mvm_power_update_mode(mvm
, vif
);
575 /* beacon filtering */
576 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
);
580 if (!mvm
->bf_allowed_vif
&&
581 vif
->type
== NL80211_IFTYPE_STATION
&& !vif
->p2p
&&
582 mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BF_UPDATED
){
583 mvm
->bf_allowed_vif
= mvmvif
;
584 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
585 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
589 * P2P_DEVICE interface does not have a channel context assigned to it,
590 * so a dedicated PHY context is allocated to it and the corresponding
591 * MAC context is bound to it at this stage.
593 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
595 mvmvif
->phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
596 if (!mvmvif
->phy_ctxt
) {
601 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
602 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
606 ret
= iwl_mvm_add_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
610 /* Save a pointer to p2p device vif, so it can later be used to
611 * update the p2p device MAC when a GO is started/stopped */
612 mvm
->p2p_device_vif
= vif
;
615 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
619 iwl_mvm_binding_remove_vif(mvm
, vif
);
621 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
623 if (mvm
->bf_allowed_vif
== mvmvif
) {
624 mvm
->bf_allowed_vif
= NULL
;
625 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
626 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
629 mvmvif
->phy_ctxt
= NULL
;
630 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
632 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
634 ieee80211_iterate_active_interfaces(
635 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
636 iwl_mvm_power_update_iterator
, mvm
);
637 iwl_mvm_mac_ctxt_release(mvm
, vif
);
639 mutex_unlock(&mvm
->mutex
);
644 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm
*mvm
,
645 struct ieee80211_vif
*vif
)
649 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
650 if (vif
->hw_queue
[ac
] != IEEE80211_INVAL_HW_QUEUE
)
651 tfd_msk
|= BIT(vif
->hw_queue
[ac
]);
653 if (vif
->cab_queue
!= IEEE80211_INVAL_HW_QUEUE
)
654 tfd_msk
|= BIT(vif
->cab_queue
);
657 mutex_lock(&mvm
->mutex
);
658 iwl_mvm_flush_tx_path(mvm
, tfd_msk
, true);
659 mutex_unlock(&mvm
->mutex
);
662 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
664 * Flush the ROC worker which will flush the OFFCHANNEL queue.
665 * We assume here that all the packets sent to the OFFCHANNEL
666 * queue are sent in ROC session.
668 flush_work(&mvm
->roc_done_wk
);
671 * By now, all the AC queues are empty. The AGG queues are
672 * empty too. We already got all the Tx responses for all the
673 * packets in the queues. The drain work can have been
674 * triggered. Flush it.
676 flush_work(&mvm
->sta_drained_wk
);
680 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw
*hw
,
681 struct ieee80211_vif
*vif
)
683 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
684 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
686 iwl_mvm_prepare_mac_removal(mvm
, vif
);
688 mutex_lock(&mvm
->mutex
);
690 if (mvm
->bf_allowed_vif
== mvmvif
) {
691 mvm
->bf_allowed_vif
= NULL
;
692 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
693 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
696 iwl_mvm_vif_dbgfs_clean(mvm
, vif
);
699 * For AP/GO interface, the tear down of the resources allocated to the
700 * interface is be handled as part of the stop_ap flow.
702 if (vif
->type
== NL80211_IFTYPE_AP
) {
703 #ifdef CONFIG_NL80211_TESTMODE
704 if (vif
== mvm
->noa_vif
) {
706 mvm
->noa_duration
= 0;
709 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->bcast_sta
);
713 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
714 mvm
->p2p_device_vif
= NULL
;
715 iwl_mvm_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
716 iwl_mvm_binding_remove_vif(mvm
, vif
);
717 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
718 mvmvif
->phy_ctxt
= NULL
;
722 * TODO: remove this temporary code.
723 * Currently MVM FW supports power management only on single MAC.
724 * Check if only one additional interface remains after removing
725 * current one. Update power mode on the remaining interface.
727 if (mvm
->vif_count
&& vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
729 IWL_DEBUG_MAC80211(mvm
, "Currently %d interfaces active\n",
731 if (mvm
->vif_count
== 1) {
732 ieee80211_iterate_active_interfaces(
733 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
734 iwl_mvm_power_update_iterator
, mvm
);
737 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
740 iwl_mvm_mac_ctxt_release(mvm
, vif
);
741 mutex_unlock(&mvm
->mutex
);
744 static int iwl_mvm_set_tx_power(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
747 /* FW is in charge of regulatory enforcement */
748 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd
= {
749 .mac_context_id
= iwl_mvm_vif_from_mac80211(vif
)->id
,
750 .pwr_restriction
= cpu_to_le16(tx_power
),
753 return iwl_mvm_send_cmd_pdu(mvm
, REDUCE_TX_POWER_CMD
, CMD_SYNC
,
754 sizeof(reduce_txpwr_cmd
),
758 static int iwl_mvm_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
763 static void iwl_mvm_configure_filter(struct ieee80211_hw
*hw
,
764 unsigned int changed_flags
,
765 unsigned int *total_flags
,
771 static int iwl_mvm_configure_mcast_filter(struct iwl_mvm
*mvm
,
772 struct ieee80211_vif
*vif
)
774 struct iwl_mcast_filter_cmd mcast_filter_cmd
= {
778 memcpy(mcast_filter_cmd
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
780 return iwl_mvm_send_cmd_pdu(mvm
, MCAST_FILTER_CMD
, CMD_SYNC
,
781 sizeof(mcast_filter_cmd
),
785 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm
*mvm
,
786 struct ieee80211_vif
*vif
,
787 struct ieee80211_bss_conf
*bss_conf
,
790 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
793 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
795 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
797 if (changes
& BSS_CHANGED_ASSOC
) {
798 if (bss_conf
->assoc
) {
799 /* add quota for this interface */
800 ret
= iwl_mvm_update_quotas(mvm
, vif
);
802 IWL_ERR(mvm
, "failed to update quotas\n");
805 iwl_mvm_configure_mcast_filter(mvm
, vif
);
807 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
,
810 * If we're restarting then the firmware will
811 * obviously have lost synchronisation with
812 * the AP. It will attempt to synchronise by
813 * itself, but we can make it more reliable by
814 * scheduling a session protection time event.
816 * The firmware needs to receive a beacon to
817 * catch up with synchronisation, use 110% of
818 * the beacon interval.
820 * Set a large maximum delay to allow for more
821 * than a single interface.
823 u32 dur
= (11 * vif
->bss_conf
.beacon_int
) / 10;
824 iwl_mvm_protect_session(mvm
, vif
, dur
, dur
,
827 } else if (mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
828 /* remove AP station now that the MAC is unassoc */
829 ret
= iwl_mvm_rm_sta_id(mvm
, vif
, mvmvif
->ap_sta_id
);
831 IWL_ERR(mvm
, "failed to remove AP station\n");
832 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
833 /* remove quota for this interface */
834 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
836 IWL_ERR(mvm
, "failed to update quotas\n");
839 /* reset rssi values */
840 mvmvif
->bf_data
.ave_beacon_signal
= 0;
842 if (!(mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_UAPSD
)) {
843 /* Workaround for FW bug, otherwise FW disables device
844 * power save upon disassociation
846 ret
= iwl_mvm_power_update_mode(mvm
, vif
);
848 IWL_ERR(mvm
, "failed to update power mode\n");
850 iwl_mvm_bt_coex_vif_assoc(mvm
, vif
);
851 } else if (changes
& BSS_CHANGED_BEACON_INFO
) {
853 * We received a beacon _after_ association so
854 * remove the session protection.
856 iwl_mvm_remove_time_event(mvm
, mvmvif
,
857 &mvmvif
->time_event_data
);
858 } else if (changes
& (BSS_CHANGED_PS
| BSS_CHANGED_QOS
)) {
859 ret
= iwl_mvm_power_update_mode(mvm
, vif
);
861 IWL_ERR(mvm
, "failed to update power mode\n");
863 if (changes
& BSS_CHANGED_TXPOWER
) {
864 IWL_DEBUG_CALIB(mvm
, "Changing TX Power to %d\n",
866 iwl_mvm_set_tx_power(mvm
, vif
, bss_conf
->txpower
);
869 if (changes
& BSS_CHANGED_CQM
) {
870 IWL_DEBUG_MAC80211(mvm
, "cqm info_changed");
871 /* reset cqm events tracking */
872 mvmvif
->bf_data
.last_cqm_event
= 0;
873 ret
= iwl_mvm_update_beacon_filter(mvm
, vif
);
875 IWL_ERR(mvm
, "failed to update CQM thresholds\n");
879 static int iwl_mvm_start_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
881 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
882 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
885 mutex_lock(&mvm
->mutex
);
887 /* Send the beacon template */
888 ret
= iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
);
892 /* Add the mac context */
893 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
897 /* Perform the binding */
898 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
902 mvmvif
->ap_active
= true;
904 /* Send the bcast station. At this stage the TBTT and DTIM time events
905 * are added and applied to the scheduler */
906 ret
= iwl_mvm_send_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
910 ret
= iwl_mvm_update_quotas(mvm
, vif
);
914 /* Need to update the P2P Device MAC */
915 if (vif
->p2p
&& mvm
->p2p_device_vif
)
916 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
918 mutex_unlock(&mvm
->mutex
);
922 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
924 iwl_mvm_binding_remove_vif(mvm
, vif
);
926 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
928 mutex_unlock(&mvm
->mutex
);
932 static void iwl_mvm_stop_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
934 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
935 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
937 iwl_mvm_prepare_mac_removal(mvm
, vif
);
939 mutex_lock(&mvm
->mutex
);
941 mvmvif
->ap_active
= false;
943 /* Need to update the P2P Device MAC */
944 if (vif
->p2p
&& mvm
->p2p_device_vif
)
945 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
947 iwl_mvm_update_quotas(mvm
, NULL
);
948 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
949 iwl_mvm_binding_remove_vif(mvm
, vif
);
950 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
952 mutex_unlock(&mvm
->mutex
);
955 static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm
*mvm
,
956 struct ieee80211_vif
*vif
,
957 struct ieee80211_bss_conf
*bss_conf
,
960 /* Need to send a new beacon template to the FW */
961 if (changes
& BSS_CHANGED_BEACON
) {
962 if (iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
))
963 IWL_WARN(mvm
, "Failed updating beacon data\n");
967 static void iwl_mvm_bss_info_changed(struct ieee80211_hw
*hw
,
968 struct ieee80211_vif
*vif
,
969 struct ieee80211_bss_conf
*bss_conf
,
972 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
974 mutex_lock(&mvm
->mutex
);
977 case NL80211_IFTYPE_STATION
:
978 iwl_mvm_bss_info_changed_station(mvm
, vif
, bss_conf
, changes
);
980 case NL80211_IFTYPE_AP
:
981 iwl_mvm_bss_info_changed_ap(mvm
, vif
, bss_conf
, changes
);
984 /* shouldn't happen */
988 mutex_unlock(&mvm
->mutex
);
991 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw
*hw
,
992 struct ieee80211_vif
*vif
,
993 struct cfg80211_scan_request
*req
)
995 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
998 if (req
->n_channels
== 0 || req
->n_channels
> MAX_NUM_SCAN_CHANNELS
)
1001 mutex_lock(&mvm
->mutex
);
1003 if (mvm
->scan_status
== IWL_MVM_SCAN_NONE
)
1004 ret
= iwl_mvm_scan_request(mvm
, vif
, req
);
1008 mutex_unlock(&mvm
->mutex
);
1013 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw
*hw
,
1014 struct ieee80211_vif
*vif
)
1016 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1018 mutex_lock(&mvm
->mutex
);
1020 iwl_mvm_cancel_scan(mvm
);
1022 mutex_unlock(&mvm
->mutex
);
1026 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw
*hw
,
1027 struct ieee80211_sta
*sta
, u16 tid
,
1029 enum ieee80211_frame_release_type reason
,
1032 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1034 /* TODO: how do we tell the fw to send frames for a specific TID */
1037 * The fw will send EOSP notification when the last frame will be
1040 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
);
1043 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw
*hw
,
1044 struct ieee80211_vif
*vif
,
1045 enum sta_notify_cmd cmd
,
1046 struct ieee80211_sta
*sta
)
1048 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1049 struct iwl_mvm_sta
*mvmsta
= (void *)sta
->drv_priv
;
1052 case STA_NOTIFY_SLEEP
:
1053 if (atomic_read(&mvm
->pending_frames
[mvmsta
->sta_id
]) > 0)
1054 ieee80211_sta_block_awake(hw
, sta
, true);
1056 * The fw updates the STA to be asleep. Tx packets on the Tx
1057 * queues to this station will not be transmitted. The fw will
1058 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1061 case STA_NOTIFY_AWAKE
:
1062 if (WARN_ON(mvmsta
->sta_id
== IWL_MVM_STATION_COUNT
))
1064 iwl_mvm_sta_modify_ps_wake(mvm
, sta
);
1071 static int iwl_mvm_mac_sta_state(struct ieee80211_hw
*hw
,
1072 struct ieee80211_vif
*vif
,
1073 struct ieee80211_sta
*sta
,
1074 enum ieee80211_sta_state old_state
,
1075 enum ieee80211_sta_state new_state
)
1077 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1078 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1081 IWL_DEBUG_MAC80211(mvm
, "station %pM state change %d->%d\n",
1082 sta
->addr
, old_state
, new_state
);
1084 /* this would be a mac80211 bug ... but don't crash */
1085 if (WARN_ON_ONCE(!mvmvif
->phy_ctxt
))
1088 /* if a STA is being removed, reuse its ID */
1089 flush_work(&mvm
->sta_drained_wk
);
1091 mutex_lock(&mvm
->mutex
);
1092 if (old_state
== IEEE80211_STA_NOTEXIST
&&
1093 new_state
== IEEE80211_STA_NONE
) {
1095 * Firmware bug - it'll crash if the beacon interval is less
1096 * than 16. We can't avoid connecting at all, so refuse the
1097 * station state change, this will cause mac80211 to abandon
1098 * attempts to connect to this AP, and eventually wpa_s will
1099 * blacklist the AP...
1101 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1102 vif
->bss_conf
.beacon_int
< 16) {
1104 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1105 sta
->addr
, vif
->bss_conf
.beacon_int
);
1109 ret
= iwl_mvm_add_sta(mvm
, vif
, sta
);
1110 } else if (old_state
== IEEE80211_STA_NONE
&&
1111 new_state
== IEEE80211_STA_AUTH
) {
1113 } else if (old_state
== IEEE80211_STA_AUTH
&&
1114 new_state
== IEEE80211_STA_ASSOC
) {
1115 ret
= iwl_mvm_update_sta(mvm
, vif
, sta
);
1117 iwl_mvm_rs_rate_init(mvm
, sta
,
1118 mvmvif
->phy_ctxt
->channel
->band
);
1119 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1120 new_state
== IEEE80211_STA_AUTHORIZED
) {
1121 /* enable beacon filtering */
1122 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
));
1124 } else if (old_state
== IEEE80211_STA_AUTHORIZED
&&
1125 new_state
== IEEE80211_STA_ASSOC
) {
1126 /* disable beacon filtering */
1127 WARN_ON(iwl_mvm_disable_beacon_filter(mvm
, vif
));
1129 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1130 new_state
== IEEE80211_STA_AUTH
) {
1132 } else if (old_state
== IEEE80211_STA_AUTH
&&
1133 new_state
== IEEE80211_STA_NONE
) {
1135 } else if (old_state
== IEEE80211_STA_NONE
&&
1136 new_state
== IEEE80211_STA_NOTEXIST
) {
1137 ret
= iwl_mvm_rm_sta(mvm
, vif
, sta
);
1142 mutex_unlock(&mvm
->mutex
);
1147 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1149 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1151 mvm
->rts_threshold
= value
;
1156 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw
*hw
,
1157 struct ieee80211_vif
*vif
, u16 ac
,
1158 const struct ieee80211_tx_queue_params
*params
)
1160 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1161 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1163 mvmvif
->queue_params
[ac
] = *params
;
1166 * No need to update right away, we'll get BSS_CHANGED_QOS
1167 * The exception is P2P_DEVICE interface which needs immediate update.
1169 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1172 mutex_lock(&mvm
->mutex
);
1173 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
1174 mutex_unlock(&mvm
->mutex
);
1180 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw
*hw
,
1181 struct ieee80211_vif
*vif
)
1183 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1184 u32 duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS
,
1185 200 + vif
->bss_conf
.beacon_int
);
1186 u32 min_duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS
,
1187 100 + vif
->bss_conf
.beacon_int
);
1189 if (WARN_ON_ONCE(vif
->bss_conf
.assoc
))
1192 mutex_lock(&mvm
->mutex
);
1193 /* Try really hard to protect the session and hear a beacon */
1194 iwl_mvm_protect_session(mvm
, vif
, duration
, min_duration
, 500);
1195 mutex_unlock(&mvm
->mutex
);
1198 static int iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
1199 enum set_key_cmd cmd
,
1200 struct ieee80211_vif
*vif
,
1201 struct ieee80211_sta
*sta
,
1202 struct ieee80211_key_conf
*key
)
1204 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1207 if (iwlwifi_mod_params
.sw_crypto
) {
1208 IWL_DEBUG_MAC80211(mvm
, "leave - hwcrypto disabled\n");
1212 switch (key
->cipher
) {
1213 case WLAN_CIPHER_SUITE_TKIP
:
1214 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1216 case WLAN_CIPHER_SUITE_CCMP
:
1217 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1219 case WLAN_CIPHER_SUITE_AES_CMAC
:
1220 WARN_ON_ONCE(!(hw
->flags
& IEEE80211_HW_MFP_CAPABLE
));
1222 case WLAN_CIPHER_SUITE_WEP40
:
1223 case WLAN_CIPHER_SUITE_WEP104
:
1225 * Support for TX only, at least for now, so accept
1226 * the key and do nothing else. Then mac80211 will
1227 * pass it for TX but we don't have to use it for RX.
1234 mutex_lock(&mvm
->mutex
);
1238 if (vif
->type
== NL80211_IFTYPE_AP
&& !sta
) {
1239 /* GTK on AP interface is a TX-only key, return 0 */
1241 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1245 IWL_DEBUG_MAC80211(mvm
, "set hwcrypto key\n");
1246 ret
= iwl_mvm_set_sta_key(mvm
, vif
, sta
, key
, false);
1248 IWL_WARN(mvm
, "set key failed\n");
1250 * can't add key for RX, but we don't need it
1251 * in the device for TX so still return 0
1253 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1259 if (key
->hw_key_idx
== STA_KEY_IDX_INVALID
) {
1264 IWL_DEBUG_MAC80211(mvm
, "disable hwcrypto key\n");
1265 ret
= iwl_mvm_remove_sta_key(mvm
, vif
, sta
, key
);
1271 mutex_unlock(&mvm
->mutex
);
1275 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw
*hw
,
1276 struct ieee80211_vif
*vif
,
1277 struct ieee80211_key_conf
*keyconf
,
1278 struct ieee80211_sta
*sta
,
1279 u32 iv32
, u16
*phase1key
)
1281 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1283 iwl_mvm_update_tkip_key(mvm
, vif
, keyconf
, sta
, iv32
, phase1key
);
1287 static int iwl_mvm_roc(struct ieee80211_hw
*hw
,
1288 struct ieee80211_vif
*vif
,
1289 struct ieee80211_channel
*channel
,
1291 enum ieee80211_roc_type type
)
1293 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1294 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1295 struct cfg80211_chan_def chandef
;
1296 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1299 IWL_DEBUG_MAC80211(mvm
, "enter (%d, %d, %d)\n", channel
->hw_value
,
1302 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
) {
1303 IWL_ERR(mvm
, "vif isn't a P2P_DEVICE: %d\n", vif
->type
);
1307 mutex_lock(&mvm
->mutex
);
1309 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
1310 phy_ctxt
= &mvm
->phy_ctxts
[i
];
1311 if (phy_ctxt
->ref
== 0 || mvmvif
->phy_ctxt
== phy_ctxt
)
1314 if (phy_ctxt
->ref
&& channel
== phy_ctxt
->channel
) {
1316 * Unbind the P2P_DEVICE from the current PHY context,
1317 * and if the PHY context is not used remove it.
1319 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1320 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1323 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1325 /* Bind the P2P_DEVICE to the current PHY Context */
1326 mvmvif
->phy_ctxt
= phy_ctxt
;
1328 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1329 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1332 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1333 goto schedule_time_event
;
1337 /* Need to update the PHY context only if the ROC channel changed */
1338 if (channel
== mvmvif
->phy_ctxt
->channel
)
1339 goto schedule_time_event
;
1341 cfg80211_chandef_create(&chandef
, channel
, NL80211_CHAN_NO_HT
);
1344 * Change the PHY context configuration as it is currently referenced
1345 * only by the P2P Device MAC
1347 if (mvmvif
->phy_ctxt
->ref
== 1) {
1348 ret
= iwl_mvm_phy_ctxt_changed(mvm
, mvmvif
->phy_ctxt
,
1354 * The PHY context is shared with other MACs. Need to remove the
1355 * P2P Device from the binding, allocate an new PHY context and
1356 * create a new binding
1358 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1364 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &chandef
,
1367 IWL_ERR(mvm
, "Failed to change PHY context\n");
1371 /* Unbind the P2P_DEVICE from the current PHY context */
1372 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1373 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1376 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1378 /* Bind the P2P_DEVICE to the new allocated PHY context */
1379 mvmvif
->phy_ctxt
= phy_ctxt
;
1381 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1382 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1385 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1388 schedule_time_event
:
1389 /* Schedule the time events */
1390 ret
= iwl_mvm_start_p2p_roc(mvm
, vif
, duration
, type
);
1393 mutex_unlock(&mvm
->mutex
);
1394 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1398 static int iwl_mvm_cancel_roc(struct ieee80211_hw
*hw
)
1400 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1402 IWL_DEBUG_MAC80211(mvm
, "enter\n");
1404 mutex_lock(&mvm
->mutex
);
1405 iwl_mvm_stop_p2p_roc(mvm
);
1406 mutex_unlock(&mvm
->mutex
);
1408 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1412 static int iwl_mvm_add_chanctx(struct ieee80211_hw
*hw
,
1413 struct ieee80211_chanctx_conf
*ctx
)
1415 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1416 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1417 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1420 IWL_DEBUG_MAC80211(mvm
, "Add channel context\n");
1422 mutex_lock(&mvm
->mutex
);
1423 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1429 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->def
,
1430 ctx
->rx_chains_static
,
1431 ctx
->rx_chains_dynamic
);
1433 IWL_ERR(mvm
, "Failed to add PHY context\n");
1437 iwl_mvm_phy_ctxt_ref(mvm
, phy_ctxt
);
1438 *phy_ctxt_id
= phy_ctxt
->id
;
1440 mutex_unlock(&mvm
->mutex
);
1444 static void iwl_mvm_remove_chanctx(struct ieee80211_hw
*hw
,
1445 struct ieee80211_chanctx_conf
*ctx
)
1447 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1448 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1449 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1451 mutex_lock(&mvm
->mutex
);
1452 iwl_mvm_phy_ctxt_unref(mvm
, phy_ctxt
);
1453 mutex_unlock(&mvm
->mutex
);
1456 static void iwl_mvm_change_chanctx(struct ieee80211_hw
*hw
,
1457 struct ieee80211_chanctx_conf
*ctx
,
1460 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1461 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1462 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1464 if (WARN_ONCE((phy_ctxt
->ref
> 1) &&
1465 (changed
& ~(IEEE80211_CHANCTX_CHANGE_WIDTH
|
1466 IEEE80211_CHANCTX_CHANGE_RX_CHAINS
|
1467 IEEE80211_CHANCTX_CHANGE_RADAR
)),
1468 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1469 phy_ctxt
->ref
, changed
))
1472 mutex_lock(&mvm
->mutex
);
1473 iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->def
,
1474 ctx
->rx_chains_static
,
1475 ctx
->rx_chains_dynamic
);
1476 mutex_unlock(&mvm
->mutex
);
1479 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw
*hw
,
1480 struct ieee80211_vif
*vif
,
1481 struct ieee80211_chanctx_conf
*ctx
)
1483 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1484 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1485 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1486 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1489 mutex_lock(&mvm
->mutex
);
1491 mvmvif
->phy_ctxt
= phy_ctxt
;
1493 switch (vif
->type
) {
1494 case NL80211_IFTYPE_AP
:
1496 * The AP binding flow is handled as part of the start_ap flow
1497 * (in bss_info_changed).
1501 case NL80211_IFTYPE_STATION
:
1502 case NL80211_IFTYPE_ADHOC
:
1503 case NL80211_IFTYPE_MONITOR
:
1510 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1515 * Setting the quota at this stage is only required for monitor
1516 * interfaces. For the other types, the bss_info changed flow
1517 * will handle quota settings.
1519 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
1520 mvmvif
->monitor_active
= true;
1521 ret
= iwl_mvm_update_quotas(mvm
, vif
);
1523 goto out_remove_binding
;
1529 iwl_mvm_binding_remove_vif(mvm
, vif
);
1531 mutex_unlock(&mvm
->mutex
);
1533 mvmvif
->phy_ctxt
= NULL
;
1537 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
1538 struct ieee80211_vif
*vif
,
1539 struct ieee80211_chanctx_conf
*ctx
)
1541 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1542 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1544 mutex_lock(&mvm
->mutex
);
1546 iwl_mvm_remove_time_event(mvm
, mvmvif
, &mvmvif
->time_event_data
);
1548 if (vif
->type
== NL80211_IFTYPE_AP
)
1551 switch (vif
->type
) {
1552 case NL80211_IFTYPE_MONITOR
:
1553 mvmvif
->monitor_active
= false;
1554 iwl_mvm_update_quotas(mvm
, NULL
);
1560 iwl_mvm_binding_remove_vif(mvm
, vif
);
1562 mvmvif
->phy_ctxt
= NULL
;
1563 mutex_unlock(&mvm
->mutex
);
1566 static int iwl_mvm_set_tim(struct ieee80211_hw
*hw
,
1567 struct ieee80211_sta
*sta
,
1570 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1571 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
1573 if (!mvm_sta
|| !mvm_sta
->vif
) {
1574 IWL_ERR(mvm
, "Station is not associated to a vif\n");
1578 return iwl_mvm_mac_ctxt_beacon_changed(mvm
, mvm_sta
->vif
);
1581 #ifdef CONFIG_NL80211_TESTMODE
1582 static const struct nla_policy iwl_mvm_tm_policy
[IWL_MVM_TM_ATTR_MAX
+ 1] = {
1583 [IWL_MVM_TM_ATTR_CMD
] = { .type
= NLA_U32
},
1584 [IWL_MVM_TM_ATTR_NOA_DURATION
] = { .type
= NLA_U32
},
1585 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
] = { .type
= NLA_U32
},
1588 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm
*mvm
,
1589 struct ieee80211_vif
*vif
,
1590 void *data
, int len
)
1592 struct nlattr
*tb
[IWL_MVM_TM_ATTR_MAX
+ 1];
1596 err
= nla_parse(tb
, IWL_MVM_TM_ATTR_MAX
, data
, len
, iwl_mvm_tm_policy
);
1600 if (!tb
[IWL_MVM_TM_ATTR_CMD
])
1603 switch (nla_get_u32(tb
[IWL_MVM_TM_ATTR_CMD
])) {
1604 case IWL_MVM_TM_CMD_SET_NOA
:
1605 if (!vif
|| vif
->type
!= NL80211_IFTYPE_AP
|| !vif
->p2p
||
1606 !vif
->bss_conf
.enable_beacon
||
1607 !tb
[IWL_MVM_TM_ATTR_NOA_DURATION
])
1610 noa_duration
= nla_get_u32(tb
[IWL_MVM_TM_ATTR_NOA_DURATION
]);
1611 if (noa_duration
>= vif
->bss_conf
.beacon_int
)
1614 mvm
->noa_duration
= noa_duration
;
1617 return iwl_mvm_update_quotas(mvm
, NULL
);
1618 case IWL_MVM_TM_CMD_SET_BEACON_FILTER
:
1619 /* must be associated client vif - ignore authorized */
1620 if (!vif
|| vif
->type
!= NL80211_IFTYPE_STATION
||
1621 !vif
->bss_conf
.assoc
|| !vif
->bss_conf
.dtim_period
||
1622 !tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
])
1625 if (nla_get_u32(tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
]))
1626 return iwl_mvm_enable_beacon_filter(mvm
, vif
);
1627 return iwl_mvm_disable_beacon_filter(mvm
, vif
);
1633 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw
*hw
,
1634 struct ieee80211_vif
*vif
,
1635 void *data
, int len
)
1637 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1640 mutex_lock(&mvm
->mutex
);
1641 err
= __iwl_mvm_mac_testmode_cmd(mvm
, vif
, data
, len
);
1642 mutex_unlock(&mvm
->mutex
);
1648 struct ieee80211_ops iwl_mvm_hw_ops
= {
1649 .tx
= iwl_mvm_mac_tx
,
1650 .ampdu_action
= iwl_mvm_mac_ampdu_action
,
1651 .start
= iwl_mvm_mac_start
,
1652 .restart_complete
= iwl_mvm_mac_restart_complete
,
1653 .stop
= iwl_mvm_mac_stop
,
1654 .add_interface
= iwl_mvm_mac_add_interface
,
1655 .remove_interface
= iwl_mvm_mac_remove_interface
,
1656 .config
= iwl_mvm_mac_config
,
1657 .configure_filter
= iwl_mvm_configure_filter
,
1658 .bss_info_changed
= iwl_mvm_bss_info_changed
,
1659 .hw_scan
= iwl_mvm_mac_hw_scan
,
1660 .cancel_hw_scan
= iwl_mvm_mac_cancel_hw_scan
,
1661 .sta_state
= iwl_mvm_mac_sta_state
,
1662 .sta_notify
= iwl_mvm_mac_sta_notify
,
1663 .allow_buffered_frames
= iwl_mvm_mac_allow_buffered_frames
,
1664 .set_rts_threshold
= iwl_mvm_mac_set_rts_threshold
,
1665 .conf_tx
= iwl_mvm_mac_conf_tx
,
1666 .mgd_prepare_tx
= iwl_mvm_mac_mgd_prepare_tx
,
1667 .set_key
= iwl_mvm_mac_set_key
,
1668 .update_tkip_key
= iwl_mvm_mac_update_tkip_key
,
1669 .remain_on_channel
= iwl_mvm_roc
,
1670 .cancel_remain_on_channel
= iwl_mvm_cancel_roc
,
1671 .add_chanctx
= iwl_mvm_add_chanctx
,
1672 .remove_chanctx
= iwl_mvm_remove_chanctx
,
1673 .change_chanctx
= iwl_mvm_change_chanctx
,
1674 .assign_vif_chanctx
= iwl_mvm_assign_vif_chanctx
,
1675 .unassign_vif_chanctx
= iwl_mvm_unassign_vif_chanctx
,
1677 .start_ap
= iwl_mvm_start_ap
,
1678 .stop_ap
= iwl_mvm_stop_ap
,
1680 .set_tim
= iwl_mvm_set_tim
,
1682 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd
)
1684 #ifdef CONFIG_PM_SLEEP
1686 .suspend
= iwl_mvm_suspend
,
1687 .resume
= iwl_mvm_resume
,
1688 .set_wakeup
= iwl_mvm_set_wakeup
,
1689 .set_rekey_data
= iwl_mvm_set_rekey_data
,
1690 #if IS_ENABLED(CONFIG_IPV6)
1691 .ipv6_addr_change
= iwl_mvm_ipv6_addr_change
,
1693 .set_default_unicast_key
= iwl_mvm_set_default_unicast_key
,