iwlwifi: mvm: don't sleep while allocating in atomic context
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / mvm / mac80211.c
CommitLineData
8ca151b5
JB
1/******************************************************************************
2 *
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.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
9 *
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.
13 *
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.
18 *
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,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
410dc5aa 25 * in the file called COPYING.
8ca151b5
JB
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
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
45 * distribution.
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.
49 *
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.
61 *
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>
f0c2646a 68#include <linux/ip.h>
8ca151b5 69#include <net/mac80211.h>
f0c2646a 70#include <net/tcp.h>
8ca151b5
JB
71
72#include "iwl-op-mode.h"
73#include "iwl-io.h"
74#include "mvm.h"
75#include "sta.h"
76#include "time-event.h"
77#include "iwl-eeprom-parse.h"
78#include "fw-api-scan.h"
79#include "iwl-phy-db.h"
507cadf2 80#include "testmode.h"
8ca151b5
JB
81
82static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
83 {
84 .max = 1,
8eb38710 85 .types = BIT(NL80211_IFTYPE_STATION),
8ca151b5 86 },
3c15a0fb
JB
87 {
88 .max = 1,
8eb38710
IP
89 .types = BIT(NL80211_IFTYPE_AP) |
90 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3c15a0fb
JB
91 BIT(NL80211_IFTYPE_P2P_GO),
92 },
93 {
94 .max = 1,
95 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
96 },
8ca151b5
JB
97};
98
99static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
100 {
101 .num_different_channels = 1,
102 .max_interfaces = 3,
103 .limits = iwl_mvm_limits,
104 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
105 },
106};
107
f0c2646a
JB
108#ifdef CONFIG_PM_SLEEP
109static const struct nl80211_wowlan_tcp_data_token_feature
110iwl_mvm_wowlan_tcp_token_feature = {
111 .min_len = 0,
112 .max_len = 255,
113 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
114};
115
116static 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),
127 .seq = true,
128};
129#endif
130
fe0f2de3
IP
131static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
132{
133 int i;
134
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;
139 }
140}
141
8ca151b5
JB
142int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
143{
144 struct ieee80211_hw *hw = mvm->hw;
831e85f3 145 int num_mac, ret, i;
8ca151b5
JB
146
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 |
8ca151b5
JB
153 IEEE80211_HW_SUPPORTS_PS |
154 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
d2931bbd 155 IEEE80211_HW_AMPDU_AGGREGATION |
d64048ed 156 IEEE80211_HW_TIMING_BEACON_ONLY |
147fc9be
EG
157 IEEE80211_HW_CONNECTION_MONITOR |
158 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
e3c588ec
AB
159 IEEE80211_HW_SUPPORTS_STATIC_SMPS |
160 IEEE80211_HW_SUPPORTS_UAPSD;
8ca151b5 161
398e8c6c
IP
162 hw->queues = IWL_MVM_FIRST_AGG_QUEUE;
163 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
8ca151b5
JB
164 hw->rate_control_algorithm = "iwl-mvm-rs";
165
166 /*
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)
170 */
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;
174
175 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
176 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
fe0f2de3 177 hw->chanctx_data_size = sizeof(u16);
8ca151b5
JB
178
179 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3c15a0fb
JB
180 BIT(NL80211_IFTYPE_P2P_CLIENT) |
181 BIT(NL80211_IFTYPE_AP) |
182 BIT(NL80211_IFTYPE_P2P_GO) |
183 BIT(NL80211_IFTYPE_P2P_DEVICE);
8ca151b5
JB
184
185 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
186 WIPHY_FLAG_DISABLE_BEACON_HINTS |
187 WIPHY_FLAG_IBSS_RSN;
188
189 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
190 hw->wiphy->n_iface_combinations =
191 ARRAY_SIZE(iwl_mvm_iface_combinations);
192
c451e6d4 193 hw->wiphy->max_remain_on_channel_duration = 10000;
8ca151b5 194 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
e3c588ec
AB
195 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
196 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
8ca151b5
JB
197
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;
831e85f3
IP
202
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;
206
207 for (i = 1; i < num_mac; i++) {
208 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
8ca151b5 209 ETH_ALEN);
831e85f3 210 mvm->addresses[i].addr[5]++;
8ca151b5
JB
211 hw->wiphy->n_addresses++;
212 }
213
fe0f2de3
IP
214 iwl_mvm_reset_phy_ctxts(mvm);
215
8ca151b5
JB
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;
220
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];
227
228 hw->wiphy->hw_version = mvm->trans->hw_id;
229
ade50652 230 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
8ca151b5
JB
231 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
232 else
233 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
234
235 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
236 NL80211_FEATURE_P2P_GO_OPPPS;
237
238 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
239
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)) {
964dc9e2
JB
245 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
246 WIPHY_WOWLAN_DISCONNECT |
247 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
248 WIPHY_WOWLAN_RFKILL_RELEASE;
8ca151b5 249 if (!iwlwifi_mod_params.sw_crypto)
964dc9e2
JB
250 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
251 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
252 WIPHY_WOWLAN_4WAY_HANDSHAKE;
253
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;
8ca151b5
JB
259 }
260#endif
261
262 ret = iwl_mvm_leds_init(mvm);
263 if (ret)
264 return ret;
265
b7327d89
EG
266 ret = ieee80211_register_hw(mvm->hw);
267 if (ret)
268 iwl_mvm_leds_exit(mvm);
269
270 return ret;
8ca151b5
JB
271}
272
273static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
274 struct ieee80211_tx_control *control,
275 struct sk_buff *skb)
276{
277 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
278
9ee718aa
EL
279 if (iwl_mvm_is_radio_killed(mvm)) {
280 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
8ca151b5
JB
281 goto drop;
282 }
283
398e8c6c 284 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
8ca151b5
JB
285 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
286 goto drop;
287
288 if (control->sta) {
289 if (iwl_mvm_tx_skb(mvm, skb, control->sta))
290 goto drop;
291 return;
292 }
293
294 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
295 goto drop;
296 return;
297 drop:
298 ieee80211_free_txskb(hw, skb);
299}
300
301static 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)
306{
307 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
308 int ret;
309
310 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
311 sta->addr, tid, action);
312
313 if (!(mvm->nvm_data->sku_cap_11n_enable))
314 return -EACCES;
315
316 mutex_lock(&mvm->mutex);
317
318 switch (action) {
319 case IEEE80211_AMPDU_RX_START:
320 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG) {
321 ret = -EINVAL;
322 break;
323 }
324 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
325 break;
326 case IEEE80211_AMPDU_RX_STOP:
327 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
328 break;
329 case IEEE80211_AMPDU_TX_START:
5d158efa
EG
330 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) {
331 ret = -EINVAL;
332 break;
333 }
8ca151b5
JB
334 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
335 break;
336 case IEEE80211_AMPDU_TX_STOP_CONT:
e3d9e7ce
EG
337 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
338 break;
8ca151b5
JB
339 case IEEE80211_AMPDU_TX_STOP_FLUSH:
340 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
e3d9e7ce 341 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
8ca151b5
JB
342 break;
343 case IEEE80211_AMPDU_TX_OPERATIONAL:
344 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
345 break;
346 default:
347 WARN_ON_ONCE(1);
348 ret = -EINVAL;
349 break;
350 }
351 mutex_unlock(&mvm->mutex);
352
353 return ret;
354}
355
356static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
357 struct ieee80211_vif *vif)
358{
359 struct iwl_mvm *mvm = data;
360 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
361
362 mvmvif->uploaded = false;
363 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
364
365 /* does this make sense at all? */
366 mvmvif->color++;
367
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);
371
fe0f2de3 372 mvmvif->phy_ctxt = NULL;
8ca151b5
JB
373}
374
375static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
376{
377 iwl_trans_stop_device(mvm->trans);
378 iwl_trans_stop_hw(mvm->trans, false);
379
380 mvm->scan_status = IWL_MVM_SCAN_NONE;
381
382 /* just in case one was running */
383 ieee80211_remain_on_channel_expired(mvm->hw);
384
385 ieee80211_iterate_active_interfaces_atomic(
386 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
387 iwl_mvm_cleanup_iterator, mvm);
388
fe0f2de3
IP
389 mvm->p2p_device_vif = NULL;
390
391 iwl_mvm_reset_phy_ctxts(mvm);
8ca151b5
JB
392 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
393 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
394
395 ieee80211_wake_queues(mvm->hw);
396
397 mvm->vif_count = 0;
113a0447 398 mvm->rx_ba_sessions = 0;
8ca151b5
JB
399}
400
401static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
402{
403 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
404 int ret;
405
406 mutex_lock(&mvm->mutex);
407
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);
411
412 ret = iwl_mvm_up(mvm);
413 mutex_unlock(&mvm->mutex);
414
415 return ret;
416}
417
418static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
419{
420 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
421 int ret;
422
423 mutex_lock(&mvm->mutex);
424
425 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
426 ret = iwl_mvm_update_quotas(mvm, NULL);
427 if (ret)
428 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
429 ret);
430
431 mutex_unlock(&mvm->mutex);
432}
433
434static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
435{
436 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
437
438 flush_work(&mvm->async_handlers_wk);
439
440 mutex_lock(&mvm->mutex);
441 /* async_handlers_wk is now blocked */
442
443 /*
444 * The work item could be running or queued if the
445 * ROC time event stops just as we get here.
446 */
447 cancel_work_sync(&mvm->roc_done_wk);
448
449 iwl_trans_stop_device(mvm->trans);
450 iwl_trans_stop_hw(mvm->trans, false);
451
452 iwl_mvm_async_handlers_purge(mvm);
453 /* async_handlers_list is empty and will stay empty: HW is stopped */
454
455 /* the fw is stopped, the aux sta is dead: clean up driver state */
456 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
457
458 mutex_unlock(&mvm->mutex);
459
460 /*
461 * The worker might have been waiting for the mutex, let it run and
462 * discover that its list is now empty.
463 */
464 cancel_work_sync(&mvm->async_handlers_wk);
465}
466
467static void iwl_mvm_pm_disable_iterator(void *data, u8 *mac,
468 struct ieee80211_vif *vif)
469{
470 struct iwl_mvm *mvm = data;
471 int ret;
472
473 ret = iwl_mvm_power_disable(mvm, vif);
474 if (ret)
475 IWL_ERR(mvm, "failed to disable power management\n");
476}
477
478static void iwl_mvm_power_update_iterator(void *data, u8 *mac,
479 struct ieee80211_vif *vif)
480{
481 struct iwl_mvm *mvm = data;
482
483 iwl_mvm_power_update_mode(mvm, vif);
484}
485
fe0f2de3
IP
486static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
487{
488 u16 i;
489
490 lockdep_assert_held(&mvm->mutex);
491
492 for (i = 0; i < NUM_PHY_CTX; i++)
493 if (!mvm->phy_ctxts[i].ref)
494 return &mvm->phy_ctxts[i];
495
496 IWL_ERR(mvm, "No available PHY context\n");
497 return NULL;
498}
499
8ca151b5
JB
500static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
501 struct ieee80211_vif *vif)
502{
503 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
504 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
505 int ret;
506
507 /*
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.
511 */
512
513 mutex_lock(&mvm->mutex);
514
e89044d7 515 /* Allocate resources for the MAC context, and add it to the fw */
8ca151b5
JB
516 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
517 if (ret)
518 goto out_unlock;
519
ea183d02
IP
520 /*
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
526 * interface.
527 * Note: the method below does not count the new interface being added
528 * at this moment.
529 */
530 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
531 mvm->vif_count++;
532 if (mvm->vif_count > 1) {
533 IWL_DEBUG_MAC80211(mvm,
534 "Disable power on existing interfaces\n");
535 ieee80211_iterate_active_interfaces_atomic(
536 mvm->hw,
537 IEEE80211_IFACE_ITER_NORMAL,
538 iwl_mvm_pm_disable_iterator, mvm);
539 }
540
8ca151b5
JB
541 /*
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 :)
551 */
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,
555 qmask);
556 if (ret) {
557 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
558 goto out_release;
559 }
560
77740cb4 561 iwl_mvm_vif_dbgfs_register(mvm, vif);
8ca151b5
JB
562 goto out_unlock;
563 }
564
8ca151b5
JB
565 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
566 if (ret)
567 goto out_release;
568
569 /*
570 * Update power state on the new interface. Admittedly, based on
571 * mac80211 logics this power update will disable power management
572 */
573 iwl_mvm_power_update_mode(mvm, vif);
574
7df15b1e 575 /* beacon filtering */
bd3351ba
EP
576 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
577 if (ret)
578 goto out_remove_mac;
579
7df15b1e 580 if (!mvm->bf_allowed_vif &&
5dca7c24
HG
581 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
582 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED){
7df15b1e 583 mvm->bf_allowed_vif = mvmvif;
a20fd398
AO
584 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
585 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
7df15b1e
HG
586 }
587
8ca151b5
JB
588 /*
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.
592 */
593 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
8ca151b5 594
fe0f2de3
IP
595 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
596 if (!mvmvif->phy_ctxt) {
597 ret = -ENOSPC;
bd3351ba 598 goto out_free_bf;
fe0f2de3 599 }
8ca151b5 600
53a9d61e 601 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
8ca151b5
JB
602 ret = iwl_mvm_binding_add_vif(mvm, vif);
603 if (ret)
53a9d61e 604 goto out_unref_phy;
8ca151b5
JB
605
606 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
607 if (ret)
608 goto out_unbind;
609
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;
613 }
614
63494374 615 iwl_mvm_vif_dbgfs_register(mvm, vif);
8ca151b5
JB
616 goto out_unlock;
617
618 out_unbind:
619 iwl_mvm_binding_remove_vif(mvm, vif);
53a9d61e 620 out_unref_phy:
fe0f2de3 621 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
bd3351ba
EP
622 out_free_bf:
623 if (mvm->bf_allowed_vif == mvmvif) {
624 mvm->bf_allowed_vif = NULL;
a20fd398
AO
625 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
626 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
bd3351ba 627 }
8ca151b5
JB
628 out_remove_mac:
629 mvmvif->phy_ctxt = NULL;
630 iwl_mvm_mac_ctxt_remove(mvm, vif);
631 out_release:
5ee2b215
AB
632 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
633 mvm->vif_count--;
4bf881f5
AB
634 ieee80211_iterate_active_interfaces(
635 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
636 iwl_mvm_power_update_iterator, mvm);
8ca151b5
JB
637 iwl_mvm_mac_ctxt_release(mvm, vif);
638 out_unlock:
639 mutex_unlock(&mvm->mutex);
640
641 return ret;
642}
643
38a12b5b
JB
644static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
645 struct ieee80211_vif *vif)
8ca151b5 646{
8ca151b5
JB
647 u32 tfd_msk = 0, ac;
648
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]);
652
653 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
654 tfd_msk |= BIT(vif->cab_queue);
655
656 if (tfd_msk) {
657 mutex_lock(&mvm->mutex);
658 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
659 mutex_unlock(&mvm->mutex);
660 }
661
662 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
663 /*
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.
667 */
668 flush_work(&mvm->roc_done_wk);
669 } else {
670 /*
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
0742a75a 674 * triggered. Flush it.
8ca151b5
JB
675 */
676 flush_work(&mvm->sta_drained_wk);
677 }
38a12b5b
JB
678}
679
680static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
681 struct ieee80211_vif *vif)
682{
683 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
684 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
685
686 iwl_mvm_prepare_mac_removal(mvm, vif);
8ca151b5
JB
687
688 mutex_lock(&mvm->mutex);
689
7df15b1e
HG
690 if (mvm->bf_allowed_vif == mvmvif) {
691 mvm->bf_allowed_vif = NULL;
a20fd398
AO
692 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
693 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
7df15b1e
HG
694 }
695
63494374
JB
696 iwl_mvm_vif_dbgfs_clean(mvm, vif);
697
8ca151b5
JB
698 /*
699 * For AP/GO interface, the tear down of the resources allocated to the
38a12b5b 700 * interface is be handled as part of the stop_ap flow.
8ca151b5
JB
701 */
702 if (vif->type == NL80211_IFTYPE_AP) {
507cadf2
DS
703#ifdef CONFIG_NL80211_TESTMODE
704 if (vif == mvm->noa_vif) {
705 mvm->noa_vif = NULL;
706 mvm->noa_duration = 0;
707 }
708#endif
8ca151b5
JB
709 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
710 goto out_release;
711 }
712
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);
fe0f2de3 717 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
8ca151b5
JB
718 mvmvif->phy_ctxt = NULL;
719 }
720
721 /*
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.
726 */
5ee2b215 727 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
8ca151b5
JB
728 mvm->vif_count--;
729 IWL_DEBUG_MAC80211(mvm, "Currently %d interfaces active\n",
730 mvm->vif_count);
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);
735 }
736
737 iwl_mvm_mac_ctxt_remove(mvm, vif);
738
739out_release:
740 iwl_mvm_mac_ctxt_release(mvm, vif);
741 mutex_unlock(&mvm->mutex);
742}
743
88f2fd73
MG
744static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
745 s8 tx_power)
746{
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),
751 };
752
753 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, CMD_SYNC,
754 sizeof(reduce_txpwr_cmd),
755 &reduce_txpwr_cmd);
756}
757
8ca151b5
JB
758static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
759{
760 return 0;
761}
762
763static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
764 unsigned int changed_flags,
765 unsigned int *total_flags,
766 u64 multicast)
767{
768 *total_flags = 0;
769}
770
51b6b9e0
EG
771static int iwl_mvm_configure_mcast_filter(struct iwl_mvm *mvm,
772 struct ieee80211_vif *vif)
773{
774 struct iwl_mcast_filter_cmd mcast_filter_cmd = {
775 .pass_all = 1,
776 };
777
778 memcpy(mcast_filter_cmd.bssid, vif->bss_conf.bssid, ETH_ALEN);
779
780 return iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_SYNC,
781 sizeof(mcast_filter_cmd),
782 &mcast_filter_cmd);
783}
784
8ca151b5
JB
785static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
786 struct ieee80211_vif *vif,
787 struct ieee80211_bss_conf *bss_conf,
788 u32 changes)
789{
790 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
791 int ret;
792
793 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
794 if (ret)
795 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
796
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);
801 if (ret) {
802 IWL_ERR(mvm, "failed to update quotas\n");
803 return;
804 }
51b6b9e0 805 iwl_mvm_configure_mcast_filter(mvm, vif);
016d27e1
JB
806
807 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
808 &mvm->status)) {
809 /*
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.
815 *
816 * The firmware needs to receive a beacon to
817 * catch up with synchronisation, use 110% of
818 * the beacon interval.
819 *
820 * Set a large maximum delay to allow for more
821 * than a single interface.
822 */
823 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
824 iwl_mvm_protect_session(mvm, vif, dur, dur,
825 5 * dur);
826 }
8ca151b5
JB
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);
830 if (ret)
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);
835 if (ret)
836 IWL_ERR(mvm, "failed to update quotas\n");
837 }
a20fd398
AO
838
839 /* reset rssi values */
840 mvmvif->bf_data.ave_beacon_signal = 0;
841
e811ada7
AB
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
845 */
846 ret = iwl_mvm_power_update_mode(mvm, vif);
847 if (ret)
848 IWL_ERR(mvm, "failed to update power mode\n");
849 }
41069b46 850 iwl_mvm_bt_coex_vif_assoc(mvm, vif);
989c6505 851 } else if (changes & BSS_CHANGED_BEACON_INFO) {
210a544e
JB
852 /*
853 * We received a beacon _after_ association so
854 * remove the session protection.
855 */
856 iwl_mvm_remove_time_event(mvm, mvmvif,
857 &mvmvif->time_event_data);
e3c588ec 858 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_QOS)) {
4bf881f5
AB
859 ret = iwl_mvm_power_update_mode(mvm, vif);
860 if (ret)
861 IWL_ERR(mvm, "failed to update power mode\n");
8ca151b5 862 }
88f2fd73
MG
863 if (changes & BSS_CHANGED_TXPOWER) {
864 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
865 bss_conf->txpower);
866 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
867 }
a20fd398
AO
868
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);
874 if (ret)
875 IWL_ERR(mvm, "failed to update CQM thresholds\n");
876 }
8ca151b5
JB
877}
878
879static int iwl_mvm_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
880{
881 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
882 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
883 int ret;
884
885 mutex_lock(&mvm->mutex);
886
887 /* Send the beacon template */
888 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
889 if (ret)
890 goto out_unlock;
891
892 /* Add the mac context */
893 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
894 if (ret)
895 goto out_unlock;
896
897 /* Perform the binding */
898 ret = iwl_mvm_binding_add_vif(mvm, vif);
899 if (ret)
900 goto out_remove;
901
902 mvmvif->ap_active = true;
903
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);
907 if (ret)
908 goto out_unbind;
909
910 ret = iwl_mvm_update_quotas(mvm, vif);
911 if (ret)
912 goto out_rm_bcast;
913
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);
917
918 mutex_unlock(&mvm->mutex);
919 return 0;
920
921out_rm_bcast:
922 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
923out_unbind:
924 iwl_mvm_binding_remove_vif(mvm, vif);
925out_remove:
926 iwl_mvm_mac_ctxt_remove(mvm, vif);
927out_unlock:
928 mutex_unlock(&mvm->mutex);
929 return ret;
930}
931
932static void iwl_mvm_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
933{
934 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
935 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
936
38a12b5b
JB
937 iwl_mvm_prepare_mac_removal(mvm, vif);
938
8ca151b5
JB
939 mutex_lock(&mvm->mutex);
940
941 mvmvif->ap_active = false;
942
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);
946
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);
951
952 mutex_unlock(&mvm->mutex);
953}
954
955static void iwl_mvm_bss_info_changed_ap(struct iwl_mvm *mvm,
956 struct ieee80211_vif *vif,
957 struct ieee80211_bss_conf *bss_conf,
958 u32 changes)
959{
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");
964 }
965}
966
967static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
968 struct ieee80211_vif *vif,
969 struct ieee80211_bss_conf *bss_conf,
970 u32 changes)
971{
972 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
973
974 mutex_lock(&mvm->mutex);
975
976 switch (vif->type) {
977 case NL80211_IFTYPE_STATION:
978 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
979 break;
980 case NL80211_IFTYPE_AP:
981 iwl_mvm_bss_info_changed_ap(mvm, vif, bss_conf, changes);
982 break;
983 default:
984 /* shouldn't happen */
985 WARN_ON_ONCE(1);
986 }
987
988 mutex_unlock(&mvm->mutex);
989}
990
991static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
992 struct ieee80211_vif *vif,
993 struct cfg80211_scan_request *req)
994{
995 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
996 int ret;
997
998 if (req->n_channels == 0 || req->n_channels > MAX_NUM_SCAN_CHANNELS)
999 return -EINVAL;
1000
1001 mutex_lock(&mvm->mutex);
1002
1003 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
1004 ret = iwl_mvm_scan_request(mvm, vif, req);
1005 else
1006 ret = -EBUSY;
1007
1008 mutex_unlock(&mvm->mutex);
1009
1010 return ret;
1011}
1012
1013static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1014 struct ieee80211_vif *vif)
1015{
1016 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1017
1018 mutex_lock(&mvm->mutex);
1019
1020 iwl_mvm_cancel_scan(mvm);
1021
1022 mutex_unlock(&mvm->mutex);
1023}
1024
1025static void
1026iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
1027 struct ieee80211_sta *sta, u16 tid,
1028 int num_frames,
1029 enum ieee80211_frame_release_type reason,
1030 bool more_data)
1031{
1032 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
8ca151b5
JB
1033
1034 /* TODO: how do we tell the fw to send frames for a specific TID */
1035
1036 /*
1037 * The fw will send EOSP notification when the last frame will be
1038 * transmitted.
1039 */
9cc40712 1040 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames);
8ca151b5
JB
1041}
1042
1043static 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)
1047{
1048 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1049 struct iwl_mvm_sta *mvmsta = (void *)sta->drv_priv;
1050
1051 switch (cmd) {
1052 case STA_NOTIFY_SLEEP:
e3d4bc8c 1053 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
8ca151b5
JB
1054 ieee80211_sta_block_awake(hw, sta, true);
1055 /*
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.
1059 */
1060 break;
1061 case STA_NOTIFY_AWAKE:
881acd89 1062 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
8ca151b5 1063 break;
9cc40712 1064 iwl_mvm_sta_modify_ps_wake(mvm, sta);
8ca151b5
JB
1065 break;
1066 default:
1067 break;
1068 }
1069}
1070
1071static 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)
1076{
1077 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1078 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1079 int ret;
1080
1081 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1082 sta->addr, old_state, new_state);
1083
1084 /* this would be a mac80211 bug ... but don't crash */
1085 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1086 return -EINVAL;
1087
1088 /* if a STA is being removed, reuse its ID */
1089 flush_work(&mvm->sta_drained_wk);
1090
1091 mutex_lock(&mvm->mutex);
1092 if (old_state == IEEE80211_STA_NOTEXIST &&
1093 new_state == IEEE80211_STA_NONE) {
48bc1307
JB
1094 /*
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...
1100 */
1101 if (vif->type == NL80211_IFTYPE_STATION &&
1102 vif->bss_conf.beacon_int < 16) {
1103 IWL_ERR(mvm,
1104 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1105 sta->addr, vif->bss_conf.beacon_int);
1106 ret = -EINVAL;
1107 goto out_unlock;
1108 }
8ca151b5
JB
1109 ret = iwl_mvm_add_sta(mvm, vif, sta);
1110 } else if (old_state == IEEE80211_STA_NONE &&
1111 new_state == IEEE80211_STA_AUTH) {
1112 ret = 0;
1113 } else if (old_state == IEEE80211_STA_AUTH &&
1114 new_state == IEEE80211_STA_ASSOC) {
7a453973
JB
1115 ret = iwl_mvm_update_sta(mvm, vif, sta);
1116 if (ret == 0)
1117 iwl_mvm_rs_rate_init(mvm, sta,
1118 mvmvif->phy_ctxt->channel->band);
8ca151b5
JB
1119 } else if (old_state == IEEE80211_STA_ASSOC &&
1120 new_state == IEEE80211_STA_AUTHORIZED) {
7df15b1e
HG
1121 /* enable beacon filtering */
1122 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
8ca151b5
JB
1123 ret = 0;
1124 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1125 new_state == IEEE80211_STA_ASSOC) {
7df15b1e
HG
1126 /* disable beacon filtering */
1127 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif));
8ca151b5
JB
1128 ret = 0;
1129 } else if (old_state == IEEE80211_STA_ASSOC &&
1130 new_state == IEEE80211_STA_AUTH) {
1131 ret = 0;
1132 } else if (old_state == IEEE80211_STA_AUTH &&
1133 new_state == IEEE80211_STA_NONE) {
1134 ret = 0;
1135 } else if (old_state == IEEE80211_STA_NONE &&
1136 new_state == IEEE80211_STA_NOTEXIST) {
1137 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1138 } else {
1139 ret = -EIO;
1140 }
48bc1307 1141 out_unlock:
8ca151b5
JB
1142 mutex_unlock(&mvm->mutex);
1143
1144 return ret;
1145}
1146
1147static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1148{
1149 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1150
1151 mvm->rts_threshold = value;
1152
1153 return 0;
1154}
1155
1156static 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)
1159{
1160 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1161 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1162
1163 mvmvif->queue_params[ac] = *params;
1164
1165 /*
1166 * No need to update right away, we'll get BSS_CHANGED_QOS
1167 * The exception is P2P_DEVICE interface which needs immediate update.
1168 */
1169 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1170 int ret;
1171
1172 mutex_lock(&mvm->mutex);
1173 ret = iwl_mvm_mac_ctxt_changed(mvm, vif);
1174 mutex_unlock(&mvm->mutex);
1175 return ret;
1176 }
1177 return 0;
1178}
1179
1180static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1181 struct ieee80211_vif *vif)
1182{
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);
1188
1189 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1190 return;
1191
1192 mutex_lock(&mvm->mutex);
1193 /* Try really hard to protect the session and hear a beacon */
016d27e1 1194 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
8ca151b5
JB
1195 mutex_unlock(&mvm->mutex);
1196}
1197
1198static 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)
1203{
1204 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1205 int ret;
1206
1207 if (iwlwifi_mod_params.sw_crypto) {
1208 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
1209 return -EOPNOTSUPP;
1210 }
1211
1212 switch (key->cipher) {
1213 case WLAN_CIPHER_SUITE_TKIP:
1214 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1215 /* fall-through */
1216 case WLAN_CIPHER_SUITE_CCMP:
1217 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1218 break;
1219 case WLAN_CIPHER_SUITE_AES_CMAC:
1220 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
1221 break;
1222 case WLAN_CIPHER_SUITE_WEP40:
1223 case WLAN_CIPHER_SUITE_WEP104:
1224 /*
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.
1228 */
1229 return 0;
1230 default:
1231 return -EOPNOTSUPP;
1232 }
1233
1234 mutex_lock(&mvm->mutex);
1235
1236 switch (cmd) {
1237 case SET_KEY:
6caffd4f
JB
1238 if (vif->type == NL80211_IFTYPE_AP && !sta) {
1239 /* GTK on AP interface is a TX-only key, return 0 */
1240 ret = 0;
1241 key->hw_key_idx = STA_KEY_IDX_INVALID;
1242 break;
1243 }
1244
8ca151b5
JB
1245 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
1246 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
1247 if (ret) {
1248 IWL_WARN(mvm, "set key failed\n");
1249 /*
1250 * can't add key for RX, but we don't need it
1251 * in the device for TX so still return 0
1252 */
6caffd4f 1253 key->hw_key_idx = STA_KEY_IDX_INVALID;
8ca151b5
JB
1254 ret = 0;
1255 }
1256
1257 break;
1258 case DISABLE_KEY:
6caffd4f
JB
1259 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
1260 ret = 0;
1261 break;
1262 }
1263
8ca151b5
JB
1264 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
1265 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
1266 break;
1267 default:
1268 ret = -EINVAL;
1269 }
1270
1271 mutex_unlock(&mvm->mutex);
1272 return ret;
1273}
1274
1275static 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)
1280{
1281 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1282
1283 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
1284}
1285
1286
1287static int iwl_mvm_roc(struct ieee80211_hw *hw,
1288 struct ieee80211_vif *vif,
1289 struct ieee80211_channel *channel,
d339d5ca
IP
1290 int duration,
1291 enum ieee80211_roc_type type)
8ca151b5
JB
1292{
1293 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3 1294 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8ca151b5 1295 struct cfg80211_chan_def chandef;
31d385ae
IP
1296 struct iwl_mvm_phy_ctxt *phy_ctxt;
1297 int ret, i;
1298
1299 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
1300 duration, type);
8ca151b5
JB
1301
1302 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
1303 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
1304 return -EINVAL;
1305 }
1306
8ca151b5
JB
1307 mutex_lock(&mvm->mutex);
1308
31d385ae
IP
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)
1312 continue;
1313
1314 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
1315 /*
1316 * Unbind the P2P_DEVICE from the current PHY context,
1317 * and if the PHY context is not used remove it.
1318 */
1319 ret = iwl_mvm_binding_remove_vif(mvm, vif);
1320 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
1321 goto out_unlock;
1322
1323 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1324
1325 /* Bind the P2P_DEVICE to the current PHY Context */
1326 mvmvif->phy_ctxt = phy_ctxt;
1327
1328 ret = iwl_mvm_binding_add_vif(mvm, vif);
1329 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1330 goto out_unlock;
1331
1332 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1333 goto schedule_time_event;
1334 }
1335 }
1336
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;
1340
8ca151b5 1341 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
8ca151b5 1342
31d385ae
IP
1343 /*
1344 * Change the PHY context configuration as it is currently referenced
1345 * only by the P2P Device MAC
1346 */
1347 if (mvmvif->phy_ctxt->ref == 1) {
1348 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
1349 &chandef, 1, 1);
1350 if (ret)
1351 goto out_unlock;
1352 } else {
1353 /*
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
1357 */
1358 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1359 if (!phy_ctxt) {
1360 ret = -ENOSPC;
1361 goto out_unlock;
1362 }
1363
1364 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
1365 1, 1);
1366 if (ret) {
1367 IWL_ERR(mvm, "Failed to change PHY context\n");
1368 goto out_unlock;
1369 }
1370
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"))
1374 goto out_unlock;
1375
1376 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1377
1378 /* Bind the P2P_DEVICE to the new allocated PHY context */
1379 mvmvif->phy_ctxt = phy_ctxt;
1380
1381 ret = iwl_mvm_binding_add_vif(mvm, vif);
1382 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
1383 goto out_unlock;
1384
1385 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1386 }
1387
1388schedule_time_event:
8ca151b5 1389 /* Schedule the time events */
e635c797 1390 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
8ca151b5 1391
31d385ae 1392out_unlock:
8ca151b5
JB
1393 mutex_unlock(&mvm->mutex);
1394 IWL_DEBUG_MAC80211(mvm, "leave\n");
8ca151b5
JB
1395 return ret;
1396}
1397
1398static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
1399{
1400 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1401
1402 IWL_DEBUG_MAC80211(mvm, "enter\n");
1403
1404 mutex_lock(&mvm->mutex);
1405 iwl_mvm_stop_p2p_roc(mvm);
1406 mutex_unlock(&mvm->mutex);
1407
1408 IWL_DEBUG_MAC80211(mvm, "leave\n");
1409 return 0;
1410}
1411
1412static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
1413 struct ieee80211_chanctx_conf *ctx)
1414{
1415 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
1416 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1417 struct iwl_mvm_phy_ctxt *phy_ctxt;
8ca151b5
JB
1418 int ret;
1419
53a9d61e 1420 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
fe0f2de3 1421
8ca151b5 1422 mutex_lock(&mvm->mutex);
fe0f2de3
IP
1423 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1424 if (!phy_ctxt) {
1425 ret = -ENOSPC;
1426 goto out;
1427 }
8ca151b5 1428
53a9d61e
IP
1429 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->def,
1430 ctx->rx_chains_static,
1431 ctx->rx_chains_dynamic);
fe0f2de3
IP
1432 if (ret) {
1433 IWL_ERR(mvm, "Failed to add PHY context\n");
1434 goto out;
1435 }
1436
53a9d61e 1437 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
fe0f2de3
IP
1438 *phy_ctxt_id = phy_ctxt->id;
1439out:
8ca151b5
JB
1440 mutex_unlock(&mvm->mutex);
1441 return ret;
1442}
1443
1444static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
1445 struct ieee80211_chanctx_conf *ctx)
1446{
1447 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
1448 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1449 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
8ca151b5
JB
1450
1451 mutex_lock(&mvm->mutex);
fe0f2de3 1452 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
8ca151b5
JB
1453 mutex_unlock(&mvm->mutex);
1454}
1455
1456static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
1457 struct ieee80211_chanctx_conf *ctx,
1458 u32 changed)
1459{
1460 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
1461 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1462 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
8ca151b5 1463
31d385ae
IP
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))
1470 return;
1471
8ca151b5
JB
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);
1477}
1478
1479static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
1480 struct ieee80211_vif *vif,
1481 struct ieee80211_chanctx_conf *ctx)
1482{
1483 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
1484 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
1485 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
8ca151b5
JB
1486 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1487 int ret;
1488
1489 mutex_lock(&mvm->mutex);
1490
fe0f2de3 1491 mvmvif->phy_ctxt = phy_ctxt;
8ca151b5
JB
1492
1493 switch (vif->type) {
1494 case NL80211_IFTYPE_AP:
1495 /*
1496 * The AP binding flow is handled as part of the start_ap flow
1497 * (in bss_info_changed).
1498 */
1499 ret = 0;
1500 goto out_unlock;
1501 case NL80211_IFTYPE_STATION:
1502 case NL80211_IFTYPE_ADHOC:
1503 case NL80211_IFTYPE_MONITOR:
1504 break;
1505 default:
1506 ret = -EINVAL;
1507 goto out_unlock;
1508 }
1509
1510 ret = iwl_mvm_binding_add_vif(mvm, vif);
1511 if (ret)
1512 goto out_unlock;
1513
1514 /*
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.
1518 */
1519 if (vif->type == NL80211_IFTYPE_MONITOR) {
1e1391ca 1520 mvmvif->monitor_active = true;
8ca151b5
JB
1521 ret = iwl_mvm_update_quotas(mvm, vif);
1522 if (ret)
1523 goto out_remove_binding;
1524 }
1525
1526 goto out_unlock;
1527
1528 out_remove_binding:
1529 iwl_mvm_binding_remove_vif(mvm, vif);
1530 out_unlock:
1531 mutex_unlock(&mvm->mutex);
1532 if (ret)
1533 mvmvif->phy_ctxt = NULL;
1534 return ret;
1535}
1536
1537static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
1538 struct ieee80211_vif *vif,
1539 struct ieee80211_chanctx_conf *ctx)
1540{
1541 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1542 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1543
1544 mutex_lock(&mvm->mutex);
1545
1546 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
1547
1548 if (vif->type == NL80211_IFTYPE_AP)
1549 goto out_unlock;
1550
8ca151b5
JB
1551 switch (vif->type) {
1552 case NL80211_IFTYPE_MONITOR:
1e1391ca
IP
1553 mvmvif->monitor_active = false;
1554 iwl_mvm_update_quotas(mvm, NULL);
8ca151b5
JB
1555 break;
1556 default:
1557 break;
1558 }
1559
1e1391ca 1560 iwl_mvm_binding_remove_vif(mvm, vif);
8ca151b5
JB
1561out_unlock:
1562 mvmvif->phy_ctxt = NULL;
1563 mutex_unlock(&mvm->mutex);
1564}
1565
1566static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
1567 struct ieee80211_sta *sta,
1568 bool set)
1569{
1570 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1571 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1572
1573 if (!mvm_sta || !mvm_sta->vif) {
1574 IWL_ERR(mvm, "Station is not associated to a vif\n");
1575 return -EINVAL;
1576 }
1577
1578 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
1579}
1580
507cadf2
DS
1581#ifdef CONFIG_NL80211_TESTMODE
1582static 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 },
f6c6ad42 1585 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
507cadf2
DS
1586};
1587
1588static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
1589 struct ieee80211_vif *vif,
1590 void *data, int len)
1591{
1592 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
1593 int err;
1594 u32 noa_duration;
1595
1596 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
1597 if (err)
1598 return err;
1599
1600 if (!tb[IWL_MVM_TM_ATTR_CMD])
1601 return -EINVAL;
1602
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])
1608 return -EINVAL;
1609
1610 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
1611 if (noa_duration >= vif->bss_conf.beacon_int)
1612 return -EINVAL;
1613
1614 mvm->noa_duration = noa_duration;
1615 mvm->noa_vif = vif;
1616
1617 return iwl_mvm_update_quotas(mvm, NULL);
f6c6ad42
JB
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])
1623 return -EINVAL;
1624
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);
507cadf2
DS
1628 }
1629
1630 return -EOPNOTSUPP;
1631}
1632
1633static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
1634 struct ieee80211_vif *vif,
1635 void *data, int len)
1636{
1637 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1638 int err;
1639
1640 mutex_lock(&mvm->mutex);
1641 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
1642 mutex_unlock(&mvm->mutex);
1643
1644 return err;
1645}
1646#endif
1647
8ca151b5
JB
1648struct 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,
8ca151b5
JB
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,
1676
1677 .start_ap = iwl_mvm_start_ap,
1678 .stop_ap = iwl_mvm_stop_ap,
1679
1680 .set_tim = iwl_mvm_set_tim,
1681
507cadf2
DS
1682 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
1683
8ca151b5
JB
1684#ifdef CONFIG_PM_SLEEP
1685 /* look at d3.c */
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,
1692#endif
1693 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
1694#endif
1695};
This page took 0.145948 seconds and 5 git commands to generate.