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