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