1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2012-2014, 2018-2023 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 /* Store the return source id */
143 src_id = resp->source_id;
144 if (IS_ERR_OR_NULL(regd)) {
145 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
146 PTR_ERR_OR_ZERO(regd));
150 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
151 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
152 mvm->lar_regdom_set = true;
153 mvm->mcc_src = src_id;
155 iwl_mei_set_country_code(__le16_to_cpu(resp->mcc));
162 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
165 struct ieee80211_regdomain *regd;
167 if (!iwl_mvm_is_lar_supported(mvm))
170 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
171 if (!IS_ERR_OR_NULL(regd)) {
172 /* only update the regulatory core if changed */
174 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
180 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
183 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
184 iwl_mvm_is_wifi_mcc_supported(mvm) ?
185 MCC_SOURCE_GET_CURRENT :
186 MCC_SOURCE_OLD_FW, changed);
189 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
191 enum iwl_mcc_source used_src;
192 struct ieee80211_regdomain *regd;
195 const struct ieee80211_regdomain *r =
196 wiphy_dereference(mvm->hw->wiphy, mvm->hw->wiphy->regd);
201 /* save the last source in case we overwrite it below */
202 used_src = mvm->mcc_src;
203 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
204 /* Notify the firmware we support wifi location updates */
205 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
206 if (!IS_ERR_OR_NULL(regd))
210 /* Now set our last stored MCC and source */
211 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
213 if (IS_ERR_OR_NULL(regd))
216 /* update cfg80211 if the regdomain was changed */
218 ret = regulatory_set_wiphy_regd_sync(mvm->hw->wiphy, regd);
226 /* Each capability added here should also be add to tm_if_types_ext_capa_sta */
227 static const u8 he_if_types_ext_capa_sta[] = {
228 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
229 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
230 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF |
231 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB,
232 [8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB,
235 static const u8 tm_if_types_ext_capa_sta[] = {
236 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
237 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT |
238 WLAN_EXT_CAPA3_TIMING_MEASUREMENT_SUPPORT,
239 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF |
240 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB,
241 [8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB,
242 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
245 /* Additional interface types for which extended capabilities are
246 * specified separately
249 #define IWL_MVM_EMLSR_CAPA (IEEE80211_EML_CAP_EMLSR_SUPP | \
250 IEEE80211_EML_CAP_EMLSR_PADDING_DELAY_32US << \
251 __bf_shf(IEEE80211_EML_CAP_EMLSR_PADDING_DELAY) | \
252 IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY_64US << \
253 __bf_shf(IEEE80211_EML_CAP_EMLSR_TRANSITION_DELAY))
255 static const struct wiphy_iftype_ext_capab add_iftypes_ext_capa[] = {
257 .iftype = NL80211_IFTYPE_STATION,
258 .extended_capabilities = he_if_types_ext_capa_sta,
259 .extended_capabilities_mask = he_if_types_ext_capa_sta,
260 .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta),
261 /* relevant only if EHT is supported */
262 .eml_capabilities = IWL_MVM_EMLSR_CAPA,
265 .iftype = NL80211_IFTYPE_STATION,
266 .extended_capabilities = tm_if_types_ext_capa_sta,
267 .extended_capabilities_mask = tm_if_types_ext_capa_sta,
268 .extended_capabilities_len = sizeof(tm_if_types_ext_capa_sta),
269 /* relevant only if EHT is supported */
270 .eml_capabilities = IWL_MVM_EMLSR_CAPA,
274 int iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
276 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
277 *tx_ant = iwl_mvm_get_valid_tx_ant(mvm);
278 *rx_ant = iwl_mvm_get_valid_rx_ant(mvm);
282 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
284 struct ieee80211_hw *hw = mvm->hw;
286 static const u32 mvm_ciphers[] = {
287 WLAN_CIPHER_SUITE_WEP40,
288 WLAN_CIPHER_SUITE_WEP104,
289 WLAN_CIPHER_SUITE_TKIP,
290 WLAN_CIPHER_SUITE_CCMP,
292 #ifdef CONFIG_PM_SLEEP
293 bool unified = fw_has_capa(&mvm->fw->ucode_capa,
294 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
296 u32 sec_key_id = WIDE_ID(DATA_PATH_GROUP, SEC_KEY_CMD);
297 u8 sec_key_ver = iwl_fw_lookup_cmd_ver(mvm->fw, sec_key_id, 0);
299 /* Tell mac80211 our characteristics */
300 ieee80211_hw_set(hw, SIGNAL_DBM);
301 ieee80211_hw_set(hw, SPECTRUM_MGMT);
302 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
303 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
304 ieee80211_hw_set(hw, SUPPORTS_PS);
305 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
306 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
307 ieee80211_hw_set(hw, CONNECTION_MONITOR);
308 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
309 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
310 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
311 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
312 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
313 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
314 ieee80211_hw_set(hw, BUFF_MMPDU_TXQ);
315 ieee80211_hw_set(hw, STA_MMPDU_TXQ);
317 /* Set this early since we need to have it for the check below */
318 if (mvm->mld_api_is_used &&
319 mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_BZ)
320 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO;
322 /* With MLD FW API, it tracks timing by itself,
323 * no need for any timing from the host
325 if (!mvm->mld_api_is_used)
326 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
328 /* We should probably have this, but mac80211
329 * currently doesn't support it for MLO.
331 if (!(hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO))
332 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
335 * On older devices, enabling TX A-MSDU occasionally leads to
336 * something getting messed up, the command read from the FIFO
337 * gets out of sync and isn't a TX command, so that we have an
340 * It's not clear where the bug is, but since we didn't used to
341 * support A-MSDU until moving the mac80211 iTXQs, just leave it
342 * for older devices. We also don't see this issue on any newer
345 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000)
346 ieee80211_hw_set(hw, TX_AMSDU);
347 ieee80211_hw_set(hw, TX_FRAG_LIST);
349 if (iwl_mvm_has_tlc_offload(mvm)) {
350 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
351 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
354 if (iwl_mvm_has_new_rx_api(mvm))
355 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
357 if (fw_has_capa(&mvm->fw->ucode_capa,
358 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
359 ieee80211_hw_set(hw, AP_LINK_PS);
360 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
362 * we absolutely need this for the new TX API since that comes
363 * with many more queues than the current code can deal with
364 * for station powersave
369 if (mvm->trans->num_rx_queues > 1)
370 ieee80211_hw_set(hw, USES_RSS);
372 if (mvm->trans->max_skb_frags)
373 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
375 hw->queues = IEEE80211_NUM_ACS;
376 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
377 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
378 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
379 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
380 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
382 hw->radiotap_timestamp.units_pos =
383 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
384 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
385 /* this is the case for CCK frames, it's better (only 8) for OFDM */
386 hw->radiotap_timestamp.accuracy = 22;
388 if (!iwl_mvm_has_tlc_offload(mvm))
389 hw->rate_control_algorithm = RS_NAME;
391 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
392 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
393 hw->max_tx_fragments = mvm->trans->max_skb_frags;
395 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
396 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
397 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
398 hw->wiphy->cipher_suites = mvm->ciphers;
400 if (iwl_mvm_has_new_rx_api(mvm)) {
401 mvm->ciphers[hw->wiphy->n_cipher_suites] =
402 WLAN_CIPHER_SUITE_GCMP;
403 hw->wiphy->n_cipher_suites++;
404 mvm->ciphers[hw->wiphy->n_cipher_suites] =
405 WLAN_CIPHER_SUITE_GCMP_256;
406 hw->wiphy->n_cipher_suites++;
409 if (iwlwifi_mod_params.swcrypto)
411 "iwlmvm doesn't allow to disable HW crypto, check swcrypto module parameter\n");
412 if (!iwlwifi_mod_params.bt_coex_active)
414 "iwlmvm doesn't allow to disable BT Coex, check bt_coex_active module parameter\n");
416 ieee80211_hw_set(hw, MFP_CAPABLE);
417 mvm->ciphers[hw->wiphy->n_cipher_suites] = WLAN_CIPHER_SUITE_AES_CMAC;
418 hw->wiphy->n_cipher_suites++;
419 if (iwl_mvm_has_new_rx_api(mvm)) {
420 mvm->ciphers[hw->wiphy->n_cipher_suites] =
421 WLAN_CIPHER_SUITE_BIP_GMAC_128;
422 hw->wiphy->n_cipher_suites++;
423 mvm->ciphers[hw->wiphy->n_cipher_suites] =
424 WLAN_CIPHER_SUITE_BIP_GMAC_256;
425 hw->wiphy->n_cipher_suites++;
428 wiphy_ext_feature_set(hw->wiphy,
429 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY);
430 wiphy_ext_feature_set(hw->wiphy,
431 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT);
433 if (fw_has_capa(&mvm->fw->ucode_capa,
434 IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) {
435 wiphy_ext_feature_set(hw->wiphy,
436 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
437 hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa;
441 fw_has_capa(&mvm->fw->ucode_capa,
442 IWL_UCODE_TLV_CAPA_BIGTK_TX_SUPPORT))
443 wiphy_ext_feature_set(hw->wiphy,
444 NL80211_EXT_FEATURE_BEACON_PROTECTION);
445 else if (fw_has_capa(&mvm->fw->ucode_capa,
446 IWL_UCODE_TLV_CAPA_BIGTK_SUPPORT))
447 wiphy_ext_feature_set(hw->wiphy,
448 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT);
450 if (fw_has_capa(&mvm->fw->ucode_capa,
451 IWL_UCODE_TLV_CAPA_TIME_SYNC_BOTH_FTM_TM))
452 hw->wiphy->hw_timestamp_max_peers = 1;
454 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
455 hw->wiphy->features |=
456 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
457 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
458 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
460 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
461 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
462 hw->chanctx_data_size = sizeof(u16);
463 hw->txq_data_size = sizeof(struct iwl_mvm_txq);
465 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
466 BIT(NL80211_IFTYPE_P2P_CLIENT) |
467 BIT(NL80211_IFTYPE_AP) |
468 BIT(NL80211_IFTYPE_P2P_GO) |
469 BIT(NL80211_IFTYPE_P2P_DEVICE) |
470 BIT(NL80211_IFTYPE_ADHOC);
472 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
473 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
475 /* The new Tx API does not allow to pass the key or keyid of a MPDU to
476 * the hw, preventing us to control which key(id) to use per MPDU.
477 * Till that's fixed we can't use Extended Key ID for the newer cards.
479 if (!iwl_mvm_has_new_tx_api(mvm))
480 wiphy_ext_feature_set(hw->wiphy,
481 NL80211_EXT_FEATURE_EXT_KEY_ID);
482 hw->wiphy->features |= NL80211_FEATURE_HT_IBSS;
484 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
485 if (iwl_mvm_is_lar_supported(mvm))
486 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
488 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
489 REGULATORY_DISABLE_BEACON_HINTS;
491 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
492 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
493 hw->wiphy->flags |= WIPHY_FLAG_SPLIT_SCAN_6GHZ;
495 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
496 hw->wiphy->n_iface_combinations =
497 ARRAY_SIZE(iwl_mvm_iface_combinations);
499 hw->wiphy->max_remain_on_channel_duration = 10000;
500 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
502 /* Extract MAC address */
503 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
504 hw->wiphy->addresses = mvm->addresses;
505 hw->wiphy->n_addresses = 1;
507 /* Extract additional MAC addresses if available */
508 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
509 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
511 for (i = 1; i < num_mac; i++) {
512 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
514 mvm->addresses[i].addr[5]++;
515 hw->wiphy->n_addresses++;
518 iwl_mvm_reset_phy_ctxts(mvm);
520 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
522 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
524 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
525 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
526 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
528 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
529 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
531 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
533 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
534 hw->wiphy->bands[NL80211_BAND_2GHZ] =
535 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
536 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
537 hw->wiphy->bands[NL80211_BAND_5GHZ] =
538 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
540 if (fw_has_capa(&mvm->fw->ucode_capa,
541 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
542 fw_has_api(&mvm->fw->ucode_capa,
543 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
544 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
545 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
547 if (fw_has_capa(&mvm->fw->ucode_capa,
548 IWL_UCODE_TLV_CAPA_PSC_CHAN_SUPPORT) &&
549 mvm->nvm_data->bands[NL80211_BAND_6GHZ].n_channels)
550 hw->wiphy->bands[NL80211_BAND_6GHZ] =
551 &mvm->nvm_data->bands[NL80211_BAND_6GHZ];
553 hw->wiphy->hw_version = mvm->trans->hw_id;
555 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
556 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
558 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
560 hw->wiphy->max_sched_scan_reqs = 1;
561 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
562 hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw);
563 /* we create the 802.11 header and zero length SSID IE. */
564 hw->wiphy->max_sched_scan_ie_len =
565 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
566 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
567 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
570 * the firmware uses u8 for num of iterations, but 0xff is saved for
571 * infinite loop, so the maximum number of iterations is actually 254.
573 hw->wiphy->max_sched_scan_plan_iterations = 254;
575 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
576 NL80211_FEATURE_LOW_PRIORITY_SCAN |
577 NL80211_FEATURE_P2P_GO_OPPPS |
578 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
579 NL80211_FEATURE_DYNAMIC_SMPS |
580 NL80211_FEATURE_STATIC_SMPS |
581 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
583 if (fw_has_capa(&mvm->fw->ucode_capa,
584 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
585 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
586 if (fw_has_capa(&mvm->fw->ucode_capa,
587 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
588 hw->wiphy->features |= NL80211_FEATURE_QUIET;
590 if (fw_has_capa(&mvm->fw->ucode_capa,
591 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
592 hw->wiphy->features |=
593 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
595 if (fw_has_capa(&mvm->fw->ucode_capa,
596 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
597 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
599 if (iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_KEK_KCK_MATERIAL,
600 IWL_FW_CMD_VER_UNKNOWN) == 3)
601 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK;
603 if (fw_has_api(&mvm->fw->ucode_capa,
604 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
605 wiphy_ext_feature_set(hw->wiphy,
606 NL80211_EXT_FEATURE_SCAN_START_TIME);
607 wiphy_ext_feature_set(hw->wiphy,
608 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
611 if (iwl_mvm_is_oce_supported(mvm)) {
612 u8 scan_ver = iwl_fw_lookup_cmd_ver(mvm->fw, SCAN_REQ_UMAC, 0);
614 wiphy_ext_feature_set(hw->wiphy,
615 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
616 wiphy_ext_feature_set(hw->wiphy,
617 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
618 wiphy_ext_feature_set(hw->wiphy,
619 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
621 /* Old firmware also supports probe deferral and suppression */
623 wiphy_ext_feature_set(hw->wiphy,
624 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
627 hw->wiphy->iftype_ext_capab = NULL;
628 hw->wiphy->num_iftype_ext_capab = 0;
630 if (mvm->nvm_data->sku_cap_11ax_enable &&
631 !iwlwifi_mod_params.disable_11ax) {
632 hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa;
633 hw->wiphy->num_iftype_ext_capab =
634 ARRAY_SIZE(add_iftypes_ext_capa) - 1;
636 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
637 ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID);
640 if (iwl_fw_lookup_cmd_ver(mvm->fw,
641 WIDE_ID(DATA_PATH_GROUP,
642 WNM_80211V_TIMING_MEASUREMENT_CONFIG_CMD),
643 IWL_FW_CMD_VER_UNKNOWN) >= 1) {
644 IWL_DEBUG_INFO(mvm->trans, "Timing measurement supported\n");
646 if (!hw->wiphy->iftype_ext_capab) {
647 hw->wiphy->num_iftype_ext_capab = 1;
648 hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa +
649 ARRAY_SIZE(add_iftypes_ext_capa) - 1;
651 hw->wiphy->iftype_ext_capab = add_iftypes_ext_capa + 1;
655 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
657 #ifdef CONFIG_PM_SLEEP
658 if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) &&
659 mvm->trans->ops->d3_suspend &&
660 mvm->trans->ops->d3_resume &&
661 device_can_wakeup(mvm->trans->dev)) {
662 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
663 WIPHY_WOWLAN_DISCONNECT |
664 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
665 WIPHY_WOWLAN_RFKILL_RELEASE |
666 WIPHY_WOWLAN_NET_DETECT;
667 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
668 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
669 WIPHY_WOWLAN_4WAY_HANDSHAKE;
671 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
672 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
673 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
674 mvm->wowlan.max_nd_match_sets =
675 iwl_umac_scan_get_max_profiles(mvm->fw);
676 hw->wiphy->wowlan = &mvm->wowlan;
680 ret = iwl_mvm_leds_init(mvm);
684 if (fw_has_capa(&mvm->fw->ucode_capa,
685 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
686 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
687 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
688 ieee80211_hw_set(hw, TDLS_WIDER_BW);
691 if (fw_has_capa(&mvm->fw->ucode_capa,
692 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
693 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
694 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
697 hw->netdev_features |= mvm->cfg->features;
698 if (!iwl_mvm_is_csum_supported(mvm))
699 hw->netdev_features &= ~IWL_CSUM_NETIF_FLAGS_MASK;
701 if (mvm->cfg->vht_mu_mimo_supported)
702 wiphy_ext_feature_set(hw->wiphy,
703 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
705 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT))
706 wiphy_ext_feature_set(hw->wiphy,
707 NL80211_EXT_FEATURE_PROTECTED_TWT);
709 iwl_mvm_vendor_cmds_register(mvm);
711 hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm);
712 hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm);
714 ret = ieee80211_register_hw(mvm->hw);
716 iwl_mvm_leds_exit(mvm);
722 static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
723 struct ieee80211_sta *sta)
726 if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0))
729 if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0))
733 ieee80211_free_txskb(mvm->hw, skb);
736 void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
737 struct ieee80211_tx_control *control, struct sk_buff *skb)
739 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
740 struct ieee80211_sta *sta = control->sta;
741 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
742 struct ieee80211_hdr *hdr = (void *)skb->data;
743 bool offchannel = IEEE80211_SKB_CB(skb)->flags &
744 IEEE80211_TX_CTL_TX_OFFCHAN;
745 u32 link_id = u32_get_bits(info->control.flags,
746 IEEE80211_TX_CTRL_MLO_LINK);
747 struct ieee80211_sta *tmp_sta = sta;
749 if (iwl_mvm_is_radio_killed(mvm)) {
750 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
755 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
756 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
760 * bufferable MMPDUs or MMPDUs on STA interfaces come via TXQs
761 * so we treat the others as broadcast
763 if (ieee80211_is_mgmt(hdr->frame_control))
766 /* If there is no sta, and it's not offchannel - send through AP */
767 if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION &&
769 struct iwl_mvm_vif *mvmvif =
770 iwl_mvm_vif_from_mac80211(info->control.vif);
771 u8 ap_sta_id = READ_ONCE(mvmvif->deflink.ap_sta_id);
773 if (ap_sta_id < mvm->fw->ucode_capa.num_stations) {
774 /* mac80211 holds rcu read lock */
775 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
776 if (IS_ERR_OR_NULL(sta))
781 if (tmp_sta && !sta && link_id != IEEE80211_LINK_UNSPECIFIED &&
782 !ieee80211_is_probe_resp(hdr->frame_control)) {
783 /* translate MLD addresses to LINK addresses */
784 struct ieee80211_link_sta *link_sta =
785 rcu_dereference(tmp_sta->link[link_id]);
786 struct ieee80211_bss_conf *link_conf =
787 rcu_dereference(info->control.vif->link_conf[link_id]);
788 struct ieee80211_mgmt *mgmt;
790 if (WARN_ON(!link_sta || !link_conf))
793 /* if sta is NULL, the frame is a management frame */
795 memcpy(mgmt->da, link_sta->addr, ETH_ALEN);
796 memcpy(mgmt->sa, link_conf->addr, ETH_ALEN);
797 memcpy(mgmt->bssid, link_conf->bssid, ETH_ALEN);
800 iwl_mvm_tx_skb(mvm, skb, sta);
803 ieee80211_free_txskb(hw, skb);
806 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
808 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
809 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
810 struct sk_buff *skb = NULL;
813 * No need for threads to be pending here, they can leave the first
814 * taker all the work.
816 * mvmtxq->tx_request logic:
818 * If 0, no one is currently TXing, set to 1 to indicate current thread
819 * will now start TX and other threads should quit.
821 * If 1, another thread is currently TXing, set to 2 to indicate to
822 * that thread that there was another request. Since that request may
823 * have raced with the check whether the queue is empty, the TXing
824 * thread should check the queue's status one more time before leaving.
825 * This check is done in order to not leave any TX hanging in the queue
826 * until the next TX invocation (which may not even happen).
828 * If 2, another thread is currently TXing, and it will already double
829 * check the queue, so do nothing.
831 if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2))
836 while (likely(!test_bit(IWL_MVM_TXQ_STATE_STOP_FULL,
838 !test_bit(IWL_MVM_TXQ_STATE_STOP_REDIRECT,
840 !test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status))) {
841 skb = ieee80211_tx_dequeue(hw, txq);
846 "TXQ of sta %pM tid %d is now empty\n",
852 iwl_mvm_tx_skb(mvm, skb, txq->sta);
854 } while (atomic_dec_return(&mvmtxq->tx_request));
858 void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw,
859 struct ieee80211_txq *txq)
861 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
862 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
864 if (likely(test_bit(IWL_MVM_TXQ_STATE_READY, &mvmtxq->state)) ||
866 iwl_mvm_mac_itxq_xmit(hw, txq);
870 /* iwl_mvm_mac_itxq_xmit() will later be called by the worker
871 * to handle any packets we leave on the txq now
874 spin_lock_bh(&mvm->add_stream_lock);
875 /* The list is being deleted only after the queue is fully allocated. */
876 if (list_empty(&mvmtxq->list) &&
877 /* recheck under lock */
878 !test_bit(IWL_MVM_TXQ_STATE_READY, &mvmtxq->state)) {
879 list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs);
880 schedule_work(&mvm->add_stream_wk);
882 spin_unlock_bh(&mvm->add_stream_lock);
885 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
887 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
889 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
893 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
894 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
895 enum ieee80211_ampdu_mlme_action action)
897 struct iwl_fw_dbg_trigger_tlv *trig;
898 struct iwl_fw_dbg_trigger_ba *ba_trig;
900 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
905 ba_trig = (void *)trig->data;
908 case IEEE80211_AMPDU_TX_OPERATIONAL: {
909 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
910 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
912 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
913 "TX AGG START: MAC %pM tid %d ssn %d\n",
914 sta->addr, tid, tid_data->ssn);
917 case IEEE80211_AMPDU_TX_STOP_CONT:
918 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
919 "TX AGG STOP: MAC %pM tid %d\n",
922 case IEEE80211_AMPDU_RX_START:
923 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
924 "RX AGG START: MAC %pM tid %d ssn %d\n",
925 sta->addr, tid, rx_ba_ssn);
927 case IEEE80211_AMPDU_RX_STOP:
928 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
929 "RX AGG STOP: MAC %pM tid %d\n",
937 int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
938 struct ieee80211_vif *vif,
939 struct ieee80211_ampdu_params *params)
941 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
943 struct ieee80211_sta *sta = params->sta;
944 enum ieee80211_ampdu_mlme_action action = params->action;
945 u16 tid = params->tid;
946 u16 *ssn = ¶ms->ssn;
947 u16 buf_size = params->buf_size;
948 bool amsdu = params->amsdu;
949 u16 timeout = params->timeout;
951 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
952 sta->addr, tid, action);
954 if (!(mvm->nvm_data->sku_cap_11n_enable))
957 mutex_lock(&mvm->mutex);
960 case IEEE80211_AMPDU_RX_START:
961 if (iwl_mvm_vif_from_mac80211(vif)->deflink.ap_sta_id ==
962 iwl_mvm_sta_from_mac80211(sta)->deflink.sta_id) {
963 struct iwl_mvm_vif *mvmvif;
964 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
965 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
967 mdata->opened_rx_ba_sessions = true;
968 mvmvif = iwl_mvm_vif_from_mac80211(vif);
969 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
971 if (!iwl_enable_rx_ampdu()) {
975 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
978 case IEEE80211_AMPDU_RX_STOP:
979 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
982 case IEEE80211_AMPDU_TX_START:
983 if (!iwl_enable_tx_ampdu()) {
987 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
989 case IEEE80211_AMPDU_TX_STOP_CONT:
990 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
992 case IEEE80211_AMPDU_TX_STOP_FLUSH:
993 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
994 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
996 case IEEE80211_AMPDU_TX_OPERATIONAL:
997 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1009 if (action == IEEE80211_AMPDU_RX_START)
1012 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1015 mutex_unlock(&mvm->mutex);
1020 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1021 struct ieee80211_vif *vif)
1023 struct iwl_mvm *mvm = data;
1024 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1025 struct iwl_probe_resp_data *probe_data;
1026 unsigned int link_id;
1028 mvmvif->uploaded = false;
1030 spin_lock_bh(&mvm->time_event_lock);
1031 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1032 spin_unlock_bh(&mvm->time_event_lock);
1034 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1036 for_each_mvm_vif_valid_link(mvmvif, link_id) {
1037 mvmvif->link[link_id]->ap_sta_id = IWL_MVM_INVALID_STA;
1038 mvmvif->link[link_id]->fw_link_id = IWL_MVM_FW_LINK_ID_INVALID;
1039 mvmvif->link[link_id]->phy_ctxt = NULL;
1040 mvmvif->link[link_id]->active = 0;
1041 mvmvif->link[link_id]->igtk = NULL;
1044 probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data,
1045 lockdep_is_held(&mvm->mutex));
1047 kfree_rcu(probe_data, rcu_head);
1048 RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL);
1051 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1053 iwl_mvm_stop_device(mvm);
1057 mvm->scan_status = 0;
1058 mvm->ps_disabled = false;
1059 mvm->rfkill_safe_init_done = false;
1061 /* just in case one was running */
1062 iwl_mvm_cleanup_roc_te(mvm);
1063 ieee80211_remain_on_channel_expired(mvm->hw);
1065 iwl_mvm_ftm_restart(mvm);
1068 * cleanup all interfaces, even inactive ones, as some might have
1069 * gone down during the HW restart
1071 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1073 mvm->p2p_device_vif = NULL;
1075 iwl_mvm_reset_phy_ctxts(mvm);
1076 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1077 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1078 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1080 ieee80211_wake_queues(mvm->hw);
1082 mvm->rx_ba_sessions = 0;
1083 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1084 mvm->monitor_on = false;
1085 #ifdef CONFIG_IWLWIFI_DEBUGFS
1086 mvm->beacon_inject_active = false;
1089 /* keep statistics ticking */
1090 iwl_mvm_accu_radio_stats(mvm);
1093 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1097 lockdep_assert_held(&mvm->mutex);
1099 ret = iwl_mvm_mei_get_ownership(mvm);
1103 if (mvm->mei_nvm_data) {
1104 /* We got the NIC, we can now free the MEI NVM data */
1105 kfree(mvm->mei_nvm_data);
1106 mvm->mei_nvm_data = NULL;
1109 * We can't free the nvm_data we allocated based on the SAP
1110 * data because we registered to cfg80211 with the channels
1111 * allocated on mvm->nvm_data. Keep a pointer in temp_nvm_data
1112 * just in order to be able free it later.
1113 * NULLify nvm_data so that we will read the NVM from the
1114 * firmware this time.
1116 mvm->temp_nvm_data = mvm->nvm_data;
1117 mvm->nvm_data = NULL;
1120 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1122 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1123 * so later code will - from now on - see that we're doing it.
1125 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1126 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1127 /* Clean up some internal and mac80211 state on restart */
1128 iwl_mvm_restart_cleanup(mvm);
1130 ret = iwl_mvm_up(mvm);
1132 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT,
1134 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC,
1137 mvm->last_reset_or_resume_time_jiffies = jiffies;
1139 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1140 /* Something went wrong - we need to finish some cleanup
1141 * that normally iwl_mvm_mac_restart_complete() below
1144 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1150 int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1152 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1154 int retry, max_retry = 0;
1156 mutex_lock(&mvm->mutex);
1158 /* we are starting the mac not in error flow, and restart is enabled */
1159 if (!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) &&
1160 iwlwifi_mod_params.fw_restart) {
1161 max_retry = IWL_MAX_INIT_RETRY;
1163 * This will prevent mac80211 recovery flows to trigger during
1166 set_bit(IWL_MVM_STATUS_STARTING, &mvm->status);
1169 for (retry = 0; retry <= max_retry; retry++) {
1170 ret = __iwl_mvm_mac_start(mvm);
1175 * In PLDR sync PCI re-enumeration is needed. no point to retry
1176 * mac start before that.
1178 if (mvm->pldr_sync) {
1179 iwl_mei_alive_notif(false);
1180 iwl_trans_pcie_remove(mvm->trans, true);
1184 IWL_ERR(mvm, "mac start retry %d\n", retry);
1186 clear_bit(IWL_MVM_STATUS_STARTING, &mvm->status);
1188 mutex_unlock(&mvm->mutex);
1190 iwl_mvm_mei_set_sw_rfkill_state(mvm);
1195 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1199 mutex_lock(&mvm->mutex);
1201 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1203 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1205 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1208 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY);
1211 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1212 * of packets the FW sent out, so we must reconnect.
1214 iwl_mvm_teardown_tdls_peers(mvm);
1216 mutex_unlock(&mvm->mutex);
1219 void iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1220 enum ieee80211_reconfig_type reconfig_type)
1222 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1224 switch (reconfig_type) {
1225 case IEEE80211_RECONFIG_TYPE_RESTART:
1226 iwl_mvm_restart_complete(mvm);
1228 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1233 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1235 lockdep_assert_held(&mvm->mutex);
1237 iwl_mvm_ftm_initiator_smooth_stop(mvm);
1239 /* firmware counters are obviously reset now, but we shouldn't
1240 * partially track so also clear the fw_reset_accu counters.
1242 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1244 /* async_handlers_wk is now blocked */
1246 if (!iwl_mvm_has_new_station_api(mvm->fw))
1247 iwl_mvm_rm_aux_sta(mvm);
1249 iwl_mvm_stop_device(mvm);
1251 iwl_mvm_async_handlers_purge(mvm);
1252 /* async_handlers_list is empty and will stay empty: HW is stopped */
1255 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1256 * hw (as restart_complete() won't be called in this case) and mac80211
1257 * won't execute the restart.
1258 * But make sure to cleanup interfaces that have gone down before/during
1259 * HW restart was requested.
1261 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1262 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1264 ieee80211_iterate_interfaces(mvm->hw, 0,
1265 iwl_mvm_cleanup_iterator, mvm);
1267 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1268 * make sure there's nothing left there and warn if any is found.
1270 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1273 for (i = 0; i < mvm->max_scans; i++) {
1274 if (WARN_ONCE(mvm->scan_uid_status[i],
1275 "UMAC scan UID %d status was not cleaned\n",
1277 mvm->scan_uid_status[i] = 0;
1282 void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1284 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1286 flush_work(&mvm->async_handlers_wk);
1287 flush_work(&mvm->add_stream_wk);
1290 * Lock and clear the firmware running bit here already, so that
1291 * new commands coming in elsewhere, e.g. from debugfs, will not
1292 * be able to proceed. This is important here because one of those
1293 * debugfs files causes the firmware dump to be triggered, and if we
1294 * don't stop debugfs accesses before canceling that it could be
1295 * retriggered after we flush it but before we've cleared the bit.
1297 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1299 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1300 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1303 * The work item could be running or queued if the
1304 * ROC time event stops just as we get here.
1306 flush_work(&mvm->roc_done_wk);
1308 iwl_mvm_mei_set_sw_rfkill_state(mvm);
1310 mutex_lock(&mvm->mutex);
1311 __iwl_mvm_mac_stop(mvm);
1312 mutex_unlock(&mvm->mutex);
1315 * The worker might have been waiting for the mutex, let it run and
1316 * discover that its list is now empty.
1318 cancel_work_sync(&mvm->async_handlers_wk);
1321 struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1325 lockdep_assert_held(&mvm->mutex);
1327 for (i = 0; i < NUM_PHY_CTX; i++)
1328 if (!mvm->phy_ctxts[i].ref)
1329 return &mvm->phy_ctxts[i];
1331 IWL_ERR(mvm, "No available PHY context\n");
1335 int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1338 u32 cmd_id = REDUCE_TX_POWER_CMD;
1340 struct iwl_dev_tx_power_cmd cmd = {
1341 .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1342 .common.mac_context_id =
1343 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1344 .common.pwr_restriction = cpu_to_le16(8 * tx_power),
1346 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id,
1347 IWL_FW_CMD_VER_UNKNOWN);
1349 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1350 cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1353 len = sizeof(cmd.v7);
1354 else if (cmd_ver == 6)
1355 len = sizeof(cmd.v6);
1356 else if (fw_has_api(&mvm->fw->ucode_capa,
1357 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1358 len = sizeof(cmd.v5);
1359 else if (fw_has_capa(&mvm->fw->ucode_capa,
1360 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1361 len = sizeof(cmd.v4);
1363 len = sizeof(cmd.v3);
1365 /* all structs have the same common part, add it */
1366 len += sizeof(cmd.common);
1368 return iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, len, &cmd);
1371 int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
1372 struct ieee80211_vif *vif)
1374 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1375 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1378 mutex_lock(&mvm->mutex);
1380 if (vif->type == NL80211_IFTYPE_STATION) {
1381 struct iwl_mvm_sta *mvmsta;
1383 mvmvif->csa_bcn_pending = false;
1384 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
1385 mvmvif->deflink.ap_sta_id);
1387 if (WARN_ON(!mvmsta)) {
1392 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
1393 if (mvm->mld_api_is_used)
1394 iwl_mvm_mld_mac_ctxt_changed(mvm, vif, false);
1396 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1398 if (!fw_has_capa(&mvm->fw->ucode_capa,
1399 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
1400 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1404 iwl_mvm_stop_session_protection(mvm, vif);
1408 mvmvif->ps_disabled = false;
1410 ret = iwl_mvm_power_update_ps(mvm);
1413 if (mvmvif->csa_failed)
1415 mutex_unlock(&mvm->mutex);
1420 void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw,
1421 struct ieee80211_vif *vif)
1423 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1424 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1425 struct iwl_chan_switch_te_cmd cmd = {
1426 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1428 .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE),
1432 * In the new flow since FW is in charge of the timing,
1433 * if driver has canceled the channel switch he will receive the
1434 * CHANNEL_SWITCH_START_NOTIF notification from FW and then cancel it
1436 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
1437 CHANNEL_SWITCH_ERROR_NOTIF, 0))
1440 IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id);
1442 mutex_lock(&mvm->mutex);
1443 if (!fw_has_capa(&mvm->fw->ucode_capa,
1444 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
1445 iwl_mvm_remove_csa_period(mvm, vif);
1447 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
1448 WIDE_ID(MAC_CONF_GROUP,
1449 CHANNEL_SWITCH_TIME_EVENT_CMD),
1450 0, sizeof(cmd), &cmd));
1451 mvmvif->csa_failed = true;
1452 mutex_unlock(&mvm->mutex);
1454 iwl_mvm_post_channel_switch(hw, vif);
1457 void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk)
1459 struct iwl_mvm_vif *mvmvif;
1460 struct ieee80211_vif *vif;
1462 mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work);
1463 vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);
1465 /* Trigger disconnect (should clear the CSA state) */
1466 ieee80211_chswitch_done(vif, false);
1470 iwl_mvm_chandef_get_primary_80(struct cfg80211_chan_def *chandef)
1476 if (chandef->width == NL80211_CHAN_WIDTH_320)
1478 else if (chandef->width == NL80211_CHAN_WIDTH_160)
1483 /* data is bw wide so the start is half the width */
1484 data_start = chandef->center_freq1 - bw / 2;
1485 /* control is 20Mhz width */
1486 control_start = chandef->chan->center_freq - 10;
1488 return (control_start - data_start) / 80;
1491 static int iwl_mvm_alloc_bcast_mcast_sta(struct iwl_mvm *mvm,
1492 struct ieee80211_vif *vif)
1494 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1497 lockdep_assert_held(&mvm->mutex);
1499 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1501 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1505 /* Only queue for this station is the mcast queue,
1506 * which shouldn't be in TFD mask anyway
1508 return iwl_mvm_allocate_int_sta(mvm, &mvmvif->deflink.mcast_sta, 0,
1513 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1514 struct ieee80211_vif *vif)
1516 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1517 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1520 mutex_lock(&mvm->mutex);
1524 /* the first link always points to the default one */
1525 mvmvif->link[0] = &mvmvif->deflink;
1528 * Not much to do here. The stack will not allow interface
1529 * types or combinations that we didn't advertise, so we
1530 * don't really have to check the types.
1533 /* make sure that beacon statistics don't go backwards with FW reset */
1534 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1535 mvmvif->deflink.beacon_stats.accu_num_beacons +=
1536 mvmvif->deflink.beacon_stats.num_beacons;
1538 /* Allocate resources for the MAC context, and add it to the fw */
1539 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1543 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif);
1545 /* Currently not much to do for NAN */
1546 if (vif->type == NL80211_IFTYPE_NAN) {
1552 * The AP binding flow can be done only after the beacon
1553 * template is configured (which happens only in the mac80211
1554 * start_ap() flow), and adding the broadcast station can happen
1555 * only after the binding.
1556 * In addition, since modifying the MAC before adding a bcast
1557 * station is not allowed by the FW, delay the adding of MAC context to
1558 * the point where we can also add the bcast station.
1559 * In short: there's not much we can do at this point, other than
1560 * allocating resources :)
1562 if (vif->type == NL80211_IFTYPE_AP ||
1563 vif->type == NL80211_IFTYPE_ADHOC) {
1564 iwl_mvm_vif_dbgfs_register(mvm, vif);
1569 mvmvif->features |= hw->netdev_features;
1571 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1575 ret = iwl_mvm_power_update_mac(mvm);
1577 goto out_remove_mac;
1579 /* beacon filtering */
1580 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1582 goto out_remove_mac;
1584 if (!mvm->bf_allowed_vif &&
1585 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1586 mvm->bf_allowed_vif = mvmvif;
1587 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1588 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1592 * P2P_DEVICE interface does not have a channel context assigned to it,
1593 * so a dedicated PHY context is allocated to it and the corresponding
1594 * MAC context is bound to it at this stage.
1596 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1598 mvmvif->deflink.phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1599 if (!mvmvif->deflink.phy_ctxt) {
1604 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->deflink.phy_ctxt);
1605 ret = iwl_mvm_binding_add_vif(mvm, vif);
1609 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1613 /* Save a pointer to p2p device vif, so it can later be used to
1614 * update the p2p device MAC when a GO is started/stopped */
1615 mvm->p2p_device_vif = vif;
1618 iwl_mvm_tcm_add_vif(mvm, vif);
1619 INIT_DELAYED_WORK(&mvmvif->csa_work,
1620 iwl_mvm_channel_switch_disconnect_wk);
1622 if (vif->type == NL80211_IFTYPE_MONITOR) {
1623 mvm->monitor_on = true;
1625 iwl_mvm_chandef_get_primary_80(&vif->bss_conf.chandef);
1628 iwl_mvm_vif_dbgfs_register(mvm, vif);
1630 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
1631 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
1632 !mvm->csme_vif && mvm->mei_registered) {
1633 iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr);
1634 iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev);
1635 mvm->csme_vif = vif;
1639 if (!ret && (vif->type == NL80211_IFTYPE_AP ||
1640 vif->type == NL80211_IFTYPE_ADHOC))
1641 ret = iwl_mvm_alloc_bcast_mcast_sta(mvm, vif);
1646 iwl_mvm_binding_remove_vif(mvm, vif);
1648 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt);
1650 if (mvm->bf_allowed_vif == mvmvif) {
1651 mvm->bf_allowed_vif = NULL;
1652 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1653 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1656 mvmvif->deflink.phy_ctxt = NULL;
1657 iwl_mvm_mac_ctxt_remove(mvm, vif);
1659 mutex_unlock(&mvm->mutex);
1664 void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1665 struct ieee80211_vif *vif)
1667 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1669 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1670 * We assume here that all the packets sent to the OFFCHANNEL
1671 * queue are sent in ROC session.
1673 flush_work(&mvm->roc_done_wk);
1677 /* This function is doing the common part of removing the interface for
1678 * both - MLD and non-MLD modes. Returns true if removing the interface
1681 static bool iwl_mvm_mac_remove_interface_common(struct ieee80211_hw *hw,
1682 struct ieee80211_vif *vif)
1684 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1685 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1686 struct iwl_probe_resp_data *probe_data;
1688 iwl_mvm_prepare_mac_removal(mvm, vif);
1690 if (!(vif->type == NL80211_IFTYPE_AP ||
1691 vif->type == NL80211_IFTYPE_ADHOC))
1692 iwl_mvm_tcm_rm_vif(mvm, vif);
1694 mutex_lock(&mvm->mutex);
1696 if (vif == mvm->csme_vif) {
1697 iwl_mei_set_netdev(NULL);
1698 mvm->csme_vif = NULL;
1701 probe_data = rcu_dereference_protected(mvmvif->deflink.probe_resp_data,
1702 lockdep_is_held(&mvm->mutex));
1703 RCU_INIT_POINTER(mvmvif->deflink.probe_resp_data, NULL);
1705 kfree_rcu(probe_data, rcu_head);
1707 if (mvm->bf_allowed_vif == mvmvif) {
1708 mvm->bf_allowed_vif = NULL;
1709 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1710 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1713 if (vif->bss_conf.ftm_responder)
1714 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
1716 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1719 * For AP/GO interface, the tear down of the resources allocated to the
1720 * interface is be handled as part of the stop_ap flow.
1722 if (vif->type == NL80211_IFTYPE_AP ||
1723 vif->type == NL80211_IFTYPE_ADHOC) {
1724 #ifdef CONFIG_NL80211_TESTMODE
1725 if (vif == mvm->noa_vif) {
1726 mvm->noa_vif = NULL;
1727 mvm->noa_duration = 0;
1733 iwl_mvm_power_update_mac(mvm);
1737 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1738 struct ieee80211_vif *vif)
1740 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1741 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1743 if (iwl_mvm_mac_remove_interface_common(hw, vif))
1746 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1747 mvm->p2p_device_vif = NULL;
1748 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1749 iwl_mvm_binding_remove_vif(mvm, vif);
1750 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt);
1751 mvmvif->deflink.phy_ctxt = NULL;
1754 iwl_mvm_mac_ctxt_remove(mvm, vif);
1756 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL);
1758 if (vif->type == NL80211_IFTYPE_MONITOR)
1759 mvm->monitor_on = false;
1762 if (vif->type == NL80211_IFTYPE_AP ||
1763 vif->type == NL80211_IFTYPE_ADHOC) {
1764 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->deflink.mcast_sta);
1765 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1768 mutex_unlock(&mvm->mutex);
1771 struct iwl_mvm_mc_iter_data {
1772 struct iwl_mvm *mvm;
1776 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1777 struct ieee80211_vif *vif)
1779 struct iwl_mvm_mc_iter_data *data = _data;
1780 struct iwl_mvm *mvm = data->mvm;
1781 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1782 struct iwl_host_cmd hcmd = {
1783 .id = MCAST_FILTER_CMD,
1785 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1789 /* if we don't have free ports, mcast frames will be dropped */
1790 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1793 if (vif->type != NL80211_IFTYPE_STATION ||
1797 cmd->port_id = data->port_id++;
1798 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1799 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1804 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1806 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1809 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1811 struct iwl_mvm_mc_iter_data iter_data = {
1816 lockdep_assert_held(&mvm->mutex);
1818 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1821 ieee80211_iterate_active_interfaces_atomic(
1822 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1823 iwl_mvm_mc_iface_iterator, &iter_data);
1826 * Send a (synchronous) ech command so that we wait for the
1827 * multiple asynchronous MCAST_FILTER_CMD commands sent by
1828 * the interface iterator. Otherwise, we might get here over
1829 * and over again (by userspace just sending a lot of these)
1830 * and the CPU can send them faster than the firmware can
1832 * Note that the CPU is still faster - but with this we'll
1833 * actually send fewer commands overall because the CPU will
1834 * not schedule the work in mac80211 as frequently if it's
1835 * still running when rescheduled (possibly multiple times).
1837 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1839 IWL_ERR(mvm, "Failed to synchronize multicast groups update\n");
1842 u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1843 struct netdev_hw_addr_list *mc_list)
1845 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1846 struct iwl_mcast_filter_cmd *cmd;
1847 struct netdev_hw_addr *addr;
1852 addr_count = netdev_hw_addr_list_count(mc_list);
1853 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1854 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1858 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1859 cmd = kzalloc(len, GFP_ATOMIC);
1865 return (u64)(unsigned long)cmd;
1868 netdev_hw_addr_list_for_each(addr, mc_list) {
1869 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1870 cmd->count, addr->addr);
1871 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1872 addr->addr, ETH_ALEN);
1876 return (u64)(unsigned long)cmd;
1879 void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1880 unsigned int changed_flags,
1881 unsigned int *total_flags, u64 multicast)
1883 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1884 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1886 mutex_lock(&mvm->mutex);
1888 /* replace previous configuration */
1889 kfree(mvm->mcast_filter_cmd);
1890 mvm->mcast_filter_cmd = cmd;
1895 if (changed_flags & FIF_ALLMULTI)
1896 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1901 iwl_mvm_recalc_multicast(mvm);
1903 mutex_unlock(&mvm->mutex);
1907 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1908 struct ieee80211_vif *vif,
1909 unsigned int filter_flags,
1910 unsigned int changed_flags)
1912 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1914 /* We support only filter for probe requests */
1915 if (!(changed_flags & FIF_PROBE_REQ))
1918 /* Supported only for p2p client interfaces */
1919 if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc ||
1923 mutex_lock(&mvm->mutex);
1924 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1925 mutex_unlock(&mvm->mutex);
1928 int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1930 struct iwl_mu_group_mgmt_cmd cmd = {};
1932 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1933 WLAN_MEMBERSHIP_LEN);
1934 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1935 WLAN_USER_POSITION_LEN);
1937 return iwl_mvm_send_cmd_pdu(mvm,
1938 WIDE_ID(DATA_PATH_GROUP,
1939 UPDATE_MU_GROUPS_CMD),
1940 0, sizeof(cmd), &cmd);
1943 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1944 struct ieee80211_vif *vif)
1946 if (vif->bss_conf.mu_mimo_owner) {
1947 struct iwl_mu_group_mgmt_notif *notif = _data;
1950 * MU-MIMO Group Id action frame is little endian. We treat
1951 * the data received from firmware as if it came from the
1952 * action frame, so no conversion is needed.
1954 ieee80211_update_mu_groups(vif, 0,
1955 (u8 *)¬if->membership_status,
1956 (u8 *)¬if->user_position);
1960 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1961 struct iwl_rx_cmd_buffer *rxb)
1963 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1964 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1966 ieee80211_iterate_active_interfaces_atomic(
1967 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1968 iwl_mvm_mu_mimo_iface_iterator, notif);
1971 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1973 u8 byte_num = ppe_pos_bit / 8;
1974 u8 bit_num = ppe_pos_bit % 8;
1979 return (ppe[byte_num] >> bit_num) &
1980 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1983 * If bit_num > 5, we have to combine bits with next byte.
1984 * Calculate how many bits we need to take from current byte (called
1985 * here "residue_bits"), and add them to bits from next byte.
1988 residue_bits = 8 - bit_num;
1990 res = (ppe[byte_num + 1] &
1991 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1993 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1998 static void iwl_mvm_parse_ppe(struct iwl_mvm *mvm,
1999 struct iwl_he_pkt_ext_v2 *pkt_ext, u8 nss,
2000 u8 ru_index_bitmap, u8 *ppe, u8 ppe_pos_bit,
2006 * FW currently supports only nss == MAX_HE_SUPP_NSS
2008 * If nss > MAX: we can ignore values we don't support
2009 * If nss < MAX: we can set zeros in other streams
2011 if (nss > MAX_HE_SUPP_NSS) {
2012 IWL_DEBUG_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2014 nss = MAX_HE_SUPP_NSS;
2017 for (i = 0; i < nss; i++) {
2018 u8 ru_index_tmp = ru_index_bitmap << 1;
2019 u8 low_th = IWL_HE_PKT_EXT_NONE, high_th = IWL_HE_PKT_EXT_NONE;
2023 bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]);
2028 * According to the 11be spec, if for a specific BW the PPE Thresholds
2029 * isn't present - it should inherit the thresholds from the last
2030 * BW for which we had PPE Thresholds. In 11ax though, we don't have
2031 * this inheritance - continue in this case
2033 if (!(ru_index_tmp & 1)) {
2035 goto set_thresholds;
2040 high_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit);
2041 ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2042 low_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit);
2043 ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2046 pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th;
2047 pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th;
2052 static void iwl_mvm_set_pkt_ext_from_he_ppe(struct iwl_mvm *mvm,
2053 struct ieee80211_link_sta *link_sta,
2054 struct iwl_he_pkt_ext_v2 *pkt_ext,
2057 u8 nss = (link_sta->he_cap.ppe_thres[0] &
2058 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2059 u8 *ppe = &link_sta->he_cap.ppe_thres[0];
2060 u8 ru_index_bitmap =
2062 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK);
2063 /* Starting after PPE header */
2064 u8 ppe_pos_bit = IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE;
2066 iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, ppe, ppe_pos_bit,
2071 iwl_mvm_set_pkt_ext_from_nominal_padding(struct iwl_he_pkt_ext_v2 *pkt_ext,
2078 /* all the macros are the same for EHT and HE */
2079 switch (nominal_padding) {
2080 case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_0US:
2081 low_th = IWL_HE_PKT_EXT_NONE;
2082 high_th = IWL_HE_PKT_EXT_NONE;
2084 case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US:
2085 low_th = IWL_HE_PKT_EXT_BPSK;
2086 high_th = IWL_HE_PKT_EXT_NONE;
2088 case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US:
2089 case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_20US:
2090 low_th = IWL_HE_PKT_EXT_NONE;
2091 high_th = IWL_HE_PKT_EXT_BPSK;
2095 if (low_th < 0 || high_th < 0)
2098 /* Set the PPE thresholds accordingly */
2099 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
2103 bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]);
2105 pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th;
2106 pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th;
2113 static void iwl_mvm_get_optimal_ppe_info(struct iwl_he_pkt_ext_v2 *pkt_ext,
2118 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
2121 for (bw = 0; bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]);
2123 u8 *qam_th = &pkt_ext->pkt_ext_qam_th[i][bw][0];
2125 if (nominal_padding >
2126 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US &&
2127 qam_th[1] == IWL_HE_PKT_EXT_NONE)
2128 qam_th[1] = IWL_HE_PKT_EXT_4096QAM;
2129 else if (nominal_padding ==
2130 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US &&
2131 qam_th[0] == IWL_HE_PKT_EXT_NONE &&
2132 qam_th[1] == IWL_HE_PKT_EXT_NONE)
2133 qam_th[0] = IWL_HE_PKT_EXT_4096QAM;
2138 /* Set the pkt_ext field according to PPE Thresholds element */
2139 int iwl_mvm_set_sta_pkt_ext(struct iwl_mvm *mvm,
2140 struct ieee80211_link_sta *link_sta,
2141 struct iwl_he_pkt_ext_v2 *pkt_ext)
2146 if (WARN_ON(!link_sta))
2149 /* Initialize the PPE thresholds to "None" (7), as described in Table
2150 * 9-262ac of 80211.ax/D3.0.
2152 memset(pkt_ext, IWL_HE_PKT_EXT_NONE,
2153 sizeof(struct iwl_he_pkt_ext_v2));
2155 if (link_sta->eht_cap.has_eht) {
2157 u8_get_bits(link_sta->eht_cap.eht_cap_elem.phy_cap_info[5],
2158 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK);
2160 /* If PPE Thresholds exists, parse them into a FW-familiar
2163 if (link_sta->eht_cap.eht_cap_elem.phy_cap_info[5] &
2164 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) {
2165 u8 nss = (link_sta->eht_cap.eht_ppe_thres[0] &
2166 IEEE80211_EHT_PPE_THRES_NSS_MASK) + 1;
2167 u8 *ppe = &link_sta->eht_cap.eht_ppe_thres[0];
2168 u8 ru_index_bitmap =
2170 IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK);
2171 /* Starting after PPE header */
2172 u8 ppe_pos_bit = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE;
2174 iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap,
2175 ppe, ppe_pos_bit, true);
2176 /* EHT PPE Thresholds doesn't exist - set the API according to
2179 } else if (link_sta->he_cap.he_cap_elem.phy_cap_info[6] &
2180 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2181 /* Even though HE Capabilities IE doesn't contain PPE
2182 * Thresholds for BW 320Mhz, thresholds for this BW will
2183 * be filled in with the same values as 160Mhz, due to
2184 * the inheritance, as required.
2186 iwl_mvm_set_pkt_ext_from_he_ppe(mvm, link_sta, pkt_ext,
2189 /* According to the requirements, for MCSs 12-13 the
2190 * maximum value between HE PPE Threshold and Common
2191 * Nominal Packet Padding needs to be taken
2193 iwl_mvm_get_optimal_ppe_info(pkt_ext, nominal_padding);
2195 /* if PPE Thresholds doesn't present in both EHT IE and HE IE -
2196 * take the Thresholds from Common Nominal Packet Padding field
2199 ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext,
2202 } else if (link_sta->he_cap.has_he) {
2203 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2204 if (link_sta->he_cap.he_cap_elem.phy_cap_info[6] &
2205 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2206 iwl_mvm_set_pkt_ext_from_he_ppe(mvm, link_sta, pkt_ext,
2208 /* PPE Thresholds doesn't exist - set the API PPE values
2209 * according to Common Nominal Packet Padding field.
2213 u8_get_bits(link_sta->he_cap.he_cap_elem.phy_cap_info[9],
2214 IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK);
2215 if (nominal_padding != IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED)
2216 ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext,
2221 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
2225 bw < ARRAY_SIZE(*pkt_ext->pkt_ext_qam_th[i]);
2228 &pkt_ext->pkt_ext_qam_th[i][bw][0];
2231 "PPE table: nss[%d] bw[%d] PPET8 = %d, PPET16 = %d\n",
2232 i, bw, qam_th[0], qam_th[1]);
2239 * This function sets the MU EDCA parameters ans returns whether MU EDCA
2242 bool iwl_mvm_set_fw_mu_edca_params(struct iwl_mvm *mvm,
2243 struct iwl_mvm_vif *mvmvif,
2244 struct iwl_he_backoff_conf *trig_based_txf)
2247 /* Mark MU EDCA as enabled, unless none detected on some AC */
2248 bool mu_edca_enabled = true;
2250 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
2251 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2252 &mvmvif->deflink.queue_params[i].mu_edca_param_rec;
2253 u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
2255 if (!mvmvif->deflink.queue_params[i].mu_edca) {
2256 mu_edca_enabled = false;
2260 trig_based_txf[ac].cwmin =
2261 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2262 trig_based_txf[ac].cwmax =
2263 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2264 trig_based_txf[ac].aifsn =
2265 cpu_to_le16(mu_edca->aifsn & 0xf);
2266 trig_based_txf[ac].mu_time =
2267 cpu_to_le16(mu_edca->mu_edca_timer);
2270 return mu_edca_enabled;
2273 bool iwl_mvm_is_nic_ack_enabled(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2275 const struct ieee80211_supported_band *sband;
2276 const struct ieee80211_sta_he_cap *own_he_cap = NULL;
2278 /* This capability is the same for all bands,
2279 * so take it from one of them.
2281 sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ];
2282 own_he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif);
2284 return (own_he_cap && (own_he_cap->he_cap_elem.mac_cap_info[2] &
2285 IEEE80211_HE_MAC_CAP2_ACK_EN));
2288 __le32 iwl_mvm_get_sta_htc_flags(struct ieee80211_sta *sta,
2289 struct ieee80211_link_sta *link_sta)
2292 &link_sta->he_cap.he_cap_elem.mac_cap_info[0];
2293 __le32 htc_flags = 0;
2295 if (mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_HTC_HE)
2296 htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
2297 if ((mac_cap_info[1] & IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2298 (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2301 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2303 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2307 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2308 else if (link_adap == 3)
2309 htc_flags |= cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2311 if (mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2312 htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2313 if (mac_cap_info[3] & IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2314 htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2315 if (mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2316 htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2321 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
2322 struct ieee80211_vif *vif, u8 sta_id)
2324 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2325 struct iwl_he_sta_context_cmd_v3 sta_ctxt_cmd = {
2327 .tid_limit = IWL_MAX_TID_COUNT,
2328 .bss_color = vif->bss_conf.he_bss_color.color,
2329 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
2330 .frame_time_rts_th =
2331 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
2333 struct iwl_he_sta_context_cmd_v2 sta_ctxt_cmd_v2 = {};
2334 u32 cmd_id = WIDE_ID(DATA_PATH_GROUP, STA_HE_CTXT_CMD);
2335 u8 ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 2);
2337 struct ieee80211_sta *sta;
2342 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_MBSSID_HE))
2347 /* same layout as v2 except some data at the end */
2348 cmd = &sta_ctxt_cmd_v2;
2349 size = sizeof(struct iwl_he_sta_context_cmd_v1);
2352 cmd = &sta_ctxt_cmd_v2;
2353 size = sizeof(struct iwl_he_sta_context_cmd_v2);
2356 cmd = &sta_ctxt_cmd;
2357 size = sizeof(struct iwl_he_sta_context_cmd_v3);
2360 IWL_ERR(mvm, "bad STA_HE_CTXT_CMD version %d\n", ver);
2366 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
2367 if (IS_ERR_OR_NULL(sta)) {
2369 WARN(1, "Can't find STA to configure HE\n");
2373 if (!sta->deflink.he_cap.has_he) {
2380 /* Block 26-tone RU OFDMA transmissions */
2381 if (mvmvif->deflink.he_ru_2mhz_block)
2382 flags |= STA_CTXT_HE_RU_2MHZ_BLOCK;
2385 sta_ctxt_cmd.htc_flags = iwl_mvm_get_sta_htc_flags(sta, &sta->deflink);
2387 /* PPE Thresholds */
2388 if (!iwl_mvm_set_sta_pkt_ext(mvm, &sta->deflink, &sta_ctxt_cmd.pkt_ext))
2389 flags |= STA_CTXT_HE_PACKET_EXT;
2391 if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] &
2392 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP)
2393 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2395 if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] &
2396 IEEE80211_HE_MAC_CAP2_ACK_EN)
2397 flags |= STA_CTXT_HE_ACK_ENABLED;
2401 if (iwl_mvm_set_fw_mu_edca_params(mvm, mvmvif,
2402 &sta_ctxt_cmd.trig_based_txf[0]))
2403 flags |= STA_CTXT_HE_MU_EDCA_CW;
2405 if (vif->bss_conf.uora_exists) {
2406 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2408 sta_ctxt_cmd.rand_alloc_ecwmin =
2409 vif->bss_conf.uora_ocw_range & 0x7;
2410 sta_ctxt_cmd.rand_alloc_ecwmax =
2411 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2414 if (!iwl_mvm_is_nic_ack_enabled(mvm, vif))
2415 flags |= STA_CTXT_HE_NIC_NOT_ACK_ENABLED;
2417 if (vif->bss_conf.nontransmitted) {
2418 flags |= STA_CTXT_HE_REF_BSSID_VALID;
2419 ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr,
2420 vif->bss_conf.transmitter_bssid);
2421 sta_ctxt_cmd.max_bssid_indicator =
2422 vif->bss_conf.bssid_indicator;
2423 sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index;
2424 sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap;
2425 sta_ctxt_cmd.profile_periodicity =
2426 vif->bss_conf.profile_periodicity;
2429 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2432 /* fields before pkt_ext */
2433 BUILD_BUG_ON(offsetof(typeof(sta_ctxt_cmd), pkt_ext) !=
2434 offsetof(typeof(sta_ctxt_cmd_v2), pkt_ext));
2435 memcpy(&sta_ctxt_cmd_v2, &sta_ctxt_cmd,
2436 offsetof(typeof(sta_ctxt_cmd), pkt_ext));
2440 i < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th);
2445 bw < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i]);
2447 BUILD_BUG_ON(sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]) !=
2448 sizeof(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw]));
2450 memcpy(&sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw],
2451 &sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw],
2452 sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]));
2456 /* fields after pkt_ext */
2457 BUILD_BUG_ON(sizeof(sta_ctxt_cmd) -
2458 offsetofend(typeof(sta_ctxt_cmd), pkt_ext) !=
2459 sizeof(sta_ctxt_cmd_v2) -
2460 offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext));
2461 memcpy((u8 *)&sta_ctxt_cmd_v2 +
2462 offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext),
2463 (u8 *)&sta_ctxt_cmd +
2464 offsetofend(typeof(sta_ctxt_cmd), pkt_ext),
2465 sizeof(sta_ctxt_cmd) -
2466 offsetofend(typeof(sta_ctxt_cmd), pkt_ext));
2467 sta_ctxt_cmd_v2.reserved3 = 0;
2470 if (iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, size, cmd))
2471 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2474 void iwl_mvm_protect_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2475 u32 duration_override)
2477 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
2478 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
2480 if (duration_override > duration)
2481 duration = duration_override;
2483 /* Try really hard to protect the session and hear a beacon
2484 * The new session protection command allows us to protect the
2485 * session for a much longer time since the firmware will internally
2486 * create two events: a 300TU one with a very high priority that
2487 * won't be fragmented which should be enough for 99% of the cases,
2488 * and another one (which we configure here to be 900TU long) which
2489 * will have a slightly lower priority, but more importantly, can be
2490 * fragmented so that it'll allow other activities to run.
2492 if (fw_has_capa(&mvm->fw->ucode_capa,
2493 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD))
2494 iwl_mvm_schedule_session_protection(mvm, vif, 900,
2495 min_duration, false);
2497 iwl_mvm_protect_session(mvm, vif, duration,
2498 min_duration, 500, false);
2501 /* Handle association common part to MLD and non-MLD modes */
2502 void iwl_mvm_bss_info_changed_station_assoc(struct iwl_mvm *mvm,
2503 struct ieee80211_vif *vif,
2506 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2509 /* The firmware tracks the MU-MIMO group on its own.
2510 * However, on HW restart we should restore this data.
2512 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2513 (changes & BSS_CHANGED_MU_GROUPS) && vif->bss_conf.mu_mimo_owner) {
2514 ret = iwl_mvm_update_mu_groups(mvm, vif);
2517 "failed to update VHT MU_MIMO groups\n");
2520 iwl_mvm_recalc_multicast(mvm);
2522 /* reset rssi values */
2523 mvmvif->bf_data.ave_beacon_signal = 0;
2525 iwl_mvm_bt_coex_vif_change(mvm);
2526 iwl_mvm_update_smps_on_active_links(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2527 IEEE80211_SMPS_AUTOMATIC);
2528 if (fw_has_capa(&mvm->fw->ucode_capa,
2529 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2530 iwl_mvm_config_scan(mvm);
2533 /* Execute the common part for MLD and non-MLD modes */
2535 iwl_mvm_bss_info_changed_station_common(struct iwl_mvm *mvm,
2536 struct ieee80211_vif *vif,
2537 struct ieee80211_bss_conf *link_conf,
2540 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2543 if (changes & BSS_CHANGED_BEACON_INFO) {
2544 /* We received a beacon from the associated AP so
2545 * remove the session protection.
2547 iwl_mvm_stop_session_protection(mvm, vif);
2549 iwl_mvm_sf_update(mvm, vif, false);
2550 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2553 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2554 /* Send power command on every beacon change,
2555 * because we may have not enabled beacon abort yet.
2557 BSS_CHANGED_BEACON_INFO)) {
2558 ret = iwl_mvm_power_update_mac(mvm);
2560 IWL_ERR(mvm, "failed to update power mode\n");
2563 if (changes & BSS_CHANGED_CQM) {
2564 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2565 /* reset cqm events tracking */
2566 mvmvif->bf_data.last_cqm_event = 0;
2567 if (mvmvif->bf_data.bf_enabled) {
2568 /* FIXME: need to update per link when FW API will
2571 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2574 "failed to update CQM thresholds\n");
2578 if (changes & BSS_CHANGED_BANDWIDTH)
2579 iwl_mvm_update_link_smps(vif, link_conf);
2582 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2583 struct ieee80211_vif *vif,
2584 struct ieee80211_bss_conf *bss_conf,
2587 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2591 * Re-calculate the tsf id, as the leader-follower relations depend
2592 * on the beacon interval, which was not known when the station
2593 * interface was added.
2595 if (changes & BSS_CHANGED_ASSOC && vif->cfg.assoc) {
2596 if ((vif->bss_conf.he_support &&
2597 !iwlwifi_mod_params.disable_11ax) ||
2598 (vif->bss_conf.eht_support &&
2599 !iwlwifi_mod_params.disable_11be))
2600 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->deflink.ap_sta_id);
2602 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2605 /* Update MU EDCA params */
2606 if (changes & BSS_CHANGED_QOS && mvmvif->associated &&
2608 ((vif->bss_conf.he_support &&
2609 !iwlwifi_mod_params.disable_11ax) ||
2610 (vif->bss_conf.eht_support &&
2611 !iwlwifi_mod_params.disable_11be)))
2612 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->deflink.ap_sta_id);
2615 * If we're not associated yet, take the (new) BSSID before associating
2616 * so the firmware knows. If we're already associated, then use the old
2617 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2618 * branch for disassociation below.
2620 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2621 memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN);
2623 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->deflink.bssid);
2625 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2627 /* after sending it once, adopt mac80211 data */
2628 memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN);
2629 mvmvif->associated = vif->cfg.assoc;
2631 if (changes & BSS_CHANGED_ASSOC) {
2632 if (vif->cfg.assoc) {
2633 /* clear statistics to get clean beacon counter */
2634 iwl_mvm_request_statistics(mvm, true);
2635 memset(&mvmvif->deflink.beacon_stats, 0,
2636 sizeof(mvmvif->deflink.beacon_stats));
2638 /* add quota for this interface */
2639 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2641 IWL_ERR(mvm, "failed to update quotas\n");
2645 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2647 !fw_has_capa(&mvm->fw->ucode_capa,
2648 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) {
2650 * If we're restarting then the firmware will
2651 * obviously have lost synchronisation with
2652 * the AP. It will attempt to synchronise by
2653 * itself, but we can make it more reliable by
2654 * scheduling a session protection time event.
2656 * The firmware needs to receive a beacon to
2657 * catch up with synchronisation, use 110% of
2658 * the beacon interval.
2660 * Set a large maximum delay to allow for more
2661 * than a single interface.
2663 * For new firmware versions, rely on the
2664 * firmware. This is relevant for DCM scenarios
2667 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2668 iwl_mvm_protect_session(mvm, vif, dur, dur,
2670 } else if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2672 !vif->bss_conf.dtim_period) {
2674 * If we're not restarting and still haven't
2675 * heard a beacon (dtim period unknown) then
2676 * make sure we still have enough minimum time
2677 * remaining in the time event, since the auth
2678 * might actually have taken quite a while
2679 * (especially for SAE) and so the remaining
2680 * time could be small without us having heard
2683 iwl_mvm_protect_assoc(mvm, vif, 0);
2686 iwl_mvm_sf_update(mvm, vif, false);
2687 iwl_mvm_power_vif_assoc(mvm, vif);
2689 iwl_mvm_update_smps(mvm, vif,
2690 IWL_MVM_SMPS_REQ_PROT,
2691 IEEE80211_SMPS_DYNAMIC, 0);
2693 } else if (mvmvif->deflink.ap_sta_id != IWL_MVM_INVALID_STA) {
2694 iwl_mvm_mei_host_disassociated(mvm);
2696 * If update fails - SF might be running in associated
2697 * mode while disassociated - which is forbidden.
2699 ret = iwl_mvm_sf_update(mvm, vif, false);
2701 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
2703 "Failed to update SF upon disassociation\n");
2706 * If we get an assert during the connection (after the
2707 * station has been added, but before the vif is set
2708 * to associated), mac80211 will re-add the station and
2709 * then configure the vif. Since the vif is not
2710 * associated, we would remove the station here and
2711 * this would fail the recovery.
2713 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2715 /* first remove remaining keys */
2716 iwl_mvm_sec_key_remove_ap(mvm, vif,
2717 &mvmvif->deflink, 0);
2720 * Remove AP station now that
2721 * the MAC is unassoc
2723 ret = iwl_mvm_rm_sta_id(mvm, vif,
2724 mvmvif->deflink.ap_sta_id);
2727 "failed to remove AP station\n");
2729 mvmvif->deflink.ap_sta_id = IWL_MVM_INVALID_STA;
2732 /* remove quota for this interface */
2733 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2735 IWL_ERR(mvm, "failed to update quotas\n");
2737 /* this will take the cleared BSSID from bss_conf */
2738 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2741 "failed to update MAC %pM (clear after unassoc)\n",
2745 iwl_mvm_bss_info_changed_station_assoc(mvm, vif, changes);
2748 iwl_mvm_bss_info_changed_station_common(mvm, vif, &vif->bss_conf,
2752 bool iwl_mvm_start_ap_ibss_common(struct ieee80211_hw *hw,
2753 struct ieee80211_vif *vif,
2756 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2757 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2760 lockdep_assert_held(&mvm->mutex);
2762 mvmvif->ap_assoc_sta_count = 0;
2764 /* must be set before quota calculations */
2765 mvmvif->ap_ibss_active = true;
2767 /* send all the early keys to the device now */
2768 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
2769 struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i];
2774 mvmvif->ap_early_keys[i] = NULL;
2776 *ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key);
2781 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2782 iwl_mvm_vif_set_low_latency(mvmvif, true,
2783 LOW_LATENCY_VIF_TYPE);
2784 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2787 /* power updated needs to be done before quotas */
2788 iwl_mvm_power_update_mac(mvm);
2793 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2794 struct ieee80211_vif *vif,
2795 struct ieee80211_bss_conf *link_conf)
2797 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2798 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2801 mutex_lock(&mvm->mutex);
2804 * Re-calculate the tsf id, as the leader-follower relations depend on
2805 * the beacon interval, which was not known when the AP interface
2808 if (vif->type == NL80211_IFTYPE_AP)
2809 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2811 /* For older devices need to send beacon template before adding mac
2812 * context. For the newer, the beacon is a resource that belongs to a
2813 * MAC, so need to send beacon template after adding the mac.
2815 if (mvm->trans->trans_cfg->device_family > IWL_DEVICE_FAMILY_22000) {
2816 /* Add the mac context */
2817 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2821 /* Send the beacon template */
2822 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf);
2826 /* Send the beacon template */
2827 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf);
2831 /* Add the mac context */
2832 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2837 /* Perform the binding */
2838 ret = iwl_mvm_binding_add_vif(mvm, vif);
2843 * This is not very nice, but the simplest:
2844 * For older FWs adding the mcast sta before the bcast station may
2845 * cause assert 0x2b00.
2846 * This is fixed in later FW so make the order of removal depend on
2849 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2850 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2854 * Send the bcast station. At this stage the TBTT and DTIM time
2855 * events are added and applied to the scheduler
2857 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2859 iwl_mvm_rm_mcast_sta(mvm, vif);
2864 * Send the bcast station. At this stage the TBTT and DTIM time
2865 * events are added and applied to the scheduler
2867 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2870 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2872 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2877 if (iwl_mvm_start_ap_ibss_common(hw, vif, &ret))
2880 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2884 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2885 if (vif->p2p && mvm->p2p_device_vif)
2886 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2888 iwl_mvm_bt_coex_vif_change(mvm);
2890 /* we don't support TDLS during DCM */
2891 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2892 iwl_mvm_teardown_tdls_peers(mvm);
2894 iwl_mvm_ftm_restart_responder(mvm, vif, &vif->bss_conf);
2899 iwl_mvm_power_update_mac(mvm);
2900 mvmvif->ap_ibss_active = false;
2901 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2902 iwl_mvm_rm_mcast_sta(mvm, vif);
2904 iwl_mvm_binding_remove_vif(mvm, vif);
2906 iwl_mvm_mac_ctxt_remove(mvm, vif);
2908 mutex_unlock(&mvm->mutex);
2912 static int iwl_mvm_start_ap(struct ieee80211_hw *hw,
2913 struct ieee80211_vif *vif,
2914 struct ieee80211_bss_conf *link_conf)
2916 return iwl_mvm_start_ap_ibss(hw, vif, link_conf);
2919 static int iwl_mvm_start_ibss(struct ieee80211_hw *hw,
2920 struct ieee80211_vif *vif)
2922 return iwl_mvm_start_ap_ibss(hw, vif, &vif->bss_conf);
2925 /* Common part for MLD and non-MLD ops */
2926 void iwl_mvm_stop_ap_ibss_common(struct iwl_mvm *mvm,
2927 struct ieee80211_vif *vif)
2929 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2931 lockdep_assert_held(&mvm->mutex);
2933 iwl_mvm_prepare_mac_removal(mvm, vif);
2935 /* Handle AP stop while in CSA */
2936 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2937 iwl_mvm_remove_time_event(mvm, mvmvif,
2938 &mvmvif->time_event_data);
2939 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2940 mvmvif->csa_countdown = false;
2943 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2944 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2945 mvm->csa_tx_block_bcn_timeout = 0;
2948 mvmvif->ap_ibss_active = false;
2949 mvm->ap_last_beacon_gp2 = 0;
2951 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2952 iwl_mvm_vif_set_low_latency(mvmvif, false,
2953 LOW_LATENCY_VIF_TYPE);
2954 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2957 iwl_mvm_bt_coex_vif_change(mvm);
2960 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2961 struct ieee80211_vif *vif,
2962 struct ieee80211_bss_conf *link_conf)
2964 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2966 mutex_lock(&mvm->mutex);
2968 iwl_mvm_stop_ap_ibss_common(mvm, vif);
2970 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2971 if (vif->p2p && mvm->p2p_device_vif)
2972 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2974 iwl_mvm_update_quotas(mvm, false, NULL);
2976 iwl_mvm_ftm_responder_clear(mvm, vif);
2979 * This is not very nice, but the simplest:
2980 * For older FWs removing the mcast sta before the bcast station may
2981 * cause assert 0x2b00.
2982 * This is fixed in later FW (which will stop beaconing when removing
2984 * So make the order of removal depend on the TLV
2986 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2987 iwl_mvm_rm_mcast_sta(mvm, vif);
2988 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2989 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2990 iwl_mvm_rm_mcast_sta(mvm, vif);
2991 iwl_mvm_binding_remove_vif(mvm, vif);
2993 iwl_mvm_power_update_mac(mvm);
2995 iwl_mvm_mac_ctxt_remove(mvm, vif);
2997 mutex_unlock(&mvm->mutex);
3000 static void iwl_mvm_stop_ap(struct ieee80211_hw *hw,
3001 struct ieee80211_vif *vif,
3002 struct ieee80211_bss_conf *link_conf)
3004 iwl_mvm_stop_ap_ibss(hw, vif, link_conf);
3007 static void iwl_mvm_stop_ibss(struct ieee80211_hw *hw,
3008 struct ieee80211_vif *vif)
3010 iwl_mvm_stop_ap_ibss(hw, vif, &vif->bss_conf);
3014 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
3015 struct ieee80211_vif *vif,
3016 struct ieee80211_bss_conf *bss_conf,
3019 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3021 /* Changes will be applied when the AP/IBSS is started */
3022 if (!mvmvif->ap_ibss_active)
3025 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
3026 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
3027 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
3028 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
3030 /* Need to send a new beacon template to the FW */
3031 if (changes & BSS_CHANGED_BEACON &&
3032 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, &vif->bss_conf))
3033 IWL_WARN(mvm, "Failed updating beacon data\n");
3035 if (changes & BSS_CHANGED_FTM_RESPONDER) {
3036 int ret = iwl_mvm_ftm_start_responder(mvm, vif, &vif->bss_conf);
3039 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
3045 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
3046 struct ieee80211_vif *vif,
3047 struct ieee80211_bss_conf *bss_conf,
3050 static const struct iwl_mvm_bss_info_changed_ops callbacks = {
3051 .bss_info_changed_sta = iwl_mvm_bss_info_changed_station,
3052 .bss_info_changed_ap_ibss = iwl_mvm_bss_info_changed_ap_ibss,
3055 iwl_mvm_bss_info_changed_common(hw, vif, bss_conf, &callbacks,
3060 iwl_mvm_bss_info_changed_common(struct ieee80211_hw *hw,
3061 struct ieee80211_vif *vif,
3062 struct ieee80211_bss_conf *bss_conf,
3063 const struct iwl_mvm_bss_info_changed_ops *callbacks,
3066 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3068 mutex_lock(&mvm->mutex);
3070 if (changes & BSS_CHANGED_IDLE && !vif->cfg.idle)
3071 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
3073 switch (vif->type) {
3074 case NL80211_IFTYPE_STATION:
3075 callbacks->bss_info_changed_sta(mvm, vif, bss_conf, changes);
3077 case NL80211_IFTYPE_AP:
3078 case NL80211_IFTYPE_ADHOC:
3079 callbacks->bss_info_changed_ap_ibss(mvm, vif, bss_conf,
3082 case NL80211_IFTYPE_MONITOR:
3083 if (changes & BSS_CHANGED_MU_GROUPS)
3084 iwl_mvm_update_mu_groups(mvm, vif);
3087 /* shouldn't happen */
3091 if (changes & BSS_CHANGED_TXPOWER) {
3092 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n",
3094 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
3097 mutex_unlock(&mvm->mutex);
3100 int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3101 struct ieee80211_scan_request *hw_req)
3103 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3106 if (hw_req->req.n_channels == 0 ||
3107 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
3110 mutex_lock(&mvm->mutex);
3111 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
3112 mutex_unlock(&mvm->mutex);
3117 void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
3118 struct ieee80211_vif *vif)
3120 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3122 mutex_lock(&mvm->mutex);
3124 /* Due to a race condition, it's possible that mac80211 asks
3125 * us to stop a hw_scan when it's already stopped. This can
3126 * happen, for instance, if we stopped the scan ourselves,
3127 * called ieee80211_scan_completed() and the userspace called
3128 * cancel scan scan before ieee80211_scan_work() could run.
3129 * To handle that, simply return if the scan is not running.
3131 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
3132 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
3134 mutex_unlock(&mvm->mutex);
3138 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
3139 struct ieee80211_sta *sta, u16 tids,
3141 enum ieee80211_frame_release_type reason,
3144 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3146 /* Called when we need to transmit (a) frame(s) from mac80211 */
3148 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
3149 tids, more_data, false);
3153 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
3154 struct ieee80211_sta *sta, u16 tids,
3156 enum ieee80211_frame_release_type reason,
3159 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3161 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
3163 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
3164 tids, more_data, true);
3167 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
3168 enum sta_notify_cmd cmd,
3169 struct ieee80211_sta *sta)
3171 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3172 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3173 unsigned long txqs = 0, tids = 0;
3177 * If we have TVQM then we get too high queue numbers - luckily
3178 * we really shouldn't get here with that because such hardware
3179 * should have firmware supporting buffer station offload.
3181 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
3184 spin_lock_bh(&mvmsta->lock);
3185 for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) {
3186 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
3188 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
3191 __set_bit(tid_data->txq_id, &txqs);
3193 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
3196 __set_bit(tid, &tids);
3200 case STA_NOTIFY_SLEEP:
3201 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
3202 ieee80211_sta_set_buffered(sta, tid, true);
3205 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
3207 * The fw updates the STA to be asleep. Tx packets on the Tx
3208 * queues to this station will not be transmitted. The fw will
3209 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
3212 case STA_NOTIFY_AWAKE:
3213 if (WARN_ON(mvmsta->deflink.sta_id == IWL_MVM_INVALID_STA))
3217 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
3218 iwl_mvm_sta_modify_ps_wake(mvm, sta);
3223 spin_unlock_bh(&mvmsta->lock);
3226 void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3227 enum sta_notify_cmd cmd, struct ieee80211_sta *sta)
3229 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
3232 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
3234 struct iwl_rx_packet *pkt = rxb_addr(rxb);
3235 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
3236 struct ieee80211_sta *sta;
3237 struct iwl_mvm_sta *mvmsta;
3238 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
3240 if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations))
3244 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
3245 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
3250 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3253 mvmsta->vif->type != NL80211_IFTYPE_AP) {
3258 if (mvmsta->sleeping != sleeping) {
3259 mvmsta->sleeping = sleeping;
3260 __iwl_mvm_mac_sta_notify(mvm->hw,
3261 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
3263 ieee80211_sta_ps_transition(sta, sleeping);
3267 switch (notif->type) {
3268 case IWL_MVM_PM_EVENT_AWAKE:
3269 case IWL_MVM_PM_EVENT_ASLEEP:
3271 case IWL_MVM_PM_EVENT_UAPSD:
3272 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
3274 case IWL_MVM_PM_EVENT_PS_POLL:
3275 ieee80211_sta_pspoll(sta);
3285 void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
3286 struct ieee80211_vif *vif,
3287 struct ieee80211_sta *sta)
3289 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3290 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3291 unsigned int link_id;
3294 * This is called before mac80211 does RCU synchronisation,
3295 * so here we already invalidate our internal RCU-protected
3296 * station pointer. The rest of the code will thus no longer
3297 * be able to find the station this way, and we don't rely
3298 * on further RCU synchronisation after the sta_state()
3299 * callback deleted the station.
3300 * Since there's mvm->mutex here, no need to have RCU lock for
3301 * mvm_sta->link access.
3303 mutex_lock(&mvm->mutex);
3304 for (link_id = 0; link_id < ARRAY_SIZE(mvm_sta->link); link_id++) {
3305 struct iwl_mvm_link_sta *link_sta;
3308 if (!mvm_sta->link[link_id])
3311 link_sta = rcu_dereference_protected(mvm_sta->link[link_id],
3312 lockdep_is_held(&mvm->mutex));
3313 sta_id = link_sta->sta_id;
3314 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[sta_id])) {
3315 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id],
3317 RCU_INIT_POINTER(mvm->fw_id_to_link_sta[sta_id], NULL);
3320 mutex_unlock(&mvm->mutex);
3323 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3328 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
3329 struct iwl_mvm_tcm_mac *mdata;
3331 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
3332 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
3333 mdata->opened_rx_ba_sessions = false;
3336 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
3339 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
3340 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3345 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
3346 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3350 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
3351 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
3352 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
3357 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
3361 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
3362 struct ieee80211_vif *vif, u8 *peer_addr,
3363 enum nl80211_tdls_operation action)
3365 struct iwl_fw_dbg_trigger_tlv *trig;
3366 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
3368 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
3369 FW_DBG_TRIGGER_TDLS);
3373 tdls_trig = (void *)trig->data;
3375 if (!(tdls_trig->action_bitmap & BIT(action)))
3378 if (tdls_trig->peer_mode &&
3379 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
3382 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
3383 "TDLS event occurred, peer %pM, action %d",
3387 struct iwl_mvm_he_obss_narrow_bw_ru_data {
3391 static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy,
3392 struct cfg80211_bss *bss,
3395 struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data;
3396 const struct cfg80211_bss_ies *ies;
3397 const struct element *elem;
3400 ies = rcu_dereference(bss->ies);
3401 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data,
3404 if (!elem || elem->datalen < 10 ||
3406 WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) {
3407 data->tolerated = false;
3413 iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw,
3414 struct ieee80211_vif *vif,
3415 unsigned int link_id,
3416 struct ieee80211_bss_conf *link_conf)
3418 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3419 struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = {
3423 if (WARN_ON_ONCE(!link_conf->chandef.chan ||
3424 !mvmvif->link[link_id]))
3427 if (!(link_conf->chandef.chan->flags & IEEE80211_CHAN_RADAR)) {
3428 mvmvif->link[link_id]->he_ru_2mhz_block = false;
3432 cfg80211_bss_iter(hw->wiphy, &link_conf->chandef,
3433 iwl_mvm_check_he_obss_narrow_bw_ru_iter,
3437 * If there is at least one AP on radar channel that cannot
3438 * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
3440 mvmvif->link[link_id]->he_ru_2mhz_block = !iter_data.tolerated;
3443 static void iwl_mvm_reset_cca_40mhz_workaround(struct iwl_mvm *mvm,
3444 struct ieee80211_vif *vif)
3446 struct ieee80211_supported_band *sband;
3447 const struct ieee80211_sta_he_cap *he_cap;
3449 if (vif->type != NL80211_IFTYPE_STATION)
3452 if (!mvm->cca_40mhz_workaround)
3455 /* decrement and check that we reached zero */
3456 mvm->cca_40mhz_workaround--;
3457 if (mvm->cca_40mhz_workaround)
3460 sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ];
3462 sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3464 he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif);
3467 /* we know that ours is writable */
3468 struct ieee80211_sta_he_cap *he = (void *)(uintptr_t)he_cap;
3470 he->he_cap_elem.phy_cap_info[0] |=
3471 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
3475 static void iwl_mvm_mei_host_associated(struct iwl_mvm *mvm,
3476 struct ieee80211_vif *vif,
3477 struct iwl_mvm_sta *mvm_sta)
3479 #if IS_ENABLED(CONFIG_IWLMEI)
3480 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3481 struct iwl_mei_conn_info conn_info = {
3482 .ssid_len = vif->cfg.ssid_len,
3485 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3488 if (!mvm->mei_registered)
3491 /* FIXME: MEI needs to be updated for MLO */
3492 if (!vif->bss_conf.chandef.chan)
3495 conn_info.channel = vif->bss_conf.chandef.chan->hw_value;
3497 switch (mvm_sta->pairwise_cipher) {
3498 case WLAN_CIPHER_SUITE_TKIP:
3499 conn_info.pairwise_cipher = IWL_MEI_CIPHER_TKIP;
3501 case WLAN_CIPHER_SUITE_CCMP:
3502 conn_info.pairwise_cipher = IWL_MEI_CIPHER_CCMP;
3504 case WLAN_CIPHER_SUITE_GCMP:
3505 conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP;
3507 case WLAN_CIPHER_SUITE_GCMP_256:
3508 conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP_256;
3514 /* cipher not supported, don't send anything to iwlmei */
3518 switch (mvmvif->rekey_data.akm) {
3519 case WLAN_AKM_SUITE_SAE & 0xff:
3520 conn_info.auth_mode = IWL_MEI_AKM_AUTH_SAE;
3522 case WLAN_AKM_SUITE_PSK & 0xff:
3523 conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA_PSK;
3525 case WLAN_AKM_SUITE_8021X & 0xff:
3526 conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA;
3530 conn_info.auth_mode = IWL_MEI_AKM_AUTH_OPEN;
3533 /* auth method / AKM not supported */
3534 /* TODO: All the FT vesions of these? */
3538 memcpy(conn_info.ssid, vif->cfg.ssid, vif->cfg.ssid_len);
3539 memcpy(conn_info.bssid, vif->bss_conf.bssid, ETH_ALEN);
3541 /* TODO: add support for collocated AP data */
3542 iwl_mei_host_associated(&conn_info, NULL);
3546 static int iwl_mvm_mac_ctxt_changed_wrapper(struct iwl_mvm *mvm,
3547 struct ieee80211_vif *vif,
3548 bool force_assoc_off)
3550 return iwl_mvm_mac_ctxt_changed(mvm, vif, force_assoc_off, NULL);
3553 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
3554 struct ieee80211_vif *vif,
3555 struct ieee80211_sta *sta,
3556 enum ieee80211_sta_state old_state,
3557 enum ieee80211_sta_state new_state)
3559 static const struct iwl_mvm_sta_state_ops callbacks = {
3560 .add_sta = iwl_mvm_add_sta,
3561 .update_sta = iwl_mvm_update_sta,
3562 .rm_sta = iwl_mvm_rm_sta,
3563 .mac_ctxt_changed = iwl_mvm_mac_ctxt_changed_wrapper,
3566 return iwl_mvm_mac_sta_state_common(hw, vif, sta, old_state, new_state,
3570 /* FIXME: temporary making two assumptions in all sta handling functions:
3571 * (1) when setting sta state, the link exists and protected
3572 * (2) if a link is valid in sta then it's valid in vif (can
3573 * use same index in the link array)
3575 static void iwl_mvm_rs_rate_init_all_links(struct iwl_mvm *mvm,
3576 struct ieee80211_vif *vif,
3577 struct ieee80211_sta *sta)
3579 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3580 unsigned int link_id;
3582 for_each_mvm_vif_valid_link(mvmvif, link_id) {
3583 struct ieee80211_bss_conf *conf =
3584 link_conf_dereference_check(vif, link_id);
3585 struct ieee80211_link_sta *link_sta =
3586 link_sta_dereference_check(sta, link_id);
3588 if (!conf || !link_sta || !mvmvif->link[link_id]->phy_ctxt)
3591 iwl_mvm_rs_rate_init(mvm, vif, sta, conf, link_sta,
3592 mvmvif->link[link_id]->phy_ctxt->channel->band);
3596 #define IWL_MVM_MIN_BEACON_INTERVAL_TU 16
3598 static bool iwl_mvm_vif_conf_from_sta(struct iwl_mvm *mvm,
3599 struct ieee80211_vif *vif,
3600 struct ieee80211_sta *sta)
3602 struct ieee80211_link_sta *link_sta;
3603 unsigned int link_id;
3605 /* Beacon interval check - firmware will crash if the beacon
3606 * interval is less than 16. We can't avoid connecting at all,
3607 * so refuse the station state change, this will cause mac80211
3608 * to abandon attempts to connect to this AP, and eventually
3609 * wpa_s will blocklist the AP...
3612 for_each_sta_active_link(vif, sta, link_sta, link_id) {
3613 struct ieee80211_bss_conf *link_conf =
3614 link_conf_dereference_protected(vif, link_id);
3619 if (link_conf->beacon_int < IWL_MVM_MIN_BEACON_INTERVAL_TU) {
3621 "Beacon interval %d for AP %pM is too small\n",
3622 link_conf->beacon_int, link_sta->addr);
3626 link_conf->he_support = link_sta->he_cap.has_he;
3632 static void iwl_mvm_vif_set_he_support(struct ieee80211_hw *hw,
3633 struct ieee80211_vif *vif,
3634 struct ieee80211_sta *sta,
3637 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3638 struct ieee80211_link_sta *link_sta;
3639 unsigned int link_id;
3641 for_each_sta_active_link(vif, sta, link_sta, link_id) {
3642 struct ieee80211_bss_conf *link_conf =
3643 link_conf_dereference_protected(vif, link_id);
3645 if (!link_conf || !mvmvif->link[link_id])
3648 link_conf->he_support = link_sta->he_cap.has_he;
3651 mvmvif->link[link_id]->he_ru_2mhz_block = false;
3652 if (link_sta->he_cap.has_he)
3653 iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif,
3661 iwl_mvm_sta_state_notexist_to_none(struct iwl_mvm *mvm,
3662 struct ieee80211_vif *vif,
3663 struct ieee80211_sta *sta,
3664 const struct iwl_mvm_sta_state_ops *callbacks)
3666 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3667 struct ieee80211_link_sta *link_sta;
3671 lockdep_assert_held(&mvm->mutex);
3673 if (vif->type == NL80211_IFTYPE_STATION &&
3674 !iwl_mvm_vif_conf_from_sta(mvm, vif, sta))
3679 iwl_mvm_tdls_sta_count(mvm, NULL) == IWL_MVM_TDLS_STA_COUNT ||
3680 iwl_mvm_phy_ctx_count(mvm) > 1)) {
3681 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
3685 ret = callbacks->add_sta(mvm, vif, sta);
3686 if (sta->tdls && ret == 0) {
3687 iwl_mvm_recalc_tdls_state(mvm, vif, true);
3688 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3689 NL80211_TDLS_SETUP);
3692 for_each_sta_active_link(vif, sta, link_sta, i)
3693 link_sta->agg.max_rc_amsdu_len = 1;
3695 ieee80211_sta_recalc_aggregates(sta);
3697 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
3698 mvmvif->ap_sta = sta;
3704 iwl_mvm_sta_state_auth_to_assoc(struct ieee80211_hw *hw,
3705 struct iwl_mvm *mvm,
3706 struct ieee80211_vif *vif,
3707 struct ieee80211_sta *sta,
3708 const struct iwl_mvm_sta_state_ops *callbacks)
3710 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3711 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3712 struct ieee80211_link_sta *link_sta;
3713 unsigned int link_id;
3715 lockdep_assert_held(&mvm->mutex);
3717 if (vif->type == NL80211_IFTYPE_AP) {
3718 iwl_mvm_vif_set_he_support(hw, vif, sta, false);
3719 mvmvif->ap_assoc_sta_count++;
3720 callbacks->mac_ctxt_changed(mvm, vif, false);
3722 /* since the below is not for MLD API, it's ok to use
3723 * the default bss_conf
3725 if (!mvm->mld_api_is_used &&
3726 ((vif->bss_conf.he_support &&
3727 !iwlwifi_mod_params.disable_11ax) ||
3728 (vif->bss_conf.eht_support &&
3729 !iwlwifi_mod_params.disable_11be)))
3730 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->deflink.sta_id);
3731 } else if (vif->type == NL80211_IFTYPE_STATION) {
3732 iwl_mvm_vif_set_he_support(hw, vif, sta, true);
3734 callbacks->mac_ctxt_changed(mvm, vif, false);
3736 if (!mvm->mld_api_is_used)
3739 for_each_sta_active_link(vif, sta, link_sta, link_id) {
3740 struct ieee80211_bss_conf *link_conf =
3741 link_conf_dereference_protected(vif, link_id);
3743 if (WARN_ON(!link_conf))
3745 if (!mvmvif->link[link_id])
3748 iwl_mvm_link_changed(mvm, vif, link_conf,
3749 LINK_CONTEXT_MODIFY_ALL &
3750 ~LINK_CONTEXT_MODIFY_ACTIVE,
3756 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta);
3758 return callbacks->update_sta(mvm, vif, sta);
3762 iwl_mvm_sta_state_assoc_to_authorized(struct iwl_mvm *mvm,
3763 struct ieee80211_vif *vif,
3764 struct ieee80211_sta *sta,
3765 const struct iwl_mvm_sta_state_ops *callbacks)
3767 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3768 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3770 lockdep_assert_held(&mvm->mutex);
3772 /* we don't support TDLS during DCM */
3773 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3774 iwl_mvm_teardown_tdls_peers(mvm);
3777 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3778 NL80211_TDLS_ENABLE_LINK);
3780 /* enable beacon filtering */
3781 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
3783 mvmvif->authorized = 1;
3785 callbacks->mac_ctxt_changed(mvm, vif, false);
3786 iwl_mvm_mei_host_associated(mvm, vif, mvm_sta);
3789 mvm_sta->authorized = true;
3791 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta);
3797 iwl_mvm_sta_state_authorized_to_assoc(struct iwl_mvm *mvm,
3798 struct ieee80211_vif *vif,
3799 struct ieee80211_sta *sta,
3800 const struct iwl_mvm_sta_state_ops *callbacks)
3802 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3803 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3805 lockdep_assert_held(&mvm->mutex);
3807 mvmsta->authorized = false;
3809 /* once we move into assoc state, need to update rate scale to
3810 * disable using wide bandwidth
3812 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta);
3815 /* Set this but don't call iwl_mvm_mac_ctxt_changed()
3816 * yet to avoid sending high prio again for a little
3819 mvmvif->authorized = 0;
3821 /* disable beacon filtering */
3822 iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3828 /* Common part for MLD and non-MLD modes */
3829 int iwl_mvm_mac_sta_state_common(struct ieee80211_hw *hw,
3830 struct ieee80211_vif *vif,
3831 struct ieee80211_sta *sta,
3832 enum ieee80211_sta_state old_state,
3833 enum ieee80211_sta_state new_state,
3834 const struct iwl_mvm_sta_state_ops *callbacks)
3836 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3837 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3838 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3839 unsigned int link_id;
3842 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
3843 sta->addr, old_state, new_state);
3846 * If we are in a STA removal flow and in DQA mode:
3848 * This is after the sync_rcu part, so the queues have already been
3849 * flushed. No more TXs on their way in mac80211's path, and no more in
3851 * Also, we won't be getting any new TX frames for this station.
3852 * What we might have are deferred TX frames that need to be taken care
3855 * Drop any still-queued deferred-frame before removing the STA, and
3856 * make sure the worker is no longer handling frames for this STA.
3858 if (old_state == IEEE80211_STA_NONE &&
3859 new_state == IEEE80211_STA_NOTEXIST) {
3860 flush_work(&mvm->add_stream_wk);
3863 * No need to make sure deferred TX indication is off since the
3864 * worker will already remove it if it was on
3868 * Additionally, reset the 40 MHz capability if we disconnected
3871 iwl_mvm_reset_cca_40mhz_workaround(mvm, vif);
3873 /* Also free dup data just in case any assertions below fail */
3874 kfree(mvm_sta->dup_data);
3877 mutex_lock(&mvm->mutex);
3879 /* this would be a mac80211 bug ... but don't crash */
3880 for_each_mvm_vif_valid_link(mvmvif, link_id) {
3881 if (WARN_ON_ONCE(!mvmvif->link[link_id]->phy_ctxt)) {
3882 mutex_unlock(&mvm->mutex);
3883 return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3884 &mvm->status) ? 0 : -EINVAL;
3888 /* track whether or not the station is associated */
3889 mvm_sta->sta_state = new_state;
3891 if (old_state == IEEE80211_STA_NOTEXIST &&
3892 new_state == IEEE80211_STA_NONE) {
3893 ret = iwl_mvm_sta_state_notexist_to_none(mvm, vif, sta,
3897 } else if (old_state == IEEE80211_STA_NONE &&
3898 new_state == IEEE80211_STA_AUTH) {
3900 * EBS may be disabled due to previous failures reported by FW.
3901 * Reset EBS status here assuming environment has been changed.
3903 mvm->last_ebs_successful = true;
3904 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
3906 } else if (old_state == IEEE80211_STA_AUTH &&
3907 new_state == IEEE80211_STA_ASSOC) {
3908 ret = iwl_mvm_sta_state_auth_to_assoc(hw, mvm, vif, sta,
3910 } else if (old_state == IEEE80211_STA_ASSOC &&
3911 new_state == IEEE80211_STA_AUTHORIZED) {
3912 ret = iwl_mvm_sta_state_assoc_to_authorized(mvm, vif, sta,
3914 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3915 new_state == IEEE80211_STA_ASSOC) {
3916 ret = iwl_mvm_sta_state_authorized_to_assoc(mvm, vif, sta,
3918 } else if (old_state == IEEE80211_STA_ASSOC &&
3919 new_state == IEEE80211_STA_AUTH) {
3920 if (vif->type == NL80211_IFTYPE_AP) {
3921 mvmvif->ap_assoc_sta_count--;
3922 callbacks->mac_ctxt_changed(mvm, vif, false);
3923 } else if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
3924 iwl_mvm_stop_session_protection(mvm, vif);
3926 } else if (old_state == IEEE80211_STA_AUTH &&
3927 new_state == IEEE80211_STA_NONE) {
3929 } else if (old_state == IEEE80211_STA_NONE &&
3930 new_state == IEEE80211_STA_NOTEXIST) {
3931 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) {
3932 iwl_mvm_stop_session_protection(mvm, vif);
3933 mvmvif->ap_sta = NULL;
3935 ret = callbacks->rm_sta(mvm, vif, sta);
3937 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3938 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3939 NL80211_TDLS_DISABLE_LINK);
3943 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3950 mutex_unlock(&mvm->mutex);
3952 if (sta->tdls && ret == 0) {
3953 if (old_state == IEEE80211_STA_NOTEXIST &&
3954 new_state == IEEE80211_STA_NONE)
3955 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3956 else if (old_state == IEEE80211_STA_NONE &&
3957 new_state == IEEE80211_STA_NOTEXIST)
3958 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3964 int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3966 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3968 mvm->rts_threshold = value;
3973 void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3974 struct ieee80211_sta *sta, u32 changed)
3976 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3978 if (changed & (IEEE80211_RC_BW_CHANGED |
3979 IEEE80211_RC_SUPP_RATES_CHANGED |
3980 IEEE80211_RC_NSS_CHANGED))
3981 iwl_mvm_rs_rate_init_all_links(mvm, vif, sta);
3983 if (vif->type == NL80211_IFTYPE_STATION &&
3984 changed & IEEE80211_RC_NSS_CHANGED)
3985 iwl_mvm_sf_update(mvm, vif, false);
3988 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3989 struct ieee80211_vif *vif,
3990 unsigned int link_id, u16 ac,
3991 const struct ieee80211_tx_queue_params *params)
3993 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3994 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3996 mvmvif->deflink.queue_params[ac] = *params;
3999 * No need to update right away, we'll get BSS_CHANGED_QOS
4000 * The exception is P2P_DEVICE interface which needs immediate update.
4002 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
4005 mutex_lock(&mvm->mutex);
4006 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4007 mutex_unlock(&mvm->mutex);
4013 void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
4014 struct ieee80211_vif *vif,
4015 struct ieee80211_prep_tx_info *info)
4017 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4019 mutex_lock(&mvm->mutex);
4020 iwl_mvm_protect_assoc(mvm, vif, info->duration);
4021 mutex_unlock(&mvm->mutex);
4024 void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw,
4025 struct ieee80211_vif *vif,
4026 struct ieee80211_prep_tx_info *info)
4028 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4030 /* for successful cases (auth/assoc), don't cancel session protection */
4034 mutex_lock(&mvm->mutex);
4035 iwl_mvm_stop_session_protection(mvm, vif);
4036 mutex_unlock(&mvm->mutex);
4039 int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
4040 struct ieee80211_vif *vif,
4041 struct cfg80211_sched_scan_request *req,
4042 struct ieee80211_scan_ies *ies)
4044 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4048 mutex_lock(&mvm->mutex);
4050 if (!vif->cfg.idle) {
4055 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
4058 mutex_unlock(&mvm->mutex);
4062 int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
4063 struct ieee80211_vif *vif)
4065 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4068 mutex_lock(&mvm->mutex);
4070 /* Due to a race condition, it's possible that mac80211 asks
4071 * us to stop a sched_scan when it's already stopped. This
4072 * can happen, for instance, if we stopped the scan ourselves,
4073 * called ieee80211_sched_scan_stopped() and the userspace called
4074 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
4075 * could run. To handle this, simply return if the scan is
4078 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
4079 mutex_unlock(&mvm->mutex);
4083 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
4084 mutex_unlock(&mvm->mutex);
4085 iwl_mvm_wait_for_async_handlers(mvm);
4090 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
4091 enum set_key_cmd cmd,
4092 struct ieee80211_vif *vif,
4093 struct ieee80211_sta *sta,
4094 struct ieee80211_key_conf *key)
4096 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4097 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4098 struct iwl_mvm_sta *mvmsta = NULL;
4099 struct iwl_mvm_key_pn *ptk_pn = NULL;
4100 int keyidx = key->keyidx;
4101 u32 sec_key_id = WIDE_ID(DATA_PATH_GROUP, SEC_KEY_CMD);
4102 u8 sec_key_ver = iwl_fw_lookup_cmd_ver(mvm->fw, sec_key_id, 0);
4107 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4109 switch (key->cipher) {
4110 case WLAN_CIPHER_SUITE_TKIP:
4111 if (!mvm->trans->trans_cfg->gen2) {
4112 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
4113 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
4114 } else if (vif->type == NL80211_IFTYPE_STATION) {
4115 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
4117 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
4121 case WLAN_CIPHER_SUITE_CCMP:
4122 case WLAN_CIPHER_SUITE_GCMP:
4123 case WLAN_CIPHER_SUITE_GCMP_256:
4124 if (!iwl_mvm_has_new_tx_api(mvm))
4125 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
4127 case WLAN_CIPHER_SUITE_AES_CMAC:
4128 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
4129 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
4130 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
4132 case WLAN_CIPHER_SUITE_WEP40:
4133 case WLAN_CIPHER_SUITE_WEP104:
4134 if (vif->type == NL80211_IFTYPE_STATION)
4136 if (iwl_mvm_has_new_tx_api(mvm))
4138 /* support HW crypto on TX */
4146 if (vif->type == NL80211_IFTYPE_STATION &&
4147 (keyidx == 6 || keyidx == 7))
4148 rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6],
4151 if ((vif->type == NL80211_IFTYPE_ADHOC ||
4152 vif->type == NL80211_IFTYPE_AP) && !sta) {
4154 * GTK on AP interface is a TX-only key, return 0;
4155 * on IBSS they're per-station and because we're lazy
4156 * we don't support them for RX, so do the same.
4157 * CMAC/GMAC in AP/IBSS modes must be done in software.
4159 * Except, of course, beacon protection - it must be
4160 * offloaded since we just set a beacon template.
4163 (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
4164 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
4165 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)) {
4170 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
4171 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
4172 !iwl_mvm_has_new_tx_api(mvm)) {
4173 key->hw_key_idx = STA_KEY_IDX_INVALID;
4178 if (!mvmvif->ap_ibss_active) {
4180 i < ARRAY_SIZE(mvmvif->ap_early_keys);
4182 if (!mvmvif->ap_early_keys[i]) {
4183 mvmvif->ap_early_keys[i] = key;
4188 if (i >= ARRAY_SIZE(mvmvif->ap_early_keys))
4197 /* During FW restart, in order to restore the state as it was,
4198 * don't try to reprogram keys we previously failed for.
4200 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
4201 key->hw_key_idx == STA_KEY_IDX_INVALID) {
4202 IWL_DEBUG_MAC80211(mvm,
4203 "skip invalid idx key programming during restart\n");
4208 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
4209 mvmsta && iwl_mvm_has_new_rx_api(mvm) &&
4210 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
4211 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
4212 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
4213 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
4214 struct ieee80211_key_seq seq;
4217 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
4218 ptk_pn = kzalloc(struct_size(ptk_pn, q,
4219 mvm->trans->num_rx_queues),
4226 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
4227 ieee80211_get_key_rx_seq(key, tid, &seq);
4228 for (q = 0; q < mvm->trans->num_rx_queues; q++)
4229 memcpy(ptk_pn->q[q].pn[tid],
4231 IEEE80211_CCMP_PN_LEN);
4234 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
4237 /* in HW restart reuse the index, otherwise request a new one */
4238 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
4239 key_offset = key->hw_key_idx;
4241 key_offset = STA_KEY_IDX_INVALID;
4243 if (mvmsta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
4244 mvmsta->pairwise_cipher = key->cipher;
4246 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key (sta:%pM, id:%d)\n",
4247 sta ? sta->addr : NULL, key->keyidx);
4250 ret = iwl_mvm_sec_key_add(mvm, vif, sta, key);
4252 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
4255 IWL_WARN(mvm, "set key failed\n");
4256 key->hw_key_idx = STA_KEY_IDX_INVALID;
4258 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
4262 * can't add key for RX, but we don't need it
4263 * in the device for TX so still return 0,
4264 * unless we have new TX API where we cannot
4265 * put key material into the TX_CMD
4267 if (iwl_mvm_has_new_tx_api(mvm))
4275 if (vif->type == NL80211_IFTYPE_STATION &&
4276 (keyidx == 6 || keyidx == 7))
4277 RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6],
4281 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
4282 if (mvmvif->ap_early_keys[i] == key) {
4283 mvmvif->ap_early_keys[i] = NULL;
4288 /* found in pending list - don't do anything else */
4292 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
4297 if (mvmsta && iwl_mvm_has_new_rx_api(mvm) &&
4298 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
4299 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
4300 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
4301 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
4302 ptk_pn = rcu_dereference_protected(
4303 mvmsta->ptk_pn[keyidx],
4304 lockdep_is_held(&mvm->mutex));
4305 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
4307 kfree_rcu(ptk_pn, rcu_head);
4310 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
4312 ret = iwl_mvm_sec_key_del(mvm, vif, sta, key);
4314 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
4323 int iwl_mvm_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
4324 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
4325 struct ieee80211_key_conf *key)
4327 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4330 mutex_lock(&mvm->mutex);
4331 ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key);
4332 mutex_unlock(&mvm->mutex);
4337 void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
4338 struct ieee80211_vif *vif,
4339 struct ieee80211_key_conf *keyconf,
4340 struct ieee80211_sta *sta,
4341 u32 iv32, u16 *phase1key)
4343 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4345 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
4348 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
4352 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
4353 struct iwl_rx_packet *pkt, void *data)
4355 struct iwl_mvm *mvm =
4356 container_of(notif_wait, struct iwl_mvm, notif_wait);
4357 struct iwl_hs20_roc_res *resp;
4358 int resp_len = iwl_rx_packet_payload_len(pkt);
4359 struct iwl_mvm_time_event_data *te_data = data;
4361 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
4364 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
4365 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
4369 resp = (void *)pkt->data;
4372 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
4373 resp->status, resp->event_unique_id);
4375 te_data->uid = le32_to_cpu(resp->event_unique_id);
4376 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
4379 spin_lock_bh(&mvm->time_event_lock);
4380 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
4381 spin_unlock_bh(&mvm->time_event_lock);
4386 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
4387 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
4388 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
4389 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
4390 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
4391 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
4392 struct ieee80211_channel *channel,
4393 struct ieee80211_vif *vif,
4397 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4398 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
4399 static const u16 time_event_response[] = { HOT_SPOT_CMD };
4400 struct iwl_notification_wait wait_time_event;
4401 u32 dtim_interval = vif->bss_conf.dtim_period *
4402 vif->bss_conf.beacon_int;
4404 struct iwl_hs20_roc_req aux_roc_req = {
4405 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
4407 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
4408 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
4410 struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm,
4411 &aux_roc_req.channel_info);
4412 u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm);
4414 /* Set the channel info data */
4415 iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value,
4416 iwl_mvm_phy_band_from_nl80211(channel->band),
4417 IWL_PHY_CHANNEL_MODE20,
4420 /* Set the time and duration */
4421 tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm));
4423 delay = AUX_ROC_MIN_DELAY;
4424 req_dur = MSEC_TO_TU(duration);
4427 * If we are associated we want the delay time to be at least one
4428 * dtim interval so that the FW can wait until after the DTIM and
4429 * then start the time event, this will potentially allow us to
4430 * remain off-channel for the max duration.
4431 * Since we want to use almost a whole dtim interval we would also
4432 * like the delay to be for 2-3 dtim intervals, in case there are
4433 * other time events with higher priority.
4435 if (vif->cfg.assoc) {
4436 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
4437 /* We cannot remain off-channel longer than the DTIM interval */
4438 if (dtim_interval <= req_dur) {
4439 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
4440 if (req_dur <= AUX_ROC_MIN_DURATION)
4441 req_dur = dtim_interval -
4442 AUX_ROC_MIN_SAFETY_BUFFER;
4446 tail->duration = cpu_to_le32(req_dur);
4447 tail->apply_time_max_delay = cpu_to_le32(delay);
4450 "ROC: Requesting to remain on channel %u for %ums\n",
4451 channel->hw_value, req_dur);
4453 "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
4454 duration, delay, dtim_interval);
4456 /* Set the node address */
4457 memcpy(tail->node_addr, vif->addr, ETH_ALEN);
4459 lockdep_assert_held(&mvm->mutex);
4461 spin_lock_bh(&mvm->time_event_lock);
4463 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
4464 spin_unlock_bh(&mvm->time_event_lock);
4469 te_data->duration = duration;
4470 te_data->id = HOT_SPOT_CMD;
4472 spin_unlock_bh(&mvm->time_event_lock);
4475 * Use a notification wait, which really just processes the
4476 * command response and doesn't wait for anything, in order
4477 * to be able to process the response and get the UID inside
4478 * the RX path. Using CMD_WANT_SKB doesn't work because it
4479 * stores the buffer and then wakes up this thread, by which
4480 * time another notification (that the time event started)
4481 * might already be processed unsuccessfully.
4483 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
4484 time_event_response,
4485 ARRAY_SIZE(time_event_response),
4486 iwl_mvm_rx_aux_roc, te_data);
4488 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len,
4492 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
4493 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
4497 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
4498 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
4499 /* should never fail */
4504 spin_lock_bh(&mvm->time_event_lock);
4505 iwl_mvm_te_clear_data(mvm, te_data);
4506 spin_unlock_bh(&mvm->time_event_lock);
4512 static int iwl_mvm_add_aux_sta_for_hs20(struct iwl_mvm *mvm, u32 lmac_id)
4516 lockdep_assert_held(&mvm->mutex);
4518 if (!fw_has_capa(&mvm->fw->ucode_capa,
4519 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
4520 IWL_ERR(mvm, "hotspot not supported\n");
4524 if (iwl_mvm_has_new_station_api(mvm->fw)) {
4525 ret = iwl_mvm_add_aux_sta(mvm, lmac_id);
4526 WARN(ret, "Failed to allocate aux station");
4532 static int iwl_mvm_roc_switch_binding(struct iwl_mvm *mvm,
4533 struct ieee80211_vif *vif,
4534 struct iwl_mvm_phy_ctxt *new_phy_ctxt)
4536 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4539 lockdep_assert_held(&mvm->mutex);
4541 /* Unbind the P2P_DEVICE from the current PHY context,
4542 * and if the PHY context is not used remove it.
4544 ret = iwl_mvm_binding_remove_vif(mvm, vif);
4545 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
4548 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt);
4550 /* Bind the P2P_DEVICE to the current PHY Context */
4551 mvmvif->deflink.phy_ctxt = new_phy_ctxt;
4553 ret = iwl_mvm_binding_add_vif(mvm, vif);
4554 WARN(ret, "Failed binding P2P_DEVICE\n");
4558 static int iwl_mvm_roc(struct ieee80211_hw *hw,
4559 struct ieee80211_vif *vif,
4560 struct ieee80211_channel *channel,
4562 enum ieee80211_roc_type type)
4564 static const struct iwl_mvm_roc_ops ops = {
4565 .add_aux_sta_for_hs20 = iwl_mvm_add_aux_sta_for_hs20,
4566 .switch_phy_ctxt = iwl_mvm_roc_switch_binding,
4569 return iwl_mvm_roc_common(hw, vif, channel, duration, type, &ops);
4572 /* Execute the common part for MLD and non-MLD modes */
4573 int iwl_mvm_roc_common(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
4574 struct ieee80211_channel *channel, int duration,
4575 enum ieee80211_roc_type type,
4576 const struct iwl_mvm_roc_ops *ops)
4578 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4579 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4580 struct cfg80211_chan_def chandef;
4581 struct iwl_mvm_phy_ctxt *phy_ctxt;
4582 bool band_change_removal;
4586 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
4590 * Flush the done work, just in case it's still pending, so that
4591 * the work it does can complete and we can accept new frames.
4593 flush_work(&mvm->roc_done_wk);
4595 mutex_lock(&mvm->mutex);
4597 switch (vif->type) {
4598 case NL80211_IFTYPE_STATION:
4599 lmac_id = iwl_mvm_get_lmac_id(mvm, channel->band);
4601 /* Use aux roc framework (HS20) */
4602 ret = ops->add_aux_sta_for_hs20(mvm, lmac_id);
4604 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
4607 case NL80211_IFTYPE_P2P_DEVICE:
4611 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
4616 for (i = 0; i < NUM_PHY_CTX; i++) {
4617 phy_ctxt = &mvm->phy_ctxts[i];
4618 if (phy_ctxt->ref == 0 || mvmvif->deflink.phy_ctxt == phy_ctxt)
4621 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
4622 ret = ops->switch_phy_ctxt(mvm, vif, phy_ctxt);
4626 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->deflink.phy_ctxt);
4627 goto schedule_time_event;
4631 /* Need to update the PHY context only if the ROC channel changed */
4632 if (channel == mvmvif->deflink.phy_ctxt->channel)
4633 goto schedule_time_event;
4635 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
4638 * Check if the remain-on-channel is on a different band and that
4639 * requires context removal, see iwl_mvm_phy_ctxt_changed(). If
4640 * so, we'll need to release and then re-configure here, since we
4641 * must not remove a PHY context that's part of a binding.
4643 band_change_removal =
4644 fw_has_capa(&mvm->fw->ucode_capa,
4645 IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT) &&
4646 mvmvif->deflink.phy_ctxt->channel->band != chandef.chan->band;
4648 if (mvmvif->deflink.phy_ctxt->ref == 1 && !band_change_removal) {
4650 * Change the PHY context configuration as it is currently
4651 * referenced only by the P2P Device MAC (and we can modify it)
4653 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->deflink.phy_ctxt,
4659 * The PHY context is shared with other MACs (or we're trying to
4660 * switch bands), so remove the P2P Device from the binding,
4661 * allocate an new PHY context and create a new binding.
4663 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
4669 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
4672 IWL_ERR(mvm, "Failed to change PHY context\n");
4676 ret = ops->switch_phy_ctxt(mvm, vif, phy_ctxt);
4680 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->deflink.phy_ctxt);
4683 schedule_time_event:
4684 /* Schedule the time events */
4685 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
4688 mutex_unlock(&mvm->mutex);
4689 IWL_DEBUG_MAC80211(mvm, "leave\n");
4693 int iwl_mvm_cancel_roc(struct ieee80211_hw *hw,
4694 struct ieee80211_vif *vif)
4696 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4698 IWL_DEBUG_MAC80211(mvm, "enter\n");
4700 mutex_lock(&mvm->mutex);
4701 iwl_mvm_stop_roc(mvm, vif);
4702 mutex_unlock(&mvm->mutex);
4704 IWL_DEBUG_MAC80211(mvm, "leave\n");
4708 struct iwl_mvm_ftm_responder_iter_data {
4710 struct ieee80211_chanctx_conf *ctx;
4713 static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac,
4714 struct ieee80211_vif *vif)
4716 struct iwl_mvm_ftm_responder_iter_data *data = _data;
4718 if (rcu_access_pointer(vif->bss_conf.chanctx_conf) == data->ctx &&
4719 vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params)
4720 data->responder = true;
4723 static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm,
4724 struct ieee80211_chanctx_conf *ctx)
4726 struct iwl_mvm_ftm_responder_iter_data data = {
4731 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
4732 IEEE80211_IFACE_ITER_NORMAL,
4733 iwl_mvm_ftm_responder_chanctx_iter,
4735 return data.responder;
4738 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
4739 struct ieee80211_chanctx_conf *ctx)
4741 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4742 struct iwl_mvm_phy_ctxt *phy_ctxt;
4743 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4744 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
4747 lockdep_assert_held(&mvm->mutex);
4749 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
4751 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
4757 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4758 ctx->rx_chains_static,
4759 ctx->rx_chains_dynamic);
4761 IWL_ERR(mvm, "Failed to add PHY context\n");
4765 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
4766 *phy_ctxt_id = phy_ctxt->id;
4771 int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
4772 struct ieee80211_chanctx_conf *ctx)
4774 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4777 mutex_lock(&mvm->mutex);
4778 ret = __iwl_mvm_add_chanctx(mvm, ctx);
4779 mutex_unlock(&mvm->mutex);
4784 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
4785 struct ieee80211_chanctx_conf *ctx)
4787 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4788 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4790 lockdep_assert_held(&mvm->mutex);
4792 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
4795 void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
4796 struct ieee80211_chanctx_conf *ctx)
4798 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4800 mutex_lock(&mvm->mutex);
4801 __iwl_mvm_remove_chanctx(mvm, ctx);
4802 mutex_unlock(&mvm->mutex);
4805 void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
4806 struct ieee80211_chanctx_conf *ctx, u32 changed)
4808 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4809 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4810 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4811 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4812 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
4814 if (WARN_ONCE((phy_ctxt->ref > 1) &&
4815 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
4816 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
4817 IEEE80211_CHANCTX_CHANGE_RADAR |
4818 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
4819 "Cannot change PHY. Ref=%d, changed=0x%X\n",
4820 phy_ctxt->ref, changed))
4823 mutex_lock(&mvm->mutex);
4825 /* we are only changing the min_width, may be a noop */
4826 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
4827 if (phy_ctxt->width == def->width)
4830 /* we are just toggling between 20_NOHT and 20 */
4831 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
4832 def->width <= NL80211_CHAN_WIDTH_20)
4836 iwl_mvm_bt_coex_vif_change(mvm);
4837 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4838 ctx->rx_chains_static,
4839 ctx->rx_chains_dynamic);
4842 mutex_unlock(&mvm->mutex);
4846 * This function executes the common part for MLD and non-MLD modes.
4848 * Returns true if we're done assigning the chanctx
4849 * (either on failure or success)
4852 __iwl_mvm_assign_vif_chanctx_common(struct iwl_mvm *mvm,
4853 struct ieee80211_vif *vif,
4854 struct ieee80211_chanctx_conf *ctx,
4855 bool switching_chanctx, int *ret)
4857 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4858 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4859 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4861 lockdep_assert_held(&mvm->mutex);
4863 mvmvif->deflink.phy_ctxt = phy_ctxt;
4865 switch (vif->type) {
4866 case NL80211_IFTYPE_AP:
4867 /* only needed if we're switching chanctx (i.e. during CSA) */
4868 if (switching_chanctx) {
4869 mvmvif->ap_ibss_active = true;
4873 case NL80211_IFTYPE_ADHOC:
4875 * The AP binding flow is handled as part of the start_ap flow
4876 * (in bss_info_changed), similarly for IBSS.
4880 case NL80211_IFTYPE_STATION:
4882 case NL80211_IFTYPE_MONITOR:
4883 /* always disable PS when a monitor interface is active */
4884 mvmvif->ps_disabled = true;
4893 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
4894 struct ieee80211_vif *vif,
4895 struct ieee80211_bss_conf *link_conf,
4896 struct ieee80211_chanctx_conf *ctx,
4897 bool switching_chanctx)
4899 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4902 if (WARN_ON(!link_conf))
4905 if (__iwl_mvm_assign_vif_chanctx_common(mvm, vif, ctx,
4906 switching_chanctx, &ret))
4909 ret = iwl_mvm_binding_add_vif(mvm, vif);
4914 * Power state must be updated before quotas,
4915 * otherwise fw will complain.
4917 iwl_mvm_power_update_mac(mvm);
4919 /* Setting the quota at this stage is only required for monitor
4920 * interfaces. For the other types, the bss_info changed flow
4921 * will handle quota settings.
4923 if (vif->type == NL80211_IFTYPE_MONITOR) {
4924 mvmvif->monitor_active = true;
4925 ret = iwl_mvm_update_quotas(mvm, false, NULL);
4927 goto out_remove_binding;
4929 ret = iwl_mvm_add_snif_sta(mvm, vif);
4931 goto out_remove_binding;
4935 /* Handle binding during CSA */
4936 if (vif->type == NL80211_IFTYPE_AP) {
4937 iwl_mvm_update_quotas(mvm, false, NULL);
4938 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4941 if (vif->type == NL80211_IFTYPE_STATION) {
4942 if (!switching_chanctx) {
4943 mvmvif->csa_bcn_pending = false;
4947 mvmvif->csa_bcn_pending = true;
4949 if (!fw_has_capa(&mvm->fw->ucode_capa,
4950 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4951 u32 duration = 3 * vif->bss_conf.beacon_int;
4953 /* Protect the session to make sure we hear the first
4954 * beacon on the new channel.
4956 iwl_mvm_protect_session(mvm, vif, duration, duration,
4957 vif->bss_conf.beacon_int / 2,
4961 iwl_mvm_update_quotas(mvm, false, NULL);
4967 iwl_mvm_binding_remove_vif(mvm, vif);
4968 iwl_mvm_power_update_mac(mvm);
4971 mvmvif->deflink.phy_ctxt = NULL;
4975 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
4976 struct ieee80211_vif *vif,
4977 struct ieee80211_bss_conf *link_conf,
4978 struct ieee80211_chanctx_conf *ctx)
4980 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4983 mutex_lock(&mvm->mutex);
4984 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, link_conf, ctx, false);
4985 mutex_unlock(&mvm->mutex);
4991 * This function executes the common part for MLD and non-MLD modes.
4993 * Returns if chanctx unassign chanctx is done
4994 * (either on failure or success)
4996 static bool __iwl_mvm_unassign_vif_chanctx_common(struct iwl_mvm *mvm,
4997 struct ieee80211_vif *vif,
4998 bool switching_chanctx)
5000 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5002 lockdep_assert_held(&mvm->mutex);
5003 iwl_mvm_remove_time_event(mvm, mvmvif,
5004 &mvmvif->time_event_data);
5006 switch (vif->type) {
5007 case NL80211_IFTYPE_ADHOC:
5009 case NL80211_IFTYPE_MONITOR:
5010 mvmvif->monitor_active = false;
5011 mvmvif->ps_disabled = false;
5013 case NL80211_IFTYPE_AP:
5014 /* This part is triggered only during CSA */
5015 if (!switching_chanctx || !mvmvif->ap_ibss_active)
5018 mvmvif->csa_countdown = false;
5020 /* Set CS bit on all the stations */
5021 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
5023 /* Save blocked iface, the timeout is set on the next beacon */
5024 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
5026 mvmvif->ap_ibss_active = false;
5034 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
5035 struct ieee80211_vif *vif,
5036 struct ieee80211_bss_conf *link_conf,
5037 struct ieee80211_chanctx_conf *ctx,
5038 bool switching_chanctx)
5040 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5041 struct ieee80211_vif *disabled_vif = NULL;
5043 if (__iwl_mvm_unassign_vif_chanctx_common(mvm, vif, switching_chanctx))
5046 if (vif->type == NL80211_IFTYPE_MONITOR)
5047 iwl_mvm_rm_snif_sta(mvm, vif);
5050 if (vif->type == NL80211_IFTYPE_STATION && switching_chanctx) {
5052 if (!fw_has_capa(&mvm->fw->ucode_capa,
5053 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
5054 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
5057 iwl_mvm_update_quotas(mvm, false, disabled_vif);
5058 iwl_mvm_binding_remove_vif(mvm, vif);
5061 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD) &&
5064 mvmvif->deflink.phy_ctxt = NULL;
5065 iwl_mvm_power_update_mac(mvm);
5068 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
5069 struct ieee80211_vif *vif,
5070 struct ieee80211_bss_conf *link_conf,
5071 struct ieee80211_chanctx_conf *ctx)
5073 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5075 mutex_lock(&mvm->mutex);
5076 __iwl_mvm_unassign_vif_chanctx(mvm, vif, link_conf, ctx, false);
5077 mutex_unlock(&mvm->mutex);
5081 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
5082 struct ieee80211_vif_chanctx_switch *vifs,
5083 const struct iwl_mvm_switch_vif_chanctx_ops *ops)
5087 mutex_lock(&mvm->mutex);
5088 ops->__unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
5089 vifs[0].old_ctx, true);
5090 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
5092 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
5094 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
5098 ret = ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
5099 vifs[0].new_ctx, true);
5102 "failed to assign new_ctx during channel switch\n");
5106 /* we don't support TDLS during DCM - can be caused by channel switch */
5107 if (iwl_mvm_phy_ctx_count(mvm) > 1)
5108 iwl_mvm_teardown_tdls_peers(mvm);
5113 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
5116 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
5117 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
5121 if (ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
5122 vifs[0].old_ctx, true)) {
5123 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
5130 /* things keep failing, better restart the hw */
5131 iwl_mvm_nic_restart(mvm, false);
5134 mutex_unlock(&mvm->mutex);
5140 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
5141 struct ieee80211_vif_chanctx_switch *vifs,
5142 const struct iwl_mvm_switch_vif_chanctx_ops *ops)
5146 mutex_lock(&mvm->mutex);
5147 ops->__unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
5148 vifs[0].old_ctx, true);
5150 ret = ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
5151 vifs[0].new_ctx, true);
5154 "failed to assign new_ctx during channel switch\n");
5161 if (ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
5162 vifs[0].old_ctx, true)) {
5163 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
5170 /* things keep failing, better restart the hw */
5171 iwl_mvm_nic_restart(mvm, false);
5174 mutex_unlock(&mvm->mutex);
5179 /* Execute the common part for both MLD and non-MLD modes */
5181 iwl_mvm_switch_vif_chanctx_common(struct ieee80211_hw *hw,
5182 struct ieee80211_vif_chanctx_switch *vifs,
5184 enum ieee80211_chanctx_switch_mode mode,
5185 const struct iwl_mvm_switch_vif_chanctx_ops *ops)
5187 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5190 /* we only support a single-vif right now */
5195 case CHANCTX_SWMODE_SWAP_CONTEXTS:
5196 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs, ops);
5198 case CHANCTX_SWMODE_REASSIGN_VIF:
5199 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs, ops);
5209 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
5210 struct ieee80211_vif_chanctx_switch *vifs,
5212 enum ieee80211_chanctx_switch_mode mode)
5214 static const struct iwl_mvm_switch_vif_chanctx_ops ops = {
5215 .__assign_vif_chanctx = __iwl_mvm_assign_vif_chanctx,
5216 .__unassign_vif_chanctx = __iwl_mvm_unassign_vif_chanctx,
5219 return iwl_mvm_switch_vif_chanctx_common(hw, vifs, n_vifs, mode, &ops);
5222 int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
5224 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5226 return mvm->ibss_manager;
5229 int iwl_mvm_set_tim(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
5232 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5233 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
5235 if (!mvm_sta || !mvm_sta->vif) {
5236 IWL_ERR(mvm, "Station is not associated to a vif\n");
5240 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif,
5241 &mvm_sta->vif->bss_conf);
5244 #ifdef CONFIG_NL80211_TESTMODE
5245 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
5246 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
5247 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
5248 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
5251 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
5252 struct ieee80211_vif *vif,
5253 void *data, int len)
5255 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
5259 err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len,
5260 iwl_mvm_tm_policy, NULL);
5264 if (!tb[IWL_MVM_TM_ATTR_CMD])
5267 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
5268 case IWL_MVM_TM_CMD_SET_NOA:
5269 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
5270 !vif->bss_conf.enable_beacon ||
5271 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
5274 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
5275 if (noa_duration >= vif->bss_conf.beacon_int)
5278 mvm->noa_duration = noa_duration;
5281 return iwl_mvm_update_quotas(mvm, true, NULL);
5282 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
5283 /* must be associated client vif - ignore authorized */
5284 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
5285 !vif->cfg.assoc || !vif->bss_conf.dtim_period ||
5286 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
5289 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
5290 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
5291 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
5297 int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
5298 struct ieee80211_vif *vif,
5299 void *data, int len)
5301 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5304 mutex_lock(&mvm->mutex);
5305 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
5306 mutex_unlock(&mvm->mutex);
5312 void iwl_mvm_channel_switch(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5313 struct ieee80211_channel_switch *chsw)
5315 /* By implementing this operation, we prevent mac80211 from
5316 * starting its own channel switch timer, so that we can call
5317 * ieee80211_chswitch_done() ourselves at the right time
5318 * (which is when the absence time event starts).
5321 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
5322 "dummy channel switch op\n");
5325 static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm,
5326 struct ieee80211_vif *vif,
5327 struct ieee80211_channel_switch *chsw)
5329 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5330 struct iwl_chan_switch_te_cmd cmd = {
5331 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
5333 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
5334 .tsf = cpu_to_le32(chsw->timestamp),
5335 .cs_count = chsw->count,
5336 .cs_mode = chsw->block_tx,
5339 lockdep_assert_held(&mvm->mutex);
5342 cmd.cs_delayed_bcn_count =
5343 DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int);
5345 return iwl_mvm_send_cmd_pdu(mvm,
5346 WIDE_ID(MAC_CONF_GROUP,
5347 CHANNEL_SWITCH_TIME_EVENT_CMD),
5348 0, sizeof(cmd), &cmd);
5351 static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm,
5352 struct ieee80211_vif *vif,
5353 struct ieee80211_channel_switch *chsw)
5355 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5358 /* Schedule the time event to a bit before beacon 1,
5359 * to make sure we're in the new channel when the
5360 * GO/AP arrives. In case count <= 1 immediately schedule the
5361 * TE (this might result with some packet loss or connection
5364 if (chsw->count <= 1)
5367 apply_time = chsw->device_timestamp +
5368 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
5369 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
5372 iwl_mvm_csa_client_absent(mvm, vif);
5374 if (mvmvif->bf_data.bf_enabled) {
5375 int ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
5381 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
5387 #define IWL_MAX_CSA_BLOCK_TX 1500
5388 int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
5389 struct ieee80211_vif *vif,
5390 struct ieee80211_channel_switch *chsw)
5392 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5393 struct ieee80211_vif *csa_vif;
5394 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5397 mutex_lock(&mvm->mutex);
5399 mvmvif->csa_failed = false;
5401 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
5402 chsw->chandef.center_freq1);
5404 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
5405 ieee80211_vif_to_wdev(vif),
5406 FW_DBG_TRIGGER_CHANNEL_SWITCH);
5408 switch (vif->type) {
5409 case NL80211_IFTYPE_AP:
5411 rcu_dereference_protected(mvm->csa_vif,
5412 lockdep_is_held(&mvm->mutex));
5413 if (WARN_ONCE(csa_vif && csa_vif->bss_conf.csa_active,
5414 "Another CSA is already in progress")) {
5419 /* we still didn't unblock tx. prevent new CS meanwhile */
5420 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
5421 lockdep_is_held(&mvm->mutex))) {
5426 rcu_assign_pointer(mvm->csa_vif, vif);
5428 if (WARN_ONCE(mvmvif->csa_countdown,
5429 "Previous CSA countdown didn't complete")) {
5434 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
5437 case NL80211_IFTYPE_STATION:
5439 * In the new flow FW is in charge of timing the switch so there
5440 * is no need for all of this
5442 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
5443 CHANNEL_SWITCH_ERROR_NOTIF,
5448 * We haven't configured the firmware to be associated yet since
5449 * we don't know the dtim period. In this case, the firmware can't
5450 * track the beacons.
5452 if (!vif->cfg.assoc || !vif->bss_conf.dtim_period) {
5457 if (chsw->delay > IWL_MAX_CSA_BLOCK_TX)
5458 schedule_delayed_work(&mvmvif->csa_work, 0);
5460 if (chsw->block_tx) {
5462 * In case of undetermined / long time with immediate
5463 * quiet monitor status to gracefully disconnect
5466 chsw->count * vif->bss_conf.beacon_int >
5467 IWL_MAX_CSA_BLOCK_TX)
5468 schedule_delayed_work(&mvmvif->csa_work,
5469 msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX));
5472 if (!fw_has_capa(&mvm->fw->ucode_capa,
5473 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
5474 ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw);
5478 iwl_mvm_schedule_client_csa(mvm, vif, chsw);
5481 mvmvif->csa_count = chsw->count;
5482 mvmvif->csa_misbehave = false;
5488 mvmvif->ps_disabled = true;
5490 ret = iwl_mvm_power_update_ps(mvm);
5494 /* we won't be on this channel any longer */
5495 iwl_mvm_teardown_tdls_peers(mvm);
5498 mutex_unlock(&mvm->mutex);
5503 void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw,
5504 struct ieee80211_vif *vif,
5505 struct ieee80211_channel_switch *chsw)
5507 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5508 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5509 struct iwl_chan_switch_te_cmd cmd = {
5510 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
5512 .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY),
5513 .tsf = cpu_to_le32(chsw->timestamp),
5514 .cs_count = chsw->count,
5515 .cs_mode = chsw->block_tx,
5519 * In the new flow FW is in charge of timing the switch so there is no
5520 * need for all of this
5522 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
5523 CHANNEL_SWITCH_ERROR_NOTIF, 0))
5526 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY))
5529 IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d (old %d) mode = %d\n",
5530 mvmvif->id, chsw->count, mvmvif->csa_count, chsw->block_tx);
5532 if (chsw->count >= mvmvif->csa_count && chsw->block_tx) {
5533 if (mvmvif->csa_misbehave) {
5534 /* Second time, give up on this AP*/
5535 iwl_mvm_abort_channel_switch(hw, vif);
5536 ieee80211_chswitch_done(vif, false);
5537 mvmvif->csa_misbehave = false;
5540 mvmvif->csa_misbehave = true;
5542 mvmvif->csa_count = chsw->count;
5544 mutex_lock(&mvm->mutex);
5545 if (mvmvif->csa_failed)
5548 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
5549 WIDE_ID(MAC_CONF_GROUP,
5550 CHANNEL_SWITCH_TIME_EVENT_CMD),
5551 0, sizeof(cmd), &cmd));
5553 mutex_unlock(&mvm->mutex);
5556 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
5560 if (!iwl_mvm_has_new_tx_api(mvm)) {
5562 mutex_lock(&mvm->mutex);
5563 iwl_mvm_flush_tx_path(mvm,
5564 iwl_mvm_flushable_queues(mvm) & queues);
5565 mutex_unlock(&mvm->mutex);
5567 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
5572 mutex_lock(&mvm->mutex);
5573 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
5574 struct ieee80211_sta *sta;
5576 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
5577 lockdep_is_held(&mvm->mutex));
5578 if (IS_ERR_OR_NULL(sta))
5582 iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF);
5584 iwl_mvm_wait_sta_queues_empty(mvm,
5585 iwl_mvm_sta_from_mac80211(sta));
5587 mutex_unlock(&mvm->mutex);
5590 void iwl_mvm_mac_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5591 u32 queues, bool drop)
5593 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5594 struct iwl_mvm_vif *mvmvif;
5595 struct iwl_mvm_sta *mvmsta;
5596 struct ieee80211_sta *sta;
5597 bool ap_sta_done = false;
5602 iwl_mvm_flush_no_vif(mvm, queues, drop);
5606 if (vif->type != NL80211_IFTYPE_STATION)
5609 /* Make sure we're done with the deferred traffic before flushing */
5610 flush_work(&mvm->add_stream_wk);
5612 mutex_lock(&mvm->mutex);
5613 mvmvif = iwl_mvm_vif_from_mac80211(vif);
5615 /* flush the AP-station and all TDLS peers */
5616 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
5617 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
5618 lockdep_is_held(&mvm->mutex));
5619 if (IS_ERR_OR_NULL(sta))
5622 mvmsta = iwl_mvm_sta_from_mac80211(sta);
5623 if (mvmsta->vif != vif)
5626 if (sta == mvmvif->ap_sta) {
5632 /* make sure only TDLS peers or the AP are flushed */
5633 WARN_ON_ONCE(sta != mvmvif->ap_sta && !sta->tdls);
5636 if (iwl_mvm_flush_sta(mvm, mvmsta, false))
5637 IWL_ERR(mvm, "flush request fail\n");
5639 if (iwl_mvm_has_new_tx_api(mvm))
5640 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
5641 else /* only used for !iwl_mvm_has_new_tx_api() below */
5642 msk |= mvmsta->tfd_queue_msk;
5646 mutex_unlock(&mvm->mutex);
5648 /* this can take a while, and we may need/want other operations
5649 * to succeed while doing this, so do it without the mutex held
5651 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
5652 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
5655 int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
5656 struct survey_info *survey)
5658 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5661 memset(survey, 0, sizeof(*survey));
5663 /* only support global statistics right now */
5667 if (!fw_has_capa(&mvm->fw->ucode_capa,
5668 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
5671 mutex_lock(&mvm->mutex);
5673 if (iwl_mvm_firmware_running(mvm)) {
5674 ret = iwl_mvm_request_statistics(mvm, false);
5679 survey->filled = SURVEY_INFO_TIME |
5680 SURVEY_INFO_TIME_RX |
5681 SURVEY_INFO_TIME_TX |
5682 SURVEY_INFO_TIME_SCAN;
5683 survey->time = mvm->accu_radio_stats.on_time_rf +
5684 mvm->radio_stats.on_time_rf;
5685 do_div(survey->time, USEC_PER_MSEC);
5687 survey->time_rx = mvm->accu_radio_stats.rx_time +
5688 mvm->radio_stats.rx_time;
5689 do_div(survey->time_rx, USEC_PER_MSEC);
5691 survey->time_tx = mvm->accu_radio_stats.tx_time +
5692 mvm->radio_stats.tx_time;
5693 do_div(survey->time_tx, USEC_PER_MSEC);
5695 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
5696 mvm->radio_stats.on_time_scan;
5697 do_div(survey->time_scan, USEC_PER_MSEC);
5701 mutex_unlock(&mvm->mutex);
5705 static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo)
5707 u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
5710 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
5711 case RATE_MCS_CHAN_WIDTH_20:
5712 rinfo->bw = RATE_INFO_BW_20;
5714 case RATE_MCS_CHAN_WIDTH_40:
5715 rinfo->bw = RATE_INFO_BW_40;
5717 case RATE_MCS_CHAN_WIDTH_80:
5718 rinfo->bw = RATE_INFO_BW_80;
5720 case RATE_MCS_CHAN_WIDTH_160:
5721 rinfo->bw = RATE_INFO_BW_160;
5723 case RATE_MCS_CHAN_WIDTH_320:
5724 rinfo->bw = RATE_INFO_BW_320;
5728 if (format == RATE_MCS_CCK_MSK ||
5729 format == RATE_MCS_LEGACY_OFDM_MSK) {
5730 int rate = u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK);
5732 /* add the offset needed to get to the legacy ofdm indices */
5733 if (format == RATE_MCS_LEGACY_OFDM_MSK)
5734 rate += IWL_FIRST_OFDM_RATE;
5737 case IWL_RATE_1M_INDEX:
5740 case IWL_RATE_2M_INDEX:
5743 case IWL_RATE_5M_INDEX:
5746 case IWL_RATE_11M_INDEX:
5747 rinfo->legacy = 110;
5749 case IWL_RATE_6M_INDEX:
5752 case IWL_RATE_9M_INDEX:
5755 case IWL_RATE_12M_INDEX:
5756 rinfo->legacy = 120;
5758 case IWL_RATE_18M_INDEX:
5759 rinfo->legacy = 180;
5761 case IWL_RATE_24M_INDEX:
5762 rinfo->legacy = 240;
5764 case IWL_RATE_36M_INDEX:
5765 rinfo->legacy = 360;
5767 case IWL_RATE_48M_INDEX:
5768 rinfo->legacy = 480;
5770 case IWL_RATE_54M_INDEX:
5771 rinfo->legacy = 540;
5776 rinfo->nss = u32_get_bits(rate_n_flags,
5777 RATE_MCS_NSS_MSK) + 1;
5778 rinfo->mcs = format == RATE_MCS_HT_MSK ?
5779 RATE_HT_MCS_INDEX(rate_n_flags) :
5780 u32_get_bits(rate_n_flags, RATE_MCS_CODE_MSK);
5782 if (rate_n_flags & RATE_MCS_SGI_MSK)
5783 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
5786 case RATE_MCS_EHT_MSK:
5787 /* TODO: GI/LTF/RU. How does the firmware encode them? */
5788 rinfo->flags |= RATE_INFO_FLAGS_EHT_MCS;
5790 case RATE_MCS_HE_MSK:
5791 gi_ltf = u32_get_bits(rate_n_flags, RATE_MCS_HE_GI_LTF_MSK);
5793 rinfo->flags |= RATE_INFO_FLAGS_HE_MCS;
5795 if (rate_n_flags & RATE_MCS_HE_106T_MSK) {
5796 rinfo->bw = RATE_INFO_BW_HE_RU;
5797 rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106;
5800 switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) {
5801 case RATE_MCS_HE_TYPE_SU:
5802 case RATE_MCS_HE_TYPE_EXT_SU:
5803 if (gi_ltf == 0 || gi_ltf == 1)
5804 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
5805 else if (gi_ltf == 2)
5806 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
5807 else if (gi_ltf == 3)
5808 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
5810 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
5812 case RATE_MCS_HE_TYPE_MU:
5813 if (gi_ltf == 0 || gi_ltf == 1)
5814 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
5815 else if (gi_ltf == 2)
5816 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
5818 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
5820 case RATE_MCS_HE_TYPE_TRIG:
5821 if (gi_ltf == 0 || gi_ltf == 1)
5822 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
5824 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
5828 if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK)
5831 case RATE_MCS_HT_MSK:
5832 rinfo->flags |= RATE_INFO_FLAGS_MCS;
5834 case RATE_MCS_VHT_MSK:
5835 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
5840 void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
5841 struct ieee80211_vif *vif,
5842 struct ieee80211_sta *sta,
5843 struct station_info *sinfo)
5845 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5846 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5847 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
5849 if (mvmsta->deflink.avg_energy) {
5850 sinfo->signal_avg = -(s8)mvmsta->deflink.avg_energy;
5851 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
5854 if (iwl_mvm_has_tlc_offload(mvm)) {
5855 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->deflink.lq_sta.rs_fw;
5857 iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate);
5858 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
5861 /* if beacon filtering isn't on mac80211 does it anyway */
5862 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
5865 if (!vif->cfg.assoc)
5868 mutex_lock(&mvm->mutex);
5870 if (mvmvif->deflink.ap_sta_id != mvmsta->deflink.sta_id)
5873 if (iwl_mvm_request_statistics(mvm, false))
5876 sinfo->rx_beacon = mvmvif->deflink.beacon_stats.num_beacons +
5877 mvmvif->deflink.beacon_stats.accu_num_beacons;
5878 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
5879 if (mvmvif->deflink.beacon_stats.avg_signal) {
5880 /* firmware only reports a value after RXing a few beacons */
5881 sinfo->rx_beacon_signal_avg =
5882 mvmvif->deflink.beacon_stats.avg_signal;
5883 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
5886 mutex_unlock(&mvm->mutex);
5889 static void iwl_mvm_event_mlme_callback_ini(struct iwl_mvm *mvm,
5890 struct ieee80211_vif *vif,
5891 const struct ieee80211_mlme_event *mlme)
5893 if ((mlme->data == ASSOC_EVENT || mlme->data == AUTH_EVENT) &&
5894 (mlme->status == MLME_DENIED || mlme->status == MLME_TIMEOUT)) {
5895 iwl_dbg_tlv_time_point(&mvm->fwrt,
5896 IWL_FW_INI_TIME_POINT_ASSOC_FAILED,
5901 if (mlme->data == DEAUTH_RX_EVENT || mlme->data == DEAUTH_TX_EVENT) {
5902 iwl_dbg_tlv_time_point(&mvm->fwrt,
5903 IWL_FW_INI_TIME_POINT_DEASSOC,
5909 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
5910 struct ieee80211_vif *vif,
5911 const struct ieee80211_event *event)
5913 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
5915 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
5917 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
5920 struct iwl_fw_dbg_trigger_tlv *trig;
5921 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
5923 if (iwl_trans_dbg_ini_valid(mvm->trans)) {
5924 iwl_mvm_event_mlme_callback_ini(mvm, vif, &event->u.mlme);
5928 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5929 FW_DBG_TRIGGER_MLME);
5933 trig_mlme = (void *)trig->data;
5935 if (event->u.mlme.data == ASSOC_EVENT) {
5936 if (event->u.mlme.status == MLME_DENIED)
5937 CHECK_MLME_TRIGGER(stop_assoc_denied,
5938 "DENIED ASSOC: reason %d",
5939 event->u.mlme.reason);
5940 else if (event->u.mlme.status == MLME_TIMEOUT)
5941 CHECK_MLME_TRIGGER(stop_assoc_timeout,
5943 } else if (event->u.mlme.data == AUTH_EVENT) {
5944 if (event->u.mlme.status == MLME_DENIED)
5945 CHECK_MLME_TRIGGER(stop_auth_denied,
5946 "DENIED AUTH: reason %d",
5947 event->u.mlme.reason);
5948 else if (event->u.mlme.status == MLME_TIMEOUT)
5949 CHECK_MLME_TRIGGER(stop_auth_timeout,
5951 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
5952 CHECK_MLME_TRIGGER(stop_rx_deauth,
5953 "DEAUTH RX %d", event->u.mlme.reason);
5954 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
5955 CHECK_MLME_TRIGGER(stop_tx_deauth,
5956 "DEAUTH TX %d", event->u.mlme.reason);
5958 #undef CHECK_MLME_TRIGGER
5961 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
5962 struct ieee80211_vif *vif,
5963 const struct ieee80211_event *event)
5965 struct iwl_fw_dbg_trigger_tlv *trig;
5966 struct iwl_fw_dbg_trigger_ba *ba_trig;
5968 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5973 ba_trig = (void *)trig->data;
5975 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
5978 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
5979 "BAR received from %pM, tid %d, ssn %d",
5980 event->u.ba.sta->addr, event->u.ba.tid,
5984 void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
5985 struct ieee80211_vif *vif,
5986 const struct ieee80211_event *event)
5988 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5990 switch (event->type) {
5992 iwl_mvm_event_mlme_callback(mvm, vif, event);
5995 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
5997 case BA_FRAME_TIMEOUT:
5998 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
6006 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
6007 enum iwl_mvm_rxq_notif_type type,
6009 const void *data, u32 size)
6012 struct iwl_rxq_sync_cmd cmd;
6013 struct iwl_mvm_internal_rxq_notif notif;
6015 .cmd.rxq_mask = cpu_to_le32(BIT(mvm->trans->num_rx_queues) - 1),
6017 cpu_to_le32(sizeof(struct iwl_mvm_internal_rxq_notif) +
6022 struct iwl_host_cmd hcmd = {
6023 .id = WIDE_ID(DATA_PATH_GROUP, TRIGGER_RX_QUEUES_NOTIF_CMD),
6025 .len[0] = sizeof(cmd),
6028 .flags = sync ? 0 : CMD_ASYNC,
6032 /* size must be a multiple of DWORD */
6033 if (WARN_ON(cmd.cmd.count & cpu_to_le32(3)))
6036 if (!iwl_mvm_has_new_rx_api(mvm))
6040 cmd.notif.cookie = mvm->queue_sync_cookie;
6041 mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1;
6044 ret = iwl_mvm_send_cmd(mvm, &hcmd);
6046 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
6051 lockdep_assert_held(&mvm->mutex);
6052 ret = wait_event_timeout(mvm->rx_sync_waitq,
6053 READ_ONCE(mvm->queue_sync_state) == 0 ||
6054 iwl_mvm_is_radio_killed(mvm),
6056 WARN_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm),
6057 "queue sync: failed to sync, state is 0x%lx\n",
6058 mvm->queue_sync_state);
6063 mvm->queue_sync_state = 0;
6064 mvm->queue_sync_cookie++;
6068 void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
6070 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
6072 mutex_lock(&mvm->mutex);
6073 iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_EMPTY, true, NULL, 0);
6074 mutex_unlock(&mvm->mutex);
6078 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw,
6079 struct ieee80211_vif *vif,
6080 struct cfg80211_ftm_responder_stats *stats)
6082 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
6083 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
6085 if (vif->p2p || vif->type != NL80211_IFTYPE_AP ||
6086 !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder)
6089 mutex_lock(&mvm->mutex);
6090 *stats = mvm->ftm_resp_stats;
6091 mutex_unlock(&mvm->mutex);
6093 stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) |
6094 BIT(NL80211_FTM_STATS_PARTIAL_NUM) |
6095 BIT(NL80211_FTM_STATS_FAILED_NUM) |
6096 BIT(NL80211_FTM_STATS_ASAP_NUM) |
6097 BIT(NL80211_FTM_STATS_NON_ASAP_NUM) |
6098 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) |
6099 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) |
6100 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) |
6101 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM);
6106 int iwl_mvm_start_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6107 struct cfg80211_pmsr_request *request)
6109 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
6112 mutex_lock(&mvm->mutex);
6113 ret = iwl_mvm_ftm_start(mvm, vif, request);
6114 mutex_unlock(&mvm->mutex);
6119 void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
6120 struct cfg80211_pmsr_request *request)
6122 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
6124 mutex_lock(&mvm->mutex);
6125 iwl_mvm_ftm_abort(mvm, request);
6126 mutex_unlock(&mvm->mutex);
6129 static bool iwl_mvm_can_hw_csum(struct sk_buff *skb)
6131 u8 protocol = ip_hdr(skb)->protocol;
6133 if (!IS_ENABLED(CONFIG_INET))
6136 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
6139 static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw,
6140 struct sk_buff *head,
6141 struct sk_buff *skb)
6143 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
6145 if (iwl_mvm_has_new_tx_csum(mvm))
6146 return iwl_mvm_tx_csum_bz(mvm, head, true) ==
6147 iwl_mvm_tx_csum_bz(mvm, skb, true);
6149 /* For now don't aggregate IPv6 in AMSDU */
6150 if (skb->protocol != htons(ETH_P_IP))
6153 if (!iwl_mvm_is_csum_supported(mvm))
6156 return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head);
6159 int iwl_mvm_set_hw_timestamp(struct ieee80211_hw *hw,
6160 struct ieee80211_vif *vif,
6161 struct cfg80211_set_hw_timestamp *hwts)
6163 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
6167 /* HW timestamping is only supported for a specific station */
6173 IWL_TIME_SYNC_PROTOCOL_TM | IWL_TIME_SYNC_PROTOCOL_FTM;
6175 mutex_lock(&mvm->mutex);
6176 ret = iwl_mvm_time_sync_config(mvm, hwts->macaddr, protocols);
6177 mutex_unlock(&mvm->mutex);
6182 const struct ieee80211_ops iwl_mvm_hw_ops = {
6183 .tx = iwl_mvm_mac_tx,
6184 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue,
6185 .ampdu_action = iwl_mvm_mac_ampdu_action,
6186 .get_antenna = iwl_mvm_op_get_antenna,
6187 .start = iwl_mvm_mac_start,
6188 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
6189 .stop = iwl_mvm_mac_stop,
6190 .add_interface = iwl_mvm_mac_add_interface,
6191 .remove_interface = iwl_mvm_mac_remove_interface,
6192 .config = iwl_mvm_mac_config,
6193 .prepare_multicast = iwl_mvm_prepare_multicast,
6194 .configure_filter = iwl_mvm_configure_filter,
6195 .config_iface_filter = iwl_mvm_config_iface_filter,
6196 .bss_info_changed = iwl_mvm_bss_info_changed,
6197 .hw_scan = iwl_mvm_mac_hw_scan,
6198 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
6199 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
6200 .sta_state = iwl_mvm_mac_sta_state,
6201 .sta_notify = iwl_mvm_mac_sta_notify,
6202 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
6203 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
6204 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
6205 .sta_rc_update = iwl_mvm_sta_rc_update,
6206 .conf_tx = iwl_mvm_mac_conf_tx,
6207 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
6208 .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx,
6209 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
6210 .flush = iwl_mvm_mac_flush,
6211 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
6212 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
6213 .set_key = iwl_mvm_mac_set_key,
6214 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
6215 .remain_on_channel = iwl_mvm_roc,
6216 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
6217 .add_chanctx = iwl_mvm_add_chanctx,
6218 .remove_chanctx = iwl_mvm_remove_chanctx,
6219 .change_chanctx = iwl_mvm_change_chanctx,
6220 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
6221 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
6222 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
6224 .start_ap = iwl_mvm_start_ap,
6225 .stop_ap = iwl_mvm_stop_ap,
6226 .join_ibss = iwl_mvm_start_ibss,
6227 .leave_ibss = iwl_mvm_stop_ibss,
6229 .tx_last_beacon = iwl_mvm_tx_last_beacon,
6231 .set_tim = iwl_mvm_set_tim,
6233 .channel_switch = iwl_mvm_channel_switch,
6234 .pre_channel_switch = iwl_mvm_pre_channel_switch,
6235 .post_channel_switch = iwl_mvm_post_channel_switch,
6236 .abort_channel_switch = iwl_mvm_abort_channel_switch,
6237 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon,
6239 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
6240 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
6241 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
6243 .event_callback = iwl_mvm_mac_event_callback,
6245 .sync_rx_queues = iwl_mvm_sync_rx_queues,
6247 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
6249 #ifdef CONFIG_PM_SLEEP
6251 .suspend = iwl_mvm_suspend,
6252 .resume = iwl_mvm_resume,
6253 .set_wakeup = iwl_mvm_set_wakeup,
6254 .set_rekey_data = iwl_mvm_set_rekey_data,
6255 #if IS_ENABLED(CONFIG_IPV6)
6256 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
6258 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
6260 .get_survey = iwl_mvm_mac_get_survey,
6261 .sta_statistics = iwl_mvm_mac_sta_statistics,
6262 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats,
6263 .start_pmsr = iwl_mvm_start_pmsr,
6264 .abort_pmsr = iwl_mvm_abort_pmsr,
6266 .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate,
6267 #ifdef CONFIG_IWLWIFI_DEBUGFS
6268 .link_sta_add_debugfs = iwl_mvm_link_sta_add_debugfs,
6270 .set_hw_timestamp = iwl_mvm_set_hw_timestamp,