iwlwifi: dbg: treat dbgc allocation failure when tlv is missing
[linux-block.git] / drivers / net / wireless / intel / iwlwifi / mvm / mac80211.c
CommitLineData
8e99ea8d
JB
1// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2/*
3 * Copyright (C) 2012-2014, 2018-2020 Intel Corporation
4 * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5 * Copyright (C) 2016-2017 Intel Deutschland GmbH
6 */
8ca151b5
JB
7#include <linux/kernel.h>
8#include <linux/slab.h>
9#include <linux/skbuff.h>
10#include <linux/netdevice.h>
11#include <linux/etherdevice.h>
f0c2646a 12#include <linux/ip.h>
2ee8f021 13#include <linux/if_arp.h>
2f89a5d7 14#include <linux/time.h>
8ca151b5 15#include <net/mac80211.h>
7b1dd048 16#include <net/ieee80211_radiotap.h>
f0c2646a 17#include <net/tcp.h>
8ca151b5
JB
18
19#include "iwl-op-mode.h"
20#include "iwl-io.h"
21#include "mvm.h"
22#include "sta.h"
23#include "time-event.h"
24#include "iwl-eeprom-parse.h"
8ca151b5 25#include "iwl-phy-db.h"
507cadf2 26#include "testmode.h"
d962f9b1 27#include "fw/error-dump.h"
655e6d6d 28#include "iwl-prph.h"
88931cc9 29#include "iwl-nvm-parse.h"
8ca151b5
JB
30
31static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
32 {
33 .max = 1,
8eb38710 34 .types = BIT(NL80211_IFTYPE_STATION),
8ca151b5 35 },
3c15a0fb
JB
36 {
37 .max = 1,
8eb38710
IP
38 .types = BIT(NL80211_IFTYPE_AP) |
39 BIT(NL80211_IFTYPE_P2P_CLIENT) |
3c15a0fb
JB
40 BIT(NL80211_IFTYPE_P2P_GO),
41 },
42 {
43 .max = 1,
44 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
45 },
8ca151b5
JB
46};
47
48static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
49 {
2624a5ca 50 .num_different_channels = 2,
8ca151b5
JB
51 .max_interfaces = 3,
52 .limits = iwl_mvm_limits,
53 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
54 },
55};
56
77736923 57#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
2ee8f021
EP
58/*
59 * Use the reserved field to indicate magic values.
60 * these values will only be used internally by the driver,
61 * and won't make it to the fw (reserved will be 0).
62 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
63 * be the vif's ip address. in case there is not a single
64 * ip address (0, or more than 1), this attribute will
65 * be skipped.
66 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
67 * the LSB bytes of the vif's mac address
68 */
69enum {
70 BC_FILTER_MAGIC_NONE = 0,
71 BC_FILTER_MAGIC_IP,
72 BC_FILTER_MAGIC_MAC,
73};
74
77736923
EP
75static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
76 {
77 /* arp */
78 .discard = 0,
79 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
80 .attrs = {
81 {
82 /* frame type - arp, hw type - ethernet */
83 .offset_type =
84 BCAST_FILTER_OFFSET_PAYLOAD_START,
85 .offset = sizeof(rfc1042_header),
86 .val = cpu_to_be32(0x08060001),
87 .mask = cpu_to_be32(0xffffffff),
88 },
2ee8f021
EP
89 {
90 /* arp dest ip */
91 .offset_type =
92 BCAST_FILTER_OFFSET_PAYLOAD_START,
93 .offset = sizeof(rfc1042_header) + 2 +
94 sizeof(struct arphdr) +
95 ETH_ALEN + sizeof(__be32) +
96 ETH_ALEN,
97 .mask = cpu_to_be32(0xffffffff),
98 /* mark it as special field */
99 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
100 },
101 },
102 },
103 {
104 /* dhcp offer bcast */
105 .discard = 0,
106 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
107 .attrs = {
108 {
109 /* udp dest port - 68 (bootp client)*/
110 .offset_type = BCAST_FILTER_OFFSET_IP_END,
111 .offset = offsetof(struct udphdr, dest),
112 .val = cpu_to_be32(0x00440000),
113 .mask = cpu_to_be32(0xffff0000),
114 },
115 {
116 /* dhcp - lsb bytes of client hw address */
117 .offset_type = BCAST_FILTER_OFFSET_IP_END,
118 .offset = 38,
119 .mask = cpu_to_be32(0xffffffff),
120 /* mark it as special field */
121 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
122 },
77736923
EP
123 },
124 },
125 /* last filter must be empty */
126 {},
127};
128#endif
129
fc36ffda
JB
130static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa = {
131 .max_peers = IWL_MVM_TOF_MAX_APS,
132 .report_ap_tsf = 1,
133 .randomize_mac_addr = 1,
134
135 .ftm = {
136 .supported = 1,
137 .asap = 1,
138 .non_asap = 1,
139 .request_lci = 1,
140 .request_civicloc = 1,
6815e3d0
AS
141 .trigger_based = 1,
142 .non_trigger_based = 1,
fc36ffda
JB
143 .max_bursts_exponent = -1, /* all supported */
144 .max_ftms_per_burst = 0, /* no limits */
145 .bandwidths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
146 BIT(NL80211_CHAN_WIDTH_20) |
147 BIT(NL80211_CHAN_WIDTH_40) |
8a2c1516
AS
148 BIT(NL80211_CHAN_WIDTH_80) |
149 BIT(NL80211_CHAN_WIDTH_160),
fc36ffda
JB
150 .preambles = BIT(NL80211_PREAMBLE_LEGACY) |
151 BIT(NL80211_PREAMBLE_HT) |
6815e3d0
AS
152 BIT(NL80211_PREAMBLE_VHT) |
153 BIT(NL80211_PREAMBLE_HE),
fc36ffda
JB
154 },
155};
156
6569e7d3
JB
157static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
158 enum set_key_cmd cmd,
159 struct ieee80211_vif *vif,
160 struct ieee80211_sta *sta,
161 struct ieee80211_key_conf *key);
c56e00a3 162
fe0f2de3
IP
163static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
164{
165 int i;
166
167 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
168 for (i = 0; i < NUM_PHY_CTX; i++) {
169 mvm->phy_ctxts[i].id = i;
170 mvm->phy_ctxts[i].ref = 0;
171 }
172}
173
88931cc9 174struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
8ba2d7a1 175 const char *alpha2,
47c8b154
JD
176 enum iwl_mcc_source src_id,
177 bool *changed)
88931cc9
AN
178{
179 struct ieee80211_regdomain *regd = NULL;
180 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
181 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
182 struct iwl_mcc_update_resp *resp;
e27c506a 183 u8 resp_ver;
88931cc9
AN
184
185 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
186
8ba2d7a1 187 lockdep_assert_held(&mvm->mutex);
88931cc9 188
8ba2d7a1 189 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
88931cc9
AN
190 if (IS_ERR_OR_NULL(resp)) {
191 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
b8c474d9 192 PTR_ERR_OR_ZERO(resp));
8ba2d7a1 193 goto out;
88931cc9
AN
194 }
195
82715ac7
EG
196 if (changed) {
197 u32 status = le32_to_cpu(resp->status);
198
199 *changed = (status == MCC_RESP_NEW_CHAN_PROFILE ||
200 status == MCC_RESP_ILLEGAL);
201 }
e27c506a
GA
202 resp_ver = iwl_fw_lookup_notif_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP,
203 MCC_UPDATE_CMD, 0);
204 IWL_DEBUG_LAR(mvm, "MCC update response version: %d\n", resp_ver);
47c8b154 205
162ee3c9 206 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
88931cc9
AN
207 __le32_to_cpu(resp->n_channels),
208 resp->channels,
77e30e10 209 __le16_to_cpu(resp->mcc),
2763bba6 210 __le16_to_cpu(resp->geo_info),
e27c506a 211 __le16_to_cpu(resp->cap), resp_ver);
8ba2d7a1
EH
212 /* Store the return source id */
213 src_id = resp->source_id;
88931cc9
AN
214 kfree(resp);
215 if (IS_ERR_OR_NULL(regd)) {
216 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
b8c474d9 217 PTR_ERR_OR_ZERO(regd));
8ba2d7a1 218 goto out;
88931cc9
AN
219 }
220
8ba2d7a1
EH
221 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
222 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
88931cc9 223 mvm->lar_regdom_set = true;
8ba2d7a1 224 mvm->mcc_src = src_id;
88931cc9 225
8ba2d7a1 226out:
88931cc9
AN
227 return regd;
228}
229
47c8b154
JD
230void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
231{
232 bool changed;
233 struct ieee80211_regdomain *regd;
234
235 if (!iwl_mvm_is_lar_supported(mvm))
236 return;
237
238 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
239 if (!IS_ERR_OR_NULL(regd)) {
240 /* only update the regulatory core if changed */
241 if (changed)
242 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
243
244 kfree(regd);
245 }
246}
247
248struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
249 bool *changed)
8ba2d7a1
EH
250{
251 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
252 iwl_mvm_is_wifi_mcc_supported(mvm) ?
253 MCC_SOURCE_GET_CURRENT :
47c8b154 254 MCC_SOURCE_OLD_FW, changed);
8ba2d7a1
EH
255}
256
257int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
258{
259 enum iwl_mcc_source used_src;
260 struct ieee80211_regdomain *regd;
b6e160ab
AN
261 int ret;
262 bool changed;
8ba2d7a1 263 const struct ieee80211_regdomain *r =
a05829a7 264 wiphy_dereference(mvm->hw->wiphy, mvm->hw->wiphy->regd);
8ba2d7a1
EH
265
266 if (!r)
b6e160ab 267 return -ENOENT;
8ba2d7a1
EH
268
269 /* save the last source in case we overwrite it below */
270 used_src = mvm->mcc_src;
271 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
272 /* Notify the firmware we support wifi location updates */
47c8b154 273 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
8ba2d7a1
EH
274 if (!IS_ERR_OR_NULL(regd))
275 kfree(regd);
276 }
277
278 /* Now set our last stored MCC and source */
b6e160ab
AN
279 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
280 &changed);
8ba2d7a1
EH
281 if (IS_ERR_OR_NULL(regd))
282 return -EIO;
283
b6e160ab
AN
284 /* update cfg80211 if the regdomain was changed */
285 if (changed)
a05829a7 286 ret = regulatory_set_wiphy_regd_sync(mvm->hw->wiphy, regd);
b6e160ab
AN
287 else
288 ret = 0;
8ba2d7a1 289
b6e160ab
AN
290 kfree(regd);
291 return ret;
8ba2d7a1
EH
292}
293
7f2ea521 294static const u8 he_if_types_ext_capa_sta[] = {
7360f99e 295 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
918cbf39 296 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
7360f99e
EG
297 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
298 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
299};
300
7f2ea521 301static const struct wiphy_iftype_ext_capab he_iftypes_ext_capa[] = {
7360f99e
EG
302 {
303 .iftype = NL80211_IFTYPE_STATION,
304 .extended_capabilities = he_if_types_ext_capa_sta,
305 .extended_capabilities_mask = he_if_types_ext_capa_sta,
306 .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta),
307 },
308};
309
e8503aec
BG
310static int
311iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
312{
313 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
314 *tx_ant = iwl_mvm_get_valid_tx_ant(mvm);
315 *rx_ant = iwl_mvm_get_valid_rx_ant(mvm);
316 return 0;
317}
318
8ca151b5
JB
319int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
320{
321 struct ieee80211_hw *hw = mvm->hw;
831e85f3 322 int num_mac, ret, i;
5f4c02e2
JB
323 static const u32 mvm_ciphers[] = {
324 WLAN_CIPHER_SUITE_WEP40,
325 WLAN_CIPHER_SUITE_WEP104,
326 WLAN_CIPHER_SUITE_TKIP,
327 WLAN_CIPHER_SUITE_CCMP,
328 };
3f37c229
IY
329#ifdef CONFIG_PM_SLEEP
330 bool unified = fw_has_capa(&mvm->fw->ucode_capa,
331 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
332#endif
8ca151b5
JB
333
334 /* Tell mac80211 our characteristics */
30686bf7
JB
335 ieee80211_hw_set(hw, SIGNAL_DBM);
336 ieee80211_hw_set(hw, SPECTRUM_MGMT);
337 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
30686bf7
JB
338 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
339 ieee80211_hw_set(hw, SUPPORTS_PS);
340 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
341 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
342 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
343 ieee80211_hw_set(hw, CONNECTION_MONITOR);
344 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
345 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
346 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
909ddf0b 347 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
30433d3b 348 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
d270e7b8 349 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
520229e4 350 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
cfbc6c4c
SS
351 ieee80211_hw_set(hw, BUFF_MMPDU_TXQ);
352 ieee80211_hw_set(hw, STA_MMPDU_TXQ);
cfb21b11
JB
353 /*
354 * On older devices, enabling TX A-MSDU occasionally leads to
355 * something getting messed up, the command read from the FIFO
356 * gets out of sync and isn't a TX command, so that we have an
357 * assert EDC.
358 *
359 * It's not clear where the bug is, but since we didn't used to
360 * support A-MSDU until moving the mac80211 iTXQs, just leave it
361 * for older devices. We also don't see this issue on any newer
362 * devices.
363 */
7d34a7d7 364 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000)
cfb21b11 365 ieee80211_hw_set(hw, TX_AMSDU);
438af969 366 ieee80211_hw_set(hw, TX_FRAG_LIST);
ecaf71de 367
4243edb4 368 if (iwl_mvm_has_tlc_offload(mvm)) {
ecaf71de
GG
369 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
370 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
371 }
372
b915c101
SS
373 if (iwl_mvm_has_new_rx_api(mvm))
374 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
960f864b
JB
375
376 if (fw_has_capa(&mvm->fw->ucode_capa,
377 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
65e25482 378 ieee80211_hw_set(hw, AP_LINK_PS);
960f864b
JB
379 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
380 /*
381 * we absolutely need this for the new TX API since that comes
382 * with many more queues than the current code can deal with
383 * for station powersave
384 */
385 return -EINVAL;
386 }
8ca151b5 387
80938abc
JB
388 if (mvm->trans->num_rx_queues > 1)
389 ieee80211_hw_set(hw, USES_RSS);
390
2d7cf549
JB
391 if (mvm->trans->max_skb_frags)
392 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
393
366fc672 394 hw->queues = IEEE80211_NUM_ACS;
398e8c6c 395 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
7b1dd048
EG
396 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
397 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
339b3086
ES
398 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
399 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
371a17ed
JB
400
401 hw->radiotap_timestamp.units_pos =
402 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
403 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
404 /* this is the case for CCK frames, it's better (only 8) for OFDM */
405 hw->radiotap_timestamp.accuracy = 22;
406
4243edb4 407 if (!iwl_mvm_has_tlc_offload(mvm))
9f66a397
GG
408 hw->rate_control_algorithm = RS_NAME;
409
848955cc
JB
410 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
411 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
438af969 412 hw->max_tx_fragments = mvm->trans->max_skb_frags;
8ca151b5 413
8e160ab8 414 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
5f4c02e2
JB
415 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
416 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
417 hw->wiphy->cipher_suites = mvm->ciphers;
418
2a53d166
AB
419 if (iwl_mvm_has_new_rx_api(mvm)) {
420 mvm->ciphers[hw->wiphy->n_cipher_suites] =
421 WLAN_CIPHER_SUITE_GCMP;
422 hw->wiphy->n_cipher_suites++;
423 mvm->ciphers[hw->wiphy->n_cipher_suites] =
424 WLAN_CIPHER_SUITE_GCMP_256;
425 hw->wiphy->n_cipher_suites++;
426 }
427
f4bfdc5e
EG
428 if (iwlwifi_mod_params.swcrypto)
429 IWL_ERR(mvm,
430 "iwlmvm doesn't allow to disable HW crypto, check swcrypto module parameter\n");
431 if (!iwlwifi_mod_params.bt_coex_active)
432 IWL_ERR(mvm,
433 "iwlmvm doesn't allow to disable BT Coex, check bt_coex_active module parameter\n");
434
435 ieee80211_hw_set(hw, MFP_CAPABLE);
436 mvm->ciphers[hw->wiphy->n_cipher_suites] = WLAN_CIPHER_SUITE_AES_CMAC;
437 hw->wiphy->n_cipher_suites++;
438 if (iwl_mvm_has_new_rx_api(mvm)) {
5f4c02e2 439 mvm->ciphers[hw->wiphy->n_cipher_suites] =
f4bfdc5e
EG
440 WLAN_CIPHER_SUITE_BIP_GMAC_128;
441 hw->wiphy->n_cipher_suites++;
442 mvm->ciphers[hw->wiphy->n_cipher_suites] =
443 WLAN_CIPHER_SUITE_BIP_GMAC_256;
5f4c02e2
JB
444 hw->wiphy->n_cipher_suites++;
445 }
446
447 /* currently FW API supports only one optional cipher scheme */
448 if (mvm->fw->cs[0].cipher) {
24ddddf3
JB
449 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
450 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
451
5f4c02e2 452 mvm->hw->n_cipher_schemes = 1;
24ddddf3
JB
453
454 cs->cipher = le32_to_cpu(fwcs->cipher);
455 cs->iftype = BIT(NL80211_IFTYPE_STATION);
456 cs->hdr_len = fwcs->hdr_len;
457 cs->pn_len = fwcs->pn_len;
458 cs->pn_off = fwcs->pn_off;
459 cs->key_idx_off = fwcs->key_idx_off;
460 cs->key_idx_mask = fwcs->key_idx_mask;
461 cs->key_idx_shift = fwcs->key_idx_shift;
462 cs->mic_len = fwcs->mic_len;
463
464 mvm->hw->cipher_schemes = mvm->cs;
465 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
5f4c02e2
JB
466 hw->wiphy->n_cipher_suites++;
467 }
8ca151b5 468
b73f9a4a 469 if (fw_has_capa(&mvm->fw->ucode_capa,
fc36ffda 470 IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) {
b73f9a4a
JB
471 wiphy_ext_feature_set(hw->wiphy,
472 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
fc36ffda
JB
473 hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa;
474 }
b73f9a4a 475
b1fdc250
JB
476 if (fw_has_capa(&mvm->fw->ucode_capa,
477 IWL_UCODE_TLV_CAPA_BIGTK_SUPPORT))
478 wiphy_ext_feature_set(hw->wiphy,
479 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT);
480
30686bf7 481 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
1f940386
LC
482 hw->wiphy->features |=
483 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
3db93420
JB
484 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
485 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
fb98be5e 486
8ca151b5
JB
487 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
488 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
fe0f2de3 489 hw->chanctx_data_size = sizeof(u16);
cfbc6c4c 490 hw->txq_data_size = sizeof(struct iwl_mvm_txq);
8ca151b5
JB
491
492 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3c15a0fb
JB
493 BIT(NL80211_IFTYPE_P2P_CLIENT) |
494 BIT(NL80211_IFTYPE_AP) |
495 BIT(NL80211_IFTYPE_P2P_GO) |
c13b1725
EG
496 BIT(NL80211_IFTYPE_P2P_DEVICE) |
497 BIT(NL80211_IFTYPE_ADHOC);
5023d966 498
a2f73b6c 499 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
e47df5bd 500 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
33e3fd99
AW
501
502 /* The new Tx API does not allow to pass the key or keyid of a MPDU to
503 * the hw, preventing us to control which key(id) to use per MPDU.
504 * Till that's fixed we can't use Extended Key ID for the newer cards.
505 */
506 if (!iwl_mvm_has_new_tx_api(mvm))
507 wiphy_ext_feature_set(hw->wiphy,
508 NL80211_EXT_FEATURE_EXT_KEY_ID);
e47df5bd
JB
509 hw->wiphy->features |= NL80211_FEATURE_HT_IBSS;
510
8ba2d7a1
EH
511 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
512 if (iwl_mvm_is_lar_supported(mvm))
513 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
514 else
515 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
516 REGULATORY_DISABLE_BEACON_HINTS;
8ca151b5 517
4b87e5af 518 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
94bbed72 519 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
eae94cf8 520 hw->wiphy->flags |= WIPHY_FLAG_SPLIT_SCAN_6GHZ;
bd3398e2 521
8ca151b5
JB
522 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
523 hw->wiphy->n_iface_combinations =
524 ARRAY_SIZE(iwl_mvm_iface_combinations);
525
c451e6d4 526 hw->wiphy->max_remain_on_channel_duration = 10000;
8ca151b5
JB
527 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
528
529 /* Extract MAC address */
530 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
531 hw->wiphy->addresses = mvm->addresses;
532 hw->wiphy->n_addresses = 1;
831e85f3
IP
533
534 /* Extract additional MAC addresses if available */
535 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
536 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
537
538 for (i = 1; i < num_mac; i++) {
539 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
8ca151b5 540 ETH_ALEN);
831e85f3 541 mvm->addresses[i].addr[5]++;
8ca151b5
JB
542 hw->wiphy->n_addresses++;
543 }
544
fe0f2de3
IP
545 iwl_mvm_reset_phy_ctxts(mvm);
546
999d2568 547 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
20f1a5de 548
8ca151b5
JB
549 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
550
c7d42480 551 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
507e4cda
LC
552 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
553 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
554
859d914c 555 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
507e4cda
LC
556 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
557 else
558 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
559
57fbcce3
JB
560 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
561 hw->wiphy->bands[NL80211_BAND_2GHZ] =
562 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
563 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
564 hw->wiphy->bands[NL80211_BAND_5GHZ] =
565 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
8ca151b5 566
859d914c
JB
567 if (fw_has_capa(&mvm->fw->ucode_capa,
568 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
569 fw_has_api(&mvm->fw->ucode_capa,
570 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
57fbcce3 571 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
3d44eebf
ES
572 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
573 }
eae94cf8
LC
574 if (fw_has_capa(&mvm->fw->ucode_capa,
575 IWL_UCODE_TLV_CAPA_PSC_CHAN_SUPPORT) &&
576 mvm->nvm_data->bands[NL80211_BAND_6GHZ].n_channels)
577 hw->wiphy->bands[NL80211_BAND_6GHZ] =
578 &mvm->nvm_data->bands[NL80211_BAND_6GHZ];
3d44eebf 579
8ca151b5
JB
580 hw->wiphy->hw_version = mvm->trans->hw_id;
581
ade50652 582 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
8ca151b5
JB
583 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
584 else
585 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
586
ca986ad9 587 hw->wiphy->max_sched_scan_reqs = 1;
9954b37c 588 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
5d1234ba 589 hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw);
9954b37c
EG
590 /* we create the 802.11 header and zero length SSID IE. */
591 hw->wiphy->max_sched_scan_ie_len =
592 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
cd55ccea
AS
593 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
594 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
595
596 /*
597 * the firmware uses u8 for num of iterations, but 0xff is saved for
598 * infinite loop, so the maximum number of iterations is actually 254.
599 */
600 hw->wiphy->max_sched_scan_plan_iterations = 254;
35a000b7 601
8ca151b5 602 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
ab480030 603 NL80211_FEATURE_LOW_PRIORITY_SCAN |
0d8614b4 604 NL80211_FEATURE_P2P_GO_OPPPS |
a904a08b 605 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
0d8614b4 606 NL80211_FEATURE_DYNAMIC_SMPS |
9b5452fd
EG
607 NL80211_FEATURE_STATIC_SMPS |
608 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
8ca151b5 609
859d914c
JB
610 if (fw_has_capa(&mvm->fw->ucode_capa,
611 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
f1daa00e 612 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
859d914c
JB
613 if (fw_has_capa(&mvm->fw->ucode_capa,
614 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
226bcd48 615 hw->wiphy->features |= NL80211_FEATURE_QUIET;
f1daa00e 616
859d914c
JB
617 if (fw_has_capa(&mvm->fw->ucode_capa,
618 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
73897bd1
AO
619 hw->wiphy->features |=
620 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
621
859d914c
JB
622 if (fw_has_capa(&mvm->fw->ucode_capa,
623 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
73897bd1
AO
624 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
625
2a42aea7
NE
626 if (iwl_fw_lookup_cmd_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP,
627 WOWLAN_KEK_KCK_MATERIAL,
628 IWL_FW_CMD_VER_UNKNOWN) == 3)
629 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK;
630
aacf8f18
AS
631 if (fw_has_api(&mvm->fw->ucode_capa,
632 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
633 wiphy_ext_feature_set(hw->wiphy,
634 NL80211_EXT_FEATURE_SCAN_START_TIME);
635 wiphy_ext_feature_set(hw->wiphy,
636 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
aacf8f18
AS
637 }
638
8f691af9
ZR
639 if (iwl_mvm_is_oce_supported(mvm)) {
640 wiphy_ext_feature_set(hw->wiphy,
641 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
642 wiphy_ext_feature_set(hw->wiphy,
643 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
644 wiphy_ext_feature_set(hw->wiphy,
645 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
646 wiphy_ext_feature_set(hw->wiphy,
647 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
648 }
649
7360f99e
EG
650 if (mvm->nvm_data->sku_cap_11ax_enable &&
651 !iwlwifi_mod_params.disable_11ax) {
652 hw->wiphy->iftype_ext_capab = he_iftypes_ext_capa;
653 hw->wiphy->num_iftype_ext_capab =
654 ARRAY_SIZE(he_iftypes_ext_capa);
918cbf39
SS
655
656 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
657 ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID);
7360f99e
EG
658 }
659
8ca151b5
JB
660 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
661
662#ifdef CONFIG_PM_SLEEP
3f37c229 663 if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) &&
8ca151b5
JB
664 mvm->trans->ops->d3_suspend &&
665 mvm->trans->ops->d3_resume &&
666 device_can_wakeup(mvm->trans->dev)) {
91742449
EP
667 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
668 WIPHY_WOWLAN_DISCONNECT |
669 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
670 WIPHY_WOWLAN_RFKILL_RELEASE |
671 WIPHY_WOWLAN_NET_DETECT;
f4bfdc5e
EG
672 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
673 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
674 WIPHY_WOWLAN_4WAY_HANDSHAKE;
964dc9e2
JB
675
676 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
677 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
678 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
5d1234ba
TM
679 mvm->wowlan.max_nd_match_sets =
680 iwl_umac_scan_get_max_profiles(mvm->fw);
964dc9e2 681 hw->wiphy->wowlan = &mvm->wowlan;
8ca151b5
JB
682 }
683#endif
684
77736923
EP
685#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
686 /* assign default bcast filtering configuration */
687 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
688#endif
689
8ca151b5
JB
690 ret = iwl_mvm_leds_init(mvm);
691 if (ret)
692 return ret;
693
859d914c
JB
694 if (fw_has_capa(&mvm->fw->ucode_capa,
695 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
d8f1c515
AN
696 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
697 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
7c4f0843 698 ieee80211_hw_set(hw, TDLS_WIDER_BW);
d8f1c515
AN
699 }
700
859d914c
JB
701 if (fw_has_capa(&mvm->fw->ucode_capa,
702 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
1d3c3f63
AN
703 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
704 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
705 }
706
93190fb0 707 hw->netdev_features |= mvm->cfg->features;
59fa61f3 708 if (!iwl_mvm_is_csum_supported(mvm))
5e6a98dc
SS
709 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
710 NETIF_F_RXCSUM);
41837ca9 711
91b08c2d
AE
712 if (mvm->cfg->vht_mu_mimo_supported)
713 wiphy_ext_feature_set(hw->wiphy,
714 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
715
9c11d8a9
ST
716 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT))
717 wiphy_ext_feature_set(hw->wiphy,
718 NL80211_EXT_FEATURE_PROTECTED_TWT);
719
e8503aec
BG
720 hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm);
721 hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm);
722
de645e89
JB
723 ret = ieee80211_register_hw(mvm->hw);
724 if (ret) {
725 iwl_mvm_leds_exit(mvm);
de645e89
JB
726 }
727
b7327d89 728 return ret;
8ca151b5
JB
729}
730
df2378ab
JB
731static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
732 struct ieee80211_sta *sta)
733{
734 if (likely(sta)) {
735 if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0))
736 return;
737 } else {
738 if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0))
739 return;
740 }
741
742 ieee80211_free_txskb(mvm->hw, skb);
743}
744
8ca151b5
JB
745static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
746 struct ieee80211_tx_control *control,
747 struct sk_buff *skb)
748{
749 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3e56eadf
JB
750 struct ieee80211_sta *sta = control->sta;
751 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
752 struct ieee80211_hdr *hdr = (void *)skb->data;
cfbc6c4c
SS
753 bool offchannel = IEEE80211_SKB_CB(skb)->flags &
754 IEEE80211_TX_CTL_TX_OFFCHAN;
8ca151b5 755
9ee718aa
EL
756 if (iwl_mvm_is_radio_killed(mvm)) {
757 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
8ca151b5
JB
758 goto drop;
759 }
760
cfbc6c4c 761 if (offchannel &&
a6cc5163
MG
762 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
763 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
8ca151b5
JB
764 goto drop;
765
10516783
JB
766 /*
767 * bufferable MMPDUs or MMPDUs on STA interfaces come via TXQs
768 * so we treat the others as broadcast
769 */
770 if (ieee80211_is_mgmt(hdr->frame_control))
3e56eadf
JB
771 sta = NULL;
772
dc1aca22 773 /* If there is no sta, and it's not offchannel - send through AP */
cfbc6c4c
SS
774 if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION &&
775 !offchannel) {
dc1aca22
AO
776 struct iwl_mvm_vif *mvmvif =
777 iwl_mvm_vif_from_mac80211(info->control.vif);
778 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
779
be9ae34e 780 if (ap_sta_id < mvm->fw->ucode_capa.num_stations) {
dc1aca22
AO
781 /* mac80211 holds rcu read lock */
782 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
783 if (IS_ERR_OR_NULL(sta))
784 goto drop;
785 }
786 }
787
df2378ab 788 iwl_mvm_tx_skb(mvm, skb, sta);
8ca151b5
JB
789 return;
790 drop:
791 ieee80211_free_txskb(hw, skb);
792}
793
cfbc6c4c 794void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
205e2210 795{
cfbc6c4c
SS
796 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
797 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
798 struct sk_buff *skb = NULL;
799
fba8248e
SS
800 /*
801 * No need for threads to be pending here, they can leave the first
802 * taker all the work.
803 *
804 * mvmtxq->tx_request logic:
805 *
806 * If 0, no one is currently TXing, set to 1 to indicate current thread
807 * will now start TX and other threads should quit.
808 *
809 * If 1, another thread is currently TXing, set to 2 to indicate to
810 * that thread that there was another request. Since that request may
811 * have raced with the check whether the queue is empty, the TXing
812 * thread should check the queue's status one more time before leaving.
813 * This check is done in order to not leave any TX hanging in the queue
814 * until the next TX invocation (which may not even happen).
815 *
816 * If 2, another thread is currently TXing, and it will already double
817 * check the queue, so do nothing.
818 */
819 if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2))
820 return;
cfbc6c4c
SS
821
822 rcu_read_lock();
fba8248e
SS
823 do {
824 while (likely(!mvmtxq->stopped &&
00520b7a 825 !test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status))) {
fba8248e
SS
826 skb = ieee80211_tx_dequeue(hw, txq);
827
f50d693b
SS
828 if (!skb) {
829 if (txq->sta)
830 IWL_DEBUG_TX(mvm,
831 "TXQ of sta %pM tid %d is now empty\n",
832 txq->sta->addr,
833 txq->tid);
fba8248e 834 break;
f50d693b 835 }
fba8248e 836
df2378ab 837 iwl_mvm_tx_skb(mvm, skb, txq->sta);
fba8248e
SS
838 }
839 } while (atomic_dec_return(&mvmtxq->tx_request));
cfbc6c4c 840 rcu_read_unlock();
205e2210
EG
841}
842
cfbc6c4c
SS
843static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw,
844 struct ieee80211_txq *txq)
205e2210 845{
cfbc6c4c
SS
846 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
847 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
205e2210 848
cfbc6c4c
SS
849 /*
850 * Please note that racing is handled very carefully here:
851 * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is
852 * deleted afterwards.
853 * This means that if:
854 * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list):
855 * queue is allocated and we can TX.
856 * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list):
857 * a race, should defer the frame.
858 * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list):
859 * need to allocate the queue and defer the frame.
860 * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list):
861 * queue is already scheduled for allocation, no need to allocate,
862 * should defer the frame.
863 */
864
865 /* If the queue is allocated TX and return. */
866 if (!txq->sta || mvmtxq->txq_id != IWL_MVM_INVALID_QUEUE) {
867 /*
868 * Check that list is empty to avoid a race where txq_id is
869 * already updated, but the queue allocation work wasn't
870 * finished
871 */
872 if (unlikely(txq->sta && !list_empty(&mvmtxq->list)))
873 return;
874
875 iwl_mvm_mac_itxq_xmit(hw, txq);
876 return;
877 }
878
879 /* The list is being deleted only after the queue is fully allocated. */
880 if (!list_empty(&mvmtxq->list))
881 return;
882
883 list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs);
884 schedule_work(&mvm->add_stream_wk);
205e2210
EG
885}
886
7174beb6
JB
887#define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
888 do { \
889 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
890 break; \
891 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
4203263d
EG
892 } while (0)
893
894static void
895iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
896 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
897 enum ieee80211_ampdu_mlme_action action)
898{
899 struct iwl_fw_dbg_trigger_tlv *trig;
900 struct iwl_fw_dbg_trigger_ba *ba_trig;
901
6c042d75
SS
902 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
903 FW_DBG_TRIGGER_BA);
904 if (!trig)
4203263d
EG
905 return;
906
4203263d
EG
907 ba_trig = (void *)trig->data;
908
4203263d
EG
909 switch (action) {
910 case IEEE80211_AMPDU_TX_OPERATIONAL: {
911 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
912 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
913
914 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
915 "TX AGG START: MAC %pM tid %d ssn %d\n",
916 sta->addr, tid, tid_data->ssn);
917 break;
918 }
919 case IEEE80211_AMPDU_TX_STOP_CONT:
920 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
921 "TX AGG STOP: MAC %pM tid %d\n",
922 sta->addr, tid);
923 break;
924 case IEEE80211_AMPDU_RX_START:
925 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
926 "RX AGG START: MAC %pM tid %d ssn %d\n",
927 sta->addr, tid, rx_ba_ssn);
928 break;
929 case IEEE80211_AMPDU_RX_STOP:
930 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
931 "RX AGG STOP: MAC %pM tid %d\n",
932 sta->addr, tid);
933 break;
934 default:
935 break;
936 }
937}
938
8ca151b5
JB
939static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
940 struct ieee80211_vif *vif,
50ea05ef 941 struct ieee80211_ampdu_params *params)
8ca151b5
JB
942{
943 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
944 int ret;
50ea05ef
SS
945 struct ieee80211_sta *sta = params->sta;
946 enum ieee80211_ampdu_mlme_action action = params->action;
947 u16 tid = params->tid;
948 u16 *ssn = &params->ssn;
514c3069 949 u16 buf_size = params->buf_size;
bb81bb68 950 bool amsdu = params->amsdu;
10b2b201 951 u16 timeout = params->timeout;
8ca151b5
JB
952
953 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
954 sta->addr, tid, action);
955
956 if (!(mvm->nvm_data->sku_cap_11n_enable))
957 return -EACCES;
958
959 mutex_lock(&mvm->mutex);
960
961 switch (action) {
962 case IEEE80211_AMPDU_RX_START:
b0ffe455
JB
963 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
964 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
965 struct iwl_mvm_vif *mvmvif;
966 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
967 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
968
969 mdata->opened_rx_ba_sessions = true;
970 mvmvif = iwl_mvm_vif_from_mac80211(vif);
971 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
972 }
e78da25e 973 if (!iwl_enable_rx_ampdu()) {
8ca151b5
JB
974 ret = -EINVAL;
975 break;
976 }
10b2b201
SS
977 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
978 timeout);
8ca151b5
JB
979 break;
980 case IEEE80211_AMPDU_RX_STOP:
10b2b201
SS
981 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
982 timeout);
8ca151b5
JB
983 break;
984 case IEEE80211_AMPDU_TX_START:
e78da25e 985 if (!iwl_enable_tx_ampdu()) {
5d158efa
EG
986 ret = -EINVAL;
987 break;
988 }
8ca151b5
JB
989 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
990 break;
991 case IEEE80211_AMPDU_TX_STOP_CONT:
e3d9e7ce
EG
992 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
993 break;
8ca151b5
JB
994 case IEEE80211_AMPDU_TX_STOP_FLUSH:
995 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
e3d9e7ce 996 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
8ca151b5
JB
997 break;
998 case IEEE80211_AMPDU_TX_OPERATIONAL:
bb81bb68
EG
999 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1000 buf_size, amsdu);
8ca151b5
JB
1001 break;
1002 default:
1003 WARN_ON_ONCE(1);
1004 ret = -EINVAL;
1005 break;
1006 }
4203263d
EG
1007
1008 if (!ret) {
1009 u16 rx_ba_ssn = 0;
1010
1011 if (action == IEEE80211_AMPDU_RX_START)
1012 rx_ba_ssn = *ssn;
1013
1014 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1015 rx_ba_ssn, action);
1016 }
8ca151b5
JB
1017 mutex_unlock(&mvm->mutex);
1018
1019 return ret;
1020}
1021
1022static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1023 struct ieee80211_vif *vif)
1024{
1025 struct iwl_mvm *mvm = data;
1026 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1027
1028 mvmvif->uploaded = false;
0ae98812 1029 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
8ca151b5 1030
8ca151b5
JB
1031 spin_lock_bh(&mvm->time_event_lock);
1032 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1033 spin_unlock_bh(&mvm->time_event_lock);
1034
fe0f2de3 1035 mvmvif->phy_ctxt = NULL;
8a275bad 1036 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
86e177d8 1037 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
8ca151b5
JB
1038}
1039
1040static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1041{
fcb6b92a 1042 iwl_mvm_stop_device(mvm);
8ca151b5 1043
9bf13bee
JB
1044 mvm->cur_aid = 0;
1045
9af91f46 1046 mvm->scan_status = 0;
b1873300 1047 mvm->ps_disabled = false;
b3500b47 1048 mvm->rfkill_safe_init_done = false;
8ca151b5
JB
1049
1050 /* just in case one was running */
305d236e 1051 iwl_mvm_cleanup_roc_te(mvm);
8ca151b5
JB
1052 ieee80211_remain_on_channel_expired(mvm->hw);
1053
fc36ffda
JB
1054 iwl_mvm_ftm_restart(mvm);
1055
737719fe
AN
1056 /*
1057 * cleanup all interfaces, even inactive ones, as some might have
1058 * gone down during the HW restart
1059 */
1060 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
8ca151b5 1061
fe0f2de3
IP
1062 mvm->p2p_device_vif = NULL;
1063
1064 iwl_mvm_reset_phy_ctxts(mvm);
9c3deeb5 1065 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
8a275bad 1066 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
8a275bad 1067 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
8ca151b5
JB
1068
1069 ieee80211_wake_queues(mvm->hw);
1070
1071 mvm->vif_count = 0;
113a0447 1072 mvm->rx_ba_sessions = 0;
7174beb6 1073 mvm->fwrt.dump.conf = FW_DBG_INVALID;
baf41bc3 1074 mvm->monitor_on = false;
91a8bcde
JB
1075
1076 /* keep statistics ticking */
1077 iwl_mvm_accu_radio_stats(mvm);
8ca151b5
JB
1078}
1079
a0a09243 1080int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
8ca151b5 1081{
8ca151b5
JB
1082 int ret;
1083
a0a09243 1084 lockdep_assert_held(&mvm->mutex);
8ca151b5 1085
bf8b286f
JB
1086 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1087 /*
1088 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1089 * so later code will - from now on - see that we're doing it.
1090 */
1091 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1092 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
a42b2af3 1093 /* Clean up some internal and mac80211 state on restart */
8ca151b5 1094 iwl_mvm_restart_cleanup(mvm);
a42b2af3 1095 }
8ca151b5 1096 ret = iwl_mvm_up(mvm);
c47af22a 1097
b108d8c7
SM
1098 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT,
1099 NULL);
1100 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC,
1101 NULL);
da2eb669 1102
e8fe3b41
IP
1103 mvm->last_reset_or_resume_time_jiffies = jiffies;
1104
c47af22a
JB
1105 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1106 /* Something went wrong - we need to finish some cleanup
1107 * that normally iwl_mvm_mac_restart_complete() below
1108 * would do.
1109 */
1110 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
c47af22a
JB
1111 }
1112
a0a09243
LC
1113 return ret;
1114}
1115
1116static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1117{
1118 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1119 int ret;
1120
1121 mutex_lock(&mvm->mutex);
1122 ret = __iwl_mvm_mac_start(mvm);
8ca151b5
JB
1123 mutex_unlock(&mvm->mutex);
1124
1125 return ret;
1126}
1127
cf2c92d8 1128static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
8ca151b5 1129{
8ca151b5
JB
1130 int ret;
1131
1132 mutex_lock(&mvm->mutex);
1133
1134 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
4d4183c4 1135
e7afe89f 1136 ret = iwl_mvm_update_quotas(mvm, true, NULL);
8ca151b5
JB
1137 if (ret)
1138 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1139 ret);
1140
f130bb75
MG
1141 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY);
1142
cbd2ae2d
AN
1143 /*
1144 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1145 * of packets the FW sent out, so we must reconnect.
1146 */
1147 iwl_mvm_teardown_tdls_peers(mvm);
1148
8ca151b5
JB
1149 mutex_unlock(&mvm->mutex);
1150}
1151
cf2c92d8
EP
1152static void
1153iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1154 enum ieee80211_reconfig_type reconfig_type)
1155{
1156 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1157
1158 switch (reconfig_type) {
1159 case IEEE80211_RECONFIG_TYPE_RESTART:
1160 iwl_mvm_restart_complete(mvm);
1161 break;
1162 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1163 break;
1164 }
1165}
1166
a0a09243 1167void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
8ca151b5 1168{
a0a09243 1169 lockdep_assert_held(&mvm->mutex);
7498cf4c 1170
b68bd2e3
IP
1171 iwl_mvm_ftm_initiator_smooth_stop(mvm);
1172
91a8bcde
JB
1173 /* firmware counters are obviously reset now, but we shouldn't
1174 * partially track so also clear the fw_reset_accu counters.
1175 */
1176 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1177
8ca151b5
JB
1178 /* async_handlers_wk is now blocked */
1179
2c2c3647
NE
1180 if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP, ADD_STA, 0) < 12)
1181 iwl_mvm_rm_aux_sta(mvm);
f327236d 1182
fcb6b92a 1183 iwl_mvm_stop_device(mvm);
8ca151b5
JB
1184
1185 iwl_mvm_async_handlers_purge(mvm);
1186 /* async_handlers_list is empty and will stay empty: HW is stopped */
1187
0a79a0c0 1188 /*
155f7e04
EG
1189 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1190 * hw (as restart_complete() won't be called in this case) and mac80211
1191 * won't execute the restart.
8b2b9fbf
AN
1192 * But make sure to cleanup interfaces that have gone down before/during
1193 * HW restart was requested.
0a79a0c0 1194 */
155f7e04
EG
1195 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1196 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1197 &mvm->status))
8b2b9fbf
AN
1198 ieee80211_iterate_interfaces(mvm->hw, 0,
1199 iwl_mvm_cleanup_iterator, mvm);
0a79a0c0 1200
963221be
AB
1201 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1202 * make sure there's nothing left there and warn if any is found.
1203 */
859d914c 1204 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
963221be
AB
1205 int i;
1206
507e4cda 1207 for (i = 0; i < mvm->max_scans; i++) {
6185af2a
LC
1208 if (WARN_ONCE(mvm->scan_uid_status[i],
1209 "UMAC scan UID %d status was not cleaned\n",
1210 i))
1211 mvm->scan_uid_status[i] = 0;
963221be
AB
1212 }
1213 }
a0a09243 1214}
bc44886d 1215
a0a09243
LC
1216static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1217{
1218 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1219
a0a09243 1220 flush_work(&mvm->async_handlers_wk);
24afba76 1221 flush_work(&mvm->add_stream_wk);
771147b0
JB
1222
1223 /*
1224 * Lock and clear the firmware running bit here already, so that
1225 * new commands coming in elsewhere, e.g. from debugfs, will not
1226 * be able to proceed. This is important here because one of those
7174beb6 1227 * debugfs files causes the firmware dump to be triggered, and if we
771147b0
JB
1228 * don't stop debugfs accesses before canceling that it could be
1229 * retriggered after we flush it but before we've cleared the bit.
1230 */
1231 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1232
d3a108a4 1233 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
69e04642 1234 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
a0a09243 1235
f9084775
NE
1236 /*
1237 * The work item could be running or queued if the
1238 * ROC time event stops just as we get here.
1239 */
1240 flush_work(&mvm->roc_done_wk);
1241
a0a09243
LC
1242 mutex_lock(&mvm->mutex);
1243 __iwl_mvm_mac_stop(mvm);
8ca151b5
JB
1244 mutex_unlock(&mvm->mutex);
1245
1246 /*
1247 * The worker might have been waiting for the mutex, let it run and
1248 * discover that its list is now empty.
1249 */
1250 cancel_work_sync(&mvm->async_handlers_wk);
1251}
1252
fe0f2de3
IP
1253static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1254{
1255 u16 i;
1256
1257 lockdep_assert_held(&mvm->mutex);
1258
1259 for (i = 0; i < NUM_PHY_CTX; i++)
1260 if (!mvm->phy_ctxts[i].ref)
1261 return &mvm->phy_ctxts[i];
1262
1263 IWL_ERR(mvm, "No available PHY context\n");
1264 return NULL;
1265}
1266
d44c3fe6
AA
1267static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1268 s16 tx_power)
1269{
0791c2fc 1270 int len;
216cdfb5
LC
1271 struct iwl_dev_tx_power_cmd cmd = {
1272 .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1273 .common.mac_context_id =
d44c3fe6 1274 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
216cdfb5 1275 .common.pwr_restriction = cpu_to_le16(8 * tx_power),
d44c3fe6 1276 };
fbb7957d 1277 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
e80bfd11
MG
1278 REDUCE_TX_POWER_CMD,
1279 IWL_FW_CMD_VER_UNKNOWN);
d44c3fe6 1280
d44c3fe6 1281 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
216cdfb5 1282 cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
d44c3fe6 1283
fbb7957d
LC
1284 if (cmd_ver == 6)
1285 len = sizeof(cmd.v6);
1286 else if (fw_has_api(&mvm->fw->ucode_capa,
1287 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
0791c2fc
HD
1288 len = sizeof(cmd.v5);
1289 else if (fw_has_capa(&mvm->fw->ucode_capa,
1290 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1291 len = sizeof(cmd.v4);
1292 else
216cdfb5
LC
1293 len = sizeof(cmd.v3);
1294
1295 /* all structs have the same common part, add it */
1296 len += sizeof(cmd.common);
da03f029
JB
1297
1298 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
d44c3fe6
AA
1299}
1300
f6780614
SS
1301static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
1302 struct ieee80211_vif *vif)
1303{
1304 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1305 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1306 int ret;
1307
1308 mutex_lock(&mvm->mutex);
1309
f6780614
SS
1310 if (vif->type == NL80211_IFTYPE_STATION) {
1311 struct iwl_mvm_sta *mvmsta;
1312
1313 mvmvif->csa_bcn_pending = false;
1314 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
1315 mvmvif->ap_sta_id);
1316
1317 if (WARN_ON(!mvmsta)) {
1318 ret = -EIO;
1319 goto out_unlock;
1320 }
1321
df720373 1322 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
f6780614
SS
1323
1324 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1325
0202bcf0
EG
1326 if (!fw_has_capa(&mvm->fw->ucode_capa,
1327 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
1328 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1329 if (ret)
1330 goto out_unlock;
f6780614 1331
0202bcf0
EG
1332 iwl_mvm_stop_session_protection(mvm, vif);
1333 }
f6780614
SS
1334 }
1335
1336 mvmvif->ps_disabled = false;
1337
1338 ret = iwl_mvm_power_update_ps(mvm);
1339
1340out_unlock:
caf46377
SS
1341 if (mvmvif->csa_failed)
1342 ret = -EIO;
f6780614
SS
1343 mutex_unlock(&mvm->mutex);
1344
1345 return ret;
1346}
1347
1348static void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw,
1349 struct ieee80211_vif *vif)
1350{
1351 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1352 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1353 struct iwl_chan_switch_te_cmd cmd = {
1354 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1355 mvmvif->color)),
1356 .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE),
1357 };
1358
1359 IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id);
1360
1361 mutex_lock(&mvm->mutex);
58ddd9b6
EG
1362 if (!fw_has_capa(&mvm->fw->ucode_capa,
1363 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
1364 iwl_mvm_remove_csa_period(mvm, vif);
1365 else
1366 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
1367 WIDE_ID(MAC_CONF_GROUP,
1368 CHANNEL_SWITCH_TIME_EVENT_CMD),
1369 0, sizeof(cmd), &cmd));
caf46377 1370 mvmvif->csa_failed = true;
f6780614
SS
1371 mutex_unlock(&mvm->mutex);
1372
caf46377 1373 iwl_mvm_post_channel_switch(hw, vif);
f6780614
SS
1374}
1375
1376static void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk)
1377{
f6780614
SS
1378 struct iwl_mvm_vif *mvmvif;
1379 struct ieee80211_vif *vif;
1380
1381 mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work);
1382 vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);
f6780614 1383
70162580 1384 /* Trigger disconnect (should clear the CSA state) */
f6780614
SS
1385 ieee80211_chswitch_done(vif, false);
1386}
1387
8ca151b5
JB
1388static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1389 struct ieee80211_vif *vif)
1390{
1391 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1392 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1393 int ret;
1394
aa5e1832 1395 mvmvif->mvm = mvm;
86e177d8 1396 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
aa5e1832 1397
8ca151b5
JB
1398 /*
1399 * Not much to do here. The stack will not allow interface
1400 * types or combinations that we didn't advertise, so we
1401 * don't really have to check the types.
1402 */
1403
1404 mutex_lock(&mvm->mutex);
1405
33cef925
JB
1406 /* make sure that beacon statistics don't go backwards with FW reset */
1407 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1408 mvmvif->beacon_stats.accu_num_beacons +=
1409 mvmvif->beacon_stats.num_beacons;
1410
e89044d7 1411 /* Allocate resources for the MAC context, and add it to the fw */
8ca151b5
JB
1412 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1413 if (ret)
1414 goto out_unlock;
1415
698478c4
SS
1416 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif);
1417
1c2abf72 1418 /* Counting number of interfaces is needed for legacy PM */
ea183d02
IP
1419 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1420 mvm->vif_count++;
ea183d02 1421
8ca151b5
JB
1422 /*
1423 * The AP binding flow can be done only after the beacon
1424 * template is configured (which happens only in the mac80211
1425 * start_ap() flow), and adding the broadcast station can happen
1426 * only after the binding.
1427 * In addition, since modifying the MAC before adding a bcast
1428 * station is not allowed by the FW, delay the adding of MAC context to
1429 * the point where we can also add the bcast station.
1430 * In short: there's not much we can do at this point, other than
1431 * allocating resources :)
1432 */
5023d966
JB
1433 if (vif->type == NL80211_IFTYPE_AP ||
1434 vif->type == NL80211_IFTYPE_ADHOC) {
013290aa 1435 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
8ca151b5
JB
1436 if (ret) {
1437 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1438 goto out_release;
1439 }
1440
c8f54701
JB
1441 /*
1442 * Only queue for this station is the mcast queue,
1443 * which shouldn't be in TFD mask anyway
1444 */
1445 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1446 0, vif->type,
1447 IWL_STA_MULTICAST);
1448 if (ret)
1449 goto out_release;
26d6c16b 1450
77740cb4 1451 iwl_mvm_vif_dbgfs_register(mvm, vif);
8ca151b5
JB
1452 goto out_unlock;
1453 }
1454
93190fb0
AA
1455 mvmvif->features |= hw->netdev_features;
1456
8ca151b5
JB
1457 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1458 if (ret)
1459 goto out_release;
1460
999609f1 1461 ret = iwl_mvm_power_update_mac(mvm);
e5e7aa8e 1462 if (ret)
fd66fc1c 1463 goto out_remove_mac;
8ca151b5 1464
7df15b1e 1465 /* beacon filtering */
a1022927 1466 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
bd3351ba
EP
1467 if (ret)
1468 goto out_remove_mac;
1469
7df15b1e 1470 if (!mvm->bf_allowed_vif &&
73e5f2c5 1471 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
7df15b1e 1472 mvm->bf_allowed_vif = mvmvif;
a20fd398
AO
1473 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1474 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
7df15b1e
HG
1475 }
1476
8ca151b5
JB
1477 /*
1478 * P2P_DEVICE interface does not have a channel context assigned to it,
1479 * so a dedicated PHY context is allocated to it and the corresponding
1480 * MAC context is bound to it at this stage.
1481 */
1482 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
8ca151b5 1483
fe0f2de3
IP
1484 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1485 if (!mvmvif->phy_ctxt) {
1486 ret = -ENOSPC;
bd3351ba 1487 goto out_free_bf;
fe0f2de3 1488 }
8ca151b5 1489
53a9d61e 1490 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
8ca151b5
JB
1491 ret = iwl_mvm_binding_add_vif(mvm, vif);
1492 if (ret)
53a9d61e 1493 goto out_unref_phy;
8ca151b5 1494
d197358b 1495 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
8ca151b5
JB
1496 if (ret)
1497 goto out_unbind;
1498
1499 /* Save a pointer to p2p device vif, so it can later be used to
1500 * update the p2p device MAC when a GO is started/stopped */
1501 mvm->p2p_device_vif = vif;
1502 }
1503
b0ffe455 1504 iwl_mvm_tcm_add_vif(mvm, vif);
f6780614
SS
1505 INIT_DELAYED_WORK(&mvmvif->csa_work,
1506 iwl_mvm_channel_switch_disconnect_wk);
b0ffe455 1507
baf41bc3
ST
1508 if (vif->type == NL80211_IFTYPE_MONITOR)
1509 mvm->monitor_on = true;
1510
63494374 1511 iwl_mvm_vif_dbgfs_register(mvm, vif);
8ca151b5
JB
1512 goto out_unlock;
1513
1514 out_unbind:
1515 iwl_mvm_binding_remove_vif(mvm, vif);
53a9d61e 1516 out_unref_phy:
fe0f2de3 1517 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
bd3351ba
EP
1518 out_free_bf:
1519 if (mvm->bf_allowed_vif == mvmvif) {
1520 mvm->bf_allowed_vif = NULL;
a20fd398
AO
1521 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1522 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
bd3351ba 1523 }
8ca151b5
JB
1524 out_remove_mac:
1525 mvmvif->phy_ctxt = NULL;
1526 iwl_mvm_mac_ctxt_remove(mvm, vif);
1527 out_release:
5ee2b215
AB
1528 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1529 mvm->vif_count--;
8ca151b5
JB
1530 out_unlock:
1531 mutex_unlock(&mvm->mutex);
1532
1533 return ret;
1534}
1535
38a12b5b
JB
1536static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1537 struct ieee80211_vif *vif)
8ca151b5 1538{
8ca151b5
JB
1539 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1540 /*
1541 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1542 * We assume here that all the packets sent to the OFFCHANNEL
1543 * queue are sent in ROC session.
1544 */
1545 flush_work(&mvm->roc_done_wk);
8ca151b5 1546 }
38a12b5b
JB
1547}
1548
1549static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1550 struct ieee80211_vif *vif)
1551{
1552 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1553 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
86e177d8 1554 struct iwl_probe_resp_data *probe_data;
38a12b5b
JB
1555
1556 iwl_mvm_prepare_mac_removal(mvm, vif);
8ca151b5 1557
b0ffe455
JB
1558 if (!(vif->type == NL80211_IFTYPE_AP ||
1559 vif->type == NL80211_IFTYPE_ADHOC))
1560 iwl_mvm_tcm_rm_vif(mvm, vif);
1561
8ca151b5
JB
1562 mutex_lock(&mvm->mutex);
1563
86e177d8
GG
1564 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1565 lockdep_is_held(&mvm->mutex));
1566 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1567 if (probe_data)
1568 kfree_rcu(probe_data, rcu_head);
1569
7df15b1e
HG
1570 if (mvm->bf_allowed_vif == mvmvif) {
1571 mvm->bf_allowed_vif = NULL;
a20fd398
AO
1572 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1573 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
7df15b1e
HG
1574 }
1575
b73f9a4a
JB
1576 if (vif->bss_conf.ftm_responder)
1577 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
1578
63494374
JB
1579 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1580
8ca151b5
JB
1581 /*
1582 * For AP/GO interface, the tear down of the resources allocated to the
38a12b5b 1583 * interface is be handled as part of the stop_ap flow.
8ca151b5 1584 */
5023d966
JB
1585 if (vif->type == NL80211_IFTYPE_AP ||
1586 vif->type == NL80211_IFTYPE_ADHOC) {
507cadf2
DS
1587#ifdef CONFIG_NL80211_TESTMODE
1588 if (vif == mvm->noa_vif) {
1589 mvm->noa_vif = NULL;
1590 mvm->noa_duration = 0;
1591 }
1592#endif
26d6c16b 1593 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
013290aa 1594 iwl_mvm_dealloc_bcast_sta(mvm, vif);
8ca151b5
JB
1595 goto out_release;
1596 }
1597
1598 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1599 mvm->p2p_device_vif = NULL;
d197358b 1600 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
8ca151b5 1601 iwl_mvm_binding_remove_vif(mvm, vif);
fe0f2de3 1602 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
8ca151b5
JB
1603 mvmvif->phy_ctxt = NULL;
1604 }
1605
5ee2b215 1606 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
8ca151b5 1607 mvm->vif_count--;
1c2abf72 1608
999609f1 1609 iwl_mvm_power_update_mac(mvm);
8ca151b5
JB
1610 iwl_mvm_mac_ctxt_remove(mvm, vif);
1611
698478c4
SS
1612 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL);
1613
baf41bc3
ST
1614 if (vif->type == NL80211_IFTYPE_MONITOR)
1615 mvm->monitor_on = false;
1616
8ca151b5 1617out_release:
8ca151b5
JB
1618 mutex_unlock(&mvm->mutex);
1619}
1620
1621static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
88f2fd73 1622{
8ca151b5
JB
1623 return 0;
1624}
1625
e59647ea
EP
1626struct iwl_mvm_mc_iter_data {
1627 struct iwl_mvm *mvm;
1628 int port_id;
1629};
1630
1631static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1632 struct ieee80211_vif *vif)
1633{
1634 struct iwl_mvm_mc_iter_data *data = _data;
1635 struct iwl_mvm *mvm = data->mvm;
1636 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
97bce57b
LC
1637 struct iwl_host_cmd hcmd = {
1638 .id = MCAST_FILTER_CMD,
1639 .flags = CMD_ASYNC,
1640 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1641 };
e59647ea
EP
1642 int ret, len;
1643
1644 /* if we don't have free ports, mcast frames will be dropped */
1645 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1646 return;
1647
1648 if (vif->type != NL80211_IFTYPE_STATION ||
1649 !vif->bss_conf.assoc)
1650 return;
1651
1652 cmd->port_id = data->port_id++;
1653 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1654 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1655
97bce57b
LC
1656 hcmd.len[0] = len;
1657 hcmd.data[0] = cmd;
1658
1659 ret = iwl_mvm_send_cmd(mvm, &hcmd);
e59647ea
EP
1660 if (ret)
1661 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1662}
1663
1664static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1665{
1666 struct iwl_mvm_mc_iter_data iter_data = {
1667 .mvm = mvm,
88f2fd73
MG
1668 };
1669
e59647ea
EP
1670 lockdep_assert_held(&mvm->mutex);
1671
1672 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1673 return;
1674
1c4abec0 1675 ieee80211_iterate_active_interfaces_atomic(
e59647ea
EP
1676 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1677 iwl_mvm_mc_iface_iterator, &iter_data);
88f2fd73
MG
1678}
1679
e59647ea
EP
1680static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1681 struct netdev_hw_addr_list *mc_list)
8ca151b5 1682{
e59647ea
EP
1683 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1684 struct iwl_mcast_filter_cmd *cmd;
1685 struct netdev_hw_addr *addr;
f3bd58f4
MS
1686 int addr_count;
1687 bool pass_all;
e59647ea
EP
1688 int len;
1689
f3bd58f4
MS
1690 addr_count = netdev_hw_addr_list_count(mc_list);
1691 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1692 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1693 if (pass_all)
e59647ea 1694 addr_count = 0;
e59647ea
EP
1695
1696 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1697 cmd = kzalloc(len, GFP_ATOMIC);
1698 if (!cmd)
1699 return 0;
1700
1701 if (pass_all) {
1702 cmd->pass_all = 1;
1703 return (u64)(unsigned long)cmd;
1704 }
1705
1706 netdev_hw_addr_list_for_each(addr, mc_list) {
1707 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1708 cmd->count, addr->addr);
1709 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1710 addr->addr, ETH_ALEN);
1711 cmd->count++;
1712 }
1713
1714 return (u64)(unsigned long)cmd;
8ca151b5
JB
1715}
1716
1717static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1718 unsigned int changed_flags,
1719 unsigned int *total_flags,
1720 u64 multicast)
1721{
e59647ea
EP
1722 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1723 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
8ca151b5 1724
e59647ea 1725 mutex_lock(&mvm->mutex);
51b6b9e0 1726
e59647ea
EP
1727 /* replace previous configuration */
1728 kfree(mvm->mcast_filter_cmd);
1729 mvm->mcast_filter_cmd = cmd;
51b6b9e0 1730
e59647ea
EP
1731 if (!cmd)
1732 goto out;
51b6b9e0 1733
61e7d91b
LC
1734 if (changed_flags & FIF_ALLMULTI)
1735 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1736
1737 if (cmd->pass_all)
1738 cmd->count = 0;
1739
e59647ea
EP
1740 iwl_mvm_recalc_multicast(mvm);
1741out:
1742 mutex_unlock(&mvm->mutex);
1743 *total_flags = 0;
51b6b9e0
EG
1744}
1745
effd1929
AO
1746static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1747 struct ieee80211_vif *vif,
1748 unsigned int filter_flags,
1749 unsigned int changed_flags)
1750{
1751 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1752
1753 /* We support only filter for probe requests */
1754 if (!(changed_flags & FIF_PROBE_REQ))
1755 return;
1756
1757 /* Supported only for p2p client interfaces */
1758 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1759 !vif->p2p)
1760 return;
1761
1762 mutex_lock(&mvm->mutex);
1763 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1764 mutex_unlock(&mvm->mutex);
1765}
1766
c87163b9
EP
1767#ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1768struct iwl_bcast_iter_data {
1769 struct iwl_mvm *mvm;
1770 struct iwl_bcast_filter_cmd *cmd;
1771 u8 current_filter;
1772};
1773
1774static void
1775iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1776 const struct iwl_fw_bcast_filter *in_filter,
1777 struct iwl_fw_bcast_filter *out_filter)
1778{
1779 struct iwl_fw_bcast_filter_attr *attr;
1780 int i;
1781
1782 memcpy(out_filter, in_filter, sizeof(*out_filter));
1783
1784 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1785 attr = &out_filter->attrs[i];
1786
1787 if (!attr->mask)
1788 break;
1789
2ee8f021
EP
1790 switch (attr->reserved1) {
1791 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1792 if (vif->bss_conf.arp_addr_cnt != 1) {
1793 attr->mask = 0;
1794 continue;
1795 }
1796
1797 attr->val = vif->bss_conf.arp_addr_list[0];
1798 break;
1799 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1800 attr->val = *(__be32 *)&vif->addr[2];
1801 break;
1802 default:
1803 break;
1804 }
1805 attr->reserved1 = 0;
c87163b9
EP
1806 out_filter->num_attrs++;
1807 }
1808}
1809
1810static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1811 struct ieee80211_vif *vif)
1812{
1813 struct iwl_bcast_iter_data *data = _data;
1814 struct iwl_mvm *mvm = data->mvm;
1815 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1816 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1817 struct iwl_fw_bcast_mac *bcast_mac;
1818 int i;
1819
1820 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1821 return;
1822
1823 bcast_mac = &cmd->macs[mvmvif->id];
1824
e48393e8
IP
1825 /*
1826 * enable filtering only for associated stations, but not for P2P
1827 * Clients
1828 */
1829 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1830 !vif->bss_conf.assoc)
c87163b9
EP
1831 return;
1832
1833 bcast_mac->default_discard = 1;
1834
1835 /* copy all configured filters */
1836 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1837 /*
1838 * Make sure we don't exceed our filters limit.
1839 * if there is still a valid filter to be configured,
1840 * be on the safe side and just allow bcast for this mac.
1841 */
1842 if (WARN_ON_ONCE(data->current_filter >=
1843 ARRAY_SIZE(cmd->filters))) {
1844 bcast_mac->default_discard = 0;
1845 bcast_mac->attached_filters = 0;
1846 break;
1847 }
1848
1849 iwl_mvm_set_bcast_filter(vif,
1850 &mvm->bcast_filters[i],
1851 &cmd->filters[data->current_filter]);
1852
1853 /* skip current filter if it contains no attributes */
1854 if (!cmd->filters[data->current_filter].num_attrs)
1855 continue;
1856
1857 /* attach the filter to current mac */
1858 bcast_mac->attached_filters |=
1859 cpu_to_le16(BIT(data->current_filter));
1860
1861 data->current_filter++;
1862 }
1863}
1864
de06a59e
EP
1865bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1866 struct iwl_bcast_filter_cmd *cmd)
c87163b9 1867{
c87163b9
EP
1868 struct iwl_bcast_iter_data iter_data = {
1869 .mvm = mvm,
de06a59e 1870 .cmd = cmd,
c87163b9
EP
1871 };
1872
3b8983b1
MS
1873 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1874 return false;
1875
de06a59e
EP
1876 memset(cmd, 0, sizeof(*cmd));
1877 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1878 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1879
1880#ifdef CONFIG_IWLWIFI_DEBUGFS
1881 /* use debugfs filters/macs if override is configured */
1882 if (mvm->dbgfs_bcast_filtering.override) {
1883 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1884 sizeof(cmd->filters));
1885 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1886 sizeof(cmd->macs));
1887 return true;
1888 }
1889#endif
c87163b9
EP
1890
1891 /* if no filters are configured, do nothing */
1892 if (!mvm->bcast_filters)
de06a59e 1893 return false;
c87163b9
EP
1894
1895 /* configure and attach these filters for each associated sta vif */
1896 ieee80211_iterate_active_interfaces(
1897 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1898 iwl_mvm_bcast_filter_iterator, &iter_data);
1899
de06a59e
EP
1900 return true;
1901}
34672bb3
EP
1902
1903static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
de06a59e
EP
1904{
1905 struct iwl_bcast_filter_cmd cmd;
1906
1907 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1908 return 0;
1909
1910 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1911 return 0;
1912
a1022927 1913 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
c87163b9
EP
1914 sizeof(cmd), &cmd);
1915}
1916#else
34672bb3 1917static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
c87163b9
EP
1918{
1919 return 0;
1920}
1921#endif
1922
a07a8f37
SS
1923static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1924 struct ieee80211_vif *vif)
1925{
1926 struct iwl_mu_group_mgmt_cmd cmd = {};
1927
1928 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1929 WLAN_MEMBERSHIP_LEN);
1930 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1931 WLAN_USER_POSITION_LEN);
1932
1933 return iwl_mvm_send_cmd_pdu(mvm,
1934 WIDE_ID(DATA_PATH_GROUP,
1935 UPDATE_MU_GROUPS_CMD),
1936 0, sizeof(cmd), &cmd);
1937}
1938
f92659a1
SS
1939static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1940 struct ieee80211_vif *vif)
1941{
1942 if (vif->mu_mimo_owner) {
1943 struct iwl_mu_group_mgmt_notif *notif = _data;
1944
1945 /*
1946 * MU-MIMO Group Id action frame is little endian. We treat
1947 * the data received from firmware as if it came from the
1948 * action frame, so no conversion is needed.
1949 */
1950 ieee80211_update_mu_groups(vif,
1951 (u8 *)&notif->membership_status,
1952 (u8 *)&notif->user_position);
1953 }
1954}
1955
1956void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1957 struct iwl_rx_cmd_buffer *rxb)
1958{
1959 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1960 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1961
1962 ieee80211_iterate_active_interfaces_atomic(
1963 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1964 iwl_mvm_mu_mimo_iface_iterator, notif);
1965}
1966
514c3069
LC
1967static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1968{
1969 u8 byte_num = ppe_pos_bit / 8;
1970 u8 bit_num = ppe_pos_bit % 8;
1971 u8 residue_bits;
1972 u8 res;
1973
1974 if (bit_num <= 5)
1975 return (ppe[byte_num] >> bit_num) &
1976 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1977
1978 /*
1979 * If bit_num > 5, we have to combine bits with next byte.
1980 * Calculate how many bits we need to take from current byte (called
1981 * here "residue_bits"), and add them to bits from next byte.
1982 */
1983
1984 residue_bits = 8 - bit_num;
1985
1986 res = (ppe[byte_num + 1] &
1987 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1988 residue_bits;
1989 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1990
1991 return res;
1992}
1993
1994static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1995 struct ieee80211_vif *vif, u8 sta_id)
1996{
1997 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1998 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
1999 .sta_id = sta_id,
2000 .tid_limit = IWL_MAX_TID_COUNT,
dd56e902 2001 .bss_color = vif->bss_conf.he_bss_color.color,
514c3069
LC
2002 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
2003 .frame_time_rts_th =
2004 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
2005 };
d14ae796
SS
2006 int size = fw_has_api(&mvm->fw->ucode_capa,
2007 IWL_UCODE_TLV_API_MBSSID_HE) ?
2008 sizeof(sta_ctxt_cmd) :
2009 sizeof(struct iwl_he_sta_context_cmd_v1);
514c3069
LC
2010 struct ieee80211_sta *sta;
2011 u32 flags;
2012 int i;
ee1a02d7
ST
2013 const struct ieee80211_sta_he_cap *own_he_cap = NULL;
2014 struct ieee80211_chanctx_conf *chanctx_conf;
2015 const struct ieee80211_supported_band *sband;
514c3069
LC
2016
2017 rcu_read_lock();
2018
ee1a02d7
ST
2019 chanctx_conf = rcu_dereference(vif->chanctx_conf);
2020 if (WARN_ON(!chanctx_conf)) {
2021 rcu_read_unlock();
2022 return;
2023 }
2024
2025 sband = mvm->hw->wiphy->bands[chanctx_conf->def.chan->band];
4e6b69ec
JB
2026 own_he_cap = ieee80211_get_he_iftype_cap(sband,
2027 ieee80211_vif_type_p2p(vif));
ee1a02d7 2028
514c3069 2029 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
12d47f0e 2030 if (IS_ERR_OR_NULL(sta)) {
514c3069
LC
2031 rcu_read_unlock();
2032 WARN(1, "Can't find STA to configure HE\n");
2033 return;
2034 }
2035
2036 if (!sta->he_cap.has_he) {
2037 rcu_read_unlock();
2038 return;
2039 }
2040
2041 flags = 0;
2042
4f58121d
IP
2043 /* Block 26-tone RU OFDMA transmissions */
2044 if (mvmvif->he_ru_2mhz_block)
2045 flags |= STA_CTXT_HE_RU_2MHZ_BLOCK;
2046
514c3069
LC
2047 /* HTC flags */
2048 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
2049 IEEE80211_HE_MAC_CAP0_HTC_HE)
2050 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
2051 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
2052 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2053 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2054 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2055 u8 link_adap =
2056 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
2057 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2058 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
2059 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2060
2061 if (link_adap == 2)
2062 sta_ctxt_cmd.htc_flags |=
2063 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2064 else if (link_adap == 3)
2065 sta_ctxt_cmd.htc_flags |=
2066 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2067 }
514c3069
LC
2068 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2069 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2070 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2071 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2072 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2073 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2074 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2075
189b8d44
NG
2076 /*
2077 * Initialize the PPE thresholds to "None" (7), as described in Table
2078 * 9-262ac of 80211.ax/D3.0.
2079 */
2080 memset(&sta_ctxt_cmd.pkt_ext, 7, sizeof(sta_ctxt_cmd.pkt_ext));
2081
2082 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
514c3069
LC
2083 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2084 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2085 u8 nss = (sta->he_cap.ppe_thres[0] &
2086 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2087 u8 ru_index_bitmap =
2088 (sta->he_cap.ppe_thres[0] &
2089 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2090 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2091 u8 *ppe = &sta->he_cap.ppe_thres[0];
2092 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2093
2094 /*
2095 * FW currently supports only nss == MAX_HE_SUPP_NSS
2096 *
2097 * If nss > MAX: we can ignore values we don't support
2098 * If nss < MAX: we can set zeros in other streams
2099 */
2100 if (nss > MAX_HE_SUPP_NSS) {
2101 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2102 MAX_HE_SUPP_NSS);
2103 nss = MAX_HE_SUPP_NSS;
2104 }
2105
2106 for (i = 0; i < nss; i++) {
2107 u8 ru_index_tmp = ru_index_bitmap << 1;
2108 u8 bw;
2109
2110 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2111 ru_index_tmp >>= 1;
2112 if (!(ru_index_tmp & 1))
2113 continue;
2114
2115 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2116 iwl_mvm_he_get_ppe_val(ppe,
2117 ppe_pos_bit);
2118 ppe_pos_bit +=
2119 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2120 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2121 iwl_mvm_he_get_ppe_val(ppe,
2122 ppe_pos_bit);
2123 ppe_pos_bit +=
2124 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2125 }
2126 }
2127
2128 flags |= STA_CTXT_HE_PACKET_EXT;
77ff2c6b
LK
2129 } else if ((sta->he_cap.he_cap_elem.phy_cap_info[9] &
2130 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) !=
2131 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_RESERVED) {
2132 int low_th = -1;
2133 int high_th = -1;
2134
2135 /* Take the PPE thresholds from the nominal padding info */
2136 switch (sta->he_cap.he_cap_elem.phy_cap_info[9] &
2137 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) {
2138 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_0US:
2139 low_th = IWL_HE_PKT_EXT_NONE;
2140 high_th = IWL_HE_PKT_EXT_NONE;
2141 break;
2142 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_8US:
2143 low_th = IWL_HE_PKT_EXT_BPSK;
2144 high_th = IWL_HE_PKT_EXT_NONE;
2145 break;
2146 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US:
2147 low_th = IWL_HE_PKT_EXT_NONE;
2148 high_th = IWL_HE_PKT_EXT_BPSK;
2149 break;
2150 }
2151
2152 /* Set the PPE thresholds accordingly */
2153 if (low_th >= 0 && high_th >= 0) {
0bfefe2f
LK
2154 struct iwl_he_pkt_ext *pkt_ext =
2155 (struct iwl_he_pkt_ext *)&sta_ctxt_cmd.pkt_ext;
77ff2c6b
LK
2156
2157 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
2158 u8 bw;
2159
2160 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX;
2161 bw++) {
0bfefe2f
LK
2162 pkt_ext->pkt_ext_qam_th[i][bw][0] =
2163 low_th;
2164 pkt_ext->pkt_ext_qam_th[i][bw][1] =
2165 high_th;
77ff2c6b
LK
2166 }
2167 }
2168
2169 flags |= STA_CTXT_HE_PACKET_EXT;
2170 }
514c3069 2171 }
73f23d91
ST
2172
2173 if (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2174 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP)
2175 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2176
2177 if (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2178 IEEE80211_HE_MAC_CAP2_ACK_EN)
2179 flags |= STA_CTXT_HE_ACK_ENABLED;
2180
514c3069
LC
2181 rcu_read_unlock();
2182
2183 /* Mark MU EDCA as enabled, unless none detected on some AC */
2184 flags |= STA_CTXT_HE_MU_EDCA_CW;
5cc74f65 2185 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
514c3069
LC
2186 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2187 &mvmvif->queue_params[i].mu_edca_param_rec;
5cc74f65 2188 u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
514c3069
LC
2189
2190 if (!mvmvif->queue_params[i].mu_edca) {
2191 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2192 break;
2193 }
2194
5cc74f65 2195 sta_ctxt_cmd.trig_based_txf[ac].cwmin =
514c3069 2196 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
5cc74f65 2197 sta_ctxt_cmd.trig_based_txf[ac].cwmax =
514c3069 2198 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
5cc74f65 2199 sta_ctxt_cmd.trig_based_txf[ac].aifsn =
514c3069 2200 cpu_to_le16(mu_edca->aifsn);
5cc74f65 2201 sta_ctxt_cmd.trig_based_txf[ac].mu_time =
514c3069
LC
2202 cpu_to_le16(mu_edca->mu_edca_timer);
2203 }
2204
514c3069
LC
2205
2206 if (vif->bss_conf.uora_exists) {
2207 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2208
2209 sta_ctxt_cmd.rand_alloc_ecwmin =
2210 vif->bss_conf.uora_ocw_range & 0x7;
2211 sta_ctxt_cmd.rand_alloc_ecwmax =
2212 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2213 }
2214
ee1a02d7
ST
2215 if (own_he_cap && !(own_he_cap->he_cap_elem.mac_cap_info[2] &
2216 IEEE80211_HE_MAC_CAP2_ACK_EN))
2217 flags |= STA_CTXT_HE_NIC_NOT_ACK_ENABLED;
2218
918cbf39
SS
2219 if (vif->bss_conf.nontransmitted) {
2220 flags |= STA_CTXT_HE_REF_BSSID_VALID;
2221 ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr,
2222 vif->bss_conf.transmitter_bssid);
d14ae796
SS
2223 sta_ctxt_cmd.max_bssid_indicator =
2224 vif->bss_conf.bssid_indicator;
2225 sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index;
2226 sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap;
2227 sta_ctxt_cmd.profile_periodicity =
2228 vif->bss_conf.profile_periodicity;
918cbf39 2229 }
514c3069
LC
2230
2231 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2232
2233 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2234 DATA_PATH_GROUP, 0),
d14ae796 2235 0, size, &sta_ctxt_cmd))
514c3069
LC
2236 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2237}
2238
8ca151b5
JB
2239static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2240 struct ieee80211_vif *vif,
2241 struct ieee80211_bss_conf *bss_conf,
2242 u32 changes)
2243{
2244 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2245 int ret;
2246
6e97b0d2 2247 /*
cdaba917
EG
2248 * Re-calculate the tsf id, as the leader-follower relations depend
2249 * on the beacon interval, which was not known when the station
2250 * interface was added.
6e97b0d2 2251 */
514c3069 2252 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
230ba6c5
LC
2253 if (vif->bss_conf.he_support &&
2254 !iwlwifi_mod_params.disable_11ax)
514c3069
LC
2255 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2256
6e97b0d2 2257 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
514c3069 2258 }
6e97b0d2 2259
40ecdd01
ST
2260 /* Update MU EDCA params */
2261 if (changes & BSS_CHANGED_QOS && mvmvif->associated &&
2262 bss_conf->assoc && vif->bss_conf.he_support &&
2263 !iwlwifi_mod_params.disable_11ax)
2264 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2265
3dfd3a97
JB
2266 /*
2267 * If we're not associated yet, take the (new) BSSID before associating
2268 * so the firmware knows. If we're already associated, then use the old
2269 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2270 * branch for disassociation below.
2271 */
2272 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2273 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2274
2275 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
8ca151b5
JB
2276 if (ret)
2277 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2278
3dfd3a97
JB
2279 /* after sending it once, adopt mac80211 data */
2280 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2281 mvmvif->associated = bss_conf->assoc;
2282
8ca151b5
JB
2283 if (changes & BSS_CHANGED_ASSOC) {
2284 if (bss_conf->assoc) {
33cef925
JB
2285 /* clear statistics to get clean beacon counter */
2286 iwl_mvm_request_statistics(mvm, true);
2287 memset(&mvmvif->beacon_stats, 0,
2288 sizeof(mvmvif->beacon_stats));
2289
8ca151b5 2290 /* add quota for this interface */
7754ae79 2291 ret = iwl_mvm_update_quotas(mvm, true, NULL);
8ca151b5
JB
2292 if (ret) {
2293 IWL_ERR(mvm, "failed to update quotas\n");
2294 return;
2295 }
016d27e1
JB
2296
2297 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
fe959c7b
EG
2298 &mvm->status) &&
2299 !fw_has_capa(&mvm->fw->ucode_capa,
2300 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) {
016d27e1
JB
2301 /*
2302 * If we're restarting then the firmware will
2303 * obviously have lost synchronisation with
2304 * the AP. It will attempt to synchronise by
2305 * itself, but we can make it more reliable by
2306 * scheduling a session protection time event.
2307 *
2308 * The firmware needs to receive a beacon to
2309 * catch up with synchronisation, use 110% of
2310 * the beacon interval.
2311 *
2312 * Set a large maximum delay to allow for more
2313 * than a single interface.
fe959c7b
EG
2314 *
2315 * For new firmware versions, rely on the
2316 * firmware. This is relevant for DCM scenarios
2317 * only anyway.
016d27e1
JB
2318 */
2319 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2320 iwl_mvm_protect_session(mvm, vif, dur, dur,
d20d37bc 2321 5 * dur, false);
016d27e1 2322 }
1f3b0ff8
LE
2323
2324 iwl_mvm_sf_update(mvm, vif, false);
175a70b7 2325 iwl_mvm_power_vif_assoc(mvm, vif);
697162a1 2326 if (vif->p2p) {
697162a1
EG
2327 iwl_mvm_update_smps(mvm, vif,
2328 IWL_MVM_SMPS_REQ_PROT,
2329 IEEE80211_SMPS_DYNAMIC);
2330 }
0ae98812 2331 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
1f3b0ff8
LE
2332 /*
2333 * If update fails - SF might be running in associated
2334 * mode while disassociated - which is forbidden.
2335 */
69e508b4
IP
2336 ret = iwl_mvm_sf_update(mvm, vif, false);
2337 WARN_ONCE(ret &&
2338 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
2339 &mvm->status),
1f3b0ff8
LE
2340 "Failed to update SF upon disassociation\n");
2341
6b28f978
EG
2342 /*
2343 * If we get an assert during the connection (after the
2344 * station has been added, but before the vif is set
2345 * to associated), mac80211 will re-add the station and
2346 * then configure the vif. Since the vif is not
2347 * associated, we would remove the station here and
2348 * this would fail the recovery.
2349 */
2350 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2351 &mvm->status)) {
2352 /*
2353 * Remove AP station now that
2354 * the MAC is unassoc
2355 */
2356 ret = iwl_mvm_rm_sta_id(mvm, vif,
2357 mvmvif->ap_sta_id);
2358 if (ret)
2359 IWL_ERR(mvm,
2360 "failed to remove AP station\n");
2361
6b28f978
EG
2362 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2363 }
37577fe2 2364
8ca151b5 2365 /* remove quota for this interface */
7754ae79 2366 ret = iwl_mvm_update_quotas(mvm, false, NULL);
8ca151b5
JB
2367 if (ret)
2368 IWL_ERR(mvm, "failed to update quotas\n");
29a90a49 2369
3dfd3a97
JB
2370 /* this will take the cleared BSSID from bss_conf */
2371 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2372 if (ret)
2373 IWL_ERR(mvm,
2374 "failed to update MAC %pM (clear after unassoc)\n",
2375 vif->addr);
8ca151b5 2376 }
a20fd398 2377
a07a8f37
SS
2378 /*
2379 * The firmware tracks the MU-MIMO group on its own.
f92659a1 2380 * However, on HW restart we should restore this data.
a07a8f37
SS
2381 */
2382 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
f92659a1 2383 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
a07a8f37
SS
2384 ret = iwl_mvm_update_mu_groups(mvm, vif);
2385 if (ret)
2386 IWL_ERR(mvm,
2387 "failed to update VHT MU_MIMO groups\n");
2388 }
2389
e59647ea 2390 iwl_mvm_recalc_multicast(mvm);
34672bb3 2391 iwl_mvm_configure_bcast_filter(mvm);
e59647ea 2392
a20fd398
AO
2393 /* reset rssi values */
2394 mvmvif->bf_data.ave_beacon_signal = 0;
2395
8e484f0b 2396 iwl_mvm_bt_coex_vif_change(mvm);
f94045ed
EG
2397 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2398 IEEE80211_SMPS_AUTOMATIC);
355346ba
AS
2399 if (fw_has_capa(&mvm->fw->ucode_capa,
2400 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2401 iwl_mvm_config_scan(mvm);
b45242c9
AS
2402 }
2403
2404 if (changes & BSS_CHANGED_BEACON_INFO) {
210a544e 2405 /*
b45242c9 2406 * We received a beacon from the associated AP so
210a544e 2407 * remove the session protection.
fe959c7b 2408 * A firmware with the new API will remove it automatically.
210a544e 2409 */
fe959c7b
EG
2410 if (!fw_has_capa(&mvm->fw->ucode_capa,
2411 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD))
2412 iwl_mvm_stop_session_protection(mvm, vif);
cc87d322 2413
cc87d322
EH
2414 iwl_mvm_sf_update(mvm, vif, false);
2415 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2416 }
2417
283115fb
AA
2418 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2419 /*
2420 * Send power command on every beacon change,
2421 * because we may have not enabled beacon abort yet.
2422 */
2423 BSS_CHANGED_BEACON_INFO)) {
1bc10d3b
JB
2424 ret = iwl_mvm_power_update_mac(mvm);
2425 if (ret)
2426 IWL_ERR(mvm, "failed to update power mode\n");
2427 }
2428
a20fd398 2429 if (changes & BSS_CHANGED_CQM) {
3c6acb61 2430 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
a20fd398
AO
2431 /* reset cqm events tracking */
2432 mvmvif->bf_data.last_cqm_event = 0;
fa7b2e7f
AA
2433 if (mvmvif->bf_data.bf_enabled) {
2434 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2435 if (ret)
2436 IWL_ERR(mvm,
2437 "failed to update CQM thresholds\n");
2438 }
a20fd398 2439 }
2ee8f021
EP
2440
2441 if (changes & BSS_CHANGED_ARP_FILTER) {
3c6acb61 2442 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
34672bb3 2443 iwl_mvm_configure_bcast_filter(mvm);
2ee8f021 2444 }
de34d1c1
JB
2445
2446 if (changes & BSS_CHANGED_BANDWIDTH)
2447 iwl_mvm_apply_fw_smps_request(vif);
8ca151b5
JB
2448}
2449
5023d966
JB
2450static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2451 struct ieee80211_vif *vif)
8ca151b5
JB
2452{
2453 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2454 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
c56e00a3 2455 int ret, i;
8ca151b5
JB
2456
2457 mutex_lock(&mvm->mutex);
2458
2459 /* Send the beacon template */
2460 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2461 if (ret)
2462 goto out_unlock;
2463
6e97b0d2 2464 /*
cdaba917
EG
2465 * Re-calculate the tsf id, as the leader-follower relations depend on
2466 * the beacon interval, which was not known when the AP interface
2467 * was added.
6e97b0d2
IP
2468 */
2469 if (vif->type == NL80211_IFTYPE_AP)
2470 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2471
94939080
GG
2472 mvmvif->ap_assoc_sta_count = 0;
2473
8ca151b5
JB
2474 /* Add the mac context */
2475 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2476 if (ret)
2477 goto out_unlock;
2478
2479 /* Perform the binding */
2480 ret = iwl_mvm_binding_add_vif(mvm, vif);
2481 if (ret)
2482 goto out_remove;
2483
63dd5d02
SS
2484 /*
2485 * This is not very nice, but the simplest:
2486 * For older FWs adding the mcast sta before the bcast station may
2487 * cause assert 0x2b00.
2488 * This is fixed in later FW so make the order of removal depend on
2489 * the TLV
2490 */
2491 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2492 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2493 if (ret)
2494 goto out_unbind;
2495 /*
2496 * Send the bcast station. At this stage the TBTT and DTIM time
2497 * events are added and applied to the scheduler
2498 */
2499 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2500 if (ret) {
2501 iwl_mvm_rm_mcast_sta(mvm, vif);
2502 goto out_unbind;
2503 }
2504 } else {
2505 /*
2506 * Send the bcast station. At this stage the TBTT and DTIM time
2507 * events are added and applied to the scheduler
2508 */
75fd4fec 2509 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
63dd5d02
SS
2510 if (ret)
2511 goto out_unbind;
75fd4fec 2512 ret = iwl_mvm_add_mcast_sta(mvm, vif);
63dd5d02
SS
2513 if (ret) {
2514 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2515 goto out_unbind;
2516 }
2517 }
26d6c16b 2518
5691e218
IP
2519 /* must be set before quota calculations */
2520 mvmvif->ap_ibss_active = true;
2521
c56e00a3
JB
2522 /* send all the early keys to the device now */
2523 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
2524 struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i];
2525
2526 if (!key)
2527 continue;
2528
2529 mvmvif->ap_early_keys[i] = NULL;
2530
6569e7d3 2531 ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key);
c56e00a3
JB
2532 if (ret)
2533 goto out_quota_failed;
2534 }
2535
47242744
TM
2536 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2537 iwl_mvm_vif_set_low_latency(mvmvif, true,
2538 LOW_LATENCY_VIF_TYPE);
2539 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2540 }
2541
a11e144e 2542 /* power updated needs to be done before quotas */
999609f1 2543 iwl_mvm_power_update_mac(mvm);
a11e144e 2544
7754ae79 2545 ret = iwl_mvm_update_quotas(mvm, false, NULL);
8ca151b5 2546 if (ret)
a11e144e 2547 goto out_quota_failed;
8ca151b5 2548
5023d966 2549 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
8ca151b5 2550 if (vif->p2p && mvm->p2p_device_vif)
3dfd3a97 2551 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
8ca151b5 2552
8e484f0b 2553 iwl_mvm_bt_coex_vif_change(mvm);
dac94da8 2554
f697267f
AN
2555 /* we don't support TDLS during DCM */
2556 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2557 iwl_mvm_teardown_tdls_peers(mvm);
2558
b73f9a4a
JB
2559 iwl_mvm_ftm_restart_responder(mvm, vif);
2560
939e4904 2561 goto out_unlock;
8ca151b5 2562
a11e144e 2563out_quota_failed:
999609f1 2564 iwl_mvm_power_update_mac(mvm);
5691e218 2565 mvmvif->ap_ibss_active = false;
013290aa 2566 iwl_mvm_send_rm_bcast_sta(mvm, vif);
ced19f26 2567 iwl_mvm_rm_mcast_sta(mvm, vif);
8ca151b5
JB
2568out_unbind:
2569 iwl_mvm_binding_remove_vif(mvm, vif);
2570out_remove:
2571 iwl_mvm_mac_ctxt_remove(mvm, vif);
2572out_unlock:
2573 mutex_unlock(&mvm->mutex);
2574 return ret;
2575}
2576
5023d966
JB
2577static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2578 struct ieee80211_vif *vif)
8ca151b5
JB
2579{
2580 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2581 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2582
38a12b5b
JB
2583 iwl_mvm_prepare_mac_removal(mvm, vif);
2584
8ca151b5
JB
2585 mutex_lock(&mvm->mutex);
2586
664322fa 2587 /* Handle AP stop while in CSA */
7f0a7c67
AO
2588 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2589 iwl_mvm_remove_time_event(mvm, mvmvif,
2590 &mvmvif->time_event_data);
664322fa 2591 RCU_INIT_POINTER(mvm->csa_vif, NULL);
e9cb0327 2592 mvmvif->csa_countdown = false;
7f0a7c67 2593 }
664322fa 2594
003e5236
AO
2595 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2596 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2597 mvm->csa_tx_block_bcn_timeout = 0;
2598 }
2599
5023d966 2600 mvmvif->ap_ibss_active = false;
1c87bbad 2601 mvm->ap_last_beacon_gp2 = 0;
8ca151b5 2602
47242744
TM
2603 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2604 iwl_mvm_vif_set_low_latency(mvmvif, false,
2605 LOW_LATENCY_VIF_TYPE);
2606 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2607 }
2608
8e484f0b 2609 iwl_mvm_bt_coex_vif_change(mvm);
dac94da8 2610
5023d966 2611 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
8ca151b5 2612 if (vif->p2p && mvm->p2p_device_vif)
3dfd3a97 2613 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
8ca151b5 2614
7754ae79 2615 iwl_mvm_update_quotas(mvm, false, NULL);
ced19f26 2616
be82ecd3
AS
2617 iwl_mvm_ftm_responder_clear(mvm, vif);
2618
ced19f26
SS
2619 /*
2620 * This is not very nice, but the simplest:
2621 * For older FWs removing the mcast sta before the bcast station may
2622 * cause assert 0x2b00.
2623 * This is fixed in later FW (which will stop beaconing when removing
2624 * bcast station).
2625 * So make the order of removal depend on the TLV
2626 */
2627 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2628 iwl_mvm_rm_mcast_sta(mvm, vif);
013290aa 2629 iwl_mvm_send_rm_bcast_sta(mvm, vif);
ced19f26
SS
2630 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2631 iwl_mvm_rm_mcast_sta(mvm, vif);
8ca151b5 2632 iwl_mvm_binding_remove_vif(mvm, vif);
a11e144e 2633
999609f1 2634 iwl_mvm_power_update_mac(mvm);
a11e144e 2635
8ca151b5
JB
2636 iwl_mvm_mac_ctxt_remove(mvm, vif);
2637
2638 mutex_unlock(&mvm->mutex);
2639}
2640
5023d966
JB
2641static void
2642iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2643 struct ieee80211_vif *vif,
2644 struct ieee80211_bss_conf *bss_conf,
2645 u32 changes)
8ca151b5 2646{
be2056fc 2647 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8a5e3660 2648
be2056fc
IP
2649 /* Changes will be applied when the AP/IBSS is started */
2650 if (!mvmvif->ap_ibss_active)
2651 return;
2652
863230da 2653 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
f7d8b702 2654 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
3dfd3a97 2655 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
863230da 2656 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
8a5e3660 2657
8ca151b5 2658 /* Need to send a new beacon template to the FW */
863230da
JB
2659 if (changes & BSS_CHANGED_BEACON &&
2660 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2661 IWL_WARN(mvm, "Failed updating beacon data\n");
79b7a69d 2662
b73f9a4a
JB
2663 if (changes & BSS_CHANGED_FTM_RESPONDER) {
2664 int ret = iwl_mvm_ftm_start_responder(mvm, vif);
2665
2666 if (ret)
2667 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
2668 ret);
2669 }
2670
8ca151b5
JB
2671}
2672
2673static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2674 struct ieee80211_vif *vif,
2675 struct ieee80211_bss_conf *bss_conf,
2676 u32 changes)
2677{
2678 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2679
2680 mutex_lock(&mvm->mutex);
2681
723f02ed 2682 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
c7d42480 2683 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
723f02ed 2684
8ca151b5
JB
2685 switch (vif->type) {
2686 case NL80211_IFTYPE_STATION:
2687 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2688 break;
2689 case NL80211_IFTYPE_AP:
5023d966
JB
2690 case NL80211_IFTYPE_ADHOC:
2691 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
8ca151b5 2692 break;
91b08c2d
AE
2693 case NL80211_IFTYPE_MONITOR:
2694 if (changes & BSS_CHANGED_MU_GROUPS)
2695 iwl_mvm_update_mu_groups(mvm, vif);
2696 break;
8ca151b5
JB
2697 default:
2698 /* shouldn't happen */
2699 WARN_ON_ONCE(1);
2700 }
2701
9aae43a4
JB
2702 if (changes & BSS_CHANGED_TXPOWER) {
2703 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n",
2704 bss_conf->txpower);
2705 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2706 }
2707
8ca151b5
JB
2708 mutex_unlock(&mvm->mutex);
2709}
2710
2711static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2712 struct ieee80211_vif *vif,
c56ef672 2713 struct ieee80211_scan_request *hw_req)
8ca151b5
JB
2714{
2715 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2716 int ret;
2717
6749dd80
LC
2718 if (hw_req->req.n_channels == 0 ||
2719 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
8ca151b5
JB
2720 return -EINVAL;
2721
2722 mutex_lock(&mvm->mutex);
6749dd80 2723 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
8ca151b5 2724 mutex_unlock(&mvm->mutex);
6749dd80 2725
8ca151b5
JB
2726 return ret;
2727}
2728
2729static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2730 struct ieee80211_vif *vif)
2731{
2732 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2733
2734 mutex_lock(&mvm->mutex);
2735
e7d3abab
LC
2736 /* Due to a race condition, it's possible that mac80211 asks
2737 * us to stop a hw_scan when it's already stopped. This can
2738 * happen, for instance, if we stopped the scan ourselves,
2739 * called ieee80211_scan_completed() and the userspace called
2740 * cancel scan scan before ieee80211_scan_work() could run.
2741 * To handle that, simply return if the scan is not running.
2742 */
262888fc 2743 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
c7d42480 2744 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
8ca151b5
JB
2745
2746 mutex_unlock(&mvm->mutex);
2747}
2748
2749static void
2750iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
3e56eadf 2751 struct ieee80211_sta *sta, u16 tids,
8ca151b5
JB
2752 int num_frames,
2753 enum ieee80211_frame_release_type reason,
2754 bool more_data)
2755{
2756 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
8ca151b5 2757
3e56eadf 2758 /* Called when we need to transmit (a) frame(s) from mac80211 */
8ca151b5 2759
3e56eadf
JB
2760 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2761 tids, more_data, false);
2762}
2763
2764static void
2765iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2766 struct ieee80211_sta *sta, u16 tids,
2767 int num_frames,
2768 enum ieee80211_frame_release_type reason,
2769 bool more_data)
2770{
2771 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2772
9a3fcf91 2773 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
3e56eadf
JB
2774
2775 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2776 tids, more_data, true);
8ca151b5
JB
2777}
2778
65e25482
JB
2779static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2780 enum sta_notify_cmd cmd,
2781 struct ieee80211_sta *sta)
8ca151b5
JB
2782{
2783 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5b577a90 2784 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
c22b0ff5 2785 unsigned long txqs = 0, tids = 0;
3e56eadf 2786 int tid;
8ca151b5 2787
960f864b
JB
2788 /*
2789 * If we have TVQM then we get too high queue numbers - luckily
2790 * we really shouldn't get here with that because such hardware
2791 * should have firmware supporting buffer station offload.
2792 */
2793 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2794 return;
2795
c22b0ff5 2796 spin_lock_bh(&mvmsta->lock);
311590a3 2797 for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) {
c22b0ff5
EG
2798 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2799
6862fcee 2800 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
1c17627b
SS
2801 continue;
2802
c22b0ff5
EG
2803 __set_bit(tid_data->txq_id, &txqs);
2804
dd32162d 2805 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
c22b0ff5
EG
2806 continue;
2807
2808 __set_bit(tid, &tids);
2809 }
2810
8ca151b5
JB
2811 switch (cmd) {
2812 case STA_NOTIFY_SLEEP:
c22b0ff5 2813 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
3e56eadf 2814 ieee80211_sta_set_buffered(sta, tid, true);
c22b0ff5
EG
2815
2816 if (txqs)
2817 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
8ca151b5
JB
2818 /*
2819 * The fw updates the STA to be asleep. Tx packets on the Tx
2820 * queues to this station will not be transmitted. The fw will
2821 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2822 */
2823 break;
2824 case STA_NOTIFY_AWAKE:
0ae98812 2825 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
8ca151b5 2826 break;
c22b0ff5
EG
2827
2828 if (txqs)
2829 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
9cc40712 2830 iwl_mvm_sta_modify_ps_wake(mvm, sta);
8ca151b5
JB
2831 break;
2832 default:
2833 break;
2834 }
c22b0ff5 2835 spin_unlock_bh(&mvmsta->lock);
8ca151b5
JB
2836}
2837
65e25482
JB
2838static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2839 struct ieee80211_vif *vif,
2840 enum sta_notify_cmd cmd,
2841 struct ieee80211_sta *sta)
2842{
2843 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2844}
2845
2846void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2847{
2848 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2849 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2850 struct ieee80211_sta *sta;
2851 struct iwl_mvm_sta *mvmsta;
2852 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2853
be9ae34e 2854 if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations))
65e25482
JB
2855 return;
2856
2857 rcu_read_lock();
a9560029 2858 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
65e25482
JB
2859 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2860 rcu_read_unlock();
2861 return;
2862 }
2863
2864 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2865
2866 if (!mvmsta->vif ||
2867 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2868 rcu_read_unlock();
2869 return;
2870 }
2871
2872 if (mvmsta->sleeping != sleeping) {
2873 mvmsta->sleeping = sleeping;
2874 __iwl_mvm_mac_sta_notify(mvm->hw,
2875 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2876 sta);
2877 ieee80211_sta_ps_transition(sta, sleeping);
2878 }
2879
2880 if (sleeping) {
2881 switch (notif->type) {
2882 case IWL_MVM_PM_EVENT_AWAKE:
2883 case IWL_MVM_PM_EVENT_ASLEEP:
2884 break;
2885 case IWL_MVM_PM_EVENT_UAPSD:
2886 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2887 break;
2888 case IWL_MVM_PM_EVENT_PS_POLL:
2889 ieee80211_sta_pspoll(sta);
2890 break;
2891 default:
2892 break;
2893 }
2894 }
2895
2896 rcu_read_unlock();
2897}
2898
1ddbbb0c
JB
2899static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2900 struct ieee80211_vif *vif,
2901 struct ieee80211_sta *sta)
2902{
2903 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
9d8ce6af 2904 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1ddbbb0c
JB
2905
2906 /*
2907 * This is called before mac80211 does RCU synchronisation,
2908 * so here we already invalidate our internal RCU-protected
2909 * station pointer. The rest of the code will thus no longer
2910 * be able to find the station this way, and we don't rely
2911 * on further RCU synchronisation after the sta_state()
2912 * callback deleted the station.
2913 */
2914 mutex_lock(&mvm->mutex);
2915 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2916 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2917 ERR_PTR(-ENOENT));
94939080 2918
1ddbbb0c
JB
2919 mutex_unlock(&mvm->mutex);
2920}
2921
bd1ba664
JB
2922static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2923 const u8 *bssid)
2924{
b0ffe455
JB
2925 int i;
2926
2927 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2928 struct iwl_mvm_tcm_mac *mdata;
2929
2930 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2931 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2932 mdata->opened_rx_ba_sessions = false;
2933 }
2934
bd1ba664
JB
2935 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2936 return;
2937
c5241b0c 2938 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
cee5a882
AA
2939 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2940 return;
2941 }
2942
11dee0b4
EG
2943 if (!vif->p2p &&
2944 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
bd1ba664
JB
2945 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2946 return;
2947 }
2948
b0ffe455
JB
2949 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2950 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2951 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2952 return;
2953 }
2954 }
2955
bd1ba664
JB
2956 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2957}
2958
1e8f1329
GBA
2959static void
2960iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2961 struct ieee80211_vif *vif, u8 *peer_addr,
2962 enum nl80211_tdls_operation action)
2963{
2964 struct iwl_fw_dbg_trigger_tlv *trig;
2965 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2966
6c042d75
SS
2967 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
2968 FW_DBG_TRIGGER_TDLS);
2969 if (!trig)
1e8f1329
GBA
2970 return;
2971
1e8f1329 2972 tdls_trig = (void *)trig->data;
1e8f1329
GBA
2973
2974 if (!(tdls_trig->action_bitmap & BIT(action)))
2975 return;
2976
2977 if (tdls_trig->peer_mode &&
2978 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2979 return;
2980
7174beb6
JB
2981 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2982 "TDLS event occurred, peer %pM, action %d",
2983 peer_addr, action);
1e8f1329
GBA
2984}
2985
4f58121d
IP
2986struct iwl_mvm_he_obss_narrow_bw_ru_data {
2987 bool tolerated;
2988};
2989
2990static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy,
2991 struct cfg80211_bss *bss,
2992 void *_data)
2993{
2994 struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data;
6c608cd6 2995 const struct cfg80211_bss_ies *ies;
4f58121d
IP
2996 const struct element *elem;
2997
6c608cd6
JB
2998 rcu_read_lock();
2999 ies = rcu_dereference(bss->ies);
3000 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data,
3001 ies->len);
4f58121d
IP
3002
3003 if (!elem || elem->datalen < 10 ||
3004 !(elem->data[10] &
3005 WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) {
3006 data->tolerated = false;
3007 }
6c608cd6 3008 rcu_read_unlock();
4f58121d
IP
3009}
3010
3011static void iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw,
3012 struct ieee80211_vif *vif)
3013{
3014 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3015 struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = {
3016 .tolerated = true,
3017 };
3018
3019 if (!(vif->bss_conf.chandef.chan->flags & IEEE80211_CHAN_RADAR)) {
3020 mvmvif->he_ru_2mhz_block = false;
3021 return;
3022 }
3023
3024 cfg80211_bss_iter(hw->wiphy, &vif->bss_conf.chandef,
3025 iwl_mvm_check_he_obss_narrow_bw_ru_iter,
3026 &iter_data);
3027
3028 /*
3029 * If there is at least one AP on radar channel that cannot
3030 * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
3031 */
3032 mvmvif->he_ru_2mhz_block = !iter_data.tolerated;
3033}
3034
f7d6ef33
JB
3035static void iwl_mvm_reset_cca_40mhz_workaround(struct iwl_mvm *mvm,
3036 struct ieee80211_vif *vif)
3037{
3038 struct ieee80211_supported_band *sband;
3039 const struct ieee80211_sta_he_cap *he_cap;
3040
3041 if (vif->type != NL80211_IFTYPE_STATION)
3042 return;
3043
3044 if (!mvm->cca_40mhz_workaround)
3045 return;
3046
3047 /* decrement and check that we reached zero */
3048 mvm->cca_40mhz_workaround--;
3049 if (mvm->cca_40mhz_workaround)
3050 return;
3051
3052 sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ];
3053
3054 sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3055
3056 he_cap = ieee80211_get_he_iftype_cap(sband,
3057 ieee80211_vif_type_p2p(vif));
3058
3059 if (he_cap) {
3060 /* we know that ours is writable */
3061 struct ieee80211_sta_he_cap *he = (void *)he_cap;
3062
3063 he->he_cap_elem.phy_cap_info[0] |=
3064 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
3065 }
3066}
3067
8ca151b5
JB
3068static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
3069 struct ieee80211_vif *vif,
3070 struct ieee80211_sta *sta,
3071 enum ieee80211_sta_state old_state,
3072 enum ieee80211_sta_state new_state)
3073{
3074 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3075 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
6ea29ce5 3076 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
8ca151b5
JB
3077 int ret;
3078
3079 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
3080 sta->addr, old_state, new_state);
3081
3082 /* this would be a mac80211 bug ... but don't crash */
3083 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
fe56d05e 3084 return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL;
8ca151b5 3085
24afba76
LK
3086 /*
3087 * If we are in a STA removal flow and in DQA mode:
3088 *
3089 * This is after the sync_rcu part, so the queues have already been
3090 * flushed. No more TXs on their way in mac80211's path, and no more in
3091 * the queues.
3092 * Also, we won't be getting any new TX frames for this station.
3093 * What we might have are deferred TX frames that need to be taken care
3094 * of.
3095 *
3096 * Drop any still-queued deferred-frame before removing the STA, and
3097 * make sure the worker is no longer handling frames for this STA.
3098 */
3099 if (old_state == IEEE80211_STA_NONE &&
c8f54701 3100 new_state == IEEE80211_STA_NOTEXIST) {
24afba76
LK
3101 flush_work(&mvm->add_stream_wk);
3102
3103 /*
3104 * No need to make sure deferred TX indication is off since the
3105 * worker will already remove it if it was on
3106 */
f7d6ef33
JB
3107
3108 /*
3109 * Additionally, reset the 40 MHz capability if we disconnected
3110 * from the AP now.
3111 */
3112 iwl_mvm_reset_cca_40mhz_workaround(mvm, vif);
24afba76
LK
3113 }
3114
8ca151b5 3115 mutex_lock(&mvm->mutex);
6ea29ce5 3116 /* track whether or not the station is associated */
d94c5a82 3117 mvm_sta->sta_state = new_state;
6ea29ce5 3118
8ca151b5
JB
3119 if (old_state == IEEE80211_STA_NOTEXIST &&
3120 new_state == IEEE80211_STA_NONE) {
48bc1307
JB
3121 /*
3122 * Firmware bug - it'll crash if the beacon interval is less
3123 * than 16. We can't avoid connecting at all, so refuse the
3124 * station state change, this will cause mac80211 to abandon
3125 * attempts to connect to this AP, and eventually wpa_s will
cdaba917 3126 * blocklist the AP...
48bc1307
JB
3127 */
3128 if (vif->type == NL80211_IFTYPE_STATION &&
3129 vif->bss_conf.beacon_int < 16) {
3130 IWL_ERR(mvm,
3131 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
3132 sta->addr, vif->bss_conf.beacon_int);
3133 ret = -EINVAL;
3134 goto out_unlock;
3135 }
cf7b491d 3136
97cc1694
AS
3137 if (vif->type == NL80211_IFTYPE_STATION)
3138 vif->bss_conf.he_support = sta->he_cap.has_he;
3139
cf7b491d
AN
3140 if (sta->tdls &&
3141 (vif->p2p ||
fa3d07e4
AN
3142 iwl_mvm_tdls_sta_count(mvm, NULL) ==
3143 IWL_MVM_TDLS_STA_COUNT ||
cf7b491d
AN
3144 iwl_mvm_phy_ctx_count(mvm) > 1)) {
3145 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
3146 ret = -EBUSY;
3147 goto out_unlock;
3148 }
3149
8ca151b5 3150 ret = iwl_mvm_add_sta(mvm, vif, sta);
1e8f1329 3151 if (sta->tdls && ret == 0) {
fa3d07e4 3152 iwl_mvm_recalc_tdls_state(mvm, vif, true);
1e8f1329
GBA
3153 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3154 NL80211_TDLS_SETUP);
3155 }
438af969
SS
3156
3157 sta->max_rc_amsdu_len = 1;
8ca151b5
JB
3158 } else if (old_state == IEEE80211_STA_NONE &&
3159 new_state == IEEE80211_STA_AUTH) {
e820c2da
HD
3160 /*
3161 * EBS may be disabled due to previous failures reported by FW.
3162 * Reset EBS status here assuming environment has been changed.
3163 */
3164 mvm->last_ebs_successful = true;
bd1ba664 3165 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
8ca151b5
JB
3166 ret = 0;
3167 } else if (old_state == IEEE80211_STA_AUTH &&
3168 new_state == IEEE80211_STA_ASSOC) {
8be30c13 3169 if (vif->type == NL80211_IFTYPE_AP) {
9394662a 3170 vif->bss_conf.he_support = sta->he_cap.has_he;
8be30c13
AB
3171 mvmvif->ap_assoc_sta_count++;
3172 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
02221a81
ST
3173 if (vif->bss_conf.he_support &&
3174 !iwlwifi_mod_params.disable_11ax)
3175 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id);
9394662a
LK
3176 } else if (vif->type == NL80211_IFTYPE_STATION) {
3177 vif->bss_conf.he_support = sta->he_cap.has_he;
4f58121d
IP
3178
3179 mvmvif->he_ru_2mhz_block = false;
3180 if (sta->he_cap.has_he)
3181 iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif);
3182
9394662a 3183 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
8be30c13 3184 }
735a0045 3185
3baf7528
AS
3186 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3187 false);
7a453973 3188 ret = iwl_mvm_update_sta(mvm, vif, sta);
8ca151b5
JB
3189 } else if (old_state == IEEE80211_STA_ASSOC &&
3190 new_state == IEEE80211_STA_AUTHORIZED) {
475c6bde 3191 ret = 0;
f59e0e3c
AN
3192
3193 /* we don't support TDLS during DCM */
3194 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3195 iwl_mvm_teardown_tdls_peers(mvm);
3196
4634b176 3197 if (sta->tdls) {
1e8f1329
GBA
3198 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3199 NL80211_TDLS_ENABLE_LINK);
4634b176
JB
3200 } else {
3201 /* enable beacon filtering */
3202 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
1e8f1329 3203
4634b176
JB
3204 /*
3205 * Now that the station is authorized, i.e., keys were already
3206 * installed, need to indicate to the FW that
3207 * multicast data frames can be forwarded to the driver
3208 */
3209 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3210 }
50f56044 3211
3baf7528
AS
3212 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3213 true);
8ca151b5
JB
3214 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3215 new_state == IEEE80211_STA_ASSOC) {
4634b176
JB
3216 if (!sta->tdls) {
3217 /* Multicast data frames are no longer allowed */
3218 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
50f56044 3219
4634b176
JB
3220 /* disable beacon filtering */
3221 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3222 WARN_ON(ret &&
3223 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3224 &mvm->status));
3225 }
8ca151b5
JB
3226 ret = 0;
3227 } else if (old_state == IEEE80211_STA_ASSOC &&
3228 new_state == IEEE80211_STA_AUTH) {
8be30c13
AB
3229 if (vif->type == NL80211_IFTYPE_AP) {
3230 mvmvif->ap_assoc_sta_count--;
3231 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3232 }
8ca151b5
JB
3233 ret = 0;
3234 } else if (old_state == IEEE80211_STA_AUTH &&
3235 new_state == IEEE80211_STA_NONE) {
3236 ret = 0;
3237 } else if (old_state == IEEE80211_STA_NONE &&
3238 new_state == IEEE80211_STA_NOTEXIST) {
3239 ret = iwl_mvm_rm_sta(mvm, vif, sta);
1e8f1329 3240 if (sta->tdls) {
fa3d07e4 3241 iwl_mvm_recalc_tdls_state(mvm, vif, false);
1e8f1329
GBA
3242 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3243 NL80211_TDLS_DISABLE_LINK);
3244 }
34a880d8 3245
44135b7c
IP
3246 if (unlikely(ret &&
3247 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3248 &mvm->status)))
3249 ret = 0;
8ca151b5
JB
3250 } else {
3251 ret = -EIO;
3252 }
48bc1307 3253 out_unlock:
8ca151b5
JB
3254 mutex_unlock(&mvm->mutex);
3255
9c126cd6
LK
3256 if (sta->tdls && ret == 0) {
3257 if (old_state == IEEE80211_STA_NOTEXIST &&
3258 new_state == IEEE80211_STA_NONE)
3259 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3260 else if (old_state == IEEE80211_STA_NONE &&
3261 new_state == IEEE80211_STA_NOTEXIST)
3262 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3263 }
3264
8ca151b5
JB
3265 return ret;
3266}
3267
3268static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3269{
3270 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3271
3272 mvm->rts_threshold = value;
3273
3274 return 0;
3275}
3276
1f3b0ff8
LE
3277static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3278 struct ieee80211_vif *vif,
3279 struct ieee80211_sta *sta, u32 changed)
3280{
3281 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
dcfe3b10
JB
3282 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3283
3284 if (changed & (IEEE80211_RC_BW_CHANGED |
3285 IEEE80211_RC_SUPP_RATES_CHANGED |
3286 IEEE80211_RC_NSS_CHANGED))
3287 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3288 true);
1f3b0ff8
LE
3289
3290 if (vif->type == NL80211_IFTYPE_STATION &&
3291 changed & IEEE80211_RC_NSS_CHANGED)
3292 iwl_mvm_sf_update(mvm, vif, false);
3293}
3294
8ca151b5
JB
3295static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3296 struct ieee80211_vif *vif, u16 ac,
3297 const struct ieee80211_tx_queue_params *params)
3298{
3299 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3300 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3301
3302 mvmvif->queue_params[ac] = *params;
3303
3304 /*
3305 * No need to update right away, we'll get BSS_CHANGED_QOS
3306 * The exception is P2P_DEVICE interface which needs immediate update.
3307 */
3308 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3309 int ret;
3310
3311 mutex_lock(&mvm->mutex);
3dfd3a97 3312 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
8ca151b5
JB
3313 mutex_unlock(&mvm->mutex);
3314 return ret;
3315 }
3316 return 0;
3317}
3318
3319static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
d4e36e55 3320 struct ieee80211_vif *vif,
15fae341 3321 struct ieee80211_prep_tx_info *info)
8ca151b5
JB
3322{
3323 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
7c70fee5
SS
3324 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3325 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
8ca151b5 3326
15fae341
JB
3327 if (info->duration > duration)
3328 duration = info->duration;
d4e36e55 3329
8ca151b5 3330 mutex_lock(&mvm->mutex);
fe959c7b
EG
3331 /* Try really hard to protect the session and hear a beacon
3332 * The new session protection command allows us to protect the
3333 * session for a much longer time since the firmware will internally
3334 * create two events: a 300TU one with a very high priority that
3335 * won't be fragmented which should be enough for 99% of the cases,
3336 * and another one (which we configure here to be 900TU long) which
3337 * will have a slightly lower priority, but more importantly, can be
3338 * fragmented so that it'll allow other activities to run.
3339 */
3340 if (fw_has_capa(&mvm->fw->ucode_capa,
3341 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD))
3342 iwl_mvm_schedule_session_protection(mvm, vif, 900,
b5b878e3 3343 min_duration, false);
fe959c7b
EG
3344 else
3345 iwl_mvm_protect_session(mvm, vif, duration,
3346 min_duration, 500, false);
8ca151b5
JB
3347 mutex_unlock(&mvm->mutex);
3348}
3349
6b1259d1
JB
3350static void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw,
3351 struct ieee80211_vif *vif,
3352 struct ieee80211_prep_tx_info *info)
3353{
3354 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3355
3356 /* for successful cases (auth/assoc), don't cancel session protection */
3357 if (info->success)
3358 return;
3359
3360 mutex_lock(&mvm->mutex);
3361 iwl_mvm_stop_session_protection(mvm, vif);
3362 mutex_unlock(&mvm->mutex);
3363}
3364
35a000b7
DS
3365static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3366 struct ieee80211_vif *vif,
3367 struct cfg80211_sched_scan_request *req,
633e2713 3368 struct ieee80211_scan_ies *ies)
35a000b7
DS
3369{
3370 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
35a000b7 3371
35a000b7 3372 int ret;
4660dfbb 3373
35a000b7
DS
3374 mutex_lock(&mvm->mutex);
3375
1f940386 3376 if (!vif->bss_conf.idle) {
bd5e4744
DS
3377 ret = -EBUSY;
3378 goto out;
3379 }
3380
19945dfb 3381 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
d2496221 3382
35a000b7
DS
3383out:
3384 mutex_unlock(&mvm->mutex);
3385 return ret;
3386}
3387
37e3308c
JB
3388static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3389 struct ieee80211_vif *vif)
35a000b7
DS
3390{
3391 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
33ea27f6 3392 int ret;
35a000b7
DS
3393
3394 mutex_lock(&mvm->mutex);
e7d3abab
LC
3395
3396 /* Due to a race condition, it's possible that mac80211 asks
3397 * us to stop a sched_scan when it's already stopped. This
3398 * can happen, for instance, if we stopped the scan ourselves,
3399 * called ieee80211_sched_scan_stopped() and the userspace called
3400 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3401 * could run. To handle this, simply return if the scan is
3402 * not running.
3403 */
262888fc 3404 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
e7d3abab
LC
3405 mutex_unlock(&mvm->mutex);
3406 return 0;
3407 }
3408
c7d42480 3409 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
35a000b7 3410 mutex_unlock(&mvm->mutex);
33ea27f6 3411 iwl_mvm_wait_for_async_handlers(mvm);
37e3308c 3412
33ea27f6 3413 return ret;
35a000b7
DS
3414}
3415
6569e7d3
JB
3416static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3417 enum set_key_cmd cmd,
3418 struct ieee80211_vif *vif,
3419 struct ieee80211_sta *sta,
3420 struct ieee80211_key_conf *key)
8ca151b5 3421{
c56e00a3 3422 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8ca151b5 3423 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
f5e28eac
JB
3424 struct iwl_mvm_sta *mvmsta;
3425 struct iwl_mvm_key_pn *ptk_pn;
3426 int keyidx = key->keyidx;
c56e00a3 3427 int ret, i;
d6ee54a9 3428 u8 key_offset;
8ca151b5 3429
8ca151b5
JB
3430 switch (key->cipher) {
3431 case WLAN_CIPHER_SUITE_TKIP:
286ca8eb 3432 if (!mvm->trans->trans_cfg->gen2) {
7f768ad5
DS
3433 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3434 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3435 } else if (vif->type == NL80211_IFTYPE_STATION) {
3436 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3437 } else {
3438 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3439 return -EOPNOTSUPP;
3440 }
8ca151b5 3441 break;
ca8c0f4b 3442 case WLAN_CIPHER_SUITE_CCMP:
2a53d166
AB
3443 case WLAN_CIPHER_SUITE_GCMP:
3444 case WLAN_CIPHER_SUITE_GCMP_256:
85aeb58c
DS
3445 if (!iwl_mvm_has_new_tx_api(mvm))
3446 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
ca8c0f4b 3447 break;
8ca151b5 3448 case WLAN_CIPHER_SUITE_AES_CMAC:
8e160ab8
AB
3449 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3450 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
30686bf7 3451 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
8ca151b5
JB
3452 break;
3453 case WLAN_CIPHER_SUITE_WEP40:
3454 case WLAN_CIPHER_SUITE_WEP104:
475c6bde
JB
3455 if (vif->type == NL80211_IFTYPE_STATION)
3456 break;
3457 if (iwl_mvm_has_new_tx_api(mvm))
3458 return -EOPNOTSUPP;
3459 /* support HW crypto on TX */
3460 return 0;
8ca151b5 3461 default:
e36e5433
MS
3462 /* currently FW supports only one optional cipher scheme */
3463 if (hw->n_cipher_schemes &&
3464 hw->cipher_schemes->cipher == key->cipher)
3465 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3466 else
3467 return -EOPNOTSUPP;
8ca151b5
JB
3468 }
3469
8ca151b5
JB
3470 switch (cmd) {
3471 case SET_KEY:
b1fdc250
JB
3472 if (keyidx == 6 || keyidx == 7)
3473 rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6],
3474 key);
3475
5023d966
JB
3476 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3477 vif->type == NL80211_IFTYPE_AP) && !sta) {
3478 /*
3479 * GTK on AP interface is a TX-only key, return 0;
3480 * on IBSS they're per-station and because we're lazy
3481 * we don't support them for RX, so do the same.
8e160ab8 3482 * CMAC/GMAC in AP/IBSS modes must be done in software.
5023d966 3483 */
8e160ab8
AB
3484 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3485 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
a1c2ff30 3486 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) {
81279c49 3487 ret = -EOPNOTSUPP;
a1c2ff30
AO
3488 break;
3489 }
85aeb58c
DS
3490
3491 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3492 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3493 !iwl_mvm_has_new_tx_api(mvm)) {
3494 key->hw_key_idx = STA_KEY_IDX_INVALID;
a1c2ff30 3495 ret = 0;
85aeb58c
DS
3496 break;
3497 }
c56e00a3
JB
3498
3499 if (!mvmvif->ap_ibss_active) {
3500 for (i = 0;
3501 i < ARRAY_SIZE(mvmvif->ap_early_keys);
3502 i++) {
3503 if (!mvmvif->ap_early_keys[i]) {
3504 mvmvif->ap_early_keys[i] = key;
3505 break;
3506 }
3507 }
3508
3509 if (i >= ARRAY_SIZE(mvmvif->ap_early_keys))
3510 ret = -ENOSPC;
a1c2ff30
AO
3511 else
3512 ret = 0;
c56e00a3
JB
3513
3514 break;
3515 }
6caffd4f
JB
3516 }
3517
b546dcd6
JB
3518 /* During FW restart, in order to restore the state as it was,
3519 * don't try to reprogram keys we previously failed for.
3520 */
3521 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3522 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3523 IWL_DEBUG_MAC80211(mvm,
3524 "skip invalid idx key programming during restart\n");
3525 ret = 0;
3526 break;
3527 }
3528
f5e28eac
JB
3529 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3530 sta && iwl_mvm_has_new_rx_api(mvm) &&
3531 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3532 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
2a53d166
AB
3533 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3534 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
f5e28eac
JB
3535 struct ieee80211_key_seq seq;
3536 int tid, q;
3537
3538 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3539 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
acafe7e3
KC
3540 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3541 mvm->trans->num_rx_queues),
f5e28eac
JB
3542 GFP_KERNEL);
3543 if (!ptk_pn) {
3544 ret = -ENOMEM;
3545 break;
3546 }
3547
3548 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3549 ieee80211_get_key_rx_seq(key, tid, &seq);
3550 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3551 memcpy(ptk_pn->q[q].pn[tid],
3552 seq.ccmp.pn,
3553 IEEE80211_CCMP_PN_LEN);
3554 }
3555
3556 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3557 }
3558
d6ee54a9
LC
3559 /* in HW restart reuse the index, otherwise request a new one */
3560 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3561 key_offset = key->hw_key_idx;
3562 else
3563 key_offset = STA_KEY_IDX_INVALID;
3564
8ca151b5 3565 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
d6ee54a9 3566 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
8ca151b5
JB
3567 if (ret) {
3568 IWL_WARN(mvm, "set key failed\n");
475c6bde 3569 key->hw_key_idx = STA_KEY_IDX_INVALID;
8ca151b5
JB
3570 /*
3571 * can't add key for RX, but we don't need it
475c6bde
JB
3572 * in the device for TX so still return 0,
3573 * unless we have new TX API where we cannot
3574 * put key material into the TX_CMD
8ca151b5 3575 */
475c6bde
JB
3576 if (iwl_mvm_has_new_tx_api(mvm))
3577 ret = -EOPNOTSUPP;
3578 else
3579 ret = 0;
8ca151b5
JB
3580 }
3581
3582 break;
3583 case DISABLE_KEY:
b1fdc250
JB
3584 if (keyidx == 6 || keyidx == 7)
3585 RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6],
3586 NULL);
3587
c56e00a3
JB
3588 ret = -ENOENT;
3589 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
3590 if (mvmvif->ap_early_keys[i] == key) {
3591 mvmvif->ap_early_keys[i] = NULL;
3592 ret = 0;
3593 }
3594 }
3595
3596 /* found in pending list - don't do anything else */
3597 if (ret == 0)
3598 break;
3599
6caffd4f
JB
3600 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3601 ret = 0;
3602 break;
3603 }
3604
f5e28eac
JB
3605 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3606 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3607 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
2a53d166
AB
3608 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3609 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
f5e28eac
JB
3610 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3611 ptk_pn = rcu_dereference_protected(
3612 mvmsta->ptk_pn[keyidx],
3613 lockdep_is_held(&mvm->mutex));
3614 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3615 if (ptk_pn)
3616 kfree_rcu(ptk_pn, rcu_head);
3617 }
3618
8ca151b5
JB
3619 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3620 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3621 break;
3622 default:
3623 ret = -EINVAL;
3624 }
3625
6569e7d3
JB
3626 return ret;
3627}
3628
3629static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3630 enum set_key_cmd cmd,
3631 struct ieee80211_vif *vif,
3632 struct ieee80211_sta *sta,
3633 struct ieee80211_key_conf *key)
3634{
3635 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3636 int ret;
3637
3638 mutex_lock(&mvm->mutex);
3639 ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key);
8ca151b5 3640 mutex_unlock(&mvm->mutex);
6569e7d3 3641
8ca151b5
JB
3642 return ret;
3643}
3644
3645static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3646 struct ieee80211_vif *vif,
3647 struct ieee80211_key_conf *keyconf,
3648 struct ieee80211_sta *sta,
3649 u32 iv32, u16 *phase1key)
3650{
3651 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3652
5023d966
JB
3653 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3654 return;
3655
8ca151b5
JB
3656 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3657}
3658
3659
b112889c
AM
3660static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3661 struct iwl_rx_packet *pkt, void *data)
3662{
3663 struct iwl_mvm *mvm =
3664 container_of(notif_wait, struct iwl_mvm, notif_wait);
3665 struct iwl_hs20_roc_res *resp;
3666 int resp_len = iwl_rx_packet_payload_len(pkt);
3667 struct iwl_mvm_time_event_data *te_data = data;
3668
3669 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3670 return true;
3671
3672 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3673 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3674 return true;
3675 }
3676
3677 resp = (void *)pkt->data;
3678
3679 IWL_DEBUG_TE(mvm,
b71a9c35 3680 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
b112889c
AM
3681 resp->status, resp->event_unique_id);
3682
3683 te_data->uid = le32_to_cpu(resp->event_unique_id);
3684 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3685 te_data->uid);
3686
3687 spin_lock_bh(&mvm->time_event_lock);
3688 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3689 spin_unlock_bh(&mvm->time_event_lock);
3690
3691 return true;
3692}
3693
dc28e12f
MG
3694#define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3695#define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3696#define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3697#define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3698#define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
b112889c
AM
3699static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3700 struct ieee80211_channel *channel,
3701 struct ieee80211_vif *vif,
3702 int duration)
3703{
afc1e3b4 3704 int res;
b112889c
AM
3705 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3706 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
6eb031d2 3707 static const u16 time_event_response[] = { HOT_SPOT_CMD };
b112889c 3708 struct iwl_notification_wait wait_time_event;
dc28e12f
MG
3709 u32 dtim_interval = vif->bss_conf.dtim_period *
3710 vif->bss_conf.beacon_int;
3711 u32 req_dur, delay;
b112889c
AM
3712 struct iwl_hs20_roc_req aux_roc_req = {
3713 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3714 .id_and_color =
3715 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3716 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
57e861d9
DS
3717 };
3718 struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm,
3719 &aux_roc_req.channel_info);
3720 u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm);
3721
3722 /* Set the channel info data */
3723 iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value,
3717f91a 3724 iwl_mvm_phy_band_from_nl80211(channel->band),
57e861d9
DS
3725 PHY_VHT_CHANNEL_MODE20,
3726 0);
3727
3728 /* Set the time and duration */
afc1e3b4 3729 tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm));
b112889c 3730
dc28e12f
MG
3731 delay = AUX_ROC_MIN_DELAY;
3732 req_dur = MSEC_TO_TU(duration);
3733
3734 /*
3735 * If we are associated we want the delay time to be at least one
3736 * dtim interval so that the FW can wait until after the DTIM and
3737 * then start the time event, this will potentially allow us to
3738 * remain off-channel for the max duration.
3739 * Since we want to use almost a whole dtim interval we would also
3740 * like the delay to be for 2-3 dtim intervals, in case there are
3741 * other time events with higher priority.
3742 */
3743 if (vif->bss_conf.assoc) {
3744 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3745 /* We cannot remain off-channel longer than the DTIM interval */
3746 if (dtim_interval <= req_dur) {
3747 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3748 if (req_dur <= AUX_ROC_MIN_DURATION)
3749 req_dur = dtim_interval -
3750 AUX_ROC_MIN_SAFETY_BUFFER;
3751 }
3752 }
3753
57e861d9
DS
3754 tail->duration = cpu_to_le32(req_dur);
3755 tail->apply_time_max_delay = cpu_to_le32(delay);
dc28e12f
MG
3756
3757 IWL_DEBUG_TE(mvm,
903b3f9b
EG
3758 "ROC: Requesting to remain on channel %u for %ums\n",
3759 channel->hw_value, req_dur);
3760 IWL_DEBUG_TE(mvm,
3761 "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3762 duration, delay, dtim_interval);
3763
b112889c 3764 /* Set the node address */
57e861d9 3765 memcpy(tail->node_addr, vif->addr, ETH_ALEN);
b112889c 3766
a6cc5163
MG
3767 lockdep_assert_held(&mvm->mutex);
3768
3769 spin_lock_bh(&mvm->time_event_lock);
3770
3771 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3772 spin_unlock_bh(&mvm->time_event_lock);
3773 return -EIO;
3774 }
3775
b112889c
AM
3776 te_data->vif = vif;
3777 te_data->duration = duration;
3778 te_data->id = HOT_SPOT_CMD;
3779
b112889c
AM
3780 spin_unlock_bh(&mvm->time_event_lock);
3781
3782 /*
3783 * Use a notification wait, which really just processes the
3784 * command response and doesn't wait for anything, in order
3785 * to be able to process the response and get the UID inside
3786 * the RX path. Using CMD_WANT_SKB doesn't work because it
3787 * stores the buffer and then wakes up this thread, by which
3788 * time another notification (that the time event started)
3789 * might already be processed unsuccessfully.
3790 */
3791 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3792 time_event_response,
3793 ARRAY_SIZE(time_event_response),
3794 iwl_mvm_rx_aux_roc, te_data);
3795
57e861d9 3796 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len,
b112889c
AM
3797 &aux_roc_req);
3798
3799 if (res) {
3800 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3801 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3802 goto out_clear_te;
3803 }
3804
3805 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3806 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3807 /* should never fail */
3808 WARN_ON_ONCE(res);
3809
3810 if (res) {
3811 out_clear_te:
3812 spin_lock_bh(&mvm->time_event_lock);
3813 iwl_mvm_te_clear_data(mvm, te_data);
3814 spin_unlock_bh(&mvm->time_event_lock);
3815 }
3816
3817 return res;
3818}
3819
8ca151b5
JB
3820static int iwl_mvm_roc(struct ieee80211_hw *hw,
3821 struct ieee80211_vif *vif,
3822 struct ieee80211_channel *channel,
d339d5ca
IP
3823 int duration,
3824 enum ieee80211_roc_type type)
8ca151b5
JB
3825{
3826 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3 3827 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8ca151b5 3828 struct cfg80211_chan_def chandef;
31d385ae 3829 struct iwl_mvm_phy_ctxt *phy_ctxt;
8835a64f 3830 bool band_change_removal;
31d385ae
IP
3831 int ret, i;
3832
3833 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3834 duration, type);
8ca151b5 3835
9834781c
JB
3836 /*
3837 * Flush the done work, just in case it's still pending, so that
3838 * the work it does can complete and we can accept new frames.
3839 */
6ed13164
MG
3840 flush_work(&mvm->roc_done_wk);
3841
a6cc5163
MG
3842 mutex_lock(&mvm->mutex);
3843
b112889c
AM
3844 switch (vif->type) {
3845 case NL80211_IFTYPE_STATION:
859d914c
JB
3846 if (fw_has_capa(&mvm->fw->ucode_capa,
3847 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
5ac6c72e 3848 /* Use aux roc framework (HS20) */
2c2c3647
NE
3849 if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
3850 ADD_STA, 0) >= 12) {
3851 u32 lmac_id;
3852
3853 lmac_id = iwl_mvm_get_lmac_id(mvm->fw,
3854 channel->band);
3855 ret = iwl_mvm_add_aux_sta(mvm, lmac_id);
3856 if (WARN(ret,
3857 "Failed to allocate aux station"))
3858 goto out_unlock;
3859 }
5ac6c72e
LC
3860 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3861 vif, duration);
3862 goto out_unlock;
3863 }
3864 IWL_ERR(mvm, "hotspot not supported\n");
3865 ret = -EINVAL;
a6cc5163 3866 goto out_unlock;
b112889c
AM
3867 case NL80211_IFTYPE_P2P_DEVICE:
3868 /* handle below */
3869 break;
3870 default:
3871 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
a6cc5163
MG
3872 ret = -EINVAL;
3873 goto out_unlock;
8ca151b5
JB
3874 }
3875
31d385ae
IP
3876 for (i = 0; i < NUM_PHY_CTX; i++) {
3877 phy_ctxt = &mvm->phy_ctxts[i];
3878 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3879 continue;
3880
3881 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3882 /*
3883 * Unbind the P2P_DEVICE from the current PHY context,
3884 * and if the PHY context is not used remove it.
3885 */
3886 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3887 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3888 goto out_unlock;
3889
3890 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3891
3892 /* Bind the P2P_DEVICE to the current PHY Context */
3893 mvmvif->phy_ctxt = phy_ctxt;
3894
3895 ret = iwl_mvm_binding_add_vif(mvm, vif);
3896 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3897 goto out_unlock;
3898
3899 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3900 goto schedule_time_event;
3901 }
3902 }
3903
3904 /* Need to update the PHY context only if the ROC channel changed */
3905 if (channel == mvmvif->phy_ctxt->channel)
3906 goto schedule_time_event;
3907
8ca151b5 3908 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
8ca151b5 3909
31d385ae 3910 /*
8835a64f
JB
3911 * Check if the remain-on-channel is on a different band and that
3912 * requires context removal, see iwl_mvm_phy_ctxt_changed(). If
3913 * so, we'll need to release and then re-configure here, since we
3914 * must not remove a PHY context that's part of a binding.
31d385ae 3915 */
8835a64f
JB
3916 band_change_removal =
3917 fw_has_capa(&mvm->fw->ucode_capa,
3918 IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT) &&
3919 mvmvif->phy_ctxt->channel->band != chandef.chan->band;
3920
3921 if (mvmvif->phy_ctxt->ref == 1 && !band_change_removal) {
3922 /*
3923 * Change the PHY context configuration as it is currently
3924 * referenced only by the P2P Device MAC (and we can modify it)
3925 */
31d385ae
IP
3926 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3927 &chandef, 1, 1);
3928 if (ret)
3929 goto out_unlock;
3930 } else {
3931 /*
8835a64f
JB
3932 * The PHY context is shared with other MACs (or we're trying to
3933 * switch bands), so remove the P2P Device from the binding,
3934 * allocate an new PHY context and create a new binding.
31d385ae
IP
3935 */
3936 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3937 if (!phy_ctxt) {
3938 ret = -ENOSPC;
3939 goto out_unlock;
3940 }
3941
3942 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3943 1, 1);
3944 if (ret) {
3945 IWL_ERR(mvm, "Failed to change PHY context\n");
3946 goto out_unlock;
3947 }
3948
3949 /* Unbind the P2P_DEVICE from the current PHY context */
3950 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3951 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3952 goto out_unlock;
3953
3954 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3955
3956 /* Bind the P2P_DEVICE to the new allocated PHY context */
3957 mvmvif->phy_ctxt = phy_ctxt;
3958
3959 ret = iwl_mvm_binding_add_vif(mvm, vif);
3960 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3961 goto out_unlock;
3962
3963 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3964 }
3965
3966schedule_time_event:
8ca151b5 3967 /* Schedule the time events */
e635c797 3968 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
8ca151b5 3969
31d385ae 3970out_unlock:
8ca151b5
JB
3971 mutex_unlock(&mvm->mutex);
3972 IWL_DEBUG_MAC80211(mvm, "leave\n");
8ca151b5
JB
3973 return ret;
3974}
3975
5db4c4b9
EG
3976static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw,
3977 struct ieee80211_vif *vif)
8ca151b5
JB
3978{
3979 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3980
3981 IWL_DEBUG_MAC80211(mvm, "enter\n");
3982
3983 mutex_lock(&mvm->mutex);
fe959c7b 3984 iwl_mvm_stop_roc(mvm, vif);
8ca151b5
JB
3985 mutex_unlock(&mvm->mutex);
3986
3987 IWL_DEBUG_MAC80211(mvm, "leave\n");
3988 return 0;
3989}
3990
b73f9a4a
JB
3991struct iwl_mvm_ftm_responder_iter_data {
3992 bool responder;
3993 struct ieee80211_chanctx_conf *ctx;
3994};
3995
3996static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac,
3997 struct ieee80211_vif *vif)
3998{
3999 struct iwl_mvm_ftm_responder_iter_data *data = _data;
4000
4001 if (rcu_access_pointer(vif->chanctx_conf) == data->ctx &&
4002 vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params)
4003 data->responder = true;
4004}
4005
4006static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm,
4007 struct ieee80211_chanctx_conf *ctx)
4008{
4009 struct iwl_mvm_ftm_responder_iter_data data = {
4010 .responder = false,
4011 .ctx = ctx,
4012 };
4013
4014 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
4015 IEEE80211_IFACE_ITER_NORMAL,
4016 iwl_mvm_ftm_responder_chanctx_iter,
4017 &data);
4018 return data.responder;
4019}
4020
b08c1d97
LC
4021static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
4022 struct ieee80211_chanctx_conf *ctx)
8ca151b5 4023{
fe0f2de3
IP
4024 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4025 struct iwl_mvm_phy_ctxt *phy_ctxt;
b73f9a4a
JB
4026 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4027 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
8ca151b5
JB
4028 int ret;
4029
b08c1d97
LC
4030 lockdep_assert_held(&mvm->mutex);
4031
53a9d61e 4032 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
fe0f2de3 4033
fe0f2de3
IP
4034 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
4035 if (!phy_ctxt) {
4036 ret = -ENOSPC;
4037 goto out;
4038 }
8ca151b5 4039
b73f9a4a 4040 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
53a9d61e
IP
4041 ctx->rx_chains_static,
4042 ctx->rx_chains_dynamic);
fe0f2de3
IP
4043 if (ret) {
4044 IWL_ERR(mvm, "Failed to add PHY context\n");
4045 goto out;
4046 }
4047
53a9d61e 4048 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
fe0f2de3
IP
4049 *phy_ctxt_id = phy_ctxt->id;
4050out:
b08c1d97
LC
4051 return ret;
4052}
4053
4054static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
4055 struct ieee80211_chanctx_conf *ctx)
4056{
4057 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4058 int ret;
4059
4060 mutex_lock(&mvm->mutex);
4061 ret = __iwl_mvm_add_chanctx(mvm, ctx);
8ca151b5 4062 mutex_unlock(&mvm->mutex);
b08c1d97 4063
8ca151b5
JB
4064 return ret;
4065}
4066
b08c1d97
LC
4067static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
4068 struct ieee80211_chanctx_conf *ctx)
4069{
4070 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4071 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4072
4073 lockdep_assert_held(&mvm->mutex);
4074
4075 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
4076}
4077
8ca151b5
JB
4078static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
4079 struct ieee80211_chanctx_conf *ctx)
4080{
4081 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
8ca151b5
JB
4082
4083 mutex_lock(&mvm->mutex);
b08c1d97 4084 __iwl_mvm_remove_chanctx(mvm, ctx);
8ca151b5
JB
4085 mutex_unlock(&mvm->mutex);
4086}
4087
4088static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
4089 struct ieee80211_chanctx_conf *ctx,
4090 u32 changed)
4091{
4092 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
fe0f2de3
IP
4093 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4094 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
b73f9a4a
JB
4095 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4096 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
8ca151b5 4097
31d385ae
IP
4098 if (WARN_ONCE((phy_ctxt->ref > 1) &&
4099 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
4100 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
2dceedae
AN
4101 IEEE80211_CHANCTX_CHANGE_RADAR |
4102 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
31d385ae
IP
4103 "Cannot change PHY. Ref=%d, changed=0x%X\n",
4104 phy_ctxt->ref, changed))
4105 return;
4106
8ca151b5 4107 mutex_lock(&mvm->mutex);
7a20bcce
EG
4108
4109 /* we are only changing the min_width, may be a noop */
4110 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
b73f9a4a 4111 if (phy_ctxt->width == def->width)
7a20bcce
EG
4112 goto out_unlock;
4113
4114 /* we are just toggling between 20_NOHT and 20 */
4115 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
b73f9a4a 4116 def->width <= NL80211_CHAN_WIDTH_20)
7a20bcce
EG
4117 goto out_unlock;
4118 }
4119
4d66449a 4120 iwl_mvm_bt_coex_vif_change(mvm);
b73f9a4a 4121 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
8ca151b5
JB
4122 ctx->rx_chains_static,
4123 ctx->rx_chains_dynamic);
7a20bcce
EG
4124
4125out_unlock:
8ca151b5
JB
4126 mutex_unlock(&mvm->mutex);
4127}
4128
b08c1d97
LC
4129static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
4130 struct ieee80211_vif *vif,
f0c97783
LC
4131 struct ieee80211_chanctx_conf *ctx,
4132 bool switching_chanctx)
8ca151b5 4133{
fe0f2de3
IP
4134 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4135 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
8ca151b5
JB
4136 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4137 int ret;
4138
b08c1d97 4139 lockdep_assert_held(&mvm->mutex);
8ca151b5 4140
fe0f2de3 4141 mvmvif->phy_ctxt = phy_ctxt;
8ca151b5
JB
4142
4143 switch (vif->type) {
4144 case NL80211_IFTYPE_AP:
4741dd04
LC
4145 /* only needed if we're switching chanctx (i.e. during CSA) */
4146 if (switching_chanctx) {
bd3398e2
AO
4147 mvmvif->ap_ibss_active = true;
4148 break;
4149 }
5a2abdca 4150 fallthrough;
5023d966 4151 case NL80211_IFTYPE_ADHOC:
8ca151b5
JB
4152 /*
4153 * The AP binding flow is handled as part of the start_ap flow
5023d966 4154 * (in bss_info_changed), similarly for IBSS.
8ca151b5
JB
4155 */
4156 ret = 0;
b08c1d97 4157 goto out;
8ca151b5 4158 case NL80211_IFTYPE_STATION:
19125cb0 4159 mvmvif->csa_bcn_pending = false;
2533edce 4160 break;
8ca151b5 4161 case NL80211_IFTYPE_MONITOR:
2533edce
LC
4162 /* always disable PS when a monitor interface is active */
4163 mvmvif->ps_disabled = true;
8ca151b5
JB
4164 break;
4165 default:
4166 ret = -EINVAL;
b08c1d97 4167 goto out;
8ca151b5
JB
4168 }
4169
4170 ret = iwl_mvm_binding_add_vif(mvm, vif);
4171 if (ret)
b08c1d97 4172 goto out;
8ca151b5
JB
4173
4174 /*
92d85562
AB
4175 * Power state must be updated before quotas,
4176 * otherwise fw will complain.
4177 */
999609f1 4178 iwl_mvm_power_update_mac(mvm);
92d85562
AB
4179
4180 /* Setting the quota at this stage is only required for monitor
8ca151b5
JB
4181 * interfaces. For the other types, the bss_info changed flow
4182 * will handle quota settings.
4183 */
4184 if (vif->type == NL80211_IFTYPE_MONITOR) {
1e1391ca 4185 mvmvif->monitor_active = true;
7754ae79 4186 ret = iwl_mvm_update_quotas(mvm, false, NULL);
8ca151b5
JB
4187 if (ret)
4188 goto out_remove_binding;
0e39eb03
CRI
4189
4190 ret = iwl_mvm_add_snif_sta(mvm, vif);
4191 if (ret)
4192 goto out_remove_binding;
4193
8ca151b5
JB
4194 }
4195
bd3398e2 4196 /* Handle binding during CSA */
a57c688d 4197 if (vif->type == NL80211_IFTYPE_AP) {
7754ae79 4198 iwl_mvm_update_quotas(mvm, false, NULL);
3dfd3a97 4199 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
bd3398e2
AO
4200 }
4201
4741dd04 4202 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
74a10252 4203 mvmvif->csa_bcn_pending = true;
686e7fe1 4204
74a10252
SS
4205 if (!fw_has_capa(&mvm->fw->ucode_capa,
4206 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4207 u32 duration = 3 * vif->bss_conf.beacon_int;
686e7fe1 4208
74a10252
SS
4209 /* Protect the session to make sure we hear the first
4210 * beacon on the new channel.
4211 */
4212 iwl_mvm_protect_session(mvm, vif, duration, duration,
4213 vif->bss_conf.beacon_int / 2,
4214 true);
74a10252 4215 }
686e7fe1 4216
7754ae79 4217 iwl_mvm_update_quotas(mvm, false, NULL);
0ce04ce7
LC
4218 }
4219
b08c1d97 4220 goto out;
8ca151b5 4221
b08c1d97 4222out_remove_binding:
8ca151b5 4223 iwl_mvm_binding_remove_vif(mvm, vif);
999609f1 4224 iwl_mvm_power_update_mac(mvm);
b08c1d97 4225out:
8ca151b5
JB
4226 if (ret)
4227 mvmvif->phy_ctxt = NULL;
4228 return ret;
4229}
b08c1d97
LC
4230static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
4231 struct ieee80211_vif *vif,
4232 struct ieee80211_chanctx_conf *ctx)
8ca151b5
JB
4233{
4234 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
b08c1d97 4235 int ret;
8ca151b5
JB
4236
4237 mutex_lock(&mvm->mutex);
f0c97783 4238 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
b08c1d97
LC
4239 mutex_unlock(&mvm->mutex);
4240
4241 return ret;
4242}
4243
4244static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
4245 struct ieee80211_vif *vif,
f0c97783
LC
4246 struct ieee80211_chanctx_conf *ctx,
4247 bool switching_chanctx)
b08c1d97
LC
4248{
4249 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
f0c97783 4250 struct ieee80211_vif *disabled_vif = NULL;
b08c1d97
LC
4251
4252 lockdep_assert_held(&mvm->mutex);
8ca151b5
JB
4253 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
4254
8ca151b5 4255 switch (vif->type) {
5023d966 4256 case NL80211_IFTYPE_ADHOC:
b08c1d97 4257 goto out;
8ca151b5 4258 case NL80211_IFTYPE_MONITOR:
1e1391ca 4259 mvmvif->monitor_active = false;
2533edce 4260 mvmvif->ps_disabled = false;
0e39eb03 4261 iwl_mvm_rm_snif_sta(mvm, vif);
8ca151b5 4262 break;
bd3398e2
AO
4263 case NL80211_IFTYPE_AP:
4264 /* This part is triggered only during CSA */
4741dd04 4265 if (!switching_chanctx || !mvmvif->ap_ibss_active)
b08c1d97 4266 goto out;
bd3398e2 4267
7ef0aab6
AO
4268 mvmvif->csa_countdown = false;
4269
003e5236
AO
4270 /* Set CS bit on all the stations */
4271 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
4272
4273 /* Save blocked iface, the timeout is set on the next beacon */
4274 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
4275
bd3398e2 4276 mvmvif->ap_ibss_active = false;
f0c97783
LC
4277 break;
4278 case NL80211_IFTYPE_STATION:
4279 if (!switching_chanctx)
4280 break;
4281
4282 disabled_vif = vif;
4283
74a10252
SS
4284 if (!fw_has_capa(&mvm->fw->ucode_capa,
4285 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
4286 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
f0c97783 4287 break;
8ca151b5
JB
4288 default:
4289 break;
4290 }
4291
7754ae79 4292 iwl_mvm_update_quotas(mvm, false, disabled_vif);
1e1391ca 4293 iwl_mvm_binding_remove_vif(mvm, vif);
1c2abf72 4294
b08c1d97 4295out:
bf544e9a
SS
4296 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD) &&
4297 switching_chanctx)
4298 return;
a11e144e 4299 mvmvif->phy_ctxt = NULL;
999609f1 4300 iwl_mvm_power_update_mac(mvm);
b08c1d97
LC
4301}
4302
4303static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
4304 struct ieee80211_vif *vif,
4305 struct ieee80211_chanctx_conf *ctx)
4306{
4307 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4308
4309 mutex_lock(&mvm->mutex);
f0c97783 4310 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
8ca151b5
JB
4311 mutex_unlock(&mvm->mutex);
4312}
4313
50cc9574
LC
4314static int
4315iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
4316 struct ieee80211_vif_chanctx_switch *vifs)
b08c1d97 4317{
b08c1d97
LC
4318 int ret;
4319
b08c1d97 4320 mutex_lock(&mvm->mutex);
f0c97783 4321 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
b08c1d97
LC
4322 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
4323
4324 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
4325 if (ret) {
4326 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
4327 goto out_reassign;
4328 }
4329
f0c97783
LC
4330 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4331 true);
b08c1d97
LC
4332 if (ret) {
4333 IWL_ERR(mvm,
4334 "failed to assign new_ctx during channel switch\n");
4335 goto out_remove;
4336 }
4337
f697267f
AN
4338 /* we don't support TDLS during DCM - can be caused by channel switch */
4339 if (iwl_mvm_phy_ctx_count(mvm) > 1)
4340 iwl_mvm_teardown_tdls_peers(mvm);
4341
b08c1d97
LC
4342 goto out;
4343
4344out_remove:
4345 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
4346
4347out_reassign:
6fd1fb63 4348 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
b08c1d97
LC
4349 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
4350 goto out_restart;
4351 }
4352
6fd1fb63
LC
4353 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4354 true)) {
b08c1d97
LC
4355 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4356 goto out_restart;
4357 }
4358
4359 goto out;
4360
4361out_restart:
4362 /* things keep failing, better restart the hw */
4363 iwl_mvm_nic_restart(mvm, false);
4364
4365out:
4366 mutex_unlock(&mvm->mutex);
50cc9574
LC
4367
4368 return ret;
4369}
4370
48a256e8
LC
4371static int
4372iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
4373 struct ieee80211_vif_chanctx_switch *vifs)
4374{
4375 int ret;
4376
4377 mutex_lock(&mvm->mutex);
4378 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4379
4380 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4381 true);
4382 if (ret) {
4383 IWL_ERR(mvm,
4384 "failed to assign new_ctx during channel switch\n");
4385 goto out_reassign;
4386 }
4387
4388 goto out;
4389
4390out_reassign:
4391 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4392 true)) {
4393 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4394 goto out_restart;
4395 }
4396
4397 goto out;
4398
4399out_restart:
4400 /* things keep failing, better restart the hw */
4401 iwl_mvm_nic_restart(mvm, false);
4402
4403out:
4404 mutex_unlock(&mvm->mutex);
4405
4406 return ret;
4407}
4408
50cc9574
LC
4409static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4410 struct ieee80211_vif_chanctx_switch *vifs,
4411 int n_vifs,
4412 enum ieee80211_chanctx_switch_mode mode)
4413{
4414 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4415 int ret;
4416
4417 /* we only support a single-vif right now */
4418 if (n_vifs > 1)
4419 return -EOPNOTSUPP;
4420
4421 switch (mode) {
4422 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4423 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4424 break;
4425 case CHANCTX_SWMODE_REASSIGN_VIF:
48a256e8 4426 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
50cc9574
LC
4427 break;
4428 default:
4429 ret = -EOPNOTSUPP;
4430 break;
4431 }
4432
b08c1d97
LC
4433 return ret;
4434}
4435
2f0282db
JB
4436static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4437{
4438 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4439
4440 return mvm->ibss_manager;
4441}
4442
8ca151b5
JB
4443static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4444 struct ieee80211_sta *sta,
4445 bool set)
4446{
4447 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
9d8ce6af 4448 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
8ca151b5
JB
4449
4450 if (!mvm_sta || !mvm_sta->vif) {
4451 IWL_ERR(mvm, "Station is not associated to a vif\n");
4452 return -EINVAL;
4453 }
4454
4455 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4456}
4457
507cadf2
DS
4458#ifdef CONFIG_NL80211_TESTMODE
4459static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4460 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4461 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
f6c6ad42 4462 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
507cadf2
DS
4463};
4464
4465static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4466 struct ieee80211_vif *vif,
4467 void *data, int len)
4468{
4469 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4470 int err;
4471 u32 noa_duration;
4472
8cb08174
JB
4473 err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len,
4474 iwl_mvm_tm_policy, NULL);
507cadf2
DS
4475 if (err)
4476 return err;
4477
4478 if (!tb[IWL_MVM_TM_ATTR_CMD])
4479 return -EINVAL;
4480
4481 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4482 case IWL_MVM_TM_CMD_SET_NOA:
4483 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4484 !vif->bss_conf.enable_beacon ||
4485 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4486 return -EINVAL;
4487
4488 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4489 if (noa_duration >= vif->bss_conf.beacon_int)
4490 return -EINVAL;
4491
4492 mvm->noa_duration = noa_duration;
4493 mvm->noa_vif = vif;
4494
22b21041 4495 return iwl_mvm_update_quotas(mvm, true, NULL);
f6c6ad42
JB
4496 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4497 /* must be associated client vif - ignore authorized */
4498 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4499 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4500 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4501 return -EINVAL;
4502
4503 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
a1022927
EG
4504 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4505 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
507cadf2
DS
4506 }
4507
4508 return -EOPNOTSUPP;
4509}
4510
4511static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4512 struct ieee80211_vif *vif,
4513 void *data, int len)
4514{
4515 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4516 int err;
4517
4518 mutex_lock(&mvm->mutex);
4519 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4520 mutex_unlock(&mvm->mutex);
4521
4522 return err;
4523}
4524#endif
4525
622e3f9b
LC
4526static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4527 struct ieee80211_vif *vif,
4528 struct ieee80211_channel_switch *chsw)
4529{
4530 /* By implementing this operation, we prevent mac80211 from
4531 * starting its own channel switch timer, so that we can call
4532 * ieee80211_chswitch_done() ourselves at the right time
4533 * (which is when the absence time event starts).
4534 */
4535
4536 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4537 "dummy channel switch op\n");
4538}
4539
74a10252
SS
4540static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm,
4541 struct ieee80211_vif *vif,
4542 struct ieee80211_channel_switch *chsw)
4543{
4544 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4545 struct iwl_chan_switch_te_cmd cmd = {
4546 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4547 mvmvif->color)),
4548 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
4549 .tsf = cpu_to_le32(chsw->timestamp),
4550 .cs_count = chsw->count,
77738865 4551 .cs_mode = chsw->block_tx,
74a10252
SS
4552 };
4553
4554 lockdep_assert_held(&mvm->mutex);
4555
9cfcf71c
SS
4556 if (chsw->delay)
4557 cmd.cs_delayed_bcn_count =
4558 DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int);
4559
74a10252
SS
4560 return iwl_mvm_send_cmd_pdu(mvm,
4561 WIDE_ID(MAC_CONF_GROUP,
4562 CHANNEL_SWITCH_TIME_EVENT_CMD),
4563 0, sizeof(cmd), &cmd);
4564}
4565
0202bcf0
EG
4566static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm,
4567 struct ieee80211_vif *vif,
4568 struct ieee80211_channel_switch *chsw)
4569{
4570 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4571 u32 apply_time;
4572
4573 /* Schedule the time event to a bit before beacon 1,
4574 * to make sure we're in the new channel when the
4575 * GO/AP arrives. In case count <= 1 immediately schedule the
4576 * TE (this might result with some packet loss or connection
4577 * loss).
4578 */
4579 if (chsw->count <= 1)
4580 apply_time = 0;
4581 else
4582 apply_time = chsw->device_timestamp +
4583 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4584 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4585
4586 if (chsw->block_tx)
4587 iwl_mvm_csa_client_absent(mvm, vif);
4588
4589 if (mvmvif->bf_data.bf_enabled) {
4590 int ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4591
4592 if (ret)
4593 return ret;
4594 }
4595
4596 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4597 apply_time);
4598
4599 return 0;
4600}
4601
f6780614 4602#define IWL_MAX_CSA_BLOCK_TX 1500
f028905c
LC
4603static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4604 struct ieee80211_vif *vif,
4605 struct ieee80211_channel_switch *chsw)
bd3398e2
AO
4606{
4607 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
664322fa 4608 struct ieee80211_vif *csa_vif;
f6c34820 4609 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
f028905c 4610 int ret;
bd3398e2
AO
4611
4612 mutex_lock(&mvm->mutex);
664322fa 4613
81d62d5a
JB
4614 mvmvif->csa_failed = false;
4615
6b20d774 4616 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
f028905c 4617 chsw->chandef.center_freq1);
6b20d774 4618
7174beb6
JB
4619 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4620 ieee80211_vif_to_wdev(vif),
4621 FW_DBG_TRIGGER_CHANNEL_SWITCH);
f35d9c55 4622
6b20d774
LC
4623 switch (vif->type) {
4624 case NL80211_IFTYPE_AP:
4625 csa_vif =
4626 rcu_dereference_protected(mvm->csa_vif,
4627 lockdep_is_held(&mvm->mutex));
4628 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4629 "Another CSA is already in progress")) {
4630 ret = -EBUSY;
4631 goto out_unlock;
4632 }
4633
d3a108a4
AO
4634 /* we still didn't unblock tx. prevent new CS meanwhile */
4635 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4636 lockdep_is_held(&mvm->mutex))) {
4637 ret = -EBUSY;
4638 goto out_unlock;
4639 }
4640
6b20d774 4641 rcu_assign_pointer(mvm->csa_vif, vif);
7ef0aab6 4642
7ef0aab6
AO
4643 if (WARN_ONCE(mvmvif->csa_countdown,
4644 "Previous CSA countdown didn't complete")) {
4645 ret = -EBUSY;
4646 goto out_unlock;
4647 }
4648
d3a108a4
AO
4649 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4650
6b20d774 4651 break;
dc88b4ba 4652 case NL80211_IFTYPE_STATION:
2360acbd
EG
4653 /*
4654 * We haven't configured the firmware to be associated yet since
4655 * we don't know the dtim period. In this case, the firmware can't
4656 * track the beacons.
4657 */
4658 if (!vif->bss_conf.assoc || !vif->bss_conf.dtim_period) {
4659 ret = -EBUSY;
4660 goto out_unlock;
4661 }
4662
87d9564e
JB
4663 if (chsw->delay > IWL_MAX_CSA_BLOCK_TX)
4664 schedule_delayed_work(&mvmvif->csa_work, 0);
4665
f6780614 4666 if (chsw->block_tx) {
f6780614
SS
4667 /*
4668 * In case of undetermined / long time with immediate
4669 * quiet monitor status to gracefully disconnect
4670 */
4671 if (!chsw->count ||
4672 chsw->count * vif->bss_conf.beacon_int >
4673 IWL_MAX_CSA_BLOCK_TX)
4674 schedule_delayed_work(&mvmvif->csa_work,
4675 msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX));
4676 }
dc88b4ba 4677
0202bcf0
EG
4678 if (!fw_has_capa(&mvm->fw->ucode_capa,
4679 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4680 ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw);
c6e0a3e0
LC
4681 if (ret)
4682 goto out_unlock;
0202bcf0 4683 } else {
74a10252 4684 iwl_mvm_schedule_client_csa(mvm, vif, chsw);
0202bcf0 4685 }
81b4e44e
SS
4686
4687 mvmvif->csa_count = chsw->count;
4688 mvmvif->csa_misbehave = false;
dc88b4ba 4689 break;
6b20d774
LC
4690 default:
4691 break;
4692 }
bd3398e2 4693
f6c34820
LC
4694 mvmvif->ps_disabled = true;
4695
4696 ret = iwl_mvm_power_update_ps(mvm);
4697 if (ret)
4698 goto out_unlock;
f028905c 4699
e198f5e7
AN
4700 /* we won't be on this channel any longer */
4701 iwl_mvm_teardown_tdls_peers(mvm);
4702
bd3398e2
AO
4703out_unlock:
4704 mutex_unlock(&mvm->mutex);
f028905c
LC
4705
4706 return ret;
bd3398e2
AO
4707}
4708
c37763d2
SS
4709static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw,
4710 struct ieee80211_vif *vif,
4711 struct ieee80211_channel_switch *chsw)
f6c34820 4712{
f6c34820 4713 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
c37763d2
SS
4714 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4715 struct iwl_chan_switch_te_cmd cmd = {
4716 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4717 mvmvif->color)),
4718 .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY),
4719 .tsf = cpu_to_le32(chsw->timestamp),
4720 .cs_count = chsw->count,
77738865 4721 .cs_mode = chsw->block_tx,
c37763d2 4722 };
a57c688d 4723
c37763d2
SS
4724 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY))
4725 return;
a57c688d 4726
81b4e44e
SS
4727 if (chsw->count >= mvmvif->csa_count && chsw->block_tx) {
4728 if (mvmvif->csa_misbehave) {
4729 /* Second time, give up on this AP*/
4730 iwl_mvm_abort_channel_switch(hw, vif);
4731 ieee80211_chswitch_done(vif, false);
4732 mvmvif->csa_misbehave = false;
4733 return;
a57c688d 4734 }
81b4e44e 4735 mvmvif->csa_misbehave = true;
a57c688d 4736 }
81b4e44e 4737 mvmvif->csa_count = chsw->count;
a57c688d 4738
caf46377
SS
4739 mutex_lock(&mvm->mutex);
4740 if (mvmvif->csa_failed)
4741 goto out_unlock;
f6c34820 4742
b06b5986
EG
4743 IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d mode = %d\n",
4744 mvmvif->id, chsw->count, chsw->block_tx);
c37763d2
SS
4745 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
4746 WIDE_ID(MAC_CONF_GROUP,
4747 CHANNEL_SWITCH_TIME_EVENT_CMD),
caf46377
SS
4748 0, sizeof(cmd), &cmd));
4749out_unlock:
4750 mutex_unlock(&mvm->mutex);
f6c34820
LC
4751}
4752
6110d9e5
DS
4753static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4754{
435d0827
SS
4755 int i;
4756
06195639 4757 if (!iwl_mvm_has_new_tx_api(mvm)) {
309c4848
LC
4758 if (drop) {
4759 mutex_lock(&mvm->mutex);
6110d9e5 4760 iwl_mvm_flush_tx_path(mvm,
d4e3a341 4761 iwl_mvm_flushable_queues(mvm) & queues);
309c4848
LC
4762 mutex_unlock(&mvm->mutex);
4763 } else {
06195639 4764 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
309c4848 4765 }
435d0827
SS
4766 return;
4767 }
6110d9e5 4768
435d0827 4769 mutex_lock(&mvm->mutex);
be9ae34e 4770 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
435d0827 4771 struct ieee80211_sta *sta;
6110d9e5 4772
435d0827
SS
4773 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4774 lockdep_is_held(&mvm->mutex));
4775 if (IS_ERR_OR_NULL(sta))
4776 continue;
6110d9e5 4777
06195639 4778 if (drop)
d4e3a341 4779 iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF);
06195639
SS
4780 else
4781 iwl_mvm_wait_sta_queues_empty(mvm,
4782 iwl_mvm_sta_from_mac80211(sta));
6110d9e5 4783 }
435d0827 4784 mutex_unlock(&mvm->mutex);
6110d9e5
DS
4785}
4786
c5b0e7c0
EG
4787static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4788 struct ieee80211_vif *vif, u32 queues, bool drop)
4789{
4790 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4791 struct iwl_mvm_vif *mvmvif;
4792 struct iwl_mvm_sta *mvmsta;
a0f6bf2a
AN
4793 struct ieee80211_sta *sta;
4794 int i;
4795 u32 msk = 0;
c5b0e7c0 4796
6110d9e5
DS
4797 if (!vif) {
4798 iwl_mvm_flush_no_vif(mvm, queues, drop);
4799 return;
4800 }
4801
4802 if (vif->type != NL80211_IFTYPE_STATION)
c5b0e7c0
EG
4803 return;
4804
24afba76 4805 /* Make sure we're done with the deferred traffic before flushing */
c8f54701 4806 flush_work(&mvm->add_stream_wk);
24afba76 4807
c5b0e7c0
EG
4808 mutex_lock(&mvm->mutex);
4809 mvmvif = iwl_mvm_vif_from_mac80211(vif);
c5b0e7c0 4810
a0f6bf2a 4811 /* flush the AP-station and all TDLS peers */
be9ae34e 4812 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
a0f6bf2a
AN
4813 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4814 lockdep_is_held(&mvm->mutex));
4815 if (IS_ERR_OR_NULL(sta))
4816 continue;
4817
4818 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4819 if (mvmsta->vif != vif)
4820 continue;
4821
4822 /* make sure only TDLS peers or the AP are flushed */
4823 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4824
d49394a1 4825 if (drop) {
f9084775 4826 if (iwl_mvm_flush_sta(mvm, mvmsta, false))
d49394a1
SS
4827 IWL_ERR(mvm, "flush request fail\n");
4828 } else {
4829 msk |= mvmsta->tfd_queue_msk;
d6d517b7
SS
4830 if (iwl_mvm_has_new_tx_api(mvm))
4831 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
d49394a1 4832 }
480acbce 4833 }
c5b0e7c0 4834
d49394a1 4835 mutex_unlock(&mvm->mutex);
4e6c48e0 4836
d49394a1
SS
4837 /* this can take a while, and we may need/want other operations
4838 * to succeed while doing this, so do it without the mutex held
4839 */
d6d517b7 4840 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
a1a57877 4841 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
c5b0e7c0
EG
4842}
4843
91a8bcde
JB
4844static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4845 struct survey_info *survey)
4846{
4847 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4848 int ret;
4849
4850 memset(survey, 0, sizeof(*survey));
4851
4852 /* only support global statistics right now */
4853 if (idx != 0)
4854 return -ENOENT;
4855
280a3efa
JB
4856 if (!fw_has_capa(&mvm->fw->ucode_capa,
4857 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
91a8bcde
JB
4858 return -ENOENT;
4859
4860 mutex_lock(&mvm->mutex);
4861
aab6930d 4862 if (iwl_mvm_firmware_running(mvm)) {
33cef925 4863 ret = iwl_mvm_request_statistics(mvm, false);
91a8bcde
JB
4864 if (ret)
4865 goto out;
4866 }
4867
4868 survey->filled = SURVEY_INFO_TIME |
4869 SURVEY_INFO_TIME_RX |
4870 SURVEY_INFO_TIME_TX |
4871 SURVEY_INFO_TIME_SCAN;
4872 survey->time = mvm->accu_radio_stats.on_time_rf +
4873 mvm->radio_stats.on_time_rf;
4874 do_div(survey->time, USEC_PER_MSEC);
4875
4876 survey->time_rx = mvm->accu_radio_stats.rx_time +
4877 mvm->radio_stats.rx_time;
4878 do_div(survey->time_rx, USEC_PER_MSEC);
4879
4880 survey->time_tx = mvm->accu_radio_stats.tx_time +
4881 mvm->radio_stats.tx_time;
4882 do_div(survey->time_tx, USEC_PER_MSEC);
4883
4884 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4885 mvm->radio_stats.on_time_scan;
4886 do_div(survey->time_scan, USEC_PER_MSEC);
4887
10a7c028 4888 ret = 0;
91a8bcde
JB
4889 out:
4890 mutex_unlock(&mvm->mutex);
4891 return ret;
4892}
4893
ed780545
JB
4894static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo)
4895{
82cdbd11
MK
4896 u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
4897
4898 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
ed780545
JB
4899 case RATE_MCS_CHAN_WIDTH_20:
4900 rinfo->bw = RATE_INFO_BW_20;
4901 break;
4902 case RATE_MCS_CHAN_WIDTH_40:
4903 rinfo->bw = RATE_INFO_BW_40;
4904 break;
4905 case RATE_MCS_CHAN_WIDTH_80:
4906 rinfo->bw = RATE_INFO_BW_80;
4907 break;
4908 case RATE_MCS_CHAN_WIDTH_160:
4909 rinfo->bw = RATE_INFO_BW_160;
4910 break;
4911 }
4912
82cdbd11
MK
4913 if (format == RATE_MCS_CCK_MSK ||
4914 format == RATE_MCS_LEGACY_OFDM_MSK) {
4915 int rate = u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK);
4916
4917 /* add the offset needed to get to the legacy ofdm indices */
4918 if (format == RATE_MCS_LEGACY_OFDM_MSK)
4919 rate += IWL_FIRST_OFDM_RATE;
4920
4921 switch (rate) {
4922 case IWL_RATE_1M_INDEX:
4923 rinfo->legacy = 10;
4924 break;
4925 case IWL_RATE_2M_INDEX:
4926 rinfo->legacy = 20;
4927 break;
4928 case IWL_RATE_5M_INDEX:
4929 rinfo->legacy = 55;
4930 break;
4931 case IWL_RATE_11M_INDEX:
4932 rinfo->legacy = 110;
4933 break;
4934 case IWL_RATE_6M_INDEX:
4935 rinfo->legacy = 60;
4936 break;
4937 case IWL_RATE_9M_INDEX:
4938 rinfo->legacy = 90;
4939 break;
4940 case IWL_RATE_12M_INDEX:
4941 rinfo->legacy = 120;
4942 break;
4943 case IWL_RATE_18M_INDEX:
4944 rinfo->legacy = 180;
4945 break;
4946 case IWL_RATE_24M_INDEX:
4947 rinfo->legacy = 240;
4948 break;
4949 case IWL_RATE_36M_INDEX:
4950 rinfo->legacy = 360;
4951 break;
4952 case IWL_RATE_48M_INDEX:
4953 rinfo->legacy = 480;
4954 break;
4955 case IWL_RATE_54M_INDEX:
4956 rinfo->legacy = 540;
4957 }
4958 return;
4959 }
4960
4961 rinfo->nss = u32_get_bits(rate_n_flags,
4962 RATE_MCS_NSS_MSK) + 1;
4963 rinfo->mcs = format == RATE_MCS_HT_MSK ?
4964 RATE_HT_MCS_INDEX(rate_n_flags) :
4965 u32_get_bits(rate_n_flags, RATE_MCS_CODE_MSK);
4966
4967 if (format == RATE_MCS_HE_MSK) {
ed780545 4968 u32 gi_ltf = u32_get_bits(rate_n_flags,
82cdbd11 4969 RATE_MCS_HE_GI_LTF_MSK);
ed780545
JB
4970
4971 rinfo->flags |= RATE_INFO_FLAGS_HE_MCS;
ed780545 4972
82cdbd11 4973 if (rate_n_flags & RATE_MCS_HE_106T_MSK) {
ed780545
JB
4974 rinfo->bw = RATE_INFO_BW_HE_RU;
4975 rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106;
4976 }
4977
82cdbd11
MK
4978 switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) {
4979 case RATE_MCS_HE_TYPE_SU:
4980 case RATE_MCS_HE_TYPE_EXT_SU:
ed780545
JB
4981 if (gi_ltf == 0 || gi_ltf == 1)
4982 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
4983 else if (gi_ltf == 2)
4984 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
82cdbd11 4985 else if (gi_ltf == 3)
ed780545 4986 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
82cdbd11
MK
4987 else
4988 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
ed780545 4989 break;
82cdbd11 4990 case RATE_MCS_HE_TYPE_MU:
ed780545
JB
4991 if (gi_ltf == 0 || gi_ltf == 1)
4992 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
4993 else if (gi_ltf == 2)
4994 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
4995 else
4996 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
4997 break;
82cdbd11 4998 case RATE_MCS_HE_TYPE_TRIG:
ed780545
JB
4999 if (gi_ltf == 0 || gi_ltf == 1)
5000 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
5001 else
5002 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
5003 break;
5004 }
5005
5006 if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK)
5007 rinfo->he_dcm = 1;
82cdbd11
MK
5008 return;
5009 }
5010
5011 if (rate_n_flags & RATE_MCS_SGI_MSK)
5012 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
5013
5014 if (format == RATE_MCS_HT_MSK) {
5015 rinfo->flags |= RATE_INFO_FLAGS_MCS;
5016
5017 } else if (format == RATE_MCS_VHT_MSK) {
5018 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
ed780545 5019 }
82cdbd11 5020
ed780545
JB
5021}
5022
33cef925
JB
5023static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
5024 struct ieee80211_vif *vif,
5025 struct ieee80211_sta *sta,
5026 struct station_info *sinfo)
5027{
5028 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5029 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5030 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
5031
988b5968 5032 if (mvmsta->avg_energy) {
88ad368a 5033 sinfo->signal_avg = -(s8)mvmsta->avg_energy;
22d0d2fa 5034 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
988b5968
SS
5035 }
5036
ed780545
JB
5037 if (iwl_mvm_has_tlc_offload(mvm)) {
5038 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
5039
5040 iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate);
5041 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
5042 }
5043
33cef925
JB
5044 /* if beacon filtering isn't on mac80211 does it anyway */
5045 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
5046 return;
5047
5048 if (!vif->bss_conf.assoc)
5049 return;
5050
5051 mutex_lock(&mvm->mutex);
5052
5053 if (mvmvif->ap_sta_id != mvmsta->sta_id)
5054 goto unlock;
5055
5056 if (iwl_mvm_request_statistics(mvm, false))
5057 goto unlock;
5058
5059 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
5060 mvmvif->beacon_stats.accu_num_beacons;
22d0d2fa 5061 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
33cef925
JB
5062 if (mvmvif->beacon_stats.avg_signal) {
5063 /* firmware only reports a value after RXing a few beacons */
5064 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
22d0d2fa 5065 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
33cef925
JB
5066 }
5067 unlock:
5068 mutex_unlock(&mvm->mutex);
5069}
5070
119c2a13
MG
5071static void iwl_mvm_event_mlme_callback_ini(struct iwl_mvm *mvm,
5072 struct ieee80211_vif *vif,
5073 const struct ieee80211_mlme_event *mlme)
5074{
1a81bddf
MG
5075 if ((mlme->data == ASSOC_EVENT || mlme->data == AUTH_EVENT) &&
5076 (mlme->status == MLME_DENIED || mlme->status == MLME_TIMEOUT)) {
119c2a13
MG
5077 iwl_dbg_tlv_time_point(&mvm->fwrt,
5078 IWL_FW_INI_TIME_POINT_ASSOC_FAILED,
5079 NULL);
5080 return;
5081 }
5082
119c2a13
MG
5083 if (mlme->data == DEAUTH_RX_EVENT || mlme->data == DEAUTH_TX_EVENT) {
5084 iwl_dbg_tlv_time_point(&mvm->fwrt,
5085 IWL_FW_INI_TIME_POINT_DEASSOC,
5086 NULL);
5087 return;
5088 }
5089}
5090
4203263d
EG
5091static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
5092 struct ieee80211_vif *vif,
5093 const struct ieee80211_event *event)
d42f5350 5094{
7174beb6
JB
5095#define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
5096 do { \
5097 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
5098 break; \
5099 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
d42f5350
EG
5100 } while (0)
5101
d42f5350
EG
5102 struct iwl_fw_dbg_trigger_tlv *trig;
5103 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
d42f5350 5104
119c2a13
MG
5105 if (iwl_trans_dbg_ini_valid(mvm->trans)) {
5106 iwl_mvm_event_mlme_callback_ini(mvm, vif, &event->u.mlme);
5107 return;
5108 }
5109
6c042d75
SS
5110 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5111 FW_DBG_TRIGGER_MLME);
5112 if (!trig)
d42f5350
EG
5113 return;
5114
d42f5350 5115 trig_mlme = (void *)trig->data;
d42f5350 5116
d42f5350
EG
5117 if (event->u.mlme.data == ASSOC_EVENT) {
5118 if (event->u.mlme.status == MLME_DENIED)
4c324a51 5119 CHECK_MLME_TRIGGER(stop_assoc_denied,
d42f5350
EG
5120 "DENIED ASSOC: reason %d",
5121 event->u.mlme.reason);
5122 else if (event->u.mlme.status == MLME_TIMEOUT)
4c324a51 5123 CHECK_MLME_TRIGGER(stop_assoc_timeout,
d42f5350
EG
5124 "ASSOC TIMEOUT");
5125 } else if (event->u.mlme.data == AUTH_EVENT) {
5126 if (event->u.mlme.status == MLME_DENIED)
4c324a51 5127 CHECK_MLME_TRIGGER(stop_auth_denied,
d42f5350
EG
5128 "DENIED AUTH: reason %d",
5129 event->u.mlme.reason);
5130 else if (event->u.mlme.status == MLME_TIMEOUT)
4c324a51 5131 CHECK_MLME_TRIGGER(stop_auth_timeout,
d42f5350
EG
5132 "AUTH TIMEOUT");
5133 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4c324a51 5134 CHECK_MLME_TRIGGER(stop_rx_deauth,
d42f5350
EG
5135 "DEAUTH RX %d", event->u.mlme.reason);
5136 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4c324a51 5137 CHECK_MLME_TRIGGER(stop_tx_deauth,
d42f5350
EG
5138 "DEAUTH TX %d", event->u.mlme.reason);
5139 }
5140#undef CHECK_MLME_TRIGGER
5141}
5142
4203263d
EG
5143static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
5144 struct ieee80211_vif *vif,
5145 const struct ieee80211_event *event)
5146{
5147 struct iwl_fw_dbg_trigger_tlv *trig;
5148 struct iwl_fw_dbg_trigger_ba *ba_trig;
5149
6c042d75
SS
5150 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5151 FW_DBG_TRIGGER_BA);
5152 if (!trig)
4203263d
EG
5153 return;
5154
4203263d 5155 ba_trig = (void *)trig->data;
4203263d
EG
5156
5157 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
5158 return;
5159
7174beb6
JB
5160 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
5161 "BAR received from %pM, tid %d, ssn %d",
5162 event->u.ba.sta->addr, event->u.ba.tid,
5163 event->u.ba.ssn);
4203263d
EG
5164}
5165
4203263d
EG
5166static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
5167 struct ieee80211_vif *vif,
5168 const struct ieee80211_event *event)
5169{
5170 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5171
5172 switch (event->type) {
5173 case MLME_EVENT:
5174 iwl_mvm_event_mlme_callback(mvm, vif, event);
5175 break;
5176 case BAR_RX_EVENT:
5177 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
5178 break;
5179 case BA_FRAME_TIMEOUT:
528a542a
EG
5180 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
5181 event->u.ba.tid);
4203263d
EG
5182 break;
5183 default:
5184 break;
5185 }
5186}
5187
d0ff5d22 5188void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
5e1688ce
JB
5189 enum iwl_mvm_rxq_notif_type type,
5190 bool sync,
5191 const void *data, u32 size)
0636b938 5192{
5e1688ce
JB
5193 struct {
5194 struct iwl_rxq_sync_cmd cmd;
5195 struct iwl_mvm_internal_rxq_notif notif;
5196 } __packed cmd = {
5197 .cmd.rxq_mask = cpu_to_le32(BIT(mvm->trans->num_rx_queues) - 1),
5198 .cmd.count =
5199 cpu_to_le32(sizeof(struct iwl_mvm_internal_rxq_notif) +
5200 size),
5201 .notif.type = type,
5202 .notif.sync = sync,
5203 };
5204 struct iwl_host_cmd hcmd = {
5205 .id = WIDE_ID(DATA_PATH_GROUP, TRIGGER_RX_QUEUES_NOTIF_CMD),
5206 .data[0] = &cmd,
5207 .len[0] = sizeof(cmd),
5208 .data[1] = data,
5209 .len[1] = size,
5210 .flags = sync ? 0 : CMD_ASYNC,
5211 };
0636b938
SS
5212 int ret;
5213
5e1688ce
JB
5214 /* size must be a multiple of DWORD */
5215 if (WARN_ON(cmd.cmd.count & cpu_to_le32(3)))
5216 return;
0636b938 5217
cb8550e1 5218 if (!iwl_mvm_has_new_rx_api(mvm))
0636b938
SS
5219 return;
5220
5e1688ce
JB
5221 if (sync) {
5222 cmd.notif.cookie = mvm->queue_sync_cookie;
2f7a04c7 5223 mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1;
a2113cc4 5224 }
0636b938 5225
5e1688ce 5226 ret = iwl_mvm_send_cmd(mvm, &hcmd);
0636b938
SS
5227 if (ret) {
5228 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
5229 goto out;
5230 }
d0ff5d22 5231
5e1688ce 5232 if (sync) {
3c514bf8 5233 lockdep_assert_held(&mvm->mutex);
3a732c65 5234 ret = wait_event_timeout(mvm->rx_sync_waitq,
2f7a04c7 5235 READ_ONCE(mvm->queue_sync_state) == 0 ||
6ad04359 5236 iwl_mvm_is_radio_killed(mvm),
d0ff5d22 5237 HZ);
2f7a04c7
JB
5238 WARN_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm),
5239 "queue sync: failed to sync, state is 0x%lx\n",
5240 mvm->queue_sync_state);
6ad04359 5241 }
0636b938
SS
5242
5243out:
5e1688ce 5244 if (sync) {
5f8a3561 5245 mvm->queue_sync_state = 0;
a2113cc4 5246 mvm->queue_sync_cookie++;
5f8a3561 5247 }
0636b938
SS
5248}
5249
5250static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
5251{
5252 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5253
5254 mutex_lock(&mvm->mutex);
5e1688ce 5255 iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_EMPTY, true, NULL, 0);
0636b938
SS
5256 mutex_unlock(&mvm->mutex);
5257}
5258
b73f9a4a
JB
5259static int
5260iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw,
5261 struct ieee80211_vif *vif,
5262 struct cfg80211_ftm_responder_stats *stats)
5263{
5264 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5265 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5266
5267 if (vif->p2p || vif->type != NL80211_IFTYPE_AP ||
5268 !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder)
5269 return -EINVAL;
5270
5271 mutex_lock(&mvm->mutex);
5272 *stats = mvm->ftm_resp_stats;
5273 mutex_unlock(&mvm->mutex);
5274
5275 stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) |
5276 BIT(NL80211_FTM_STATS_PARTIAL_NUM) |
5277 BIT(NL80211_FTM_STATS_FAILED_NUM) |
5278 BIT(NL80211_FTM_STATS_ASAP_NUM) |
5279 BIT(NL80211_FTM_STATS_NON_ASAP_NUM) |
5280 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) |
5281 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) |
5282 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) |
5283 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM);
5284
5285 return 0;
5286}
5287
fc36ffda
JB
5288static int iwl_mvm_start_pmsr(struct ieee80211_hw *hw,
5289 struct ieee80211_vif *vif,
5290 struct cfg80211_pmsr_request *request)
5291{
5292 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5293 int ret;
5294
5295 mutex_lock(&mvm->mutex);
5296 ret = iwl_mvm_ftm_start(mvm, vif, request);
5297 mutex_unlock(&mvm->mutex);
5298
5299 return ret;
5300}
5301
5302static void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw,
5303 struct ieee80211_vif *vif,
5304 struct cfg80211_pmsr_request *request)
5305{
5306 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5307
5308 mutex_lock(&mvm->mutex);
5309 iwl_mvm_ftm_abort(mvm, request);
5310 mutex_unlock(&mvm->mutex);
5311}
5312
438af969
SS
5313static bool iwl_mvm_can_hw_csum(struct sk_buff *skb)
5314{
5315 u8 protocol = ip_hdr(skb)->protocol;
5316
5317 if (!IS_ENABLED(CONFIG_INET))
5318 return false;
5319
5320 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
5321}
5322
5323static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw,
5324 struct sk_buff *head,
5325 struct sk_buff *skb)
5326{
5327 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5328
5329 /* For now don't aggregate IPv6 in AMSDU */
5330 if (skb->protocol != htons(ETH_P_IP))
5331 return false;
5332
5333 if (!iwl_mvm_is_csum_supported(mvm))
5334 return true;
5335
5336 return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head);
5337}
5338
e5209263 5339const struct ieee80211_ops iwl_mvm_hw_ops = {
8ca151b5 5340 .tx = iwl_mvm_mac_tx,
cfbc6c4c 5341 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue,
8ca151b5 5342 .ampdu_action = iwl_mvm_mac_ampdu_action,
e8503aec 5343 .get_antenna = iwl_mvm_op_get_antenna,
8ca151b5 5344 .start = iwl_mvm_mac_start,
cf2c92d8 5345 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
8ca151b5
JB
5346 .stop = iwl_mvm_mac_stop,
5347 .add_interface = iwl_mvm_mac_add_interface,
5348 .remove_interface = iwl_mvm_mac_remove_interface,
5349 .config = iwl_mvm_mac_config,
e59647ea 5350 .prepare_multicast = iwl_mvm_prepare_multicast,
8ca151b5 5351 .configure_filter = iwl_mvm_configure_filter,
effd1929 5352 .config_iface_filter = iwl_mvm_config_iface_filter,
8ca151b5
JB
5353 .bss_info_changed = iwl_mvm_bss_info_changed,
5354 .hw_scan = iwl_mvm_mac_hw_scan,
5355 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
1ddbbb0c 5356 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
8ca151b5
JB
5357 .sta_state = iwl_mvm_mac_sta_state,
5358 .sta_notify = iwl_mvm_mac_sta_notify,
5359 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
3e56eadf 5360 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
8ca151b5 5361 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
1f3b0ff8 5362 .sta_rc_update = iwl_mvm_sta_rc_update,
8ca151b5
JB
5363 .conf_tx = iwl_mvm_mac_conf_tx,
5364 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
6b1259d1 5365 .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx,
07ecd897 5366 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
c5b0e7c0 5367 .flush = iwl_mvm_mac_flush,
35a000b7
DS
5368 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
5369 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
8ca151b5
JB
5370 .set_key = iwl_mvm_mac_set_key,
5371 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
5372 .remain_on_channel = iwl_mvm_roc,
5373 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
8ca151b5
JB
5374 .add_chanctx = iwl_mvm_add_chanctx,
5375 .remove_chanctx = iwl_mvm_remove_chanctx,
5376 .change_chanctx = iwl_mvm_change_chanctx,
5377 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
5378 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
b08c1d97 5379 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
8ca151b5 5380
5023d966
JB
5381 .start_ap = iwl_mvm_start_ap_ibss,
5382 .stop_ap = iwl_mvm_stop_ap_ibss,
5383 .join_ibss = iwl_mvm_start_ap_ibss,
5384 .leave_ibss = iwl_mvm_stop_ap_ibss,
8ca151b5 5385
2f0282db
JB
5386 .tx_last_beacon = iwl_mvm_tx_last_beacon,
5387
8ca151b5
JB
5388 .set_tim = iwl_mvm_set_tim,
5389
622e3f9b 5390 .channel_switch = iwl_mvm_channel_switch,
f028905c 5391 .pre_channel_switch = iwl_mvm_pre_channel_switch,
f6c34820 5392 .post_channel_switch = iwl_mvm_post_channel_switch,
79221126 5393 .abort_channel_switch = iwl_mvm_abort_channel_switch,
c37763d2 5394 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon,
bd3398e2 5395
1d3c3f63
AN
5396 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
5397 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
5398 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
5399
d42f5350
EG
5400 .event_callback = iwl_mvm_mac_event_callback,
5401
0636b938
SS
5402 .sync_rx_queues = iwl_mvm_sync_rx_queues,
5403
507cadf2
DS
5404 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
5405
8ca151b5
JB
5406#ifdef CONFIG_PM_SLEEP
5407 /* look at d3.c */
5408 .suspend = iwl_mvm_suspend,
5409 .resume = iwl_mvm_resume,
5410 .set_wakeup = iwl_mvm_set_wakeup,
5411 .set_rekey_data = iwl_mvm_set_rekey_data,
5412#if IS_ENABLED(CONFIG_IPV6)
5413 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
5414#endif
5415 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
5416#endif
91a8bcde 5417 .get_survey = iwl_mvm_mac_get_survey,
33cef925 5418 .sta_statistics = iwl_mvm_mac_sta_statistics,
b73f9a4a 5419 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats,
fc36ffda
JB
5420 .start_pmsr = iwl_mvm_start_pmsr,
5421 .abort_pmsr = iwl_mvm_abort_pmsr,
b73f9a4a 5422
438af969 5423 .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate,
177a11cf
GG
5424#ifdef CONFIG_IWLWIFI_DEBUGFS
5425 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,
5426#endif
8ca151b5 5427};