iwlwifi: mvm: don't write to DBGC_OUT_CTRL when stopping the recording
[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.
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>
aadede6e 72#include <linux/devcoredump.h>
8ca151b5 73#include <net/mac80211.h>
7b1dd048 74#include <net/ieee80211_radiotap.h>
f0c2646a 75#include <net/tcp.h>
8ca151b5
JB
76
77#include "iwl-op-mode.h"
78#include "iwl-io.h"
79#include "mvm.h"
80#include "sta.h"
81#include "time-event.h"
82#include "iwl-eeprom-parse.h"
83#include "fw-api-scan.h"
84#include "iwl-phy-db.h"
507cadf2 85#include "testmode.h"
655e6d6d
EG
86#include "iwl-fw-error-dump.h"
87#include "iwl-prph.h"
363039be 88#include "iwl-csr.h"
8ca151b5
JB
89
90static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
91 {
92 .max = 1,
8eb38710 93 .types = BIT(NL80211_IFTYPE_STATION),
8ca151b5 94 },
3c15a0fb
JB
95 {
96 .max = 1,
8eb38710
IP
97 .types = BIT(NL80211_IFTYPE_AP) |
98 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3c15a0fb
JB
99 BIT(NL80211_IFTYPE_P2P_GO),
100 },
101 {
102 .max = 1,
103 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
104 },
8ca151b5
JB
105};
106
107static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
108 {
2624a5ca 109 .num_different_channels = 2,
8ca151b5
JB
110 .max_interfaces = 3,
111 .limits = iwl_mvm_limits,
112 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
113 },
114};
115
f0c2646a
JB
116#ifdef CONFIG_PM_SLEEP
117static const struct nl80211_wowlan_tcp_data_token_feature
118iwl_mvm_wowlan_tcp_token_feature = {
119 .min_len = 0,
120 .max_len = 255,
121 .bufsize = IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS,
122};
123
124static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support = {
125 .tok = &iwl_mvm_wowlan_tcp_token_feature,
126 .data_payload_max = IWL_WOWLAN_TCP_MAX_PACKET_LEN -
127 sizeof(struct ethhdr) -
128 sizeof(struct iphdr) -
129 sizeof(struct tcphdr),
130 .data_interval_max = 65535, /* __le16 in API */
131 .wake_payload_max = IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN -
132 sizeof(struct ethhdr) -
133 sizeof(struct iphdr) -
134 sizeof(struct tcphdr),
135 .seq = true,
136};
137#endif
138
77736923 139#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
2ee8f021
EP
140/*
141 * Use the reserved field to indicate magic values.
142 * these values will only be used internally by the driver,
143 * and won't make it to the fw (reserved will be 0).
144 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
145 * be the vif's ip address. in case there is not a single
146 * ip address (0, or more than 1), this attribute will
147 * be skipped.
148 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
149 * the LSB bytes of the vif's mac address
150 */
151enum {
152 BC_FILTER_MAGIC_NONE = 0,
153 BC_FILTER_MAGIC_IP,
154 BC_FILTER_MAGIC_MAC,
155};
156
77736923
EP
157static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
158 {
159 /* arp */
160 .discard = 0,
161 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
162 .attrs = {
163 {
164 /* frame type - arp, hw type - ethernet */
165 .offset_type =
166 BCAST_FILTER_OFFSET_PAYLOAD_START,
167 .offset = sizeof(rfc1042_header),
168 .val = cpu_to_be32(0x08060001),
169 .mask = cpu_to_be32(0xffffffff),
170 },
2ee8f021
EP
171 {
172 /* arp dest ip */
173 .offset_type =
174 BCAST_FILTER_OFFSET_PAYLOAD_START,
175 .offset = sizeof(rfc1042_header) + 2 +
176 sizeof(struct arphdr) +
177 ETH_ALEN + sizeof(__be32) +
178 ETH_ALEN,
179 .mask = cpu_to_be32(0xffffffff),
180 /* mark it as special field */
181 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
182 },
183 },
184 },
185 {
186 /* dhcp offer bcast */
187 .discard = 0,
188 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
189 .attrs = {
190 {
191 /* udp dest port - 68 (bootp client)*/
192 .offset_type = BCAST_FILTER_OFFSET_IP_END,
193 .offset = offsetof(struct udphdr, dest),
194 .val = cpu_to_be32(0x00440000),
195 .mask = cpu_to_be32(0xffff0000),
196 },
197 {
198 /* dhcp - lsb bytes of client hw address */
199 .offset_type = BCAST_FILTER_OFFSET_IP_END,
200 .offset = 38,
201 .mask = cpu_to_be32(0xffffffff),
202 /* mark it as special field */
203 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
204 },
77736923
EP
205 },
206 },
207 /* last filter must be empty */
208 {},
209};
210#endif
211
7498cf4c
EP
212void iwl_mvm_ref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
213{
7bb426ea 214 if (!iwl_mvm_is_d0i3_supported(mvm))
7498cf4c
EP
215 return;
216
217 IWL_DEBUG_RPM(mvm, "Take mvm reference - type %d\n", ref_type);
576eeee9
EP
218 spin_lock_bh(&mvm->refs_lock);
219 mvm->refs[ref_type]++;
220 spin_unlock_bh(&mvm->refs_lock);
7498cf4c
EP
221 iwl_trans_ref(mvm->trans);
222}
223
224void iwl_mvm_unref(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
225{
7bb426ea 226 if (!iwl_mvm_is_d0i3_supported(mvm))
7498cf4c
EP
227 return;
228
229 IWL_DEBUG_RPM(mvm, "Leave mvm reference - type %d\n", ref_type);
576eeee9
EP
230 spin_lock_bh(&mvm->refs_lock);
231 WARN_ON(!mvm->refs[ref_type]--);
232 spin_unlock_bh(&mvm->refs_lock);
7498cf4c
EP
233 iwl_trans_unref(mvm->trans);
234}
235
576eeee9
EP
236static void iwl_mvm_unref_all_except(struct iwl_mvm *mvm,
237 enum iwl_mvm_ref_type except_ref)
7498cf4c 238{
576eeee9 239 int i, j;
7498cf4c 240
7bb426ea 241 if (!iwl_mvm_is_d0i3_supported(mvm))
7498cf4c
EP
242 return;
243
576eeee9
EP
244 spin_lock_bh(&mvm->refs_lock);
245 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
246 if (except_ref == i || !mvm->refs[i])
7498cf4c
EP
247 continue;
248
576eeee9
EP
249 IWL_DEBUG_RPM(mvm, "Cleanup: remove mvm ref type %d (%d)\n",
250 i, mvm->refs[i]);
251 for (j = 0; j < mvm->refs[i]; j++)
252 iwl_trans_unref(mvm->trans);
253 mvm->refs[i] = 0;
7498cf4c 254 }
576eeee9 255 spin_unlock_bh(&mvm->refs_lock);
7498cf4c
EP
256}
257
f4cf8680
EP
258bool iwl_mvm_ref_taken(struct iwl_mvm *mvm)
259{
260 int i;
261 bool taken = false;
262
263 if (!iwl_mvm_is_d0i3_supported(mvm))
264 return true;
265
266 spin_lock_bh(&mvm->refs_lock);
267 for (i = 0; i < IWL_MVM_REF_COUNT; i++) {
268 if (mvm->refs[i]) {
269 taken = true;
270 break;
271 }
272 }
273 spin_unlock_bh(&mvm->refs_lock);
274
275 return taken;
276}
277
576eeee9 278int iwl_mvm_ref_sync(struct iwl_mvm *mvm, enum iwl_mvm_ref_type ref_type)
d40fc489
GG
279{
280 iwl_mvm_ref(mvm, ref_type);
281
282 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
283 !test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status),
284 HZ)) {
285 WARN_ON_ONCE(1);
286 iwl_mvm_unref(mvm, ref_type);
287 return -EIO;
288 }
289
290 return 0;
291}
292
fe0f2de3
IP
293static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
294{
295 int i;
296
297 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
298 for (i = 0; i < NUM_PHY_CTX; i++) {
299 mvm->phy_ctxts[i].id = i;
300 mvm->phy_ctxts[i].ref = 0;
301 }
302}
303
8ca151b5
JB
304int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
305{
306 struct ieee80211_hw *hw = mvm->hw;
831e85f3 307 int num_mac, ret, i;
8ca151b5
JB
308
309 /* Tell mac80211 our characteristics */
310 hw->flags = IEEE80211_HW_SIGNAL_DBM |
311 IEEE80211_HW_SPECTRUM_MGMT |
312 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
313 IEEE80211_HW_QUEUE_CONTROL |
314 IEEE80211_HW_WANT_MONITOR_VIF |
8ca151b5
JB
315 IEEE80211_HW_SUPPORTS_PS |
316 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
d2931bbd 317 IEEE80211_HW_AMPDU_AGGREGATION |
d64048ed 318 IEEE80211_HW_TIMING_BEACON_ONLY |
147fc9be 319 IEEE80211_HW_CONNECTION_MONITOR |
b71d9c8a
IY
320 IEEE80211_HW_CHANCTX_STA_CSA |
321 IEEE80211_HW_SUPPORTS_CLONED_SKBS;
8ca151b5 322
19e737c9 323 hw->queues = mvm->first_agg_queue;
398e8c6c 324 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
7b1dd048
EG
325 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
326 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
339b3086
ES
327 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
328 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
8ca151b5 329 hw->rate_control_algorithm = "iwl-mvm-rs";
848955cc
JB
330 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
331 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
8ca151b5
JB
332
333 /*
334 * Enable 11w if advertised by firmware and software crypto
335 * is not enabled (as the firmware will interpret some mgmt
336 * packets, so enabling it with software crypto isn't safe)
337 */
338 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_MFP &&
339 !iwlwifi_mod_params.sw_crypto)
340 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
341
1f940386
LC
342 hw->flags |= IEEE80211_SINGLE_HW_SCAN_ON_ALL_BANDS;
343 hw->wiphy->features |=
344 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
345 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
fb98be5e 346
8ca151b5
JB
347 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
348 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
fe0f2de3 349 hw->chanctx_data_size = sizeof(u16);
8ca151b5
JB
350
351 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3c15a0fb
JB
352 BIT(NL80211_IFTYPE_P2P_CLIENT) |
353 BIT(NL80211_IFTYPE_AP) |
354 BIT(NL80211_IFTYPE_P2P_GO) |
c13b1725
EG
355 BIT(NL80211_IFTYPE_P2P_DEVICE) |
356 BIT(NL80211_IFTYPE_ADHOC);
5023d966 357
a2f73b6c
LR
358 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
359 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
360 REGULATORY_DISABLE_BEACON_HINTS;
8ca151b5 361
3e56eadf
JB
362 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_GO_UAPSD)
363 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
364
94bbed72 365 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
bd3398e2 366
8ca151b5
JB
367 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
368 hw->wiphy->n_iface_combinations =
369 ARRAY_SIZE(iwl_mvm_iface_combinations);
370
c451e6d4 371 hw->wiphy->max_remain_on_channel_duration = 10000;
8ca151b5 372 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
f1a68542
EG
373 /* we can compensate an offset of up to 3 channels = 15 MHz */
374 hw->wiphy->max_adj_channel_rssi_comp = 3 * 5;
8ca151b5
JB
375
376 /* Extract MAC address */
377 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
378 hw->wiphy->addresses = mvm->addresses;
379 hw->wiphy->n_addresses = 1;
831e85f3
IP
380
381 /* Extract additional MAC addresses if available */
382 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
383 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
384
385 for (i = 1; i < num_mac; i++) {
386 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
8ca151b5 387 ETH_ALEN);
831e85f3 388 mvm->addresses[i].addr[5]++;
8ca151b5
JB
389 hw->wiphy->n_addresses++;
390 }
391
fe0f2de3
IP
392 iwl_mvm_reset_phy_ctxts(mvm);
393
48849a41 394 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm, false);
20f1a5de 395
8ca151b5
JB
396 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
397
398 if (mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels)
399 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
400 &mvm->nvm_data->bands[IEEE80211_BAND_2GHZ];
3d44eebf 401 if (mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels) {
8ca151b5
JB
402 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
403 &mvm->nvm_data->bands[IEEE80211_BAND_5GHZ];
404
3d44eebf
ES
405 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_BEAMFORMER)
406 hw->wiphy->bands[IEEE80211_BAND_5GHZ]->vht_cap.cap |=
407 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
408 }
409
8ca151b5
JB
410 hw->wiphy->hw_version = mvm->trans->hw_id;
411
ade50652 412 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
8ca151b5
JB
413 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
414 else
415 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
416
6efaaf33
EG
417 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 10) {
418 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
419 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
420 hw->wiphy->max_match_sets = IWL_SCAN_MAX_PROFILES;
421 /* we create the 802.11 header and zero length SSID IE. */
422 hw->wiphy->max_sched_scan_ie_len =
423 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
424 }
35a000b7 425
8ca151b5 426 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
ab480030 427 NL80211_FEATURE_LOW_PRIORITY_SCAN |
0d8614b4
EP
428 NL80211_FEATURE_P2P_GO_OPPPS |
429 NL80211_FEATURE_DYNAMIC_SMPS |
9b5452fd
EG
430 NL80211_FEATURE_STATIC_SMPS |
431 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
8ca151b5 432
f1daa00e
AO
433 if (mvm->fw->ucode_capa.capa[0] &
434 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT)
435 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
226bcd48
AK
436 if (mvm->fw->ucode_capa.capa[0] &
437 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT)
438 hw->wiphy->features |= NL80211_FEATURE_QUIET;
f1daa00e 439
73897bd1
AO
440 if (mvm->fw->ucode_capa.capa[0] &
441 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT)
442 hw->wiphy->features |=
443 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
444
445 if (mvm->fw->ucode_capa.capa[0] &
446 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT)
447 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
448
8ca151b5
JB
449 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
450
e36e5433 451 /* currently FW API supports only one optional cipher scheme */
9ddca860 452 if (mvm->fw->cs[0].cipher) {
e36e5433 453 mvm->hw->n_cipher_schemes = 1;
9ddca860 454 mvm->hw->cipher_schemes = &mvm->fw->cs[0];
e36e5433
MS
455 }
456
8ca151b5 457#ifdef CONFIG_PM_SLEEP
d15a747f
EP
458 if (iwl_mvm_is_d0i3_supported(mvm) &&
459 device_can_wakeup(mvm->trans->dev)) {
460 mvm->wowlan.flags = WIPHY_WOWLAN_ANY;
461 hw->wiphy->wowlan = &mvm->wowlan;
91742449
EP
462 }
463
464 if (mvm->fw->img[IWL_UCODE_WOWLAN].sec[0].len &&
8ca151b5
JB
465 mvm->trans->ops->d3_suspend &&
466 mvm->trans->ops->d3_resume &&
467 device_can_wakeup(mvm->trans->dev)) {
91742449
EP
468 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
469 WIPHY_WOWLAN_DISCONNECT |
470 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
471 WIPHY_WOWLAN_RFKILL_RELEASE |
472 WIPHY_WOWLAN_NET_DETECT;
8ca151b5 473 if (!iwlwifi_mod_params.sw_crypto)
964dc9e2
JB
474 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
475 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
476 WIPHY_WOWLAN_4WAY_HANDSHAKE;
477
478 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
479 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
480 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
c55385f5 481 mvm->wowlan.max_nd_match_sets = IWL_SCAN_MAX_PROFILES;
964dc9e2
JB
482 mvm->wowlan.tcp = &iwl_mvm_wowlan_tcp_support;
483 hw->wiphy->wowlan = &mvm->wowlan;
8ca151b5
JB
484 }
485#endif
486
77736923
EP
487#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
488 /* assign default bcast filtering configuration */
489 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
490#endif
491
8ca151b5
JB
492 ret = iwl_mvm_leds_init(mvm);
493 if (ret)
494 return ret;
495
d8f1c515
AN
496 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_TDLS_SUPPORT) {
497 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
498 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
499 }
500
1d3c3f63
AN
501 if (mvm->fw->ucode_capa.capa[0] &
502 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH) {
503 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
504 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
505 }
506
b7327d89
EG
507 ret = ieee80211_register_hw(mvm->hw);
508 if (ret)
509 iwl_mvm_leds_exit(mvm);
510
511 return ret;
8ca151b5
JB
512}
513
b2492501
AN
514static bool iwl_mvm_defer_tx(struct iwl_mvm *mvm,
515 struct ieee80211_sta *sta,
516 struct sk_buff *skb)
517{
518 struct iwl_mvm_sta *mvmsta;
519 bool defer = false;
520
521 /*
522 * double check the IN_D0I3 flag both before and after
523 * taking the spinlock, in order to prevent taking
524 * the spinlock when not needed.
525 */
526 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)))
527 return false;
528
529 spin_lock(&mvm->d0i3_tx_lock);
530 /*
531 * testing the flag again ensures the skb dequeue
532 * loop (on d0i3 exit) hasn't run yet.
533 */
534 if (!test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status))
535 goto out;
536
537 mvmsta = iwl_mvm_sta_from_mac80211(sta);
538 if (mvmsta->sta_id == IWL_MVM_STATION_COUNT ||
539 mvmsta->sta_id != mvm->d0i3_ap_sta_id)
540 goto out;
541
542 __skb_queue_tail(&mvm->d0i3_tx, skb);
543 ieee80211_stop_queues(mvm->hw);
544
545 /* trigger wakeup */
546 iwl_mvm_ref(mvm, IWL_MVM_REF_TX);
547 iwl_mvm_unref(mvm, IWL_MVM_REF_TX);
548
549 defer = true;
550out:
551 spin_unlock(&mvm->d0i3_tx_lock);
552 return defer;
553}
554
8ca151b5
JB
555static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
556 struct ieee80211_tx_control *control,
557 struct sk_buff *skb)
558{
559 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3e56eadf
JB
560 struct ieee80211_sta *sta = control->sta;
561 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
562 struct ieee80211_hdr *hdr = (void *)skb->data;
8ca151b5 563
9ee718aa
EL
564 if (iwl_mvm_is_radio_killed(mvm)) {
565 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
8ca151b5
JB
566 goto drop;
567 }
568
398e8c6c 569 if (IEEE80211_SKB_CB(skb)->hw_queue == IWL_MVM_OFFCHANNEL_QUEUE &&
a6cc5163
MG
570 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
571 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
8ca151b5
JB
572 goto drop;
573
3e56eadf
JB
574 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
575 if (unlikely(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER &&
576 ieee80211_is_mgmt(hdr->frame_control) &&
577 !ieee80211_is_deauth(hdr->frame_control) &&
578 !ieee80211_is_disassoc(hdr->frame_control) &&
579 !ieee80211_is_action(hdr->frame_control)))
580 sta = NULL;
581
582 if (sta) {
b2492501
AN
583 if (iwl_mvm_defer_tx(mvm, sta, skb))
584 return;
3e56eadf 585 if (iwl_mvm_tx_skb(mvm, skb, sta))
8ca151b5
JB
586 goto drop;
587 return;
588 }
589
590 if (iwl_mvm_tx_skb_non_sta(mvm, skb))
591 goto drop;
592 return;
593 drop:
594 ieee80211_free_txskb(hw, skb);
595}
596
205e2210
EG
597static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg *cfg)
598{
599 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_RXAGG)
600 return false;
601 return true;
602}
603
604static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg *cfg)
605{
606 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
607 return false;
608 if (iwlwifi_mod_params.disable_11n & IWL_ENABLE_HT_TXAGG)
609 return true;
610
611 /* enabled by default */
612 return true;
613}
614
8ca151b5
JB
615static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
616 struct ieee80211_vif *vif,
617 enum ieee80211_ampdu_mlme_action action,
618 struct ieee80211_sta *sta, u16 tid,
619 u16 *ssn, u8 buf_size)
620{
621 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
622 int ret;
b2492501 623 bool tx_agg_ref = false;
8ca151b5
JB
624
625 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
626 sta->addr, tid, action);
627
628 if (!(mvm->nvm_data->sku_cap_11n_enable))
629 return -EACCES;
630
b2492501 631 /* return from D0i3 before starting a new Tx aggregation */
9256c205
EP
632 switch (action) {
633 case IEEE80211_AMPDU_TX_START:
634 case IEEE80211_AMPDU_TX_STOP_CONT:
635 case IEEE80211_AMPDU_TX_STOP_FLUSH:
636 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
637 case IEEE80211_AMPDU_TX_OPERATIONAL:
b2492501 638 /*
9256c205
EP
639 * for tx start, wait synchronously until D0i3 exit to
640 * get the correct sequence number for the tid.
641 * additionally, some other ampdu actions use direct
642 * target access, which is not handled automatically
643 * by the trans layer (unlike commands), so wait for
644 * d0i3 exit in these cases as well.
b2492501 645 */
d40fc489
GG
646 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_TX_AGG);
647 if (ret)
648 return ret;
649
650 tx_agg_ref = true;
9256c205
EP
651 break;
652 default:
653 break;
b2492501
AN
654 }
655
8ca151b5
JB
656 mutex_lock(&mvm->mutex);
657
658 switch (action) {
659 case IEEE80211_AMPDU_RX_START:
205e2210 660 if (!iwl_enable_rx_ampdu(mvm->cfg)) {
8ca151b5
JB
661 ret = -EINVAL;
662 break;
663 }
664 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true);
665 break;
666 case IEEE80211_AMPDU_RX_STOP:
667 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false);
668 break;
669 case IEEE80211_AMPDU_TX_START:
205e2210 670 if (!iwl_enable_tx_ampdu(mvm->cfg)) {
5d158efa
EG
671 ret = -EINVAL;
672 break;
673 }
8ca151b5
JB
674 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
675 break;
676 case IEEE80211_AMPDU_TX_STOP_CONT:
e3d9e7ce
EG
677 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
678 break;
8ca151b5
JB
679 case IEEE80211_AMPDU_TX_STOP_FLUSH:
680 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
e3d9e7ce 681 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
8ca151b5
JB
682 break;
683 case IEEE80211_AMPDU_TX_OPERATIONAL:
684 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid, buf_size);
685 break;
686 default:
687 WARN_ON_ONCE(1);
688 ret = -EINVAL;
689 break;
690 }
691 mutex_unlock(&mvm->mutex);
692
b2492501
AN
693 /*
694 * If the tid is marked as started, we won't use it for offloaded
695 * traffic on the next D0i3 entry. It's safe to unref.
696 */
697 if (tx_agg_ref)
698 iwl_mvm_unref(mvm, IWL_MVM_REF_TX_AGG);
699
8ca151b5
JB
700 return ret;
701}
702
703static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
704 struct ieee80211_vif *vif)
705{
706 struct iwl_mvm *mvm = data;
707 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
708
709 mvmvif->uploaded = false;
710 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
711
8ca151b5
JB
712 spin_lock_bh(&mvm->time_event_lock);
713 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
714 spin_unlock_bh(&mvm->time_event_lock);
715
fe0f2de3 716 mvmvif->phy_ctxt = NULL;
8a275bad 717 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
8ca151b5
JB
718}
719
aadede6e
JB
720static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
721 const void *data, size_t datalen)
722{
723 const struct iwl_mvm_dump_ptrs *dump_ptrs = data;
724 ssize_t bytes_read;
725 ssize_t bytes_read_trans;
726
727 if (offset < dump_ptrs->op_mode_len) {
728 bytes_read = min_t(ssize_t, count,
729 dump_ptrs->op_mode_len - offset);
730 memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset,
731 bytes_read);
732 offset += bytes_read;
733 count -= bytes_read;
734
735 if (count == 0)
736 return bytes_read;
737 } else {
738 bytes_read = 0;
739 }
740
741 if (!dump_ptrs->trans_ptr)
742 return bytes_read;
743
744 offset -= dump_ptrs->op_mode_len;
745 bytes_read_trans = min_t(ssize_t, count,
746 dump_ptrs->trans_ptr->len - offset);
747 memcpy(buffer + bytes_read,
748 (u8 *)dump_ptrs->trans_ptr->data + offset,
749 bytes_read_trans);
750
751 return bytes_read + bytes_read_trans;
752}
753
754static void iwl_mvm_free_coredump(const void *data)
755{
756 const struct iwl_mvm_dump_ptrs *fw_error_dump = data;
757
758 vfree(fw_error_dump->op_mode_ptr);
759 vfree(fw_error_dump->trans_ptr);
760 kfree(fw_error_dump);
761}
762
04fd2c28
LK
763static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm,
764 struct iwl_fw_error_dump_data **dump_data)
765{
766 struct iwl_fw_error_dump_fifo *fifo_hdr;
767 u32 *fifo_data;
768 u32 fifo_len;
769 unsigned long flags;
770 int i, j;
771
772 if (!iwl_trans_grab_nic_access(mvm->trans, false, &flags))
773 return;
774
775 /* Pull RXF data from all RXFs */
776 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) {
777 /*
778 * Keep aside the additional offset that might be needed for
779 * next RXF
780 */
781 u32 offset_diff = RXF_DIFF_FROM_PREV * i;
782
783 fifo_hdr = (void *)(*dump_data)->data;
784 fifo_data = (void *)fifo_hdr->data;
785 fifo_len = mvm->shared_mem_cfg.rxfifo_size[i];
786
787 /* No need to try to read the data if the length is 0 */
788 if (fifo_len == 0)
789 continue;
790
791 /* Add a TLV for the RXF */
792 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
793 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
794
795 fifo_hdr->fifo_num = cpu_to_le32(i);
796 fifo_hdr->available_bytes =
797 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
798 RXF_RD_D_SPACE +
799 offset_diff));
800 fifo_hdr->wr_ptr =
801 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
802 RXF_RD_WR_PTR +
803 offset_diff));
804 fifo_hdr->rd_ptr =
805 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
806 RXF_RD_RD_PTR +
807 offset_diff));
808 fifo_hdr->fence_ptr =
809 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
810 RXF_RD_FENCE_PTR +
811 offset_diff));
812 fifo_hdr->fence_mode =
813 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
814 RXF_SET_FENCE_MODE +
815 offset_diff));
816
817 /* Lock fence */
818 iwl_trans_write_prph(mvm->trans,
819 RXF_SET_FENCE_MODE + offset_diff, 0x1);
820 /* Set fence pointer to the same place like WR pointer */
821 iwl_trans_write_prph(mvm->trans,
822 RXF_LD_WR2FENCE + offset_diff, 0x1);
823 /* Set fence offset */
824 iwl_trans_write_prph(mvm->trans,
825 RXF_LD_FENCE_OFFSET_ADDR + offset_diff,
826 0x0);
827
828 /* Read FIFO */
829 fifo_len /= sizeof(u32); /* Size in DWORDS */
830 for (j = 0; j < fifo_len; j++)
831 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
832 RXF_FIFO_RD_FENCE_INC +
833 offset_diff);
834 *dump_data = iwl_fw_error_next_data(*dump_data);
835 }
836
837 /* Pull TXF data from all TXFs */
838 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++) {
839 /* Mark the number of TXF we're pulling now */
840 iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i);
841
842 fifo_hdr = (void *)(*dump_data)->data;
843 fifo_data = (void *)fifo_hdr->data;
844 fifo_len = mvm->shared_mem_cfg.txfifo_size[i];
845
846 /* No need to try to read the data if the length is 0 */
847 if (fifo_len == 0)
848 continue;
849
850 /* Add a TLV for the FIFO */
851 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF);
852 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
853
854 fifo_hdr->fifo_num = cpu_to_le32(i);
855 fifo_hdr->available_bytes =
856 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
857 TXF_FIFO_ITEM_CNT));
858 fifo_hdr->wr_ptr =
859 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
860 TXF_WR_PTR));
861 fifo_hdr->rd_ptr =
862 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
863 TXF_RD_PTR));
864 fifo_hdr->fence_ptr =
865 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
866 TXF_FENCE_PTR));
867 fifo_hdr->fence_mode =
868 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
869 TXF_LOCK_FENCE));
870
871 /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */
872 iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR,
873 TXF_WR_PTR);
874
875 /* Dummy-read to advance the read pointer to the head */
876 iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA);
877
878 /* Read FIFO */
879 fifo_len /= sizeof(u32); /* Size in DWORDS */
880 for (j = 0; j < fifo_len; j++)
881 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
882 TXF_READ_MODIFY_DATA);
883 *dump_data = iwl_fw_error_next_data(*dump_data);
884 }
885
886 iwl_trans_release_nic_access(mvm->trans, &flags);
887}
888
4bfa47f3 889void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
655e6d6d
EG
890{
891 struct iwl_fw_error_dump_file *dump_file;
892 struct iwl_fw_error_dump_data *dump_data;
893 struct iwl_fw_error_dump_info *dump_info;
a549b296 894 struct iwl_fw_error_dump_mem *dump_mem;
48eb7b34 895 struct iwl_mvm_dump_ptrs *fw_error_dump;
655e6d6d 896 u32 sram_len, sram_ofs;
04fd2c28 897 u32 file_len, fifo_data_len = 0;
addfaada 898 u32 smem_len = mvm->cfg->smem_len;
86138324 899 u32 sram2_len = mvm->cfg->dccm2_len;
655e6d6d
EG
900
901 lockdep_assert_held(&mvm->mutex);
902
addfaada 903 /* W/A for 8000 HW family A-step */
86138324
IY
904 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
905 CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_A_STEP) {
906 if (smem_len)
907 smem_len = 0x38000;
908
909 if (sram2_len)
910 sram2_len = 0x10000;
911 }
addfaada 912
aadede6e 913 fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
48eb7b34
EG
914 if (!fw_error_dump)
915 return;
916
f53bf4c7
LK
917 /* SRAM - include stack CCM if driver knows the values for it */
918 if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
919 const struct fw_img *img;
920
921 img = &mvm->fw->img[mvm->cur_ucode];
922 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
923 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
924 } else {
925 sram_ofs = mvm->cfg->dccm_offset;
926 sram_len = mvm->cfg->dccm_len;
927 }
655e6d6d 928
04fd2c28
LK
929 /* reading RXF/TXF sizes */
930 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
931 struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->shared_mem_cfg;
932 int i;
933
934 fifo_data_len = 0;
935
936 /* Count RXF size */
937 for (i = 0; i < ARRAY_SIZE(mem_cfg->rxfifo_size); i++) {
938 if (!mem_cfg->rxfifo_size[i])
939 continue;
940
941 /* Add header info */
942 fifo_data_len += mem_cfg->rxfifo_size[i] +
943 sizeof(*dump_data) +
944 sizeof(struct iwl_fw_error_dump_fifo);
945 }
946
947 for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) {
948 if (!mem_cfg->txfifo_size[i])
949 continue;
655e6d6d 950
04fd2c28
LK
951 /* Add header info */
952 fifo_data_len += mem_cfg->txfifo_size[i] +
953 sizeof(*dump_data) +
954 sizeof(struct iwl_fw_error_dump_fifo);
955 }
956 }
655e6d6d
EG
957
958 file_len = sizeof(*dump_file) +
04fd2c28 959 sizeof(*dump_data) * 2 +
a549b296 960 sram_len + sizeof(*dump_mem) +
04fd2c28 961 fifo_data_len +
655e6d6d
EG
962 sizeof(*dump_info);
963
addfaada
LK
964 /* Make room for the SMEM, if it exists */
965 if (smem_len)
a549b296 966 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
addfaada 967
86138324
IY
968 /* Make room for the secondary SRAM, if it exists */
969 if (sram2_len)
970 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
971
5bfe6f53 972 dump_file = vzalloc(file_len);
48eb7b34
EG
973 if (!dump_file) {
974 kfree(fw_error_dump);
655e6d6d 975 return;
48eb7b34 976 }
655e6d6d 977
48eb7b34 978 fw_error_dump->op_mode_ptr = dump_file;
655e6d6d
EG
979
980 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
655e6d6d
EG
981 dump_data = (void *)dump_file->data;
982
983 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
984 dump_data->len = cpu_to_le32(sizeof(*dump_info));
985 dump_info = (void *) dump_data->data;
986 dump_info->device_family =
987 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
988 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
989 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
435da2ce 990 dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
655e6d6d
EG
991 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
992 sizeof(dump_info->fw_human_readable));
993 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
994 sizeof(dump_info->dev_human_readable));
995 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
996 sizeof(dump_info->bus_human_readable));
997
998 dump_data = iwl_fw_error_next_data(dump_data);
04fd2c28
LK
999 /* We only dump the FIFOs if the FW is in error state */
1000 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status))
1001 iwl_mvm_dump_fifos(mvm, &dump_data);
655e6d6d 1002
a549b296
EG
1003 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1004 dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
1005 dump_mem = (void *)dump_data->data;
1006 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1007 dump_mem->offset = cpu_to_le32(sram_ofs);
1008 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
655e6d6d
EG
1009 sram_len);
1010
addfaada
LK
1011 if (smem_len) {
1012 dump_data = iwl_fw_error_next_data(dump_data);
e06d8437
EG
1013 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1014 dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
1015 dump_mem = (void *)dump_data->data;
1016 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
1017 dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
addfaada 1018 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
e06d8437 1019 dump_mem->data, smem_len);
addfaada
LK
1020 }
1021
86138324
IY
1022 if (sram2_len) {
1023 dump_data = iwl_fw_error_next_data(dump_data);
1024 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
1025 dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
1026 dump_mem = (void *)dump_data->data;
1027 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
1028 dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
1029 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
1030 dump_mem->data, sram2_len);
1031 }
1032
48eb7b34
EG
1033 fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans);
1034 fw_error_dump->op_mode_len = file_len;
1035 if (fw_error_dump->trans_ptr)
1036 file_len += fw_error_dump->trans_ptr->len;
1037 dump_file->file_len = cpu_to_le32(file_len);
4bfa47f3 1038
aadede6e
JB
1039 dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
1040 GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
655e6d6d 1041}
655e6d6d 1042
8ca151b5
JB
1043static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1044{
58629d9d
JB
1045 /* clear the D3 reconfig, we only need it to avoid dumping a
1046 * firmware coredump on reconfiguration, we shouldn't do that
1047 * on D3->D0 transition
1048 */
1049 if (!test_and_clear_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status))
1050 iwl_mvm_fw_error_dump(mvm);
1bd3cbc1 1051
744cb695
EP
1052 /* cleanup all stale references (scan, roc), but keep the
1053 * ucode_down ref until reconfig is complete
1054 */
1055 iwl_mvm_unref_all_except(mvm, IWL_MVM_REF_UCODE_DOWN);
1056
8ca151b5 1057 iwl_trans_stop_device(mvm->trans);
8ca151b5
JB
1058
1059 mvm->scan_status = IWL_MVM_SCAN_NONE;
b1873300 1060 mvm->ps_disabled = false;
31b8b343 1061 mvm->calibrating = false;
8ca151b5
JB
1062
1063 /* just in case one was running */
1064 ieee80211_remain_on_channel_expired(mvm->hw);
1065
1066 ieee80211_iterate_active_interfaces_atomic(
1067 mvm->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
1068 iwl_mvm_cleanup_iterator, mvm);
1069
fe0f2de3 1070 mvm->p2p_device_vif = NULL;
37577fe2 1071 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
fe0f2de3
IP
1072
1073 iwl_mvm_reset_phy_ctxts(mvm);
8ca151b5
JB
1074 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1075 memset(mvm->sta_drained, 0, sizeof(mvm->sta_drained));
a0f6bf2a 1076 memset(mvm->tfd_drained, 0, sizeof(mvm->tfd_drained));
8a275bad
EG
1077 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1078 memset(&mvm->last_bt_notif_old, 0, sizeof(mvm->last_bt_notif_old));
1079 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1080 memset(&mvm->last_bt_ci_cmd_old, 0, sizeof(mvm->last_bt_ci_cmd_old));
1081 memset(&mvm->bt_ack_kill_msk, 0, sizeof(mvm->bt_ack_kill_msk));
1082 memset(&mvm->bt_cts_kill_msk, 0, sizeof(mvm->bt_cts_kill_msk));
8ca151b5
JB
1083
1084 ieee80211_wake_queues(mvm->hw);
1085
228670b2
EP
1086 /* clear any stale d0i3 state */
1087 clear_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status);
1088
8ca151b5 1089 mvm->vif_count = 0;
113a0447 1090 mvm->rx_ba_sessions = 0;
91a8bcde
JB
1091
1092 /* keep statistics ticking */
1093 iwl_mvm_accu_radio_stats(mvm);
8ca151b5
JB
1094}
1095
a0a09243 1096int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
8ca151b5 1097{
8ca151b5
JB
1098 int ret;
1099
a0a09243 1100 lockdep_assert_held(&mvm->mutex);
8ca151b5
JB
1101
1102 /* Clean up some internal and mac80211 state on restart */
1103 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1104 iwl_mvm_restart_cleanup(mvm);
1105
1106 ret = iwl_mvm_up(mvm);
c47af22a
JB
1107
1108 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1109 /* Something went wrong - we need to finish some cleanup
1110 * that normally iwl_mvm_mac_restart_complete() below
1111 * would do.
1112 */
1113 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1114 iwl_mvm_d0i3_enable_tx(mvm, NULL);
1115 }
1116
a0a09243
LC
1117 return ret;
1118}
1119
1120static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1121{
1122 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1123 int ret;
1124
37948fcf
EP
1125 /* Some hw restart cleanups must not hold the mutex */
1126 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1127 /*
1128 * Make sure we are out of d0i3. This is needed
1129 * to make sure the reference accounting is correct
1130 * (and there is no stale d0i3_exit_work).
1131 */
1132 wait_event_timeout(mvm->d0i3_exit_waitq,
1133 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1134 &mvm->status),
1135 HZ);
1136 }
1137
a0a09243
LC
1138 mutex_lock(&mvm->mutex);
1139 ret = __iwl_mvm_mac_start(mvm);
8ca151b5
JB
1140 mutex_unlock(&mvm->mutex);
1141
1142 return ret;
1143}
1144
cf2c92d8 1145static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
8ca151b5 1146{
8ca151b5
JB
1147 int ret;
1148
1149 mutex_lock(&mvm->mutex);
1150
1151 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
b2492501 1152 iwl_mvm_d0i3_enable_tx(mvm, NULL);
0166230c 1153 ret = iwl_mvm_update_quotas(mvm, NULL);
8ca151b5
JB
1154 if (ret)
1155 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1156 ret);
1157
7498cf4c
EP
1158 /* allow transport/FW low power modes */
1159 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1160
cbd2ae2d
AN
1161 /*
1162 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1163 * of packets the FW sent out, so we must reconnect.
1164 */
1165 iwl_mvm_teardown_tdls_peers(mvm);
1166
8ca151b5
JB
1167 mutex_unlock(&mvm->mutex);
1168}
1169
088070a2
EP
1170static void iwl_mvm_resume_complete(struct iwl_mvm *mvm)
1171{
1172 bool exit_now;
1173
1174 if (!iwl_mvm_is_d0i3_supported(mvm))
1175 return;
1176
1177 mutex_lock(&mvm->d0i3_suspend_mutex);
1178 __clear_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags);
1179 exit_now = __test_and_clear_bit(D0I3_PENDING_WAKEUP,
1180 &mvm->d0i3_suspend_flags);
1181 mutex_unlock(&mvm->d0i3_suspend_mutex);
1182
1183 if (exit_now) {
1184 IWL_DEBUG_RPM(mvm, "Run deferred d0i3 exit\n");
1185 _iwl_mvm_exit_d0i3(mvm);
1186 }
6735943f
EP
1187
1188 if (mvm->trans->d0i3_mode == IWL_D0I3_MODE_ON_SUSPEND)
1189 if (!wait_event_timeout(mvm->d0i3_exit_waitq,
1190 !test_bit(IWL_MVM_STATUS_IN_D0I3,
1191 &mvm->status),
1192 HZ))
1193 WARN_ONCE(1, "D0i3 exit on resume timed out\n");
088070a2
EP
1194}
1195
cf2c92d8
EP
1196static void
1197iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1198 enum ieee80211_reconfig_type reconfig_type)
1199{
1200 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1201
1202 switch (reconfig_type) {
1203 case IEEE80211_RECONFIG_TYPE_RESTART:
1204 iwl_mvm_restart_complete(mvm);
1205 break;
1206 case IEEE80211_RECONFIG_TYPE_SUSPEND:
088070a2 1207 iwl_mvm_resume_complete(mvm);
cf2c92d8
EP
1208 break;
1209 }
1210}
1211
a0a09243 1212void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
8ca151b5 1213{
a0a09243 1214 lockdep_assert_held(&mvm->mutex);
7498cf4c 1215
91a8bcde
JB
1216 /* firmware counters are obviously reset now, but we shouldn't
1217 * partially track so also clear the fw_reset_accu counters.
1218 */
1219 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1220
0a79a0c0
EP
1221 /*
1222 * Disallow low power states when the FW is down by taking
1223 * the UCODE_DOWN ref. in case of ongoing hw restart the
1224 * ref is already taken, so don't take it again.
1225 */
1226 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1227 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
7498cf4c 1228
8ca151b5
JB
1229 /* async_handlers_wk is now blocked */
1230
1231 /*
1232 * The work item could be running or queued if the
1233 * ROC time event stops just as we get here.
1234 */
1235 cancel_work_sync(&mvm->roc_done_wk);
1236
1237 iwl_trans_stop_device(mvm->trans);
8ca151b5
JB
1238
1239 iwl_mvm_async_handlers_purge(mvm);
1240 /* async_handlers_list is empty and will stay empty: HW is stopped */
1241
1242 /* the fw is stopped, the aux sta is dead: clean up driver state */
712b24ad 1243 iwl_mvm_del_aux_sta(mvm);
8ca151b5 1244
0a79a0c0
EP
1245 /*
1246 * Clear IN_HW_RESTART flag when stopping the hw (as restart_complete()
1247 * won't be called in this case).
1248 */
1249 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1250
bc44886d 1251 mvm->ucode_loaded = false;
a0a09243 1252}
bc44886d 1253
a0a09243
LC
1254static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1255{
1256 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1257
1258 flush_work(&mvm->d0i3_exit_work);
1259 flush_work(&mvm->async_handlers_wk);
4bfa47f3 1260 flush_work(&mvm->fw_error_dump_wk);
a0a09243
LC
1261
1262 mutex_lock(&mvm->mutex);
1263 __iwl_mvm_mac_stop(mvm);
8ca151b5
JB
1264 mutex_unlock(&mvm->mutex);
1265
1266 /*
1267 * The worker might have been waiting for the mutex, let it run and
1268 * discover that its list is now empty.
1269 */
1270 cancel_work_sync(&mvm->async_handlers_wk);
1271}
1272
fe0f2de3
IP
1273static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1274{
1275 u16 i;
1276
1277 lockdep_assert_held(&mvm->mutex);
1278
1279 for (i = 0; i < NUM_PHY_CTX; i++)
1280 if (!mvm->phy_ctxts[i].ref)
1281 return &mvm->phy_ctxts[i];
1282
1283 IWL_ERR(mvm, "No available PHY context\n");
1284 return NULL;
1285}
1286
ee9c6cb0
EG
1287static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1288 s8 tx_power)
1289{
1290 /* FW is in charge of regulatory enforcement */
1291 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd = {
1292 .mac_context_id = iwl_mvm_vif_from_mac80211(vif)->id,
1293 .pwr_restriction = cpu_to_le16(tx_power),
1294 };
1295
a1022927 1296 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
ee9c6cb0
EG
1297 sizeof(reduce_txpwr_cmd),
1298 &reduce_txpwr_cmd);
1299}
1300
8ca151b5
JB
1301static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1302 struct ieee80211_vif *vif)
1303{
1304 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1305 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1306 int ret;
1307
d40fc489
GG
1308 /*
1309 * make sure D0i3 exit is completed, otherwise a target access
1310 * during tx queue configuration could be done when still in
1311 * D0i3 state.
1312 */
1313 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_ADD_IF);
1314 if (ret)
1315 return ret;
1316
8ca151b5
JB
1317 /*
1318 * Not much to do here. The stack will not allow interface
1319 * types or combinations that we didn't advertise, so we
1320 * don't really have to check the types.
1321 */
1322
1323 mutex_lock(&mvm->mutex);
1324
e89044d7 1325 /* Allocate resources for the MAC context, and add it to the fw */
8ca151b5
JB
1326 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1327 if (ret)
1328 goto out_unlock;
1329
1c2abf72 1330 /* Counting number of interfaces is needed for legacy PM */
ea183d02
IP
1331 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1332 mvm->vif_count++;
ea183d02 1333
8ca151b5
JB
1334 /*
1335 * The AP binding flow can be done only after the beacon
1336 * template is configured (which happens only in the mac80211
1337 * start_ap() flow), and adding the broadcast station can happen
1338 * only after the binding.
1339 * In addition, since modifying the MAC before adding a bcast
1340 * station is not allowed by the FW, delay the adding of MAC context to
1341 * the point where we can also add the bcast station.
1342 * In short: there's not much we can do at this point, other than
1343 * allocating resources :)
1344 */
5023d966
JB
1345 if (vif->type == NL80211_IFTYPE_AP ||
1346 vif->type == NL80211_IFTYPE_ADHOC) {
013290aa 1347 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
8ca151b5
JB
1348 if (ret) {
1349 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1350 goto out_release;
1351 }
1352
77740cb4 1353 iwl_mvm_vif_dbgfs_register(mvm, vif);
8ca151b5
JB
1354 goto out_unlock;
1355 }
1356
8ca151b5
JB
1357 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1358 if (ret)
1359 goto out_release;
1360
999609f1 1361 ret = iwl_mvm_power_update_mac(mvm);
e5e7aa8e 1362 if (ret)
fd66fc1c 1363 goto out_remove_mac;
8ca151b5 1364
7df15b1e 1365 /* beacon filtering */
a1022927 1366 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
bd3351ba
EP
1367 if (ret)
1368 goto out_remove_mac;
1369
7df15b1e 1370 if (!mvm->bf_allowed_vif &&
73e5f2c5 1371 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
7df15b1e 1372 mvm->bf_allowed_vif = mvmvif;
a20fd398
AO
1373 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1374 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
7df15b1e
HG
1375 }
1376
8ca151b5
JB
1377 /*
1378 * P2P_DEVICE interface does not have a channel context assigned to it,
1379 * so a dedicated PHY context is allocated to it and the corresponding
1380 * MAC context is bound to it at this stage.
1381 */
1382 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
8ca151b5 1383
fe0f2de3
IP
1384 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1385 if (!mvmvif->phy_ctxt) {
1386 ret = -ENOSPC;
bd3351ba 1387 goto out_free_bf;
fe0f2de3 1388 }
8ca151b5 1389
53a9d61e 1390 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
8ca151b5
JB
1391 ret = iwl_mvm_binding_add_vif(mvm, vif);
1392 if (ret)
53a9d61e 1393 goto out_unref_phy;
8ca151b5 1394
013290aa 1395 ret = iwl_mvm_add_bcast_sta(mvm, vif);
8ca151b5
JB
1396 if (ret)
1397 goto out_unbind;
1398
1399 /* Save a pointer to p2p device vif, so it can later be used to
1400 * update the p2p device MAC when a GO is started/stopped */
1401 mvm->p2p_device_vif = vif;
1402 }
1403
63494374 1404 iwl_mvm_vif_dbgfs_register(mvm, vif);
8ca151b5
JB
1405 goto out_unlock;
1406
1407 out_unbind:
1408 iwl_mvm_binding_remove_vif(mvm, vif);
53a9d61e 1409 out_unref_phy:
fe0f2de3 1410 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
bd3351ba
EP
1411 out_free_bf:
1412 if (mvm->bf_allowed_vif == mvmvif) {
1413 mvm->bf_allowed_vif = NULL;
a20fd398
AO
1414 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1415 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
bd3351ba 1416 }
8ca151b5
JB
1417 out_remove_mac:
1418 mvmvif->phy_ctxt = NULL;
1419 iwl_mvm_mac_ctxt_remove(mvm, vif);
1420 out_release:
5ee2b215
AB
1421 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1422 mvm->vif_count--;
1c2abf72 1423
8ca151b5
JB
1424 iwl_mvm_mac_ctxt_release(mvm, vif);
1425 out_unlock:
1426 mutex_unlock(&mvm->mutex);
1427
d40fc489
GG
1428 iwl_mvm_unref(mvm, IWL_MVM_REF_ADD_IF);
1429
8ca151b5
JB
1430 return ret;
1431}
1432
38a12b5b
JB
1433static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1434 struct ieee80211_vif *vif)
8ca151b5 1435{
d92b732e 1436 u32 tfd_msk = iwl_mvm_mac_get_queues_mask(vif);
8ca151b5
JB
1437
1438 if (tfd_msk) {
1439 mutex_lock(&mvm->mutex);
1440 iwl_mvm_flush_tx_path(mvm, tfd_msk, true);
1441 mutex_unlock(&mvm->mutex);
1442 }
1443
1444 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1445 /*
1446 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1447 * We assume here that all the packets sent to the OFFCHANNEL
1448 * queue are sent in ROC session.
1449 */
1450 flush_work(&mvm->roc_done_wk);
1451 } else {
1452 /*
1453 * By now, all the AC queues are empty. The AGG queues are
1454 * empty too. We already got all the Tx responses for all the
1455 * packets in the queues. The drain work can have been
0742a75a 1456 * triggered. Flush it.
8ca151b5
JB
1457 */
1458 flush_work(&mvm->sta_drained_wk);
1459 }
38a12b5b
JB
1460}
1461
1462static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1463 struct ieee80211_vif *vif)
1464{
1465 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1466 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1467
1468 iwl_mvm_prepare_mac_removal(mvm, vif);
8ca151b5
JB
1469
1470 mutex_lock(&mvm->mutex);
1471
7df15b1e
HG
1472 if (mvm->bf_allowed_vif == mvmvif) {
1473 mvm->bf_allowed_vif = NULL;
a20fd398
AO
1474 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1475 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
7df15b1e
HG
1476 }
1477
63494374
JB
1478 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1479
8ca151b5
JB
1480 /*
1481 * For AP/GO interface, the tear down of the resources allocated to the
38a12b5b 1482 * interface is be handled as part of the stop_ap flow.
8ca151b5 1483 */
5023d966
JB
1484 if (vif->type == NL80211_IFTYPE_AP ||
1485 vif->type == NL80211_IFTYPE_ADHOC) {
507cadf2
DS
1486#ifdef CONFIG_NL80211_TESTMODE
1487 if (vif == mvm->noa_vif) {
1488 mvm->noa_vif = NULL;
1489 mvm->noa_duration = 0;
1490 }
1491#endif
013290aa 1492 iwl_mvm_dealloc_bcast_sta(mvm, vif);
8ca151b5
JB
1493 goto out_release;
1494 }
1495
1496 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1497 mvm->p2p_device_vif = NULL;
013290aa 1498 iwl_mvm_rm_bcast_sta(mvm, vif);
8ca151b5 1499 iwl_mvm_binding_remove_vif(mvm, vif);
fe0f2de3 1500 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
8ca151b5
JB
1501 mvmvif->phy_ctxt = NULL;
1502 }
1503
5ee2b215 1504 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
8ca151b5 1505 mvm->vif_count--;
1c2abf72 1506
999609f1 1507 iwl_mvm_power_update_mac(mvm);
8ca151b5
JB
1508 iwl_mvm_mac_ctxt_remove(mvm, vif);
1509
1510out_release:
1511 iwl_mvm_mac_ctxt_release(mvm, vif);
1512 mutex_unlock(&mvm->mutex);
1513}
1514
1515static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
88f2fd73 1516{
8ca151b5
JB
1517 return 0;
1518}
1519
e59647ea
EP
1520struct iwl_mvm_mc_iter_data {
1521 struct iwl_mvm *mvm;
1522 int port_id;
1523};
1524
1525static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1526 struct ieee80211_vif *vif)
1527{
1528 struct iwl_mvm_mc_iter_data *data = _data;
1529 struct iwl_mvm *mvm = data->mvm;
1530 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1531 int ret, len;
1532
1533 /* if we don't have free ports, mcast frames will be dropped */
1534 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1535 return;
1536
1537 if (vif->type != NL80211_IFTYPE_STATION ||
1538 !vif->bss_conf.assoc)
1539 return;
1540
1541 cmd->port_id = data->port_id++;
1542 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1543 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1544
1c4abec0 1545 ret = iwl_mvm_send_cmd_pdu(mvm, MCAST_FILTER_CMD, CMD_ASYNC, len, cmd);
e59647ea
EP
1546 if (ret)
1547 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1548}
1549
1550static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1551{
1552 struct iwl_mvm_mc_iter_data iter_data = {
1553 .mvm = mvm,
88f2fd73
MG
1554 };
1555
e59647ea
EP
1556 lockdep_assert_held(&mvm->mutex);
1557
1558 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1559 return;
1560
1c4abec0 1561 ieee80211_iterate_active_interfaces_atomic(
e59647ea
EP
1562 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1563 iwl_mvm_mc_iface_iterator, &iter_data);
88f2fd73
MG
1564}
1565
e59647ea
EP
1566static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1567 struct netdev_hw_addr_list *mc_list)
8ca151b5 1568{
e59647ea
EP
1569 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1570 struct iwl_mcast_filter_cmd *cmd;
1571 struct netdev_hw_addr *addr;
f3bd58f4
MS
1572 int addr_count;
1573 bool pass_all;
e59647ea
EP
1574 int len;
1575
f3bd58f4
MS
1576 addr_count = netdev_hw_addr_list_count(mc_list);
1577 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1578 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1579 if (pass_all)
e59647ea 1580 addr_count = 0;
e59647ea
EP
1581
1582 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1583 cmd = kzalloc(len, GFP_ATOMIC);
1584 if (!cmd)
1585 return 0;
1586
1587 if (pass_all) {
1588 cmd->pass_all = 1;
1589 return (u64)(unsigned long)cmd;
1590 }
1591
1592 netdev_hw_addr_list_for_each(addr, mc_list) {
1593 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1594 cmd->count, addr->addr);
1595 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1596 addr->addr, ETH_ALEN);
1597 cmd->count++;
1598 }
1599
1600 return (u64)(unsigned long)cmd;
8ca151b5
JB
1601}
1602
1603static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1604 unsigned int changed_flags,
1605 unsigned int *total_flags,
1606 u64 multicast)
1607{
e59647ea
EP
1608 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1609 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
8ca151b5 1610
e59647ea 1611 mutex_lock(&mvm->mutex);
51b6b9e0 1612
e59647ea
EP
1613 /* replace previous configuration */
1614 kfree(mvm->mcast_filter_cmd);
1615 mvm->mcast_filter_cmd = cmd;
51b6b9e0 1616
e59647ea
EP
1617 if (!cmd)
1618 goto out;
51b6b9e0 1619
e59647ea
EP
1620 iwl_mvm_recalc_multicast(mvm);
1621out:
1622 mutex_unlock(&mvm->mutex);
1623 *total_flags = 0;
51b6b9e0
EG
1624}
1625
c87163b9
EP
1626#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1627struct iwl_bcast_iter_data {
1628 struct iwl_mvm *mvm;
1629 struct iwl_bcast_filter_cmd *cmd;
1630 u8 current_filter;
1631};
1632
1633static void
1634iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1635 const struct iwl_fw_bcast_filter *in_filter,
1636 struct iwl_fw_bcast_filter *out_filter)
1637{
1638 struct iwl_fw_bcast_filter_attr *attr;
1639 int i;
1640
1641 memcpy(out_filter, in_filter, sizeof(*out_filter));
1642
1643 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1644 attr = &out_filter->attrs[i];
1645
1646 if (!attr->mask)
1647 break;
1648
2ee8f021
EP
1649 switch (attr->reserved1) {
1650 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1651 if (vif->bss_conf.arp_addr_cnt != 1) {
1652 attr->mask = 0;
1653 continue;
1654 }
1655
1656 attr->val = vif->bss_conf.arp_addr_list[0];
1657 break;
1658 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1659 attr->val = *(__be32 *)&vif->addr[2];
1660 break;
1661 default:
1662 break;
1663 }
1664 attr->reserved1 = 0;
c87163b9
EP
1665 out_filter->num_attrs++;
1666 }
1667}
1668
1669static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1670 struct ieee80211_vif *vif)
1671{
1672 struct iwl_bcast_iter_data *data = _data;
1673 struct iwl_mvm *mvm = data->mvm;
1674 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1675 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1676 struct iwl_fw_bcast_mac *bcast_mac;
1677 int i;
1678
1679 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1680 return;
1681
1682 bcast_mac = &cmd->macs[mvmvif->id];
1683
e48393e8
IP
1684 /*
1685 * enable filtering only for associated stations, but not for P2P
1686 * Clients
1687 */
1688 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1689 !vif->bss_conf.assoc)
c87163b9
EP
1690 return;
1691
1692 bcast_mac->default_discard = 1;
1693
1694 /* copy all configured filters */
1695 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1696 /*
1697 * Make sure we don't exceed our filters limit.
1698 * if there is still a valid filter to be configured,
1699 * be on the safe side and just allow bcast for this mac.
1700 */
1701 if (WARN_ON_ONCE(data->current_filter >=
1702 ARRAY_SIZE(cmd->filters))) {
1703 bcast_mac->default_discard = 0;
1704 bcast_mac->attached_filters = 0;
1705 break;
1706 }
1707
1708 iwl_mvm_set_bcast_filter(vif,
1709 &mvm->bcast_filters[i],
1710 &cmd->filters[data->current_filter]);
1711
1712 /* skip current filter if it contains no attributes */
1713 if (!cmd->filters[data->current_filter].num_attrs)
1714 continue;
1715
1716 /* attach the filter to current mac */
1717 bcast_mac->attached_filters |=
1718 cpu_to_le16(BIT(data->current_filter));
1719
1720 data->current_filter++;
1721 }
1722}
1723
de06a59e
EP
1724bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1725 struct iwl_bcast_filter_cmd *cmd)
c87163b9 1726{
c87163b9
EP
1727 struct iwl_bcast_iter_data iter_data = {
1728 .mvm = mvm,
de06a59e 1729 .cmd = cmd,
c87163b9
EP
1730 };
1731
3b8983b1
MS
1732 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1733 return false;
1734
de06a59e
EP
1735 memset(cmd, 0, sizeof(*cmd));
1736 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1737 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1738
1739#ifdef CONFIG_IWLWIFI_DEBUGFS
1740 /* use debugfs filters/macs if override is configured */
1741 if (mvm->dbgfs_bcast_filtering.override) {
1742 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1743 sizeof(cmd->filters));
1744 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1745 sizeof(cmd->macs));
1746 return true;
1747 }
1748#endif
c87163b9
EP
1749
1750 /* if no filters are configured, do nothing */
1751 if (!mvm->bcast_filters)
de06a59e 1752 return false;
c87163b9
EP
1753
1754 /* configure and attach these filters for each associated sta vif */
1755 ieee80211_iterate_active_interfaces(
1756 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1757 iwl_mvm_bcast_filter_iterator, &iter_data);
1758
de06a59e
EP
1759 return true;
1760}
1761static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1762 struct ieee80211_vif *vif)
1763{
1764 struct iwl_bcast_filter_cmd cmd;
1765
1766 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1767 return 0;
1768
1769 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1770 return 0;
1771
a1022927 1772 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
c87163b9
EP
1773 sizeof(cmd), &cmd);
1774}
1775#else
1776static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm,
1777 struct ieee80211_vif *vif)
1778{
1779 return 0;
1780}
1781#endif
1782
8ca151b5
JB
1783static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
1784 struct ieee80211_vif *vif,
1785 struct ieee80211_bss_conf *bss_conf,
1786 u32 changes)
1787{
1788 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1789 int ret;
1790
6e97b0d2
IP
1791 /*
1792 * Re-calculate the tsf id, as the master-slave relations depend on the
1793 * beacon interval, which was not known when the station interface was
1794 * added.
1795 */
1796 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc)
1797 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1798
3dfd3a97
JB
1799 /*
1800 * If we're not associated yet, take the (new) BSSID before associating
1801 * so the firmware knows. If we're already associated, then use the old
1802 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
1803 * branch for disassociation below.
1804 */
1805 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
1806 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1807
1808 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
8ca151b5
JB
1809 if (ret)
1810 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
1811
3dfd3a97
JB
1812 /* after sending it once, adopt mac80211 data */
1813 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
1814 mvmvif->associated = bss_conf->assoc;
1815
8ca151b5
JB
1816 if (changes & BSS_CHANGED_ASSOC) {
1817 if (bss_conf->assoc) {
1818 /* add quota for this interface */
0166230c 1819 ret = iwl_mvm_update_quotas(mvm, NULL);
8ca151b5
JB
1820 if (ret) {
1821 IWL_ERR(mvm, "failed to update quotas\n");
1822 return;
1823 }
016d27e1
JB
1824
1825 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
1826 &mvm->status)) {
1827 /*
1828 * If we're restarting then the firmware will
1829 * obviously have lost synchronisation with
1830 * the AP. It will attempt to synchronise by
1831 * itself, but we can make it more reliable by
1832 * scheduling a session protection time event.
1833 *
1834 * The firmware needs to receive a beacon to
1835 * catch up with synchronisation, use 110% of
1836 * the beacon interval.
1837 *
1838 * Set a large maximum delay to allow for more
1839 * than a single interface.
1840 */
1841 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
1842 iwl_mvm_protect_session(mvm, vif, dur, dur,
d20d37bc 1843 5 * dur, false);
016d27e1 1844 }
1f3b0ff8
LE
1845
1846 iwl_mvm_sf_update(mvm, vif, false);
175a70b7 1847 iwl_mvm_power_vif_assoc(mvm, vif);
697162a1 1848 if (vif->p2p) {
29a90a49 1849 iwl_mvm_ref(mvm, IWL_MVM_REF_P2P_CLIENT);
697162a1
EG
1850 iwl_mvm_update_smps(mvm, vif,
1851 IWL_MVM_SMPS_REQ_PROT,
1852 IEEE80211_SMPS_DYNAMIC);
1853 }
8ca151b5 1854 } else if (mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1f3b0ff8
LE
1855 /*
1856 * If update fails - SF might be running in associated
1857 * mode while disassociated - which is forbidden.
1858 */
1859 WARN_ONCE(iwl_mvm_sf_update(mvm, vif, false),
1860 "Failed to update SF upon disassociation\n");
1861
8ca151b5
JB
1862 /* remove AP station now that the MAC is unassoc */
1863 ret = iwl_mvm_rm_sta_id(mvm, vif, mvmvif->ap_sta_id);
1864 if (ret)
1865 IWL_ERR(mvm, "failed to remove AP station\n");
37577fe2
EP
1866
1867 if (mvm->d0i3_ap_sta_id == mvmvif->ap_sta_id)
1868 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
8ca151b5
JB
1869 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1870 /* remove quota for this interface */
0166230c 1871 ret = iwl_mvm_update_quotas(mvm, NULL);
8ca151b5
JB
1872 if (ret)
1873 IWL_ERR(mvm, "failed to update quotas\n");
29a90a49
EP
1874
1875 if (vif->p2p)
1876 iwl_mvm_unref(mvm, IWL_MVM_REF_P2P_CLIENT);
3dfd3a97
JB
1877
1878 /* this will take the cleared BSSID from bss_conf */
1879 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1880 if (ret)
1881 IWL_ERR(mvm,
1882 "failed to update MAC %pM (clear after unassoc)\n",
1883 vif->addr);
8ca151b5 1884 }
a20fd398 1885
e59647ea 1886 iwl_mvm_recalc_multicast(mvm);
c87163b9 1887 iwl_mvm_configure_bcast_filter(mvm, vif);
e59647ea 1888
a20fd398
AO
1889 /* reset rssi values */
1890 mvmvif->bf_data.ave_beacon_signal = 0;
1891
8e484f0b 1892 iwl_mvm_bt_coex_vif_change(mvm);
f94045ed
EG
1893 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
1894 IEEE80211_SMPS_AUTOMATIC);
989c6505 1895 } else if (changes & BSS_CHANGED_BEACON_INFO) {
210a544e
JB
1896 /*
1897 * We received a beacon _after_ association so
1898 * remove the session protection.
1899 */
1900 iwl_mvm_remove_time_event(mvm, mvmvif,
1901 &mvmvif->time_event_data);
8ca151b5 1902 }
cc87d322
EH
1903
1904 if (changes & BSS_CHANGED_BEACON_INFO) {
1905 iwl_mvm_sf_update(mvm, vif, false);
1906 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1907 }
1908
1bc10d3b
JB
1909 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS)) {
1910 ret = iwl_mvm_power_update_mac(mvm);
1911 if (ret)
1912 IWL_ERR(mvm, "failed to update power mode\n");
1913 }
1914
88f2fd73
MG
1915 if (changes & BSS_CHANGED_TXPOWER) {
1916 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
1917 bss_conf->txpower);
1918 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
1919 }
a20fd398
AO
1920
1921 if (changes & BSS_CHANGED_CQM) {
3c6acb61 1922 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
a20fd398
AO
1923 /* reset cqm events tracking */
1924 mvmvif->bf_data.last_cqm_event = 0;
fa7b2e7f
AA
1925 if (mvmvif->bf_data.bf_enabled) {
1926 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1927 if (ret)
1928 IWL_ERR(mvm,
1929 "failed to update CQM thresholds\n");
1930 }
a20fd398 1931 }
2ee8f021
EP
1932
1933 if (changes & BSS_CHANGED_ARP_FILTER) {
3c6acb61 1934 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2ee8f021
EP
1935 iwl_mvm_configure_bcast_filter(mvm, vif);
1936 }
8ca151b5
JB
1937}
1938
5023d966
JB
1939static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
1940 struct ieee80211_vif *vif)
8ca151b5
JB
1941{
1942 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1943 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1944 int ret;
1945
576eeee9
EP
1946 /*
1947 * iwl_mvm_mac_ctxt_add() might read directly from the device
1948 * (the system time), so make sure it is available.
1949 */
1950 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_START_AP);
1951 if (ret)
1952 return ret;
1953
8ca151b5
JB
1954 mutex_lock(&mvm->mutex);
1955
1956 /* Send the beacon template */
1957 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
1958 if (ret)
1959 goto out_unlock;
1960
6e97b0d2
IP
1961 /*
1962 * Re-calculate the tsf id, as the master-slave relations depend on the
1963 * beacon interval, which was not known when the AP interface was added.
1964 */
1965 if (vif->type == NL80211_IFTYPE_AP)
1966 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
1967
8ca151b5
JB
1968 /* Add the mac context */
1969 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1970 if (ret)
1971 goto out_unlock;
1972
1973 /* Perform the binding */
1974 ret = iwl_mvm_binding_add_vif(mvm, vif);
1975 if (ret)
1976 goto out_remove;
1977
8ca151b5
JB
1978 /* Send the bcast station. At this stage the TBTT and DTIM time events
1979 * are added and applied to the scheduler */
013290aa 1980 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
8ca151b5
JB
1981 if (ret)
1982 goto out_unbind;
1983
5691e218
IP
1984 /* must be set before quota calculations */
1985 mvmvif->ap_ibss_active = true;
1986
a11e144e 1987 /* power updated needs to be done before quotas */
999609f1 1988 iwl_mvm_power_update_mac(mvm);
a11e144e 1989
0166230c 1990 ret = iwl_mvm_update_quotas(mvm, NULL);
8ca151b5 1991 if (ret)
a11e144e 1992 goto out_quota_failed;
8ca151b5 1993
5023d966 1994 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
8ca151b5 1995 if (vif->p2p && mvm->p2p_device_vif)
3dfd3a97 1996 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
8ca151b5 1997
29a90a49
EP
1998 iwl_mvm_ref(mvm, IWL_MVM_REF_AP_IBSS);
1999
8e484f0b 2000 iwl_mvm_bt_coex_vif_change(mvm);
dac94da8 2001
f697267f
AN
2002 /* we don't support TDLS during DCM */
2003 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2004 iwl_mvm_teardown_tdls_peers(mvm);
2005
8ca151b5
JB
2006 mutex_unlock(&mvm->mutex);
2007 return 0;
2008
a11e144e 2009out_quota_failed:
999609f1 2010 iwl_mvm_power_update_mac(mvm);
5691e218 2011 mvmvif->ap_ibss_active = false;
013290aa 2012 iwl_mvm_send_rm_bcast_sta(mvm, vif);
8ca151b5
JB
2013out_unbind:
2014 iwl_mvm_binding_remove_vif(mvm, vif);
2015out_remove:
2016 iwl_mvm_mac_ctxt_remove(mvm, vif);
2017out_unlock:
2018 mutex_unlock(&mvm->mutex);
576eeee9 2019 iwl_mvm_unref(mvm, IWL_MVM_REF_START_AP);
8ca151b5
JB
2020 return ret;
2021}
2022
5023d966
JB
2023static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2024 struct ieee80211_vif *vif)
8ca151b5
JB
2025{
2026 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2027 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2028
38a12b5b
JB
2029 iwl_mvm_prepare_mac_removal(mvm, vif);
2030
8ca151b5
JB
2031 mutex_lock(&mvm->mutex);
2032
664322fa 2033 /* Handle AP stop while in CSA */
7f0a7c67
AO
2034 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2035 iwl_mvm_remove_time_event(mvm, mvmvif,
2036 &mvmvif->time_event_data);
664322fa 2037 RCU_INIT_POINTER(mvm->csa_vif, NULL);
7f0a7c67 2038 }
664322fa 2039
003e5236
AO
2040 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2041 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2042 mvm->csa_tx_block_bcn_timeout = 0;
2043 }
2044
5023d966 2045 mvmvif->ap_ibss_active = false;
1c87bbad 2046 mvm->ap_last_beacon_gp2 = 0;
8ca151b5 2047
8e484f0b 2048 iwl_mvm_bt_coex_vif_change(mvm);
dac94da8 2049
29a90a49
EP
2050 iwl_mvm_unref(mvm, IWL_MVM_REF_AP_IBSS);
2051
5023d966 2052 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
8ca151b5 2053 if (vif->p2p && mvm->p2p_device_vif)
3dfd3a97 2054 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
8ca151b5 2055
0166230c 2056 iwl_mvm_update_quotas(mvm, NULL);
013290aa 2057 iwl_mvm_send_rm_bcast_sta(mvm, vif);
8ca151b5 2058 iwl_mvm_binding_remove_vif(mvm, vif);
a11e144e 2059
999609f1 2060 iwl_mvm_power_update_mac(mvm);
a11e144e 2061
8ca151b5
JB
2062 iwl_mvm_mac_ctxt_remove(mvm, vif);
2063
2064 mutex_unlock(&mvm->mutex);
2065}
2066
5023d966
JB
2067static void
2068iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2069 struct ieee80211_vif *vif,
2070 struct ieee80211_bss_conf *bss_conf,
2071 u32 changes)
8ca151b5 2072{
be2056fc 2073 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8a5e3660 2074
be2056fc
IP
2075 /* Changes will be applied when the AP/IBSS is started */
2076 if (!mvmvif->ap_ibss_active)
2077 return;
2078
863230da 2079 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
f7d8b702 2080 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
3dfd3a97 2081 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
863230da 2082 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
8a5e3660 2083
8ca151b5 2084 /* Need to send a new beacon template to the FW */
863230da
JB
2085 if (changes & BSS_CHANGED_BEACON &&
2086 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2087 IWL_WARN(mvm, "Failed updating beacon data\n");
79b7a69d
HD
2088
2089 if (changes & BSS_CHANGED_TXPOWER) {
2090 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2091 bss_conf->txpower);
2092 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2093 }
2094
8ca151b5
JB
2095}
2096
2097static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2098 struct ieee80211_vif *vif,
2099 struct ieee80211_bss_conf *bss_conf,
2100 u32 changes)
2101{
2102 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2103
576eeee9
EP
2104 /*
2105 * iwl_mvm_bss_info_changed_station() might call
2106 * iwl_mvm_protect_session(), which reads directly from
2107 * the device (the system time), so make sure it is available.
2108 */
2109 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_BSS_CHANGED))
2110 return;
2111
8ca151b5
JB
2112 mutex_lock(&mvm->mutex);
2113
723f02ed 2114 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
fb98be5e 2115 iwl_mvm_scan_offload_stop(mvm, true);
723f02ed 2116
8ca151b5
JB
2117 switch (vif->type) {
2118 case NL80211_IFTYPE_STATION:
2119 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2120 break;
2121 case NL80211_IFTYPE_AP:
5023d966
JB
2122 case NL80211_IFTYPE_ADHOC:
2123 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
8ca151b5
JB
2124 break;
2125 default:
2126 /* shouldn't happen */
2127 WARN_ON_ONCE(1);
2128 }
2129
2130 mutex_unlock(&mvm->mutex);
576eeee9 2131 iwl_mvm_unref(mvm, IWL_MVM_REF_BSS_CHANGED);
8ca151b5
JB
2132}
2133
4660dfbb
EP
2134static int iwl_mvm_cancel_scan_wait_notif(struct iwl_mvm *mvm,
2135 enum iwl_scan_status scan_type)
2136{
2137 int ret;
2138 bool wait_for_handlers = false;
2139
2140 mutex_lock(&mvm->mutex);
2141
2142 if (mvm->scan_status != scan_type) {
2143 ret = 0;
2144 /* make sure there are no pending notifications */
2145 wait_for_handlers = true;
2146 goto out;
2147 }
2148
2149 switch (scan_type) {
2150 case IWL_MVM_SCAN_SCHED:
2151 ret = iwl_mvm_scan_offload_stop(mvm, true);
2152 break;
2153 case IWL_MVM_SCAN_OS:
2154 ret = iwl_mvm_cancel_scan(mvm);
2155 break;
2156 case IWL_MVM_SCAN_NONE:
2157 default:
2158 WARN_ON_ONCE(1);
2159 ret = -EINVAL;
2160 break;
2161 }
2162 if (ret)
2163 goto out;
2164
2165 wait_for_handlers = true;
2166out:
2167 mutex_unlock(&mvm->mutex);
2168
2169 /* make sure we consume the completion notification */
2170 if (wait_for_handlers)
2171 iwl_mvm_wait_for_async_handlers(mvm);
2172
2173 return ret;
2174}
8ca151b5
JB
2175static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2176 struct ieee80211_vif *vif,
c56ef672 2177 struct ieee80211_scan_request *hw_req)
8ca151b5
JB
2178{
2179 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
c56ef672 2180 struct cfg80211_scan_request *req = &hw_req->req;
8ca151b5
JB
2181 int ret;
2182
762533ba
DS
2183 if (req->n_channels == 0 ||
2184 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
8ca151b5
JB
2185 return -EINVAL;
2186
d2496221
DS
2187 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2188 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_SCHED);
2189 if (ret)
2190 return ret;
2191 }
4660dfbb 2192
8ca151b5
JB
2193 mutex_lock(&mvm->mutex);
2194
4660dfbb 2195 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
8ca151b5 2196 ret = -EBUSY;
519e2026
AN
2197 goto out;
2198 }
8ca151b5 2199
519e2026
AN
2200 iwl_mvm_ref(mvm, IWL_MVM_REF_SCAN);
2201
b975e55a 2202 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)
d2496221 2203 ret = iwl_mvm_scan_umac(mvm, vif, hw_req);
fb98be5e 2204 else
1f940386 2205 ret = iwl_mvm_unified_scan_lmac(mvm, vif, hw_req);
fb98be5e 2206
519e2026
AN
2207 if (ret)
2208 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
2209out:
8ca151b5 2210 mutex_unlock(&mvm->mutex);
8ca151b5
JB
2211 return ret;
2212}
2213
2214static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2215 struct ieee80211_vif *vif)
2216{
2217 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2218
2219 mutex_lock(&mvm->mutex);
2220
2221 iwl_mvm_cancel_scan(mvm);
2222
2223 mutex_unlock(&mvm->mutex);
2224}
2225
2226static void
2227iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
3e56eadf 2228 struct ieee80211_sta *sta, u16 tids,
8ca151b5
JB
2229 int num_frames,
2230 enum ieee80211_frame_release_type reason,
2231 bool more_data)
2232{
2233 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
8ca151b5 2234
3e56eadf 2235 /* Called when we need to transmit (a) frame(s) from mac80211 */
8ca151b5 2236
3e56eadf
JB
2237 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2238 tids, more_data, false);
2239}
2240
2241static void
2242iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2243 struct ieee80211_sta *sta, u16 tids,
2244 int num_frames,
2245 enum ieee80211_frame_release_type reason,
2246 bool more_data)
2247{
2248 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2249
2250 /* Called when we need to transmit (a) frame(s) from agg queue */
2251
2252 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2253 tids, more_data, true);
8ca151b5
JB
2254}
2255
2256static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2257 struct ieee80211_vif *vif,
2258 enum sta_notify_cmd cmd,
2259 struct ieee80211_sta *sta)
2260{
2261 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5b577a90 2262 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3e56eadf 2263 int tid;
8ca151b5
JB
2264
2265 switch (cmd) {
2266 case STA_NOTIFY_SLEEP:
e3d4bc8c 2267 if (atomic_read(&mvm->pending_frames[mvmsta->sta_id]) > 0)
8ca151b5 2268 ieee80211_sta_block_awake(hw, sta, true);
3e56eadf
JB
2269 spin_lock_bh(&mvmsta->lock);
2270 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
2271 struct iwl_mvm_tid_data *tid_data;
2272
2273 tid_data = &mvmsta->tid_data[tid];
2274 if (tid_data->state != IWL_AGG_ON &&
2275 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA)
2276 continue;
2277 if (iwl_mvm_tid_queued(tid_data) == 0)
2278 continue;
2279 ieee80211_sta_set_buffered(sta, tid, true);
2280 }
2281 spin_unlock_bh(&mvmsta->lock);
8ca151b5
JB
2282 /*
2283 * The fw updates the STA to be asleep. Tx packets on the Tx
2284 * queues to this station will not be transmitted. The fw will
2285 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2286 */
2287 break;
2288 case STA_NOTIFY_AWAKE:
881acd89 2289 if (WARN_ON(mvmsta->sta_id == IWL_MVM_STATION_COUNT))
8ca151b5 2290 break;
9cc40712 2291 iwl_mvm_sta_modify_ps_wake(mvm, sta);
8ca151b5
JB
2292 break;
2293 default:
2294 break;
2295 }
2296}
2297
1ddbbb0c
JB
2298static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2299 struct ieee80211_vif *vif,
2300 struct ieee80211_sta *sta)
2301{
2302 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
9d8ce6af 2303 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1ddbbb0c
JB
2304
2305 /*
2306 * This is called before mac80211 does RCU synchronisation,
2307 * so here we already invalidate our internal RCU-protected
2308 * station pointer. The rest of the code will thus no longer
2309 * be able to find the station this way, and we don't rely
2310 * on further RCU synchronisation after the sta_state()
2311 * callback deleted the station.
2312 */
2313 mutex_lock(&mvm->mutex);
2314 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2315 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2316 ERR_PTR(-ENOENT));
2317 mutex_unlock(&mvm->mutex);
2318}
2319
bd1ba664
JB
2320static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2321 const u8 *bssid)
2322{
2323 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2324 return;
2325
2326 if (iwlwifi_mod_params.uapsd_disable) {
2327 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2328 return;
2329 }
2330
2331 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2332}
2333
8ca151b5
JB
2334static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
2335 struct ieee80211_vif *vif,
2336 struct ieee80211_sta *sta,
2337 enum ieee80211_sta_state old_state,
2338 enum ieee80211_sta_state new_state)
2339{
2340 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2341 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2342 int ret;
2343
2344 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
2345 sta->addr, old_state, new_state);
2346
2347 /* this would be a mac80211 bug ... but don't crash */
2348 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
2349 return -EINVAL;
2350
2351 /* if a STA is being removed, reuse its ID */
2352 flush_work(&mvm->sta_drained_wk);
2353
2354 mutex_lock(&mvm->mutex);
2355 if (old_state == IEEE80211_STA_NOTEXIST &&
2356 new_state == IEEE80211_STA_NONE) {
48bc1307
JB
2357 /*
2358 * Firmware bug - it'll crash if the beacon interval is less
2359 * than 16. We can't avoid connecting at all, so refuse the
2360 * station state change, this will cause mac80211 to abandon
2361 * attempts to connect to this AP, and eventually wpa_s will
2362 * blacklist the AP...
2363 */
2364 if (vif->type == NL80211_IFTYPE_STATION &&
2365 vif->bss_conf.beacon_int < 16) {
2366 IWL_ERR(mvm,
2367 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
2368 sta->addr, vif->bss_conf.beacon_int);
2369 ret = -EINVAL;
2370 goto out_unlock;
2371 }
cf7b491d
AN
2372
2373 if (sta->tdls &&
2374 (vif->p2p ||
fa3d07e4
AN
2375 iwl_mvm_tdls_sta_count(mvm, NULL) ==
2376 IWL_MVM_TDLS_STA_COUNT ||
cf7b491d
AN
2377 iwl_mvm_phy_ctx_count(mvm) > 1)) {
2378 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
2379 ret = -EBUSY;
2380 goto out_unlock;
2381 }
2382
8ca151b5 2383 ret = iwl_mvm_add_sta(mvm, vif, sta);
fa3d07e4
AN
2384 if (sta->tdls && ret == 0)
2385 iwl_mvm_recalc_tdls_state(mvm, vif, true);
8ca151b5
JB
2386 } else if (old_state == IEEE80211_STA_NONE &&
2387 new_state == IEEE80211_STA_AUTH) {
e820c2da
HD
2388 /*
2389 * EBS may be disabled due to previous failures reported by FW.
2390 * Reset EBS status here assuming environment has been changed.
2391 */
2392 mvm->last_ebs_successful = true;
bd1ba664 2393 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
8ca151b5
JB
2394 ret = 0;
2395 } else if (old_state == IEEE80211_STA_AUTH &&
2396 new_state == IEEE80211_STA_ASSOC) {
7a453973
JB
2397 ret = iwl_mvm_update_sta(mvm, vif, sta);
2398 if (ret == 0)
2399 iwl_mvm_rs_rate_init(mvm, sta,
b87c2179
ES
2400 mvmvif->phy_ctxt->channel->band,
2401 true);
8ca151b5
JB
2402 } else if (old_state == IEEE80211_STA_ASSOC &&
2403 new_state == IEEE80211_STA_AUTHORIZED) {
f59e0e3c
AN
2404
2405 /* we don't support TDLS during DCM */
2406 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2407 iwl_mvm_teardown_tdls_peers(mvm);
2408
7df15b1e 2409 /* enable beacon filtering */
fa7b2e7f 2410 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
8ca151b5
JB
2411 ret = 0;
2412 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
2413 new_state == IEEE80211_STA_ASSOC) {
7df15b1e 2414 /* disable beacon filtering */
a1022927 2415 WARN_ON(iwl_mvm_disable_beacon_filter(mvm, vif, 0));
8ca151b5
JB
2416 ret = 0;
2417 } else if (old_state == IEEE80211_STA_ASSOC &&
2418 new_state == IEEE80211_STA_AUTH) {
2419 ret = 0;
2420 } else if (old_state == IEEE80211_STA_AUTH &&
2421 new_state == IEEE80211_STA_NONE) {
2422 ret = 0;
2423 } else if (old_state == IEEE80211_STA_NONE &&
2424 new_state == IEEE80211_STA_NOTEXIST) {
2425 ret = iwl_mvm_rm_sta(mvm, vif, sta);
fa3d07e4
AN
2426 if (sta->tdls)
2427 iwl_mvm_recalc_tdls_state(mvm, vif, false);
8ca151b5
JB
2428 } else {
2429 ret = -EIO;
2430 }
48bc1307 2431 out_unlock:
8ca151b5
JB
2432 mutex_unlock(&mvm->mutex);
2433
9c126cd6
LK
2434 if (sta->tdls && ret == 0) {
2435 if (old_state == IEEE80211_STA_NOTEXIST &&
2436 new_state == IEEE80211_STA_NONE)
2437 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2438 else if (old_state == IEEE80211_STA_NONE &&
2439 new_state == IEEE80211_STA_NOTEXIST)
2440 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
2441 }
2442
8ca151b5
JB
2443 return ret;
2444}
2445
2446static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2447{
2448 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2449
2450 mvm->rts_threshold = value;
2451
2452 return 0;
2453}
2454
1f3b0ff8
LE
2455static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
2456 struct ieee80211_vif *vif,
2457 struct ieee80211_sta *sta, u32 changed)
2458{
2459 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2460
2461 if (vif->type == NL80211_IFTYPE_STATION &&
2462 changed & IEEE80211_RC_NSS_CHANGED)
2463 iwl_mvm_sf_update(mvm, vif, false);
2464}
2465
8ca151b5
JB
2466static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
2467 struct ieee80211_vif *vif, u16 ac,
2468 const struct ieee80211_tx_queue_params *params)
2469{
2470 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2471 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2472
2473 mvmvif->queue_params[ac] = *params;
2474
2475 /*
2476 * No need to update right away, we'll get BSS_CHANGED_QOS
2477 * The exception is P2P_DEVICE interface which needs immediate update.
2478 */
2479 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2480 int ret;
2481
2482 mutex_lock(&mvm->mutex);
3dfd3a97 2483 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
8ca151b5
JB
2484 mutex_unlock(&mvm->mutex);
2485 return ret;
2486 }
2487 return 0;
2488}
2489
2490static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
2491 struct ieee80211_vif *vif)
2492{
2493 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2494 u32 duration = min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS,
2495 200 + vif->bss_conf.beacon_int);
2496 u32 min_duration = min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS,
2497 100 + vif->bss_conf.beacon_int);
2498
2499 if (WARN_ON_ONCE(vif->bss_conf.assoc))
2500 return;
2501
576eeee9
EP
2502 /*
2503 * iwl_mvm_protect_session() reads directly from the device
2504 * (the system time), so make sure it is available.
2505 */
2506 if (iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PREPARE_TX))
2507 return;
2508
8ca151b5
JB
2509 mutex_lock(&mvm->mutex);
2510 /* Try really hard to protect the session and hear a beacon */
d20d37bc 2511 iwl_mvm_protect_session(mvm, vif, duration, min_duration, 500, false);
8ca151b5 2512 mutex_unlock(&mvm->mutex);
576eeee9
EP
2513
2514 iwl_mvm_unref(mvm, IWL_MVM_REF_PREPARE_TX);
8ca151b5
JB
2515}
2516
35a000b7
DS
2517static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
2518 struct ieee80211_vif *vif,
2519 struct cfg80211_sched_scan_request *req,
633e2713 2520 struct ieee80211_scan_ies *ies)
35a000b7
DS
2521{
2522 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2523 int ret;
2524
d2496221
DS
2525 if (!(mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
2526 ret = iwl_mvm_cancel_scan_wait_notif(mvm, IWL_MVM_SCAN_OS);
2527 if (ret)
2528 return ret;
2529 }
4660dfbb 2530
35a000b7
DS
2531 mutex_lock(&mvm->mutex);
2532
1f940386 2533 if (!vif->bss_conf.idle) {
bd5e4744
DS
2534 ret = -EBUSY;
2535 goto out;
2536 }
2537
4660dfbb 2538 if (mvm->scan_status != IWL_MVM_SCAN_NONE) {
35a000b7
DS
2539 ret = -EBUSY;
2540 goto out;
2541 }
2542
b141c235 2543 ret = iwl_mvm_scan_offload_start(mvm, vif, req, ies);
35a000b7 2544 if (ret)
b141c235 2545 mvm->scan_status = IWL_MVM_SCAN_NONE;
d2496221 2546
35a000b7
DS
2547out:
2548 mutex_unlock(&mvm->mutex);
2549 return ret;
2550}
2551
37e3308c
JB
2552static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
2553 struct ieee80211_vif *vif)
35a000b7
DS
2554{
2555 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
33ea27f6 2556 int ret;
35a000b7
DS
2557
2558 mutex_lock(&mvm->mutex);
fb98be5e 2559 ret = iwl_mvm_scan_offload_stop(mvm, false);
35a000b7 2560 mutex_unlock(&mvm->mutex);
33ea27f6 2561 iwl_mvm_wait_for_async_handlers(mvm);
37e3308c 2562
33ea27f6 2563 return ret;
d2496221 2564
35a000b7
DS
2565}
2566
8ca151b5
JB
2567static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
2568 enum set_key_cmd cmd,
2569 struct ieee80211_vif *vif,
2570 struct ieee80211_sta *sta,
2571 struct ieee80211_key_conf *key)
2572{
2573 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2574 int ret;
2575
2576 if (iwlwifi_mod_params.sw_crypto) {
2577 IWL_DEBUG_MAC80211(mvm, "leave - hwcrypto disabled\n");
2578 return -EOPNOTSUPP;
2579 }
2580
2581 switch (key->cipher) {
2582 case WLAN_CIPHER_SUITE_TKIP:
2583 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
2584 /* fall-through */
2585 case WLAN_CIPHER_SUITE_CCMP:
2586 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2587 break;
2588 case WLAN_CIPHER_SUITE_AES_CMAC:
2589 WARN_ON_ONCE(!(hw->flags & IEEE80211_HW_MFP_CAPABLE));
2590 break;
2591 case WLAN_CIPHER_SUITE_WEP40:
2592 case WLAN_CIPHER_SUITE_WEP104:
ba3943b0
JB
2593 /* For non-client mode, only use WEP keys for TX as we probably
2594 * don't have a station yet anyway and would then have to keep
2595 * track of the keys, linking them to each of the clients/peers
2596 * as they appear. For now, don't do that, for performance WEP
2597 * offload doesn't really matter much, but we need it for some
2598 * other offload features in client mode.
8ca151b5 2599 */
ba3943b0
JB
2600 if (vif->type != NL80211_IFTYPE_STATION)
2601 return 0;
2602 break;
8ca151b5 2603 default:
e36e5433
MS
2604 /* currently FW supports only one optional cipher scheme */
2605 if (hw->n_cipher_schemes &&
2606 hw->cipher_schemes->cipher == key->cipher)
2607 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
2608 else
2609 return -EOPNOTSUPP;
8ca151b5
JB
2610 }
2611
2612 mutex_lock(&mvm->mutex);
2613
2614 switch (cmd) {
2615 case SET_KEY:
5023d966
JB
2616 if ((vif->type == NL80211_IFTYPE_ADHOC ||
2617 vif->type == NL80211_IFTYPE_AP) && !sta) {
2618 /*
2619 * GTK on AP interface is a TX-only key, return 0;
2620 * on IBSS they're per-station and because we're lazy
2621 * we don't support them for RX, so do the same.
2622 */
6caffd4f
JB
2623 ret = 0;
2624 key->hw_key_idx = STA_KEY_IDX_INVALID;
2625 break;
2626 }
2627
8ca151b5
JB
2628 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
2629 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, false);
2630 if (ret) {
2631 IWL_WARN(mvm, "set key failed\n");
2632 /*
2633 * can't add key for RX, but we don't need it
2634 * in the device for TX so still return 0
2635 */
6caffd4f 2636 key->hw_key_idx = STA_KEY_IDX_INVALID;
8ca151b5
JB
2637 ret = 0;
2638 }
2639
2640 break;
2641 case DISABLE_KEY:
6caffd4f
JB
2642 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
2643 ret = 0;
2644 break;
2645 }
2646
8ca151b5
JB
2647 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
2648 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
2649 break;
2650 default:
2651 ret = -EINVAL;
2652 }
2653
2654 mutex_unlock(&mvm->mutex);
2655 return ret;
2656}
2657
2658static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
2659 struct ieee80211_vif *vif,
2660 struct ieee80211_key_conf *keyconf,
2661 struct ieee80211_sta *sta,
2662 u32 iv32, u16 *phase1key)
2663{
2664 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2665
5023d966
JB
2666 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
2667 return;
2668
8ca151b5
JB
2669 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
2670}
2671
2672
b112889c
AM
2673static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
2674 struct iwl_rx_packet *pkt, void *data)
2675{
2676 struct iwl_mvm *mvm =
2677 container_of(notif_wait, struct iwl_mvm, notif_wait);
2678 struct iwl_hs20_roc_res *resp;
2679 int resp_len = iwl_rx_packet_payload_len(pkt);
2680 struct iwl_mvm_time_event_data *te_data = data;
2681
2682 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
2683 return true;
2684
2685 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
2686 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
2687 return true;
2688 }
2689
2690 resp = (void *)pkt->data;
2691
2692 IWL_DEBUG_TE(mvm,
2693 "Aux ROC: Recieved response from ucode: status=%d uid=%d\n",
2694 resp->status, resp->event_unique_id);
2695
2696 te_data->uid = le32_to_cpu(resp->event_unique_id);
2697 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
2698 te_data->uid);
2699
2700 spin_lock_bh(&mvm->time_event_lock);
2701 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
2702 spin_unlock_bh(&mvm->time_event_lock);
2703
2704 return true;
2705}
2706
2707#define AUX_ROC_MAX_DELAY_ON_CHANNEL 5000
2708static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
2709 struct ieee80211_channel *channel,
2710 struct ieee80211_vif *vif,
2711 int duration)
2712{
2713 int res, time_reg = DEVICE_SYSTEM_TIME_REG;
2714 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2715 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
2716 static const u8 time_event_response[] = { HOT_SPOT_CMD };
2717 struct iwl_notification_wait wait_time_event;
2718 struct iwl_hs20_roc_req aux_roc_req = {
2719 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
2720 .id_and_color =
2721 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
2722 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
2723 /* Set the channel info data */
2724 .channel_info.band = (channel->band == IEEE80211_BAND_2GHZ) ?
2725 PHY_BAND_24 : PHY_BAND_5,
2726 .channel_info.channel = channel->hw_value,
2727 .channel_info.width = PHY_VHT_CHANNEL_MODE20,
2728 /* Set the time and duration */
2729 .apply_time = cpu_to_le32(iwl_read_prph(mvm->trans, time_reg)),
2730 .apply_time_max_delay =
2731 cpu_to_le32(MSEC_TO_TU(AUX_ROC_MAX_DELAY_ON_CHANNEL)),
2732 .duration = cpu_to_le32(MSEC_TO_TU(duration)),
2733 };
2734
2735 /* Set the node address */
2736 memcpy(aux_roc_req.node_addr, vif->addr, ETH_ALEN);
2737
a6cc5163
MG
2738 lockdep_assert_held(&mvm->mutex);
2739
2740 spin_lock_bh(&mvm->time_event_lock);
2741
2742 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
2743 spin_unlock_bh(&mvm->time_event_lock);
2744 return -EIO;
2745 }
2746
b112889c
AM
2747 te_data->vif = vif;
2748 te_data->duration = duration;
2749 te_data->id = HOT_SPOT_CMD;
2750
b112889c
AM
2751 spin_unlock_bh(&mvm->time_event_lock);
2752
2753 /*
2754 * Use a notification wait, which really just processes the
2755 * command response and doesn't wait for anything, in order
2756 * to be able to process the response and get the UID inside
2757 * the RX path. Using CMD_WANT_SKB doesn't work because it
2758 * stores the buffer and then wakes up this thread, by which
2759 * time another notification (that the time event started)
2760 * might already be processed unsuccessfully.
2761 */
2762 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
2763 time_event_response,
2764 ARRAY_SIZE(time_event_response),
2765 iwl_mvm_rx_aux_roc, te_data);
2766
2767 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, sizeof(aux_roc_req),
2768 &aux_roc_req);
2769
2770 if (res) {
2771 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
2772 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
2773 goto out_clear_te;
2774 }
2775
2776 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
2777 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
2778 /* should never fail */
2779 WARN_ON_ONCE(res);
2780
2781 if (res) {
2782 out_clear_te:
2783 spin_lock_bh(&mvm->time_event_lock);
2784 iwl_mvm_te_clear_data(mvm, te_data);
2785 spin_unlock_bh(&mvm->time_event_lock);
2786 }
2787
2788 return res;
2789}
2790
8ca151b5
JB
2791static int iwl_mvm_roc(struct ieee80211_hw *hw,
2792 struct ieee80211_vif *vif,
2793 struct ieee80211_channel *channel,
d339d5ca
IP
2794 int duration,
2795 enum ieee80211_roc_type type)
8ca151b5
JB
2796{
2797 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3 2798 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8ca151b5 2799 struct cfg80211_chan_def chandef;
31d385ae
IP
2800 struct iwl_mvm_phy_ctxt *phy_ctxt;
2801 int ret, i;
2802
2803 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
2804 duration, type);
8ca151b5 2805
a6cc5163
MG
2806 mutex_lock(&mvm->mutex);
2807
b112889c
AM
2808 switch (vif->type) {
2809 case NL80211_IFTYPE_STATION:
5ac6c72e
LC
2810 if (mvm->fw->ucode_capa.capa[0] &
2811 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT) {
2812 /* Use aux roc framework (HS20) */
2813 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
2814 vif, duration);
2815 goto out_unlock;
2816 }
2817 IWL_ERR(mvm, "hotspot not supported\n");
2818 ret = -EINVAL;
a6cc5163 2819 goto out_unlock;
b112889c
AM
2820 case NL80211_IFTYPE_P2P_DEVICE:
2821 /* handle below */
2822 break;
2823 default:
2824 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
a6cc5163
MG
2825 ret = -EINVAL;
2826 goto out_unlock;
8ca151b5
JB
2827 }
2828
31d385ae
IP
2829 for (i = 0; i < NUM_PHY_CTX; i++) {
2830 phy_ctxt = &mvm->phy_ctxts[i];
2831 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
2832 continue;
2833
2834 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
2835 /*
2836 * Unbind the P2P_DEVICE from the current PHY context,
2837 * and if the PHY context is not used remove it.
2838 */
2839 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2840 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2841 goto out_unlock;
2842
2843 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2844
2845 /* Bind the P2P_DEVICE to the current PHY Context */
2846 mvmvif->phy_ctxt = phy_ctxt;
2847
2848 ret = iwl_mvm_binding_add_vif(mvm, vif);
2849 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2850 goto out_unlock;
2851
2852 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2853 goto schedule_time_event;
2854 }
2855 }
2856
2857 /* Need to update the PHY context only if the ROC channel changed */
2858 if (channel == mvmvif->phy_ctxt->channel)
2859 goto schedule_time_event;
2860
8ca151b5 2861 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
8ca151b5 2862
31d385ae
IP
2863 /*
2864 * Change the PHY context configuration as it is currently referenced
2865 * only by the P2P Device MAC
2866 */
2867 if (mvmvif->phy_ctxt->ref == 1) {
2868 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
2869 &chandef, 1, 1);
2870 if (ret)
2871 goto out_unlock;
2872 } else {
2873 /*
2874 * The PHY context is shared with other MACs. Need to remove the
2875 * P2P Device from the binding, allocate an new PHY context and
2876 * create a new binding
2877 */
2878 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2879 if (!phy_ctxt) {
2880 ret = -ENOSPC;
2881 goto out_unlock;
2882 }
2883
2884 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
2885 1, 1);
2886 if (ret) {
2887 IWL_ERR(mvm, "Failed to change PHY context\n");
2888 goto out_unlock;
2889 }
2890
2891 /* Unbind the P2P_DEVICE from the current PHY context */
2892 ret = iwl_mvm_binding_remove_vif(mvm, vif);
2893 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
2894 goto out_unlock;
2895
2896 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
2897
2898 /* Bind the P2P_DEVICE to the new allocated PHY context */
2899 mvmvif->phy_ctxt = phy_ctxt;
2900
2901 ret = iwl_mvm_binding_add_vif(mvm, vif);
2902 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
2903 goto out_unlock;
2904
2905 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
2906 }
2907
2908schedule_time_event:
8ca151b5 2909 /* Schedule the time events */
e635c797 2910 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
8ca151b5 2911
31d385ae 2912out_unlock:
8ca151b5
JB
2913 mutex_unlock(&mvm->mutex);
2914 IWL_DEBUG_MAC80211(mvm, "leave\n");
8ca151b5
JB
2915 return ret;
2916}
2917
2918static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw)
2919{
2920 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2921
2922 IWL_DEBUG_MAC80211(mvm, "enter\n");
2923
2924 mutex_lock(&mvm->mutex);
bf5da87f 2925 iwl_mvm_stop_roc(mvm);
8ca151b5
JB
2926 mutex_unlock(&mvm->mutex);
2927
2928 IWL_DEBUG_MAC80211(mvm, "leave\n");
2929 return 0;
2930}
2931
b08c1d97
LC
2932static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
2933 struct ieee80211_chanctx_conf *ctx)
8ca151b5 2934{
fe0f2de3
IP
2935 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2936 struct iwl_mvm_phy_ctxt *phy_ctxt;
8ca151b5
JB
2937 int ret;
2938
b08c1d97
LC
2939 lockdep_assert_held(&mvm->mutex);
2940
53a9d61e 2941 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
fe0f2de3 2942
fe0f2de3
IP
2943 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
2944 if (!phy_ctxt) {
2945 ret = -ENOSPC;
2946 goto out;
2947 }
8ca151b5 2948
dcbc3e1a 2949 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
53a9d61e
IP
2950 ctx->rx_chains_static,
2951 ctx->rx_chains_dynamic);
fe0f2de3
IP
2952 if (ret) {
2953 IWL_ERR(mvm, "Failed to add PHY context\n");
2954 goto out;
2955 }
2956
53a9d61e 2957 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
fe0f2de3
IP
2958 *phy_ctxt_id = phy_ctxt->id;
2959out:
b08c1d97
LC
2960 return ret;
2961}
2962
2963static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
2964 struct ieee80211_chanctx_conf *ctx)
2965{
2966 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2967 int ret;
2968
2969 mutex_lock(&mvm->mutex);
2970 ret = __iwl_mvm_add_chanctx(mvm, ctx);
8ca151b5 2971 mutex_unlock(&mvm->mutex);
b08c1d97 2972
8ca151b5
JB
2973 return ret;
2974}
2975
b08c1d97
LC
2976static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
2977 struct ieee80211_chanctx_conf *ctx)
2978{
2979 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
2980 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
2981
2982 lockdep_assert_held(&mvm->mutex);
2983
2984 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
2985}
2986
8ca151b5
JB
2987static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
2988 struct ieee80211_chanctx_conf *ctx)
2989{
2990 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
8ca151b5
JB
2991
2992 mutex_lock(&mvm->mutex);
b08c1d97 2993 __iwl_mvm_remove_chanctx(mvm, ctx);
8ca151b5
JB
2994 mutex_unlock(&mvm->mutex);
2995}
2996
2997static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
2998 struct ieee80211_chanctx_conf *ctx,
2999 u32 changed)
3000{
3001 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
3002 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3003 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
8ca151b5 3004
31d385ae
IP
3005 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3006 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
3007 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
2dceedae
AN
3008 IEEE80211_CHANCTX_CHANGE_RADAR |
3009 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
31d385ae
IP
3010 "Cannot change PHY. Ref=%d, changed=0x%X\n",
3011 phy_ctxt->ref, changed))
3012 return;
3013
8ca151b5 3014 mutex_lock(&mvm->mutex);
4d66449a 3015 iwl_mvm_bt_coex_vif_change(mvm);
dcbc3e1a 3016 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &ctx->min_def,
8ca151b5
JB
3017 ctx->rx_chains_static,
3018 ctx->rx_chains_dynamic);
3019 mutex_unlock(&mvm->mutex);
3020}
3021
b08c1d97
LC
3022static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
3023 struct ieee80211_vif *vif,
f0c97783
LC
3024 struct ieee80211_chanctx_conf *ctx,
3025 bool switching_chanctx)
8ca151b5 3026{
fe0f2de3
IP
3027 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3028 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
8ca151b5
JB
3029 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3030 int ret;
3031
b08c1d97 3032 lockdep_assert_held(&mvm->mutex);
8ca151b5 3033
fe0f2de3 3034 mvmvif->phy_ctxt = phy_ctxt;
8ca151b5
JB
3035
3036 switch (vif->type) {
3037 case NL80211_IFTYPE_AP:
4741dd04
LC
3038 /* only needed if we're switching chanctx (i.e. during CSA) */
3039 if (switching_chanctx) {
bd3398e2
AO
3040 mvmvif->ap_ibss_active = true;
3041 break;
3042 }
5023d966 3043 case NL80211_IFTYPE_ADHOC:
8ca151b5
JB
3044 /*
3045 * The AP binding flow is handled as part of the start_ap flow
5023d966 3046 * (in bss_info_changed), similarly for IBSS.
8ca151b5
JB
3047 */
3048 ret = 0;
b08c1d97 3049 goto out;
8ca151b5 3050 case NL80211_IFTYPE_STATION:
2533edce 3051 break;
8ca151b5 3052 case NL80211_IFTYPE_MONITOR:
2533edce
LC
3053 /* always disable PS when a monitor interface is active */
3054 mvmvif->ps_disabled = true;
8ca151b5
JB
3055 break;
3056 default:
3057 ret = -EINVAL;
b08c1d97 3058 goto out;
8ca151b5
JB
3059 }
3060
3061 ret = iwl_mvm_binding_add_vif(mvm, vif);
3062 if (ret)
b08c1d97 3063 goto out;
8ca151b5
JB
3064
3065 /*
92d85562
AB
3066 * Power state must be updated before quotas,
3067 * otherwise fw will complain.
3068 */
999609f1 3069 iwl_mvm_power_update_mac(mvm);
92d85562
AB
3070
3071 /* Setting the quota at this stage is only required for monitor
8ca151b5
JB
3072 * interfaces. For the other types, the bss_info changed flow
3073 * will handle quota settings.
3074 */
3075 if (vif->type == NL80211_IFTYPE_MONITOR) {
1e1391ca 3076 mvmvif->monitor_active = true;
0166230c 3077 ret = iwl_mvm_update_quotas(mvm, NULL);
8ca151b5
JB
3078 if (ret)
3079 goto out_remove_binding;
3080 }
3081
bd3398e2 3082 /* Handle binding during CSA */
a57c688d 3083 if (vif->type == NL80211_IFTYPE_AP) {
0166230c 3084 iwl_mvm_update_quotas(mvm, NULL);
3dfd3a97 3085 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
bd3398e2
AO
3086 }
3087
4741dd04 3088 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
686e7fe1
LC
3089 u32 duration = 2 * vif->bss_conf.beacon_int;
3090
3091 /* iwl_mvm_protect_session() reads directly from the
3092 * device (the system time), so make sure it is
3093 * available.
3094 */
3095 ret = iwl_mvm_ref_sync(mvm, IWL_MVM_REF_PROTECT_CSA);
3096 if (ret)
3097 goto out_remove_binding;
3098
3099 /* Protect the session to make sure we hear the first
3100 * beacon on the new channel.
3101 */
3102 iwl_mvm_protect_session(mvm, vif, duration, duration,
3103 vif->bss_conf.beacon_int / 2,
3104 true);
3105
3106 iwl_mvm_unref(mvm, IWL_MVM_REF_PROTECT_CSA);
3107
a57c688d 3108 iwl_mvm_update_quotas(mvm, NULL);
0ce04ce7
LC
3109 }
3110
b08c1d97 3111 goto out;
8ca151b5 3112
b08c1d97 3113out_remove_binding:
8ca151b5 3114 iwl_mvm_binding_remove_vif(mvm, vif);
999609f1 3115 iwl_mvm_power_update_mac(mvm);
b08c1d97 3116out:
8ca151b5
JB
3117 if (ret)
3118 mvmvif->phy_ctxt = NULL;
3119 return ret;
3120}
b08c1d97
LC
3121static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
3122 struct ieee80211_vif *vif,
3123 struct ieee80211_chanctx_conf *ctx)
8ca151b5
JB
3124{
3125 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
b08c1d97 3126 int ret;
8ca151b5
JB
3127
3128 mutex_lock(&mvm->mutex);
f0c97783 3129 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
b08c1d97
LC
3130 mutex_unlock(&mvm->mutex);
3131
3132 return ret;
3133}
3134
3135static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
3136 struct ieee80211_vif *vif,
f0c97783
LC
3137 struct ieee80211_chanctx_conf *ctx,
3138 bool switching_chanctx)
b08c1d97
LC
3139{
3140 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
f0c97783 3141 struct ieee80211_vif *disabled_vif = NULL;
b08c1d97
LC
3142
3143 lockdep_assert_held(&mvm->mutex);
8ca151b5
JB
3144
3145 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
3146
8ca151b5 3147 switch (vif->type) {
5023d966 3148 case NL80211_IFTYPE_ADHOC:
b08c1d97 3149 goto out;
8ca151b5 3150 case NL80211_IFTYPE_MONITOR:
1e1391ca 3151 mvmvif->monitor_active = false;
2533edce 3152 mvmvif->ps_disabled = false;
8ca151b5 3153 break;
bd3398e2
AO
3154 case NL80211_IFTYPE_AP:
3155 /* This part is triggered only during CSA */
4741dd04 3156 if (!switching_chanctx || !mvmvif->ap_ibss_active)
b08c1d97 3157 goto out;
bd3398e2 3158
7ef0aab6
AO
3159 mvmvif->csa_countdown = false;
3160
003e5236
AO
3161 /* Set CS bit on all the stations */
3162 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
3163
3164 /* Save blocked iface, the timeout is set on the next beacon */
3165 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
3166
bd3398e2 3167 mvmvif->ap_ibss_active = false;
f0c97783
LC
3168 break;
3169 case NL80211_IFTYPE_STATION:
3170 if (!switching_chanctx)
3171 break;
3172
3173 disabled_vif = vif;
3174
3dfd3a97 3175 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
f0c97783 3176 break;
8ca151b5
JB
3177 default:
3178 break;
3179 }
3180
f0c97783 3181 iwl_mvm_update_quotas(mvm, disabled_vif);
1e1391ca 3182 iwl_mvm_binding_remove_vif(mvm, vif);
1c2abf72 3183
b08c1d97 3184out:
a11e144e 3185 mvmvif->phy_ctxt = NULL;
999609f1 3186 iwl_mvm_power_update_mac(mvm);
b08c1d97
LC
3187}
3188
3189static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
3190 struct ieee80211_vif *vif,
3191 struct ieee80211_chanctx_conf *ctx)
3192{
3193 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3194
3195 mutex_lock(&mvm->mutex);
f0c97783 3196 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
8ca151b5
JB
3197 mutex_unlock(&mvm->mutex);
3198}
3199
50cc9574
LC
3200static int
3201iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
3202 struct ieee80211_vif_chanctx_switch *vifs)
b08c1d97 3203{
b08c1d97
LC
3204 int ret;
3205
b08c1d97 3206 mutex_lock(&mvm->mutex);
f0c97783 3207 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
b08c1d97
LC
3208 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
3209
3210 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
3211 if (ret) {
3212 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
3213 goto out_reassign;
3214 }
3215
f0c97783
LC
3216 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3217 true);
b08c1d97
LC
3218 if (ret) {
3219 IWL_ERR(mvm,
3220 "failed to assign new_ctx during channel switch\n");
3221 goto out_remove;
3222 }
3223
f697267f
AN
3224 /* we don't support TDLS during DCM - can be caused by channel switch */
3225 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3226 iwl_mvm_teardown_tdls_peers(mvm);
3227
b08c1d97
LC
3228 goto out;
3229
3230out_remove:
3231 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
3232
3233out_reassign:
6fd1fb63 3234 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
b08c1d97
LC
3235 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
3236 goto out_restart;
3237 }
3238
6fd1fb63
LC
3239 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3240 true)) {
b08c1d97
LC
3241 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3242 goto out_restart;
3243 }
3244
3245 goto out;
3246
3247out_restart:
3248 /* things keep failing, better restart the hw */
3249 iwl_mvm_nic_restart(mvm, false);
3250
3251out:
3252 mutex_unlock(&mvm->mutex);
50cc9574
LC
3253
3254 return ret;
3255}
3256
48a256e8
LC
3257static int
3258iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
3259 struct ieee80211_vif_chanctx_switch *vifs)
3260{
3261 int ret;
3262
3263 mutex_lock(&mvm->mutex);
3264 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
3265
3266 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
3267 true);
3268 if (ret) {
3269 IWL_ERR(mvm,
3270 "failed to assign new_ctx during channel switch\n");
3271 goto out_reassign;
3272 }
3273
3274 goto out;
3275
3276out_reassign:
3277 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
3278 true)) {
3279 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
3280 goto out_restart;
3281 }
3282
3283 goto out;
3284
3285out_restart:
3286 /* things keep failing, better restart the hw */
3287 iwl_mvm_nic_restart(mvm, false);
3288
3289out:
3290 mutex_unlock(&mvm->mutex);
3291
3292 return ret;
3293}
3294
50cc9574
LC
3295static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
3296 struct ieee80211_vif_chanctx_switch *vifs,
3297 int n_vifs,
3298 enum ieee80211_chanctx_switch_mode mode)
3299{
3300 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3301 int ret;
3302
3303 /* we only support a single-vif right now */
3304 if (n_vifs > 1)
3305 return -EOPNOTSUPP;
3306
3307 switch (mode) {
3308 case CHANCTX_SWMODE_SWAP_CONTEXTS:
3309 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
3310 break;
3311 case CHANCTX_SWMODE_REASSIGN_VIF:
48a256e8 3312 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
50cc9574
LC
3313 break;
3314 default:
3315 ret = -EOPNOTSUPP;
3316 break;
3317 }
3318
b08c1d97
LC
3319 return ret;
3320}
3321
8ca151b5
JB
3322static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
3323 struct ieee80211_sta *sta,
3324 bool set)
3325{
3326 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
9d8ce6af 3327 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
8ca151b5
JB
3328
3329 if (!mvm_sta || !mvm_sta->vif) {
3330 IWL_ERR(mvm, "Station is not associated to a vif\n");
3331 return -EINVAL;
3332 }
3333
3334 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
3335}
3336
507cadf2
DS
3337#ifdef CONFIG_NL80211_TESTMODE
3338static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
3339 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
3340 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
f6c6ad42 3341 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
507cadf2
DS
3342};
3343
3344static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
3345 struct ieee80211_vif *vif,
3346 void *data, int len)
3347{
3348 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
3349 int err;
3350 u32 noa_duration;
3351
3352 err = nla_parse(tb, IWL_MVM_TM_ATTR_MAX, data, len, iwl_mvm_tm_policy);
3353 if (err)
3354 return err;
3355
3356 if (!tb[IWL_MVM_TM_ATTR_CMD])
3357 return -EINVAL;
3358
3359 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
3360 case IWL_MVM_TM_CMD_SET_NOA:
3361 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
3362 !vif->bss_conf.enable_beacon ||
3363 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
3364 return -EINVAL;
3365
3366 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
3367 if (noa_duration >= vif->bss_conf.beacon_int)
3368 return -EINVAL;
3369
3370 mvm->noa_duration = noa_duration;
3371 mvm->noa_vif = vif;
3372
0166230c 3373 return iwl_mvm_update_quotas(mvm, NULL);
f6c6ad42
JB
3374 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
3375 /* must be associated client vif - ignore authorized */
3376 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
3377 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
3378 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
3379 return -EINVAL;
3380
3381 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
a1022927
EG
3382 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3383 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
507cadf2
DS
3384 }
3385
3386 return -EOPNOTSUPP;
3387}
3388
3389static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
3390 struct ieee80211_vif *vif,
3391 void *data, int len)
3392{
3393 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3394 int err;
3395
3396 mutex_lock(&mvm->mutex);
3397 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
3398 mutex_unlock(&mvm->mutex);
3399
3400 return err;
3401}
3402#endif
3403
622e3f9b
LC
3404static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
3405 struct ieee80211_vif *vif,
3406 struct ieee80211_channel_switch *chsw)
3407{
3408 /* By implementing this operation, we prevent mac80211 from
3409 * starting its own channel switch timer, so that we can call
3410 * ieee80211_chswitch_done() ourselves at the right time
3411 * (which is when the absence time event starts).
3412 */
3413
3414 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
3415 "dummy channel switch op\n");
3416}
3417
f028905c
LC
3418static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
3419 struct ieee80211_vif *vif,
3420 struct ieee80211_channel_switch *chsw)
bd3398e2
AO
3421{
3422 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
664322fa 3423 struct ieee80211_vif *csa_vif;
f6c34820 3424 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
dc88b4ba 3425 u32 apply_time;
f028905c 3426 int ret;
bd3398e2
AO
3427
3428 mutex_lock(&mvm->mutex);
664322fa 3429
6b20d774 3430 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
f028905c 3431 chsw->chandef.center_freq1);
6b20d774
LC
3432
3433 switch (vif->type) {
3434 case NL80211_IFTYPE_AP:
3435 csa_vif =
3436 rcu_dereference_protected(mvm->csa_vif,
3437 lockdep_is_held(&mvm->mutex));
3438 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
3439 "Another CSA is already in progress")) {
3440 ret = -EBUSY;
3441 goto out_unlock;
3442 }
3443
3444 rcu_assign_pointer(mvm->csa_vif, vif);
7ef0aab6 3445
7ef0aab6
AO
3446 if (WARN_ONCE(mvmvif->csa_countdown,
3447 "Previous CSA countdown didn't complete")) {
3448 ret = -EBUSY;
3449 goto out_unlock;
3450 }
3451
6b20d774 3452 break;
dc88b4ba 3453 case NL80211_IFTYPE_STATION:
4500e133
LC
3454 /* Schedule the time event to a bit before beacon 1,
3455 * to make sure we're in the new channel when the
3456 * GO/AP arrives.
3457 */
3458 apply_time = chsw->device_timestamp +
3459 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
3460 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
dc88b4ba
LC
3461
3462 if (chsw->block_tx)
3463 iwl_mvm_csa_client_absent(mvm, vif);
3464
4500e133 3465 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
dc88b4ba 3466 apply_time);
c6e0a3e0
LC
3467 if (mvmvif->bf_data.bf_enabled) {
3468 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3469 if (ret)
3470 goto out_unlock;
3471 }
3472
dc88b4ba 3473 break;
6b20d774
LC
3474 default:
3475 break;
3476 }
bd3398e2 3477
f6c34820
LC
3478 mvmvif->ps_disabled = true;
3479
3480 ret = iwl_mvm_power_update_ps(mvm);
3481 if (ret)
3482 goto out_unlock;
f028905c 3483
e198f5e7
AN
3484 /* we won't be on this channel any longer */
3485 iwl_mvm_teardown_tdls_peers(mvm);
3486
bd3398e2
AO
3487out_unlock:
3488 mutex_unlock(&mvm->mutex);
f028905c
LC
3489
3490 return ret;
bd3398e2
AO
3491}
3492
f6c34820
LC
3493static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
3494 struct ieee80211_vif *vif)
3495{
3496 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3497 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3498 int ret;
3499
3500 mutex_lock(&mvm->mutex);
3501
a57c688d
LC
3502 if (vif->type == NL80211_IFTYPE_STATION) {
3503 struct iwl_mvm_sta *mvmsta;
3504
3505 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
3506 mvmvif->ap_sta_id);
3507
3508 if (WARN_ON(!mvmsta)) {
3509 ret = -EIO;
3510 goto out_unlock;
3511 }
3512
3513 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
3514
3515 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
c6e0a3e0
LC
3516
3517 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
3518 if (ret)
3519 goto out_unlock;
686e7fe1
LC
3520
3521 iwl_mvm_stop_session_protection(mvm, vif);
a57c688d
LC
3522 }
3523
f6c34820
LC
3524 mvmvif->ps_disabled = false;
3525
3526 ret = iwl_mvm_power_update_ps(mvm);
3527
a57c688d 3528out_unlock:
f6c34820
LC
3529 mutex_unlock(&mvm->mutex);
3530
3531 return ret;
3532}
3533
c5b0e7c0
EG
3534static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
3535 struct ieee80211_vif *vif, u32 queues, bool drop)
3536{
3537 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3538 struct iwl_mvm_vif *mvmvif;
3539 struct iwl_mvm_sta *mvmsta;
a0f6bf2a
AN
3540 struct ieee80211_sta *sta;
3541 int i;
3542 u32 msk = 0;
c5b0e7c0
EG
3543
3544 if (!vif || vif->type != NL80211_IFTYPE_STATION)
3545 return;
3546
3547 mutex_lock(&mvm->mutex);
3548 mvmvif = iwl_mvm_vif_from_mac80211(vif);
c5b0e7c0 3549
a0f6bf2a
AN
3550 /* flush the AP-station and all TDLS peers */
3551 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
3552 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3553 lockdep_is_held(&mvm->mutex));
3554 if (IS_ERR_OR_NULL(sta))
3555 continue;
3556
3557 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3558 if (mvmsta->vif != vif)
3559 continue;
3560
3561 /* make sure only TDLS peers or the AP are flushed */
3562 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
3563
3564 msk |= mvmsta->tfd_queue_msk;
480acbce 3565 }
c5b0e7c0 3566
6d440b25
EG
3567 if (drop) {
3568 if (iwl_mvm_flush_tx_path(mvm, msk, true))
3569 IWL_ERR(mvm, "flush request fail\n");
3570 mutex_unlock(&mvm->mutex);
3571 } else {
3572 mutex_unlock(&mvm->mutex);
4e6c48e0 3573
6d440b25
EG
3574 /* this can take a while, and we may need/want other operations
3575 * to succeed while doing this, so do it without the mutex held
3576 */
3577 iwl_trans_wait_tx_queue_empty(mvm->trans, msk);
3578 }
c5b0e7c0
EG
3579}
3580
91a8bcde
JB
3581static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
3582 struct survey_info *survey)
3583{
3584 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3585 int ret;
3586
3587 memset(survey, 0, sizeof(*survey));
3588
3589 /* only support global statistics right now */
3590 if (idx != 0)
3591 return -ENOENT;
3592
3593 if (!(mvm->fw->ucode_capa.capa[0] &
3594 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
3595 return -ENOENT;
3596
3597 mutex_lock(&mvm->mutex);
3598
3599 if (mvm->ucode_loaded) {
3600 ret = iwl_mvm_request_statistics(mvm);
3601 if (ret)
3602 goto out;
3603 }
3604
3605 survey->filled = SURVEY_INFO_TIME |
3606 SURVEY_INFO_TIME_RX |
3607 SURVEY_INFO_TIME_TX |
3608 SURVEY_INFO_TIME_SCAN;
3609 survey->time = mvm->accu_radio_stats.on_time_rf +
3610 mvm->radio_stats.on_time_rf;
3611 do_div(survey->time, USEC_PER_MSEC);
3612
3613 survey->time_rx = mvm->accu_radio_stats.rx_time +
3614 mvm->radio_stats.rx_time;
3615 do_div(survey->time_rx, USEC_PER_MSEC);
3616
3617 survey->time_tx = mvm->accu_radio_stats.tx_time +
3618 mvm->radio_stats.tx_time;
3619 do_div(survey->time_tx, USEC_PER_MSEC);
3620
3621 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
3622 mvm->radio_stats.on_time_scan;
3623 do_div(survey->time_scan, USEC_PER_MSEC);
3624
3625 out:
3626 mutex_unlock(&mvm->mutex);
3627 return ret;
3628}
3629
e5209263 3630const struct ieee80211_ops iwl_mvm_hw_ops = {
8ca151b5
JB
3631 .tx = iwl_mvm_mac_tx,
3632 .ampdu_action = iwl_mvm_mac_ampdu_action,
3633 .start = iwl_mvm_mac_start,
cf2c92d8 3634 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
8ca151b5
JB
3635 .stop = iwl_mvm_mac_stop,
3636 .add_interface = iwl_mvm_mac_add_interface,
3637 .remove_interface = iwl_mvm_mac_remove_interface,
3638 .config = iwl_mvm_mac_config,
e59647ea 3639 .prepare_multicast = iwl_mvm_prepare_multicast,
8ca151b5
JB
3640 .configure_filter = iwl_mvm_configure_filter,
3641 .bss_info_changed = iwl_mvm_bss_info_changed,
3642 .hw_scan = iwl_mvm_mac_hw_scan,
3643 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1ddbbb0c 3644 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
8ca151b5
JB
3645 .sta_state = iwl_mvm_mac_sta_state,
3646 .sta_notify = iwl_mvm_mac_sta_notify,
3647 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
3e56eadf 3648 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
8ca151b5 3649 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1f3b0ff8 3650 .sta_rc_update = iwl_mvm_sta_rc_update,
8ca151b5
JB
3651 .conf_tx = iwl_mvm_mac_conf_tx,
3652 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
07ecd897 3653 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
c5b0e7c0 3654 .flush = iwl_mvm_mac_flush,
35a000b7
DS
3655 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
3656 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
8ca151b5
JB
3657 .set_key = iwl_mvm_mac_set_key,
3658 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
3659 .remain_on_channel = iwl_mvm_roc,
3660 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
8ca151b5
JB
3661 .add_chanctx = iwl_mvm_add_chanctx,
3662 .remove_chanctx = iwl_mvm_remove_chanctx,
3663 .change_chanctx = iwl_mvm_change_chanctx,
3664 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
3665 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
b08c1d97 3666 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
8ca151b5 3667
5023d966
JB
3668 .start_ap = iwl_mvm_start_ap_ibss,
3669 .stop_ap = iwl_mvm_stop_ap_ibss,
3670 .join_ibss = iwl_mvm_start_ap_ibss,
3671 .leave_ibss = iwl_mvm_stop_ap_ibss,
8ca151b5
JB
3672
3673 .set_tim = iwl_mvm_set_tim,
3674
622e3f9b 3675 .channel_switch = iwl_mvm_channel_switch,
f028905c 3676 .pre_channel_switch = iwl_mvm_pre_channel_switch,
f6c34820 3677 .post_channel_switch = iwl_mvm_post_channel_switch,
bd3398e2 3678
1d3c3f63
AN
3679 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
3680 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
3681 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
3682
507cadf2
DS
3683 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
3684
8ca151b5
JB
3685#ifdef CONFIG_PM_SLEEP
3686 /* look at d3.c */
3687 .suspend = iwl_mvm_suspend,
3688 .resume = iwl_mvm_resume,
3689 .set_wakeup = iwl_mvm_set_wakeup,
3690 .set_rekey_data = iwl_mvm_set_rekey_data,
3691#if IS_ENABLED(CONFIG_IPV6)
3692 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
3693#endif
3694 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
3695#endif
91a8bcde 3696 .get_survey = iwl_mvm_mac_get_survey,
8ca151b5 3697};
This page took 0.373457 seconds and 5 git commands to generate.