iwlwifi: mvm: kill iwl_mvm_fw_error_rxf_dump
[linux-2.6-block.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 *
51368bf7 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8ca151b5
JB
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 *
51368bf7 33 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8ca151b5
JB
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>
2ee8f021 69#include <linux/if_arp.h>
8ca151b5 70#include <net/mac80211.h>
7b1dd048 71#include <net/ieee80211_radiotap.h>
f0c2646a 72#include <net/tcp.h>
8ca151b5
JB
73
74#include "iwl-op-mode.h"
75#include "iwl-io.h"
76#include "mvm.h"
77#include "sta.h"
78#include "time-event.h"
79#include "iwl-eeprom-parse.h"
80#include "fw-api-scan.h"
81#include "iwl-phy-db.h"
507cadf2 82#include "testmode.h"
655e6d6d
EG
83#include "iwl-fw-error-dump.h"
84#include "iwl-prph.h"
8ca151b5
JB
85
86static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
87 {
88 .max = 1,
8eb38710 89 .types = BIT(NL80211_IFTYPE_STATION),
8ca151b5 90 },
3c15a0fb
JB
91 {
92 .max = 1,
8eb38710
IP
93 .types = BIT(NL80211_IFTYPE_AP) |
94 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3c15a0fb
JB
95 BIT(NL80211_IFTYPE_P2P_GO),
96 },
97 {
98 .max = 1,
99 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
100 },
8ca151b5
JB
101};
102
103static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
104 {
105 .num_different_channels = 1,
106 .max_interfaces = 3,
107 .limits = iwl_mvm_limits,
108 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
109 },
110};
111
f0c2646a
JB
112#ifdef CONFIG_PM_SLEEP
113static const struct nl80211_wowlan_tcp_data_token_feature
114iwl_mvm_wowlan_tcp_token_feature = {
115 .min_len = 0,
116 .max_len = 255,
117 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
118};
119
120static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
121 .tok = &iwl_mvm_wowlan_tcp_token_feature,
122 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
123 sizeof(struct ethhdr) -
124 sizeof(struct iphdr) -
125 sizeof(struct tcphdr),
126 .data_interval_max = 65535, /* __le16 in API */
127 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
128 sizeof(struct ethhdr) -
129 sizeof(struct iphdr) -
130 sizeof(struct tcphdr),
131 .seq = true,
132};
133#endif
134
77736923 135#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
2ee8f021
EP
136/*
137 * Use the reserved field to indicate magic values.
138 * these values will only be used internally by the driver,
139 * and won't make it to the fw (reserved will be 0).
140 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
141 * be the vif's ip address. in case there is not a single
142 * ip address (0, or more than 1), this attribute will
143 * be skipped.
144 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
145 * the LSB bytes of the vif's mac address
146 */
147enum {
148 BC_FILTER_MAGIC_NONE = 0,
149 BC_FILTER_MAGIC_IP,
150 BC_FILTER_MAGIC_MAC,
151};
152
77736923
EP
153static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
154 {
155 /* arp */
156 .discard = 0,
157 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
158 .attrs = {
159 {
160 /* frame type - arp, hw type - ethernet */
161 .offset_type =
162 BCAST_FILTER_OFFSET_PAYLOAD_START,
163 .offset = sizeof(rfc1042_header),
164 .val = cpu_to_be32(0x08060001),
165 .mask = cpu_to_be32(0xffffffff),
166 },
2ee8f021
EP
167 {
168 /* arp dest ip */
169 .offset_type =
170 BCAST_FILTER_OFFSET_PAYLOAD_START,
171 .offset = sizeof(rfc1042_header) + 2 +
172 sizeof(struct arphdr) +
173 ETH_ALEN + sizeof(__be32) +
174 ETH_ALEN,
175 .mask = cpu_to_be32(0xffffffff),
176 /* mark it as special field */
177 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
178 },
179 },
180 },
181 {
182 /* dhcp offer bcast */
183 .discard = 0,
184 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
185 .attrs = {
186 {
187 /* udp dest port - 68 (bootp client)*/
188 .offset_type = BCAST_FILTER_OFFSET_IP_END,
189 .offset = offsetof(struct udphdr, dest),
190 .val = cpu_to_be32(0x00440000),
191 .mask = cpu_to_be32(0xffff0000),
192 },
193 {
194 /* dhcp - lsb bytes of client hw address */
195 .offset_type = BCAST_FILTER_OFFSET_IP_END,
196 .offset = 38,
197 .mask = cpu_to_be32(0xffffffff),
198 /* mark it as special field */
199 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
200 },
77736923
EP
201 },
202 },
203 /* last filter must be empty */
204 {},
205};
206#endif
207
7498cf4c
EP
208void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
209{
7bb426ea 210 if (!iwl_mvm_is_d0i3_supported(mvm))
7498cf4c
EP
211 return;
212
213 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
214 WARN_ON(test_and_set_bit(ref_type, mvm->ref_bitmap));
215 iwl_trans_ref(mvm->trans);
216}
217
218void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
219{
7bb426ea 220 if (!iwl_mvm_is_d0i3_supported(mvm))
7498cf4c
EP
221 return;
222
223 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
224 WARN_ON(!test_and_clear_bit(ref_type, mvm->ref_bitmap));
225 iwl_trans_unref(mvm->trans);
226}
227
228static void
229iwl_mvm_unref_all_except(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref)
230{
231 int i;
232
7bb426ea 233 if (!iwl_mvm_is_d0i3_supported(mvm))
7498cf4c
EP
234 return;
235
236 for_each_set_bit(i, mvm->ref_bitmap, IWL_MVM_REF_COUNT) {
237 if (ref == i)
238 continue;
239
240 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d\n", i);
241 clear_bit(i, mvm->ref_bitmap);
242 iwl_trans_unref(mvm->trans);
243 }
244}
245
fe0f2de3
IP
246static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
247{
248 int i;
249
250 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
251 for (i = 0; i < NUM_PHY_CTX; i++) {
252 mvm->phy_ctxts[i].id = i;
253 mvm->phy_ctxts[i].ref = 0;
254 }
255}
256
20f1a5de
DS
257static int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm)
258{
259 /* we create the 802.11 header and SSID element */
260 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID)
261 return mvm->fw->ucode_capa.max_probe_length - 24 - 2;
262 return mvm->fw->ucode_capa.max_probe_length - 24 - 34;
263}
264
8ca151b5
JB
265int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
266{
267 struct ieee80211_hw *hw = mvm->hw;
831e85f3 268 int num_mac, ret, i;
8ca151b5
JB
269
270 /* Tell mac80211 our characteristics */
271 hw->flags = IEEE80211_HW_SIGNAL_DBM |
272 IEEE80211_HW_SPECTRUM_MGMT |
273 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
274 IEEE80211_HW_QUEUE_CONTROL |
275 IEEE80211_HW_WANT_MONITOR_VIF |
8ca151b5
JB
276 IEEE80211_HW_SUPPORTS_PS |
277 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
d2931bbd 278 IEEE80211_HW_AMPDU_AGGREGATION |
d64048ed 279 IEEE80211_HW_TIMING_BEACON_ONLY |
147fc9be
EG
280 IEEE80211_HW_CONNECTION_MONITOR |
281 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
e8e626ad 282 IEEE80211_HW_SUPPORTS_STATIC_SMPS;
8ca151b5 283
19e737c9 284 hw->queues = mvm->first_agg_queue;
398e8c6c 285 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
7b1dd048
EG
286 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
287 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
288 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC;
8ca151b5
JB
289 hw->rate_control_algorithm = "iwl-mvm-rs";
290
291 /*
292 * Enable 11w if advertised by firmware and software crypto
293 * is not enabled (as the firmware will interpret some mgmt
294 * packets, so enabling it with software crypto isn't safe)
295 */
296 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
297 !iwlwifi_mod_params.sw_crypto)
298 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
299
1504f48d
MC
300 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT &&
301 IWL_UCODE_API(mvm->fw->ucode_ver) >= 9 &&
302 !iwlwifi_mod_params.uapsd_disable) {
303 hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
304 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
305 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
306 }
e8e626ad 307
a42c9fcc
AN
308 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT &&
309 !iwlwifi_mod_params.uapsd_disable) {
310 hw->flags |= IEEE80211_HW_SUPPORTS_UAPSD;
311 hw->uapsd_queues = IWL_UAPSD_AC_INFO;
312 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
313 }
e8e626ad 314
8ca151b5
JB
315 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
316 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
fe0f2de3 317 hw->chanctx_data_size = sizeof(u16);
8ca151b5
JB
318
319 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3c15a0fb
JB
320 BIT(NL80211_IFTYPE_P2P_CLIENT) |
321 BIT(NL80211_IFTYPE_AP) |
322 BIT(NL80211_IFTYPE_P2P_GO) |
c13b1725
EG
323 BIT(NL80211_IFTYPE_P2P_DEVICE) |
324 BIT(NL80211_IFTYPE_ADHOC);
5023d966 325
a2f73b6c
LR
326 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
327 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
328 REGULATORY_DISABLE_BEACON_HINTS;
8ca151b5 329
3e56eadf
JB
330 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
331 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
332
bd3398e2
AO
333 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_CSA_FLOW)
334 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
335
8ca151b5
JB
336 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
337 hw->wiphy->n_iface_combinations =
338 ARRAY_SIZE(iwl_mvm_iface_combinations);
339
c451e6d4 340 hw->wiphy->max_remain_on_channel_duration = 10000;
8ca151b5
JB
341 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
342
343 /* Extract MAC address */
344 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
345 hw->wiphy->addresses = mvm->addresses;
346 hw->wiphy->n_addresses = 1;
831e85f3
IP
347
348 /* Extract additional MAC addresses if available */
349 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
350 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
351
352 for (i = 1; i < num_mac; i++) {
353 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
8ca151b5 354 ETH_ALEN);
831e85f3 355 mvm->addresses[i].addr[5]++;
8ca151b5
JB
356 hw->wiphy->n_addresses++;
357 }
358
fe0f2de3
IP
359 iwl_mvm_reset_phy_ctxts(mvm);
360
20f1a5de
DS
361 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
362
8ca151b5
JB
363 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
364
365 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
366 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
367 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
368 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels)
369 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
370 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
371
372 hw->wiphy->hw_version = mvm->trans->hw_id;
373
ade50652 374 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
8ca151b5
JB
375 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
376 else
377 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
378
536a3eee
EG
379 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
380 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
381 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
382 /* we create the 802.11 header and zero length SSID IE. */
383 hw->wiphy->max_sched_scan_ie_len = SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
35a000b7 384
8ca151b5 385 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
ab480030 386 NL80211_FEATURE_LOW_PRIORITY_SCAN |
8a110d9b 387 NL80211_FEATURE_P2P_GO_OPPPS;
8ca151b5
JB
388
389 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
390
e36e5433 391 /* currently FW API supports only one optional cipher scheme */
9ddca860 392 if (mvm->fw->cs[0].cipher) {
e36e5433 393 mvm->hw->n_cipher_schemes = 1;
9ddca860 394 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
e36e5433
MS
395 }
396
8ca151b5 397#ifdef CONFIG_PM_SLEEP
d15a747f
EP
398 if (iwl_mvm_is_d0i3_supported(mvm) &&
399 device_can_wakeup(mvm->trans->dev)) {
400 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
401 hw->wiphy->wowlan = &mvm->wowlan;
402 } else if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
8ca151b5
JB
403 mvm->trans->ops->d3_suspend &&
404 mvm->trans->ops->d3_resume &&
405 device_can_wakeup(mvm->trans->dev)) {
964dc9e2
JB
406 mvm->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
407 WIPHY_WOWLAN_DISCONNECT |
408 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
409 WIPHY_WOWLAN_RFKILL_RELEASE;
8ca151b5 410 if (!iwlwifi_mod_params.sw_crypto)
964dc9e2
JB
411 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
412 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
413 WIPHY_WOWLAN_4WAY_HANDSHAKE;
414
415 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
416 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
417 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
418 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
419 hw->wiphy->wowlan = &mvm->wowlan;
8ca151b5
JB
420 }
421#endif
422
77736923
EP
423#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
424 /* assign default bcast filtering configuration */
425 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
426#endif
427
8ca151b5
JB
428 ret = iwl_mvm_leds_init(mvm);
429 if (ret)
430 return ret;
431
b7327d89
EG
432 ret = ieee80211_register_hw(mvm->hw);
433 if (ret)
434 iwl_mvm_leds_exit(mvm);
435
436 return ret;
8ca151b5
JB
437}
438
b2492501
AN
439static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
440 struct ieee80211_sta *sta,
441 struct sk_buff *skb)
442{
443 struct iwl_mvm_sta *mvmsta;
444 bool defer = false;
445
446 /*
447 * double check the IN_D0I3 flag both before and after
448 * taking the spinlock, in order to prevent taking
449 * the spinlock when not needed.
450 */
451 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
452 return false;
453
454 spin_lock(&mvm->d0i3_tx_lock);
455 /*
456 * testing the flag again ensures the skb dequeue
457 * loop (on d0i3 exit) hasn't run yet.
458 */
459 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
460 goto out;
461
462 mvmsta = iwl_mvm_sta_from_mac80211(sta);
463 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
464 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
465 goto out;
466
467 __skb_queue_tail(&mvm->d0i3_tx, skb);
468 ieee80211_stop_queues(mvm->hw);
469
470 /* trigger wakeup */
471 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
472 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
473
474 defer = true;
475out:
476 spin_unlock(&mvm->d0i3_tx_lock);
477 return defer;
478}
479
8ca151b5
JB
480static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
481 struct ieee80211_tx_control *control,
482 struct sk_buff *skb)
483{
484 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3e56eadf
JB
485 struct ieee80211_sta *sta = control->sta;
486 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
487 struct ieee80211_hdr *hdr = (void *)skb->data;
8ca151b5 488
9ee718aa
EL
489 if (iwl_mvm_is_radio_killed(mvm)) {
490 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
8ca151b5
JB
491 goto drop;
492 }
493
398e8c6c 494 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
8ca151b5
JB
495 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status))
496 goto drop;
497
3e56eadf
JB
498 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
499 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
500 ieee80211_is_mgmt(hdr->frame_control) &&
501 !ieee80211_is_deauth(hdr->frame_control) &&
502 !ieee80211_is_disassoc(hdr->frame_control) &&
503 !ieee80211_is_action(hdr->frame_control)))
504 sta = NULL;
505
506 if (sta) {
b2492501
AN
507 if (iwl_mvm_defer_tx(mvm, sta, skb))
508 return;
3e56eadf 509 if (iwl_mvm_tx_skb(mvm, skb, sta))
8ca151b5
JB
510 goto drop;
511 return;
512 }
513
514 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
515 goto drop;
516 return;
517 drop:
518 ieee80211_free_txskb(hw, skb);
519}
520
205e2210
EG
521static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
522{
523 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
524 return false;
525 return true;
526}
527
528static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
529{
530 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
531 return false;
532 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
533 return true;
534
535 /* enabled by default */
536 return true;
537}
538
8ca151b5
JB
539static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
540 struct ieee80211_vif *vif,
541 enum ieee80211_ampdu_mlme_action action,
542 struct ieee80211_sta *sta, u16 tid,
543 u16 *ssn, u8 buf_size)
544{
545 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
546 int ret;
b2492501 547 bool tx_agg_ref = false;
8ca151b5
JB
548
549 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
550 sta->addr, tid, action);
551
552 if (!(mvm->nvm_data->sku_cap_11n_enable))
553 return -EACCES;
554
b2492501 555 /* return from D0i3 before starting a new Tx aggregation */
9256c205
EP
556 switch (action) {
557 case IEEE80211_AMPDU_TX_START:
558 case IEEE80211_AMPDU_TX_STOP_CONT:
559 case IEEE80211_AMPDU_TX_STOP_FLUSH:
560 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
561 case IEEE80211_AMPDU_TX_OPERATIONAL:
b2492501
AN
562 iwl_mvm_ref(mvm, IWL_MVM_REF_TX_AGG);
563 tx_agg_ref = true;
564
565 /*
9256c205
EP
566 * for tx start, wait synchronously until D0i3 exit to
567 * get the correct sequence number for the tid.
568 * additionally, some other ampdu actions use direct
569 * target access, which is not handled automatically
570 * by the trans layer (unlike commands), so wait for
571 * d0i3 exit in these cases as well.
b2492501
AN
572 */
573 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
574 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status), HZ)) {
575 WARN_ON_ONCE(1);
576 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
577 return -EIO;
578 }
9256c205
EP
579 break;
580 default:
581 break;
b2492501
AN
582 }
583
8ca151b5
JB
584 mutex_lock(&mvm->mutex);
585
586 switch (action) {
587 case IEEE80211_AMPDU_RX_START:
205e2210 588 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
8ca151b5
JB
589 ret = -EINVAL;
590 break;
591 }
592 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
593 break;
594 case IEEE80211_AMPDU_RX_STOP:
595 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
596 break;
597 case IEEE80211_AMPDU_TX_START:
205e2210 598 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
5d158efa
EG
599 ret = -EINVAL;
600 break;
601 }
8ca151b5
JB
602 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
603 break;
604 case IEEE80211_AMPDU_TX_STOP_CONT:
e3d9e7ce
EG
605 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
606 break;
8ca151b5
JB
607 case IEEE80211_AMPDU_TX_STOP_FLUSH:
608 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
e3d9e7ce 609 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
8ca151b5
JB
610 break;
611 case IEEE80211_AMPDU_TX_OPERATIONAL:
612 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
613 break;
614 default:
615 WARN_ON_ONCE(1);
616 ret = -EINVAL;
617 break;
618 }
619 mutex_unlock(&mvm->mutex);
620
b2492501
AN
621 /*
622 * If the tid is marked as started, we won't use it for offloaded
623 * traffic on the next D0i3 entry. It's safe to unref.
624 */
625 if (tx_agg_ref)
626 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
627
8ca151b5
JB
628 return ret;
629}
630
631static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
632 struct ieee80211_vif *vif)
633{
634 struct iwl_mvm *mvm = data;
635 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
636
637 mvmvif->uploaded = false;
638 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
639
640 /* does this make sense at all? */
641 mvmvif->color++;
642
643 spin_lock_bh(&mvm->time_event_lock);
644 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
645 spin_unlock_bh(&mvm->time_event_lock);
646
fe0f2de3 647 mvmvif->phy_ctxt = NULL;
8ca151b5
JB
648}
649
655e6d6d
EG
650#ifdef CONFIG_IWLWIFI_DEBUGFS
651static void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
652{
653 struct iwl_fw_error_dump_file *dump_file;
654 struct iwl_fw_error_dump_data *dump_data;
655 struct iwl_fw_error_dump_info *dump_info;
656 const struct fw_img *img;
657 u32 sram_len, sram_ofs;
658 u32 file_len, rxf_len;
659 unsigned long flags;
660 u32 trans_len;
661 int reg_val;
662
663 lockdep_assert_held(&mvm->mutex);
664
665 if (mvm->fw_error_dump)
666 return;
667
668 img = &mvm->fw->img[mvm->cur_ucode];
669 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
670 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
671
672 /* reading buffer size */
673 reg_val = iwl_trans_read_prph(mvm->trans, RXF_SIZE_ADDR);
674 rxf_len = (reg_val & RXF_SIZE_BYTE_CNT_MSK) >> RXF_SIZE_BYTE_CND_POS;
675
676 /* the register holds the value divided by 128 */
677 rxf_len = rxf_len << 7;
678
679 file_len = sizeof(*dump_file) +
680 sizeof(*dump_data) * 3 +
681 sram_len +
682 rxf_len +
683 sizeof(*dump_info);
684
685 trans_len = iwl_trans_dump_data(mvm->trans, NULL, 0);
686 if (trans_len)
687 file_len += trans_len;
688
689 dump_file = vmalloc(file_len);
690 if (!dump_file)
691 return;
692
693 mvm->fw_error_dump = dump_file;
694
695 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
696 dump_file->file_len = cpu_to_le32(file_len);
697 dump_data = (void *)dump_file->data;
698
699 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
700 dump_data->len = cpu_to_le32(sizeof(*dump_info));
701 dump_info = (void *) dump_data->data;
702 dump_info->device_family =
703 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
704 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
705 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
706 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
707 sizeof(dump_info->fw_human_readable));
708 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
709 sizeof(dump_info->dev_human_readable));
710 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
711 sizeof(dump_info->bus_human_readable));
712
713 dump_data = iwl_fw_error_next_data(dump_data);
714 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
715 dump_data->len = cpu_to_le32(rxf_len);
716
717 if (iwl_trans_grab_nic_access(mvm->trans, false, &flags)) {
718 u32 *rxf = (void *)dump_data->data;
719 int i;
720
721 for (i = 0; i < (rxf_len / sizeof(u32)); i++) {
722 iwl_trans_write_prph(mvm->trans,
723 RXF_LD_FENCE_OFFSET_ADDR,
724 i * sizeof(u32));
725 rxf[i] = iwl_trans_read_prph(mvm->trans,
726 RXF_FIFO_RD_FENCE_ADDR);
727 }
728 iwl_trans_release_nic_access(mvm->trans, &flags);
729 }
730
731 dump_data = iwl_fw_error_next_data(dump_data);
732 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_SRAM);
733 dump_data->len = cpu_to_le32(sram_len);
734 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_data->data,
735 sram_len);
736
737 if (trans_len) {
738 void *buf = iwl_fw_error_next_data(dump_data);
739 u32 real_trans_len = iwl_trans_dump_data(mvm->trans, buf,
740 trans_len);
741 dump_data = (void *)((u8 *)buf + real_trans_len);
742 dump_file->file_len =
743 cpu_to_le32(file_len - trans_len + real_trans_len);
744 }
745}
746#endif
747
8ca151b5
JB
748static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
749{
1bd3cbc1
EG
750#ifdef CONFIG_IWLWIFI_DEBUGFS
751 static char *env[] = { "DRIVER=iwlwifi", "EVENT=error_dump", NULL };
752
753 iwl_mvm_fw_error_dump(mvm);
754
755 /* notify the userspace about the error we had */
756 kobject_uevent_env(&mvm->hw->wiphy->dev.kobj, KOBJ_CHANGE, env);
757#endif
758
8ca151b5 759 iwl_trans_stop_device(mvm->trans);
8ca151b5
JB
760
761 mvm->scan_status = IWL_MVM_SCAN_NONE;
762
763 /* just in case one was running */
764 ieee80211_remain_on_channel_expired(mvm->hw);
765
766 ieee80211_iterate_active_interfaces_atomic(
767 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
768 iwl_mvm_cleanup_iterator, mvm);
769
fe0f2de3 770 mvm->p2p_device_vif = NULL;
37577fe2 771 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
fe0f2de3
IP
772
773 iwl_mvm_reset_phy_ctxts(mvm);
8ca151b5
JB
774 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
775 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
776
777 ieee80211_wake_queues(mvm->hw);
778
7498cf4c
EP
779 /* cleanup all stale references (scan, roc), but keep the
780 * ucode_down ref until reconfig is complete */
781 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
782
8ca151b5 783 mvm->vif_count = 0;
113a0447 784 mvm->rx_ba_sessions = 0;
8ca151b5
JB
785}
786
787static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
788{
789 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
790 int ret;
791
792 mutex_lock(&mvm->mutex);
793
794 /* Clean up some internal and mac80211 state on restart */
795 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
796 iwl_mvm_restart_cleanup(mvm);
797
798 ret = iwl_mvm_up(mvm);
c47af22a
JB
799
800 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
801 /* Something went wrong - we need to finish some cleanup
802 * that normally iwl_mvm_mac_restart_complete() below
803 * would do.
804 */
805 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
806 iwl_mvm_d0i3_enable_tx(mvm, NULL);
807 }
808
8ca151b5
JB
809 mutex_unlock(&mvm->mutex);
810
811 return ret;
812}
813
814static void iwl_mvm_mac_restart_complete(struct ieee80211_hw *hw)
815{
816 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
817 int ret;
818
819 mutex_lock(&mvm->mutex);
820
821 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
b2492501 822 iwl_mvm_d0i3_enable_tx(mvm, NULL);
8ca151b5
JB
823 ret = iwl_mvm_update_quotas(mvm, NULL);
824 if (ret)
825 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
826 ret);
827
7498cf4c
EP
828 /* allow transport/FW low power modes */
829 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
830
8ca151b5
JB
831 mutex_unlock(&mvm->mutex);
832}
833
834static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
835{
836 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
837
37577fe2 838 flush_work(&mvm->d0i3_exit_work);
8ca151b5
JB
839 flush_work(&mvm->async_handlers_wk);
840
841 mutex_lock(&mvm->mutex);
7498cf4c
EP
842
843 /* disallow low power states when the FW is down */
844 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
845
8ca151b5
JB
846 /* async_handlers_wk is now blocked */
847
848 /*
849 * The work item could be running or queued if the
850 * ROC time event stops just as we get here.
851 */
852 cancel_work_sync(&mvm->roc_done_wk);
853
854 iwl_trans_stop_device(mvm->trans);
8ca151b5
JB
855
856 iwl_mvm_async_handlers_purge(mvm);
857 /* async_handlers_list is empty and will stay empty: HW is stopped */
858
859 /* the fw is stopped, the aux sta is dead: clean up driver state */
860 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
861
862 mutex_unlock(&mvm->mutex);
863
864 /*
865 * The worker might have been waiting for the mutex, let it run and
866 * discover that its list is now empty.
867 */
868 cancel_work_sync(&mvm->async_handlers_wk);
869}
870
fe0f2de3
IP
871static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
872{
873 u16 i;
874
875 lockdep_assert_held(&mvm->mutex);
876
877 for (i = 0; i < NUM_PHY_CTX; i++)
878 if (!mvm->phy_ctxts[i].ref)
879 return &mvm->phy_ctxts[i];
880
881 IWL_ERR(mvm, "No available PHY context\n");
882 return NULL;
883}
884
ee9c6cb0
EG
885static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
886 s8 tx_power)
887{
888 /* FW is in charge of regulatory enforcement */
889 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
890 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
891 .pwr_restriction = cpu_to_le16(tx_power),
892 };
893
a1022927 894 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
ee9c6cb0
EG
895 sizeof(reduce_txpwr_cmd),
896 &reduce_txpwr_cmd);
897}
898
8ca151b5
JB
899static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
900 struct ieee80211_vif *vif)
901{
902 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
903 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
904 int ret;
905
906 /*
907 * Not much to do here. The stack will not allow interface
908 * types or combinations that we didn't advertise, so we
909 * don't really have to check the types.
910 */
911
912 mutex_lock(&mvm->mutex);
913
e89044d7 914 /* Allocate resources for the MAC context, and add it to the fw */
8ca151b5
JB
915 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
916 if (ret)
917 goto out_unlock;
918
1c2abf72 919 /* Counting number of interfaces is needed for legacy PM */
ea183d02
IP
920 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
921 mvm->vif_count++;
ea183d02 922
8ca151b5
JB
923 /*
924 * The AP binding flow can be done only after the beacon
925 * template is configured (which happens only in the mac80211
926 * start_ap() flow), and adding the broadcast station can happen
927 * only after the binding.
928 * In addition, since modifying the MAC before adding a bcast
929 * station is not allowed by the FW, delay the adding of MAC context to
930 * the point where we can also add the bcast station.
931 * In short: there's not much we can do at this point, other than
932 * allocating resources :)
933 */
5023d966
JB
934 if (vif->type == NL80211_IFTYPE_AP ||
935 vif->type == NL80211_IFTYPE_ADHOC) {
8ca151b5
JB
936 u32 qmask = iwl_mvm_mac_get_queues_mask(mvm, vif);
937 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta,
b92e661b
EP
938 qmask,
939 ieee80211_vif_type_p2p(vif));
8ca151b5
JB
940 if (ret) {
941 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
942 goto out_release;
943 }
944
77740cb4 945 iwl_mvm_vif_dbgfs_register(mvm, vif);
8ca151b5
JB
946 goto out_unlock;
947 }
948
8ca151b5
JB
949 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
950 if (ret)
951 goto out_release;
952
999609f1 953 ret = iwl_mvm_power_update_mac(mvm);
e5e7aa8e
EG
954 if (ret)
955 goto out_release;
8ca151b5 956
7df15b1e 957 /* beacon filtering */
a1022927 958 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
bd3351ba
EP
959 if (ret)
960 goto out_remove_mac;
961
7df15b1e 962 if (!mvm->bf_allowed_vif &&
73e5f2c5 963 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
7df15b1e 964 mvm->bf_allowed_vif = mvmvif;
a20fd398
AO
965 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
966 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
7df15b1e
HG
967 }
968
8ca151b5
JB
969 /*
970 * P2P_DEVICE interface does not have a channel context assigned to it,
971 * so a dedicated PHY context is allocated to it and the corresponding
972 * MAC context is bound to it at this stage.
973 */
974 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
8ca151b5 975
fe0f2de3
IP
976 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
977 if (!mvmvif->phy_ctxt) {
978 ret = -ENOSPC;
bd3351ba 979 goto out_free_bf;
fe0f2de3 980 }
8ca151b5 981
53a9d61e 982 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
8ca151b5
JB
983 ret = iwl_mvm_binding_add_vif(mvm, vif);
984 if (ret)
53a9d61e 985 goto out_unref_phy;
8ca151b5
JB
986
987 ret = iwl_mvm_add_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
988 if (ret)
989 goto out_unbind;
990
991 /* Save a pointer to p2p device vif, so it can later be used to
992 * update the p2p device MAC when a GO is started/stopped */
993 mvm->p2p_device_vif = vif;
994 }
995
63494374 996 iwl_mvm_vif_dbgfs_register(mvm, vif);
8ca151b5
JB
997 goto out_unlock;
998
999 out_unbind:
1000 iwl_mvm_binding_remove_vif(mvm, vif);
53a9d61e 1001 out_unref_phy:
fe0f2de3 1002 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
bd3351ba
EP
1003 out_free_bf:
1004 if (mvm->bf_allowed_vif == mvmvif) {
1005 mvm->bf_allowed_vif = NULL;
a20fd398
AO
1006 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1007 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
bd3351ba 1008 }
8ca151b5
JB
1009 out_remove_mac:
1010 mvmvif->phy_ctxt = NULL;
1011 iwl_mvm_mac_ctxt_remove(mvm, vif);
1012 out_release:
5ee2b215
AB
1013 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1014 mvm->vif_count--;
1c2abf72 1015
8ca151b5
JB
1016 iwl_mvm_mac_ctxt_release(mvm, vif);
1017 out_unlock:
1018 mutex_unlock(&mvm->mutex);
1019
1020 return ret;
1021}
1022
38a12b5b
JB
1023static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1024 struct ieee80211_vif *vif)
8ca151b5 1025{
8ca151b5
JB
1026 u32 tfd_msk = 0, ac;
1027
1028 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
1029 if (vif->hw_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
1030 tfd_msk |= BIT(vif->hw_queue[ac]);
1031
1032 if (vif->cab_queue != IEEE80211_INVAL_HW_QUEUE)
1033 tfd_msk |= BIT(vif->cab_queue);
1034
1035 if (tfd_msk) {
1036 mutex_lock(&mvm->mutex);
1037 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
1038 mutex_unlock(&mvm->mutex);
1039 }
1040
1041 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1042 /*
1043 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1044 * We assume here that all the packets sent to the OFFCHANNEL
1045 * queue are sent in ROC session.
1046 */
1047 flush_work(&mvm->roc_done_wk);
1048 } else {
1049 /*
1050 * By now, all the AC queues are empty. The AGG queues are
1051 * empty too. We already got all the Tx responses for all the
1052 * packets in the queues. The drain work can have been
0742a75a 1053 * triggered. Flush it.
8ca151b5
JB
1054 */
1055 flush_work(&mvm->sta_drained_wk);
1056 }
38a12b5b
JB
1057}
1058
1059static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1060 struct ieee80211_vif *vif)
1061{
1062 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1063 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1064
1065 iwl_mvm_prepare_mac_removal(mvm, vif);
8ca151b5
JB
1066
1067 mutex_lock(&mvm->mutex);
1068
7df15b1e
HG
1069 if (mvm->bf_allowed_vif == mvmvif) {
1070 mvm->bf_allowed_vif = NULL;
a20fd398
AO
1071 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1072 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
7df15b1e
HG
1073 }
1074
63494374
JB
1075 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1076
8ca151b5
JB
1077 /*
1078 * For AP/GO interface, the tear down of the resources allocated to the
38a12b5b 1079 * interface is be handled as part of the stop_ap flow.
8ca151b5 1080 */
5023d966
JB
1081 if (vif->type == NL80211_IFTYPE_AP ||
1082 vif->type == NL80211_IFTYPE_ADHOC) {
507cadf2
DS
1083#ifdef CONFIG_NL80211_TESTMODE
1084 if (vif == mvm->noa_vif) {
1085 mvm->noa_vif = NULL;
1086 mvm->noa_duration = 0;
1087 }
1088#endif
8ca151b5
JB
1089 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
1090 goto out_release;
1091 }
1092
1093 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1094 mvm->p2p_device_vif = NULL;
1095 iwl_mvm_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1096 iwl_mvm_binding_remove_vif(mvm, vif);
fe0f2de3 1097 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
8ca151b5
JB
1098 mvmvif->phy_ctxt = NULL;
1099 }
1100
5ee2b215 1101 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
8ca151b5 1102 mvm->vif_count--;
1c2abf72 1103
999609f1 1104 iwl_mvm_power_update_mac(mvm);
8ca151b5
JB
1105 iwl_mvm_mac_ctxt_remove(mvm, vif);
1106
1107out_release:
1108 iwl_mvm_mac_ctxt_release(mvm, vif);
1109 mutex_unlock(&mvm->mutex);
1110}
1111
1112static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
88f2fd73 1113{
8ca151b5
JB
1114 return 0;
1115}
1116
e59647ea
EP
1117struct iwl_mvm_mc_iter_data {
1118 struct iwl_mvm *mvm;
1119 int port_id;
1120};
1121
1122static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1123 struct ieee80211_vif *vif)
1124{
1125 struct iwl_mvm_mc_iter_data *data = _data;
1126 struct iwl_mvm *mvm = data->mvm;
1127 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1128 int ret, len;
1129
1130 /* if we don't have free ports, mcast frames will be dropped */
1131 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1132 return;
1133
1134 if (vif->type != NL80211_IFTYPE_STATION ||
1135 !vif->bss_conf.assoc)
1136 return;
1137
1138 cmd->port_id = data->port_id++;
1139 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1140 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1141
1c4abec0 1142 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
e59647ea
EP
1143 if (ret)
1144 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1145}
1146
1147static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1148{
1149 struct iwl_mvm_mc_iter_data iter_data = {
1150 .mvm = mvm,
88f2fd73
MG
1151 };
1152
e59647ea
EP
1153 lockdep_assert_held(&mvm->mutex);
1154
1155 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1156 return;
1157
1c4abec0 1158 ieee80211_iterate_active_interfaces_atomic(
e59647ea
EP
1159 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1160 iwl_mvm_mc_iface_iterator, &iter_data);
88f2fd73
MG
1161}
1162
e59647ea
EP
1163static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1164 struct netdev_hw_addr_list *mc_list)
8ca151b5 1165{
e59647ea
EP
1166 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1167 struct iwl_mcast_filter_cmd *cmd;
1168 struct netdev_hw_addr *addr;
1169 int addr_count = netdev_hw_addr_list_count(mc_list);
1170 bool pass_all = false;
1171 int len;
1172
1173 if (addr_count > MAX_MCAST_FILTERING_ADDRESSES) {
1174 pass_all = true;
1175 addr_count = 0;
1176 }
1177
1178 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1179 cmd = kzalloc(len, GFP_ATOMIC);
1180 if (!cmd)
1181 return 0;
1182
1183 if (pass_all) {
1184 cmd->pass_all = 1;
1185 return (u64)(unsigned long)cmd;
1186 }
1187
1188 netdev_hw_addr_list_for_each(addr, mc_list) {
1189 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1190 cmd->count, addr->addr);
1191 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1192 addr->addr, ETH_ALEN);
1193 cmd->count++;
1194 }
1195
1196 return (u64)(unsigned long)cmd;
8ca151b5
JB
1197}
1198
1199static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1200 unsigned int changed_flags,
1201 unsigned int *total_flags,
1202 u64 multicast)
1203{
e59647ea
EP
1204 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1205 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
8ca151b5 1206
e59647ea 1207 mutex_lock(&mvm->mutex);
51b6b9e0 1208
e59647ea
EP
1209 /* replace previous configuration */
1210 kfree(mvm->mcast_filter_cmd);
1211 mvm->mcast_filter_cmd = cmd;
51b6b9e0 1212
e59647ea
EP
1213 if (!cmd)
1214 goto out;
51b6b9e0 1215
e59647ea
EP
1216 iwl_mvm_recalc_multicast(mvm);
1217out:
1218 mutex_unlock(&mvm->mutex);
1219 *total_flags = 0;
51b6b9e0
EG
1220}
1221
c87163b9
EP
1222#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1223struct iwl_bcast_iter_data {
1224 struct iwl_mvm *mvm;
1225 struct iwl_bcast_filter_cmd *cmd;
1226 u8 current_filter;
1227};
1228
1229static void
1230iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1231 const struct iwl_fw_bcast_filter *in_filter,
1232 struct iwl_fw_bcast_filter *out_filter)
1233{
1234 struct iwl_fw_bcast_filter_attr *attr;
1235 int i;
1236
1237 memcpy(out_filter, in_filter, sizeof(*out_filter));
1238
1239 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1240 attr = &out_filter->attrs[i];
1241
1242 if (!attr->mask)
1243 break;
1244
2ee8f021
EP
1245 switch (attr->reserved1) {
1246 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1247 if (vif->bss_conf.arp_addr_cnt != 1) {
1248 attr->mask = 0;
1249 continue;
1250 }
1251
1252 attr->val = vif->bss_conf.arp_addr_list[0];
1253 break;
1254 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1255 attr->val = *(__be32 *)&vif->addr[2];
1256 break;
1257 default:
1258 break;
1259 }
1260 attr->reserved1 = 0;
c87163b9
EP
1261 out_filter->num_attrs++;
1262 }
1263}
1264
1265static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1266 struct ieee80211_vif *vif)
1267{
1268 struct iwl_bcast_iter_data *data = _data;
1269 struct iwl_mvm *mvm = data->mvm;
1270 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1271 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1272 struct iwl_fw_bcast_mac *bcast_mac;
1273 int i;
1274
1275 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1276 return;
1277
1278 bcast_mac = &cmd->macs[mvmvif->id];
1279
e48393e8
IP
1280 /*
1281 * enable filtering only for associated stations, but not for P2P
1282 * Clients
1283 */
1284 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1285 !vif->bss_conf.assoc)
c87163b9
EP
1286 return;
1287
1288 bcast_mac->default_discard = 1;
1289
1290 /* copy all configured filters */
1291 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1292 /*
1293 * Make sure we don't exceed our filters limit.
1294 * if there is still a valid filter to be configured,
1295 * be on the safe side and just allow bcast for this mac.
1296 */
1297 if (WARN_ON_ONCE(data->current_filter >=
1298 ARRAY_SIZE(cmd->filters))) {
1299 bcast_mac->default_discard = 0;
1300 bcast_mac->attached_filters = 0;
1301 break;
1302 }
1303
1304 iwl_mvm_set_bcast_filter(vif,
1305 &mvm->bcast_filters[i],
1306 &cmd->filters[data->current_filter]);
1307
1308 /* skip current filter if it contains no attributes */
1309 if (!cmd->filters[data->current_filter].num_attrs)
1310 continue;
1311
1312 /* attach the filter to current mac */
1313 bcast_mac->attached_filters |=
1314 cpu_to_le16(BIT(data->current_filter));
1315
1316 data->current_filter++;
1317 }
1318}
1319
de06a59e
EP
1320bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1321 struct iwl_bcast_filter_cmd *cmd)
c87163b9 1322{
c87163b9
EP
1323 struct iwl_bcast_iter_data iter_data = {
1324 .mvm = mvm,
de06a59e 1325 .cmd = cmd,
c87163b9
EP
1326 };
1327
de06a59e
EP
1328 memset(cmd, 0, sizeof(*cmd));
1329 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1330 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1331
1332#ifdef CONFIG_IWLWIFI_DEBUGFS
1333 /* use debugfs filters/macs if override is configured */
1334 if (mvm->dbgfs_bcast_filtering.override) {
1335 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1336 sizeof(cmd->filters));
1337 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1338 sizeof(cmd->macs));
1339 return true;
1340 }
1341#endif
c87163b9
EP
1342
1343 /* if no filters are configured, do nothing */
1344 if (!mvm->bcast_filters)
de06a59e 1345 return false;
c87163b9
EP
1346
1347 /* configure and attach these filters for each associated sta vif */
1348 ieee80211_iterate_active_interfaces(
1349 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1350 iwl_mvm_bcast_filter_iterator, &iter_data);
1351
de06a59e
EP
1352 return true;
1353}
1354static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1355 struct ieee80211_vif *vif)
1356{
1357 struct iwl_bcast_filter_cmd cmd;
1358
1359 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1360 return 0;
1361
1362 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1363 return 0;
1364
a1022927 1365 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
c87163b9
EP
1366 sizeof(cmd), &cmd);
1367}
1368#else
1369static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1370 struct ieee80211_vif *vif)
1371{
1372 return 0;
1373}
1374#endif
1375
8ca151b5
JB
1376static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1377 struct ieee80211_vif *vif,
1378 struct ieee80211_bss_conf *bss_conf,
1379 u32 changes)
1380{
1381 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1382 int ret;
1383
6e97b0d2
IP
1384 /*
1385 * Re-calculate the tsf id, as the master-slave relations depend on the
1386 * beacon interval, which was not known when the station interface was
1387 * added.
1388 */
1389 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1390 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1391
bca49d9a 1392 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false);
8ca151b5
JB
1393 if (ret)
1394 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1395
1396 if (changes & BSS_CHANGED_ASSOC) {
1397 if (bss_conf->assoc) {
1398 /* add quota for this interface */
1399 ret = iwl_mvm_update_quotas(mvm, vif);
1400 if (ret) {
1401 IWL_ERR(mvm, "failed to update quotas\n");
1402 return;
1403 }
016d27e1
JB
1404
1405 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1406 &mvm->status)) {
1407 /*
1408 * If we're restarting then the firmware will
1409 * obviously have lost synchronisation with
1410 * the AP. It will attempt to synchronise by
1411 * itself, but we can make it more reliable by
1412 * scheduling a session protection time event.
1413 *
1414 * The firmware needs to receive a beacon to
1415 * catch up with synchronisation, use 110% of
1416 * the beacon interval.
1417 *
1418 * Set a large maximum delay to allow for more
1419 * than a single interface.
1420 */
1421 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1422 iwl_mvm_protect_session(mvm, vif, dur, dur,
1423 5 * dur);
1424 }
1f3b0ff8
LE
1425
1426 iwl_mvm_sf_update(mvm, vif, false);
175a70b7 1427 iwl_mvm_power_vif_assoc(mvm, vif);
29a90a49
EP
1428 if (vif->p2p)
1429 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
8ca151b5 1430 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1f3b0ff8
LE
1431 /*
1432 * If update fails - SF might be running in associated
1433 * mode while disassociated - which is forbidden.
1434 */
1435 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1436 "Failed to update SF upon disassociation\n");
1437
8ca151b5
JB
1438 /* remove AP station now that the MAC is unassoc */
1439 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1440 if (ret)
1441 IWL_ERR(mvm, "failed to remove AP station\n");
37577fe2
EP
1442
1443 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1444 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
8ca151b5
JB
1445 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1446 /* remove quota for this interface */
1447 ret = iwl_mvm_update_quotas(mvm, NULL);
1448 if (ret)
1449 IWL_ERR(mvm, "failed to update quotas\n");
29a90a49
EP
1450
1451 if (vif->p2p)
1452 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
8ca151b5 1453 }
a20fd398 1454
e59647ea 1455 iwl_mvm_recalc_multicast(mvm);
c87163b9 1456 iwl_mvm_configure_bcast_filter(mvm, vif);
e59647ea 1457
a20fd398
AO
1458 /* reset rssi values */
1459 mvmvif->bf_data.ave_beacon_signal = 0;
1460
8e484f0b 1461 iwl_mvm_bt_coex_vif_change(mvm);
f94045ed
EG
1462 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1463 IEEE80211_SMPS_AUTOMATIC);
989c6505 1464 } else if (changes & BSS_CHANGED_BEACON_INFO) {
210a544e
JB
1465 /*
1466 * We received a beacon _after_ association so
1467 * remove the session protection.
1468 */
1469 iwl_mvm_remove_time_event(mvm, mvmvif,
1470 &mvmvif->time_event_data);
0229cdaf 1471 iwl_mvm_sf_update(mvm, vif, false);
a1022927 1472 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
51498cf6
AB
1473 } else if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS |
1474 BSS_CHANGED_QOS)) {
999609f1 1475 ret = iwl_mvm_power_update_mac(mvm);
4bf881f5
AB
1476 if (ret)
1477 IWL_ERR(mvm, "failed to update power mode\n");
8ca151b5 1478 }
88f2fd73
MG
1479 if (changes & BSS_CHANGED_TXPOWER) {
1480 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1481 bss_conf->txpower);
1482 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1483 }
a20fd398
AO
1484
1485 if (changes & BSS_CHANGED_CQM) {
3c6acb61 1486 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
a20fd398
AO
1487 /* reset cqm events tracking */
1488 mvmvif->bf_data.last_cqm_event = 0;
fa7b2e7f
AA
1489 if (mvmvif->bf_data.bf_enabled) {
1490 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1491 if (ret)
1492 IWL_ERR(mvm,
1493 "failed to update CQM thresholds\n");
1494 }
a20fd398 1495 }
2ee8f021
EP
1496
1497 if (changes & BSS_CHANGED_ARP_FILTER) {
3c6acb61 1498 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2ee8f021
EP
1499 iwl_mvm_configure_bcast_filter(mvm, vif);
1500 }
8ca151b5
JB
1501}
1502
5023d966
JB
1503static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1504 struct ieee80211_vif *vif)
8ca151b5
JB
1505{
1506 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1507 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1508 int ret;
1509
1510 mutex_lock(&mvm->mutex);
1511
1512 /* Send the beacon template */
1513 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1514 if (ret)
1515 goto out_unlock;
1516
6e97b0d2
IP
1517 /*
1518 * Re-calculate the tsf id, as the master-slave relations depend on the
1519 * beacon interval, which was not known when the AP interface was added.
1520 */
1521 if (vif->type == NL80211_IFTYPE_AP)
1522 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1523
8ca151b5
JB
1524 /* Add the mac context */
1525 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1526 if (ret)
1527 goto out_unlock;
1528
1529 /* Perform the binding */
1530 ret = iwl_mvm_binding_add_vif(mvm, vif);
1531 if (ret)
1532 goto out_remove;
1533
8ca151b5
JB
1534 /* Send the bcast station. At this stage the TBTT and DTIM time events
1535 * are added and applied to the scheduler */
1536 ret = iwl_mvm_send_bcast_sta(mvm, vif, &mvmvif->bcast_sta);
1537 if (ret)
1538 goto out_unbind;
1539
5691e218
IP
1540 /* must be set before quota calculations */
1541 mvmvif->ap_ibss_active = true;
1542
a11e144e 1543 /* power updated needs to be done before quotas */
999609f1 1544 iwl_mvm_power_update_mac(mvm);
a11e144e 1545
8ca151b5
JB
1546 ret = iwl_mvm_update_quotas(mvm, vif);
1547 if (ret)
a11e144e 1548 goto out_quota_failed;
8ca151b5 1549
5023d966 1550 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
8ca151b5 1551 if (vif->p2p && mvm->p2p_device_vif)
bca49d9a 1552 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false);
8ca151b5 1553
29a90a49
EP
1554 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1555
8e484f0b 1556 iwl_mvm_bt_coex_vif_change(mvm);
dac94da8 1557
8ca151b5
JB
1558 mutex_unlock(&mvm->mutex);
1559 return 0;
1560
a11e144e 1561out_quota_failed:
999609f1 1562 iwl_mvm_power_update_mac(mvm);
5691e218 1563 mvmvif->ap_ibss_active = false;
8ca151b5
JB
1564 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1565out_unbind:
1566 iwl_mvm_binding_remove_vif(mvm, vif);
1567out_remove:
1568 iwl_mvm_mac_ctxt_remove(mvm, vif);
1569out_unlock:
1570 mutex_unlock(&mvm->mutex);
1571 return ret;
1572}
1573
5023d966
JB
1574static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
1575 struct ieee80211_vif *vif)
8ca151b5
JB
1576{
1577 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1578 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1579
38a12b5b
JB
1580 iwl_mvm_prepare_mac_removal(mvm, vif);
1581
8ca151b5
JB
1582 mutex_lock(&mvm->mutex);
1583
5023d966 1584 mvmvif->ap_ibss_active = false;
1c87bbad 1585 mvm->ap_last_beacon_gp2 = 0;
8ca151b5 1586
8e484f0b 1587 iwl_mvm_bt_coex_vif_change(mvm);
dac94da8 1588
29a90a49
EP
1589 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
1590
5023d966 1591 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
8ca151b5 1592 if (vif->p2p && mvm->p2p_device_vif)
bca49d9a 1593 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false);
8ca151b5
JB
1594
1595 iwl_mvm_update_quotas(mvm, NULL);
1596 iwl_mvm_send_rm_bcast_sta(mvm, &mvmvif->bcast_sta);
1597 iwl_mvm_binding_remove_vif(mvm, vif);
a11e144e 1598
999609f1 1599 iwl_mvm_power_update_mac(mvm);
a11e144e 1600
8ca151b5
JB
1601 iwl_mvm_mac_ctxt_remove(mvm, vif);
1602
1603 mutex_unlock(&mvm->mutex);
1604}
1605
5023d966
JB
1606static void
1607iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
1608 struct ieee80211_vif *vif,
1609 struct ieee80211_bss_conf *bss_conf,
1610 u32 changes)
8ca151b5 1611{
be2056fc 1612 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8a5e3660 1613
be2056fc
IP
1614 /* Changes will be applied when the AP/IBSS is started */
1615 if (!mvmvif->ap_ibss_active)
1616 return;
1617
863230da
JB
1618 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
1619 BSS_CHANGED_BANDWIDTH) &&
bca49d9a 1620 iwl_mvm_mac_ctxt_changed(mvm, vif, false))
863230da 1621 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
8a5e3660 1622
8ca151b5 1623 /* Need to send a new beacon template to the FW */
863230da
JB
1624 if (changes & BSS_CHANGED_BEACON &&
1625 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
1626 IWL_WARN(mvm, "Failed updating beacon data\n");
8ca151b5
JB
1627}
1628
1629static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
1630 struct ieee80211_vif *vif,
1631 struct ieee80211_bss_conf *bss_conf,
1632 u32 changes)
1633{
1634 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1635
1636 mutex_lock(&mvm->mutex);
1637
723f02ed
DS
1638 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
1639 iwl_mvm_sched_scan_stop(mvm, true);
1640
8ca151b5
JB
1641 switch (vif->type) {
1642 case NL80211_IFTYPE_STATION:
1643 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
1644 break;
1645 case NL80211_IFTYPE_AP:
5023d966
JB
1646 case NL80211_IFTYPE_ADHOC:
1647 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
8ca151b5
JB
1648 break;
1649 default:
1650 /* shouldn't happen */
1651 WARN_ON_ONCE(1);
1652 }
1653
1654 mutex_unlock(&mvm->mutex);
1655}
1656
1657static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
1658 struct ieee80211_vif *vif,
c56ef672 1659 struct ieee80211_scan_request *hw_req)
8ca151b5
JB
1660{
1661 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
c56ef672 1662 struct cfg80211_scan_request *req = &hw_req->req;
8ca151b5
JB
1663 int ret;
1664
762533ba
DS
1665 if (req->n_channels == 0 ||
1666 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
8ca151b5
JB
1667 return -EINVAL;
1668
1669 mutex_lock(&mvm->mutex);
1670
a6623e84
JB
1671 switch (mvm->scan_status) {
1672 case IWL_MVM_SCAN_SCHED:
636a2cdc 1673 ret = iwl_mvm_sched_scan_stop(mvm, true);
a6623e84
JB
1674 if (ret) {
1675 ret = -EBUSY;
1676 goto out;
1677 }
a6623e84
JB
1678 break;
1679 case IWL_MVM_SCAN_NONE:
1680 break;
1681 default:
8ca151b5 1682 ret = -EBUSY;
519e2026
AN
1683 goto out;
1684 }
8ca151b5 1685
519e2026
AN
1686 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
1687
1688 ret = iwl_mvm_scan_request(mvm, vif, req);
1689 if (ret)
1690 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1691out:
8ca151b5 1692 mutex_unlock(&mvm->mutex);
33ea27f6
AN
1693 /* make sure to flush the Rx handler before the next scan arrives */
1694 iwl_mvm_wait_for_async_handlers(mvm);
8ca151b5
JB
1695 return ret;
1696}
1697
1698static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
1699 struct ieee80211_vif *vif)
1700{
1701 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1702
1703 mutex_lock(&mvm->mutex);
1704
1705 iwl_mvm_cancel_scan(mvm);
1706
1707 mutex_unlock(&mvm->mutex);
1708}
1709
1710static void
1711iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
3e56eadf 1712 struct ieee80211_sta *sta, u16 tids,
8ca151b5
JB
1713 int num_frames,
1714 enum ieee80211_frame_release_type reason,
1715 bool more_data)
1716{
1717 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
8ca151b5 1718
3e56eadf 1719 /* Called when we need to transmit (a) frame(s) from mac80211 */
8ca151b5 1720
3e56eadf
JB
1721 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1722 tids, more_data, false);
1723}
1724
1725static void
1726iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
1727 struct ieee80211_sta *sta, u16 tids,
1728 int num_frames,
1729 enum ieee80211_frame_release_type reason,
1730 bool more_data)
1731{
1732 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1733
1734 /* Called when we need to transmit (a) frame(s) from agg queue */
1735
1736 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
1737 tids, more_data, true);
8ca151b5
JB
1738}
1739
1740static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
1741 struct ieee80211_vif *vif,
1742 enum sta_notify_cmd cmd,
1743 struct ieee80211_sta *sta)
1744{
1745 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5b577a90 1746 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3e56eadf 1747 int tid;
8ca151b5
JB
1748
1749 switch (cmd) {
1750 case STA_NOTIFY_SLEEP:
e3d4bc8c 1751 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
8ca151b5 1752 ieee80211_sta_block_awake(hw, sta, true);
3e56eadf
JB
1753 spin_lock_bh(&mvmsta->lock);
1754 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1755 struct iwl_mvm_tid_data *tid_data;
1756
1757 tid_data = &mvmsta->tid_data[tid];
1758 if (tid_data->state != IWL_AGG_ON &&
1759 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
1760 continue;
1761 if (iwl_mvm_tid_queued(tid_data) == 0)
1762 continue;
1763 ieee80211_sta_set_buffered(sta, tid, true);
1764 }
1765 spin_unlock_bh(&mvmsta->lock);
8ca151b5
JB
1766 /*
1767 * The fw updates the STA to be asleep. Tx packets on the Tx
1768 * queues to this station will not be transmitted. The fw will
1769 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1770 */
1771 break;
1772 case STA_NOTIFY_AWAKE:
881acd89 1773 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
8ca151b5 1774 break;
9cc40712 1775 iwl_mvm_sta_modify_ps_wake(mvm, sta);
8ca151b5
JB
1776 break;
1777 default:
1778 break;
1779 }
1780}
1781
1ddbbb0c
JB
1782static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
1783 struct ieee80211_vif *vif,
1784 struct ieee80211_sta *sta)
1785{
1786 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1787 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
1788
1789 /*
1790 * This is called before mac80211 does RCU synchronisation,
1791 * so here we already invalidate our internal RCU-protected
1792 * station pointer. The rest of the code will thus no longer
1793 * be able to find the station this way, and we don't rely
1794 * on further RCU synchronisation after the sta_state()
1795 * callback deleted the station.
1796 */
1797 mutex_lock(&mvm->mutex);
1798 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
1799 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1800 ERR_PTR(-ENOENT));
1801 mutex_unlock(&mvm->mutex);
1802}
1803
8ca151b5
JB
1804static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
1805 struct ieee80211_vif *vif,
1806 struct ieee80211_sta *sta,
1807 enum ieee80211_sta_state old_state,
1808 enum ieee80211_sta_state new_state)
1809{
1810 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1811 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1812 int ret;
1813
1814 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
1815 sta->addr, old_state, new_state);
1816
1817 /* this would be a mac80211 bug ... but don't crash */
1818 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
1819 return -EINVAL;
1820
1821 /* if a STA is being removed, reuse its ID */
1822 flush_work(&mvm->sta_drained_wk);
1823
1824 mutex_lock(&mvm->mutex);
1825 if (old_state == IEEE80211_STA_NOTEXIST &&
1826 new_state == IEEE80211_STA_NONE) {
48bc1307
JB
1827 /*
1828 * Firmware bug - it'll crash if the beacon interval is less
1829 * than 16. We can't avoid connecting at all, so refuse the
1830 * station state change, this will cause mac80211 to abandon
1831 * attempts to connect to this AP, and eventually wpa_s will
1832 * blacklist the AP...
1833 */
1834 if (vif->type == NL80211_IFTYPE_STATION &&
1835 vif->bss_conf.beacon_int < 16) {
1836 IWL_ERR(mvm,
1837 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1838 sta->addr, vif->bss_conf.beacon_int);
1839 ret = -EINVAL;
1840 goto out_unlock;
1841 }
8ca151b5
JB
1842 ret = iwl_mvm_add_sta(mvm, vif, sta);
1843 } else if (old_state == IEEE80211_STA_NONE &&
1844 new_state == IEEE80211_STA_AUTH) {
e820c2da
HD
1845 /*
1846 * EBS may be disabled due to previous failures reported by FW.
1847 * Reset EBS status here assuming environment has been changed.
1848 */
1849 mvm->last_ebs_successful = true;
8ca151b5
JB
1850 ret = 0;
1851 } else if (old_state == IEEE80211_STA_AUTH &&
1852 new_state == IEEE80211_STA_ASSOC) {
7a453973
JB
1853 ret = iwl_mvm_update_sta(mvm, vif, sta);
1854 if (ret == 0)
1855 iwl_mvm_rs_rate_init(mvm, sta,
b87c2179
ES
1856 mvmvif->phy_ctxt->channel->band,
1857 true);
8ca151b5
JB
1858 } else if (old_state == IEEE80211_STA_ASSOC &&
1859 new_state == IEEE80211_STA_AUTHORIZED) {
7df15b1e 1860 /* enable beacon filtering */
fa7b2e7f 1861 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
8ca151b5
JB
1862 ret = 0;
1863 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
1864 new_state == IEEE80211_STA_ASSOC) {
7df15b1e 1865 /* disable beacon filtering */
a1022927 1866 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
8ca151b5
JB
1867 ret = 0;
1868 } else if (old_state == IEEE80211_STA_ASSOC &&
1869 new_state == IEEE80211_STA_AUTH) {
1870 ret = 0;
1871 } else if (old_state == IEEE80211_STA_AUTH &&
1872 new_state == IEEE80211_STA_NONE) {
1873 ret = 0;
1874 } else if (old_state == IEEE80211_STA_NONE &&
1875 new_state == IEEE80211_STA_NOTEXIST) {
1876 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1877 } else {
1878 ret = -EIO;
1879 }
48bc1307 1880 out_unlock:
8ca151b5
JB
1881 mutex_unlock(&mvm->mutex);
1882
1883 return ret;
1884}
1885
1886static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1887{
1888 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1889
1890 mvm->rts_threshold = value;
1891
1892 return 0;
1893}
1894
1f3b0ff8
LE
1895static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
1896 struct ieee80211_vif *vif,
1897 struct ieee80211_sta *sta, u32 changed)
1898{
1899 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1900
1901 if (vif->type == NL80211_IFTYPE_STATION &&
1902 changed & IEEE80211_RC_NSS_CHANGED)
1903 iwl_mvm_sf_update(mvm, vif, false);
1904}
1905
8ca151b5
JB
1906static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
1907 struct ieee80211_vif *vif, u16 ac,
1908 const struct ieee80211_tx_queue_params *params)
1909{
1910 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1911 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1912
1913 mvmvif->queue_params[ac] = *params;
1914
1915 /*
1916 * No need to update right away, we'll get BSS_CHANGED_QOS
1917 * The exception is P2P_DEVICE interface which needs immediate update.
1918 */
1919 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1920 int ret;
1921
1922 mutex_lock(&mvm->mutex);
bca49d9a 1923 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false);
8ca151b5
JB
1924 mutex_unlock(&mvm->mutex);
1925 return ret;
1926 }
1927 return 0;
1928}
1929
1930static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
1931 struct ieee80211_vif *vif)
1932{
1933 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1934 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
1935 200 + vif->bss_conf.beacon_int);
1936 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
1937 100 + vif->bss_conf.beacon_int);
1938
1939 if (WARN_ON_ONCE(vif->bss_conf.assoc))
1940 return;
1941
1942 mutex_lock(&mvm->mutex);
1943 /* Try really hard to protect the session and hear a beacon */
016d27e1 1944 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500);
8ca151b5
JB
1945 mutex_unlock(&mvm->mutex);
1946}
1947
35a000b7
DS
1948static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
1949 struct ieee80211_vif *vif,
1950 struct cfg80211_sched_scan_request *req,
633e2713 1951 struct ieee80211_scan_ies *ies)
35a000b7
DS
1952{
1953 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1954 int ret;
1955
1956 mutex_lock(&mvm->mutex);
1957
b538b8ce 1958 if (!iwl_mvm_is_idle(mvm)) {
bd5e4744
DS
1959 ret = -EBUSY;
1960 goto out;
1961 }
1962
91b80256
AN
1963 switch (mvm->scan_status) {
1964 case IWL_MVM_SCAN_OS:
1965 IWL_DEBUG_SCAN(mvm, "Stopping previous scan for sched_scan\n");
1966 ret = iwl_mvm_cancel_scan(mvm);
1967 if (ret) {
1968 ret = -EBUSY;
1969 goto out;
1970 }
1971
1972 /*
1973 * iwl_mvm_rx_scan_complete() will be called soon but will
1974 * not reset the scan status as it won't be IWL_MVM_SCAN_OS
1975 * any more since we queue the next scan immediately (below).
1976 * We make sure it is called before the next scan starts by
1977 * flushing the async-handlers work.
1978 */
1979 break;
1980 case IWL_MVM_SCAN_NONE:
1981 break;
1982 default:
35a000b7
DS
1983 ret = -EBUSY;
1984 goto out;
1985 }
1986
1987 mvm->scan_status = IWL_MVM_SCAN_SCHED;
1988
1989 ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies);
1990 if (ret)
1991 goto err;
1992
1993 ret = iwl_mvm_config_sched_scan_profiles(mvm, req);
1994 if (ret)
1995 goto err;
1996
1997 ret = iwl_mvm_sched_scan_start(mvm, req);
1998 if (!ret)
1999 goto out;
2000err:
2001 mvm->scan_status = IWL_MVM_SCAN_NONE;
2002out:
2003 mutex_unlock(&mvm->mutex);
91b80256
AN
2004 /* make sure to flush the Rx handler before the next scan arrives */
2005 iwl_mvm_wait_for_async_handlers(mvm);
35a000b7
DS
2006 return ret;
2007}
2008
37e3308c
JB
2009static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2010 struct ieee80211_vif *vif)
35a000b7
DS
2011{
2012 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
33ea27f6 2013 int ret;
35a000b7
DS
2014
2015 mutex_lock(&mvm->mutex);
636a2cdc 2016 ret = iwl_mvm_sched_scan_stop(mvm, false);
35a000b7 2017 mutex_unlock(&mvm->mutex);
33ea27f6 2018 iwl_mvm_wait_for_async_handlers(mvm);
37e3308c 2019
33ea27f6 2020 return ret;
35a000b7
DS
2021}
2022
8ca151b5
JB
2023static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2024 enum set_key_cmd cmd,
2025 struct ieee80211_vif *vif,
2026 struct ieee80211_sta *sta,
2027 struct ieee80211_key_conf *key)
2028{
2029 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2030 int ret;
2031
2032 if (iwlwifi_mod_params.sw_crypto) {
2033 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2034 return -EOPNOTSUPP;
2035 }
2036
2037 switch (key->cipher) {
2038 case WLAN_CIPHER_SUITE_TKIP:
2039 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2040 /* fall-through */
2041 case WLAN_CIPHER_SUITE_CCMP:
2042 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2043 break;
2044 case WLAN_CIPHER_SUITE_AES_CMAC:
2045 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
2046 break;
2047 case WLAN_CIPHER_SUITE_WEP40:
2048 case WLAN_CIPHER_SUITE_WEP104:
2049 /*
2050 * Support for TX only, at least for now, so accept
2051 * the key and do nothing else. Then mac80211 will
2052 * pass it for TX but we don't have to use it for RX.
2053 */
2054 return 0;
2055 default:
e36e5433
MS
2056 /* currently FW supports only one optional cipher scheme */
2057 if (hw->n_cipher_schemes &&
2058 hw->cipher_schemes->cipher == key->cipher)
2059 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2060 else
2061 return -EOPNOTSUPP;
8ca151b5
JB
2062 }
2063
2064 mutex_lock(&mvm->mutex);
2065
2066 switch (cmd) {
2067 case SET_KEY:
5023d966
JB
2068 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2069 vif->type == NL80211_IFTYPE_AP) && !sta) {
2070 /*
2071 * GTK on AP interface is a TX-only key, return 0;
2072 * on IBSS they're per-station and because we're lazy
2073 * we don't support them for RX, so do the same.
2074 */
6caffd4f
JB
2075 ret = 0;
2076 key->hw_key_idx = STA_KEY_IDX_INVALID;
2077 break;
2078 }
2079
8ca151b5
JB
2080 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2081 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
2082 if (ret) {
2083 IWL_WARN(mvm, "set key failed\n");
2084 /*
2085 * can't add key for RX, but we don't need it
2086 * in the device for TX so still return 0
2087 */
6caffd4f 2088 key->hw_key_idx = STA_KEY_IDX_INVALID;
8ca151b5
JB
2089 ret = 0;
2090 }
2091
2092 break;
2093 case DISABLE_KEY:
6caffd4f
JB
2094 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2095 ret = 0;
2096 break;
2097 }
2098
8ca151b5
JB
2099 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2100 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2101 break;
2102 default:
2103 ret = -EINVAL;
2104 }
2105
2106 mutex_unlock(&mvm->mutex);
2107 return ret;
2108}
2109
2110static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2111 struct ieee80211_vif *vif,
2112 struct ieee80211_key_conf *keyconf,
2113 struct ieee80211_sta *sta,
2114 u32 iv32, u16 *phase1key)
2115{
2116 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2117
5023d966
JB
2118 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2119 return;
2120
8ca151b5
JB
2121 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2122}
2123
2124
2125static int iwl_mvm_roc(struct ieee80211_hw *hw,
2126 struct ieee80211_vif *vif,
2127 struct ieee80211_channel *channel,
d339d5ca
IP
2128 int duration,
2129 enum ieee80211_roc_type type)
8ca151b5
JB
2130{
2131 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3 2132 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8ca151b5 2133 struct cfg80211_chan_def chandef;
31d385ae
IP
2134 struct iwl_mvm_phy_ctxt *phy_ctxt;
2135 int ret, i;
2136
2137 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2138 duration, type);
8ca151b5
JB
2139
2140 if (vif->type != NL80211_IFTYPE_P2P_DEVICE) {
2141 IWL_ERR(mvm, "vif isn't a P2P_DEVICE: %d\n", vif->type);
2142 return -EINVAL;
2143 }
2144
8ca151b5
JB
2145 mutex_lock(&mvm->mutex);
2146
31d385ae
IP
2147 for (i = 0; i < NUM_PHY_CTX; i++) {
2148 phy_ctxt = &mvm->phy_ctxts[i];
2149 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2150 continue;
2151
2152 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2153 /*
2154 * Unbind the P2P_DEVICE from the current PHY context,
2155 * and if the PHY context is not used remove it.
2156 */
2157 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2158 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2159 goto out_unlock;
2160
2161 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2162
2163 /* Bind the P2P_DEVICE to the current PHY Context */
2164 mvmvif->phy_ctxt = phy_ctxt;
2165
2166 ret = iwl_mvm_binding_add_vif(mvm, vif);
2167 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2168 goto out_unlock;
2169
2170 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2171 goto schedule_time_event;
2172 }
2173 }
2174
2175 /* Need to update the PHY context only if the ROC channel changed */
2176 if (channel == mvmvif->phy_ctxt->channel)
2177 goto schedule_time_event;
2178
8ca151b5 2179 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
8ca151b5 2180
31d385ae
IP
2181 /*
2182 * Change the PHY context configuration as it is currently referenced
2183 * only by the P2P Device MAC
2184 */
2185 if (mvmvif->phy_ctxt->ref == 1) {
2186 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2187 &chandef, 1, 1);
2188 if (ret)
2189 goto out_unlock;
2190 } else {
2191 /*
2192 * The PHY context is shared with other MACs. Need to remove the
2193 * P2P Device from the binding, allocate an new PHY context and
2194 * create a new binding
2195 */
2196 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2197 if (!phy_ctxt) {
2198 ret = -ENOSPC;
2199 goto out_unlock;
2200 }
2201
2202 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2203 1, 1);
2204 if (ret) {
2205 IWL_ERR(mvm, "Failed to change PHY context\n");
2206 goto out_unlock;
2207 }
2208
2209 /* Unbind the P2P_DEVICE from the current PHY context */
2210 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2211 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2212 goto out_unlock;
2213
2214 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2215
2216 /* Bind the P2P_DEVICE to the new allocated PHY context */
2217 mvmvif->phy_ctxt = phy_ctxt;
2218
2219 ret = iwl_mvm_binding_add_vif(mvm, vif);
2220 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2221 goto out_unlock;
2222
2223 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2224 }
2225
2226schedule_time_event:
8ca151b5 2227 /* Schedule the time events */
e635c797 2228 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
8ca151b5 2229
31d385ae 2230out_unlock:
8ca151b5
JB
2231 mutex_unlock(&mvm->mutex);
2232 IWL_DEBUG_MAC80211(mvm, "leave\n");
8ca151b5
JB
2233 return ret;
2234}
2235
2236static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2237{
2238 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2239
2240 IWL_DEBUG_MAC80211(mvm, "enter\n");
2241
2242 mutex_lock(&mvm->mutex);
2243 iwl_mvm_stop_p2p_roc(mvm);
2244 mutex_unlock(&mvm->mutex);
2245
2246 IWL_DEBUG_MAC80211(mvm, "leave\n");
2247 return 0;
2248}
2249
2250static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2251 struct ieee80211_chanctx_conf *ctx)
2252{
2253 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
2254 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2255 struct iwl_mvm_phy_ctxt *phy_ctxt;
8ca151b5
JB
2256 int ret;
2257
53a9d61e 2258 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
fe0f2de3 2259
8ca151b5 2260 mutex_lock(&mvm->mutex);
fe0f2de3
IP
2261 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2262 if (!phy_ctxt) {
2263 ret = -ENOSPC;
2264 goto out;
2265 }
8ca151b5 2266
dcbc3e1a 2267 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
53a9d61e
IP
2268 ctx->rx_chains_static,
2269 ctx->rx_chains_dynamic);
fe0f2de3
IP
2270 if (ret) {
2271 IWL_ERR(mvm, "Failed to add PHY context\n");
2272 goto out;
2273 }
2274
53a9d61e 2275 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
fe0f2de3
IP
2276 *phy_ctxt_id = phy_ctxt->id;
2277out:
8ca151b5
JB
2278 mutex_unlock(&mvm->mutex);
2279 return ret;
2280}
2281
2282static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2283 struct ieee80211_chanctx_conf *ctx)
2284{
2285 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
2286 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2287 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
8ca151b5
JB
2288
2289 mutex_lock(&mvm->mutex);
fe0f2de3 2290 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
8ca151b5
JB
2291 mutex_unlock(&mvm->mutex);
2292}
2293
2294static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2295 struct ieee80211_chanctx_conf *ctx,
2296 u32 changed)
2297{
2298 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
2299 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2300 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
8ca151b5 2301
31d385ae
IP
2302 if (WARN_ONCE((phy_ctxt->ref > 1) &&
2303 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
2304 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
2dceedae
AN
2305 IEEE80211_CHANCTX_CHANGE_RADAR |
2306 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
31d385ae
IP
2307 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2308 phy_ctxt->ref, changed))
2309 return;
2310
8ca151b5 2311 mutex_lock(&mvm->mutex);
4d66449a 2312 iwl_mvm_bt_coex_vif_change(mvm);
dcbc3e1a 2313 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
8ca151b5
JB
2314 ctx->rx_chains_static,
2315 ctx->rx_chains_dynamic);
2316 mutex_unlock(&mvm->mutex);
2317}
2318
2319static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
2320 struct ieee80211_vif *vif,
2321 struct ieee80211_chanctx_conf *ctx)
2322{
2323 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
2324 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2325 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
8ca151b5
JB
2326 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2327 int ret;
2328
2329 mutex_lock(&mvm->mutex);
2330
fe0f2de3 2331 mvmvif->phy_ctxt = phy_ctxt;
8ca151b5
JB
2332
2333 switch (vif->type) {
2334 case NL80211_IFTYPE_AP:
bd3398e2
AO
2335 /* Unless it's a CSA flow we have nothing to do here */
2336 if (vif->csa_active) {
2337 mvmvif->ap_ibss_active = true;
2338 break;
2339 }
5023d966 2340 case NL80211_IFTYPE_ADHOC:
8ca151b5
JB
2341 /*
2342 * The AP binding flow is handled as part of the start_ap flow
5023d966 2343 * (in bss_info_changed), similarly for IBSS.
8ca151b5
JB
2344 */
2345 ret = 0;
2346 goto out_unlock;
2347 case NL80211_IFTYPE_STATION:
8ca151b5
JB
2348 case NL80211_IFTYPE_MONITOR:
2349 break;
2350 default:
2351 ret = -EINVAL;
2352 goto out_unlock;
2353 }
2354
2355 ret = iwl_mvm_binding_add_vif(mvm, vif);
2356 if (ret)
2357 goto out_unlock;
2358
2359 /*
92d85562
AB
2360 * Power state must be updated before quotas,
2361 * otherwise fw will complain.
2362 */
999609f1 2363 iwl_mvm_power_update_mac(mvm);
92d85562
AB
2364
2365 /* Setting the quota at this stage is only required for monitor
8ca151b5
JB
2366 * interfaces. For the other types, the bss_info changed flow
2367 * will handle quota settings.
2368 */
2369 if (vif->type == NL80211_IFTYPE_MONITOR) {
1e1391ca 2370 mvmvif->monitor_active = true;
8ca151b5
JB
2371 ret = iwl_mvm_update_quotas(mvm, vif);
2372 if (ret)
2373 goto out_remove_binding;
2374 }
2375
bd3398e2
AO
2376 /* Handle binding during CSA */
2377 if (vif->type == NL80211_IFTYPE_AP) {
2378 iwl_mvm_update_quotas(mvm, vif);
bca49d9a 2379 iwl_mvm_mac_ctxt_changed(mvm, vif, false);
bd3398e2
AO
2380 }
2381
8ca151b5
JB
2382 goto out_unlock;
2383
2384 out_remove_binding:
2385 iwl_mvm_binding_remove_vif(mvm, vif);
999609f1 2386 iwl_mvm_power_update_mac(mvm);
8ca151b5
JB
2387 out_unlock:
2388 mutex_unlock(&mvm->mutex);
2389 if (ret)
2390 mvmvif->phy_ctxt = NULL;
2391 return ret;
2392}
2393
2394static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
2395 struct ieee80211_vif *vif,
2396 struct ieee80211_chanctx_conf *ctx)
2397{
2398 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2399 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2400
2401 mutex_lock(&mvm->mutex);
2402
2403 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
2404
8ca151b5 2405 switch (vif->type) {
5023d966
JB
2406 case NL80211_IFTYPE_ADHOC:
2407 goto out_unlock;
8ca151b5 2408 case NL80211_IFTYPE_MONITOR:
1e1391ca
IP
2409 mvmvif->monitor_active = false;
2410 iwl_mvm_update_quotas(mvm, NULL);
8ca151b5 2411 break;
bd3398e2
AO
2412 case NL80211_IFTYPE_AP:
2413 /* This part is triggered only during CSA */
2414 if (!vif->csa_active || !mvmvif->ap_ibss_active)
2415 goto out_unlock;
2416
2417 mvmvif->ap_ibss_active = false;
2418 iwl_mvm_update_quotas(mvm, NULL);
2419 /*TODO: bt_coex notification here? */
8ca151b5
JB
2420 default:
2421 break;
2422 }
2423
1e1391ca 2424 iwl_mvm_binding_remove_vif(mvm, vif);
1c2abf72 2425
a11e144e
IP
2426out_unlock:
2427 mvmvif->phy_ctxt = NULL;
999609f1 2428 iwl_mvm_power_update_mac(mvm);
8ca151b5
JB
2429 mutex_unlock(&mvm->mutex);
2430}
2431
2432static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
2433 struct ieee80211_sta *sta,
2434 bool set)
2435{
2436 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2437 struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv;
2438
2439 if (!mvm_sta || !mvm_sta->vif) {
2440 IWL_ERR(mvm, "Station is not associated to a vif\n");
2441 return -EINVAL;
2442 }
2443
2444 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
2445}
2446
507cadf2
DS
2447#ifdef CONFIG_NL80211_TESTMODE
2448static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
2449 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
2450 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
f6c6ad42 2451 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
507cadf2
DS
2452};
2453
2454static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
2455 struct ieee80211_vif *vif,
2456 void *data, int len)
2457{
2458 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
2459 int err;
2460 u32 noa_duration;
2461
2462 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
2463 if (err)
2464 return err;
2465
2466 if (!tb[IWL_MVM_TM_ATTR_CMD])
2467 return -EINVAL;
2468
2469 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
2470 case IWL_MVM_TM_CMD_SET_NOA:
2471 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
2472 !vif->bss_conf.enable_beacon ||
2473 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
2474 return -EINVAL;
2475
2476 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
2477 if (noa_duration >= vif->bss_conf.beacon_int)
2478 return -EINVAL;
2479
2480 mvm->noa_duration = noa_duration;
2481 mvm->noa_vif = vif;
2482
2483 return iwl_mvm_update_quotas(mvm, NULL);
f6c6ad42
JB
2484 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
2485 /* must be associated client vif - ignore authorized */
2486 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
2487 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
2488 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
2489 return -EINVAL;
2490
2491 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
a1022927
EG
2492 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2493 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
507cadf2
DS
2494 }
2495
2496 return -EOPNOTSUPP;
2497}
2498
2499static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
2500 struct ieee80211_vif *vif,
2501 void *data, int len)
2502{
2503 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2504 int err;
2505
2506 mutex_lock(&mvm->mutex);
2507 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
2508 mutex_unlock(&mvm->mutex);
2509
2510 return err;
2511}
2512#endif
2513
bd3398e2
AO
2514static void iwl_mvm_channel_switch_beacon(struct ieee80211_hw *hw,
2515 struct ieee80211_vif *vif,
2516 struct cfg80211_chan_def *chandef)
2517{
2518 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2519
2520 mutex_lock(&mvm->mutex);
2521 if (WARN(mvm->csa_vif && mvm->csa_vif->csa_active,
2522 "Another CSA is already in progress"))
2523 goto out_unlock;
2524
2525 IWL_DEBUG_MAC80211(mvm, "CSA started to freq %d\n",
2526 chandef->center_freq1);
2527 mvm->csa_vif = vif;
2528
2529out_unlock:
2530 mutex_unlock(&mvm->mutex);
2531}
2532
c5b0e7c0
EG
2533static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
2534 struct ieee80211_vif *vif, u32 queues, bool drop)
2535{
2536 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2537 struct iwl_mvm_vif *mvmvif;
2538 struct iwl_mvm_sta *mvmsta;
2539
2540 if (!vif || vif->type != NL80211_IFTYPE_STATION)
2541 return;
2542
2543 mutex_lock(&mvm->mutex);
2544 mvmvif = iwl_mvm_vif_from_mac80211(vif);
2545 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, mvmvif->ap_sta_id);
2546
2547 if (WARN_ON_ONCE(!mvmsta))
2548 goto done;
2549
2550 if (drop) {
2551 if (iwl_mvm_flush_tx_path(mvm, mvmsta->tfd_queue_msk, true))
2552 IWL_ERR(mvm, "flush request fail\n");
2553 } else {
2554 iwl_trans_wait_tx_queue_empty(mvm->trans,
2555 mvmsta->tfd_queue_msk);
2556 }
2557done:
2558 mutex_unlock(&mvm->mutex);
2559}
2560
e5209263 2561const struct ieee80211_ops iwl_mvm_hw_ops = {
8ca151b5
JB
2562 .tx = iwl_mvm_mac_tx,
2563 .ampdu_action = iwl_mvm_mac_ampdu_action,
2564 .start = iwl_mvm_mac_start,
2565 .restart_complete = iwl_mvm_mac_restart_complete,
2566 .stop = iwl_mvm_mac_stop,
2567 .add_interface = iwl_mvm_mac_add_interface,
2568 .remove_interface = iwl_mvm_mac_remove_interface,
2569 .config = iwl_mvm_mac_config,
e59647ea 2570 .prepare_multicast = iwl_mvm_prepare_multicast,
8ca151b5
JB
2571 .configure_filter = iwl_mvm_configure_filter,
2572 .bss_info_changed = iwl_mvm_bss_info_changed,
2573 .hw_scan = iwl_mvm_mac_hw_scan,
2574 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1ddbbb0c 2575 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
8ca151b5
JB
2576 .sta_state = iwl_mvm_mac_sta_state,
2577 .sta_notify = iwl_mvm_mac_sta_notify,
2578 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
3e56eadf 2579 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
8ca151b5 2580 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1f3b0ff8 2581 .sta_rc_update = iwl_mvm_sta_rc_update,
8ca151b5
JB
2582 .conf_tx = iwl_mvm_mac_conf_tx,
2583 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
c5b0e7c0 2584 .flush = iwl_mvm_mac_flush,
35a000b7
DS
2585 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
2586 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
8ca151b5
JB
2587 .set_key = iwl_mvm_mac_set_key,
2588 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
2589 .remain_on_channel = iwl_mvm_roc,
2590 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
8ca151b5
JB
2591 .add_chanctx = iwl_mvm_add_chanctx,
2592 .remove_chanctx = iwl_mvm_remove_chanctx,
2593 .change_chanctx = iwl_mvm_change_chanctx,
2594 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
2595 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
2596
5023d966
JB
2597 .start_ap = iwl_mvm_start_ap_ibss,
2598 .stop_ap = iwl_mvm_stop_ap_ibss,
2599 .join_ibss = iwl_mvm_start_ap_ibss,
2600 .leave_ibss = iwl_mvm_stop_ap_ibss,
8ca151b5
JB
2601
2602 .set_tim = iwl_mvm_set_tim,
2603
bd3398e2
AO
2604 .channel_switch_beacon = iwl_mvm_channel_switch_beacon,
2605
507cadf2
DS
2606 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
2607
8ca151b5
JB
2608#ifdef CONFIG_PM_SLEEP
2609 /* look at d3.c */
2610 .suspend = iwl_mvm_suspend,
2611 .resume = iwl_mvm_resume,
2612 .set_wakeup = iwl_mvm_set_wakeup,
2613 .set_rekey_data = iwl_mvm_set_rekey_data,
2614#if IS_ENABLED(CONFIG_IPV6)
2615 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
2616#endif
2617 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
2618#endif
2619};