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