1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 *****************************************************************************/
63 #include <linux/kernel.h>
64 #include <linux/slab.h>
65 #include <linux/skbuff.h>
66 #include <linux/netdevice.h>
67 #include <linux/etherdevice.h>
69 #include <net/mac80211.h>
72 #include "iwl-op-mode.h"
76 #include "time-event.h"
77 #include "iwl-eeprom-parse.h"
78 #include "fw-api-scan.h"
79 #include "iwl-phy-db.h"
81 static const struct ieee80211_iface_limit iwl_mvm_limits
[] = {
84 .types
= BIT(NL80211_IFTYPE_STATION
) |
85 BIT(NL80211_IFTYPE_AP
),
89 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations
[] = {
91 .num_different_channels
= 1,
93 .limits
= iwl_mvm_limits
,
94 .n_limits
= ARRAY_SIZE(iwl_mvm_limits
),
98 #ifdef CONFIG_PM_SLEEP
99 static const struct nl80211_wowlan_tcp_data_token_feature
100 iwl_mvm_wowlan_tcp_token_feature
= {
103 .bufsize
= IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS
,
106 static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support
= {
107 .tok
= &iwl_mvm_wowlan_tcp_token_feature
,
108 .data_payload_max
= IWL_WOWLAN_TCP_MAX_PACKET_LEN
-
109 sizeof(struct ethhdr
) -
110 sizeof(struct iphdr
) -
111 sizeof(struct tcphdr
),
112 .data_interval_max
= 65535, /* __le16 in API */
113 .wake_payload_max
= IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN
-
114 sizeof(struct ethhdr
) -
115 sizeof(struct iphdr
) -
116 sizeof(struct tcphdr
),
121 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm
*mvm
)
125 memset(mvm
->phy_ctxts
, 0, sizeof(mvm
->phy_ctxts
));
126 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
127 mvm
->phy_ctxts
[i
].id
= i
;
128 mvm
->phy_ctxts
[i
].ref
= 0;
132 int iwl_mvm_mac_setup_register(struct iwl_mvm
*mvm
)
134 struct ieee80211_hw
*hw
= mvm
->hw
;
137 /* Tell mac80211 our characteristics */
138 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
139 IEEE80211_HW_SPECTRUM_MGMT
|
140 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
141 IEEE80211_HW_QUEUE_CONTROL
|
142 IEEE80211_HW_WANT_MONITOR_VIF
|
143 IEEE80211_HW_SUPPORTS_PS
|
144 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
145 IEEE80211_HW_AMPDU_AGGREGATION
|
146 IEEE80211_HW_TIMING_BEACON_ONLY
|
147 IEEE80211_HW_CONNECTION_MONITOR
;
149 hw
->queues
= IWL_MVM_FIRST_AGG_QUEUE
;
150 hw
->offchannel_tx_hw_queue
= IWL_MVM_OFFCHANNEL_QUEUE
;
151 hw
->rate_control_algorithm
= "iwl-mvm-rs";
154 * Enable 11w if advertised by firmware and software crypto
155 * is not enabled (as the firmware will interpret some mgmt
156 * packets, so enabling it with software crypto isn't safe)
158 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_MFP
&&
159 !iwlwifi_mod_params
.sw_crypto
)
160 hw
->flags
|= IEEE80211_HW_MFP_CAPABLE
;
162 hw
->sta_data_size
= sizeof(struct iwl_mvm_sta
);
163 hw
->vif_data_size
= sizeof(struct iwl_mvm_vif
);
164 hw
->chanctx_data_size
= sizeof(u16
);
166 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
167 BIT(NL80211_IFTYPE_AP
);
169 hw
->wiphy
->flags
|= WIPHY_FLAG_CUSTOM_REGULATORY
|
170 WIPHY_FLAG_DISABLE_BEACON_HINTS
|
173 hw
->wiphy
->iface_combinations
= iwl_mvm_iface_combinations
;
174 hw
->wiphy
->n_iface_combinations
=
175 ARRAY_SIZE(iwl_mvm_iface_combinations
);
177 hw
->wiphy
->max_remain_on_channel_duration
= 10000;
178 hw
->max_listen_interval
= IWL_CONN_MAX_LISTEN_INTERVAL
;
180 /* Extract MAC address */
181 memcpy(mvm
->addresses
[0].addr
, mvm
->nvm_data
->hw_addr
, ETH_ALEN
);
182 hw
->wiphy
->addresses
= mvm
->addresses
;
183 hw
->wiphy
->n_addresses
= 1;
185 /* Extract additional MAC addresses if available */
186 num_mac
= (mvm
->nvm_data
->n_hw_addrs
> 1) ?
187 min(IWL_MVM_MAX_ADDRESSES
, mvm
->nvm_data
->n_hw_addrs
) : 1;
189 for (i
= 1; i
< num_mac
; i
++) {
190 memcpy(mvm
->addresses
[i
].addr
, mvm
->addresses
[i
-1].addr
,
192 mvm
->addresses
[i
].addr
[5]++;
193 hw
->wiphy
->n_addresses
++;
196 iwl_mvm_reset_phy_ctxts(mvm
);
198 /* we create the 802.11 header and a max-length SSID element */
199 hw
->wiphy
->max_scan_ie_len
=
200 mvm
->fw
->ucode_capa
.max_probe_length
- 24 - 34;
201 hw
->wiphy
->max_scan_ssids
= PROBE_OPTION_MAX
;
203 if (mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
204 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
205 &mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
];
206 if (mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
207 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
208 &mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
];
210 hw
->wiphy
->hw_version
= mvm
->trans
->hw_id
;
212 if (iwlmvm_mod_params
.power_scheme
!= IWL_POWER_SCHEME_CAM
)
213 hw
->wiphy
->flags
|= WIPHY_FLAG_PS_ON_BY_DEFAULT
;
215 hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
217 hw
->wiphy
->features
|= NL80211_FEATURE_P2P_GO_CTWIN
|
218 NL80211_FEATURE_P2P_GO_OPPPS
;
220 mvm
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
222 #ifdef CONFIG_PM_SLEEP
223 if (mvm
->fw
->img
[IWL_UCODE_WOWLAN
].sec
[0].len
&&
224 mvm
->trans
->ops
->d3_suspend
&&
225 mvm
->trans
->ops
->d3_resume
&&
226 device_can_wakeup(mvm
->trans
->dev
)) {
227 hw
->wiphy
->wowlan
.flags
= WIPHY_WOWLAN_MAGIC_PKT
|
228 WIPHY_WOWLAN_DISCONNECT
|
229 WIPHY_WOWLAN_EAP_IDENTITY_REQ
|
230 WIPHY_WOWLAN_RFKILL_RELEASE
;
231 if (!iwlwifi_mod_params
.sw_crypto
)
232 hw
->wiphy
->wowlan
.flags
|=
233 WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
|
234 WIPHY_WOWLAN_GTK_REKEY_FAILURE
|
235 WIPHY_WOWLAN_4WAY_HANDSHAKE
;
237 hw
->wiphy
->wowlan
.n_patterns
= IWL_WOWLAN_MAX_PATTERNS
;
238 hw
->wiphy
->wowlan
.pattern_min_len
= IWL_WOWLAN_MIN_PATTERN_LEN
;
239 hw
->wiphy
->wowlan
.pattern_max_len
= IWL_WOWLAN_MAX_PATTERN_LEN
;
240 hw
->wiphy
->wowlan
.tcp
= &iwl_mvm_wowlan_tcp_support
;
244 ret
= iwl_mvm_leds_init(mvm
);
248 return ieee80211_register_hw(mvm
->hw
);
251 static void iwl_mvm_mac_tx(struct ieee80211_hw
*hw
,
252 struct ieee80211_tx_control
*control
,
255 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
257 if (iwl_mvm_is_radio_killed(mvm
)) {
258 IWL_DEBUG_DROP(mvm
, "Dropping - RF/CT KILL\n");
262 if (IEEE80211_SKB_CB(skb
)->hw_queue
== IWL_MVM_OFFCHANNEL_QUEUE
&&
263 !test_bit(IWL_MVM_STATUS_ROC_RUNNING
, &mvm
->status
))
267 if (iwl_mvm_tx_skb(mvm
, skb
, control
->sta
))
272 if (iwl_mvm_tx_skb_non_sta(mvm
, skb
))
276 ieee80211_free_txskb(hw
, skb
);
279 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw
*hw
,
280 struct ieee80211_vif
*vif
,
281 enum ieee80211_ampdu_mlme_action action
,
282 struct ieee80211_sta
*sta
, u16 tid
,
283 u16
*ssn
, u8 buf_size
)
285 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
288 IWL_DEBUG_HT(mvm
, "A-MPDU action on addr %pM tid %d: action %d\n",
289 sta
->addr
, tid
, action
);
291 if (!(mvm
->nvm_data
->sku_cap_11n_enable
))
294 mutex_lock(&mvm
->mutex
);
297 case IEEE80211_AMPDU_RX_START
:
298 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_RXAGG
) {
302 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, *ssn
, true);
304 case IEEE80211_AMPDU_RX_STOP
:
305 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, 0, false);
307 case IEEE80211_AMPDU_TX_START
:
308 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_TXAGG
) {
312 ret
= iwl_mvm_sta_tx_agg_start(mvm
, vif
, sta
, tid
, ssn
);
314 case IEEE80211_AMPDU_TX_STOP_CONT
:
315 ret
= iwl_mvm_sta_tx_agg_stop(mvm
, vif
, sta
, tid
);
317 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
318 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
319 ret
= iwl_mvm_sta_tx_agg_flush(mvm
, vif
, sta
, tid
);
321 case IEEE80211_AMPDU_TX_OPERATIONAL
:
322 ret
= iwl_mvm_sta_tx_agg_oper(mvm
, vif
, sta
, tid
, buf_size
);
329 mutex_unlock(&mvm
->mutex
);
334 static void iwl_mvm_cleanup_iterator(void *data
, u8
*mac
,
335 struct ieee80211_vif
*vif
)
337 struct iwl_mvm
*mvm
= data
;
338 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
340 mvmvif
->uploaded
= false;
341 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
343 /* does this make sense at all? */
346 spin_lock_bh(&mvm
->time_event_lock
);
347 iwl_mvm_te_clear_data(mvm
, &mvmvif
->time_event_data
);
348 spin_unlock_bh(&mvm
->time_event_lock
);
350 mvmvif
->phy_ctxt
= NULL
;
353 static void iwl_mvm_restart_cleanup(struct iwl_mvm
*mvm
)
355 iwl_trans_stop_device(mvm
->trans
);
356 iwl_trans_stop_hw(mvm
->trans
, false);
358 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
360 /* just in case one was running */
361 ieee80211_remain_on_channel_expired(mvm
->hw
);
363 ieee80211_iterate_active_interfaces_atomic(
364 mvm
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
365 iwl_mvm_cleanup_iterator
, mvm
);
367 mvm
->p2p_device_vif
= NULL
;
369 iwl_mvm_reset_phy_ctxts(mvm
);
370 memset(mvm
->fw_key_table
, 0, sizeof(mvm
->fw_key_table
));
371 memset(mvm
->sta_drained
, 0, sizeof(mvm
->sta_drained
));
373 ieee80211_wake_queues(mvm
->hw
);
378 static int iwl_mvm_mac_start(struct ieee80211_hw
*hw
)
380 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
383 mutex_lock(&mvm
->mutex
);
385 /* Clean up some internal and mac80211 state on restart */
386 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
387 iwl_mvm_restart_cleanup(mvm
);
389 ret
= iwl_mvm_up(mvm
);
390 mutex_unlock(&mvm
->mutex
);
395 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw
*hw
)
397 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
400 mutex_lock(&mvm
->mutex
);
402 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
403 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
405 IWL_ERR(mvm
, "Failed to update quotas after restart (%d)\n",
408 mutex_unlock(&mvm
->mutex
);
411 static void iwl_mvm_mac_stop(struct ieee80211_hw
*hw
)
413 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
415 flush_work(&mvm
->async_handlers_wk
);
417 mutex_lock(&mvm
->mutex
);
418 /* async_handlers_wk is now blocked */
421 * The work item could be running or queued if the
422 * ROC time event stops just as we get here.
424 cancel_work_sync(&mvm
->roc_done_wk
);
426 iwl_trans_stop_device(mvm
->trans
);
427 iwl_trans_stop_hw(mvm
->trans
, false);
429 iwl_mvm_async_handlers_purge(mvm
);
430 /* async_handlers_list is empty and will stay empty: HW is stopped */
432 /* the fw is stopped, the aux sta is dead: clean up driver state */
433 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
435 mutex_unlock(&mvm
->mutex
);
438 * The worker might have been waiting for the mutex, let it run and
439 * discover that its list is now empty.
441 cancel_work_sync(&mvm
->async_handlers_wk
);
444 static void iwl_mvm_pm_disable_iterator(void *data
, u8
*mac
,
445 struct ieee80211_vif
*vif
)
447 struct iwl_mvm
*mvm
= data
;
450 ret
= iwl_mvm_power_disable(mvm
, vif
);
452 IWL_ERR(mvm
, "failed to disable power management\n");
455 static void iwl_mvm_power_update_iterator(void *data
, u8
*mac
,
456 struct ieee80211_vif
*vif
)
458 struct iwl_mvm
*mvm
= data
;
460 iwl_mvm_power_update_mode(mvm
, vif
);
463 static struct iwl_mvm_phy_ctxt
*iwl_mvm_get_free_phy_ctxt(struct iwl_mvm
*mvm
)
467 lockdep_assert_held(&mvm
->mutex
);
469 for (i
= 0; i
< NUM_PHY_CTX
; i
++)
470 if (!mvm
->phy_ctxts
[i
].ref
)
471 return &mvm
->phy_ctxts
[i
];
473 IWL_ERR(mvm
, "No available PHY context\n");
477 static int iwl_mvm_mac_add_interface(struct ieee80211_hw
*hw
,
478 struct ieee80211_vif
*vif
)
480 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
481 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
485 * Not much to do here. The stack will not allow interface
486 * types or combinations that we didn't advertise, so we
487 * don't really have to check the types.
490 mutex_lock(&mvm
->mutex
);
492 /* Allocate resources for the MAC context, and add it the the fw */
493 ret
= iwl_mvm_mac_ctxt_init(mvm
, vif
);
498 * The AP binding flow can be done only after the beacon
499 * template is configured (which happens only in the mac80211
500 * start_ap() flow), and adding the broadcast station can happen
501 * only after the binding.
502 * In addition, since modifying the MAC before adding a bcast
503 * station is not allowed by the FW, delay the adding of MAC context to
504 * the point where we can also add the bcast station.
505 * In short: there's not much we can do at this point, other than
506 * allocating resources :)
508 if (vif
->type
== NL80211_IFTYPE_AP
) {
509 u32 qmask
= iwl_mvm_mac_get_queues_mask(mvm
, vif
);
510 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->bcast_sta
,
513 IWL_ERR(mvm
, "Failed to allocate bcast sta\n");
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
);
541 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
546 * Update power state on the new interface. Admittedly, based on
547 * mac80211 logics this power update will disable power management
549 iwl_mvm_power_update_mode(mvm
, vif
);
551 /* beacon filtering */
552 if (!mvm
->bf_allowed_vif
&&
553 vif
->type
== NL80211_IFTYPE_STATION
&& !vif
->p2p
){
554 mvm
->bf_allowed_vif
= mvmvif
;
555 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
;
558 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
);
563 * P2P_DEVICE interface does not have a channel context assigned to it,
564 * so a dedicated PHY context is allocated to it and the corresponding
565 * MAC context is bound to it at this stage.
567 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
569 mvmvif
->phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
570 if (!mvmvif
->phy_ctxt
) {
575 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
576 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
580 ret
= iwl_mvm_add_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
584 /* Save a pointer to p2p device vif, so it can later be used to
585 * update the p2p device MAC when a GO is started/stopped */
586 mvm
->p2p_device_vif
= vif
;
589 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
593 iwl_mvm_binding_remove_vif(mvm
, vif
);
595 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
597 mvmvif
->phy_ctxt
= NULL
;
598 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
601 * TODO: remove this temporary code.
602 * Currently MVM FW supports power management only on single MAC.
603 * Check if only one additional interface remains after releasing
604 * current one. Update power mode on the remaining interface.
606 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
608 IWL_DEBUG_MAC80211(mvm
, "Currently %d interfaces active\n",
610 if (mvm
->vif_count
== 1) {
611 ieee80211_iterate_active_interfaces(
612 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
613 iwl_mvm_power_update_iterator
, mvm
);
615 iwl_mvm_mac_ctxt_release(mvm
, vif
);
617 mutex_unlock(&mvm
->mutex
);
622 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm
*mvm
,
623 struct ieee80211_vif
*vif
)
627 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
628 if (vif
->hw_queue
[ac
] != IEEE80211_INVAL_HW_QUEUE
)
629 tfd_msk
|= BIT(vif
->hw_queue
[ac
]);
631 if (vif
->cab_queue
!= IEEE80211_INVAL_HW_QUEUE
)
632 tfd_msk
|= BIT(vif
->cab_queue
);
635 mutex_lock(&mvm
->mutex
);
636 iwl_mvm_flush_tx_path(mvm
, tfd_msk
, true);
637 mutex_unlock(&mvm
->mutex
);
640 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
642 * Flush the ROC worker which will flush the OFFCHANNEL queue.
643 * We assume here that all the packets sent to the OFFCHANNEL
644 * queue are sent in ROC session.
646 flush_work(&mvm
->roc_done_wk
);
649 * By now, all the AC queues are empty. The AGG queues are
650 * empty too. We already got all the Tx responses for all the
651 * packets in the queues. The drain work can have been
652 * triggered. Flush it. This work item takes the mutex, so kill
653 * it before we take it.
655 flush_work(&mvm
->sta_drained_wk
);
659 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw
*hw
,
660 struct ieee80211_vif
*vif
)
662 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
663 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
665 iwl_mvm_prepare_mac_removal(mvm
, vif
);
667 mutex_lock(&mvm
->mutex
);
669 if (mvm
->bf_allowed_vif
== mvmvif
) {
670 mvm
->bf_allowed_vif
= NULL
;
671 vif
->driver_flags
&= ~IEEE80211_VIF_BEACON_FILTER
;
674 iwl_mvm_vif_dbgfs_clean(mvm
, vif
);
677 * For AP/GO interface, the tear down of the resources allocated to the
678 * interface is be handled as part of the stop_ap flow.
680 if (vif
->type
== NL80211_IFTYPE_AP
) {
681 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->bcast_sta
);
685 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
686 mvm
->p2p_device_vif
= NULL
;
687 iwl_mvm_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
688 iwl_mvm_binding_remove_vif(mvm
, vif
);
689 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
690 mvmvif
->phy_ctxt
= NULL
;
694 * TODO: remove this temporary code.
695 * Currently MVM FW supports power management only on single MAC.
696 * Check if only one additional interface remains after removing
697 * current one. Update power mode on the remaining interface.
699 if (mvm
->vif_count
&& vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
701 IWL_DEBUG_MAC80211(mvm
, "Currently %d interfaces active\n",
703 if (mvm
->vif_count
== 1) {
704 ieee80211_iterate_active_interfaces(
705 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
706 iwl_mvm_power_update_iterator
, mvm
);
709 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
712 iwl_mvm_mac_ctxt_release(mvm
, vif
);
713 mutex_unlock(&mvm
->mutex
);
716 static int iwl_mvm_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
721 static void iwl_mvm_configure_filter(struct ieee80211_hw
*hw
,
722 unsigned int changed_flags
,
723 unsigned int *total_flags
,
729 static int iwl_mvm_configure_mcast_filter(struct iwl_mvm
*mvm
,
730 struct ieee80211_vif
*vif
)
732 struct iwl_mcast_filter_cmd mcast_filter_cmd
= {
736 memcpy(mcast_filter_cmd
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
738 return iwl_mvm_send_cmd_pdu(mvm
, MCAST_FILTER_CMD
, CMD_SYNC
,
739 sizeof(mcast_filter_cmd
),
743 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm
*mvm
,
744 struct ieee80211_vif
*vif
,
745 struct ieee80211_bss_conf
*bss_conf
,
748 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
751 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
753 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
755 if (changes
& BSS_CHANGED_ASSOC
) {
756 if (bss_conf
->assoc
) {
757 /* add quota for this interface */
758 ret
= iwl_mvm_update_quotas(mvm
, vif
);
760 IWL_ERR(mvm
, "failed to update quotas\n");
763 iwl_mvm_bt_coex_vif_assoc(mvm
, vif
);
764 iwl_mvm_configure_mcast_filter(mvm
, vif
);
765 } else if (mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
766 /* remove AP station now that the MAC is unassoc */
767 ret
= iwl_mvm_rm_sta_id(mvm
, vif
, mvmvif
->ap_sta_id
);
769 IWL_ERR(mvm
, "failed to remove AP station\n");
770 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
771 /* remove quota for this interface */
772 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
774 IWL_ERR(mvm
, "failed to update quotas\n");
776 } else if (changes
& BSS_CHANGED_DTIM_PERIOD
) {
778 * We received a beacon _after_ association so
779 * remove the session protection.
781 iwl_mvm_remove_time_event(mvm
, mvmvif
,
782 &mvmvif
->time_event_data
);
783 } else if (changes
& BSS_CHANGED_PS
) {
785 * TODO: remove this temporary code.
786 * Currently MVM FW supports power management only on single
787 * MAC. Avoid power mode update if more than one interface
790 IWL_DEBUG_MAC80211(mvm
, "Currently %d interfaces active\n",
792 if (mvm
->vif_count
== 1) {
793 ret
= iwl_mvm_power_update_mode(mvm
, vif
);
795 IWL_ERR(mvm
, "failed to update power mode\n");
800 static int iwl_mvm_start_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
802 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
803 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
806 mutex_lock(&mvm
->mutex
);
808 /* Send the beacon template */
809 ret
= iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
);
813 /* Add the mac context */
814 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
818 /* Perform the binding */
819 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
823 mvmvif
->ap_active
= true;
825 /* Send the bcast station. At this stage the TBTT and DTIM time events
826 * are added and applied to the scheduler */
827 ret
= iwl_mvm_send_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
831 ret
= iwl_mvm_update_quotas(mvm
, vif
);
835 /* Need to update the P2P Device MAC */
836 if (vif
->p2p
&& mvm
->p2p_device_vif
)
837 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
839 mutex_unlock(&mvm
->mutex
);
843 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
845 iwl_mvm_binding_remove_vif(mvm
, vif
);
847 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
849 mutex_unlock(&mvm
->mutex
);
853 static void iwl_mvm_stop_ap(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
855 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
856 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
858 iwl_mvm_prepare_mac_removal(mvm
, vif
);
860 mutex_lock(&mvm
->mutex
);
862 mvmvif
->ap_active
= false;
864 /* Need to update the P2P Device MAC */
865 if (vif
->p2p
&& mvm
->p2p_device_vif
)
866 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
868 iwl_mvm_update_quotas(mvm
, NULL
);
869 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
870 iwl_mvm_binding_remove_vif(mvm
, vif
);
871 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
873 mutex_unlock(&mvm
->mutex
);
876 static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm
*mvm
,
877 struct ieee80211_vif
*vif
,
878 struct ieee80211_bss_conf
*bss_conf
,
881 /* Need to send a new beacon template to the FW */
882 if (changes
& BSS_CHANGED_BEACON
) {
883 if (iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
))
884 IWL_WARN(mvm
, "Failed updating beacon data\n");
888 static void iwl_mvm_bss_info_changed(struct ieee80211_hw
*hw
,
889 struct ieee80211_vif
*vif
,
890 struct ieee80211_bss_conf
*bss_conf
,
893 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
895 mutex_lock(&mvm
->mutex
);
898 case NL80211_IFTYPE_STATION
:
899 iwl_mvm_bss_info_changed_station(mvm
, vif
, bss_conf
, changes
);
901 case NL80211_IFTYPE_AP
:
902 iwl_mvm_bss_info_changed_ap(mvm
, vif
, bss_conf
, changes
);
905 /* shouldn't happen */
909 mutex_unlock(&mvm
->mutex
);
912 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw
*hw
,
913 struct ieee80211_vif
*vif
,
914 struct cfg80211_scan_request
*req
)
916 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
919 if (req
->n_channels
== 0 || req
->n_channels
> MAX_NUM_SCAN_CHANNELS
)
922 mutex_lock(&mvm
->mutex
);
924 if (mvm
->scan_status
== IWL_MVM_SCAN_NONE
)
925 ret
= iwl_mvm_scan_request(mvm
, vif
, req
);
929 mutex_unlock(&mvm
->mutex
);
934 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw
*hw
,
935 struct ieee80211_vif
*vif
)
937 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
939 mutex_lock(&mvm
->mutex
);
941 iwl_mvm_cancel_scan(mvm
);
943 mutex_unlock(&mvm
->mutex
);
947 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw
*hw
,
948 struct ieee80211_sta
*sta
, u16 tid
,
950 enum ieee80211_frame_release_type reason
,
953 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
955 /* TODO: how do we tell the fw to send frames for a specific TID */
958 * The fw will send EOSP notification when the last frame will be
961 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
);
964 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw
*hw
,
965 struct ieee80211_vif
*vif
,
966 enum sta_notify_cmd cmd
,
967 struct ieee80211_sta
*sta
)
969 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
970 struct iwl_mvm_sta
*mvmsta
= (void *)sta
->drv_priv
;
973 case STA_NOTIFY_SLEEP
:
974 if (atomic_read(&mvm
->pending_frames
[mvmsta
->sta_id
]) > 0)
975 ieee80211_sta_block_awake(hw
, sta
, true);
977 * The fw updates the STA to be asleep. Tx packets on the Tx
978 * queues to this station will not be transmitted. The fw will
979 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
982 case STA_NOTIFY_AWAKE
:
983 if (WARN_ON(mvmsta
->sta_id
== IWL_MVM_STATION_COUNT
))
985 iwl_mvm_sta_modify_ps_wake(mvm
, sta
);
992 static int iwl_mvm_mac_sta_state(struct ieee80211_hw
*hw
,
993 struct ieee80211_vif
*vif
,
994 struct ieee80211_sta
*sta
,
995 enum ieee80211_sta_state old_state
,
996 enum ieee80211_sta_state new_state
)
998 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
999 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1002 IWL_DEBUG_MAC80211(mvm
, "station %pM state change %d->%d\n",
1003 sta
->addr
, old_state
, new_state
);
1005 /* this would be a mac80211 bug ... but don't crash */
1006 if (WARN_ON_ONCE(!mvmvif
->phy_ctxt
))
1009 /* if a STA is being removed, reuse its ID */
1010 flush_work(&mvm
->sta_drained_wk
);
1012 mutex_lock(&mvm
->mutex
);
1013 if (old_state
== IEEE80211_STA_NOTEXIST
&&
1014 new_state
== IEEE80211_STA_NONE
) {
1015 ret
= iwl_mvm_add_sta(mvm
, vif
, sta
);
1016 } else if (old_state
== IEEE80211_STA_NONE
&&
1017 new_state
== IEEE80211_STA_AUTH
) {
1019 } else if (old_state
== IEEE80211_STA_AUTH
&&
1020 new_state
== IEEE80211_STA_ASSOC
) {
1021 ret
= iwl_mvm_update_sta(mvm
, vif
, sta
);
1023 iwl_mvm_rs_rate_init(mvm
, sta
,
1024 mvmvif
->phy_ctxt
->channel
->band
);
1025 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1026 new_state
== IEEE80211_STA_AUTHORIZED
) {
1027 /* enable beacon filtering */
1028 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
));
1030 } else if (old_state
== IEEE80211_STA_AUTHORIZED
&&
1031 new_state
== IEEE80211_STA_ASSOC
) {
1032 /* disable beacon filtering */
1033 WARN_ON(iwl_mvm_disable_beacon_filter(mvm
, vif
));
1035 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1036 new_state
== IEEE80211_STA_AUTH
) {
1038 } else if (old_state
== IEEE80211_STA_AUTH
&&
1039 new_state
== IEEE80211_STA_NONE
) {
1041 } else if (old_state
== IEEE80211_STA_NONE
&&
1042 new_state
== IEEE80211_STA_NOTEXIST
) {
1043 ret
= iwl_mvm_rm_sta(mvm
, vif
, sta
);
1047 mutex_unlock(&mvm
->mutex
);
1052 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1054 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1056 mvm
->rts_threshold
= value
;
1061 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw
*hw
,
1062 struct ieee80211_vif
*vif
, u16 ac
,
1063 const struct ieee80211_tx_queue_params
*params
)
1065 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1066 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1068 mvmvif
->queue_params
[ac
] = *params
;
1071 * No need to update right away, we'll get BSS_CHANGED_QOS
1072 * The exception is P2P_DEVICE interface which needs immediate update.
1074 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1077 mutex_lock(&mvm
->mutex
);
1078 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
1079 mutex_unlock(&mvm
->mutex
);
1085 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw
*hw
,
1086 struct ieee80211_vif
*vif
)
1088 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1089 u32 duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS
,
1090 200 + vif
->bss_conf
.beacon_int
);
1091 u32 min_duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS
,
1092 100 + vif
->bss_conf
.beacon_int
);
1094 if (WARN_ON_ONCE(vif
->bss_conf
.assoc
))
1097 mutex_lock(&mvm
->mutex
);
1098 /* Try really hard to protect the session and hear a beacon */
1099 iwl_mvm_protect_session(mvm
, vif
, duration
, min_duration
);
1100 mutex_unlock(&mvm
->mutex
);
1103 static int iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
1104 enum set_key_cmd cmd
,
1105 struct ieee80211_vif
*vif
,
1106 struct ieee80211_sta
*sta
,
1107 struct ieee80211_key_conf
*key
)
1109 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1112 if (iwlwifi_mod_params
.sw_crypto
) {
1113 IWL_DEBUG_MAC80211(mvm
, "leave - hwcrypto disabled\n");
1117 switch (key
->cipher
) {
1118 case WLAN_CIPHER_SUITE_TKIP
:
1119 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1121 case WLAN_CIPHER_SUITE_CCMP
:
1122 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1124 case WLAN_CIPHER_SUITE_AES_CMAC
:
1125 WARN_ON_ONCE(!(hw
->flags
& IEEE80211_HW_MFP_CAPABLE
));
1127 case WLAN_CIPHER_SUITE_WEP40
:
1128 case WLAN_CIPHER_SUITE_WEP104
:
1130 * Support for TX only, at least for now, so accept
1131 * the key and do nothing else. Then mac80211 will
1132 * pass it for TX but we don't have to use it for RX.
1139 mutex_lock(&mvm
->mutex
);
1143 if (vif
->type
== NL80211_IFTYPE_AP
&& !sta
) {
1144 /* GTK on AP interface is a TX-only key, return 0 */
1146 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1150 IWL_DEBUG_MAC80211(mvm
, "set hwcrypto key\n");
1151 ret
= iwl_mvm_set_sta_key(mvm
, vif
, sta
, key
, false);
1153 IWL_WARN(mvm
, "set key failed\n");
1155 * can't add key for RX, but we don't need it
1156 * in the device for TX so still return 0
1158 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1164 if (key
->hw_key_idx
== STA_KEY_IDX_INVALID
) {
1169 IWL_DEBUG_MAC80211(mvm
, "disable hwcrypto key\n");
1170 ret
= iwl_mvm_remove_sta_key(mvm
, vif
, sta
, key
);
1176 mutex_unlock(&mvm
->mutex
);
1180 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw
*hw
,
1181 struct ieee80211_vif
*vif
,
1182 struct ieee80211_key_conf
*keyconf
,
1183 struct ieee80211_sta
*sta
,
1184 u32 iv32
, u16
*phase1key
)
1186 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1188 iwl_mvm_update_tkip_key(mvm
, vif
, keyconf
, sta
, iv32
, phase1key
);
1192 static int iwl_mvm_roc(struct ieee80211_hw
*hw
,
1193 struct ieee80211_vif
*vif
,
1194 struct ieee80211_channel
*channel
,
1196 enum ieee80211_roc_type type
)
1198 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1199 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1200 struct cfg80211_chan_def chandef
;
1201 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1204 IWL_DEBUG_MAC80211(mvm
, "enter (%d, %d, %d)\n", channel
->hw_value
,
1207 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
) {
1208 IWL_ERR(mvm
, "vif isn't a P2P_DEVICE: %d\n", vif
->type
);
1212 mutex_lock(&mvm
->mutex
);
1214 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
1215 phy_ctxt
= &mvm
->phy_ctxts
[i
];
1216 if (phy_ctxt
->ref
== 0 || mvmvif
->phy_ctxt
== phy_ctxt
)
1219 if (phy_ctxt
->ref
&& channel
== phy_ctxt
->channel
) {
1221 * Unbind the P2P_DEVICE from the current PHY context,
1222 * and if the PHY context is not used remove it.
1224 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1225 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1228 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1230 /* Bind the P2P_DEVICE to the current PHY Context */
1231 mvmvif
->phy_ctxt
= phy_ctxt
;
1233 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1234 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1237 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1238 goto schedule_time_event
;
1242 /* Need to update the PHY context only if the ROC channel changed */
1243 if (channel
== mvmvif
->phy_ctxt
->channel
)
1244 goto schedule_time_event
;
1246 cfg80211_chandef_create(&chandef
, channel
, NL80211_CHAN_NO_HT
);
1249 * Change the PHY context configuration as it is currently referenced
1250 * only by the P2P Device MAC
1252 if (mvmvif
->phy_ctxt
->ref
== 1) {
1253 ret
= iwl_mvm_phy_ctxt_changed(mvm
, mvmvif
->phy_ctxt
,
1259 * The PHY context is shared with other MACs. Need to remove the
1260 * P2P Device from the binding, allocate an new PHY context and
1261 * create a new binding
1263 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1269 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &chandef
,
1272 IWL_ERR(mvm
, "Failed to change PHY context\n");
1276 /* Unbind the P2P_DEVICE from the current PHY context */
1277 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1278 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1281 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1283 /* Bind the P2P_DEVICE to the new allocated PHY context */
1284 mvmvif
->phy_ctxt
= phy_ctxt
;
1286 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1287 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1290 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1293 schedule_time_event
:
1294 /* Schedule the time events */
1295 ret
= iwl_mvm_start_p2p_roc(mvm
, vif
, duration
, type
);
1298 mutex_unlock(&mvm
->mutex
);
1299 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1303 static int iwl_mvm_cancel_roc(struct ieee80211_hw
*hw
)
1305 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1307 IWL_DEBUG_MAC80211(mvm
, "enter\n");
1309 mutex_lock(&mvm
->mutex
);
1310 iwl_mvm_stop_p2p_roc(mvm
);
1311 mutex_unlock(&mvm
->mutex
);
1313 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1317 static int iwl_mvm_add_chanctx(struct ieee80211_hw
*hw
,
1318 struct ieee80211_chanctx_conf
*ctx
)
1320 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1321 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1322 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1325 IWL_DEBUG_MAC80211(mvm
, "Add channel context\n");
1327 mutex_lock(&mvm
->mutex
);
1328 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1334 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->def
,
1335 ctx
->rx_chains_static
,
1336 ctx
->rx_chains_dynamic
);
1338 IWL_ERR(mvm
, "Failed to add PHY context\n");
1342 iwl_mvm_phy_ctxt_ref(mvm
, phy_ctxt
);
1343 *phy_ctxt_id
= phy_ctxt
->id
;
1345 mutex_unlock(&mvm
->mutex
);
1349 static void iwl_mvm_remove_chanctx(struct ieee80211_hw
*hw
,
1350 struct ieee80211_chanctx_conf
*ctx
)
1352 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1353 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1354 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1356 mutex_lock(&mvm
->mutex
);
1357 iwl_mvm_phy_ctxt_unref(mvm
, phy_ctxt
);
1358 mutex_unlock(&mvm
->mutex
);
1361 static void iwl_mvm_change_chanctx(struct ieee80211_hw
*hw
,
1362 struct ieee80211_chanctx_conf
*ctx
,
1365 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1366 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1367 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1369 if (WARN_ONCE((phy_ctxt
->ref
> 1) &&
1370 (changed
& ~(IEEE80211_CHANCTX_CHANGE_WIDTH
|
1371 IEEE80211_CHANCTX_CHANGE_RX_CHAINS
|
1372 IEEE80211_CHANCTX_CHANGE_RADAR
)),
1373 "Cannot change PHY. Ref=%d, changed=0x%X\n",
1374 phy_ctxt
->ref
, changed
))
1377 mutex_lock(&mvm
->mutex
);
1378 iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->def
,
1379 ctx
->rx_chains_static
,
1380 ctx
->rx_chains_dynamic
);
1381 mutex_unlock(&mvm
->mutex
);
1384 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw
*hw
,
1385 struct ieee80211_vif
*vif
,
1386 struct ieee80211_chanctx_conf
*ctx
)
1388 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1389 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1390 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
1391 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1394 mutex_lock(&mvm
->mutex
);
1396 mvmvif
->phy_ctxt
= phy_ctxt
;
1398 switch (vif
->type
) {
1399 case NL80211_IFTYPE_AP
:
1401 * The AP binding flow is handled as part of the start_ap flow
1402 * (in bss_info_changed).
1406 case NL80211_IFTYPE_STATION
:
1407 case NL80211_IFTYPE_ADHOC
:
1408 case NL80211_IFTYPE_MONITOR
:
1415 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1420 * Setting the quota at this stage is only required for monitor
1421 * interfaces. For the other types, the bss_info changed flow
1422 * will handle quota settings.
1424 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
1425 mvmvif
->monitor_active
= true;
1426 ret
= iwl_mvm_update_quotas(mvm
, vif
);
1428 goto out_remove_binding
;
1434 iwl_mvm_binding_remove_vif(mvm
, vif
);
1436 mutex_unlock(&mvm
->mutex
);
1438 mvmvif
->phy_ctxt
= NULL
;
1442 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
1443 struct ieee80211_vif
*vif
,
1444 struct ieee80211_chanctx_conf
*ctx
)
1446 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1447 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1449 mutex_lock(&mvm
->mutex
);
1451 iwl_mvm_remove_time_event(mvm
, mvmvif
, &mvmvif
->time_event_data
);
1453 if (vif
->type
== NL80211_IFTYPE_AP
)
1456 switch (vif
->type
) {
1457 case NL80211_IFTYPE_MONITOR
:
1458 mvmvif
->monitor_active
= false;
1459 iwl_mvm_update_quotas(mvm
, NULL
);
1465 iwl_mvm_binding_remove_vif(mvm
, vif
);
1467 mvmvif
->phy_ctxt
= NULL
;
1468 mutex_unlock(&mvm
->mutex
);
1471 static int iwl_mvm_set_tim(struct ieee80211_hw
*hw
,
1472 struct ieee80211_sta
*sta
,
1475 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1476 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
1478 if (!mvm_sta
|| !mvm_sta
->vif
) {
1479 IWL_ERR(mvm
, "Station is not associated to a vif\n");
1483 return iwl_mvm_mac_ctxt_beacon_changed(mvm
, mvm_sta
->vif
);
1486 static void iwl_mvm_mac_rssi_callback(struct ieee80211_hw
*hw
,
1487 struct ieee80211_vif
*vif
,
1488 enum ieee80211_rssi_event rssi_event
)
1490 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1492 iwl_mvm_bt_rssi_event(mvm
, vif
, rssi_event
);
1495 struct ieee80211_ops iwl_mvm_hw_ops
= {
1496 .tx
= iwl_mvm_mac_tx
,
1497 .ampdu_action
= iwl_mvm_mac_ampdu_action
,
1498 .start
= iwl_mvm_mac_start
,
1499 .restart_complete
= iwl_mvm_mac_restart_complete
,
1500 .stop
= iwl_mvm_mac_stop
,
1501 .add_interface
= iwl_mvm_mac_add_interface
,
1502 .remove_interface
= iwl_mvm_mac_remove_interface
,
1503 .config
= iwl_mvm_mac_config
,
1504 .configure_filter
= iwl_mvm_configure_filter
,
1505 .bss_info_changed
= iwl_mvm_bss_info_changed
,
1506 .hw_scan
= iwl_mvm_mac_hw_scan
,
1507 .cancel_hw_scan
= iwl_mvm_mac_cancel_hw_scan
,
1508 .sta_state
= iwl_mvm_mac_sta_state
,
1509 .sta_notify
= iwl_mvm_mac_sta_notify
,
1510 .allow_buffered_frames
= iwl_mvm_mac_allow_buffered_frames
,
1511 .set_rts_threshold
= iwl_mvm_mac_set_rts_threshold
,
1512 .conf_tx
= iwl_mvm_mac_conf_tx
,
1513 .mgd_prepare_tx
= iwl_mvm_mac_mgd_prepare_tx
,
1514 .set_key
= iwl_mvm_mac_set_key
,
1515 .update_tkip_key
= iwl_mvm_mac_update_tkip_key
,
1516 .remain_on_channel
= iwl_mvm_roc
,
1517 .cancel_remain_on_channel
= iwl_mvm_cancel_roc
,
1518 .rssi_callback
= iwl_mvm_mac_rssi_callback
,
1520 .add_chanctx
= iwl_mvm_add_chanctx
,
1521 .remove_chanctx
= iwl_mvm_remove_chanctx
,
1522 .change_chanctx
= iwl_mvm_change_chanctx
,
1523 .assign_vif_chanctx
= iwl_mvm_assign_vif_chanctx
,
1524 .unassign_vif_chanctx
= iwl_mvm_unassign_vif_chanctx
,
1526 .start_ap
= iwl_mvm_start_ap
,
1527 .stop_ap
= iwl_mvm_stop_ap
,
1529 .set_tim
= iwl_mvm_set_tim
,
1531 #ifdef CONFIG_PM_SLEEP
1533 .suspend
= iwl_mvm_suspend
,
1534 .resume
= iwl_mvm_resume
,
1535 .set_wakeup
= iwl_mvm_set_wakeup
,
1536 .set_rekey_data
= iwl_mvm_set_rekey_data
,
1537 #if IS_ENABLED(CONFIG_IPV6)
1538 .ipv6_addr_change
= iwl_mvm_ipv6_addr_change
,
1540 .set_default_unicast_key
= iwl_mvm_set_default_unicast_key
,