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