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