1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2012-2014, 2018-2024 Intel Corporation
4 * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5 * Copyright (C) 2016-2017 Intel Deutschland GmbH
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>
13 #include <linux/if_arp.h>
14 #include <linux/time.h>
15 #include <net/mac80211.h>
16 #include <net/ieee80211_radiotap.h>
20 #include "iwl-op-mode.h"
24 #include "time-event.h"
25 #include "iwl-eeprom-parse.h"
26 #include "iwl-phy-db.h"
28 #include "fw/error-dump.h"
30 #include "iwl-nvm-parse.h"
31 #include "time-sync.h"
33 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
36 .types = BIT(NL80211_IFTYPE_STATION),
40 .types = BIT(NL80211_IFTYPE_AP) |
41 BIT(NL80211_IFTYPE_P2P_CLIENT) |
42 BIT(NL80211_IFTYPE_P2P_GO),
46 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
50 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
52 .num_different_channels = 2,
54 .limits = iwl_mvm_limits,
55 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
59 static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa = {
60 .max_peers = IWL_MVM_TOF_MAX_APS,
62 .randomize_mac_addr = 1,
69 .request_civicloc = 1,
71 .non_trigger_based = 1,
72 .max_bursts_exponent = -1, /* all supported */
73 .max_ftms_per_burst = 0, /* no limits */
74 .bandwidths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
75 BIT(NL80211_CHAN_WIDTH_20) |
76 BIT(NL80211_CHAN_WIDTH_40) |
77 BIT(NL80211_CHAN_WIDTH_80) |
78 BIT(NL80211_CHAN_WIDTH_160),
79 .preambles = BIT(NL80211_PREAMBLE_LEGACY) |
80 BIT(NL80211_PREAMBLE_HT) |
81 BIT(NL80211_PREAMBLE_VHT) |
82 BIT(NL80211_PREAMBLE_HE),
86 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
88 struct ieee80211_vif *vif,
89 struct ieee80211_sta *sta,
90 struct ieee80211_key_conf *key);
92 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
96 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
97 for (i = 0; i < NUM_PHY_CTX; i++) {
98 mvm->phy_ctxts[i].id = i;
99 mvm->phy_ctxts[i].ref = 0;
103 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
105 enum iwl_mcc_source src_id,
108 struct ieee80211_regdomain *regd = NULL;
109 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
110 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
111 struct iwl_mcc_update_resp_v8 *resp;
114 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
116 lockdep_assert_held(&mvm->mutex);
118 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
119 if (IS_ERR_OR_NULL(resp)) {
120 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
121 PTR_ERR_OR_ZERO(resp));
127 u32 status = le32_to_cpu(resp->status);
129 *changed = (status == MCC_RESP_NEW_CHAN_PROFILE ||
130 status == MCC_RESP_ILLEGAL);
132 resp_ver = iwl_fw_lookup_notif_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP,
134 IWL_DEBUG_LAR(mvm, "MCC update response version: %d\n", resp_ver);
136 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
137 __le32_to_cpu(resp->n_channels),
139 __le16_to_cpu(resp->mcc),
140 __le16_to_cpu(resp->geo_info),
141 le32_to_cpu(resp->cap), resp_ver,
142 mvm->fwrt.uats_enabled);
143 /* Store the return source id */
144 src_id = resp->source_id;
145 if (IS_ERR_OR_NULL(regd)) {
146 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
147 PTR_ERR_OR_ZERO(regd));
151 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
152 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
153 mvm->lar_regdom_set = true;
154 mvm->mcc_src = src_id;
156 /* Some kind of regulatory mess means we need to currently disallow
157 * puncturing in the US and Canada. Do that here, at least until we
158 * figure out the new chanctx APIs for puncturing.
160 if (resp->mcc == cpu_to_le16(IWL_MCC_US) ||
161 resp->mcc == cpu_to_le16(IWL_MCC_CANADA))
162 ieee80211_hw_set(mvm->hw, DISALLOW_PUNCTURING);
164 __clear_bit(IEEE80211_HW_DISALLOW_PUNCTURING, mvm->hw->flags);
166 iwl_mei_set_country_code(__le16_to_cpu(resp->mcc));
173 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
176 struct ieee80211_regdomain *regd;
178 if (!iwl_mvm_is_lar_supported(mvm))
181 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
182 if (!IS_ERR_OR_NULL(regd)) {
183 /* only update the regulatory core if changed */
185 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
191 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
194 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
195 iwl_mvm_is_wifi_mcc_supported(mvm) ?
196 MCC_SOURCE_GET_CURRENT :
197 MCC_SOURCE_OLD_FW, changed);
200 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm, bool force_regd_sync)
202 enum iwl_mcc_source used_src;
203 struct ieee80211_regdomain *regd;
206 const struct ieee80211_regdomain *r =
207 wiphy_dereference(mvm->hw->wiphy, mvm->hw->wiphy->regd);
212 /* save the last source in case we overwrite it below */
213 used_src = mvm->mcc_src;
214 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
215 /* Notify the firmware we support wifi location updates */
216 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
217 if (!IS_ERR_OR_NULL(regd))
221 /* Now set our last stored MCC and source */
222 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
224 if (IS_ERR_OR_NULL(regd))
227 /* update cfg80211 if the regdomain was changed or the caller explicitly
228 * asked to update regdomain
230 if (changed || force_regd_sync)
231 ret = regulatory_set_wiphy_regd_sync(mvm->hw->wiphy, regd);
239 /* Each capability added here should also be add to tm_if_types_ext_capa_sta */
240 static const u8 he_if_types_ext_capa_sta[] = {
241 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
242 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
243 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF |
244 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB,
245 [8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB,
248 static const u8 tm_if_types_ext_capa_sta[] = {
249 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
250 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT |
251 WLAN_EXT_CAPA3_TIMING_MEASUREMENT_SUPPORT,
252 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF |
253 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB,
254 [8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB,
255 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
258 /* Additional interface types for which extended capabilities are
259 * specified separately
262 #define IWL_MVM_EMLSR_CAPA (IEEE80211_EML_CAP_EMLSR_SUPP | \
263 IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_32US << \
264 __bf_shf(IEEE80211_EML_CAP_EMLSR_PADDING_DELAY) | \
265 IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_64US << \
266 __bf_shf(IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY))
267 #define IWL_MVM_MLD_CAPA_OPS FIELD_PREP_CONST( \
268 IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP, \
269 IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP_SAME)
271 static const struct wiphy_iftype_ext_capab add_iftypes_ext_capa[] = {
273 .iftype = NL80211_IFTYPE_STATION,
274 .extended_capabilities = he_if_types_ext_capa_sta,
275 .extended_capabilities_mask = he_if_types_ext_capa_sta,
276 .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta),
277 /* relevant only if EHT is supported */
278 .eml_capabilities = IWL_MVM_EMLSR_CAPA,
279 .mld_capa_and_ops = IWL_MVM_MLD_CAPA_OPS,
282 .iftype = NL80211_IFTYPE_STATION,
283 .extended_capabilities = tm_if_types_ext_capa_sta,
284 .extended_capabilities_mask = tm_if_types_ext_capa_sta,
285 .extended_capabilities_len = sizeof(tm_if_types_ext_capa_sta),
286 /* relevant only if EHT is supported */
287 .eml_capabilities = IWL_MVM_EMLSR_CAPA,
288 .mld_capa_and_ops = IWL_MVM_MLD_CAPA_OPS,
292 int iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
294 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
295 *tx_ant = iwl_mvm_get_valid_tx_ant(mvm);
296 *rx_ant = iwl_mvm_get_valid_rx_ant(mvm);
300 int iwl_mvm_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
302 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
304 /* This has been tested on those devices only */
305 if (mvm->trans->trans_cfg->device_family != IWL_DEVICE_FAMILY_9000 &&
306 mvm->trans->trans_cfg->device_family != IWL_DEVICE_FAMILY_22000)
312 /* mac80211 ensures the device is not started,
313 * so the firmware cannot be running
316 mvm->set_tx_ant = tx_ant;
317 mvm->set_rx_ant = rx_ant;
319 iwl_reinit_cab(mvm->trans, mvm->nvm_data, tx_ant, rx_ant, mvm->fw);
324 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
326 struct ieee80211_hw *hw = mvm->hw;
328 static const u32 mvm_ciphers[] = {
329 WLAN_CIPHER_SUITE_WEP40,
330 WLAN_CIPHER_SUITE_WEP104,
331 WLAN_CIPHER_SUITE_TKIP,
332 WLAN_CIPHER_SUITE_CCMP,
334 #ifdef CONFIG_PM_SLEEP
335 bool unified = fw_has_capa(&mvm->fw->ucode_capa,
336 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
338 u32 sec_key_id = WIDE_ID(DATA_PATH_GROUP, SEC_KEY_CMD);
339 u8 sec_key_ver = iwl_fw_lookup_cmd_ver(mvm->fw, sec_key_id, 0);
341 /* Tell mac80211 our characteristics */
342 ieee80211_hw_set(hw, SIGNAL_DBM);
343 ieee80211_hw_set(hw, SPECTRUM_MGMT);
344 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
345 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
346 ieee80211_hw_set(hw, SUPPORTS_PS);
347 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
348 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
349 ieee80211_hw_set(hw, CONNECTION_MONITOR);
350 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
351 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
352 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
353 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
354 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
355 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
356 ieee80211_hw_set(hw, BUFF_MMPDU_TXQ);
357 ieee80211_hw_set(hw, STA_MMPDU_TXQ);
359 /* Set this early since we need to have it for the check below */
360 if (mvm->mld_api_is_used && mvm->nvm_data->sku_cap_11be_enable &&
361 !iwlwifi_mod_params.disable_11ax &&
362 !iwlwifi_mod_params.disable_11be)
363 hw->wiphy->flags |= WIPHY_FLAG_DISABLE_WEXT;
365 /* With MLD FW API, it tracks timing by itself,
366 * no need for any timing from the host
368 if (!mvm->mld_api_is_used)
369 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
371 /* We should probably have this, but mac80211
372 * currently doesn't support it for MLO.
374 if (!(hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO))
375 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
378 * On older devices, enabling TX A-MSDU occasionally leads to
379 * something getting messed up, the command read from the FIFO
380 * gets out of sync and isn't a TX command, so that we have an
383 * It's not clear where the bug is, but since we didn't used to
384 * support A-MSDU until moving the mac80211 iTXQs, just leave it
385 * for older devices. We also don't see this issue on any newer
388 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000)
389 ieee80211_hw_set(hw, TX_AMSDU);
390 ieee80211_hw_set(hw, TX_FRAG_LIST);
392 if (iwl_mvm_has_tlc_offload(mvm)) {
393 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
394 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
397 /* We want to use the mac80211's reorder buffer for 9000 */
398 if (iwl_mvm_has_new_rx_api(mvm) &&
399 mvm->trans->trans_cfg->device_family > IWL_DEVICE_FAMILY_9000)
400 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
402 if (fw_has_capa(&mvm->fw->ucode_capa,
403 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
404 ieee80211_hw_set(hw, AP_LINK_PS);
405 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
407 * we absolutely need this for the new TX API since that comes
408 * with many more queues than the current code can deal with
409 * for station powersave
414 if (mvm->trans->num_rx_queues > 1)
415 ieee80211_hw_set(hw, USES_RSS);
417 if (mvm->trans->max_skb_frags)
418 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
420 hw->queues = IEEE80211_NUM_ACS;
421 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
422 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
423 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
424 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
425 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
427 hw->radiotap_timestamp.units_pos =
428 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
429 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
430 /* this is the case for CCK frames, it's better (only 8) for OFDM */
431 hw->radiotap_timestamp.accuracy = 22;
433 if (!iwl_mvm_has_tlc_offload(mvm))
434 hw->rate_control_algorithm = RS_NAME;
436 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
437 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
438 hw->max_tx_fragments = mvm->trans->max_skb_frags;
440 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
441 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
442 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
443 hw->wiphy->cipher_suites = mvm->ciphers;
445 if (iwl_mvm_has_new_rx_api(mvm)) {
446 mvm->ciphers[hw->wiphy->n_cipher_suites] =
447 WLAN_CIPHER_SUITE_GCMP;
448 hw->wiphy->n_cipher_suites++;
449 mvm->ciphers[hw->wiphy->n_cipher_suites] =
450 WLAN_CIPHER_SUITE_GCMP_256;
451 hw->wiphy->n_cipher_suites++;
454 if (iwlwifi_mod_params.swcrypto)
456 "iwlmvm doesn't allow to disable HW crypto, check swcrypto module parameter\n");
457 if (!iwlwifi_mod_params.bt_coex_active)
459 "iwlmvm doesn't allow to disable BT Coex, check bt_coex_active module parameter\n");
461 ieee80211_hw_set(hw, MFP_CAPABLE);
462 mvm->ciphers[hw->wiphy->n_cipher_suites] = WLAN_CIPHER_SUITE_AES_CMAC;
463 hw->wiphy->n_cipher_suites++;
464 if (iwl_mvm_has_new_rx_api(mvm)) {
465 mvm->ciphers[hw->wiphy->n_cipher_suites] =
466 WLAN_CIPHER_SUITE_BIP_GMAC_128;
467 hw->wiphy->n_cipher_suites++;
468 mvm->ciphers[hw->wiphy->n_cipher_suites] =
469 WLAN_CIPHER_SUITE_BIP_GMAC_256;
470 hw->wiphy->n_cipher_suites++;
473 wiphy_ext_feature_set(hw->wiphy,
474 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY);
475 wiphy_ext_feature_set(hw->wiphy,
476 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT);
478 if (fw_has_capa(&mvm->fw->ucode_capa,
479 IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) {
480 wiphy_ext_feature_set(hw->wiphy,
481 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
482 hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa;
486 fw_has_capa(&mvm->fw->ucode_capa,
487 IWL_UCODE_TLV_CAPA_BIGTK_TX_SUPPORT))
488 wiphy_ext_feature_set(hw->wiphy,
489 NL80211_EXT_FEATURE_BEACON_PROTECTION);
490 else if (fw_has_capa(&mvm->fw->ucode_capa,
491 IWL_UCODE_TLV_CAPA_BIGTK_SUPPORT))
492 wiphy_ext_feature_set(hw->wiphy,
493 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT);
495 if (fw_has_capa(&mvm->fw->ucode_capa,
496 IWL_UCODE_TLV_CAPA_TIME_SYNC_BOTH_FTM_TM))
497 hw->wiphy->hw_timestamp_max_peers = 1;
499 if (fw_has_capa(&mvm->fw->ucode_capa,
500 IWL_UCODE_TLV_CAPA_SPP_AMSDU_SUPPORT))
501 wiphy_ext_feature_set(hw->wiphy,
502 NL80211_EXT_FEATURE_SPP_AMSDU_SUPPORT);
504 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
505 hw->wiphy->features |=
506 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
507 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
508 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
510 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
511 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
512 hw->chanctx_data_size = sizeof(u16);
513 hw->txq_data_size = sizeof(struct iwl_mvm_txq);
515 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
516 BIT(NL80211_IFTYPE_P2P_CLIENT) |
517 BIT(NL80211_IFTYPE_AP) |
518 BIT(NL80211_IFTYPE_P2P_GO) |
519 BIT(NL80211_IFTYPE_P2P_DEVICE) |
520 BIT(NL80211_IFTYPE_ADHOC);
522 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
523 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
525 /* The new Tx API does not allow to pass the key or keyid of a MPDU to
526 * the hw, preventing us to control which key(id) to use per MPDU.
527 * Till that's fixed we can't use Extended Key ID for the newer cards.
529 if (!iwl_mvm_has_new_tx_api(mvm))
530 wiphy_ext_feature_set(hw->wiphy,
531 NL80211_EXT_FEATURE_EXT_KEY_ID);
532 hw->wiphy->features |= NL80211_FEATURE_HT_IBSS;
534 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
535 if (iwl_mvm_is_lar_supported(mvm))
536 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
538 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
539 REGULATORY_DISABLE_BEACON_HINTS;
541 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210)
542 wiphy_ext_feature_set(hw->wiphy,
543 NL80211_EXT_FEATURE_DFS_CONCURRENT);
545 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
546 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
547 hw->wiphy->flags |= WIPHY_FLAG_SPLIT_SCAN_6GHZ;
549 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
550 hw->wiphy->n_iface_combinations =
551 ARRAY_SIZE(iwl_mvm_iface_combinations);
553 hw->wiphy->max_remain_on_channel_duration = 10000;
554 hw->max_listen_interval = IWL_MVM_CONN_LISTEN_INTERVAL;
556 /* Extract MAC address */
557 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
558 hw->wiphy->addresses = mvm->addresses;
559 hw->wiphy->n_addresses = 1;
561 /* Extract additional MAC addresses if available */
562 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
563 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
565 for (i = 1; i < num_mac; i++) {
566 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
568 mvm->addresses[i].addr[5]++;
569 hw->wiphy->n_addresses++;
572 iwl_mvm_reset_phy_ctxts(mvm);
574 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
576 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
578 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
579 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
580 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
582 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
583 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
585 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
587 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
588 hw->wiphy->bands[NL80211_BAND_2GHZ] =
589 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
590 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
591 hw->wiphy->bands[NL80211_BAND_5GHZ] =
592 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
594 if (fw_has_capa(&mvm->fw->ucode_capa,
595 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
596 fw_has_api(&mvm->fw->ucode_capa,
597 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
598 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
599 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
601 if (fw_has_capa(&mvm->fw->ucode_capa,
602 IWL_UCODE_TLV_CAPA_PSC_CHAN_SUPPORT) &&
603 mvm->nvm_data->bands[NL80211_BAND_6GHZ].n_channels)
604 hw->wiphy->bands[NL80211_BAND_6GHZ] =
605 &mvm->nvm_data->bands[NL80211_BAND_6GHZ];
607 hw->wiphy->hw_version = mvm->trans->hw_id;
609 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
610 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
612 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
614 hw->wiphy->max_sched_scan_reqs = 1;
615 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
616 hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw);
617 /* we create the 802.11 header and zero length SSID IE. */
618 hw->wiphy->max_sched_scan_ie_len =
619 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
620 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
621 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
624 * the firmware uses u8 for num of iterations, but 0xff is saved for
625 * infinite loop, so the maximum number of iterations is actually 254.
627 hw->wiphy->max_sched_scan_plan_iterations = 254;
629 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
630 NL80211_FEATURE_LOW_PRIORITY_SCAN |
631 NL80211_FEATURE_P2P_GO_OPPPS |
632 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
633 NL80211_FEATURE_DYNAMIC_SMPS |
634 NL80211_FEATURE_STATIC_SMPS |
635 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
637 if (fw_has_capa(&mvm->fw->ucode_capa,
638 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
639 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
640 if (fw_has_capa(&mvm->fw->ucode_capa,
641 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
642 hw->wiphy->features |= NL80211_FEATURE_QUIET;
644 if (fw_has_capa(&mvm->fw->ucode_capa,
645 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
646 hw->wiphy->features |=
647 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
649 if (fw_has_capa(&mvm->fw->ucode_capa,
650 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
651 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
653 if (iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_KEK_KCK_MATERIAL,
654 IWL_FW_CMD_VER_UNKNOWN) == 3)
655 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK;
657 if (fw_has_api(&mvm->fw->ucode_capa,
658 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
659 wiphy_ext_feature_set(hw->wiphy,
660 NL80211_EXT_FEATURE_SCAN_START_TIME);
661 wiphy_ext_feature_set(hw->wiphy,
662 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
665 if (iwl_mvm_is_oce_supported(mvm)) {
666 u8 scan_ver = iwl_fw_lookup_cmd_ver(mvm->fw, SCAN_REQ_UMAC, 0);
668 wiphy_ext_feature_set(hw->wiphy,
669 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
670 wiphy_ext_feature_set(hw->wiphy,
671 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
672 wiphy_ext_feature_set(hw->wiphy,
673 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
675 /* Old firmware also supports probe deferral and suppression */
677 wiphy_ext_feature_set(hw->wiphy,
678 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
681 hw->wiphy->iftype_ext_capab = NULL;
682 hw->wiphy->num_iftype_ext_capab = 0;
684 if (mvm->nvm_data->sku_cap_11ax_enable &&
685 !iwlwifi_mod_params.disable_11ax) {
686 hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa;
687 hw->wiphy->num_iftype_ext_capab =
688 ARRAY_SIZE(add_iftypes_ext_capa) - 1;
690 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
691 ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID);
694 if (iwl_fw_lookup_cmd_ver(mvm->fw,
695 WIDE_ID(DATA_PATH_GROUP,
696 WNM_80211V_TIMING_MEASUREMENT_CONFIG_CMD),
697 IWL_FW_CMD_VER_UNKNOWN) >= 1) {
698 IWL_DEBUG_INFO(mvm->trans, "Timing measurement supported\n");
700 if (!hw->wiphy->iftype_ext_capab) {
701 hw->wiphy->num_iftype_ext_capab = 1;
702 hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa +
703 ARRAY_SIZE(add_iftypes_ext_capa) - 1;
705 hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa + 1;
709 if (iwl_fw_lookup_cmd_ver(mvm->fw, WIDE_ID(LOCATION_GROUP,
711 IWL_FW_CMD_VER_UNKNOWN) >= 11) {
712 wiphy_ext_feature_set(hw->wiphy,
713 NL80211_EXT_FEATURE_PROT_RANGE_NEGO_AND_MEASURE);
715 if (fw_has_capa(&mvm->fw->ucode_capa,
716 IWL_UCODE_TLV_CAPA_SECURE_LTF_SUPPORT))
717 wiphy_ext_feature_set(hw->wiphy,
718 NL80211_EXT_FEATURE_SECURE_LTF);
721 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
723 #ifdef CONFIG_PM_SLEEP
724 if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) &&
725 mvm->trans->ops->d3_suspend &&
726 mvm->trans->ops->d3_resume &&
727 device_can_wakeup(mvm->trans->dev)) {
728 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
729 WIPHY_WOWLAN_DISCONNECT |
730 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
731 WIPHY_WOWLAN_RFKILL_RELEASE |
732 WIPHY_WOWLAN_NET_DETECT;
733 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
734 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
735 WIPHY_WOWLAN_4WAY_HANDSHAKE;
737 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
738 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
739 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
740 mvm->wowlan.max_nd_match_sets =
741 iwl_umac_scan_get_max_profiles(mvm->fw);
742 hw->wiphy->wowlan = &mvm->wowlan;
746 ret = iwl_mvm_leds_init(mvm);
750 if (fw_has_capa(&mvm->fw->ucode_capa,
751 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
752 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
753 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
754 ieee80211_hw_set(hw, TDLS_WIDER_BW);
757 if (fw_has_capa(&mvm->fw->ucode_capa,
758 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
759 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
760 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
763 hw->netdev_features |= mvm->cfg->features;
764 if (!iwl_mvm_is_csum_supported(mvm))
765 hw->netdev_features &= ~IWL_CSUM_NETIF_FLAGS_MASK;
767 if (mvm->cfg->vht_mu_mimo_supported)
768 wiphy_ext_feature_set(hw->wiphy,
769 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
771 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT))
772 wiphy_ext_feature_set(hw->wiphy,
773 NL80211_EXT_FEATURE_PROTECTED_TWT);
775 iwl_mvm_vendor_cmds_register(mvm);
777 hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm);
778 hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm);
780 ret = ieee80211_register_hw(mvm->hw);
782 iwl_mvm_leds_exit(mvm);
788 static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
789 struct ieee80211_sta *sta)
792 if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0))
795 if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0))
799 ieee80211_free_txskb(mvm->hw, skb);
802 void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
803 struct ieee80211_tx_control *control, struct sk_buff *skb)
805 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
806 struct ieee80211_sta *sta = control->sta;
807 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
808 struct ieee80211_hdr *hdr = (void *)skb->data;
809 bool offchannel = IEEE80211_SKB_CB(skb)->flags &
810 IEEE80211_TX_CTL_TX_OFFCHAN;
811 u32 link_id = u32_get_bits(info->control.flags,
812 IEEE80211_TX_CTRL_MLO_LINK);
813 struct ieee80211_sta *tmp_sta = sta;
815 if (iwl_mvm_is_radio_killed(mvm)) {
816 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
821 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
822 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
826 * bufferable MMPDUs or MMPDUs on STA interfaces come via TXQs
827 * so we treat the others as broadcast
829 if (ieee80211_is_mgmt(hdr->frame_control))
832 /* If there is no sta, and it's not offchannel - send through AP */
833 if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION &&
835 struct iwl_mvm_vif *mvmvif =
836 iwl_mvm_vif_from_mac80211(info->control.vif);
837 u8 ap_sta_id = READ_ONCE(mvmvif->deflink.ap_sta_id);
839 if (ap_sta_id < mvm->fw->ucode_capa.num_stations) {
840 /* mac80211 holds rcu read lock */
841 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
842 if (IS_ERR_OR_NULL(sta))
847 if (tmp_sta && !sta && link_id != IEEE80211_LINK_UNSPECIFIED &&
848 !ieee80211_is_probe_resp(hdr->frame_control)) {
849 /* translate MLD addresses to LINK addresses */
850 struct ieee80211_link_sta *link_sta =
851 rcu_dereference(tmp_sta->link[link_id]);
852 struct ieee80211_bss_conf *link_conf =
853 rcu_dereference(info->control.vif->link_conf[link_id]);
854 struct ieee80211_mgmt *mgmt;
856 if (WARN_ON(!link_sta || !link_conf))
859 /* if sta is NULL, the frame is a management frame */
861 memcpy(mgmt->da, link_sta->addr, ETH_ALEN);
862 memcpy(mgmt->sa, link_conf->addr, ETH_ALEN);
863 memcpy(mgmt->bssid, link_conf->bssid, ETH_ALEN);
866 iwl_mvm_tx_skb(mvm, skb, sta);
869 ieee80211_free_txskb(hw, skb);
872 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
874 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
875 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
876 struct sk_buff *skb = NULL;
879 * No need for threads to be pending here, they can leave the first
880 * taker all the work.
882 * mvmtxq->tx_request logic:
884 * If 0, no one is currently TXing, set to 1 to indicate current thread
885 * will now start TX and other threads should quit.
887 * If 1, another thread is currently TXing, set to 2 to indicate to
888 * that thread that there was another request. Since that request may
889 * have raced with the check whether the queue is empty, the TXing
890 * thread should check the queue's status one more time before leaving.
891 * This check is done in order to not leave any TX hanging in the queue
892 * until the next TX invocation (which may not even happen).
894 * If 2, another thread is currently TXing, and it will already double
895 * check the queue, so do nothing.
897 if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2))
902 while (likely(!test_bit(IWL_MVM_TXQ_STATE_STOP_FULL,
904 !test_bit(IWL_MVM_TXQ_STATE_STOP_REDIRECT,
906 !test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status))) {
907 skb = ieee80211_tx_dequeue(hw, txq);
912 "TXQ of sta %pM tid %d is now empty\n",
918 iwl_mvm_tx_skb(mvm, skb, txq->sta);
920 } while (atomic_dec_return(&mvmtxq->tx_request));
924 void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw,
925 struct ieee80211_txq *txq)
927 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
928 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
930 if (likely(test_bit(IWL_MVM_TXQ_STATE_READY, &mvmtxq->state)) ||
932 iwl_mvm_mac_itxq_xmit(hw, txq);
936 /* iwl_mvm_mac_itxq_xmit() will later be called by the worker
937 * to handle any packets we leave on the txq now
940 spin_lock_bh(&mvm->add_stream_lock);
941 /* The list is being deleted only after the queue is fully allocated. */
942 if (list_empty(&mvmtxq->list) &&
943 /* recheck under lock */
944 !test_bit(IWL_MVM_TXQ_STATE_READY, &mvmtxq->state)) {
945 list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs);
946 schedule_work(&mvm->add_stream_wk);
948 spin_unlock_bh(&mvm->add_stream_lock);
951 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
953 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
955 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
959 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
960 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
961 enum ieee80211_ampdu_mlme_action action)
963 struct iwl_fw_dbg_trigger_tlv *trig;
964 struct iwl_fw_dbg_trigger_ba *ba_trig;
966 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
971 ba_trig = (void *)trig->data;
974 case IEEE80211_AMPDU_TX_OPERATIONAL: {
975 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
976 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
978 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
979 "TX AGG START: MAC %pM tid %d ssn %d\n",
980 sta->addr, tid, tid_data->ssn);
983 case IEEE80211_AMPDU_TX_STOP_CONT:
984 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
985 "TX AGG STOP: MAC %pM tid %d\n",
988 case IEEE80211_AMPDU_RX_START:
989 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
990 "RX AGG START: MAC %pM tid %d ssn %d\n",
991 sta->addr, tid, rx_ba_ssn);
993 case IEEE80211_AMPDU_RX_STOP:
994 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
995 "RX AGG STOP: MAC %pM tid %d\n",
1003 int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
1004 struct ieee80211_vif *vif,
1005 struct ieee80211_ampdu_params *params)
1007 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1009 struct ieee80211_sta *sta = params->sta;
1010 enum ieee80211_ampdu_mlme_action action = params->action;
1011 u16 tid = params->tid;
1012 u16 *ssn = ¶ms->ssn;
1013 u16 buf_size = params->buf_size;
1014 bool amsdu = params->amsdu;
1015 u16 timeout = params->timeout;
1017 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
1018 sta->addr, tid, action);
1020 if (!(mvm->nvm_data->sku_cap_11n_enable))
1023 mutex_lock(&mvm->mutex);
1026 case IEEE80211_AMPDU_RX_START:
1027 if (iwl_mvm_vif_from_mac80211(vif)->deflink.ap_sta_id ==
1028 iwl_mvm_sta_from_mac80211(sta)->deflink.sta_id) {
1029 struct iwl_mvm_vif *mvmvif;
1030 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
1031 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
1033 mdata->opened_rx_ba_sessions = true;
1034 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1035 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
1037 if (!iwl_enable_rx_ampdu()) {
1041 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
1044 case IEEE80211_AMPDU_RX_STOP:
1045 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
1048 case IEEE80211_AMPDU_TX_START:
1049 if (!iwl_enable_tx_ampdu()) {
1053 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
1055 case IEEE80211_AMPDU_TX_STOP_CONT:
1056 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
1058 case IEEE80211_AMPDU_TX_STOP_FLUSH:
1059 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
1060 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
1062 case IEEE80211_AMPDU_TX_OPERATIONAL:
1063 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1075 if (action == IEEE80211_AMPDU_RX_START)
1078 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1081 mutex_unlock(&mvm->mutex);
1086 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1087 struct ieee80211_vif *vif)
1089 struct iwl_mvm *mvm = data;
1090 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1091 struct iwl_probe_resp_data *probe_data;
1092 unsigned int link_id;
1094 mvmvif->uploaded = false;
1096 spin_lock_bh(&mvm->time_event_lock);
1097 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1098 spin_unlock_bh(&mvm->time_event_lock);
1100 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1101 mvmvif->ap_sta = NULL;
1103 for_each_mvm_vif_valid_link(mvmvif, link_id) {
1104 mvmvif->link[link_id]->ap_sta_id = IWL_MVM_INVALID_STA;
1105 mvmvif->link[link_id]->fw_link_id = IWL_MVM_FW_LINK_ID_INVALID;
1106 mvmvif->link[link_id]->phy_ctxt = NULL;
1107 mvmvif->link[link_id]->active = 0;
1108 mvmvif->link[link_id]->igtk = NULL;
1111 probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data,
1112 lockdep_is_held(&mvm->mutex));
1114 kfree_rcu(probe_data, rcu_head);
1115 RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL);
1118 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1120 iwl_mvm_stop_device(mvm);
1124 mvm->scan_status = 0;
1125 mvm->ps_disabled = false;
1126 mvm->rfkill_safe_init_done = false;
1128 /* just in case one was running */
1129 iwl_mvm_cleanup_roc_te(mvm);
1130 ieee80211_remain_on_channel_expired(mvm->hw);
1132 iwl_mvm_ftm_restart(mvm);
1135 * cleanup all interfaces, even inactive ones, as some might have
1136 * gone down during the HW restart
1138 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1140 mvm->p2p_device_vif = NULL;
1142 iwl_mvm_reset_phy_ctxts(mvm);
1143 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1144 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1145 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1147 ieee80211_wake_queues(mvm->hw);
1149 mvm->rx_ba_sessions = 0;
1150 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1151 mvm->monitor_on = false;
1152 #ifdef CONFIG_IWLWIFI_DEBUGFS
1153 mvm->beacon_inject_active = false;
1156 /* keep statistics ticking */
1157 iwl_mvm_accu_radio_stats(mvm);
1160 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1164 lockdep_assert_held(&mvm->mutex);
1166 ret = iwl_mvm_mei_get_ownership(mvm);
1170 if (mvm->mei_nvm_data) {
1171 /* We got the NIC, we can now free the MEI NVM data */
1172 kfree(mvm->mei_nvm_data);
1173 mvm->mei_nvm_data = NULL;
1176 * We can't free the nvm_data we allocated based on the SAP
1177 * data because we registered to cfg80211 with the channels
1178 * allocated on mvm->nvm_data. Keep a pointer in temp_nvm_data
1179 * just in order to be able free it later.
1180 * NULLify nvm_data so that we will read the NVM from the
1181 * firmware this time.
1183 mvm->temp_nvm_data = mvm->nvm_data;
1184 mvm->nvm_data = NULL;
1187 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1189 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1190 * so later code will - from now on - see that we're doing it.
1192 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1193 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1194 /* Clean up some internal and mac80211 state on restart */
1195 iwl_mvm_restart_cleanup(mvm);
1197 ret = iwl_mvm_up(mvm);
1199 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT,
1201 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC,
1204 mvm->last_reset_or_resume_time_jiffies = jiffies;
1206 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1207 /* Something went wrong - we need to finish some cleanup
1208 * that normally iwl_mvm_mac_restart_complete() below
1211 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1217 int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1219 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1222 mutex_lock(&mvm->mutex);
1224 /* we are starting the mac not in error flow, and restart is enabled */
1225 if (!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) &&
1226 iwlwifi_mod_params.fw_restart) {
1228 * This will prevent mac80211 recovery flows to trigger during
1231 set_bit(IWL_MVM_STATUS_STARTING, &mvm->status);
1234 ret = __iwl_mvm_mac_start(mvm);
1235 clear_bit(IWL_MVM_STATUS_STARTING, &mvm->status);
1237 mutex_unlock(&mvm->mutex);
1239 iwl_mvm_mei_set_sw_rfkill_state(mvm);
1244 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1248 mutex_lock(&mvm->mutex);
1250 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1252 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1254 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1257 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY);
1260 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1261 * of packets the FW sent out, so we must reconnect.
1263 iwl_mvm_teardown_tdls_peers(mvm);
1265 mutex_unlock(&mvm->mutex);
1268 void iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1269 enum ieee80211_reconfig_type reconfig_type)
1271 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1273 switch (reconfig_type) {
1274 case IEEE80211_RECONFIG_TYPE_RESTART:
1275 iwl_mvm_restart_complete(mvm);
1277 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1282 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1284 lockdep_assert_held(&mvm->mutex);
1286 iwl_mvm_ftm_initiator_smooth_stop(mvm);
1288 /* firmware counters are obviously reset now, but we shouldn't
1289 * partially track so also clear the fw_reset_accu counters.
1291 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1293 /* async_handlers_wk is now blocked */
1295 if (!iwl_mvm_has_new_station_api(mvm->fw))
1296 iwl_mvm_rm_aux_sta(mvm);
1298 iwl_mvm_stop_device(mvm);
1300 iwl_mvm_async_handlers_purge(mvm);
1301 /* async_handlers_list is empty and will stay empty: HW is stopped */
1304 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1305 * hw (as restart_complete() won't be called in this case) and mac80211
1306 * won't execute the restart.
1307 * But make sure to cleanup interfaces that have gone down before/during
1308 * HW restart was requested.
1310 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1311 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1313 ieee80211_iterate_interfaces(mvm->hw, 0,
1314 iwl_mvm_cleanup_iterator, mvm);
1316 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1317 * make sure there's nothing left there and warn if any is found.
1319 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1322 for (i = 0; i < mvm->max_scans; i++) {
1323 if (WARN_ONCE(mvm->scan_uid_status[i],
1324 "UMAC scan UID %d status was not cleaned\n",
1326 mvm->scan_uid_status[i] = 0;
1331 void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1333 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1335 flush_work(&mvm->async_handlers_wk);
1336 flush_work(&mvm->add_stream_wk);
1339 * Lock and clear the firmware running bit here already, so that
1340 * new commands coming in elsewhere, e.g. from debugfs, will not
1341 * be able to proceed. This is important here because one of those
1342 * debugfs files causes the firmware dump to be triggered, and if we
1343 * don't stop debugfs accesses before canceling that it could be
1344 * retriggered after we flush it but before we've cleared the bit.
1346 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1348 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1349 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1352 * The work item could be running or queued if the
1353 * ROC time event stops just as we get here.
1355 flush_work(&mvm->roc_done_wk);
1357 iwl_mvm_mei_set_sw_rfkill_state(mvm);
1359 mutex_lock(&mvm->mutex);
1360 __iwl_mvm_mac_stop(mvm);
1361 mutex_unlock(&mvm->mutex);
1364 * The worker might have been waiting for the mutex, let it run and
1365 * discover that its list is now empty.
1367 cancel_work_sync(&mvm->async_handlers_wk);
1368 wiphy_work_cancel(hw->wiphy, &mvm->async_handlers_wiphy_wk);
1371 struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1375 lockdep_assert_held(&mvm->mutex);
1377 for (i = 0; i < NUM_PHY_CTX; i++)
1378 if (!mvm->phy_ctxts[i].ref)
1379 return &mvm->phy_ctxts[i];
1381 IWL_ERR(mvm, "No available PHY context\n");
1385 int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1388 u32 cmd_id = REDUCE_TX_POWER_CMD;
1390 struct iwl_dev_tx_power_cmd cmd = {
1391 .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1392 .common.mac_context_id =
1393 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1394 .common.pwr_restriction = cpu_to_le16(8 * tx_power),
1396 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id,
1397 IWL_FW_CMD_VER_UNKNOWN);
1399 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1400 cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1403 len = sizeof(cmd.v7);
1404 else if (cmd_ver == 6)
1405 len = sizeof(cmd.v6);
1406 else if (fw_has_api(&mvm->fw->ucode_capa,
1407 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1408 len = sizeof(cmd.v5);
1409 else if (fw_has_capa(&mvm->fw->ucode_capa,
1410 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1411 len = sizeof(cmd.v4);
1413 len = sizeof(cmd.v3);
1415 /* all structs have the same common part, add it */
1416 len += sizeof(cmd.common);
1418 return iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, len, &cmd);
1421 int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
1422 struct ieee80211_vif *vif,
1423 struct ieee80211_bss_conf *link_conf)
1425 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1426 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1429 mutex_lock(&mvm->mutex);
1431 if (vif->type == NL80211_IFTYPE_STATION) {
1432 struct iwl_mvm_sta *mvmsta;
1433 unsigned int link_id = link_conf->link_id;
1434 u8 ap_sta_id = mvmvif->link[link_id]->ap_sta_id;
1436 mvmvif->csa_bcn_pending = false;
1437 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, ap_sta_id);
1439 if (WARN_ON(!mvmsta)) {
1444 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
1445 if (mvm->mld_api_is_used)
1446 iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false);
1448 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1450 if (!fw_has_capa(&mvm->fw->ucode_capa,
1451 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
1452 ret = iwl_mvm_enable_beacon_filter(mvm, vif);
1456 iwl_mvm_stop_session_protection(mvm, vif);
1460 mvmvif->ps_disabled = false;
1462 ret = iwl_mvm_power_update_ps(mvm);
1465 if (mvmvif->csa_failed)
1467 mutex_unlock(&mvm->mutex);
1472 void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw,
1473 struct ieee80211_vif *vif,
1474 struct ieee80211_bss_conf *link_conf)
1476 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1477 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1478 struct iwl_chan_switch_te_cmd cmd = {
1479 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1481 .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE),
1485 * In the new flow since FW is in charge of the timing,
1486 * if driver has canceled the channel switch he will receive the
1487 * CHANNEL_SWITCH_START_NOTIF notification from FW and then cancel it
1489 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
1490 CHANNEL_SWITCH_ERROR_NOTIF, 0))
1493 IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id);
1495 mutex_lock(&mvm->mutex);
1496 if (!fw_has_capa(&mvm->fw->ucode_capa,
1497 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
1498 iwl_mvm_remove_csa_period(mvm, vif);
1500 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
1501 WIDE_ID(MAC_CONF_GROUP,
1502 CHANNEL_SWITCH_TIME_EVENT_CMD),
1503 0, sizeof(cmd), &cmd));
1504 mvmvif->csa_failed = true;
1505 mutex_unlock(&mvm->mutex);
1507 /* If we're here, we can't support MLD */
1508 iwl_mvm_post_channel_switch(hw, vif, &vif->bss_conf);
1511 void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk)
1513 struct iwl_mvm_vif *mvmvif;
1514 struct ieee80211_vif *vif;
1516 mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work);
1517 vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);
1519 /* Trigger disconnect (should clear the CSA state) */
1520 ieee80211_chswitch_done(vif, false, 0);
1524 iwl_mvm_chandef_get_primary_80(struct cfg80211_chan_def *chandef)
1530 if (chandef->width == NL80211_CHAN_WIDTH_320)
1532 else if (chandef->width == NL80211_CHAN_WIDTH_160)
1537 /* data is bw wide so the start is half the width */
1538 data_start = chandef->center_freq1 - bw / 2;
1539 /* control is 20Mhz width */
1540 control_start = chandef->chan->center_freq - 10;
1542 return (control_start - data_start) / 80;
1545 static int iwl_mvm_alloc_bcast_mcast_sta(struct iwl_mvm *mvm,
1546 struct ieee80211_vif *vif)
1548 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1551 lockdep_assert_held(&mvm->mutex);
1553 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1555 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1559 /* Only queue for this station is the mcast queue,
1560 * which shouldn't be in TFD mask anyway
1562 return iwl_mvm_allocate_int_sta(mvm, &mvmvif->deflink.mcast_sta, 0,
1567 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1568 struct ieee80211_vif *vif)
1570 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1571 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1575 mutex_lock(&mvm->mutex);
1579 /* the first link always points to the default one */
1580 mvmvif->deflink.fw_link_id = IWL_MVM_FW_LINK_ID_INVALID;
1581 mvmvif->deflink.active = 0;
1582 mvmvif->link[0] = &mvmvif->deflink;
1584 ret = iwl_mvm_set_link_mapping(mvm, vif, &vif->bss_conf);
1589 * Not much to do here. The stack will not allow interface
1590 * types or combinations that we didn't advertise, so we
1591 * don't really have to check the types.
1594 /* make sure that beacon statistics don't go backwards with FW reset */
1595 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1596 for_each_mvm_vif_valid_link(mvmvif, i)
1597 mvmvif->link[i]->beacon_stats.accu_num_beacons +=
1598 mvmvif->link[i]->beacon_stats.num_beacons;
1600 /* Allocate resources for the MAC context, and add it to the fw */
1601 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1605 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif);
1607 /* Currently not much to do for NAN */
1608 if (vif->type == NL80211_IFTYPE_NAN) {
1614 * The AP binding flow can be done only after the beacon
1615 * template is configured (which happens only in the mac80211
1616 * start_ap() flow), and adding the broadcast station can happen
1617 * only after the binding.
1618 * In addition, since modifying the MAC before adding a bcast
1619 * station is not allowed by the FW, delay the adding of MAC context to
1620 * the point where we can also add the bcast station.
1621 * In short: there's not much we can do at this point, other than
1622 * allocating resources :)
1624 if (vif->type == NL80211_IFTYPE_AP ||
1625 vif->type == NL80211_IFTYPE_ADHOC) {
1626 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1627 iwl_mvm_vif_dbgfs_add_link(mvm, vif);
1632 mvmvif->features |= hw->netdev_features;
1634 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1638 ret = iwl_mvm_power_update_mac(mvm);
1640 goto out_remove_mac;
1642 /* beacon filtering */
1643 ret = iwl_mvm_disable_beacon_filter(mvm, vif);
1645 goto out_remove_mac;
1647 if (!mvm->bf_allowed_vif &&
1648 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1649 mvm->bf_allowed_vif = mvmvif;
1650 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1651 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1654 if (vif->p2p || iwl_fw_lookup_cmd_ver(mvm->fw, PHY_CONTEXT_CMD, 1) < 5)
1655 vif->driver_flags |= IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW;
1657 if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
1658 mvm->p2p_device_vif = vif;
1660 iwl_mvm_tcm_add_vif(mvm, vif);
1661 INIT_DELAYED_WORK(&mvmvif->csa_work,
1662 iwl_mvm_channel_switch_disconnect_wk);
1664 if (vif->type == NL80211_IFTYPE_MONITOR) {
1665 mvm->monitor_on = true;
1667 iwl_mvm_chandef_get_primary_80(&vif->bss_conf.chanreq.oper);
1670 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1671 iwl_mvm_vif_dbgfs_add_link(mvm, vif);
1673 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
1674 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
1675 !mvm->csme_vif && mvm->mei_registered) {
1676 iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr);
1677 iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev);
1678 mvm->csme_vif = vif;
1682 if (!ret && (vif->type == NL80211_IFTYPE_AP ||
1683 vif->type == NL80211_IFTYPE_ADHOC))
1684 ret = iwl_mvm_alloc_bcast_mcast_sta(mvm, vif);
1689 mvmvif->deflink.phy_ctxt = NULL;
1690 iwl_mvm_mac_ctxt_remove(mvm, vif);
1692 mutex_unlock(&mvm->mutex);
1697 void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1698 struct ieee80211_vif *vif)
1700 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1702 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1703 * We assume here that all the packets sent to the OFFCHANNEL
1704 * queue are sent in ROC session.
1706 flush_work(&mvm->roc_done_wk);
1710 /* This function is doing the common part of removing the interface for
1711 * both - MLD and non-MLD modes. Returns true if removing the interface
1714 static bool iwl_mvm_mac_remove_interface_common(struct ieee80211_hw *hw,
1715 struct ieee80211_vif *vif)
1717 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1718 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1719 struct iwl_probe_resp_data *probe_data;
1721 iwl_mvm_prepare_mac_removal(mvm, vif);
1723 if (!(vif->type == NL80211_IFTYPE_AP ||
1724 vif->type == NL80211_IFTYPE_ADHOC))
1725 iwl_mvm_tcm_rm_vif(mvm, vif);
1727 mutex_lock(&mvm->mutex);
1729 if (vif == mvm->csme_vif) {
1730 iwl_mei_set_netdev(NULL);
1731 mvm->csme_vif = NULL;
1734 probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data,
1735 lockdep_is_held(&mvm->mutex));
1736 RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL);
1738 kfree_rcu(probe_data, rcu_head);
1740 if (mvm->bf_allowed_vif == mvmvif) {
1741 mvm->bf_allowed_vif = NULL;
1742 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1743 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1746 if (vif->bss_conf.ftm_responder)
1747 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
1749 iwl_mvm_vif_dbgfs_rm_link(mvm, vif);
1752 * For AP/GO interface, the tear down of the resources allocated to the
1753 * interface is be handled as part of the stop_ap flow.
1755 if (vif->type == NL80211_IFTYPE_AP ||
1756 vif->type == NL80211_IFTYPE_ADHOC) {
1757 #ifdef CONFIG_NL80211_TESTMODE
1758 if (vif == mvm->noa_vif) {
1759 mvm->noa_vif = NULL;
1760 mvm->noa_duration = 0;
1766 iwl_mvm_power_update_mac(mvm);
1770 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1771 struct ieee80211_vif *vif)
1773 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1774 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1776 if (iwl_mvm_mac_remove_interface_common(hw, vif))
1779 /* Before the interface removal, mac80211 would cancel the ROC, and the
1780 * ROC worker would be scheduled if needed. The worker would be flushed
1781 * in iwl_mvm_prepare_mac_removal() and thus at this point there is no
1782 * binding etc. so nothing needs to be done here.
1784 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1785 if (mvmvif->deflink.phy_ctxt) {
1786 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt);
1787 mvmvif->deflink.phy_ctxt = NULL;
1789 mvm->p2p_device_vif = NULL;
1792 iwl_mvm_unset_link_mapping(mvm, vif, &vif->bss_conf);
1793 iwl_mvm_mac_ctxt_remove(mvm, vif);
1795 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL);
1797 if (vif->type == NL80211_IFTYPE_MONITOR)
1798 mvm->monitor_on = false;
1801 if (vif->type == NL80211_IFTYPE_AP ||
1802 vif->type == NL80211_IFTYPE_ADHOC) {
1803 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->deflink.mcast_sta);
1804 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1807 mutex_unlock(&mvm->mutex);
1810 struct iwl_mvm_mc_iter_data {
1811 struct iwl_mvm *mvm;
1815 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1816 struct ieee80211_vif *vif)
1818 struct iwl_mvm_mc_iter_data *data = _data;
1819 struct iwl_mvm *mvm = data->mvm;
1820 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1821 struct iwl_host_cmd hcmd = {
1822 .id = MCAST_FILTER_CMD,
1824 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1828 /* if we don't have free ports, mcast frames will be dropped */
1829 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1832 if (vif->type != NL80211_IFTYPE_STATION ||
1836 cmd->port_id = data->port_id++;
1837 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1838 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1843 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1845 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1848 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1850 struct iwl_mvm_mc_iter_data iter_data = {
1855 lockdep_assert_held(&mvm->mutex);
1857 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1860 ieee80211_iterate_active_interfaces_atomic(
1861 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1862 iwl_mvm_mc_iface_iterator, &iter_data);
1865 * Send a (synchronous) ech command so that we wait for the
1866 * multiple asynchronous MCAST_FILTER_CMD commands sent by
1867 * the interface iterator. Otherwise, we might get here over
1868 * and over again (by userspace just sending a lot of these)
1869 * and the CPU can send them faster than the firmware can
1871 * Note that the CPU is still faster - but with this we'll
1872 * actually send fewer commands overall because the CPU will
1873 * not schedule the work in mac80211 as frequently if it's
1874 * still running when rescheduled (possibly multiple times).
1876 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1878 IWL_ERR(mvm, "Failed to synchronize multicast groups update\n");
1881 u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1882 struct netdev_hw_addr_list *mc_list)
1884 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1885 struct iwl_mcast_filter_cmd *cmd;
1886 struct netdev_hw_addr *addr;
1891 addr_count = netdev_hw_addr_list_count(mc_list);
1892 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1893 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1897 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1898 cmd = kzalloc(len, GFP_ATOMIC);
1904 return (u64)(unsigned long)cmd;
1907 netdev_hw_addr_list_for_each(addr, mc_list) {
1908 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1909 cmd->count, addr->addr);
1910 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1911 addr->addr, ETH_ALEN);
1915 return (u64)(unsigned long)cmd;
1918 void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1919 unsigned int changed_flags,
1920 unsigned int *total_flags, u64 multicast)
1922 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1923 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1925 mutex_lock(&mvm->mutex);
1927 /* replace previous configuration */
1928 kfree(mvm->mcast_filter_cmd);
1929 mvm->mcast_filter_cmd = cmd;
1934 if (changed_flags & FIF_ALLMULTI)
1935 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1940 iwl_mvm_recalc_multicast(mvm);
1942 mutex_unlock(&mvm->mutex);
1946 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1947 struct ieee80211_vif *vif,
1948 unsigned int filter_flags,
1949 unsigned int changed_flags)
1951 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1953 /* We support only filter for probe requests */
1954 if (!(changed_flags & FIF_PROBE_REQ))
1957 /* Supported only for p2p client interfaces */
1958 if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc ||
1962 mutex_lock(&mvm->mutex);
1963 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1964 mutex_unlock(&mvm->mutex);
1967 int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1969 struct iwl_mu_group_mgmt_cmd cmd = {};
1971 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1972 WLAN_MEMBERSHIP_LEN);
1973 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1974 WLAN_USER_POSITION_LEN);
1976 return iwl_mvm_send_cmd_pdu(mvm,
1977 WIDE_ID(DATA_PATH_GROUP,
1978 UPDATE_MU_GROUPS_CMD),
1979 0, sizeof(cmd), &cmd);
1982 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1983 struct ieee80211_vif *vif)
1985 if (vif->bss_conf.mu_mimo_owner) {
1986 struct iwl_mu_group_mgmt_notif *notif = _data;
1989 * MU-MIMO Group Id action frame is little endian. We treat
1990 * the data received from firmware as if it came from the
1991 * action frame, so no conversion is needed.
1993 ieee80211_update_mu_groups(vif, 0,
1994 (u8 *)¬if->membership_status,
1995 (u8 *)¬if->user_position);
1999 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
2000 struct iwl_rx_cmd_buffer *rxb)
2002 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2003 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
2005 ieee80211_iterate_active_interfaces_atomic(
2006 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
2007 iwl_mvm_mu_mimo_iface_iterator, notif);
2010 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
2012 u8 byte_num = ppe_pos_bit / 8;
2013 u8 bit_num = ppe_pos_bit % 8;
2018 return (ppe[byte_num] >> bit_num) &
2019 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
2022 * If bit_num > 5, we have to combine bits with next byte.
2023 * Calculate how many bits we need to take from current byte (called
2024 * here "residue_bits"), and add them to bits from next byte.
2027 residue_bits = 8 - bit_num;
2029 res = (ppe[byte_num + 1] &
2030 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
2032 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
2037 static void iwl_mvm_parse_ppe(struct iwl_mvm *mvm,
2038 struct iwl_he_pkt_ext_v2 *pkt_ext, u8 nss,
2039 u8 ru_index_bitmap, u8 *ppe, u8 ppe_pos_bit,
2045 * FW currently supports only nss == MAX_HE_SUPP_NSS
2047 * If nss > MAX: we can ignore values we don't support
2048 * If nss < MAX: we can set zeros in other streams
2050 if (nss > MAX_HE_SUPP_NSS) {
2051 IWL_DEBUG_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2053 nss = MAX_HE_SUPP_NSS;
2056 for (i = 0; i < nss; i++) {
2057 u8 ru_index_tmp = ru_index_bitmap << 1;
2058 u8 low_th = IWL_HE_PKT_EXT_NONE, high_th = IWL_HE_PKT_EXT_NONE;
2062 bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]);
2067 * According to the 11be spec, if for a specific BW the PPE Thresholds
2068 * isn't present - it should inherit the thresholds from the last
2069 * BW for which we had PPE Thresholds. In 11ax though, we don't have
2070 * this inheritance - continue in this case
2072 if (!(ru_index_tmp & 1)) {
2074 goto set_thresholds;
2079 high_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit);
2080 ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2081 low_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit);
2082 ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2085 pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th;
2086 pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th;
2091 static void iwl_mvm_set_pkt_ext_from_he_ppe(struct iwl_mvm *mvm,
2092 struct ieee80211_link_sta *link_sta,
2093 struct iwl_he_pkt_ext_v2 *pkt_ext,
2096 u8 nss = (link_sta->he_cap.ppe_thres[0] &
2097 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2098 u8 *ppe = &link_sta->he_cap.ppe_thres[0];
2099 u8 ru_index_bitmap =
2101 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK);
2102 /* Starting after PPE header */
2103 u8 ppe_pos_bit = IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE;
2105 iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, ppe, ppe_pos_bit,
2110 iwl_mvm_set_pkt_ext_from_nominal_padding(struct iwl_he_pkt_ext_v2 *pkt_ext,
2117 /* all the macros are the same for EHT and HE */
2118 switch (nominal_padding) {
2119 case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_0US:
2120 low_th = IWL_HE_PKT_EXT_NONE;
2121 high_th = IWL_HE_PKT_EXT_NONE;
2123 case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US:
2124 low_th = IWL_HE_PKT_EXT_BPSK;
2125 high_th = IWL_HE_PKT_EXT_NONE;
2127 case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US:
2128 case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_20US:
2129 low_th = IWL_HE_PKT_EXT_NONE;
2130 high_th = IWL_HE_PKT_EXT_BPSK;
2134 if (low_th < 0 || high_th < 0)
2137 /* Set the PPE thresholds accordingly */
2138 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
2142 bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]);
2144 pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th;
2145 pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th;
2152 static void iwl_mvm_get_optimal_ppe_info(struct iwl_he_pkt_ext_v2 *pkt_ext,
2157 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
2160 for (bw = 0; bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]);
2162 u8 *qam_th = &pkt_ext->pkt_ext_qam_th[i][bw][0];
2164 if (nominal_padding >
2165 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US &&
2166 qam_th[1] == IWL_HE_PKT_EXT_NONE)
2167 qam_th[1] = IWL_HE_PKT_EXT_4096QAM;
2168 else if (nominal_padding ==
2169 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US &&
2170 qam_th[0] == IWL_HE_PKT_EXT_NONE &&
2171 qam_th[1] == IWL_HE_PKT_EXT_NONE)
2172 qam_th[0] = IWL_HE_PKT_EXT_4096QAM;
2177 /* Set the pkt_ext field according to PPE Thresholds element */
2178 int iwl_mvm_set_sta_pkt_ext(struct iwl_mvm *mvm,
2179 struct ieee80211_link_sta *link_sta,
2180 struct iwl_he_pkt_ext_v2 *pkt_ext)
2185 if (WARN_ON(!link_sta))
2188 /* Initialize the PPE thresholds to "None" (7), as described in Table
2189 * 9-262ac of 80211.ax/D3.0.
2191 memset(pkt_ext, IWL_HE_PKT_EXT_NONE,
2192 sizeof(struct iwl_he_pkt_ext_v2));
2194 if (link_sta->eht_cap.has_eht) {
2196 u8_get_bits(link_sta->eht_cap.eht_cap_elem.phy_cap_info[5],
2197 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK);
2199 /* If PPE Thresholds exists, parse them into a FW-familiar
2202 if (link_sta->eht_cap.eht_cap_elem.phy_cap_info[5] &
2203 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) {
2204 u8 nss = (link_sta->eht_cap.eht_ppe_thres[0] &
2205 IEEE80211_EHT_PPE_THRES_NSS_MASK) + 1;
2206 u8 *ppe = &link_sta->eht_cap.eht_ppe_thres[0];
2207 u8 ru_index_bitmap =
2209 IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK);
2210 /* Starting after PPE header */
2211 u8 ppe_pos_bit = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE;
2213 iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap,
2214 ppe, ppe_pos_bit, true);
2215 /* EHT PPE Thresholds doesn't exist - set the API according to
2218 } else if (link_sta->he_cap.he_cap_elem.phy_cap_info[6] &
2219 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2220 /* Even though HE Capabilities IE doesn't contain PPE
2221 * Thresholds for BW 320Mhz, thresholds for this BW will
2222 * be filled in with the same values as 160Mhz, due to
2223 * the inheritance, as required.
2225 iwl_mvm_set_pkt_ext_from_he_ppe(mvm, link_sta, pkt_ext,
2228 /* According to the requirements, for MCSs 12-13 the
2229 * maximum value between HE PPE Threshold and Common
2230 * Nominal Packet Padding needs to be taken
2232 iwl_mvm_get_optimal_ppe_info(pkt_ext, nominal_padding);
2234 /* if PPE Thresholds doesn't present in both EHT IE and HE IE -
2235 * take the Thresholds from Common Nominal Packet Padding field
2238 ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext,
2241 } else if (link_sta->he_cap.has_he) {
2242 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2243 if (link_sta->he_cap.he_cap_elem.phy_cap_info[6] &
2244 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2245 iwl_mvm_set_pkt_ext_from_he_ppe(mvm, link_sta, pkt_ext,
2247 /* PPE Thresholds doesn't exist - set the API PPE values
2248 * according to Common Nominal Packet Padding field.
2252 u8_get_bits(link_sta->he_cap.he_cap_elem.phy_cap_info[9],
2253 IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK);
2254 if (nominal_padding != IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED)
2255 ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext,
2260 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
2264 bw < ARRAY_SIZE(*pkt_ext->pkt_ext_qam_th[i]);
2267 &pkt_ext->pkt_ext_qam_th[i][bw][0];
2270 "PPE table: nss[%d] bw[%d] PPET8 = %d, PPET16 = %d\n",
2271 i, bw, qam_th[0], qam_th[1]);
2278 * This function sets the MU EDCA parameters ans returns whether MU EDCA
2281 bool iwl_mvm_set_fw_mu_edca_params(struct iwl_mvm *mvm,
2282 const struct iwl_mvm_vif_link_info *link_info,
2283 struct iwl_he_backoff_conf *trig_based_txf)
2286 /* Mark MU EDCA as enabled, unless none detected on some AC */
2287 bool mu_edca_enabled = true;
2289 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
2290 const struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2291 &link_info->queue_params[i].mu_edca_param_rec;
2292 u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
2294 if (!link_info->queue_params[i].mu_edca) {
2295 mu_edca_enabled = false;
2299 trig_based_txf[ac].cwmin =
2300 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2301 trig_based_txf[ac].cwmax =
2302 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2303 trig_based_txf[ac].aifsn =
2304 cpu_to_le16(mu_edca->aifsn & 0xf);
2305 trig_based_txf[ac].mu_time =
2306 cpu_to_le16(mu_edca->mu_edca_timer);
2309 return mu_edca_enabled;
2312 bool iwl_mvm_is_nic_ack_enabled(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2314 const struct ieee80211_supported_band *sband;
2315 const struct ieee80211_sta_he_cap *own_he_cap = NULL;
2317 /* This capability is the same for all bands,
2318 * so take it from one of them.
2320 sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ];
2321 own_he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif);
2323 return (own_he_cap && (own_he_cap->he_cap_elem.mac_cap_info[2] &
2324 IEEE80211_HE_MAC_CAP2_ACK_EN));
2327 __le32 iwl_mvm_get_sta_htc_flags(struct ieee80211_sta *sta,
2328 struct ieee80211_link_sta *link_sta)
2331 &link_sta->he_cap.he_cap_elem.mac_cap_info[0];
2332 __le32 htc_flags = 0;
2334 if (mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_HTC_HE)
2335 htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
2336 if ((mac_cap_info[1] & IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2337 (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2340 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2342 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2346 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2347 else if (link_adap == 3)
2348 htc_flags |= cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2350 if (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2351 htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2352 if (mac_cap_info[3] & IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2353 htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2354 if (mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2355 htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2360 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
2361 struct ieee80211_vif *vif, u8 sta_id)
2363 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2364 struct iwl_he_sta_context_cmd_v3 sta_ctxt_cmd = {
2366 .tid_limit = IWL_MAX_TID_COUNT,
2367 .bss_color = vif->bss_conf.he_bss_color.color,
2368 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
2369 .frame_time_rts_th =
2370 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
2372 struct iwl_he_sta_context_cmd_v2 sta_ctxt_cmd_v2 = {};
2373 u32 cmd_id = WIDE_ID(DATA_PATH_GROUP, STA_HE_CTXT_CMD);
2374 u8 ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 2);
2376 struct ieee80211_sta *sta;
2381 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_MBSSID_HE))
2386 /* same layout as v2 except some data at the end */
2387 cmd = &sta_ctxt_cmd_v2;
2388 size = sizeof(struct iwl_he_sta_context_cmd_v1);
2391 cmd = &sta_ctxt_cmd_v2;
2392 size = sizeof(struct iwl_he_sta_context_cmd_v2);
2395 cmd = &sta_ctxt_cmd;
2396 size = sizeof(struct iwl_he_sta_context_cmd_v3);
2399 IWL_ERR(mvm, "bad STA_HE_CTXT_CMD version %d\n", ver);
2405 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
2406 if (IS_ERR_OR_NULL(sta)) {
2408 WARN(1, "Can't find STA to configure HE\n");
2412 if (!sta->deflink.he_cap.has_he) {
2419 /* Block 26-tone RU OFDMA transmissions */
2420 if (mvmvif->deflink.he_ru_2mhz_block)
2421 flags |= STA_CTXT_HE_RU_2MHZ_BLOCK;
2424 sta_ctxt_cmd.htc_flags = iwl_mvm_get_sta_htc_flags(sta, &sta->deflink);
2426 /* PPE Thresholds */
2427 if (!iwl_mvm_set_sta_pkt_ext(mvm, &sta->deflink, &sta_ctxt_cmd.pkt_ext))
2428 flags |= STA_CTXT_HE_PACKET_EXT;
2430 if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] &
2431 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP)
2432 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2434 if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] &
2435 IEEE80211_HE_MAC_CAP2_ACK_EN)
2436 flags |= STA_CTXT_HE_ACK_ENABLED;
2440 if (iwl_mvm_set_fw_mu_edca_params(mvm, &mvmvif->deflink,
2441 &sta_ctxt_cmd.trig_based_txf[0]))
2442 flags |= STA_CTXT_HE_MU_EDCA_CW;
2444 if (vif->bss_conf.uora_exists) {
2445 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2447 sta_ctxt_cmd.rand_alloc_ecwmin =
2448 vif->bss_conf.uora_ocw_range & 0x7;
2449 sta_ctxt_cmd.rand_alloc_ecwmax =
2450 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2453 if (!iwl_mvm_is_nic_ack_enabled(mvm, vif))
2454 flags |= STA_CTXT_HE_NIC_NOT_ACK_ENABLED;
2456 if (vif->bss_conf.nontransmitted) {
2457 flags |= STA_CTXT_HE_REF_BSSID_VALID;
2458 ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr,
2459 vif->bss_conf.transmitter_bssid);
2460 sta_ctxt_cmd.max_bssid_indicator =
2461 vif->bss_conf.bssid_indicator;
2462 sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index;
2463 sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap;
2464 sta_ctxt_cmd.profile_periodicity =
2465 vif->bss_conf.profile_periodicity;
2468 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2471 /* fields before pkt_ext */
2472 BUILD_BUG_ON(offsetof(typeof(sta_ctxt_cmd), pkt_ext) !=
2473 offsetof(typeof(sta_ctxt_cmd_v2), pkt_ext));
2474 memcpy(&sta_ctxt_cmd_v2, &sta_ctxt_cmd,
2475 offsetof(typeof(sta_ctxt_cmd), pkt_ext));
2479 i < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th);
2484 bw < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i]);
2486 BUILD_BUG_ON(sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]) !=
2487 sizeof(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw]));
2489 memcpy(&sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw],
2490 &sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw],
2491 sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]));
2495 /* fields after pkt_ext */
2496 BUILD_BUG_ON(sizeof(sta_ctxt_cmd) -
2497 offsetofend(typeof(sta_ctxt_cmd), pkt_ext) !=
2498 sizeof(sta_ctxt_cmd_v2) -
2499 offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext));
2500 memcpy((u8 *)&sta_ctxt_cmd_v2 +
2501 offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext),
2502 (u8 *)&sta_ctxt_cmd +
2503 offsetofend(typeof(sta_ctxt_cmd), pkt_ext),
2504 sizeof(sta_ctxt_cmd) -
2505 offsetofend(typeof(sta_ctxt_cmd), pkt_ext));
2506 sta_ctxt_cmd_v2.reserved3 = 0;
2509 if (iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, size, cmd))
2510 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2513 void iwl_mvm_protect_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2514 u32 duration_override, unsigned int link_id)
2516 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
2517 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
2519 if (duration_override > duration)
2520 duration = duration_override;
2522 /* Try really hard to protect the session and hear a beacon
2523 * The new session protection command allows us to protect the
2524 * session for a much longer time since the firmware will internally
2525 * create two events: a 300TU one with a very high priority that
2526 * won't be fragmented which should be enough for 99% of the cases,
2527 * and another one (which we configure here to be 900TU long) which
2528 * will have a slightly lower priority, but more importantly, can be
2529 * fragmented so that it'll allow other activities to run.
2531 if (fw_has_capa(&mvm->fw->ucode_capa,
2532 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD))
2533 iwl_mvm_schedule_session_protection(mvm, vif, 900,
2534 min_duration, false,
2537 iwl_mvm_protect_session(mvm, vif, duration,
2538 min_duration, 500, false);
2541 /* Handle association common part to MLD and non-MLD modes */
2542 void iwl_mvm_bss_info_changed_station_assoc(struct iwl_mvm *mvm,
2543 struct ieee80211_vif *vif,
2546 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2549 /* The firmware tracks the MU-MIMO group on its own.
2550 * However, on HW restart we should restore this data.
2552 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2553 (changes & BSS_CHANGED_MU_GROUPS) && vif->bss_conf.mu_mimo_owner) {
2554 ret = iwl_mvm_update_mu_groups(mvm, vif);
2557 "failed to update VHT MU_MIMO groups\n");
2560 iwl_mvm_recalc_multicast(mvm);
2562 /* reset rssi values */
2563 mvmvif->bf_data.ave_beacon_signal = 0;
2565 iwl_mvm_bt_coex_vif_change(mvm);
2566 iwl_mvm_update_smps_on_active_links(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2567 IEEE80211_SMPS_AUTOMATIC);
2568 if (fw_has_capa(&mvm->fw->ucode_capa,
2569 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2570 iwl_mvm_config_scan(mvm);
2573 /* Execute the common part for MLD and non-MLD modes */
2575 iwl_mvm_bss_info_changed_station_common(struct iwl_mvm *mvm,
2576 struct ieee80211_vif *vif,
2577 struct ieee80211_bss_conf *link_conf,
2580 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2583 if (changes & BSS_CHANGED_BEACON_INFO) {
2584 /* We received a beacon from the associated AP so
2585 * remove the session protection.
2587 iwl_mvm_stop_session_protection(mvm, vif);
2589 iwl_mvm_sf_update(mvm, vif, false);
2590 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
2593 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2594 /* Send power command on every beacon change,
2595 * because we may have not enabled beacon abort yet.
2597 BSS_CHANGED_BEACON_INFO)) {
2598 ret = iwl_mvm_power_update_mac(mvm);
2600 IWL_ERR(mvm, "failed to update power mode\n");
2603 if (changes & BSS_CHANGED_CQM) {
2604 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2605 /* reset cqm events tracking */
2606 mvmvif->bf_data.last_cqm_event = 0;
2607 if (mvmvif->bf_data.bf_enabled) {
2608 /* FIXME: need to update per link when FW API will
2611 ret = iwl_mvm_enable_beacon_filter(mvm, vif);
2614 "failed to update CQM thresholds\n");
2618 if (changes & BSS_CHANGED_BANDWIDTH)
2619 iwl_mvm_update_link_smps(vif, link_conf);
2622 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2623 struct ieee80211_vif *vif,
2624 struct ieee80211_bss_conf *bss_conf,
2627 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2632 * Re-calculate the tsf id, as the leader-follower relations depend
2633 * on the beacon interval, which was not known when the station
2634 * interface was added.
2636 if (changes & BSS_CHANGED_ASSOC && vif->cfg.assoc) {
2637 if ((vif->bss_conf.he_support &&
2638 !iwlwifi_mod_params.disable_11ax))
2639 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->deflink.ap_sta_id);
2641 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2644 /* Update MU EDCA params */
2645 if (changes & BSS_CHANGED_QOS && mvmvif->associated &&
2647 (vif->bss_conf.he_support && !iwlwifi_mod_params.disable_11ax))
2648 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->deflink.ap_sta_id);
2651 * If we're not associated yet, take the (new) BSSID before associating
2652 * so the firmware knows. If we're already associated, then use the old
2653 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2654 * branch for disassociation below.
2656 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2657 memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN);
2659 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->deflink.bssid);
2661 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2663 /* after sending it once, adopt mac80211 data */
2664 memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN);
2665 mvmvif->associated = vif->cfg.assoc;
2667 if (changes & BSS_CHANGED_ASSOC) {
2668 if (vif->cfg.assoc) {
2669 /* clear statistics to get clean beacon counter */
2670 iwl_mvm_request_statistics(mvm, true);
2671 for_each_mvm_vif_valid_link(mvmvif, i)
2672 memset(&mvmvif->link[i]->beacon_stats, 0,
2673 sizeof(mvmvif->link[i]->beacon_stats));
2675 /* add quota for this interface */
2676 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2678 IWL_ERR(mvm, "failed to update quotas\n");
2682 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2684 !fw_has_capa(&mvm->fw->ucode_capa,
2685 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) {
2687 * If we're restarting then the firmware will
2688 * obviously have lost synchronisation with
2689 * the AP. It will attempt to synchronise by
2690 * itself, but we can make it more reliable by
2691 * scheduling a session protection time event.
2693 * The firmware needs to receive a beacon to
2694 * catch up with synchronisation, use 110% of
2695 * the beacon interval.
2697 * Set a large maximum delay to allow for more
2698 * than a single interface.
2700 * For new firmware versions, rely on the
2701 * firmware. This is relevant for DCM scenarios
2704 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2705 iwl_mvm_protect_session(mvm, vif, dur, dur,
2707 } else if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2709 !vif->bss_conf.dtim_period) {
2711 * If we're not restarting and still haven't
2712 * heard a beacon (dtim period unknown) then
2713 * make sure we still have enough minimum time
2714 * remaining in the time event, since the auth
2715 * might actually have taken quite a while
2716 * (especially for SAE) and so the remaining
2717 * time could be small without us having heard
2720 iwl_mvm_protect_assoc(mvm, vif, 0, 0);
2723 iwl_mvm_sf_update(mvm, vif, false);
2724 iwl_mvm_power_vif_assoc(mvm, vif);
2726 iwl_mvm_update_smps(mvm, vif,
2727 IWL_MVM_SMPS_REQ_PROT,
2728 IEEE80211_SMPS_DYNAMIC, 0);
2730 } else if (mvmvif->deflink.ap_sta_id != IWL_MVM_INVALID_STA) {
2731 iwl_mvm_mei_host_disassociated(mvm);
2733 * If update fails - SF might be running in associated
2734 * mode while disassociated - which is forbidden.
2736 ret = iwl_mvm_sf_update(mvm, vif, false);
2738 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
2740 "Failed to update SF upon disassociation\n");
2743 * If we get an assert during the connection (after the
2744 * station has been added, but before the vif is set
2745 * to associated), mac80211 will re-add the station and
2746 * then configure the vif. Since the vif is not
2747 * associated, we would remove the station here and
2748 * this would fail the recovery.
2750 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2752 /* first remove remaining keys */
2753 iwl_mvm_sec_key_remove_ap(mvm, vif,
2754 &mvmvif->deflink, 0);
2757 * Remove AP station now that
2758 * the MAC is unassoc
2760 ret = iwl_mvm_rm_sta_id(mvm, vif,
2761 mvmvif->deflink.ap_sta_id);
2764 "failed to remove AP station\n");
2766 mvmvif->deflink.ap_sta_id = IWL_MVM_INVALID_STA;
2769 /* remove quota for this interface */
2770 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2772 IWL_ERR(mvm, "failed to update quotas\n");
2774 /* this will take the cleared BSSID from bss_conf */
2775 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2778 "failed to update MAC %pM (clear after unassoc)\n",
2782 iwl_mvm_bss_info_changed_station_assoc(mvm, vif, changes);
2785 iwl_mvm_bss_info_changed_station_common(mvm, vif, &vif->bss_conf,
2789 bool iwl_mvm_start_ap_ibss_common(struct ieee80211_hw *hw,
2790 struct ieee80211_vif *vif,
2793 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2794 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2797 lockdep_assert_held(&mvm->mutex);
2799 mvmvif->ap_assoc_sta_count = 0;
2801 /* must be set before quota calculations */
2802 mvmvif->ap_ibss_active = true;
2804 /* send all the early keys to the device now */
2805 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
2806 struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i];
2811 mvmvif->ap_early_keys[i] = NULL;
2813 *ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key);
2818 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2819 iwl_mvm_vif_set_low_latency(mvmvif, true,
2820 LOW_LATENCY_VIF_TYPE);
2821 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2824 /* power updated needs to be done before quotas */
2825 iwl_mvm_power_update_mac(mvm);
2830 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2831 struct ieee80211_vif *vif,
2832 struct ieee80211_bss_conf *link_conf)
2834 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2835 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2838 mutex_lock(&mvm->mutex);
2841 * Re-calculate the tsf id, as the leader-follower relations depend on
2842 * the beacon interval, which was not known when the AP interface
2845 if (vif->type == NL80211_IFTYPE_AP)
2846 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2848 /* For older devices need to send beacon template before adding mac
2849 * context. For the newer, the beacon is a resource that belongs to a
2850 * MAC, so need to send beacon template after adding the mac.
2852 if (mvm->trans->trans_cfg->device_family > IWL_DEVICE_FAMILY_22000) {
2853 /* Add the mac context */
2854 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2858 /* Send the beacon template */
2859 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf);
2863 /* Send the beacon template */
2864 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf);
2868 /* Add the mac context */
2869 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2874 /* Perform the binding */
2875 ret = iwl_mvm_binding_add_vif(mvm, vif);
2880 * This is not very nice, but the simplest:
2881 * For older FWs adding the mcast sta before the bcast station may
2882 * cause assert 0x2b00.
2883 * This is fixed in later FW so make the order of removal depend on
2886 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2887 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2891 * Send the bcast station. At this stage the TBTT and DTIM time
2892 * events are added and applied to the scheduler
2894 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2896 iwl_mvm_rm_mcast_sta(mvm, vif);
2901 * Send the bcast station. At this stage the TBTT and DTIM time
2902 * events are added and applied to the scheduler
2904 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2907 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2909 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2914 if (iwl_mvm_start_ap_ibss_common(hw, vif, &ret))
2917 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2921 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2922 if (vif->p2p && mvm->p2p_device_vif)
2923 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2925 iwl_mvm_bt_coex_vif_change(mvm);
2927 /* we don't support TDLS during DCM */
2928 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2929 iwl_mvm_teardown_tdls_peers(mvm);
2931 iwl_mvm_ftm_restart_responder(mvm, vif, &vif->bss_conf);
2936 iwl_mvm_power_update_mac(mvm);
2937 mvmvif->ap_ibss_active = false;
2938 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2939 iwl_mvm_rm_mcast_sta(mvm, vif);
2941 iwl_mvm_binding_remove_vif(mvm, vif);
2943 iwl_mvm_mac_ctxt_remove(mvm, vif);
2945 mutex_unlock(&mvm->mutex);
2949 static int iwl_mvm_start_ap(struct ieee80211_hw *hw,
2950 struct ieee80211_vif *vif,
2951 struct ieee80211_bss_conf *link_conf)
2953 return iwl_mvm_start_ap_ibss(hw, vif, link_conf);
2956 static int iwl_mvm_start_ibss(struct ieee80211_hw *hw,
2957 struct ieee80211_vif *vif)
2959 return iwl_mvm_start_ap_ibss(hw, vif, &vif->bss_conf);
2962 /* Common part for MLD and non-MLD ops */
2963 void iwl_mvm_stop_ap_ibss_common(struct iwl_mvm *mvm,
2964 struct ieee80211_vif *vif)
2966 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2968 lockdep_assert_held(&mvm->mutex);
2970 iwl_mvm_prepare_mac_removal(mvm, vif);
2972 /* Handle AP stop while in CSA */
2973 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2974 iwl_mvm_remove_time_event(mvm, mvmvif,
2975 &mvmvif->time_event_data);
2976 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2977 mvmvif->csa_countdown = false;
2980 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2981 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2982 mvm->csa_tx_block_bcn_timeout = 0;
2985 mvmvif->ap_ibss_active = false;
2986 mvm->ap_last_beacon_gp2 = 0;
2988 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2989 iwl_mvm_vif_set_low_latency(mvmvif, false,
2990 LOW_LATENCY_VIF_TYPE);
2991 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2994 iwl_mvm_bt_coex_vif_change(mvm);
2997 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2998 struct ieee80211_vif *vif,
2999 struct ieee80211_bss_conf *link_conf)
3001 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3003 mutex_lock(&mvm->mutex);
3005 iwl_mvm_stop_ap_ibss_common(mvm, vif);
3007 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
3008 if (vif->p2p && mvm->p2p_device_vif)
3009 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
3011 iwl_mvm_update_quotas(mvm, false, NULL);
3013 iwl_mvm_ftm_responder_clear(mvm, vif);
3016 * This is not very nice, but the simplest:
3017 * For older FWs removing the mcast sta before the bcast station may
3018 * cause assert 0x2b00.
3019 * This is fixed in later FW (which will stop beaconing when removing
3021 * So make the order of removal depend on the TLV
3023 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
3024 iwl_mvm_rm_mcast_sta(mvm, vif);
3025 iwl_mvm_send_rm_bcast_sta(mvm, vif);
3026 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
3027 iwl_mvm_rm_mcast_sta(mvm, vif);
3028 iwl_mvm_binding_remove_vif(mvm, vif);
3030 iwl_mvm_power_update_mac(mvm);
3032 iwl_mvm_mac_ctxt_remove(mvm, vif);
3034 mutex_unlock(&mvm->mutex);
3037 static void iwl_mvm_stop_ap(struct ieee80211_hw *hw,
3038 struct ieee80211_vif *vif,
3039 struct ieee80211_bss_conf *link_conf)
3041 iwl_mvm_stop_ap_ibss(hw, vif, link_conf);
3044 static void iwl_mvm_stop_ibss(struct ieee80211_hw *hw,
3045 struct ieee80211_vif *vif)
3047 iwl_mvm_stop_ap_ibss(hw, vif, &vif->bss_conf);
3051 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
3052 struct ieee80211_vif *vif,
3053 struct ieee80211_bss_conf *bss_conf,
3056 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3058 /* Changes will be applied when the AP/IBSS is started */
3059 if (!mvmvif->ap_ibss_active)
3062 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
3063 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
3064 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
3065 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
3067 /* Need to send a new beacon template to the FW */
3068 if (changes & BSS_CHANGED_BEACON &&
3069 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, &vif->bss_conf))
3070 IWL_WARN(mvm, "Failed updating beacon data\n");
3072 if (changes & BSS_CHANGED_FTM_RESPONDER) {
3073 int ret = iwl_mvm_ftm_start_responder(mvm, vif, &vif->bss_conf);
3076 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
3082 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
3083 struct ieee80211_vif *vif,
3084 struct ieee80211_bss_conf *bss_conf,
3087 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3089 mutex_lock(&mvm->mutex);
3091 if (changes & BSS_CHANGED_IDLE && !vif->cfg.idle)
3092 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
3094 switch (vif->type) {
3095 case NL80211_IFTYPE_STATION:
3096 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
3098 case NL80211_IFTYPE_AP:
3099 case NL80211_IFTYPE_ADHOC:
3100 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
3102 case NL80211_IFTYPE_MONITOR:
3103 if (changes & BSS_CHANGED_MU_GROUPS)
3104 iwl_mvm_update_mu_groups(mvm, vif);
3107 /* shouldn't happen */
3111 if (changes & BSS_CHANGED_TXPOWER) {
3112 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n",
3114 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
3117 mutex_unlock(&mvm->mutex);
3120 int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3121 struct ieee80211_scan_request *hw_req)
3123 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3126 if (hw_req->req.n_channels == 0 ||
3127 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
3130 mutex_lock(&mvm->mutex);
3131 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
3132 mutex_unlock(&mvm->mutex);
3137 void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
3138 struct ieee80211_vif *vif)
3140 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3142 mutex_lock(&mvm->mutex);
3144 /* Due to a race condition, it's possible that mac80211 asks
3145 * us to stop a hw_scan when it's already stopped. This can
3146 * happen, for instance, if we stopped the scan ourselves,
3147 * called ieee80211_scan_completed() and the userspace called
3148 * cancel scan scan before ieee80211_scan_work() could run.
3149 * To handle that, simply return if the scan is not running.
3151 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
3152 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
3154 mutex_unlock(&mvm->mutex);
3158 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
3159 struct ieee80211_sta *sta, u16 tids,
3161 enum ieee80211_frame_release_type reason,
3164 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3166 /* Called when we need to transmit (a) frame(s) from mac80211 */
3168 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
3169 tids, more_data, false);
3173 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
3174 struct ieee80211_sta *sta, u16 tids,
3176 enum ieee80211_frame_release_type reason,
3179 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3181 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
3183 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
3184 tids, more_data, true);
3187 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
3188 enum sta_notify_cmd cmd,
3189 struct ieee80211_sta *sta)
3191 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3192 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3193 unsigned long txqs = 0, tids = 0;
3197 * If we have TVQM then we get too high queue numbers - luckily
3198 * we really shouldn't get here with that because such hardware
3199 * should have firmware supporting buffer station offload.
3201 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
3204 spin_lock_bh(&mvmsta->lock);
3205 for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) {
3206 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
3208 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
3211 __set_bit(tid_data->txq_id, &txqs);
3213 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
3216 __set_bit(tid, &tids);
3220 case STA_NOTIFY_SLEEP:
3221 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
3222 ieee80211_sta_set_buffered(sta, tid, true);
3225 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
3227 * The fw updates the STA to be asleep. Tx packets on the Tx
3228 * queues to this station will not be transmitted. The fw will
3229 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
3232 case STA_NOTIFY_AWAKE:
3233 if (WARN_ON(mvmsta->deflink.sta_id == IWL_MVM_INVALID_STA))
3237 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
3238 iwl_mvm_sta_modify_ps_wake(mvm, sta);
3243 spin_unlock_bh(&mvmsta->lock);
3246 void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3247 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
3249 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
3252 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
3254 struct iwl_rx_packet *pkt = rxb_addr(rxb);
3255 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
3256 struct ieee80211_sta *sta;
3257 struct iwl_mvm_sta *mvmsta;
3258 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
3260 if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations))
3264 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
3265 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
3270 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3273 mvmsta->vif->type != NL80211_IFTYPE_AP) {
3278 if (mvmsta->sleeping != sleeping) {
3279 mvmsta->sleeping = sleeping;
3280 __iwl_mvm_mac_sta_notify(mvm->hw,
3281 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
3283 ieee80211_sta_ps_transition(sta, sleeping);
3287 switch (notif->type) {
3288 case IWL_MVM_PM_EVENT_AWAKE:
3289 case IWL_MVM_PM_EVENT_ASLEEP:
3291 case IWL_MVM_PM_EVENT_UAPSD:
3292 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
3294 case IWL_MVM_PM_EVENT_PS_POLL:
3295 ieee80211_sta_pspoll(sta);
3305 void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
3306 struct ieee80211_vif *vif,
3307 struct ieee80211_sta *sta)
3309 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3310 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3311 unsigned int link_id;
3314 * This is called before mac80211 does RCU synchronisation,
3315 * so here we already invalidate our internal RCU-protected
3316 * station pointer. The rest of the code will thus no longer
3317 * be able to find the station this way, and we don't rely
3318 * on further RCU synchronisation after the sta_state()
3319 * callback deleted the station.
3320 * Since there's mvm->mutex here, no need to have RCU lock for
3321 * mvm_sta->link access.
3323 mutex_lock(&mvm->mutex);
3324 for (link_id = 0; link_id < ARRAY_SIZE(mvm_sta->link); link_id++) {
3325 struct iwl_mvm_link_sta *link_sta;
3328 if (!mvm_sta->link[link_id])
3331 link_sta = rcu_dereference_protected(mvm_sta->link[link_id],
3332 lockdep_is_held(&mvm->mutex));
3333 sta_id = link_sta->sta_id;
3334 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[sta_id])) {
3335 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id],
3337 RCU_INIT_POINTER(mvm->fw_id_to_link_sta[sta_id], NULL);
3340 mutex_unlock(&mvm->mutex);
3343 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3348 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
3349 struct iwl_mvm_tcm_mac *mdata;
3351 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
3352 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
3353 mdata->opened_rx_ba_sessions = false;
3356 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
3359 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
3360 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3365 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
3366 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3370 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
3371 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
3372 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3377 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3381 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
3382 struct ieee80211_vif *vif, u8 *peer_addr,
3383 enum nl80211_tdls_operation action)
3385 struct iwl_fw_dbg_trigger_tlv *trig;
3386 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
3388 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
3389 FW_DBG_TRIGGER_TDLS);
3393 tdls_trig = (void *)trig->data;
3395 if (!(tdls_trig->action_bitmap & BIT(action)))
3398 if (tdls_trig->peer_mode &&
3399 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
3402 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
3403 "TDLS event occurred, peer %pM, action %d",
3407 struct iwl_mvm_he_obss_narrow_bw_ru_data {
3411 static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy,
3412 struct cfg80211_bss *bss,
3415 struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data;
3416 const struct cfg80211_bss_ies *ies;
3417 const struct element *elem;
3420 ies = rcu_dereference(bss->ies);
3421 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data,
3424 if (!elem || elem->datalen < 10 ||
3426 WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) {
3427 data->tolerated = false;
3433 iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw,
3434 struct ieee80211_vif *vif,
3435 unsigned int link_id,
3436 struct ieee80211_bss_conf *link_conf)
3438 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3439 struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = {
3443 if (WARN_ON_ONCE(!link_conf->chanreq.oper.chan ||
3444 !mvmvif->link[link_id]))
3447 if (!(link_conf->chanreq.oper.chan->flags & IEEE80211_CHAN_RADAR)) {
3448 mvmvif->link[link_id]->he_ru_2mhz_block = false;
3452 cfg80211_bss_iter(hw->wiphy, &link_conf->chanreq.oper,
3453 iwl_mvm_check_he_obss_narrow_bw_ru_iter,
3457 * If there is at least one AP on radar channel that cannot
3458 * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
3460 mvmvif->link[link_id]->he_ru_2mhz_block = !iter_data.tolerated;
3463 static void iwl_mvm_reset_cca_40mhz_workaround(struct iwl_mvm *mvm,
3464 struct ieee80211_vif *vif)
3466 struct ieee80211_supported_band *sband;
3467 const struct ieee80211_sta_he_cap *he_cap;
3469 if (vif->type != NL80211_IFTYPE_STATION)
3472 if (!mvm->cca_40mhz_workaround)
3475 /* decrement and check that we reached zero */
3476 mvm->cca_40mhz_workaround--;
3477 if (mvm->cca_40mhz_workaround)
3480 sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ];
3482 sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3484 he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif);
3487 /* we know that ours is writable */
3488 struct ieee80211_sta_he_cap *he = (void *)(uintptr_t)he_cap;
3490 he->he_cap_elem.phy_cap_info[0] |=
3491 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
3495 static void iwl_mvm_mei_host_associated(struct iwl_mvm *mvm,
3496 struct ieee80211_vif *vif,
3497 struct iwl_mvm_sta *mvm_sta)
3499 #if IS_ENABLED(CONFIG_IWLMEI)
3500 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3501 struct iwl_mei_conn_info conn_info = {
3502 .ssid_len = vif->cfg.ssid_len,
3505 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3508 if (!mvm->mei_registered)
3511 /* FIXME: MEI needs to be updated for MLO */
3512 if (!vif->bss_conf.chanreq.oper.chan)
3515 conn_info.channel = vif->bss_conf.chanreq.oper.chan->hw_value;
3517 switch (mvm_sta->pairwise_cipher) {
3518 case WLAN_CIPHER_SUITE_TKIP:
3519 conn_info.pairwise_cipher = IWL_MEI_CIPHER_TKIP;
3521 case WLAN_CIPHER_SUITE_CCMP:
3522 conn_info.pairwise_cipher = IWL_MEI_CIPHER_CCMP;
3524 case WLAN_CIPHER_SUITE_GCMP:
3525 conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP;
3527 case WLAN_CIPHER_SUITE_GCMP_256:
3528 conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP_256;
3534 /* cipher not supported, don't send anything to iwlmei */
3538 switch (mvmvif->rekey_data.akm) {
3539 case WLAN_AKM_SUITE_SAE & 0xff:
3540 conn_info.auth_mode = IWL_MEI_AKM_AUTH_SAE;
3542 case WLAN_AKM_SUITE_PSK & 0xff:
3543 conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA_PSK;
3545 case WLAN_AKM_SUITE_8021X & 0xff:
3546 conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA;
3550 conn_info.auth_mode = IWL_MEI_AKM_AUTH_OPEN;
3553 /* auth method / AKM not supported */
3554 /* TODO: All the FT vesions of these? */
3558 memcpy(conn_info.ssid, vif->cfg.ssid, vif->cfg.ssid_len);
3559 memcpy(conn_info.bssid, vif->bss_conf.bssid, ETH_ALEN);
3561 /* TODO: add support for collocated AP data */
3562 iwl_mei_host_associated(&conn_info, NULL);
3566 static int iwl_mvm_mac_ctxt_changed_wrapper(struct iwl_mvm *mvm,
3567 struct ieee80211_vif *vif,
3568 bool force_assoc_off)
3570 return iwl_mvm_mac_ctxt_changed(mvm, vif, force_assoc_off, NULL);
3573 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
3574 struct ieee80211_vif *vif,
3575 struct ieee80211_sta *sta,
3576 enum ieee80211_sta_state old_state,
3577 enum ieee80211_sta_state new_state)
3579 static const struct iwl_mvm_sta_state_ops callbacks = {
3580 .add_sta = iwl_mvm_add_sta,
3581 .update_sta = iwl_mvm_update_sta,
3582 .rm_sta = iwl_mvm_rm_sta,
3583 .mac_ctxt_changed = iwl_mvm_mac_ctxt_changed_wrapper,
3586 return iwl_mvm_mac_sta_state_common(hw, vif, sta, old_state, new_state,
3590 /* FIXME: temporary making two assumptions in all sta handling functions:
3591 * (1) when setting sta state, the link exists and protected
3592 * (2) if a link is valid in sta then it's valid in vif (can
3593 * use same index in the link array)
3595 static void iwl_mvm_rs_rate_init_all_links(struct iwl_mvm *mvm,
3596 struct ieee80211_vif *vif,
3597 struct ieee80211_sta *sta)
3599 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3600 unsigned int link_id;
3602 for_each_mvm_vif_valid_link(mvmvif, link_id) {
3603 struct ieee80211_bss_conf *conf =
3604 link_conf_dereference_check(vif, link_id);
3605 struct ieee80211_link_sta *link_sta =
3606 link_sta_dereference_check(sta, link_id);
3608 if (!conf || !link_sta || !mvmvif->link[link_id]->phy_ctxt)
3611 iwl_mvm_rs_rate_init(mvm, vif, sta, conf, link_sta,
3612 mvmvif->link[link_id]->phy_ctxt->channel->band);
3616 #define IWL_MVM_MIN_BEACON_INTERVAL_TU 16
3618 static bool iwl_mvm_vif_conf_from_sta(struct iwl_mvm *mvm,
3619 struct ieee80211_vif *vif,
3620 struct ieee80211_sta *sta)
3622 struct ieee80211_link_sta *link_sta;
3623 unsigned int link_id;
3625 /* Beacon interval check - firmware will crash if the beacon
3626 * interval is less than 16. We can't avoid connecting at all,
3627 * so refuse the station state change, this will cause mac80211
3628 * to abandon attempts to connect to this AP, and eventually
3629 * wpa_s will blocklist the AP...
3632 for_each_sta_active_link(vif, sta, link_sta, link_id) {
3633 struct ieee80211_bss_conf *link_conf =
3634 link_conf_dereference_protected(vif, link_id);
3639 if (link_conf->beacon_int < IWL_MVM_MIN_BEACON_INTERVAL_TU) {
3641 "Beacon interval %d for AP %pM is too small\n",
3642 link_conf->beacon_int, link_sta->addr);
3646 link_conf->he_support = link_sta->he_cap.has_he;
3652 static void iwl_mvm_vif_set_he_support(struct ieee80211_hw *hw,
3653 struct ieee80211_vif *vif,
3654 struct ieee80211_sta *sta,
3657 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3658 struct ieee80211_link_sta *link_sta;
3659 unsigned int link_id;
3661 for_each_sta_active_link(vif, sta, link_sta, link_id) {
3662 struct ieee80211_bss_conf *link_conf =
3663 link_conf_dereference_protected(vif, link_id);
3665 if (!link_conf || !mvmvif->link[link_id])
3668 link_conf->he_support = link_sta->he_cap.has_he;
3671 mvmvif->link[link_id]->he_ru_2mhz_block = false;
3672 if (link_sta->he_cap.has_he)
3673 iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif,
3681 iwl_mvm_sta_state_notexist_to_none(struct iwl_mvm *mvm,
3682 struct ieee80211_vif *vif,
3683 struct ieee80211_sta *sta,
3684 const struct iwl_mvm_sta_state_ops *callbacks)
3686 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3687 struct ieee80211_link_sta *link_sta;
3691 lockdep_assert_held(&mvm->mutex);
3693 if (vif->type == NL80211_IFTYPE_STATION &&
3694 !iwl_mvm_vif_conf_from_sta(mvm, vif, sta))
3699 iwl_mvm_tdls_sta_count(mvm, NULL) == IWL_MVM_TDLS_STA_COUNT ||
3700 iwl_mvm_phy_ctx_count(mvm) > 1)) {
3701 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
3705 ret = callbacks->add_sta(mvm, vif, sta);
3706 if (sta->tdls && ret == 0) {
3707 iwl_mvm_recalc_tdls_state(mvm, vif, true);
3708 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3709 NL80211_TDLS_SETUP);
3715 for_each_sta_active_link(vif, sta, link_sta, i)
3716 link_sta->agg.max_rc_amsdu_len = 1;
3718 ieee80211_sta_recalc_aggregates(sta);
3720 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
3721 mvmvif->ap_sta = sta;
3724 * Initialize the rates here already - this really tells
3725 * the firmware only what the supported legacy rates are
3726 * (may be) since it's initialized already from what the
3727 * AP advertised in the beacon/probe response. This will
3728 * allow the firmware to send auth/assoc frames with one
3729 * of the supported rates already, rather than having to
3730 * use a mandatory rate.
3731 * If we're the AP, we'll just assume mandatory rates at
3732 * this point, but we know nothing about the STA anyway.
3734 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta);
3740 iwl_mvm_sta_state_auth_to_assoc(struct ieee80211_hw *hw,
3741 struct iwl_mvm *mvm,
3742 struct ieee80211_vif *vif,
3743 struct ieee80211_sta *sta,
3744 const struct iwl_mvm_sta_state_ops *callbacks)
3746 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3747 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3748 struct ieee80211_link_sta *link_sta;
3749 unsigned int link_id;
3751 lockdep_assert_held(&mvm->mutex);
3753 if (vif->type == NL80211_IFTYPE_AP) {
3754 iwl_mvm_vif_set_he_support(hw, vif, sta, false);
3755 mvmvif->ap_assoc_sta_count++;
3756 callbacks->mac_ctxt_changed(mvm, vif, false);
3758 /* since the below is not for MLD API, it's ok to use
3759 * the default bss_conf
3761 if (!mvm->mld_api_is_used &&
3762 (vif->bss_conf.he_support &&
3763 !iwlwifi_mod_params.disable_11ax))
3764 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->deflink.sta_id);
3765 } else if (vif->type == NL80211_IFTYPE_STATION) {
3766 iwl_mvm_vif_set_he_support(hw, vif, sta, true);
3768 callbacks->mac_ctxt_changed(mvm, vif, false);
3770 if (!mvm->mld_api_is_used)
3773 for_each_sta_active_link(vif, sta, link_sta, link_id) {
3774 struct ieee80211_bss_conf *link_conf =
3775 link_conf_dereference_protected(vif, link_id);
3777 if (WARN_ON(!link_conf))
3779 if (!mvmvif->link[link_id])
3782 iwl_mvm_link_changed(mvm, vif, link_conf,
3783 LINK_CONTEXT_MODIFY_ALL &
3784 ~LINK_CONTEXT_MODIFY_ACTIVE,
3790 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta);
3792 return callbacks->update_sta(mvm, vif, sta);
3796 iwl_mvm_sta_state_assoc_to_authorized(struct iwl_mvm *mvm,
3797 struct ieee80211_vif *vif,
3798 struct ieee80211_sta *sta,
3799 const struct iwl_mvm_sta_state_ops *callbacks)
3801 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3802 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3804 lockdep_assert_held(&mvm->mutex);
3806 /* we don't support TDLS during DCM */
3807 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3808 iwl_mvm_teardown_tdls_peers(mvm);
3811 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3812 NL80211_TDLS_ENABLE_LINK);
3814 /* enable beacon filtering */
3815 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif));
3817 mvmvif->authorized = 1;
3819 callbacks->mac_ctxt_changed(mvm, vif, false);
3820 iwl_mvm_mei_host_associated(mvm, vif, mvm_sta);
3822 /* when client is authorized (AP station marked as such),
3823 * try to enable more links
3825 if (vif->type == NL80211_IFTYPE_STATION &&
3826 !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3827 iwl_mvm_mld_select_links(mvm, vif, false);
3830 mvm_sta->authorized = true;
3832 /* MFP is set by default before the station is authorized.
3833 * Clear it here in case it's not used.
3836 int ret = callbacks->update_sta(mvm, vif, sta);
3842 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta);
3848 iwl_mvm_sta_state_authorized_to_assoc(struct iwl_mvm *mvm,
3849 struct ieee80211_vif *vif,
3850 struct ieee80211_sta *sta,
3851 const struct iwl_mvm_sta_state_ops *callbacks)
3853 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3854 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3856 lockdep_assert_held(&mvm->mutex);
3858 mvmsta->authorized = false;
3860 /* once we move into assoc state, need to update rate scale to
3861 * disable using wide bandwidth
3863 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta);
3866 /* Set this but don't call iwl_mvm_mac_ctxt_changed()
3867 * yet to avoid sending high prio again for a little
3870 mvmvif->authorized = 0;
3872 /* disable beacon filtering */
3873 iwl_mvm_disable_beacon_filter(mvm, vif);
3879 /* Common part for MLD and non-MLD modes */
3880 int iwl_mvm_mac_sta_state_common(struct ieee80211_hw *hw,
3881 struct ieee80211_vif *vif,
3882 struct ieee80211_sta *sta,
3883 enum ieee80211_sta_state old_state,
3884 enum ieee80211_sta_state new_state,
3885 const struct iwl_mvm_sta_state_ops *callbacks)
3887 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3888 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3889 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3890 struct ieee80211_link_sta *link_sta;
3891 unsigned int link_id;
3894 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
3895 sta->addr, old_state, new_state);
3898 * If we are in a STA removal flow and in DQA mode:
3900 * This is after the sync_rcu part, so the queues have already been
3901 * flushed. No more TXs on their way in mac80211's path, and no more in
3903 * Also, we won't be getting any new TX frames for this station.
3904 * What we might have are deferred TX frames that need to be taken care
3907 * Drop any still-queued deferred-frame before removing the STA, and
3908 * make sure the worker is no longer handling frames for this STA.
3910 if (old_state == IEEE80211_STA_NONE &&
3911 new_state == IEEE80211_STA_NOTEXIST) {
3912 flush_work(&mvm->add_stream_wk);
3915 * No need to make sure deferred TX indication is off since the
3916 * worker will already remove it if it was on
3920 * Additionally, reset the 40 MHz capability if we disconnected
3923 iwl_mvm_reset_cca_40mhz_workaround(mvm, vif);
3925 /* Also free dup data just in case any assertions below fail */
3926 kfree(mvm_sta->dup_data);
3929 mutex_lock(&mvm->mutex);
3931 /* this would be a mac80211 bug ... but don't crash, unless we had a
3932 * firmware crash while we were activating a link, in which case it is
3933 * legit to have phy_ctxt = NULL. Don't bother not to WARN if we are in
3934 * recovery flow since we spit tons of error messages anyway.
3936 for_each_sta_active_link(vif, sta, link_sta, link_id) {
3937 if (WARN_ON_ONCE(!mvmvif->link[link_id] ||
3938 !mvmvif->link[link_id]->phy_ctxt)) {
3939 mutex_unlock(&mvm->mutex);
3940 return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3941 &mvm->status) ? 0 : -EINVAL;
3945 /* track whether or not the station is associated */
3946 mvm_sta->sta_state = new_state;
3948 if (old_state == IEEE80211_STA_NOTEXIST &&
3949 new_state == IEEE80211_STA_NONE) {
3950 ret = iwl_mvm_sta_state_notexist_to_none(mvm, vif, sta,
3954 } else if (old_state == IEEE80211_STA_NONE &&
3955 new_state == IEEE80211_STA_AUTH) {
3957 * EBS may be disabled due to previous failures reported by FW.
3958 * Reset EBS status here assuming environment has been changed.
3960 mvm->last_ebs_successful = true;
3961 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
3963 } else if (old_state == IEEE80211_STA_AUTH &&
3964 new_state == IEEE80211_STA_ASSOC) {
3965 ret = iwl_mvm_sta_state_auth_to_assoc(hw, mvm, vif, sta,
3967 } else if (old_state == IEEE80211_STA_ASSOC &&
3968 new_state == IEEE80211_STA_AUTHORIZED) {
3969 ret = iwl_mvm_sta_state_assoc_to_authorized(mvm, vif, sta,
3971 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3972 new_state == IEEE80211_STA_ASSOC) {
3973 ret = iwl_mvm_sta_state_authorized_to_assoc(mvm, vif, sta,
3975 } else if (old_state == IEEE80211_STA_ASSOC &&
3976 new_state == IEEE80211_STA_AUTH) {
3977 if (vif->type == NL80211_IFTYPE_AP) {
3978 mvmvif->ap_assoc_sta_count--;
3979 callbacks->mac_ctxt_changed(mvm, vif, false);
3980 } else if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
3981 iwl_mvm_stop_session_protection(mvm, vif);
3983 } else if (old_state == IEEE80211_STA_AUTH &&
3984 new_state == IEEE80211_STA_NONE) {
3986 } else if (old_state == IEEE80211_STA_NONE &&
3987 new_state == IEEE80211_STA_NOTEXIST) {
3988 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) {
3989 iwl_mvm_stop_session_protection(mvm, vif);
3990 mvmvif->ap_sta = NULL;
3992 ret = callbacks->rm_sta(mvm, vif, sta);
3994 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3995 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3996 NL80211_TDLS_DISABLE_LINK);
4000 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
4007 mutex_unlock(&mvm->mutex);
4009 if (sta->tdls && ret == 0) {
4010 if (old_state == IEEE80211_STA_NOTEXIST &&
4011 new_state == IEEE80211_STA_NONE)
4012 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
4013 else if (old_state == IEEE80211_STA_NONE &&
4014 new_state == IEEE80211_STA_NOTEXIST)
4015 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
4021 int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
4023 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4025 mvm->rts_threshold = value;
4030 void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4031 struct ieee80211_sta *sta, u32 changed)
4033 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4035 if (changed & (IEEE80211_RC_BW_CHANGED |
4036 IEEE80211_RC_SUPP_RATES_CHANGED |
4037 IEEE80211_RC_NSS_CHANGED))
4038 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta);
4040 if (vif->type == NL80211_IFTYPE_STATION &&
4041 changed & IEEE80211_RC_NSS_CHANGED)
4042 iwl_mvm_sf_update(mvm, vif, false);
4045 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
4046 struct ieee80211_vif *vif,
4047 unsigned int link_id, u16 ac,
4048 const struct ieee80211_tx_queue_params *params)
4050 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4051 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4053 mvmvif->deflink.queue_params[ac] = *params;
4056 * No need to update right away, we'll get BSS_CHANGED_QOS
4057 * The exception is P2P_DEVICE interface which needs immediate update.
4059 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
4062 mutex_lock(&mvm->mutex);
4063 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4064 mutex_unlock(&mvm->mutex);
4070 void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
4071 struct ieee80211_vif *vif,
4072 struct ieee80211_prep_tx_info *info)
4074 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4076 mutex_lock(&mvm->mutex);
4077 iwl_mvm_protect_assoc(mvm, vif, info->duration, info->link_id);
4078 mutex_unlock(&mvm->mutex);
4081 void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw,
4082 struct ieee80211_vif *vif,
4083 struct ieee80211_prep_tx_info *info)
4085 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4087 /* for successful cases (auth/assoc), don't cancel session protection */
4091 mutex_lock(&mvm->mutex);
4092 iwl_mvm_stop_session_protection(mvm, vif);
4093 mutex_unlock(&mvm->mutex);
4096 int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
4097 struct ieee80211_vif *vif,
4098 struct cfg80211_sched_scan_request *req,
4099 struct ieee80211_scan_ies *ies)
4101 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4105 mutex_lock(&mvm->mutex);
4107 if (!vif->cfg.idle) {
4112 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
4115 mutex_unlock(&mvm->mutex);
4119 int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
4120 struct ieee80211_vif *vif)
4122 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4125 mutex_lock(&mvm->mutex);
4127 /* Due to a race condition, it's possible that mac80211 asks
4128 * us to stop a sched_scan when it's already stopped. This
4129 * can happen, for instance, if we stopped the scan ourselves,
4130 * called ieee80211_sched_scan_stopped() and the userspace called
4131 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
4132 * could run. To handle this, simply return if the scan is
4135 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
4136 mutex_unlock(&mvm->mutex);
4140 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
4141 mutex_unlock(&mvm->mutex);
4142 iwl_mvm_wait_for_async_handlers(mvm);
4147 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
4148 enum set_key_cmd cmd,
4149 struct ieee80211_vif *vif,
4150 struct ieee80211_sta *sta,
4151 struct ieee80211_key_conf *key)
4153 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4154 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4155 struct iwl_mvm_sta *mvmsta = NULL;
4156 struct iwl_mvm_key_pn *ptk_pn = NULL;
4157 int keyidx = key->keyidx;
4158 u32 sec_key_id = WIDE_ID(DATA_PATH_GROUP, SEC_KEY_CMD);
4159 u8 sec_key_ver = iwl_fw_lookup_cmd_ver(mvm->fw, sec_key_id, 0);
4164 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4166 switch (key->cipher) {
4167 case WLAN_CIPHER_SUITE_TKIP:
4168 if (!mvm->trans->trans_cfg->gen2) {
4169 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
4170 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
4171 } else if (vif->type == NL80211_IFTYPE_STATION) {
4172 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
4174 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
4178 case WLAN_CIPHER_SUITE_CCMP:
4179 case WLAN_CIPHER_SUITE_GCMP:
4180 case WLAN_CIPHER_SUITE_GCMP_256:
4181 if (!iwl_mvm_has_new_tx_api(mvm))
4182 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
4184 case WLAN_CIPHER_SUITE_AES_CMAC:
4185 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
4186 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
4187 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
4189 case WLAN_CIPHER_SUITE_WEP40:
4190 case WLAN_CIPHER_SUITE_WEP104:
4191 if (vif->type == NL80211_IFTYPE_STATION)
4193 if (iwl_mvm_has_new_tx_api(mvm))
4195 /* support HW crypto on TX */
4203 if (vif->type == NL80211_IFTYPE_STATION &&
4204 (keyidx == 6 || keyidx == 7))
4205 rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6],
4208 if ((vif->type == NL80211_IFTYPE_ADHOC ||
4209 vif->type == NL80211_IFTYPE_AP) && !sta) {
4211 * GTK on AP interface is a TX-only key, return 0;
4212 * on IBSS they're per-station and because we're lazy
4213 * we don't support them for RX, so do the same.
4214 * CMAC/GMAC in AP/IBSS modes must be done in software
4217 * Except, of course, beacon protection - it must be
4218 * offloaded since we just set a beacon template, and
4219 * then we must also offload the IGTK (not just BIGTK)
4220 * for firmware reasons.
4222 * So just check for beacon protection - if we don't
4223 * have it we cannot get here with keyidx >= 6, and
4224 * if we do have it we need to send the key to FW in
4225 * all cases (CMAC/GMAC).
4227 if (!wiphy_ext_feature_isset(hw->wiphy,
4228 NL80211_EXT_FEATURE_BEACON_PROTECTION) &&
4229 (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
4230 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
4231 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)) {
4236 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
4237 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
4238 !iwl_mvm_has_new_tx_api(mvm)) {
4239 key->hw_key_idx = STA_KEY_IDX_INVALID;
4244 if (!mvmvif->ap_ibss_active) {
4246 i < ARRAY_SIZE(mvmvif->ap_early_keys);
4248 if (!mvmvif->ap_early_keys[i]) {
4249 mvmvif->ap_early_keys[i] = key;
4254 if (i >= ARRAY_SIZE(mvmvif->ap_early_keys))
4263 /* During FW restart, in order to restore the state as it was,
4264 * don't try to reprogram keys we previously failed for.
4266 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
4267 key->hw_key_idx == STA_KEY_IDX_INVALID) {
4268 IWL_DEBUG_MAC80211(mvm,
4269 "skip invalid idx key programming during restart\n");
4274 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
4275 mvmsta && iwl_mvm_has_new_rx_api(mvm) &&
4276 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
4277 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
4278 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
4279 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
4280 struct ieee80211_key_seq seq;
4283 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
4284 ptk_pn = kzalloc(struct_size(ptk_pn, q,
4285 mvm->trans->num_rx_queues),
4292 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
4293 ieee80211_get_key_rx_seq(key, tid, &seq);
4294 for (q = 0; q < mvm->trans->num_rx_queues; q++)
4295 memcpy(ptk_pn->q[q].pn[tid],
4297 IEEE80211_CCMP_PN_LEN);
4300 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
4303 /* in HW restart reuse the index, otherwise request a new one */
4304 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
4305 key_offset = key->hw_key_idx;
4307 key_offset = STA_KEY_IDX_INVALID;
4309 if (mvmsta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4310 mvmsta->pairwise_cipher = key->cipher;
4312 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key (sta:%pM, id:%d)\n",
4313 sta ? sta->addr : NULL, key->keyidx);
4316 ret = iwl_mvm_sec_key_add(mvm, vif, sta, key);
4318 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
4321 IWL_WARN(mvm, "set key failed\n");
4322 key->hw_key_idx = STA_KEY_IDX_INVALID;
4324 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
4328 * can't add key for RX, but we don't need it
4329 * in the device for TX so still return 0,
4330 * unless we have new TX API where we cannot
4331 * put key material into the TX_CMD
4333 if (iwl_mvm_has_new_tx_api(mvm))
4341 if (vif->type == NL80211_IFTYPE_STATION &&
4342 (keyidx == 6 || keyidx == 7))
4343 RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6],
4347 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
4348 if (mvmvif->ap_early_keys[i] == key) {
4349 mvmvif->ap_early_keys[i] = NULL;
4354 /* found in pending list - don't do anything else */
4358 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
4363 if (mvmsta && iwl_mvm_has_new_rx_api(mvm) &&
4364 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
4365 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
4366 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
4367 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
4368 ptk_pn = rcu_dereference_protected(
4369 mvmsta->ptk_pn[keyidx],
4370 lockdep_is_held(&mvm->mutex));
4371 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
4373 kfree_rcu(ptk_pn, rcu_head);
4376 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
4378 ret = iwl_mvm_sec_key_del(mvm, vif, sta, key);
4380 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
4389 int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4390 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4391 struct ieee80211_key_conf *key)
4393 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4396 mutex_lock(&mvm->mutex);
4397 ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key);
4398 mutex_unlock(&mvm->mutex);
4403 void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
4404 struct ieee80211_vif *vif,
4405 struct ieee80211_key_conf *keyconf,
4406 struct ieee80211_sta *sta,
4407 u32 iv32, u16 *phase1key)
4409 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4411 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
4414 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
4418 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
4419 struct iwl_rx_packet *pkt, void *data)
4421 struct iwl_mvm *mvm =
4422 container_of(notif_wait, struct iwl_mvm, notif_wait);
4423 struct iwl_hs20_roc_res *resp;
4424 int resp_len = iwl_rx_packet_payload_len(pkt);
4425 struct iwl_mvm_time_event_data *te_data = data;
4427 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
4430 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
4431 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
4435 resp = (void *)pkt->data;
4438 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
4439 resp->status, resp->event_unique_id);
4441 te_data->uid = le32_to_cpu(resp->event_unique_id);
4442 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
4445 spin_lock_bh(&mvm->time_event_lock);
4446 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
4447 spin_unlock_bh(&mvm->time_event_lock);
4452 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
4453 struct ieee80211_channel *channel,
4454 struct ieee80211_vif *vif,
4458 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4459 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
4460 static const u16 time_event_response[] = { HOT_SPOT_CMD };
4461 struct iwl_notification_wait wait_time_event;
4463 struct iwl_hs20_roc_req aux_roc_req = {
4464 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
4466 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
4467 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
4469 struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm,
4470 &aux_roc_req.channel_info);
4471 u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm);
4473 /* Set the channel info data */
4474 iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value,
4475 iwl_mvm_phy_band_from_nl80211(channel->band),
4476 IWL_PHY_CHANNEL_MODE20,
4479 /* Set the time and duration */
4480 tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm));
4482 iwl_mvm_roc_duration_and_delay(vif, duration, &req_dur, &delay);
4483 tail->duration = cpu_to_le32(req_dur);
4484 tail->apply_time_max_delay = cpu_to_le32(delay);
4487 "ROC: Requesting to remain on channel %u for %ums\n",
4488 channel->hw_value, req_dur);
4490 "\t(requested = %ums, max_delay = %ums)\n",
4493 /* Set the node address */
4494 memcpy(tail->node_addr, vif->addr, ETH_ALEN);
4496 lockdep_assert_held(&mvm->mutex);
4498 spin_lock_bh(&mvm->time_event_lock);
4500 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
4501 spin_unlock_bh(&mvm->time_event_lock);
4506 te_data->duration = duration;
4507 te_data->id = HOT_SPOT_CMD;
4509 spin_unlock_bh(&mvm->time_event_lock);
4512 * Use a notification wait, which really just processes the
4513 * command response and doesn't wait for anything, in order
4514 * to be able to process the response and get the UID inside
4515 * the RX path. Using CMD_WANT_SKB doesn't work because it
4516 * stores the buffer and then wakes up this thread, by which
4517 * time another notification (that the time event started)
4518 * might already be processed unsuccessfully.
4520 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
4521 time_event_response,
4522 ARRAY_SIZE(time_event_response),
4523 iwl_mvm_rx_aux_roc, te_data);
4525 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len,
4529 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
4530 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
4534 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
4535 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
4536 /* should never fail */
4541 spin_lock_bh(&mvm->time_event_lock);
4542 iwl_mvm_te_clear_data(mvm, te_data);
4543 spin_unlock_bh(&mvm->time_event_lock);
4549 static int iwl_mvm_add_aux_sta_for_hs20(struct iwl_mvm *mvm, u32 lmac_id)
4553 lockdep_assert_held(&mvm->mutex);
4555 if (!fw_has_capa(&mvm->fw->ucode_capa,
4556 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
4557 IWL_ERR(mvm, "hotspot not supported\n");
4561 if (iwl_mvm_has_new_station_api(mvm->fw)) {
4562 ret = iwl_mvm_add_aux_sta(mvm, lmac_id);
4563 WARN(ret, "Failed to allocate aux station");
4569 static int iwl_mvm_roc_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
4573 lockdep_assert_held(&mvm->mutex);
4575 ret = iwl_mvm_binding_add_vif(mvm, vif);
4576 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
4579 /* The station and queue allocation must be done only after the binding
4580 * is done, as otherwise the FW might incorrectly configure its state.
4582 return iwl_mvm_add_p2p_bcast_sta(mvm, vif);
4585 static int iwl_mvm_roc(struct ieee80211_hw *hw,
4586 struct ieee80211_vif *vif,
4587 struct ieee80211_channel *channel,
4589 enum ieee80211_roc_type type)
4591 static const struct iwl_mvm_roc_ops ops = {
4592 .add_aux_sta_for_hs20 = iwl_mvm_add_aux_sta_for_hs20,
4593 .link = iwl_mvm_roc_link,
4596 return iwl_mvm_roc_common(hw, vif, channel, duration, type, &ops);
4599 static int iwl_mvm_roc_station(struct iwl_mvm *mvm,
4600 struct ieee80211_channel *channel,
4601 struct ieee80211_vif *vif,
4605 u32 cmd_id = WIDE_ID(MAC_CONF_GROUP, ROC_CMD);
4606 u8 fw_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id,
4607 IWL_FW_CMD_VER_UNKNOWN);
4609 if (fw_ver == IWL_FW_CMD_VER_UNKNOWN) {
4610 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, vif, duration);
4611 } else if (fw_ver == 3) {
4612 ret = iwl_mvm_roc_add_cmd(mvm, channel, vif, duration,
4613 ROC_ACTIVITY_HOTSPOT);
4616 IWL_ERR(mvm, "ROC command version %d mismatch!\n", fw_ver);
4622 static int iwl_mvm_p2p_find_phy_ctxt(struct iwl_mvm *mvm,
4623 struct ieee80211_vif *vif,
4624 struct ieee80211_channel *channel)
4626 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4627 struct cfg80211_chan_def chandef;
4630 lockdep_assert_held(&mvm->mutex);
4632 if (mvmvif->deflink.phy_ctxt &&
4633 channel == mvmvif->deflink.phy_ctxt->channel)
4636 /* Try using a PHY context that is already in use */
4637 for (i = 0; i < NUM_PHY_CTX; i++) {
4638 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[i];
4640 if (!phy_ctxt->ref || mvmvif->deflink.phy_ctxt == phy_ctxt)
4643 if (channel == phy_ctxt->channel) {
4644 if (mvmvif->deflink.phy_ctxt)
4645 iwl_mvm_phy_ctxt_unref(mvm,
4646 mvmvif->deflink.phy_ctxt);
4648 mvmvif->deflink.phy_ctxt = phy_ctxt;
4649 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->deflink.phy_ctxt);
4654 /* We already have a phy_ctxt, but it's not on the right channel */
4655 if (mvmvif->deflink.phy_ctxt)
4656 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt);
4658 mvmvif->deflink.phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
4659 if (!mvmvif->deflink.phy_ctxt)
4662 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
4664 return iwl_mvm_phy_ctxt_add(mvm, mvmvif->deflink.phy_ctxt,
4665 &chandef, NULL, 1, 1);
4668 /* Execute the common part for MLD and non-MLD modes */
4669 int iwl_mvm_roc_common(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4670 struct ieee80211_channel *channel, int duration,
4671 enum ieee80211_roc_type type,
4672 const struct iwl_mvm_roc_ops *ops)
4674 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4678 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
4682 * Flush the done work, just in case it's still pending, so that
4683 * the work it does can complete and we can accept new frames.
4685 flush_work(&mvm->roc_done_wk);
4687 mutex_lock(&mvm->mutex);
4689 switch (vif->type) {
4690 case NL80211_IFTYPE_STATION:
4691 lmac_id = iwl_mvm_get_lmac_id(mvm, channel->band);
4693 /* Use aux roc framework (HS20) */
4694 ret = ops->add_aux_sta_for_hs20(mvm, lmac_id);
4696 ret = iwl_mvm_roc_station(mvm, channel, vif, duration);
4698 case NL80211_IFTYPE_P2P_DEVICE:
4702 IWL_ERR(mvm, "ROC: Invalid vif type=%u\n", vif->type);
4708 ret = iwl_mvm_p2p_find_phy_ctxt(mvm, vif, channel);
4712 ret = ops->link(mvm, vif);
4716 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
4718 mutex_unlock(&mvm->mutex);
4719 IWL_DEBUG_MAC80211(mvm, "leave\n");
4723 int iwl_mvm_cancel_roc(struct ieee80211_hw *hw,
4724 struct ieee80211_vif *vif)
4726 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4728 IWL_DEBUG_MAC80211(mvm, "enter\n");
4730 mutex_lock(&mvm->mutex);
4731 iwl_mvm_stop_roc(mvm, vif);
4732 mutex_unlock(&mvm->mutex);
4734 IWL_DEBUG_MAC80211(mvm, "leave\n");
4738 struct iwl_mvm_ftm_responder_iter_data {
4740 struct ieee80211_chanctx_conf *ctx;
4743 static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac,
4744 struct ieee80211_vif *vif)
4746 struct iwl_mvm_ftm_responder_iter_data *data = _data;
4748 if (rcu_access_pointer(vif->bss_conf.chanctx_conf) == data->ctx &&
4749 vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params)
4750 data->responder = true;
4753 bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm,
4754 struct ieee80211_chanctx_conf *ctx)
4756 struct iwl_mvm_ftm_responder_iter_data data = {
4761 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
4762 IEEE80211_IFACE_ITER_NORMAL,
4763 iwl_mvm_ftm_responder_chanctx_iter,
4765 return data.responder;
4768 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
4769 struct ieee80211_chanctx_conf *ctx)
4771 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4772 struct iwl_mvm_phy_ctxt *phy_ctxt;
4773 struct cfg80211_chan_def *def = iwl_mvm_chanctx_def(mvm, ctx);
4776 lockdep_assert_held(&mvm->mutex);
4778 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
4780 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
4786 ret = iwl_mvm_phy_ctxt_add(mvm, phy_ctxt, def, &ctx->ap,
4787 ctx->rx_chains_static,
4788 ctx->rx_chains_dynamic);
4790 IWL_ERR(mvm, "Failed to add PHY context\n");
4794 *phy_ctxt_id = phy_ctxt->id;
4799 int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
4800 struct ieee80211_chanctx_conf *ctx)
4802 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4805 mutex_lock(&mvm->mutex);
4806 ret = __iwl_mvm_add_chanctx(mvm, ctx);
4807 mutex_unlock(&mvm->mutex);
4812 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
4813 struct ieee80211_chanctx_conf *ctx)
4815 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4816 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4818 lockdep_assert_held(&mvm->mutex);
4820 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
4823 void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
4824 struct ieee80211_chanctx_conf *ctx)
4826 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4828 mutex_lock(&mvm->mutex);
4829 __iwl_mvm_remove_chanctx(mvm, ctx);
4830 mutex_unlock(&mvm->mutex);
4833 void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
4834 struct ieee80211_chanctx_conf *ctx, u32 changed)
4836 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4837 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4838 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4839 struct cfg80211_chan_def *def = iwl_mvm_chanctx_def(mvm, ctx);
4841 if (WARN_ONCE((phy_ctxt->ref > 1) &&
4842 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
4843 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
4844 IEEE80211_CHANCTX_CHANGE_RADAR |
4845 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
4846 "Cannot change PHY. Ref=%d, changed=0x%X\n",
4847 phy_ctxt->ref, changed))
4850 mutex_lock(&mvm->mutex);
4852 /* we are only changing the min_width, may be a noop */
4853 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
4854 if (phy_ctxt->width == def->width)
4857 /* we are just toggling between 20_NOHT and 20 */
4858 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
4859 def->width <= NL80211_CHAN_WIDTH_20)
4863 iwl_mvm_bt_coex_vif_change(mvm);
4864 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def, &ctx->ap,
4865 ctx->rx_chains_static,
4866 ctx->rx_chains_dynamic);
4869 mutex_unlock(&mvm->mutex);
4873 * This function executes the common part for MLD and non-MLD modes.
4875 * Returns true if we're done assigning the chanctx
4876 * (either on failure or success)
4879 __iwl_mvm_assign_vif_chanctx_common(struct iwl_mvm *mvm,
4880 struct ieee80211_vif *vif,
4881 struct ieee80211_chanctx_conf *ctx,
4882 bool switching_chanctx, int *ret)
4884 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4885 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4886 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4888 lockdep_assert_held(&mvm->mutex);
4890 mvmvif->deflink.phy_ctxt = phy_ctxt;
4892 switch (vif->type) {
4893 case NL80211_IFTYPE_AP:
4894 /* only needed if we're switching chanctx (i.e. during CSA) */
4895 if (switching_chanctx) {
4896 mvmvif->ap_ibss_active = true;
4900 case NL80211_IFTYPE_ADHOC:
4902 * The AP binding flow is handled as part of the start_ap flow
4903 * (in bss_info_changed), similarly for IBSS.
4907 case NL80211_IFTYPE_STATION:
4909 case NL80211_IFTYPE_MONITOR:
4910 /* always disable PS when a monitor interface is active */
4911 mvmvif->ps_disabled = true;
4920 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
4921 struct ieee80211_vif *vif,
4922 struct ieee80211_bss_conf *link_conf,
4923 struct ieee80211_chanctx_conf *ctx,
4924 bool switching_chanctx)
4926 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4929 if (WARN_ON(!link_conf))
4932 if (__iwl_mvm_assign_vif_chanctx_common(mvm, vif, ctx,
4933 switching_chanctx, &ret))
4936 ret = iwl_mvm_binding_add_vif(mvm, vif);
4941 * Power state must be updated before quotas,
4942 * otherwise fw will complain.
4944 iwl_mvm_power_update_mac(mvm);
4946 /* Setting the quota at this stage is only required for monitor
4947 * interfaces. For the other types, the bss_info changed flow
4948 * will handle quota settings.
4950 if (vif->type == NL80211_IFTYPE_MONITOR) {
4951 mvmvif->monitor_active = true;
4952 ret = iwl_mvm_update_quotas(mvm, false, NULL);
4954 goto out_remove_binding;
4956 ret = iwl_mvm_add_snif_sta(mvm, vif);
4958 goto out_remove_binding;
4962 /* Handle binding during CSA */
4963 if (vif->type == NL80211_IFTYPE_AP) {
4964 iwl_mvm_update_quotas(mvm, false, NULL);
4965 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4968 if (vif->type == NL80211_IFTYPE_STATION) {
4969 if (!switching_chanctx) {
4970 mvmvif->csa_bcn_pending = false;
4974 mvmvif->csa_bcn_pending = true;
4976 if (!fw_has_capa(&mvm->fw->ucode_capa,
4977 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4978 u32 duration = 5 * vif->bss_conf.beacon_int;
4980 /* Protect the session to make sure we hear the first
4981 * beacon on the new channel.
4983 iwl_mvm_protect_session(mvm, vif, duration, duration,
4984 vif->bss_conf.beacon_int / 2,
4988 iwl_mvm_update_quotas(mvm, false, NULL);
4994 iwl_mvm_binding_remove_vif(mvm, vif);
4995 iwl_mvm_power_update_mac(mvm);
4998 mvmvif->deflink.phy_ctxt = NULL;
5002 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
5003 struct ieee80211_vif *vif,
5004 struct ieee80211_bss_conf *link_conf,
5005 struct ieee80211_chanctx_conf *ctx)
5007 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5010 mutex_lock(&mvm->mutex);
5011 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, link_conf, ctx, false);
5012 mutex_unlock(&mvm->mutex);
5018 * This function executes the common part for MLD and non-MLD modes.
5020 * Returns if chanctx unassign chanctx is done
5021 * (either on failure or success)
5023 static bool __iwl_mvm_unassign_vif_chanctx_common(struct iwl_mvm *mvm,
5024 struct ieee80211_vif *vif,
5025 bool switching_chanctx)
5027 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5029 lockdep_assert_held(&mvm->mutex);
5030 iwl_mvm_remove_time_event(mvm, mvmvif,
5031 &mvmvif->time_event_data);
5033 switch (vif->type) {
5034 case NL80211_IFTYPE_ADHOC:
5036 case NL80211_IFTYPE_MONITOR:
5037 mvmvif->monitor_active = false;
5038 mvmvif->ps_disabled = false;
5040 case NL80211_IFTYPE_AP:
5041 /* This part is triggered only during CSA */
5042 if (!switching_chanctx || !mvmvif->ap_ibss_active)
5045 mvmvif->csa_countdown = false;
5047 /* Set CS bit on all the stations */
5048 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
5050 /* Save blocked iface, the timeout is set on the next beacon */
5051 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
5053 mvmvif->ap_ibss_active = false;
5061 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
5062 struct ieee80211_vif *vif,
5063 struct ieee80211_bss_conf *link_conf,
5064 struct ieee80211_chanctx_conf *ctx,
5065 bool switching_chanctx)
5067 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5068 struct ieee80211_vif *disabled_vif = NULL;
5070 if (__iwl_mvm_unassign_vif_chanctx_common(mvm, vif, switching_chanctx))
5073 if (vif->type == NL80211_IFTYPE_MONITOR)
5074 iwl_mvm_rm_snif_sta(mvm, vif);
5077 if (vif->type == NL80211_IFTYPE_STATION && switching_chanctx) {
5079 if (!fw_has_capa(&mvm->fw->ucode_capa,
5080 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
5081 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
5084 iwl_mvm_update_quotas(mvm, false, disabled_vif);
5085 iwl_mvm_binding_remove_vif(mvm, vif);
5088 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD) &&
5091 mvmvif->deflink.phy_ctxt = NULL;
5092 iwl_mvm_power_update_mac(mvm);
5095 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
5096 struct ieee80211_vif *vif,
5097 struct ieee80211_bss_conf *link_conf,
5098 struct ieee80211_chanctx_conf *ctx)
5100 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5102 mutex_lock(&mvm->mutex);
5103 __iwl_mvm_unassign_vif_chanctx(mvm, vif, link_conf, ctx, false);
5104 mutex_unlock(&mvm->mutex);
5108 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
5109 struct ieee80211_vif_chanctx_switch *vifs,
5110 const struct iwl_mvm_switch_vif_chanctx_ops *ops)
5114 mutex_lock(&mvm->mutex);
5115 ops->__unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
5116 vifs[0].old_ctx, true);
5117 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
5119 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
5121 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
5125 ret = ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
5126 vifs[0].new_ctx, true);
5129 "failed to assign new_ctx during channel switch\n");
5133 /* we don't support TDLS during DCM - can be caused by channel switch */
5134 if (iwl_mvm_phy_ctx_count(mvm) > 1)
5135 iwl_mvm_teardown_tdls_peers(mvm);
5140 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
5143 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
5144 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
5148 if (ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
5149 vifs[0].old_ctx, true)) {
5150 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
5157 /* things keep failing, better restart the hw */
5158 iwl_mvm_nic_restart(mvm, false);
5161 mutex_unlock(&mvm->mutex);
5167 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
5168 struct ieee80211_vif_chanctx_switch *vifs,
5169 const struct iwl_mvm_switch_vif_chanctx_ops *ops)
5173 mutex_lock(&mvm->mutex);
5174 ops->__unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
5175 vifs[0].old_ctx, true);
5177 ret = ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
5178 vifs[0].new_ctx, true);
5181 "failed to assign new_ctx during channel switch\n");
5188 if (ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
5189 vifs[0].old_ctx, true)) {
5190 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
5197 /* things keep failing, better restart the hw */
5198 iwl_mvm_nic_restart(mvm, false);
5201 mutex_unlock(&mvm->mutex);
5206 /* Execute the common part for both MLD and non-MLD modes */
5208 iwl_mvm_switch_vif_chanctx_common(struct ieee80211_hw *hw,
5209 struct ieee80211_vif_chanctx_switch *vifs,
5211 enum ieee80211_chanctx_switch_mode mode,
5212 const struct iwl_mvm_switch_vif_chanctx_ops *ops)
5214 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5217 /* we only support a single-vif right now */
5222 case CHANCTX_SWMODE_SWAP_CONTEXTS:
5223 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs, ops);
5225 case CHANCTX_SWMODE_REASSIGN_VIF:
5226 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs, ops);
5236 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
5237 struct ieee80211_vif_chanctx_switch *vifs,
5239 enum ieee80211_chanctx_switch_mode mode)
5241 static const struct iwl_mvm_switch_vif_chanctx_ops ops = {
5242 .__assign_vif_chanctx = __iwl_mvm_assign_vif_chanctx,
5243 .__unassign_vif_chanctx = __iwl_mvm_unassign_vif_chanctx,
5246 return iwl_mvm_switch_vif_chanctx_common(hw, vifs, n_vifs, mode, &ops);
5249 int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
5251 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5253 return mvm->ibss_manager;
5256 static int iwl_mvm_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
5259 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5260 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
5262 if (!mvm_sta || !mvm_sta->vif) {
5263 IWL_ERR(mvm, "Station is not associated to a vif\n");
5267 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif,
5268 &mvm_sta->vif->bss_conf);
5271 #ifdef CONFIG_NL80211_TESTMODE
5272 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
5273 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
5274 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
5275 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
5278 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
5279 struct ieee80211_vif *vif,
5280 void *data, int len)
5282 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
5286 err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len,
5287 iwl_mvm_tm_policy, NULL);
5291 if (!tb[IWL_MVM_TM_ATTR_CMD])
5294 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
5295 case IWL_MVM_TM_CMD_SET_NOA:
5296 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
5297 !vif->bss_conf.enable_beacon ||
5298 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
5301 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
5302 if (noa_duration >= vif->bss_conf.beacon_int)
5305 mvm->noa_duration = noa_duration;
5308 return iwl_mvm_update_quotas(mvm, true, NULL);
5309 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
5310 /* must be associated client vif - ignore authorized */
5311 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
5312 !vif->cfg.assoc || !vif->bss_conf.dtim_period ||
5313 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
5316 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
5317 return iwl_mvm_enable_beacon_filter(mvm, vif);
5318 return iwl_mvm_disable_beacon_filter(mvm, vif);
5324 int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
5325 struct ieee80211_vif *vif,
5326 void *data, int len)
5328 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5331 mutex_lock(&mvm->mutex);
5332 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
5333 mutex_unlock(&mvm->mutex);
5339 void iwl_mvm_channel_switch(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5340 struct ieee80211_channel_switch *chsw)
5342 /* By implementing this operation, we prevent mac80211 from
5343 * starting its own channel switch timer, so that we can call
5344 * ieee80211_chswitch_done() ourselves at the right time
5345 * (which is when the absence time event starts).
5348 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
5349 "dummy channel switch op\n");
5352 static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm,
5353 struct ieee80211_vif *vif,
5354 struct ieee80211_channel_switch *chsw)
5356 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5357 struct iwl_chan_switch_te_cmd cmd = {
5358 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
5360 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
5361 .tsf = cpu_to_le32(chsw->timestamp),
5362 .cs_count = chsw->count,
5363 .cs_mode = chsw->block_tx,
5366 lockdep_assert_held(&mvm->mutex);
5369 cmd.cs_delayed_bcn_count =
5370 DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int);
5372 return iwl_mvm_send_cmd_pdu(mvm,
5373 WIDE_ID(MAC_CONF_GROUP,
5374 CHANNEL_SWITCH_TIME_EVENT_CMD),
5375 0, sizeof(cmd), &cmd);
5378 static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm,
5379 struct ieee80211_vif *vif,
5380 struct ieee80211_channel_switch *chsw)
5382 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5385 /* Schedule the time event to a bit before beacon 1,
5386 * to make sure we're in the new channel when the
5387 * GO/AP arrives. In case count <= 1 immediately schedule the
5388 * TE (this might result with some packet loss or connection
5391 if (chsw->count <= 1)
5394 apply_time = chsw->device_timestamp +
5395 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
5396 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
5399 iwl_mvm_csa_client_absent(mvm, vif);
5401 if (mvmvif->bf_data.bf_enabled) {
5402 int ret = iwl_mvm_disable_beacon_filter(mvm, vif);
5408 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
5414 #define IWL_MAX_CSA_BLOCK_TX 1500
5415 int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
5416 struct ieee80211_vif *vif,
5417 struct ieee80211_channel_switch *chsw)
5419 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5420 struct ieee80211_vif *csa_vif;
5421 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5424 mutex_lock(&mvm->mutex);
5426 mvmvif->csa_failed = false;
5428 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
5429 chsw->chandef.center_freq1);
5431 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
5432 ieee80211_vif_to_wdev(vif),
5433 FW_DBG_TRIGGER_CHANNEL_SWITCH);
5435 switch (vif->type) {
5436 case NL80211_IFTYPE_AP:
5438 rcu_dereference_protected(mvm->csa_vif,
5439 lockdep_is_held(&mvm->mutex));
5440 if (WARN_ONCE(csa_vif && csa_vif->bss_conf.csa_active,
5441 "Another CSA is already in progress")) {
5446 /* we still didn't unblock tx. prevent new CS meanwhile */
5447 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
5448 lockdep_is_held(&mvm->mutex))) {
5453 rcu_assign_pointer(mvm->csa_vif, vif);
5455 if (WARN_ONCE(mvmvif->csa_countdown,
5456 "Previous CSA countdown didn't complete")) {
5461 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
5464 case NL80211_IFTYPE_STATION:
5466 * In the new flow FW is in charge of timing the switch so there
5467 * is no need for all of this
5469 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
5470 CHANNEL_SWITCH_ERROR_NOTIF,
5475 * We haven't configured the firmware to be associated yet since
5476 * we don't know the dtim period. In this case, the firmware can't
5477 * track the beacons.
5479 if (!vif->cfg.assoc || !vif->bss_conf.dtim_period) {
5484 if (chsw->delay > IWL_MAX_CSA_BLOCK_TX &&
5485 hweight16(vif->valid_links) <= 1)
5486 schedule_delayed_work(&mvmvif->csa_work, 0);
5488 if (chsw->block_tx) {
5490 * In case of undetermined / long time with immediate
5491 * quiet monitor status to gracefully disconnect
5494 chsw->count * vif->bss_conf.beacon_int >
5495 IWL_MAX_CSA_BLOCK_TX)
5496 schedule_delayed_work(&mvmvif->csa_work,
5497 msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX));
5500 if (!fw_has_capa(&mvm->fw->ucode_capa,
5501 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
5502 ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw);
5506 iwl_mvm_schedule_client_csa(mvm, vif, chsw);
5509 mvmvif->csa_count = chsw->count;
5510 mvmvif->csa_misbehave = false;
5516 mvmvif->ps_disabled = true;
5518 ret = iwl_mvm_power_update_ps(mvm);
5522 /* we won't be on this channel any longer */
5523 iwl_mvm_teardown_tdls_peers(mvm);
5526 mutex_unlock(&mvm->mutex);
5531 void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw,
5532 struct ieee80211_vif *vif,
5533 struct ieee80211_channel_switch *chsw)
5535 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5536 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5537 struct iwl_chan_switch_te_cmd cmd = {
5538 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
5540 .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY),
5541 .tsf = cpu_to_le32(chsw->timestamp),
5542 .cs_count = chsw->count,
5543 .cs_mode = chsw->block_tx,
5547 * In the new flow FW is in charge of timing the switch so there is no
5548 * need for all of this
5550 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
5551 CHANNEL_SWITCH_ERROR_NOTIF, 0))
5554 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY))
5557 IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d (old %d) mode = %d\n",
5558 mvmvif->id, chsw->count, mvmvif->csa_count, chsw->block_tx);
5560 if (chsw->count >= mvmvif->csa_count && chsw->block_tx) {
5561 if (mvmvif->csa_misbehave) {
5562 struct ieee80211_bss_conf *link_conf;
5564 /* Second time, give up on this AP*/
5566 link_conf = wiphy_dereference(hw->wiphy,
5567 vif->link_conf[chsw->link_id]);
5568 if (WARN_ON(!link_conf))
5571 iwl_mvm_abort_channel_switch(hw, vif, link_conf);
5572 ieee80211_chswitch_done(vif, false, 0);
5573 mvmvif->csa_misbehave = false;
5576 mvmvif->csa_misbehave = true;
5578 mvmvif->csa_count = chsw->count;
5580 mutex_lock(&mvm->mutex);
5581 if (mvmvif->csa_failed)
5584 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
5585 WIDE_ID(MAC_CONF_GROUP,
5586 CHANNEL_SWITCH_TIME_EVENT_CMD),
5587 0, sizeof(cmd), &cmd));
5589 mutex_unlock(&mvm->mutex);
5592 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
5596 if (!iwl_mvm_has_new_tx_api(mvm)) {
5598 mutex_lock(&mvm->mutex);
5599 iwl_mvm_flush_tx_path(mvm,
5600 iwl_mvm_flushable_queues(mvm) & queues);
5601 mutex_unlock(&mvm->mutex);
5603 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
5608 mutex_lock(&mvm->mutex);
5609 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
5610 struct ieee80211_sta *sta;
5612 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
5613 lockdep_is_held(&mvm->mutex));
5614 if (IS_ERR_OR_NULL(sta))
5618 iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF);
5620 iwl_mvm_wait_sta_queues_empty(mvm,
5621 iwl_mvm_sta_from_mac80211(sta));
5623 mutex_unlock(&mvm->mutex);
5626 void iwl_mvm_mac_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5627 u32 queues, bool drop)
5629 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5630 struct iwl_mvm_vif *mvmvif;
5631 struct iwl_mvm_sta *mvmsta;
5632 struct ieee80211_sta *sta;
5633 bool ap_sta_done = false;
5638 iwl_mvm_flush_no_vif(mvm, queues, drop);
5642 /* Make sure we're done with the deferred traffic before flushing */
5643 flush_work(&mvm->add_stream_wk);
5645 mutex_lock(&mvm->mutex);
5646 mvmvif = iwl_mvm_vif_from_mac80211(vif);
5648 /* flush the AP-station and all TDLS peers */
5649 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
5650 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
5651 lockdep_is_held(&mvm->mutex));
5652 if (IS_ERR_OR_NULL(sta))
5655 mvmsta = iwl_mvm_sta_from_mac80211(sta);
5656 if (mvmsta->vif != vif)
5659 if (sta == mvmvif->ap_sta) {
5666 if (iwl_mvm_flush_sta(mvm, mvmsta->deflink.sta_id,
5667 mvmsta->tfd_queue_msk))
5668 IWL_ERR(mvm, "flush request fail\n");
5670 if (iwl_mvm_has_new_tx_api(mvm))
5671 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
5672 else /* only used for !iwl_mvm_has_new_tx_api() below */
5673 msk |= mvmsta->tfd_queue_msk;
5677 mutex_unlock(&mvm->mutex);
5679 /* this can take a while, and we may need/want other operations
5680 * to succeed while doing this, so do it without the mutex held
5682 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
5683 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
5686 void iwl_mvm_mac_flush_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5687 struct ieee80211_sta *sta)
5689 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
5690 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5691 struct iwl_mvm_link_sta *mvm_link_sta;
5692 struct ieee80211_link_sta *link_sta;
5695 mutex_lock(&mvm->mutex);
5696 for_each_sta_active_link(vif, sta, link_sta, link_id) {
5697 mvm_link_sta = rcu_dereference_protected(mvmsta->link[link_id],
5698 lockdep_is_held(&mvm->mutex));
5702 if (iwl_mvm_flush_sta(mvm, mvm_link_sta->sta_id,
5703 mvmsta->tfd_queue_msk))
5704 IWL_ERR(mvm, "flush request fail\n");
5706 mutex_unlock(&mvm->mutex);
5709 int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
5710 struct survey_info *survey)
5712 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5714 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw,
5715 WIDE_ID(SYSTEM_GROUP,
5716 SYSTEM_STATISTICS_CMD),
5717 IWL_FW_CMD_VER_UNKNOWN);
5719 memset(survey, 0, sizeof(*survey));
5721 /* only support global statistics right now */
5725 if (!fw_has_capa(&mvm->fw->ucode_capa,
5726 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
5729 mutex_lock(&mvm->mutex);
5731 if (iwl_mvm_firmware_running(mvm)) {
5732 ret = iwl_mvm_request_statistics(mvm, false);
5737 survey->filled = SURVEY_INFO_TIME_RX |
5738 SURVEY_INFO_TIME_TX;
5740 survey->time_rx = mvm->accu_radio_stats.rx_time +
5741 mvm->radio_stats.rx_time;
5742 do_div(survey->time_rx, USEC_PER_MSEC);
5744 survey->time_tx = mvm->accu_radio_stats.tx_time +
5745 mvm->radio_stats.tx_time;
5746 do_div(survey->time_tx, USEC_PER_MSEC);
5748 /* the new fw api doesn't support the following fields */
5749 if (cmd_ver != IWL_FW_CMD_VER_UNKNOWN)
5752 survey->filled |= SURVEY_INFO_TIME |
5753 SURVEY_INFO_TIME_SCAN;
5754 survey->time = mvm->accu_radio_stats.on_time_rf +
5755 mvm->radio_stats.on_time_rf;
5756 do_div(survey->time, USEC_PER_MSEC);
5758 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
5759 mvm->radio_stats.on_time_scan;
5760 do_div(survey->time_scan, USEC_PER_MSEC);
5763 mutex_unlock(&mvm->mutex);
5767 static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo)
5769 u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
5772 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
5773 case RATE_MCS_CHAN_WIDTH_20:
5774 rinfo->bw = RATE_INFO_BW_20;
5776 case RATE_MCS_CHAN_WIDTH_40:
5777 rinfo->bw = RATE_INFO_BW_40;
5779 case RATE_MCS_CHAN_WIDTH_80:
5780 rinfo->bw = RATE_INFO_BW_80;
5782 case RATE_MCS_CHAN_WIDTH_160:
5783 rinfo->bw = RATE_INFO_BW_160;
5785 case RATE_MCS_CHAN_WIDTH_320:
5786 rinfo->bw = RATE_INFO_BW_320;
5790 if (format == RATE_MCS_CCK_MSK ||
5791 format == RATE_MCS_LEGACY_OFDM_MSK) {
5792 int rate = u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK);
5794 /* add the offset needed to get to the legacy ofdm indices */
5795 if (format == RATE_MCS_LEGACY_OFDM_MSK)
5796 rate += IWL_FIRST_OFDM_RATE;
5799 case IWL_RATE_1M_INDEX:
5802 case IWL_RATE_2M_INDEX:
5805 case IWL_RATE_5M_INDEX:
5808 case IWL_RATE_11M_INDEX:
5809 rinfo->legacy = 110;
5811 case IWL_RATE_6M_INDEX:
5814 case IWL_RATE_9M_INDEX:
5817 case IWL_RATE_12M_INDEX:
5818 rinfo->legacy = 120;
5820 case IWL_RATE_18M_INDEX:
5821 rinfo->legacy = 180;
5823 case IWL_RATE_24M_INDEX:
5824 rinfo->legacy = 240;
5826 case IWL_RATE_36M_INDEX:
5827 rinfo->legacy = 360;
5829 case IWL_RATE_48M_INDEX:
5830 rinfo->legacy = 480;
5832 case IWL_RATE_54M_INDEX:
5833 rinfo->legacy = 540;
5838 rinfo->nss = u32_get_bits(rate_n_flags,
5839 RATE_MCS_NSS_MSK) + 1;
5840 rinfo->mcs = format == RATE_MCS_HT_MSK ?
5841 RATE_HT_MCS_INDEX(rate_n_flags) :
5842 u32_get_bits(rate_n_flags, RATE_MCS_CODE_MSK);
5844 if (rate_n_flags & RATE_MCS_SGI_MSK)
5845 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
5848 case RATE_MCS_EHT_MSK:
5849 /* TODO: GI/LTF/RU. How does the firmware encode them? */
5850 rinfo->flags |= RATE_INFO_FLAGS_EHT_MCS;
5852 case RATE_MCS_HE_MSK:
5853 gi_ltf = u32_get_bits(rate_n_flags, RATE_MCS_HE_GI_LTF_MSK);
5855 rinfo->flags |= RATE_INFO_FLAGS_HE_MCS;
5857 if (rate_n_flags & RATE_MCS_HE_106T_MSK) {
5858 rinfo->bw = RATE_INFO_BW_HE_RU;
5859 rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106;
5862 switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) {
5863 case RATE_MCS_HE_TYPE_SU:
5864 case RATE_MCS_HE_TYPE_EXT_SU:
5865 if (gi_ltf == 0 || gi_ltf == 1)
5866 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
5867 else if (gi_ltf == 2)
5868 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
5869 else if (gi_ltf == 3)
5870 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
5872 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
5874 case RATE_MCS_HE_TYPE_MU:
5875 if (gi_ltf == 0 || gi_ltf == 1)
5876 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
5877 else if (gi_ltf == 2)
5878 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
5880 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
5882 case RATE_MCS_HE_TYPE_TRIG:
5883 if (gi_ltf == 0 || gi_ltf == 1)
5884 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
5886 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
5890 if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK)
5893 case RATE_MCS_HT_MSK:
5894 rinfo->flags |= RATE_INFO_FLAGS_MCS;
5896 case RATE_MCS_VHT_MSK:
5897 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
5902 void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
5903 struct ieee80211_vif *vif,
5904 struct ieee80211_sta *sta,
5905 struct station_info *sinfo)
5907 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5908 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5909 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
5912 if (mvmsta->deflink.avg_energy) {
5913 sinfo->signal_avg = -(s8)mvmsta->deflink.avg_energy;
5914 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
5917 if (iwl_mvm_has_tlc_offload(mvm)) {
5918 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->deflink.lq_sta.rs_fw;
5920 iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate);
5921 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
5924 /* if beacon filtering isn't on mac80211 does it anyway */
5925 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
5928 if (!vif->cfg.assoc)
5931 mutex_lock(&mvm->mutex);
5933 if (mvmvif->deflink.ap_sta_id != mvmsta->deflink.sta_id)
5936 if (iwl_mvm_request_statistics(mvm, false))
5939 sinfo->rx_beacon = 0;
5940 for_each_mvm_vif_valid_link(mvmvif, i)
5941 sinfo->rx_beacon += mvmvif->link[i]->beacon_stats.num_beacons +
5942 mvmvif->link[i]->beacon_stats.accu_num_beacons;
5944 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
5945 if (mvmvif->deflink.beacon_stats.avg_signal) {
5946 /* firmware only reports a value after RXing a few beacons */
5947 sinfo->rx_beacon_signal_avg =
5948 mvmvif->deflink.beacon_stats.avg_signal;
5949 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
5952 mutex_unlock(&mvm->mutex);
5955 static void iwl_mvm_event_mlme_callback_ini(struct iwl_mvm *mvm,
5956 struct ieee80211_vif *vif,
5957 const struct ieee80211_mlme_event *mlme)
5959 if ((mlme->data == ASSOC_EVENT || mlme->data == AUTH_EVENT) &&
5960 (mlme->status == MLME_DENIED || mlme->status == MLME_TIMEOUT)) {
5961 iwl_dbg_tlv_time_point(&mvm->fwrt,
5962 IWL_FW_INI_TIME_POINT_ASSOC_FAILED,
5967 if (mlme->data == DEAUTH_RX_EVENT || mlme->data == DEAUTH_TX_EVENT) {
5968 iwl_dbg_tlv_time_point(&mvm->fwrt,
5969 IWL_FW_INI_TIME_POINT_DEASSOC,
5975 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
5976 struct ieee80211_vif *vif,
5977 const struct ieee80211_event *event)
5979 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
5981 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
5983 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
5986 struct iwl_fw_dbg_trigger_tlv *trig;
5987 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
5989 if (iwl_trans_dbg_ini_valid(mvm->trans)) {
5990 iwl_mvm_event_mlme_callback_ini(mvm, vif, &event->u.mlme);
5994 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5995 FW_DBG_TRIGGER_MLME);
5999 trig_mlme = (void *)trig->data;
6001 if (event->u.mlme.data == ASSOC_EVENT) {
6002 if (event->u.mlme.status == MLME_DENIED)
6003 CHECK_MLME_TRIGGER(stop_assoc_denied,
6004 "DENIED ASSOC: reason %d",
6005 event->u.mlme.reason);
6006 else if (event->u.mlme.status == MLME_TIMEOUT)
6007 CHECK_MLME_TRIGGER(stop_assoc_timeout,
6009 } else if (event->u.mlme.data == AUTH_EVENT) {
6010 if (event->u.mlme.status == MLME_DENIED)
6011 CHECK_MLME_TRIGGER(stop_auth_denied,
6012 "DENIED AUTH: reason %d",
6013 event->u.mlme.reason);
6014 else if (event->u.mlme.status == MLME_TIMEOUT)
6015 CHECK_MLME_TRIGGER(stop_auth_timeout,
6017 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
6018 CHECK_MLME_TRIGGER(stop_rx_deauth,
6019 "DEAUTH RX %d", event->u.mlme.reason);
6020 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
6021 CHECK_MLME_TRIGGER(stop_tx_deauth,
6022 "DEAUTH TX %d", event->u.mlme.reason);
6024 #undef CHECK_MLME_TRIGGER
6027 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
6028 struct ieee80211_vif *vif,
6029 const struct ieee80211_event *event)
6031 struct iwl_fw_dbg_trigger_tlv *trig;
6032 struct iwl_fw_dbg_trigger_ba *ba_trig;
6034 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
6039 ba_trig = (void *)trig->data;
6041 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
6044 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
6045 "BAR received from %pM, tid %d, ssn %d",
6046 event->u.ba.sta->addr, event->u.ba.tid,
6050 void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
6051 struct ieee80211_vif *vif,
6052 const struct ieee80211_event *event)
6054 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
6056 switch (event->type) {
6058 iwl_mvm_event_mlme_callback(mvm, vif, event);
6061 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
6063 case BA_FRAME_TIMEOUT:
6064 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
6072 #define SYNC_RX_QUEUE_TIMEOUT (HZ)
6073 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
6074 enum iwl_mvm_rxq_notif_type type,
6076 const void *data, u32 size)
6079 struct iwl_rxq_sync_cmd cmd;
6080 struct iwl_mvm_internal_rxq_notif notif;
6082 .cmd.rxq_mask = cpu_to_le32(BIT(mvm->trans->num_rx_queues) - 1),
6084 cpu_to_le32(sizeof(struct iwl_mvm_internal_rxq_notif) +
6089 struct iwl_host_cmd hcmd = {
6090 .id = WIDE_ID(DATA_PATH_GROUP, TRIGGER_RX_QUEUES_NOTIF_CMD),
6092 .len[0] = sizeof(cmd),
6095 .flags = sync ? 0 : CMD_ASYNC,
6099 /* size must be a multiple of DWORD */
6100 if (WARN_ON(cmd.cmd.count & cpu_to_le32(3)))
6103 if (!iwl_mvm_has_new_rx_api(mvm))
6107 cmd.notif.cookie = mvm->queue_sync_cookie;
6108 mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1;
6111 ret = iwl_mvm_send_cmd(mvm, &hcmd);
6113 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
6118 lockdep_assert_held(&mvm->mutex);
6119 ret = wait_event_timeout(mvm->rx_sync_waitq,
6120 READ_ONCE(mvm->queue_sync_state) == 0 ||
6121 iwl_mvm_is_radio_hw_killed(mvm),
6122 SYNC_RX_QUEUE_TIMEOUT);
6123 WARN_ONCE(!ret && !iwl_mvm_is_radio_hw_killed(mvm),
6124 "queue sync: failed to sync, state is 0x%lx, cookie %d\n",
6125 mvm->queue_sync_state,
6126 mvm->queue_sync_cookie);
6131 mvm->queue_sync_state = 0;
6132 mvm->queue_sync_cookie++;
6136 void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
6138 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
6140 mutex_lock(&mvm->mutex);
6141 iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_EMPTY, true, NULL, 0);
6142 mutex_unlock(&mvm->mutex);
6146 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw,
6147 struct ieee80211_vif *vif,
6148 struct cfg80211_ftm_responder_stats *stats)
6150 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
6151 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
6153 if (vif->p2p || vif->type != NL80211_IFTYPE_AP ||
6154 !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder)
6157 mutex_lock(&mvm->mutex);
6158 *stats = mvm->ftm_resp_stats;
6159 mutex_unlock(&mvm->mutex);
6161 stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) |
6162 BIT(NL80211_FTM_STATS_PARTIAL_NUM) |
6163 BIT(NL80211_FTM_STATS_FAILED_NUM) |
6164 BIT(NL80211_FTM_STATS_ASAP_NUM) |
6165 BIT(NL80211_FTM_STATS_NON_ASAP_NUM) |
6166 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) |
6167 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) |
6168 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) |
6169 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM);
6174 int iwl_mvm_start_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6175 struct cfg80211_pmsr_request *request)
6177 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
6180 mutex_lock(&mvm->mutex);
6181 ret = iwl_mvm_ftm_start(mvm, vif, request);
6182 mutex_unlock(&mvm->mutex);
6187 void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6188 struct cfg80211_pmsr_request *request)
6190 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
6192 mutex_lock(&mvm->mutex);
6193 iwl_mvm_ftm_abort(mvm, request);
6194 mutex_unlock(&mvm->mutex);
6197 static bool iwl_mvm_can_hw_csum(struct sk_buff *skb)
6199 u8 protocol = ip_hdr(skb)->protocol;
6201 if (!IS_ENABLED(CONFIG_INET))
6204 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
6207 static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw,
6208 struct sk_buff *head,
6209 struct sk_buff *skb)
6211 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
6213 /* For now don't aggregate IPv6 in AMSDU */
6214 if (skb->protocol != htons(ETH_P_IP))
6217 if (!iwl_mvm_is_csum_supported(mvm))
6220 return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head);
6223 int iwl_mvm_set_hw_timestamp(struct ieee80211_hw *hw,
6224 struct ieee80211_vif *vif,
6225 struct cfg80211_set_hw_timestamp *hwts)
6227 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
6231 /* HW timestamping is only supported for a specific station */
6237 IWL_TIME_SYNC_PROTOCOL_TM | IWL_TIME_SYNC_PROTOCOL_FTM;
6239 mutex_lock(&mvm->mutex);
6240 ret = iwl_mvm_time_sync_config(mvm, hwts->macaddr, protocols);
6241 mutex_unlock(&mvm->mutex);
6246 const struct ieee80211_ops iwl_mvm_hw_ops = {
6247 .tx = iwl_mvm_mac_tx,
6248 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue,
6249 .ampdu_action = iwl_mvm_mac_ampdu_action,
6250 .get_antenna = iwl_mvm_op_get_antenna,
6251 .set_antenna = iwl_mvm_op_set_antenna,
6252 .start = iwl_mvm_mac_start,
6253 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
6254 .stop = iwl_mvm_mac_stop,
6255 .add_interface = iwl_mvm_mac_add_interface,
6256 .remove_interface = iwl_mvm_mac_remove_interface,
6257 .config = iwl_mvm_mac_config,
6258 .prepare_multicast = iwl_mvm_prepare_multicast,
6259 .configure_filter = iwl_mvm_configure_filter,
6260 .config_iface_filter = iwl_mvm_config_iface_filter,
6261 .bss_info_changed = iwl_mvm_bss_info_changed,
6262 .hw_scan = iwl_mvm_mac_hw_scan,
6263 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
6264 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
6265 .sta_state = iwl_mvm_mac_sta_state,
6266 .sta_notify = iwl_mvm_mac_sta_notify,
6267 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
6268 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
6269 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
6270 .sta_rc_update = iwl_mvm_sta_rc_update,
6271 .conf_tx = iwl_mvm_mac_conf_tx,
6272 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
6273 .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx,
6274 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
6275 .flush = iwl_mvm_mac_flush,
6276 .flush_sta = iwl_mvm_mac_flush_sta,
6277 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
6278 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
6279 .set_key = iwl_mvm_mac_set_key,
6280 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
6281 .remain_on_channel = iwl_mvm_roc,
6282 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
6283 .add_chanctx = iwl_mvm_add_chanctx,
6284 .remove_chanctx = iwl_mvm_remove_chanctx,
6285 .change_chanctx = iwl_mvm_change_chanctx,
6286 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
6287 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
6288 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
6290 .start_ap = iwl_mvm_start_ap,
6291 .stop_ap = iwl_mvm_stop_ap,
6292 .join_ibss = iwl_mvm_start_ibss,
6293 .leave_ibss = iwl_mvm_stop_ibss,
6295 .tx_last_beacon = iwl_mvm_tx_last_beacon,
6297 .set_tim = iwl_mvm_set_tim,
6299 .channel_switch = iwl_mvm_channel_switch,
6300 .pre_channel_switch = iwl_mvm_pre_channel_switch,
6301 .post_channel_switch = iwl_mvm_post_channel_switch,
6302 .abort_channel_switch = iwl_mvm_abort_channel_switch,
6303 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon,
6305 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
6306 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
6307 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
6309 .event_callback = iwl_mvm_mac_event_callback,
6311 .sync_rx_queues = iwl_mvm_sync_rx_queues,
6313 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
6315 #ifdef CONFIG_PM_SLEEP
6317 .suspend = iwl_mvm_suspend,
6318 .resume = iwl_mvm_resume,
6319 .set_wakeup = iwl_mvm_set_wakeup,
6320 .set_rekey_data = iwl_mvm_set_rekey_data,
6321 #if IS_ENABLED(CONFIG_IPV6)
6322 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
6324 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
6326 .get_survey = iwl_mvm_mac_get_survey,
6327 .sta_statistics = iwl_mvm_mac_sta_statistics,
6328 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats,
6329 .start_pmsr = iwl_mvm_start_pmsr,
6330 .abort_pmsr = iwl_mvm_abort_pmsr,
6332 .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate,
6333 #ifdef CONFIG_IWLWIFI_DEBUGFS
6334 .vif_add_debugfs = iwl_mvm_vif_add_debugfs,
6335 .link_sta_add_debugfs = iwl_mvm_link_sta_add_debugfs,
6337 .set_hw_timestamp = iwl_mvm_set_hw_timestamp,