1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2012-2014, 2018-2022 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"
32 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
35 .types = BIT(NL80211_IFTYPE_STATION),
39 .types = BIT(NL80211_IFTYPE_AP) |
40 BIT(NL80211_IFTYPE_P2P_CLIENT) |
41 BIT(NL80211_IFTYPE_P2P_GO),
45 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
49 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
51 .num_different_channels = 2,
53 .limits = iwl_mvm_limits,
54 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
58 static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa = {
59 .max_peers = IWL_MVM_TOF_MAX_APS,
61 .randomize_mac_addr = 1,
68 .request_civicloc = 1,
70 .non_trigger_based = 1,
71 .max_bursts_exponent = -1, /* all supported */
72 .max_ftms_per_burst = 0, /* no limits */
73 .bandwidths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
74 BIT(NL80211_CHAN_WIDTH_20) |
75 BIT(NL80211_CHAN_WIDTH_40) |
76 BIT(NL80211_CHAN_WIDTH_80) |
77 BIT(NL80211_CHAN_WIDTH_160),
78 .preambles = BIT(NL80211_PREAMBLE_LEGACY) |
79 BIT(NL80211_PREAMBLE_HT) |
80 BIT(NL80211_PREAMBLE_VHT) |
81 BIT(NL80211_PREAMBLE_HE),
85 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
87 struct ieee80211_vif *vif,
88 struct ieee80211_sta *sta,
89 struct ieee80211_key_conf *key);
91 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
95 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
96 for (i = 0; i < NUM_PHY_CTX; i++) {
97 mvm->phy_ctxts[i].id = i;
98 mvm->phy_ctxts[i].ref = 0;
102 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
104 enum iwl_mcc_source src_id,
107 struct ieee80211_regdomain *regd = NULL;
108 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
109 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
110 struct iwl_mcc_update_resp *resp;
113 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
115 lockdep_assert_held(&mvm->mutex);
117 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
118 if (IS_ERR_OR_NULL(resp)) {
119 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
120 PTR_ERR_OR_ZERO(resp));
126 u32 status = le32_to_cpu(resp->status);
128 *changed = (status == MCC_RESP_NEW_CHAN_PROFILE ||
129 status == MCC_RESP_ILLEGAL);
131 resp_ver = iwl_fw_lookup_notif_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP,
133 IWL_DEBUG_LAR(mvm, "MCC update response version: %d\n", resp_ver);
135 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
136 __le32_to_cpu(resp->n_channels),
138 __le16_to_cpu(resp->mcc),
139 __le16_to_cpu(resp->geo_info),
140 __le16_to_cpu(resp->cap), resp_ver);
141 /* Store the return source id */
142 src_id = resp->source_id;
143 if (IS_ERR_OR_NULL(regd)) {
144 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
145 PTR_ERR_OR_ZERO(regd));
149 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
150 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
151 mvm->lar_regdom_set = true;
152 mvm->mcc_src = src_id;
154 iwl_mei_set_country_code(__le16_to_cpu(resp->mcc));
161 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
164 struct ieee80211_regdomain *regd;
166 if (!iwl_mvm_is_lar_supported(mvm))
169 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
170 if (!IS_ERR_OR_NULL(regd)) {
171 /* only update the regulatory core if changed */
173 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
179 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
182 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
183 iwl_mvm_is_wifi_mcc_supported(mvm) ?
184 MCC_SOURCE_GET_CURRENT :
185 MCC_SOURCE_OLD_FW, changed);
188 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
190 enum iwl_mcc_source used_src;
191 struct ieee80211_regdomain *regd;
194 const struct ieee80211_regdomain *r =
195 wiphy_dereference(mvm->hw->wiphy, mvm->hw->wiphy->regd);
200 /* save the last source in case we overwrite it below */
201 used_src = mvm->mcc_src;
202 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
203 /* Notify the firmware we support wifi location updates */
204 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
205 if (!IS_ERR_OR_NULL(regd))
209 /* Now set our last stored MCC and source */
210 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
212 if (IS_ERR_OR_NULL(regd))
215 /* update cfg80211 if the regdomain was changed */
217 ret = regulatory_set_wiphy_regd_sync(mvm->hw->wiphy, regd);
225 static const u8 he_if_types_ext_capa_sta[] = {
226 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
227 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
228 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
231 static const struct wiphy_iftype_ext_capab he_iftypes_ext_capa[] = {
233 .iftype = NL80211_IFTYPE_STATION,
234 .extended_capabilities = he_if_types_ext_capa_sta,
235 .extended_capabilities_mask = he_if_types_ext_capa_sta,
236 .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta),
241 iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
243 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
244 *tx_ant = iwl_mvm_get_valid_tx_ant(mvm);
245 *rx_ant = iwl_mvm_get_valid_rx_ant(mvm);
249 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
251 struct ieee80211_hw *hw = mvm->hw;
253 static const u32 mvm_ciphers[] = {
254 WLAN_CIPHER_SUITE_WEP40,
255 WLAN_CIPHER_SUITE_WEP104,
256 WLAN_CIPHER_SUITE_TKIP,
257 WLAN_CIPHER_SUITE_CCMP,
259 #ifdef CONFIG_PM_SLEEP
260 bool unified = fw_has_capa(&mvm->fw->ucode_capa,
261 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
264 /* Tell mac80211 our characteristics */
265 ieee80211_hw_set(hw, SIGNAL_DBM);
266 ieee80211_hw_set(hw, SPECTRUM_MGMT);
267 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
268 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
269 ieee80211_hw_set(hw, SUPPORTS_PS);
270 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
271 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
272 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
273 ieee80211_hw_set(hw, CONNECTION_MONITOR);
274 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
275 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
276 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
277 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
278 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
279 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
280 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
281 ieee80211_hw_set(hw, BUFF_MMPDU_TXQ);
282 ieee80211_hw_set(hw, STA_MMPDU_TXQ);
284 * On older devices, enabling TX A-MSDU occasionally leads to
285 * something getting messed up, the command read from the FIFO
286 * gets out of sync and isn't a TX command, so that we have an
289 * It's not clear where the bug is, but since we didn't used to
290 * support A-MSDU until moving the mac80211 iTXQs, just leave it
291 * for older devices. We also don't see this issue on any newer
294 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000)
295 ieee80211_hw_set(hw, TX_AMSDU);
296 ieee80211_hw_set(hw, TX_FRAG_LIST);
298 if (iwl_mvm_has_tlc_offload(mvm)) {
299 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
300 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
303 if (iwl_mvm_has_new_rx_api(mvm))
304 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
306 if (fw_has_capa(&mvm->fw->ucode_capa,
307 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
308 ieee80211_hw_set(hw, AP_LINK_PS);
309 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
311 * we absolutely need this for the new TX API since that comes
312 * with many more queues than the current code can deal with
313 * for station powersave
318 if (mvm->trans->num_rx_queues > 1)
319 ieee80211_hw_set(hw, USES_RSS);
321 if (mvm->trans->max_skb_frags)
322 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
324 hw->queues = IEEE80211_NUM_ACS;
325 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
326 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
327 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
328 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
329 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
331 hw->radiotap_timestamp.units_pos =
332 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
333 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
334 /* this is the case for CCK frames, it's better (only 8) for OFDM */
335 hw->radiotap_timestamp.accuracy = 22;
337 if (!iwl_mvm_has_tlc_offload(mvm))
338 hw->rate_control_algorithm = RS_NAME;
340 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
341 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
342 hw->max_tx_fragments = mvm->trans->max_skb_frags;
344 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
345 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
346 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
347 hw->wiphy->cipher_suites = mvm->ciphers;
349 if (iwl_mvm_has_new_rx_api(mvm)) {
350 mvm->ciphers[hw->wiphy->n_cipher_suites] =
351 WLAN_CIPHER_SUITE_GCMP;
352 hw->wiphy->n_cipher_suites++;
353 mvm->ciphers[hw->wiphy->n_cipher_suites] =
354 WLAN_CIPHER_SUITE_GCMP_256;
355 hw->wiphy->n_cipher_suites++;
358 if (iwlwifi_mod_params.swcrypto)
360 "iwlmvm doesn't allow to disable HW crypto, check swcrypto module parameter\n");
361 if (!iwlwifi_mod_params.bt_coex_active)
363 "iwlmvm doesn't allow to disable BT Coex, check bt_coex_active module parameter\n");
365 ieee80211_hw_set(hw, MFP_CAPABLE);
366 mvm->ciphers[hw->wiphy->n_cipher_suites] = WLAN_CIPHER_SUITE_AES_CMAC;
367 hw->wiphy->n_cipher_suites++;
368 if (iwl_mvm_has_new_rx_api(mvm)) {
369 mvm->ciphers[hw->wiphy->n_cipher_suites] =
370 WLAN_CIPHER_SUITE_BIP_GMAC_128;
371 hw->wiphy->n_cipher_suites++;
372 mvm->ciphers[hw->wiphy->n_cipher_suites] =
373 WLAN_CIPHER_SUITE_BIP_GMAC_256;
374 hw->wiphy->n_cipher_suites++;
377 if (fw_has_capa(&mvm->fw->ucode_capa,
378 IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) {
379 wiphy_ext_feature_set(hw->wiphy,
380 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
381 hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa;
384 if (fw_has_capa(&mvm->fw->ucode_capa,
385 IWL_UCODE_TLV_CAPA_BIGTK_SUPPORT))
386 wiphy_ext_feature_set(hw->wiphy,
387 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT);
389 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
390 hw->wiphy->features |=
391 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
392 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
393 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
395 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
396 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
397 hw->chanctx_data_size = sizeof(u16);
398 hw->txq_data_size = sizeof(struct iwl_mvm_txq);
400 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
401 BIT(NL80211_IFTYPE_P2P_CLIENT) |
402 BIT(NL80211_IFTYPE_AP) |
403 BIT(NL80211_IFTYPE_P2P_GO) |
404 BIT(NL80211_IFTYPE_P2P_DEVICE) |
405 BIT(NL80211_IFTYPE_ADHOC);
407 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
408 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
410 /* The new Tx API does not allow to pass the key or keyid of a MPDU to
411 * the hw, preventing us to control which key(id) to use per MPDU.
412 * Till that's fixed we can't use Extended Key ID for the newer cards.
414 if (!iwl_mvm_has_new_tx_api(mvm))
415 wiphy_ext_feature_set(hw->wiphy,
416 NL80211_EXT_FEATURE_EXT_KEY_ID);
417 hw->wiphy->features |= NL80211_FEATURE_HT_IBSS;
419 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
420 if (iwl_mvm_is_lar_supported(mvm))
421 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
423 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
424 REGULATORY_DISABLE_BEACON_HINTS;
426 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
427 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
428 hw->wiphy->flags |= WIPHY_FLAG_SPLIT_SCAN_6GHZ;
430 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
431 hw->wiphy->n_iface_combinations =
432 ARRAY_SIZE(iwl_mvm_iface_combinations);
434 hw->wiphy->max_remain_on_channel_duration = 10000;
435 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
437 /* Extract MAC address */
438 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
439 hw->wiphy->addresses = mvm->addresses;
440 hw->wiphy->n_addresses = 1;
442 /* Extract additional MAC addresses if available */
443 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
444 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
446 for (i = 1; i < num_mac; i++) {
447 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
449 mvm->addresses[i].addr[5]++;
450 hw->wiphy->n_addresses++;
453 iwl_mvm_reset_phy_ctxts(mvm);
455 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
457 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
459 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
460 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
461 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
463 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
464 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
466 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
468 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
469 hw->wiphy->bands[NL80211_BAND_2GHZ] =
470 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
471 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
472 hw->wiphy->bands[NL80211_BAND_5GHZ] =
473 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
475 if (fw_has_capa(&mvm->fw->ucode_capa,
476 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
477 fw_has_api(&mvm->fw->ucode_capa,
478 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
479 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
480 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
482 if (fw_has_capa(&mvm->fw->ucode_capa,
483 IWL_UCODE_TLV_CAPA_PSC_CHAN_SUPPORT) &&
484 mvm->nvm_data->bands[NL80211_BAND_6GHZ].n_channels)
485 hw->wiphy->bands[NL80211_BAND_6GHZ] =
486 &mvm->nvm_data->bands[NL80211_BAND_6GHZ];
488 hw->wiphy->hw_version = mvm->trans->hw_id;
490 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
491 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
493 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
495 hw->wiphy->max_sched_scan_reqs = 1;
496 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
497 hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw);
498 /* we create the 802.11 header and zero length SSID IE. */
499 hw->wiphy->max_sched_scan_ie_len =
500 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
501 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
502 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
505 * the firmware uses u8 for num of iterations, but 0xff is saved for
506 * infinite loop, so the maximum number of iterations is actually 254.
508 hw->wiphy->max_sched_scan_plan_iterations = 254;
510 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
511 NL80211_FEATURE_LOW_PRIORITY_SCAN |
512 NL80211_FEATURE_P2P_GO_OPPPS |
513 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
514 NL80211_FEATURE_DYNAMIC_SMPS |
515 NL80211_FEATURE_STATIC_SMPS |
516 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
518 if (fw_has_capa(&mvm->fw->ucode_capa,
519 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
520 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
521 if (fw_has_capa(&mvm->fw->ucode_capa,
522 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
523 hw->wiphy->features |= NL80211_FEATURE_QUIET;
525 if (fw_has_capa(&mvm->fw->ucode_capa,
526 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
527 hw->wiphy->features |=
528 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
530 if (fw_has_capa(&mvm->fw->ucode_capa,
531 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
532 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
534 if (iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_KEK_KCK_MATERIAL,
535 IWL_FW_CMD_VER_UNKNOWN) == 3)
536 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK;
538 if (fw_has_api(&mvm->fw->ucode_capa,
539 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
540 wiphy_ext_feature_set(hw->wiphy,
541 NL80211_EXT_FEATURE_SCAN_START_TIME);
542 wiphy_ext_feature_set(hw->wiphy,
543 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
546 if (iwl_mvm_is_oce_supported(mvm)) {
547 u8 scan_ver = iwl_fw_lookup_cmd_ver(mvm->fw, SCAN_REQ_UMAC, 0);
549 wiphy_ext_feature_set(hw->wiphy,
550 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
551 wiphy_ext_feature_set(hw->wiphy,
552 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
553 wiphy_ext_feature_set(hw->wiphy,
554 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
556 /* Old firmware also supports probe deferral and suppression */
558 wiphy_ext_feature_set(hw->wiphy,
559 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
562 if (mvm->nvm_data->sku_cap_11ax_enable &&
563 !iwlwifi_mod_params.disable_11ax) {
564 hw->wiphy->iftype_ext_capab = he_iftypes_ext_capa;
565 hw->wiphy->num_iftype_ext_capab =
566 ARRAY_SIZE(he_iftypes_ext_capa);
568 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
569 ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID);
572 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
574 #ifdef CONFIG_PM_SLEEP
575 if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) &&
576 mvm->trans->ops->d3_suspend &&
577 mvm->trans->ops->d3_resume &&
578 device_can_wakeup(mvm->trans->dev)) {
579 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
580 WIPHY_WOWLAN_DISCONNECT |
581 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
582 WIPHY_WOWLAN_RFKILL_RELEASE |
583 WIPHY_WOWLAN_NET_DETECT;
584 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
585 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
586 WIPHY_WOWLAN_4WAY_HANDSHAKE;
588 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
589 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
590 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
591 mvm->wowlan.max_nd_match_sets =
592 iwl_umac_scan_get_max_profiles(mvm->fw);
593 hw->wiphy->wowlan = &mvm->wowlan;
597 ret = iwl_mvm_leds_init(mvm);
601 if (fw_has_capa(&mvm->fw->ucode_capa,
602 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
603 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
604 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
605 ieee80211_hw_set(hw, TDLS_WIDER_BW);
608 if (fw_has_capa(&mvm->fw->ucode_capa,
609 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
610 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
611 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
614 hw->netdev_features |= mvm->cfg->features;
615 if (!iwl_mvm_is_csum_supported(mvm))
616 hw->netdev_features &= ~IWL_CSUM_NETIF_FLAGS_MASK;
618 if (mvm->cfg->vht_mu_mimo_supported)
619 wiphy_ext_feature_set(hw->wiphy,
620 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
622 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT))
623 wiphy_ext_feature_set(hw->wiphy,
624 NL80211_EXT_FEATURE_PROTECTED_TWT);
626 iwl_mvm_vendor_cmds_register(mvm);
628 hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm);
629 hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm);
631 ret = ieee80211_register_hw(mvm->hw);
633 iwl_mvm_leds_exit(mvm);
639 static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
640 struct ieee80211_sta *sta)
643 if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0))
646 if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0))
650 ieee80211_free_txskb(mvm->hw, skb);
653 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
654 struct ieee80211_tx_control *control,
657 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
658 struct ieee80211_sta *sta = control->sta;
659 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
660 struct ieee80211_hdr *hdr = (void *)skb->data;
661 bool offchannel = IEEE80211_SKB_CB(skb)->flags &
662 IEEE80211_TX_CTL_TX_OFFCHAN;
664 if (iwl_mvm_is_radio_killed(mvm)) {
665 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
670 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
671 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
675 * bufferable MMPDUs or MMPDUs on STA interfaces come via TXQs
676 * so we treat the others as broadcast
678 if (ieee80211_is_mgmt(hdr->frame_control))
681 /* If there is no sta, and it's not offchannel - send through AP */
682 if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION &&
684 struct iwl_mvm_vif *mvmvif =
685 iwl_mvm_vif_from_mac80211(info->control.vif);
686 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
688 if (ap_sta_id < mvm->fw->ucode_capa.num_stations) {
689 /* mac80211 holds rcu read lock */
690 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
691 if (IS_ERR_OR_NULL(sta))
696 iwl_mvm_tx_skb(mvm, skb, sta);
699 ieee80211_free_txskb(hw, skb);
702 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
704 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
705 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
706 struct sk_buff *skb = NULL;
709 * No need for threads to be pending here, they can leave the first
710 * taker all the work.
712 * mvmtxq->tx_request logic:
714 * If 0, no one is currently TXing, set to 1 to indicate current thread
715 * will now start TX and other threads should quit.
717 * If 1, another thread is currently TXing, set to 2 to indicate to
718 * that thread that there was another request. Since that request may
719 * have raced with the check whether the queue is empty, the TXing
720 * thread should check the queue's status one more time before leaving.
721 * This check is done in order to not leave any TX hanging in the queue
722 * until the next TX invocation (which may not even happen).
724 * If 2, another thread is currently TXing, and it will already double
725 * check the queue, so do nothing.
727 if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2))
732 while (likely(!mvmtxq->stopped &&
733 !test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status))) {
734 skb = ieee80211_tx_dequeue(hw, txq);
739 "TXQ of sta %pM tid %d is now empty\n",
745 iwl_mvm_tx_skb(mvm, skb, txq->sta);
747 } while (atomic_dec_return(&mvmtxq->tx_request));
751 static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw,
752 struct ieee80211_txq *txq)
754 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
755 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
758 * Please note that racing is handled very carefully here:
759 * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is
760 * deleted afterwards.
761 * This means that if:
762 * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list):
763 * queue is allocated and we can TX.
764 * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list):
765 * a race, should defer the frame.
766 * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list):
767 * need to allocate the queue and defer the frame.
768 * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list):
769 * queue is already scheduled for allocation, no need to allocate,
770 * should defer the frame.
773 /* If the queue is allocated TX and return. */
774 if (!txq->sta || mvmtxq->txq_id != IWL_MVM_INVALID_QUEUE) {
776 * Check that list is empty to avoid a race where txq_id is
777 * already updated, but the queue allocation work wasn't
780 if (unlikely(txq->sta && !list_empty(&mvmtxq->list)))
783 iwl_mvm_mac_itxq_xmit(hw, txq);
787 /* The list is being deleted only after the queue is fully allocated. */
788 if (!list_empty(&mvmtxq->list))
791 list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs);
792 schedule_work(&mvm->add_stream_wk);
795 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
797 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
799 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
803 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
804 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
805 enum ieee80211_ampdu_mlme_action action)
807 struct iwl_fw_dbg_trigger_tlv *trig;
808 struct iwl_fw_dbg_trigger_ba *ba_trig;
810 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
815 ba_trig = (void *)trig->data;
818 case IEEE80211_AMPDU_TX_OPERATIONAL: {
819 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
820 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
822 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
823 "TX AGG START: MAC %pM tid %d ssn %d\n",
824 sta->addr, tid, tid_data->ssn);
827 case IEEE80211_AMPDU_TX_STOP_CONT:
828 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
829 "TX AGG STOP: MAC %pM tid %d\n",
832 case IEEE80211_AMPDU_RX_START:
833 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
834 "RX AGG START: MAC %pM tid %d ssn %d\n",
835 sta->addr, tid, rx_ba_ssn);
837 case IEEE80211_AMPDU_RX_STOP:
838 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
839 "RX AGG STOP: MAC %pM tid %d\n",
847 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
848 struct ieee80211_vif *vif,
849 struct ieee80211_ampdu_params *params)
851 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
853 struct ieee80211_sta *sta = params->sta;
854 enum ieee80211_ampdu_mlme_action action = params->action;
855 u16 tid = params->tid;
856 u16 *ssn = ¶ms->ssn;
857 u16 buf_size = params->buf_size;
858 bool amsdu = params->amsdu;
859 u16 timeout = params->timeout;
861 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
862 sta->addr, tid, action);
864 if (!(mvm->nvm_data->sku_cap_11n_enable))
867 mutex_lock(&mvm->mutex);
870 case IEEE80211_AMPDU_RX_START:
871 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
872 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
873 struct iwl_mvm_vif *mvmvif;
874 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
875 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
877 mdata->opened_rx_ba_sessions = true;
878 mvmvif = iwl_mvm_vif_from_mac80211(vif);
879 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
881 if (!iwl_enable_rx_ampdu()) {
885 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
888 case IEEE80211_AMPDU_RX_STOP:
889 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
892 case IEEE80211_AMPDU_TX_START:
893 if (!iwl_enable_tx_ampdu()) {
897 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
899 case IEEE80211_AMPDU_TX_STOP_CONT:
900 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
902 case IEEE80211_AMPDU_TX_STOP_FLUSH:
903 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
904 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
906 case IEEE80211_AMPDU_TX_OPERATIONAL:
907 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
919 if (action == IEEE80211_AMPDU_RX_START)
922 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
925 mutex_unlock(&mvm->mutex);
930 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
931 struct ieee80211_vif *vif)
933 struct iwl_mvm *mvm = data;
934 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
936 mvmvif->uploaded = false;
937 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
939 spin_lock_bh(&mvm->time_event_lock);
940 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
941 spin_unlock_bh(&mvm->time_event_lock);
943 mvmvif->phy_ctxt = NULL;
944 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
945 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
948 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
950 iwl_mvm_stop_device(mvm);
954 mvm->scan_status = 0;
955 mvm->ps_disabled = false;
956 mvm->rfkill_safe_init_done = false;
958 /* just in case one was running */
959 iwl_mvm_cleanup_roc_te(mvm);
960 ieee80211_remain_on_channel_expired(mvm->hw);
962 iwl_mvm_ftm_restart(mvm);
965 * cleanup all interfaces, even inactive ones, as some might have
966 * gone down during the HW restart
968 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
970 mvm->p2p_device_vif = NULL;
972 iwl_mvm_reset_phy_ctxts(mvm);
973 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
974 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
975 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
977 ieee80211_wake_queues(mvm->hw);
980 mvm->rx_ba_sessions = 0;
981 mvm->fwrt.dump.conf = FW_DBG_INVALID;
982 mvm->monitor_on = false;
984 /* keep statistics ticking */
985 iwl_mvm_accu_radio_stats(mvm);
988 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
992 lockdep_assert_held(&mvm->mutex);
994 ret = iwl_mvm_mei_get_ownership(mvm);
998 if (mvm->mei_nvm_data) {
999 /* We got the NIC, we can now free the MEI NVM data */
1000 kfree(mvm->mei_nvm_data);
1001 mvm->mei_nvm_data = NULL;
1004 * We can't free the nvm_data we allocated based on the SAP
1005 * data because we registered to cfg80211 with the channels
1006 * allocated on mvm->nvm_data. Keep a pointer in temp_nvm_data
1007 * just in order to be able free it later.
1008 * NULLify nvm_data so that we will read the NVM from the
1009 * firmware this time.
1011 mvm->temp_nvm_data = mvm->nvm_data;
1012 mvm->nvm_data = NULL;
1015 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1017 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1018 * so later code will - from now on - see that we're doing it.
1020 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1021 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1022 /* Clean up some internal and mac80211 state on restart */
1023 iwl_mvm_restart_cleanup(mvm);
1025 ret = iwl_mvm_up(mvm);
1027 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT,
1029 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC,
1032 mvm->last_reset_or_resume_time_jiffies = jiffies;
1034 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1035 /* Something went wrong - we need to finish some cleanup
1036 * that normally iwl_mvm_mac_restart_complete() below
1039 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1045 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1047 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1049 int retry, max_retry = 0;
1051 mutex_lock(&mvm->mutex);
1053 /* we are starting the mac not in error flow, and restart is enabled */
1054 if (!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) &&
1055 iwlwifi_mod_params.fw_restart) {
1056 max_retry = IWL_MAX_INIT_RETRY;
1058 * This will prevent mac80211 recovery flows to trigger during
1061 set_bit(IWL_MVM_STATUS_STARTING, &mvm->status);
1064 for (retry = 0; retry <= max_retry; retry++) {
1065 ret = __iwl_mvm_mac_start(mvm);
1069 IWL_ERR(mvm, "mac start retry %d\n", retry);
1071 clear_bit(IWL_MVM_STATUS_STARTING, &mvm->status);
1073 mutex_unlock(&mvm->mutex);
1075 iwl_mvm_mei_set_sw_rfkill_state(mvm);
1080 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1084 mutex_lock(&mvm->mutex);
1086 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1088 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1090 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1093 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY);
1096 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1097 * of packets the FW sent out, so we must reconnect.
1099 iwl_mvm_teardown_tdls_peers(mvm);
1101 mutex_unlock(&mvm->mutex);
1105 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1106 enum ieee80211_reconfig_type reconfig_type)
1108 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1110 switch (reconfig_type) {
1111 case IEEE80211_RECONFIG_TYPE_RESTART:
1112 iwl_mvm_restart_complete(mvm);
1114 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1119 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1121 lockdep_assert_held(&mvm->mutex);
1123 iwl_mvm_ftm_initiator_smooth_stop(mvm);
1125 /* firmware counters are obviously reset now, but we shouldn't
1126 * partially track so also clear the fw_reset_accu counters.
1128 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1130 /* async_handlers_wk is now blocked */
1132 if (iwl_fw_lookup_cmd_ver(mvm->fw, ADD_STA, 0) < 12)
1133 iwl_mvm_rm_aux_sta(mvm);
1135 iwl_mvm_stop_device(mvm);
1137 iwl_mvm_async_handlers_purge(mvm);
1138 /* async_handlers_list is empty and will stay empty: HW is stopped */
1141 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1142 * hw (as restart_complete() won't be called in this case) and mac80211
1143 * won't execute the restart.
1144 * But make sure to cleanup interfaces that have gone down before/during
1145 * HW restart was requested.
1147 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1148 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1150 ieee80211_iterate_interfaces(mvm->hw, 0,
1151 iwl_mvm_cleanup_iterator, mvm);
1153 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1154 * make sure there's nothing left there and warn if any is found.
1156 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1159 for (i = 0; i < mvm->max_scans; i++) {
1160 if (WARN_ONCE(mvm->scan_uid_status[i],
1161 "UMAC scan UID %d status was not cleaned\n",
1163 mvm->scan_uid_status[i] = 0;
1168 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1170 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1172 flush_work(&mvm->async_handlers_wk);
1173 flush_work(&mvm->add_stream_wk);
1176 * Lock and clear the firmware running bit here already, so that
1177 * new commands coming in elsewhere, e.g. from debugfs, will not
1178 * be able to proceed. This is important here because one of those
1179 * debugfs files causes the firmware dump to be triggered, and if we
1180 * don't stop debugfs accesses before canceling that it could be
1181 * retriggered after we flush it but before we've cleared the bit.
1183 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1185 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1186 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1189 * The work item could be running or queued if the
1190 * ROC time event stops just as we get here.
1192 flush_work(&mvm->roc_done_wk);
1194 iwl_mvm_mei_set_sw_rfkill_state(mvm);
1196 mutex_lock(&mvm->mutex);
1197 __iwl_mvm_mac_stop(mvm);
1198 mutex_unlock(&mvm->mutex);
1201 * The worker might have been waiting for the mutex, let it run and
1202 * discover that its list is now empty.
1204 cancel_work_sync(&mvm->async_handlers_wk);
1207 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1211 lockdep_assert_held(&mvm->mutex);
1213 for (i = 0; i < NUM_PHY_CTX; i++)
1214 if (!mvm->phy_ctxts[i].ref)
1215 return &mvm->phy_ctxts[i];
1217 IWL_ERR(mvm, "No available PHY context\n");
1221 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1224 u32 cmd_id = REDUCE_TX_POWER_CMD;
1226 struct iwl_dev_tx_power_cmd cmd = {
1227 .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1228 .common.mac_context_id =
1229 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1230 .common.pwr_restriction = cpu_to_le16(8 * tx_power),
1232 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id,
1233 IWL_FW_CMD_VER_UNKNOWN);
1235 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1236 cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1239 len = sizeof(cmd.v7);
1240 else if (cmd_ver == 6)
1241 len = sizeof(cmd.v6);
1242 else if (fw_has_api(&mvm->fw->ucode_capa,
1243 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1244 len = sizeof(cmd.v5);
1245 else if (fw_has_capa(&mvm->fw->ucode_capa,
1246 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1247 len = sizeof(cmd.v4);
1249 len = sizeof(cmd.v3);
1251 /* all structs have the same common part, add it */
1252 len += sizeof(cmd.common);
1254 return iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, len, &cmd);
1257 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
1258 struct ieee80211_vif *vif)
1260 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1261 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1264 mutex_lock(&mvm->mutex);
1266 if (vif->type == NL80211_IFTYPE_STATION) {
1267 struct iwl_mvm_sta *mvmsta;
1269 mvmvif->csa_bcn_pending = false;
1270 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
1273 if (WARN_ON(!mvmsta)) {
1278 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
1280 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1282 if (!fw_has_capa(&mvm->fw->ucode_capa,
1283 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
1284 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1288 iwl_mvm_stop_session_protection(mvm, vif);
1292 mvmvif->ps_disabled = false;
1294 ret = iwl_mvm_power_update_ps(mvm);
1297 if (mvmvif->csa_failed)
1299 mutex_unlock(&mvm->mutex);
1304 static void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw,
1305 struct ieee80211_vif *vif)
1307 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1308 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1309 struct iwl_chan_switch_te_cmd cmd = {
1310 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1312 .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE),
1316 * In the new flow since FW is in charge of the timing,
1317 * if driver has canceled the channel switch he will receive the
1318 * CHANNEL_SWITCH_START_NOTIF notification from FW and then cancel it
1320 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
1321 CHANNEL_SWITCH_ERROR_NOTIF, 0))
1324 IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id);
1326 mutex_lock(&mvm->mutex);
1327 if (!fw_has_capa(&mvm->fw->ucode_capa,
1328 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
1329 iwl_mvm_remove_csa_period(mvm, vif);
1331 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
1332 WIDE_ID(MAC_CONF_GROUP,
1333 CHANNEL_SWITCH_TIME_EVENT_CMD),
1334 0, sizeof(cmd), &cmd));
1335 mvmvif->csa_failed = true;
1336 mutex_unlock(&mvm->mutex);
1338 iwl_mvm_post_channel_switch(hw, vif);
1341 static void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk)
1343 struct iwl_mvm_vif *mvmvif;
1344 struct ieee80211_vif *vif;
1346 mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work);
1347 vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);
1349 /* Trigger disconnect (should clear the CSA state) */
1350 ieee80211_chswitch_done(vif, false);
1353 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1354 struct ieee80211_vif *vif)
1356 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1357 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1361 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1364 * Not much to do here. The stack will not allow interface
1365 * types or combinations that we didn't advertise, so we
1366 * don't really have to check the types.
1369 mutex_lock(&mvm->mutex);
1371 /* make sure that beacon statistics don't go backwards with FW reset */
1372 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1373 mvmvif->beacon_stats.accu_num_beacons +=
1374 mvmvif->beacon_stats.num_beacons;
1376 /* Allocate resources for the MAC context, and add it to the fw */
1377 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1381 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif);
1383 /* Counting number of interfaces is needed for legacy PM */
1384 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1388 * The AP binding flow can be done only after the beacon
1389 * template is configured (which happens only in the mac80211
1390 * start_ap() flow), and adding the broadcast station can happen
1391 * only after the binding.
1392 * In addition, since modifying the MAC before adding a bcast
1393 * station is not allowed by the FW, delay the adding of MAC context to
1394 * the point where we can also add the bcast station.
1395 * In short: there's not much we can do at this point, other than
1396 * allocating resources :)
1398 if (vif->type == NL80211_IFTYPE_AP ||
1399 vif->type == NL80211_IFTYPE_ADHOC) {
1400 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1402 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1407 * Only queue for this station is the mcast queue,
1408 * which shouldn't be in TFD mask anyway
1410 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1416 iwl_mvm_vif_dbgfs_register(mvm, vif);
1420 mvmvif->features |= hw->netdev_features;
1422 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1426 ret = iwl_mvm_power_update_mac(mvm);
1428 goto out_remove_mac;
1430 /* beacon filtering */
1431 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1433 goto out_remove_mac;
1435 if (!mvm->bf_allowed_vif &&
1436 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1437 mvm->bf_allowed_vif = mvmvif;
1438 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1439 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1443 * P2P_DEVICE interface does not have a channel context assigned to it,
1444 * so a dedicated PHY context is allocated to it and the corresponding
1445 * MAC context is bound to it at this stage.
1447 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1449 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1450 if (!mvmvif->phy_ctxt) {
1455 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1456 ret = iwl_mvm_binding_add_vif(mvm, vif);
1460 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1464 /* Save a pointer to p2p device vif, so it can later be used to
1465 * update the p2p device MAC when a GO is started/stopped */
1466 mvm->p2p_device_vif = vif;
1469 iwl_mvm_tcm_add_vif(mvm, vif);
1470 INIT_DELAYED_WORK(&mvmvif->csa_work,
1471 iwl_mvm_channel_switch_disconnect_wk);
1473 if (vif->type == NL80211_IFTYPE_MONITOR)
1474 mvm->monitor_on = true;
1476 iwl_mvm_vif_dbgfs_register(mvm, vif);
1478 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
1479 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
1480 !mvm->csme_vif && mvm->mei_registered) {
1481 iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr);
1482 iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev);
1483 mvm->csme_vif = vif;
1489 iwl_mvm_binding_remove_vif(mvm, vif);
1491 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1493 if (mvm->bf_allowed_vif == mvmvif) {
1494 mvm->bf_allowed_vif = NULL;
1495 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1496 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1499 mvmvif->phy_ctxt = NULL;
1500 iwl_mvm_mac_ctxt_remove(mvm, vif);
1502 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1505 mutex_unlock(&mvm->mutex);
1510 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1511 struct ieee80211_vif *vif)
1513 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1515 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1516 * We assume here that all the packets sent to the OFFCHANNEL
1517 * queue are sent in ROC session.
1519 flush_work(&mvm->roc_done_wk);
1523 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1524 struct ieee80211_vif *vif)
1526 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1527 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1528 struct iwl_probe_resp_data *probe_data;
1530 iwl_mvm_prepare_mac_removal(mvm, vif);
1532 if (!(vif->type == NL80211_IFTYPE_AP ||
1533 vif->type == NL80211_IFTYPE_ADHOC))
1534 iwl_mvm_tcm_rm_vif(mvm, vif);
1536 mutex_lock(&mvm->mutex);
1538 if (vif == mvm->csme_vif) {
1539 iwl_mei_set_netdev(NULL);
1540 mvm->csme_vif = NULL;
1543 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1544 lockdep_is_held(&mvm->mutex));
1545 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1547 kfree_rcu(probe_data, rcu_head);
1549 if (mvm->bf_allowed_vif == mvmvif) {
1550 mvm->bf_allowed_vif = NULL;
1551 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1552 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1555 if (vif->bss_conf.ftm_responder)
1556 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
1558 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1561 * For AP/GO interface, the tear down of the resources allocated to the
1562 * interface is be handled as part of the stop_ap flow.
1564 if (vif->type == NL80211_IFTYPE_AP ||
1565 vif->type == NL80211_IFTYPE_ADHOC) {
1566 #ifdef CONFIG_NL80211_TESTMODE
1567 if (vif == mvm->noa_vif) {
1568 mvm->noa_vif = NULL;
1569 mvm->noa_duration = 0;
1572 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1573 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1577 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1578 mvm->p2p_device_vif = NULL;
1579 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1580 iwl_mvm_binding_remove_vif(mvm, vif);
1581 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1582 mvmvif->phy_ctxt = NULL;
1585 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1588 iwl_mvm_power_update_mac(mvm);
1589 iwl_mvm_mac_ctxt_remove(mvm, vif);
1591 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL);
1593 if (vif->type == NL80211_IFTYPE_MONITOR)
1594 mvm->monitor_on = false;
1597 mutex_unlock(&mvm->mutex);
1600 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1605 struct iwl_mvm_mc_iter_data {
1606 struct iwl_mvm *mvm;
1610 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1611 struct ieee80211_vif *vif)
1613 struct iwl_mvm_mc_iter_data *data = _data;
1614 struct iwl_mvm *mvm = data->mvm;
1615 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1616 struct iwl_host_cmd hcmd = {
1617 .id = MCAST_FILTER_CMD,
1619 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1623 /* if we don't have free ports, mcast frames will be dropped */
1624 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1627 if (vif->type != NL80211_IFTYPE_STATION ||
1628 !vif->bss_conf.assoc)
1631 cmd->port_id = data->port_id++;
1632 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1633 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1638 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1640 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1643 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1645 struct iwl_mvm_mc_iter_data iter_data = {
1650 lockdep_assert_held(&mvm->mutex);
1652 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1655 ieee80211_iterate_active_interfaces_atomic(
1656 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1657 iwl_mvm_mc_iface_iterator, &iter_data);
1660 * Send a (synchronous) ech command so that we wait for the
1661 * multiple asynchronous MCAST_FILTER_CMD commands sent by
1662 * the interface iterator. Otherwise, we might get here over
1663 * and over again (by userspace just sending a lot of these)
1664 * and the CPU can send them faster than the firmware can
1666 * Note that the CPU is still faster - but with this we'll
1667 * actually send fewer commands overall because the CPU will
1668 * not schedule the work in mac80211 as frequently if it's
1669 * still running when rescheduled (possibly multiple times).
1671 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1673 IWL_ERR(mvm, "Failed to synchronize multicast groups update\n");
1676 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1677 struct netdev_hw_addr_list *mc_list)
1679 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1680 struct iwl_mcast_filter_cmd *cmd;
1681 struct netdev_hw_addr *addr;
1686 addr_count = netdev_hw_addr_list_count(mc_list);
1687 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1688 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1692 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1693 cmd = kzalloc(len, GFP_ATOMIC);
1699 return (u64)(unsigned long)cmd;
1702 netdev_hw_addr_list_for_each(addr, mc_list) {
1703 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1704 cmd->count, addr->addr);
1705 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1706 addr->addr, ETH_ALEN);
1710 return (u64)(unsigned long)cmd;
1713 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1714 unsigned int changed_flags,
1715 unsigned int *total_flags,
1718 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1719 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1721 mutex_lock(&mvm->mutex);
1723 /* replace previous configuration */
1724 kfree(mvm->mcast_filter_cmd);
1725 mvm->mcast_filter_cmd = cmd;
1730 if (changed_flags & FIF_ALLMULTI)
1731 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1736 iwl_mvm_recalc_multicast(mvm);
1738 mutex_unlock(&mvm->mutex);
1742 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1743 struct ieee80211_vif *vif,
1744 unsigned int filter_flags,
1745 unsigned int changed_flags)
1747 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1749 /* We support only filter for probe requests */
1750 if (!(changed_flags & FIF_PROBE_REQ))
1753 /* Supported only for p2p client interfaces */
1754 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1758 mutex_lock(&mvm->mutex);
1759 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1760 mutex_unlock(&mvm->mutex);
1763 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1764 struct ieee80211_vif *vif)
1766 struct iwl_mu_group_mgmt_cmd cmd = {};
1768 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1769 WLAN_MEMBERSHIP_LEN);
1770 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1771 WLAN_USER_POSITION_LEN);
1773 return iwl_mvm_send_cmd_pdu(mvm,
1774 WIDE_ID(DATA_PATH_GROUP,
1775 UPDATE_MU_GROUPS_CMD),
1776 0, sizeof(cmd), &cmd);
1779 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1780 struct ieee80211_vif *vif)
1782 if (vif->mu_mimo_owner) {
1783 struct iwl_mu_group_mgmt_notif *notif = _data;
1786 * MU-MIMO Group Id action frame is little endian. We treat
1787 * the data received from firmware as if it came from the
1788 * action frame, so no conversion is needed.
1790 ieee80211_update_mu_groups(vif,
1791 (u8 *)¬if->membership_status,
1792 (u8 *)¬if->user_position);
1796 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1797 struct iwl_rx_cmd_buffer *rxb)
1799 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1800 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1802 ieee80211_iterate_active_interfaces_atomic(
1803 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1804 iwl_mvm_mu_mimo_iface_iterator, notif);
1807 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1809 u8 byte_num = ppe_pos_bit / 8;
1810 u8 bit_num = ppe_pos_bit % 8;
1815 return (ppe[byte_num] >> bit_num) &
1816 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1819 * If bit_num > 5, we have to combine bits with next byte.
1820 * Calculate how many bits we need to take from current byte (called
1821 * here "residue_bits"), and add them to bits from next byte.
1824 residue_bits = 8 - bit_num;
1826 res = (ppe[byte_num + 1] &
1827 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1829 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1834 static void iwl_mvm_parse_ppe(struct iwl_mvm *mvm,
1835 struct iwl_he_pkt_ext_v2 *pkt_ext, u8 nss,
1836 u8 ru_index_bitmap, u8 *ppe, u8 ppe_pos_bit)
1841 * FW currently supports only nss == MAX_HE_SUPP_NSS
1843 * If nss > MAX: we can ignore values we don't support
1844 * If nss < MAX: we can set zeros in other streams
1846 if (nss > MAX_HE_SUPP_NSS) {
1847 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
1849 nss = MAX_HE_SUPP_NSS;
1852 for (i = 0; i < nss; i++) {
1853 u8 ru_index_tmp = ru_index_bitmap << 1;
1854 u8 low_th = IWL_HE_PKT_EXT_NONE, high_th = IWL_HE_PKT_EXT_NONE;
1858 bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]);
1862 if (!(ru_index_tmp & 1))
1865 high_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit);
1866 ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE;
1867 low_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit);
1868 ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE;
1870 pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th;
1871 pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th;
1876 static void iwl_mvm_set_pkt_ext_from_he_ppe(struct iwl_mvm *mvm,
1877 struct ieee80211_sta *sta,
1878 struct iwl_he_pkt_ext_v2 *pkt_ext)
1880 u8 nss = (sta->he_cap.ppe_thres[0] & IEEE80211_PPE_THRES_NSS_MASK) + 1;
1881 u8 *ppe = &sta->he_cap.ppe_thres[0];
1882 u8 ru_index_bitmap =
1884 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK);
1885 /* Starting after PPE header */
1886 u8 ppe_pos_bit = IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE;
1888 iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, ppe, ppe_pos_bit);
1891 static void iwl_mvm_set_pkt_ext_from_nominal_padding(struct iwl_he_pkt_ext_v2 *pkt_ext,
1899 switch (nominal_padding) {
1900 case IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_0US:
1901 low_th = IWL_HE_PKT_EXT_NONE;
1902 high_th = IWL_HE_PKT_EXT_NONE;
1904 case IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_8US:
1905 low_th = IWL_HE_PKT_EXT_BPSK;
1906 high_th = IWL_HE_PKT_EXT_NONE;
1908 case IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US:
1909 low_th = IWL_HE_PKT_EXT_NONE;
1910 high_th = IWL_HE_PKT_EXT_BPSK;
1914 /* Set the PPE thresholds accordingly */
1915 if (low_th >= 0 && high_th >= 0) {
1916 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
1920 bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]);
1922 pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th;
1923 pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th;
1927 *flags |= STA_CTXT_HE_PACKET_EXT;
1931 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1932 struct ieee80211_vif *vif, u8 sta_id)
1934 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1935 struct iwl_he_sta_context_cmd_v3 sta_ctxt_cmd = {
1937 .tid_limit = IWL_MAX_TID_COUNT,
1938 .bss_color = vif->bss_conf.he_bss_color.color,
1939 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
1940 .frame_time_rts_th =
1941 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
1943 struct iwl_he_sta_context_cmd_v2 sta_ctxt_cmd_v2 = {};
1944 u32 cmd_id = WIDE_ID(DATA_PATH_GROUP, STA_HE_CTXT_CMD);
1945 u8 ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 2);
1947 struct ieee80211_sta *sta;
1950 const struct ieee80211_sta_he_cap *own_he_cap = NULL;
1951 struct ieee80211_chanctx_conf *chanctx_conf;
1952 const struct ieee80211_supported_band *sband;
1955 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_MBSSID_HE))
1960 /* same layout as v2 except some data at the end */
1961 cmd = &sta_ctxt_cmd_v2;
1962 size = sizeof(struct iwl_he_sta_context_cmd_v1);
1965 cmd = &sta_ctxt_cmd_v2;
1966 size = sizeof(struct iwl_he_sta_context_cmd_v2);
1969 cmd = &sta_ctxt_cmd;
1970 size = sizeof(struct iwl_he_sta_context_cmd_v3);
1973 IWL_ERR(mvm, "bad STA_HE_CTXT_CMD version %d\n", ver);
1979 chanctx_conf = rcu_dereference(vif->chanctx_conf);
1980 if (WARN_ON(!chanctx_conf)) {
1985 sband = mvm->hw->wiphy->bands[chanctx_conf->def.chan->band];
1986 own_he_cap = ieee80211_get_he_iftype_cap(sband,
1987 ieee80211_vif_type_p2p(vif));
1989 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
1990 if (IS_ERR_OR_NULL(sta)) {
1992 WARN(1, "Can't find STA to configure HE\n");
1996 if (!sta->he_cap.has_he) {
2003 /* Block 26-tone RU OFDMA transmissions */
2004 if (mvmvif->he_ru_2mhz_block)
2005 flags |= STA_CTXT_HE_RU_2MHZ_BLOCK;
2008 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
2009 IEEE80211_HE_MAC_CAP0_HTC_HE)
2010 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
2011 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
2012 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2013 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2014 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2016 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
2017 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2018 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
2019 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2022 sta_ctxt_cmd.htc_flags |=
2023 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2024 else if (link_adap == 3)
2025 sta_ctxt_cmd.htc_flags |=
2026 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2028 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2029 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2030 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2031 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2032 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2033 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2034 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2037 * Initialize the PPE thresholds to "None" (7), as described in Table
2038 * 9-262ac of 80211.ax/D3.0.
2040 memset(&sta_ctxt_cmd.pkt_ext, IWL_HE_PKT_EXT_NONE,
2041 sizeof(sta_ctxt_cmd.pkt_ext));
2043 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2044 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2045 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2046 iwl_mvm_set_pkt_ext_from_he_ppe(mvm, sta,
2047 &sta_ctxt_cmd.pkt_ext);
2048 flags |= STA_CTXT_HE_PACKET_EXT;
2049 /* PPE Thresholds doesn't exist - set the API PPE values
2050 * according to Common Nominal Packet Padding fiels. */
2052 u8 nominal_padding =
2053 u8_get_bits(sta->he_cap.he_cap_elem.phy_cap_info[9],
2054 IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK);
2055 if (nominal_padding != IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED)
2056 iwl_mvm_set_pkt_ext_from_nominal_padding(&sta_ctxt_cmd.pkt_ext,
2061 if (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2062 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP)
2063 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2065 if (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2066 IEEE80211_HE_MAC_CAP2_ACK_EN)
2067 flags |= STA_CTXT_HE_ACK_ENABLED;
2071 /* Mark MU EDCA as enabled, unless none detected on some AC */
2072 flags |= STA_CTXT_HE_MU_EDCA_CW;
2073 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
2074 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2075 &mvmvif->queue_params[i].mu_edca_param_rec;
2076 u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
2078 if (!mvmvif->queue_params[i].mu_edca) {
2079 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2083 sta_ctxt_cmd.trig_based_txf[ac].cwmin =
2084 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2085 sta_ctxt_cmd.trig_based_txf[ac].cwmax =
2086 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2087 sta_ctxt_cmd.trig_based_txf[ac].aifsn =
2088 cpu_to_le16(mu_edca->aifsn);
2089 sta_ctxt_cmd.trig_based_txf[ac].mu_time =
2090 cpu_to_le16(mu_edca->mu_edca_timer);
2094 if (vif->bss_conf.uora_exists) {
2095 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2097 sta_ctxt_cmd.rand_alloc_ecwmin =
2098 vif->bss_conf.uora_ocw_range & 0x7;
2099 sta_ctxt_cmd.rand_alloc_ecwmax =
2100 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2103 if (own_he_cap && !(own_he_cap->he_cap_elem.mac_cap_info[2] &
2104 IEEE80211_HE_MAC_CAP2_ACK_EN))
2105 flags |= STA_CTXT_HE_NIC_NOT_ACK_ENABLED;
2107 if (vif->bss_conf.nontransmitted) {
2108 flags |= STA_CTXT_HE_REF_BSSID_VALID;
2109 ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr,
2110 vif->bss_conf.transmitter_bssid);
2111 sta_ctxt_cmd.max_bssid_indicator =
2112 vif->bss_conf.bssid_indicator;
2113 sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index;
2114 sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap;
2115 sta_ctxt_cmd.profile_periodicity =
2116 vif->bss_conf.profile_periodicity;
2119 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2122 /* fields before pkt_ext */
2123 BUILD_BUG_ON(offsetof(typeof(sta_ctxt_cmd), pkt_ext) !=
2124 offsetof(typeof(sta_ctxt_cmd_v2), pkt_ext));
2125 memcpy(&sta_ctxt_cmd_v2, &sta_ctxt_cmd,
2126 offsetof(typeof(sta_ctxt_cmd), pkt_ext));
2130 i < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th);
2135 bw < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i]);
2137 BUILD_BUG_ON(sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]) !=
2138 sizeof(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw]));
2140 memcpy(&sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw],
2141 &sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw],
2142 sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]));
2146 /* fields after pkt_ext */
2147 BUILD_BUG_ON(sizeof(sta_ctxt_cmd) -
2148 offsetofend(typeof(sta_ctxt_cmd), pkt_ext) !=
2149 sizeof(sta_ctxt_cmd_v2) -
2150 offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext));
2151 memcpy((u8 *)&sta_ctxt_cmd_v2 +
2152 offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext),
2153 (u8 *)&sta_ctxt_cmd +
2154 offsetofend(typeof(sta_ctxt_cmd), pkt_ext),
2155 sizeof(sta_ctxt_cmd) -
2156 offsetofend(typeof(sta_ctxt_cmd), pkt_ext));
2157 sta_ctxt_cmd_v2.reserved3 = 0;
2160 if (iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, size, cmd))
2161 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2164 static void iwl_mvm_protect_assoc(struct iwl_mvm *mvm,
2165 struct ieee80211_vif *vif,
2166 u32 duration_override)
2168 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
2169 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
2171 if (duration_override > duration)
2172 duration = duration_override;
2174 /* Try really hard to protect the session and hear a beacon
2175 * The new session protection command allows us to protect the
2176 * session for a much longer time since the firmware will internally
2177 * create two events: a 300TU one with a very high priority that
2178 * won't be fragmented which should be enough for 99% of the cases,
2179 * and another one (which we configure here to be 900TU long) which
2180 * will have a slightly lower priority, but more importantly, can be
2181 * fragmented so that it'll allow other activities to run.
2183 if (fw_has_capa(&mvm->fw->ucode_capa,
2184 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD))
2185 iwl_mvm_schedule_session_protection(mvm, vif, 900,
2186 min_duration, false);
2188 iwl_mvm_protect_session(mvm, vif, duration,
2189 min_duration, 500, false);
2192 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2193 struct ieee80211_vif *vif,
2194 struct ieee80211_bss_conf *bss_conf,
2197 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2201 * Re-calculate the tsf id, as the leader-follower relations depend
2202 * on the beacon interval, which was not known when the station
2203 * interface was added.
2205 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2206 if (vif->bss_conf.he_support &&
2207 !iwlwifi_mod_params.disable_11ax)
2208 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2210 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2213 /* Update MU EDCA params */
2214 if (changes & BSS_CHANGED_QOS && mvmvif->associated &&
2215 bss_conf->assoc && vif->bss_conf.he_support &&
2216 !iwlwifi_mod_params.disable_11ax)
2217 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2220 * If we're not associated yet, take the (new) BSSID before associating
2221 * so the firmware knows. If we're already associated, then use the old
2222 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2223 * branch for disassociation below.
2225 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2226 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2228 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2230 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2232 /* after sending it once, adopt mac80211 data */
2233 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2234 mvmvif->associated = bss_conf->assoc;
2236 if (changes & BSS_CHANGED_ASSOC) {
2237 if (bss_conf->assoc) {
2238 /* clear statistics to get clean beacon counter */
2239 iwl_mvm_request_statistics(mvm, true);
2240 memset(&mvmvif->beacon_stats, 0,
2241 sizeof(mvmvif->beacon_stats));
2243 /* add quota for this interface */
2244 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2246 IWL_ERR(mvm, "failed to update quotas\n");
2250 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2252 !fw_has_capa(&mvm->fw->ucode_capa,
2253 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) {
2255 * If we're restarting then the firmware will
2256 * obviously have lost synchronisation with
2257 * the AP. It will attempt to synchronise by
2258 * itself, but we can make it more reliable by
2259 * scheduling a session protection time event.
2261 * The firmware needs to receive a beacon to
2262 * catch up with synchronisation, use 110% of
2263 * the beacon interval.
2265 * Set a large maximum delay to allow for more
2266 * than a single interface.
2268 * For new firmware versions, rely on the
2269 * firmware. This is relevant for DCM scenarios
2272 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2273 iwl_mvm_protect_session(mvm, vif, dur, dur,
2275 } else if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2277 !vif->bss_conf.dtim_period) {
2279 * If we're not restarting and still haven't
2280 * heard a beacon (dtim period unknown) then
2281 * make sure we still have enough minimum time
2282 * remaining in the time event, since the auth
2283 * might actually have taken quite a while
2284 * (especially for SAE) and so the remaining
2285 * time could be small without us having heard
2288 iwl_mvm_protect_assoc(mvm, vif, 0);
2291 iwl_mvm_sf_update(mvm, vif, false);
2292 iwl_mvm_power_vif_assoc(mvm, vif);
2294 iwl_mvm_update_smps(mvm, vif,
2295 IWL_MVM_SMPS_REQ_PROT,
2296 IEEE80211_SMPS_DYNAMIC);
2298 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2299 iwl_mvm_mei_host_disassociated(mvm);
2301 * If update fails - SF might be running in associated
2302 * mode while disassociated - which is forbidden.
2304 ret = iwl_mvm_sf_update(mvm, vif, false);
2306 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
2308 "Failed to update SF upon disassociation\n");
2311 * If we get an assert during the connection (after the
2312 * station has been added, but before the vif is set
2313 * to associated), mac80211 will re-add the station and
2314 * then configure the vif. Since the vif is not
2315 * associated, we would remove the station here and
2316 * this would fail the recovery.
2318 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2321 * Remove AP station now that
2322 * the MAC is unassoc
2324 ret = iwl_mvm_rm_sta_id(mvm, vif,
2328 "failed to remove AP station\n");
2330 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2333 /* remove quota for this interface */
2334 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2336 IWL_ERR(mvm, "failed to update quotas\n");
2338 /* this will take the cleared BSSID from bss_conf */
2339 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2342 "failed to update MAC %pM (clear after unassoc)\n",
2347 * The firmware tracks the MU-MIMO group on its own.
2348 * However, on HW restart we should restore this data.
2350 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2351 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2352 ret = iwl_mvm_update_mu_groups(mvm, vif);
2355 "failed to update VHT MU_MIMO groups\n");
2358 iwl_mvm_recalc_multicast(mvm);
2360 /* reset rssi values */
2361 mvmvif->bf_data.ave_beacon_signal = 0;
2363 iwl_mvm_bt_coex_vif_change(mvm);
2364 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2365 IEEE80211_SMPS_AUTOMATIC);
2366 if (fw_has_capa(&mvm->fw->ucode_capa,
2367 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2368 iwl_mvm_config_scan(mvm);
2371 if (changes & BSS_CHANGED_BEACON_INFO) {
2373 * We received a beacon from the associated AP so
2374 * remove the session protection.
2376 iwl_mvm_stop_session_protection(mvm, vif);
2378 iwl_mvm_sf_update(mvm, vif, false);
2379 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2382 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2384 * Send power command on every beacon change,
2385 * because we may have not enabled beacon abort yet.
2387 BSS_CHANGED_BEACON_INFO)) {
2388 ret = iwl_mvm_power_update_mac(mvm);
2390 IWL_ERR(mvm, "failed to update power mode\n");
2393 if (changes & BSS_CHANGED_CQM) {
2394 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2395 /* reset cqm events tracking */
2396 mvmvif->bf_data.last_cqm_event = 0;
2397 if (mvmvif->bf_data.bf_enabled) {
2398 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2401 "failed to update CQM thresholds\n");
2405 if (changes & BSS_CHANGED_BANDWIDTH)
2406 iwl_mvm_apply_fw_smps_request(vif);
2409 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2410 struct ieee80211_vif *vif)
2412 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2413 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2416 mutex_lock(&mvm->mutex);
2418 /* Send the beacon template */
2419 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2424 * Re-calculate the tsf id, as the leader-follower relations depend on
2425 * the beacon interval, which was not known when the AP interface
2428 if (vif->type == NL80211_IFTYPE_AP)
2429 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2431 mvmvif->ap_assoc_sta_count = 0;
2433 /* Add the mac context */
2434 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2438 /* Perform the binding */
2439 ret = iwl_mvm_binding_add_vif(mvm, vif);
2444 * This is not very nice, but the simplest:
2445 * For older FWs adding the mcast sta before the bcast station may
2446 * cause assert 0x2b00.
2447 * This is fixed in later FW so make the order of removal depend on
2450 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2451 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2455 * Send the bcast station. At this stage the TBTT and DTIM time
2456 * events are added and applied to the scheduler
2458 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2460 iwl_mvm_rm_mcast_sta(mvm, vif);
2465 * Send the bcast station. At this stage the TBTT and DTIM time
2466 * events are added and applied to the scheduler
2468 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2471 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2473 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2478 /* must be set before quota calculations */
2479 mvmvif->ap_ibss_active = true;
2481 /* send all the early keys to the device now */
2482 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
2483 struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i];
2488 mvmvif->ap_early_keys[i] = NULL;
2490 ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key);
2492 goto out_quota_failed;
2495 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2496 iwl_mvm_vif_set_low_latency(mvmvif, true,
2497 LOW_LATENCY_VIF_TYPE);
2498 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2501 /* power updated needs to be done before quotas */
2502 iwl_mvm_power_update_mac(mvm);
2504 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2506 goto out_quota_failed;
2508 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2509 if (vif->p2p && mvm->p2p_device_vif)
2510 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2512 iwl_mvm_bt_coex_vif_change(mvm);
2514 /* we don't support TDLS during DCM */
2515 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2516 iwl_mvm_teardown_tdls_peers(mvm);
2518 iwl_mvm_ftm_restart_responder(mvm, vif);
2523 iwl_mvm_power_update_mac(mvm);
2524 mvmvif->ap_ibss_active = false;
2525 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2526 iwl_mvm_rm_mcast_sta(mvm, vif);
2528 iwl_mvm_binding_remove_vif(mvm, vif);
2530 iwl_mvm_mac_ctxt_remove(mvm, vif);
2532 mutex_unlock(&mvm->mutex);
2536 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2537 struct ieee80211_vif *vif)
2539 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2540 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2542 iwl_mvm_prepare_mac_removal(mvm, vif);
2544 mutex_lock(&mvm->mutex);
2546 /* Handle AP stop while in CSA */
2547 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2548 iwl_mvm_remove_time_event(mvm, mvmvif,
2549 &mvmvif->time_event_data);
2550 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2551 mvmvif->csa_countdown = false;
2554 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2555 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2556 mvm->csa_tx_block_bcn_timeout = 0;
2559 mvmvif->ap_ibss_active = false;
2560 mvm->ap_last_beacon_gp2 = 0;
2562 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2563 iwl_mvm_vif_set_low_latency(mvmvif, false,
2564 LOW_LATENCY_VIF_TYPE);
2565 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2568 iwl_mvm_bt_coex_vif_change(mvm);
2570 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2571 if (vif->p2p && mvm->p2p_device_vif)
2572 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2574 iwl_mvm_update_quotas(mvm, false, NULL);
2576 iwl_mvm_ftm_responder_clear(mvm, vif);
2579 * This is not very nice, but the simplest:
2580 * For older FWs removing the mcast sta before the bcast station may
2581 * cause assert 0x2b00.
2582 * This is fixed in later FW (which will stop beaconing when removing
2584 * So make the order of removal depend on the TLV
2586 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2587 iwl_mvm_rm_mcast_sta(mvm, vif);
2588 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2589 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2590 iwl_mvm_rm_mcast_sta(mvm, vif);
2591 iwl_mvm_binding_remove_vif(mvm, vif);
2593 iwl_mvm_power_update_mac(mvm);
2595 iwl_mvm_mac_ctxt_remove(mvm, vif);
2597 mutex_unlock(&mvm->mutex);
2601 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2602 struct ieee80211_vif *vif,
2603 struct ieee80211_bss_conf *bss_conf,
2606 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2608 /* Changes will be applied when the AP/IBSS is started */
2609 if (!mvmvif->ap_ibss_active)
2612 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2613 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2614 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2615 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2617 /* Need to send a new beacon template to the FW */
2618 if (changes & BSS_CHANGED_BEACON &&
2619 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2620 IWL_WARN(mvm, "Failed updating beacon data\n");
2622 if (changes & BSS_CHANGED_FTM_RESPONDER) {
2623 int ret = iwl_mvm_ftm_start_responder(mvm, vif);
2626 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
2632 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2633 struct ieee80211_vif *vif,
2634 struct ieee80211_bss_conf *bss_conf,
2637 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2639 mutex_lock(&mvm->mutex);
2641 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2642 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2644 switch (vif->type) {
2645 case NL80211_IFTYPE_STATION:
2646 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2648 case NL80211_IFTYPE_AP:
2649 case NL80211_IFTYPE_ADHOC:
2650 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2652 case NL80211_IFTYPE_MONITOR:
2653 if (changes & BSS_CHANGED_MU_GROUPS)
2654 iwl_mvm_update_mu_groups(mvm, vif);
2657 /* shouldn't happen */
2661 if (changes & BSS_CHANGED_TXPOWER) {
2662 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n",
2664 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2667 mutex_unlock(&mvm->mutex);
2670 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2671 struct ieee80211_vif *vif,
2672 struct ieee80211_scan_request *hw_req)
2674 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2677 if (hw_req->req.n_channels == 0 ||
2678 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2681 mutex_lock(&mvm->mutex);
2682 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2683 mutex_unlock(&mvm->mutex);
2688 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2689 struct ieee80211_vif *vif)
2691 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2693 mutex_lock(&mvm->mutex);
2695 /* Due to a race condition, it's possible that mac80211 asks
2696 * us to stop a hw_scan when it's already stopped. This can
2697 * happen, for instance, if we stopped the scan ourselves,
2698 * called ieee80211_scan_completed() and the userspace called
2699 * cancel scan scan before ieee80211_scan_work() could run.
2700 * To handle that, simply return if the scan is not running.
2702 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2703 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2705 mutex_unlock(&mvm->mutex);
2709 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2710 struct ieee80211_sta *sta, u16 tids,
2712 enum ieee80211_frame_release_type reason,
2715 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2717 /* Called when we need to transmit (a) frame(s) from mac80211 */
2719 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2720 tids, more_data, false);
2724 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2725 struct ieee80211_sta *sta, u16 tids,
2727 enum ieee80211_frame_release_type reason,
2730 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2732 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2734 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2735 tids, more_data, true);
2738 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2739 enum sta_notify_cmd cmd,
2740 struct ieee80211_sta *sta)
2742 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2743 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2744 unsigned long txqs = 0, tids = 0;
2748 * If we have TVQM then we get too high queue numbers - luckily
2749 * we really shouldn't get here with that because such hardware
2750 * should have firmware supporting buffer station offload.
2752 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2755 spin_lock_bh(&mvmsta->lock);
2756 for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) {
2757 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2759 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2762 __set_bit(tid_data->txq_id, &txqs);
2764 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2767 __set_bit(tid, &tids);
2771 case STA_NOTIFY_SLEEP:
2772 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2773 ieee80211_sta_set_buffered(sta, tid, true);
2776 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2778 * The fw updates the STA to be asleep. Tx packets on the Tx
2779 * queues to this station will not be transmitted. The fw will
2780 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2783 case STA_NOTIFY_AWAKE:
2784 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2788 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2789 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2794 spin_unlock_bh(&mvmsta->lock);
2797 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2798 struct ieee80211_vif *vif,
2799 enum sta_notify_cmd cmd,
2800 struct ieee80211_sta *sta)
2802 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2805 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2807 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2808 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2809 struct ieee80211_sta *sta;
2810 struct iwl_mvm_sta *mvmsta;
2811 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2813 if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations))
2817 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2818 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2823 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2826 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2831 if (mvmsta->sleeping != sleeping) {
2832 mvmsta->sleeping = sleeping;
2833 __iwl_mvm_mac_sta_notify(mvm->hw,
2834 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2836 ieee80211_sta_ps_transition(sta, sleeping);
2840 switch (notif->type) {
2841 case IWL_MVM_PM_EVENT_AWAKE:
2842 case IWL_MVM_PM_EVENT_ASLEEP:
2844 case IWL_MVM_PM_EVENT_UAPSD:
2845 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2847 case IWL_MVM_PM_EVENT_PS_POLL:
2848 ieee80211_sta_pspoll(sta);
2858 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2859 struct ieee80211_vif *vif,
2860 struct ieee80211_sta *sta)
2862 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2863 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2866 * This is called before mac80211 does RCU synchronisation,
2867 * so here we already invalidate our internal RCU-protected
2868 * station pointer. The rest of the code will thus no longer
2869 * be able to find the station this way, and we don't rely
2870 * on further RCU synchronisation after the sta_state()
2871 * callback deleted the station.
2873 mutex_lock(&mvm->mutex);
2874 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2875 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2878 mutex_unlock(&mvm->mutex);
2881 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2886 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2887 struct iwl_mvm_tcm_mac *mdata;
2889 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2890 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2891 mdata->opened_rx_ba_sessions = false;
2894 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2897 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2898 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2903 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2904 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2908 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2909 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2910 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2915 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2919 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2920 struct ieee80211_vif *vif, u8 *peer_addr,
2921 enum nl80211_tdls_operation action)
2923 struct iwl_fw_dbg_trigger_tlv *trig;
2924 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2926 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
2927 FW_DBG_TRIGGER_TDLS);
2931 tdls_trig = (void *)trig->data;
2933 if (!(tdls_trig->action_bitmap & BIT(action)))
2936 if (tdls_trig->peer_mode &&
2937 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2940 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2941 "TDLS event occurred, peer %pM, action %d",
2945 struct iwl_mvm_he_obss_narrow_bw_ru_data {
2949 static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy,
2950 struct cfg80211_bss *bss,
2953 struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data;
2954 const struct cfg80211_bss_ies *ies;
2955 const struct element *elem;
2958 ies = rcu_dereference(bss->ies);
2959 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data,
2962 if (!elem || elem->datalen < 10 ||
2964 WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) {
2965 data->tolerated = false;
2970 static void iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw,
2971 struct ieee80211_vif *vif)
2973 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2974 struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = {
2978 if (!(vif->bss_conf.chandef.chan->flags & IEEE80211_CHAN_RADAR)) {
2979 mvmvif->he_ru_2mhz_block = false;
2983 cfg80211_bss_iter(hw->wiphy, &vif->bss_conf.chandef,
2984 iwl_mvm_check_he_obss_narrow_bw_ru_iter,
2988 * If there is at least one AP on radar channel that cannot
2989 * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
2991 mvmvif->he_ru_2mhz_block = !iter_data.tolerated;
2994 static void iwl_mvm_reset_cca_40mhz_workaround(struct iwl_mvm *mvm,
2995 struct ieee80211_vif *vif)
2997 struct ieee80211_supported_band *sband;
2998 const struct ieee80211_sta_he_cap *he_cap;
3000 if (vif->type != NL80211_IFTYPE_STATION)
3003 if (!mvm->cca_40mhz_workaround)
3006 /* decrement and check that we reached zero */
3007 mvm->cca_40mhz_workaround--;
3008 if (mvm->cca_40mhz_workaround)
3011 sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ];
3013 sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3015 he_cap = ieee80211_get_he_iftype_cap(sband,
3016 ieee80211_vif_type_p2p(vif));
3019 /* we know that ours is writable */
3020 struct ieee80211_sta_he_cap *he = (void *)(uintptr_t)he_cap;
3022 he->he_cap_elem.phy_cap_info[0] |=
3023 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
3027 static void iwl_mvm_mei_host_associated(struct iwl_mvm *mvm,
3028 struct ieee80211_vif *vif,
3029 struct iwl_mvm_sta *mvm_sta)
3031 #if IS_ENABLED(CONFIG_IWLMEI)
3032 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3033 struct iwl_mei_conn_info conn_info = {
3034 .ssid_len = vif->bss_conf.ssid_len,
3035 .channel = vif->bss_conf.chandef.chan->hw_value,
3038 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3041 if (!mvm->mei_registered)
3044 switch (mvm_sta->pairwise_cipher) {
3045 case WLAN_CIPHER_SUITE_CCMP:
3046 conn_info.pairwise_cipher = IWL_MEI_CIPHER_CCMP;
3048 case WLAN_CIPHER_SUITE_GCMP:
3049 conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP;
3051 case WLAN_CIPHER_SUITE_GCMP_256:
3052 conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP_256;
3058 /* cipher not supported, don't send anything to iwlmei */
3062 switch (mvmvif->rekey_data.akm) {
3063 case WLAN_AKM_SUITE_SAE & 0xff:
3064 conn_info.auth_mode = IWL_MEI_AKM_AUTH_SAE;
3066 case WLAN_AKM_SUITE_PSK & 0xff:
3067 conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA_PSK;
3069 case WLAN_AKM_SUITE_8021X & 0xff:
3070 conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA;
3074 conn_info.auth_mode = IWL_MEI_AKM_AUTH_OPEN;
3077 /* auth method / AKM not supported */
3078 /* TODO: All the FT vesions of these? */
3082 memcpy(conn_info.ssid, vif->bss_conf.ssid, vif->bss_conf.ssid_len);
3083 memcpy(conn_info.bssid, vif->bss_conf.bssid, ETH_ALEN);
3085 /* TODO: add support for collocated AP data */
3086 iwl_mei_host_associated(&conn_info, NULL);
3090 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
3091 struct ieee80211_vif *vif,
3092 struct ieee80211_sta *sta,
3093 enum ieee80211_sta_state old_state,
3094 enum ieee80211_sta_state new_state)
3096 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3097 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3098 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3101 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
3102 sta->addr, old_state, new_state);
3104 /* this would be a mac80211 bug ... but don't crash */
3105 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
3106 return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL;
3109 * If we are in a STA removal flow and in DQA mode:
3111 * This is after the sync_rcu part, so the queues have already been
3112 * flushed. No more TXs on their way in mac80211's path, and no more in
3114 * Also, we won't be getting any new TX frames for this station.
3115 * What we might have are deferred TX frames that need to be taken care
3118 * Drop any still-queued deferred-frame before removing the STA, and
3119 * make sure the worker is no longer handling frames for this STA.
3121 if (old_state == IEEE80211_STA_NONE &&
3122 new_state == IEEE80211_STA_NOTEXIST) {
3123 flush_work(&mvm->add_stream_wk);
3126 * No need to make sure deferred TX indication is off since the
3127 * worker will already remove it if it was on
3131 * Additionally, reset the 40 MHz capability if we disconnected
3134 iwl_mvm_reset_cca_40mhz_workaround(mvm, vif);
3137 mutex_lock(&mvm->mutex);
3138 /* track whether or not the station is associated */
3139 mvm_sta->sta_state = new_state;
3141 if (old_state == IEEE80211_STA_NOTEXIST &&
3142 new_state == IEEE80211_STA_NONE) {
3144 * Firmware bug - it'll crash if the beacon interval is less
3145 * than 16. We can't avoid connecting at all, so refuse the
3146 * station state change, this will cause mac80211 to abandon
3147 * attempts to connect to this AP, and eventually wpa_s will
3148 * blocklist the AP...
3150 if (vif->type == NL80211_IFTYPE_STATION &&
3151 vif->bss_conf.beacon_int < 16) {
3153 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
3154 sta->addr, vif->bss_conf.beacon_int);
3159 if (vif->type == NL80211_IFTYPE_STATION)
3160 vif->bss_conf.he_support = sta->he_cap.has_he;
3164 iwl_mvm_tdls_sta_count(mvm, NULL) ==
3165 IWL_MVM_TDLS_STA_COUNT ||
3166 iwl_mvm_phy_ctx_count(mvm) > 1)) {
3167 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
3172 ret = iwl_mvm_add_sta(mvm, vif, sta);
3173 if (sta->tdls && ret == 0) {
3174 iwl_mvm_recalc_tdls_state(mvm, vif, true);
3175 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3176 NL80211_TDLS_SETUP);
3179 sta->max_rc_amsdu_len = 1;
3180 } else if (old_state == IEEE80211_STA_NONE &&
3181 new_state == IEEE80211_STA_AUTH) {
3183 * EBS may be disabled due to previous failures reported by FW.
3184 * Reset EBS status here assuming environment has been changed.
3186 mvm->last_ebs_successful = true;
3187 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
3189 } else if (old_state == IEEE80211_STA_AUTH &&
3190 new_state == IEEE80211_STA_ASSOC) {
3191 if (vif->type == NL80211_IFTYPE_AP) {
3192 vif->bss_conf.he_support = sta->he_cap.has_he;
3193 mvmvif->ap_assoc_sta_count++;
3194 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3195 if (vif->bss_conf.he_support &&
3196 !iwlwifi_mod_params.disable_11ax)
3197 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id);
3198 } else if (vif->type == NL80211_IFTYPE_STATION) {
3199 vif->bss_conf.he_support = sta->he_cap.has_he;
3201 mvmvif->he_ru_2mhz_block = false;
3202 if (sta->he_cap.has_he)
3203 iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif);
3205 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3208 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3210 ret = iwl_mvm_update_sta(mvm, vif, sta);
3211 } else if (old_state == IEEE80211_STA_ASSOC &&
3212 new_state == IEEE80211_STA_AUTHORIZED) {
3215 /* we don't support TDLS during DCM */
3216 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3217 iwl_mvm_teardown_tdls_peers(mvm);
3220 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3221 NL80211_TDLS_ENABLE_LINK);
3223 /* enable beacon filtering */
3224 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
3226 mvmvif->authorized = 1;
3229 * Now that the station is authorized, i.e., keys were already
3230 * installed, need to indicate to the FW that
3231 * multicast data frames can be forwarded to the driver
3233 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3234 iwl_mvm_mei_host_associated(mvm, vif, mvm_sta);
3237 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3239 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3240 new_state == IEEE80211_STA_ASSOC) {
3241 /* once we move into assoc state, need to update rate scale to
3242 * disable using wide bandwidth
3244 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3247 /* Multicast data frames are no longer allowed */
3248 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3251 * Set this after the above iwl_mvm_mac_ctxt_changed()
3252 * to avoid sending high prio again for a little time.
3254 mvmvif->authorized = 0;
3256 /* disable beacon filtering */
3257 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3259 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3263 } else if (old_state == IEEE80211_STA_ASSOC &&
3264 new_state == IEEE80211_STA_AUTH) {
3265 if (vif->type == NL80211_IFTYPE_AP) {
3266 mvmvif->ap_assoc_sta_count--;
3267 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3268 } else if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
3269 iwl_mvm_stop_session_protection(mvm, vif);
3271 } else if (old_state == IEEE80211_STA_AUTH &&
3272 new_state == IEEE80211_STA_NONE) {
3274 } else if (old_state == IEEE80211_STA_NONE &&
3275 new_state == IEEE80211_STA_NOTEXIST) {
3276 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
3277 iwl_mvm_stop_session_protection(mvm, vif);
3278 ret = iwl_mvm_rm_sta(mvm, vif, sta);
3280 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3281 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3282 NL80211_TDLS_DISABLE_LINK);
3286 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3293 mutex_unlock(&mvm->mutex);
3295 if (sta->tdls && ret == 0) {
3296 if (old_state == IEEE80211_STA_NOTEXIST &&
3297 new_state == IEEE80211_STA_NONE)
3298 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3299 else if (old_state == IEEE80211_STA_NONE &&
3300 new_state == IEEE80211_STA_NOTEXIST)
3301 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3307 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3309 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3311 mvm->rts_threshold = value;
3316 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3317 struct ieee80211_vif *vif,
3318 struct ieee80211_sta *sta, u32 changed)
3320 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3321 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3323 if (changed & (IEEE80211_RC_BW_CHANGED |
3324 IEEE80211_RC_SUPP_RATES_CHANGED |
3325 IEEE80211_RC_NSS_CHANGED))
3326 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3329 if (vif->type == NL80211_IFTYPE_STATION &&
3330 changed & IEEE80211_RC_NSS_CHANGED)
3331 iwl_mvm_sf_update(mvm, vif, false);
3334 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3335 struct ieee80211_vif *vif, u16 ac,
3336 const struct ieee80211_tx_queue_params *params)
3338 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3339 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3341 mvmvif->queue_params[ac] = *params;
3344 * No need to update right away, we'll get BSS_CHANGED_QOS
3345 * The exception is P2P_DEVICE interface which needs immediate update.
3347 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3350 mutex_lock(&mvm->mutex);
3351 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3352 mutex_unlock(&mvm->mutex);
3358 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3359 struct ieee80211_vif *vif,
3360 struct ieee80211_prep_tx_info *info)
3362 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3364 mutex_lock(&mvm->mutex);
3365 iwl_mvm_protect_assoc(mvm, vif, info->duration);
3366 mutex_unlock(&mvm->mutex);
3369 static void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw,
3370 struct ieee80211_vif *vif,
3371 struct ieee80211_prep_tx_info *info)
3373 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3375 /* for successful cases (auth/assoc), don't cancel session protection */
3379 mutex_lock(&mvm->mutex);
3380 iwl_mvm_stop_session_protection(mvm, vif);
3381 mutex_unlock(&mvm->mutex);
3384 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3385 struct ieee80211_vif *vif,
3386 struct cfg80211_sched_scan_request *req,
3387 struct ieee80211_scan_ies *ies)
3389 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3393 mutex_lock(&mvm->mutex);
3395 if (!vif->bss_conf.idle) {
3400 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3403 mutex_unlock(&mvm->mutex);
3407 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3408 struct ieee80211_vif *vif)
3410 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3413 mutex_lock(&mvm->mutex);
3415 /* Due to a race condition, it's possible that mac80211 asks
3416 * us to stop a sched_scan when it's already stopped. This
3417 * can happen, for instance, if we stopped the scan ourselves,
3418 * called ieee80211_sched_scan_stopped() and the userspace called
3419 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3420 * could run. To handle this, simply return if the scan is
3423 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3424 mutex_unlock(&mvm->mutex);
3428 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3429 mutex_unlock(&mvm->mutex);
3430 iwl_mvm_wait_for_async_handlers(mvm);
3435 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3436 enum set_key_cmd cmd,
3437 struct ieee80211_vif *vif,
3438 struct ieee80211_sta *sta,
3439 struct ieee80211_key_conf *key)
3441 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3442 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3443 struct iwl_mvm_sta *mvmsta = NULL;
3444 struct iwl_mvm_key_pn *ptk_pn;
3445 int keyidx = key->keyidx;
3450 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3452 switch (key->cipher) {
3453 case WLAN_CIPHER_SUITE_TKIP:
3454 if (!mvm->trans->trans_cfg->gen2) {
3455 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3456 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3457 } else if (vif->type == NL80211_IFTYPE_STATION) {
3458 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3460 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3464 case WLAN_CIPHER_SUITE_CCMP:
3465 case WLAN_CIPHER_SUITE_GCMP:
3466 case WLAN_CIPHER_SUITE_GCMP_256:
3467 if (!iwl_mvm_has_new_tx_api(mvm))
3468 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3470 case WLAN_CIPHER_SUITE_AES_CMAC:
3471 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3472 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3473 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3475 case WLAN_CIPHER_SUITE_WEP40:
3476 case WLAN_CIPHER_SUITE_WEP104:
3477 if (vif->type == NL80211_IFTYPE_STATION)
3479 if (iwl_mvm_has_new_tx_api(mvm))
3481 /* support HW crypto on TX */
3489 if (keyidx == 6 || keyidx == 7)
3490 rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6],
3493 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3494 vif->type == NL80211_IFTYPE_AP) && !sta) {
3496 * GTK on AP interface is a TX-only key, return 0;
3497 * on IBSS they're per-station and because we're lazy
3498 * we don't support them for RX, so do the same.
3499 * CMAC/GMAC in AP/IBSS modes must be done in software.
3501 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3502 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3503 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) {
3508 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3509 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3510 !iwl_mvm_has_new_tx_api(mvm)) {
3511 key->hw_key_idx = STA_KEY_IDX_INVALID;
3516 if (!mvmvif->ap_ibss_active) {
3518 i < ARRAY_SIZE(mvmvif->ap_early_keys);
3520 if (!mvmvif->ap_early_keys[i]) {
3521 mvmvif->ap_early_keys[i] = key;
3526 if (i >= ARRAY_SIZE(mvmvif->ap_early_keys))
3535 /* During FW restart, in order to restore the state as it was,
3536 * don't try to reprogram keys we previously failed for.
3538 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3539 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3540 IWL_DEBUG_MAC80211(mvm,
3541 "skip invalid idx key programming during restart\n");
3546 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3547 mvmsta && iwl_mvm_has_new_rx_api(mvm) &&
3548 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3549 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3550 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3551 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3552 struct ieee80211_key_seq seq;
3555 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3556 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3557 mvm->trans->num_rx_queues),
3564 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3565 ieee80211_get_key_rx_seq(key, tid, &seq);
3566 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3567 memcpy(ptk_pn->q[q].pn[tid],
3569 IEEE80211_CCMP_PN_LEN);
3572 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3575 /* in HW restart reuse the index, otherwise request a new one */
3576 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3577 key_offset = key->hw_key_idx;
3579 key_offset = STA_KEY_IDX_INVALID;
3581 if (mvmsta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3582 mvmsta->pairwise_cipher = key->cipher;
3584 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3585 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3587 IWL_WARN(mvm, "set key failed\n");
3588 key->hw_key_idx = STA_KEY_IDX_INVALID;
3590 * can't add key for RX, but we don't need it
3591 * in the device for TX so still return 0,
3592 * unless we have new TX API where we cannot
3593 * put key material into the TX_CMD
3595 if (iwl_mvm_has_new_tx_api(mvm))
3603 if (keyidx == 6 || keyidx == 7)
3604 RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6],
3608 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
3609 if (mvmvif->ap_early_keys[i] == key) {
3610 mvmvif->ap_early_keys[i] = NULL;
3615 /* found in pending list - don't do anything else */
3619 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3624 if (mvmsta && iwl_mvm_has_new_rx_api(mvm) &&
3625 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3626 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3627 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3628 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3629 ptk_pn = rcu_dereference_protected(
3630 mvmsta->ptk_pn[keyidx],
3631 lockdep_is_held(&mvm->mutex));
3632 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3634 kfree_rcu(ptk_pn, rcu_head);
3637 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3638 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3647 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3648 enum set_key_cmd cmd,
3649 struct ieee80211_vif *vif,
3650 struct ieee80211_sta *sta,
3651 struct ieee80211_key_conf *key)
3653 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3656 mutex_lock(&mvm->mutex);
3657 ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key);
3658 mutex_unlock(&mvm->mutex);
3663 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3664 struct ieee80211_vif *vif,
3665 struct ieee80211_key_conf *keyconf,
3666 struct ieee80211_sta *sta,
3667 u32 iv32, u16 *phase1key)
3669 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3671 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3674 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3678 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3679 struct iwl_rx_packet *pkt, void *data)
3681 struct iwl_mvm *mvm =
3682 container_of(notif_wait, struct iwl_mvm, notif_wait);
3683 struct iwl_hs20_roc_res *resp;
3684 int resp_len = iwl_rx_packet_payload_len(pkt);
3685 struct iwl_mvm_time_event_data *te_data = data;
3687 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3690 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3691 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3695 resp = (void *)pkt->data;
3698 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
3699 resp->status, resp->event_unique_id);
3701 te_data->uid = le32_to_cpu(resp->event_unique_id);
3702 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3705 spin_lock_bh(&mvm->time_event_lock);
3706 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3707 spin_unlock_bh(&mvm->time_event_lock);
3712 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3713 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3714 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3715 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3716 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3717 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3718 struct ieee80211_channel *channel,
3719 struct ieee80211_vif *vif,
3723 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3724 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3725 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3726 struct iwl_notification_wait wait_time_event;
3727 u32 dtim_interval = vif->bss_conf.dtim_period *
3728 vif->bss_conf.beacon_int;
3730 struct iwl_hs20_roc_req aux_roc_req = {
3731 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3733 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3734 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3736 struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm,
3737 &aux_roc_req.channel_info);
3738 u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm);
3740 /* Set the channel info data */
3741 iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value,
3742 iwl_mvm_phy_band_from_nl80211(channel->band),
3743 PHY_VHT_CHANNEL_MODE20,
3746 /* Set the time and duration */
3747 tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm));
3749 delay = AUX_ROC_MIN_DELAY;
3750 req_dur = MSEC_TO_TU(duration);
3753 * If we are associated we want the delay time to be at least one
3754 * dtim interval so that the FW can wait until after the DTIM and
3755 * then start the time event, this will potentially allow us to
3756 * remain off-channel for the max duration.
3757 * Since we want to use almost a whole dtim interval we would also
3758 * like the delay to be for 2-3 dtim intervals, in case there are
3759 * other time events with higher priority.
3761 if (vif->bss_conf.assoc) {
3762 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3763 /* We cannot remain off-channel longer than the DTIM interval */
3764 if (dtim_interval <= req_dur) {
3765 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3766 if (req_dur <= AUX_ROC_MIN_DURATION)
3767 req_dur = dtim_interval -
3768 AUX_ROC_MIN_SAFETY_BUFFER;
3772 tail->duration = cpu_to_le32(req_dur);
3773 tail->apply_time_max_delay = cpu_to_le32(delay);
3776 "ROC: Requesting to remain on channel %u for %ums\n",
3777 channel->hw_value, req_dur);
3779 "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3780 duration, delay, dtim_interval);
3782 /* Set the node address */
3783 memcpy(tail->node_addr, vif->addr, ETH_ALEN);
3785 lockdep_assert_held(&mvm->mutex);
3787 spin_lock_bh(&mvm->time_event_lock);
3789 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3790 spin_unlock_bh(&mvm->time_event_lock);
3795 te_data->duration = duration;
3796 te_data->id = HOT_SPOT_CMD;
3798 spin_unlock_bh(&mvm->time_event_lock);
3801 * Use a notification wait, which really just processes the
3802 * command response and doesn't wait for anything, in order
3803 * to be able to process the response and get the UID inside
3804 * the RX path. Using CMD_WANT_SKB doesn't work because it
3805 * stores the buffer and then wakes up this thread, by which
3806 * time another notification (that the time event started)
3807 * might already be processed unsuccessfully.
3809 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3810 time_event_response,
3811 ARRAY_SIZE(time_event_response),
3812 iwl_mvm_rx_aux_roc, te_data);
3814 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len,
3818 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3819 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3823 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3824 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3825 /* should never fail */
3830 spin_lock_bh(&mvm->time_event_lock);
3831 iwl_mvm_te_clear_data(mvm, te_data);
3832 spin_unlock_bh(&mvm->time_event_lock);
3838 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3839 struct ieee80211_vif *vif,
3840 struct ieee80211_channel *channel,
3842 enum ieee80211_roc_type type)
3844 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3845 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3846 struct cfg80211_chan_def chandef;
3847 struct iwl_mvm_phy_ctxt *phy_ctxt;
3848 bool band_change_removal;
3851 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3855 * Flush the done work, just in case it's still pending, so that
3856 * the work it does can complete and we can accept new frames.
3858 flush_work(&mvm->roc_done_wk);
3860 mutex_lock(&mvm->mutex);
3862 switch (vif->type) {
3863 case NL80211_IFTYPE_STATION:
3864 if (fw_has_capa(&mvm->fw->ucode_capa,
3865 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3866 /* Use aux roc framework (HS20) */
3867 if (iwl_fw_lookup_cmd_ver(mvm->fw, ADD_STA, 0) >= 12) {
3870 lmac_id = iwl_mvm_get_lmac_id(mvm->fw,
3872 ret = iwl_mvm_add_aux_sta(mvm, lmac_id);
3874 "Failed to allocate aux station"))
3877 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3881 IWL_ERR(mvm, "hotspot not supported\n");
3884 case NL80211_IFTYPE_P2P_DEVICE:
3888 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3893 for (i = 0; i < NUM_PHY_CTX; i++) {
3894 phy_ctxt = &mvm->phy_ctxts[i];
3895 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3898 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3900 * Unbind the P2P_DEVICE from the current PHY context,
3901 * and if the PHY context is not used remove it.
3903 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3904 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3907 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3909 /* Bind the P2P_DEVICE to the current PHY Context */
3910 mvmvif->phy_ctxt = phy_ctxt;
3912 ret = iwl_mvm_binding_add_vif(mvm, vif);
3913 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3916 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3917 goto schedule_time_event;
3921 /* Need to update the PHY context only if the ROC channel changed */
3922 if (channel == mvmvif->phy_ctxt->channel)
3923 goto schedule_time_event;
3925 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3928 * Check if the remain-on-channel is on a different band and that
3929 * requires context removal, see iwl_mvm_phy_ctxt_changed(). If
3930 * so, we'll need to release and then re-configure here, since we
3931 * must not remove a PHY context that's part of a binding.
3933 band_change_removal =
3934 fw_has_capa(&mvm->fw->ucode_capa,
3935 IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT) &&
3936 mvmvif->phy_ctxt->channel->band != chandef.chan->band;
3938 if (mvmvif->phy_ctxt->ref == 1 && !band_change_removal) {
3940 * Change the PHY context configuration as it is currently
3941 * referenced only by the P2P Device MAC (and we can modify it)
3943 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3949 * The PHY context is shared with other MACs (or we're trying to
3950 * switch bands), so remove the P2P Device from the binding,
3951 * allocate an new PHY context and create a new binding.
3953 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3959 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3962 IWL_ERR(mvm, "Failed to change PHY context\n");
3966 /* Unbind the P2P_DEVICE from the current PHY context */
3967 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3968 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3971 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3973 /* Bind the P2P_DEVICE to the new allocated PHY context */
3974 mvmvif->phy_ctxt = phy_ctxt;
3976 ret = iwl_mvm_binding_add_vif(mvm, vif);
3977 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3980 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3983 schedule_time_event:
3984 /* Schedule the time events */
3985 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3988 mutex_unlock(&mvm->mutex);
3989 IWL_DEBUG_MAC80211(mvm, "leave\n");
3993 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw,
3994 struct ieee80211_vif *vif)
3996 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3998 IWL_DEBUG_MAC80211(mvm, "enter\n");
4000 mutex_lock(&mvm->mutex);
4001 iwl_mvm_stop_roc(mvm, vif);
4002 mutex_unlock(&mvm->mutex);
4004 IWL_DEBUG_MAC80211(mvm, "leave\n");
4008 struct iwl_mvm_ftm_responder_iter_data {
4010 struct ieee80211_chanctx_conf *ctx;
4013 static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac,
4014 struct ieee80211_vif *vif)
4016 struct iwl_mvm_ftm_responder_iter_data *data = _data;
4018 if (rcu_access_pointer(vif->chanctx_conf) == data->ctx &&
4019 vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params)
4020 data->responder = true;
4023 static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm,
4024 struct ieee80211_chanctx_conf *ctx)
4026 struct iwl_mvm_ftm_responder_iter_data data = {
4031 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
4032 IEEE80211_IFACE_ITER_NORMAL,
4033 iwl_mvm_ftm_responder_chanctx_iter,
4035 return data.responder;
4038 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
4039 struct ieee80211_chanctx_conf *ctx)
4041 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4042 struct iwl_mvm_phy_ctxt *phy_ctxt;
4043 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4044 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
4047 lockdep_assert_held(&mvm->mutex);
4049 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
4051 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
4057 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4058 ctx->rx_chains_static,
4059 ctx->rx_chains_dynamic);
4061 IWL_ERR(mvm, "Failed to add PHY context\n");
4065 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
4066 *phy_ctxt_id = phy_ctxt->id;
4071 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
4072 struct ieee80211_chanctx_conf *ctx)
4074 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4077 mutex_lock(&mvm->mutex);
4078 ret = __iwl_mvm_add_chanctx(mvm, ctx);
4079 mutex_unlock(&mvm->mutex);
4084 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
4085 struct ieee80211_chanctx_conf *ctx)
4087 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4088 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4090 lockdep_assert_held(&mvm->mutex);
4092 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
4095 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
4096 struct ieee80211_chanctx_conf *ctx)
4098 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4100 mutex_lock(&mvm->mutex);
4101 __iwl_mvm_remove_chanctx(mvm, ctx);
4102 mutex_unlock(&mvm->mutex);
4105 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
4106 struct ieee80211_chanctx_conf *ctx,
4109 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4110 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4111 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4112 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4113 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
4115 if (WARN_ONCE((phy_ctxt->ref > 1) &&
4116 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
4117 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
4118 IEEE80211_CHANCTX_CHANGE_RADAR |
4119 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
4120 "Cannot change PHY. Ref=%d, changed=0x%X\n",
4121 phy_ctxt->ref, changed))
4124 mutex_lock(&mvm->mutex);
4126 /* we are only changing the min_width, may be a noop */
4127 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
4128 if (phy_ctxt->width == def->width)
4131 /* we are just toggling between 20_NOHT and 20 */
4132 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
4133 def->width <= NL80211_CHAN_WIDTH_20)
4137 iwl_mvm_bt_coex_vif_change(mvm);
4138 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4139 ctx->rx_chains_static,
4140 ctx->rx_chains_dynamic);
4143 mutex_unlock(&mvm->mutex);
4146 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
4147 struct ieee80211_vif *vif,
4148 struct ieee80211_chanctx_conf *ctx,
4149 bool switching_chanctx)
4151 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4152 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4153 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4156 lockdep_assert_held(&mvm->mutex);
4158 mvmvif->phy_ctxt = phy_ctxt;
4160 switch (vif->type) {
4161 case NL80211_IFTYPE_AP:
4162 /* only needed if we're switching chanctx (i.e. during CSA) */
4163 if (switching_chanctx) {
4164 mvmvif->ap_ibss_active = true;
4168 case NL80211_IFTYPE_ADHOC:
4170 * The AP binding flow is handled as part of the start_ap flow
4171 * (in bss_info_changed), similarly for IBSS.
4175 case NL80211_IFTYPE_STATION:
4176 mvmvif->csa_bcn_pending = false;
4178 case NL80211_IFTYPE_MONITOR:
4179 /* always disable PS when a monitor interface is active */
4180 mvmvif->ps_disabled = true;
4187 ret = iwl_mvm_binding_add_vif(mvm, vif);
4192 * Power state must be updated before quotas,
4193 * otherwise fw will complain.
4195 iwl_mvm_power_update_mac(mvm);
4197 /* Setting the quota at this stage is only required for monitor
4198 * interfaces. For the other types, the bss_info changed flow
4199 * will handle quota settings.
4201 if (vif->type == NL80211_IFTYPE_MONITOR) {
4202 mvmvif->monitor_active = true;
4203 ret = iwl_mvm_update_quotas(mvm, false, NULL);
4205 goto out_remove_binding;
4207 ret = iwl_mvm_add_snif_sta(mvm, vif);
4209 goto out_remove_binding;
4213 /* Handle binding during CSA */
4214 if (vif->type == NL80211_IFTYPE_AP) {
4215 iwl_mvm_update_quotas(mvm, false, NULL);
4216 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4219 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
4220 mvmvif->csa_bcn_pending = true;
4222 if (!fw_has_capa(&mvm->fw->ucode_capa,
4223 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4224 u32 duration = 3 * vif->bss_conf.beacon_int;
4226 /* Protect the session to make sure we hear the first
4227 * beacon on the new channel.
4229 iwl_mvm_protect_session(mvm, vif, duration, duration,
4230 vif->bss_conf.beacon_int / 2,
4234 iwl_mvm_update_quotas(mvm, false, NULL);
4240 iwl_mvm_binding_remove_vif(mvm, vif);
4241 iwl_mvm_power_update_mac(mvm);
4244 mvmvif->phy_ctxt = NULL;
4247 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
4248 struct ieee80211_vif *vif,
4249 struct ieee80211_chanctx_conf *ctx)
4251 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4254 mutex_lock(&mvm->mutex);
4255 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
4256 mutex_unlock(&mvm->mutex);
4261 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
4262 struct ieee80211_vif *vif,
4263 struct ieee80211_chanctx_conf *ctx,
4264 bool switching_chanctx)
4266 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4267 struct ieee80211_vif *disabled_vif = NULL;
4269 lockdep_assert_held(&mvm->mutex);
4270 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
4272 switch (vif->type) {
4273 case NL80211_IFTYPE_ADHOC:
4275 case NL80211_IFTYPE_MONITOR:
4276 mvmvif->monitor_active = false;
4277 mvmvif->ps_disabled = false;
4278 iwl_mvm_rm_snif_sta(mvm, vif);
4280 case NL80211_IFTYPE_AP:
4281 /* This part is triggered only during CSA */
4282 if (!switching_chanctx || !mvmvif->ap_ibss_active)
4285 mvmvif->csa_countdown = false;
4287 /* Set CS bit on all the stations */
4288 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
4290 /* Save blocked iface, the timeout is set on the next beacon */
4291 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
4293 mvmvif->ap_ibss_active = false;
4295 case NL80211_IFTYPE_STATION:
4296 if (!switching_chanctx)
4301 if (!fw_has_capa(&mvm->fw->ucode_capa,
4302 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
4303 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
4309 iwl_mvm_update_quotas(mvm, false, disabled_vif);
4310 iwl_mvm_binding_remove_vif(mvm, vif);
4313 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD) &&
4316 mvmvif->phy_ctxt = NULL;
4317 iwl_mvm_power_update_mac(mvm);
4320 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
4321 struct ieee80211_vif *vif,
4322 struct ieee80211_chanctx_conf *ctx)
4324 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4326 mutex_lock(&mvm->mutex);
4327 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
4328 mutex_unlock(&mvm->mutex);
4332 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
4333 struct ieee80211_vif_chanctx_switch *vifs)
4337 mutex_lock(&mvm->mutex);
4338 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4339 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
4341 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
4343 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
4347 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4351 "failed to assign new_ctx during channel switch\n");
4355 /* we don't support TDLS during DCM - can be caused by channel switch */
4356 if (iwl_mvm_phy_ctx_count(mvm) > 1)
4357 iwl_mvm_teardown_tdls_peers(mvm);
4362 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
4365 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
4366 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
4370 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4372 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4379 /* things keep failing, better restart the hw */
4380 iwl_mvm_nic_restart(mvm, false);
4383 mutex_unlock(&mvm->mutex);
4389 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
4390 struct ieee80211_vif_chanctx_switch *vifs)
4394 mutex_lock(&mvm->mutex);
4395 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4397 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4401 "failed to assign new_ctx during channel switch\n");
4408 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4410 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4417 /* things keep failing, better restart the hw */
4418 iwl_mvm_nic_restart(mvm, false);
4421 mutex_unlock(&mvm->mutex);
4426 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4427 struct ieee80211_vif_chanctx_switch *vifs,
4429 enum ieee80211_chanctx_switch_mode mode)
4431 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4434 /* we only support a single-vif right now */
4439 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4440 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4442 case CHANCTX_SWMODE_REASSIGN_VIF:
4443 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4453 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4455 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4457 return mvm->ibss_manager;
4460 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4461 struct ieee80211_sta *sta,
4464 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4465 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4467 if (!mvm_sta || !mvm_sta->vif) {
4468 IWL_ERR(mvm, "Station is not associated to a vif\n");
4472 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4475 #ifdef CONFIG_NL80211_TESTMODE
4476 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4477 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4478 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4479 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4482 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4483 struct ieee80211_vif *vif,
4484 void *data, int len)
4486 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4490 err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len,
4491 iwl_mvm_tm_policy, NULL);
4495 if (!tb[IWL_MVM_TM_ATTR_CMD])
4498 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4499 case IWL_MVM_TM_CMD_SET_NOA:
4500 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4501 !vif->bss_conf.enable_beacon ||
4502 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4505 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4506 if (noa_duration >= vif->bss_conf.beacon_int)
4509 mvm->noa_duration = noa_duration;
4512 return iwl_mvm_update_quotas(mvm, true, NULL);
4513 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4514 /* must be associated client vif - ignore authorized */
4515 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4516 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4517 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4520 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4521 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4522 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4528 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4529 struct ieee80211_vif *vif,
4530 void *data, int len)
4532 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4535 mutex_lock(&mvm->mutex);
4536 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4537 mutex_unlock(&mvm->mutex);
4543 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4544 struct ieee80211_vif *vif,
4545 struct ieee80211_channel_switch *chsw)
4547 /* By implementing this operation, we prevent mac80211 from
4548 * starting its own channel switch timer, so that we can call
4549 * ieee80211_chswitch_done() ourselves at the right time
4550 * (which is when the absence time event starts).
4553 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4554 "dummy channel switch op\n");
4557 static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm,
4558 struct ieee80211_vif *vif,
4559 struct ieee80211_channel_switch *chsw)
4561 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4562 struct iwl_chan_switch_te_cmd cmd = {
4563 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4565 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
4566 .tsf = cpu_to_le32(chsw->timestamp),
4567 .cs_count = chsw->count,
4568 .cs_mode = chsw->block_tx,
4571 lockdep_assert_held(&mvm->mutex);
4574 cmd.cs_delayed_bcn_count =
4575 DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int);
4577 return iwl_mvm_send_cmd_pdu(mvm,
4578 WIDE_ID(MAC_CONF_GROUP,
4579 CHANNEL_SWITCH_TIME_EVENT_CMD),
4580 0, sizeof(cmd), &cmd);
4583 static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm,
4584 struct ieee80211_vif *vif,
4585 struct ieee80211_channel_switch *chsw)
4587 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4590 /* Schedule the time event to a bit before beacon 1,
4591 * to make sure we're in the new channel when the
4592 * GO/AP arrives. In case count <= 1 immediately schedule the
4593 * TE (this might result with some packet loss or connection
4596 if (chsw->count <= 1)
4599 apply_time = chsw->device_timestamp +
4600 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4601 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4604 iwl_mvm_csa_client_absent(mvm, vif);
4606 if (mvmvif->bf_data.bf_enabled) {
4607 int ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4613 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4619 #define IWL_MAX_CSA_BLOCK_TX 1500
4620 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4621 struct ieee80211_vif *vif,
4622 struct ieee80211_channel_switch *chsw)
4624 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4625 struct ieee80211_vif *csa_vif;
4626 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4629 mutex_lock(&mvm->mutex);
4631 mvmvif->csa_failed = false;
4633 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4634 chsw->chandef.center_freq1);
4636 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4637 ieee80211_vif_to_wdev(vif),
4638 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4640 switch (vif->type) {
4641 case NL80211_IFTYPE_AP:
4643 rcu_dereference_protected(mvm->csa_vif,
4644 lockdep_is_held(&mvm->mutex));
4645 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4646 "Another CSA is already in progress")) {
4651 /* we still didn't unblock tx. prevent new CS meanwhile */
4652 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4653 lockdep_is_held(&mvm->mutex))) {
4658 rcu_assign_pointer(mvm->csa_vif, vif);
4660 if (WARN_ONCE(mvmvif->csa_countdown,
4661 "Previous CSA countdown didn't complete")) {
4666 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4669 case NL80211_IFTYPE_STATION:
4671 * In the new flow FW is in charge of timing the switch so there
4672 * is no need for all of this
4674 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
4675 CHANNEL_SWITCH_ERROR_NOTIF,
4680 * We haven't configured the firmware to be associated yet since
4681 * we don't know the dtim period. In this case, the firmware can't
4682 * track the beacons.
4684 if (!vif->bss_conf.assoc || !vif->bss_conf.dtim_period) {
4689 if (chsw->delay > IWL_MAX_CSA_BLOCK_TX)
4690 schedule_delayed_work(&mvmvif->csa_work, 0);
4692 if (chsw->block_tx) {
4694 * In case of undetermined / long time with immediate
4695 * quiet monitor status to gracefully disconnect
4698 chsw->count * vif->bss_conf.beacon_int >
4699 IWL_MAX_CSA_BLOCK_TX)
4700 schedule_delayed_work(&mvmvif->csa_work,
4701 msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX));
4704 if (!fw_has_capa(&mvm->fw->ucode_capa,
4705 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4706 ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw);
4710 iwl_mvm_schedule_client_csa(mvm, vif, chsw);
4713 mvmvif->csa_count = chsw->count;
4714 mvmvif->csa_misbehave = false;
4720 mvmvif->ps_disabled = true;
4722 ret = iwl_mvm_power_update_ps(mvm);
4726 /* we won't be on this channel any longer */
4727 iwl_mvm_teardown_tdls_peers(mvm);
4730 mutex_unlock(&mvm->mutex);
4735 static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw,
4736 struct ieee80211_vif *vif,
4737 struct ieee80211_channel_switch *chsw)
4739 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4740 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4741 struct iwl_chan_switch_te_cmd cmd = {
4742 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4744 .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY),
4745 .tsf = cpu_to_le32(chsw->timestamp),
4746 .cs_count = chsw->count,
4747 .cs_mode = chsw->block_tx,
4751 * In the new flow FW is in charge of timing the switch so there is no
4752 * need for all of this
4754 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
4755 CHANNEL_SWITCH_ERROR_NOTIF, 0))
4758 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY))
4761 IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d (old %d) mode = %d\n",
4762 mvmvif->id, chsw->count, mvmvif->csa_count, chsw->block_tx);
4764 if (chsw->count >= mvmvif->csa_count && chsw->block_tx) {
4765 if (mvmvif->csa_misbehave) {
4766 /* Second time, give up on this AP*/
4767 iwl_mvm_abort_channel_switch(hw, vif);
4768 ieee80211_chswitch_done(vif, false);
4769 mvmvif->csa_misbehave = false;
4772 mvmvif->csa_misbehave = true;
4774 mvmvif->csa_count = chsw->count;
4776 mutex_lock(&mvm->mutex);
4777 if (mvmvif->csa_failed)
4780 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
4781 WIDE_ID(MAC_CONF_GROUP,
4782 CHANNEL_SWITCH_TIME_EVENT_CMD),
4783 0, sizeof(cmd), &cmd));
4785 mutex_unlock(&mvm->mutex);
4788 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4792 if (!iwl_mvm_has_new_tx_api(mvm)) {
4794 mutex_lock(&mvm->mutex);
4795 iwl_mvm_flush_tx_path(mvm,
4796 iwl_mvm_flushable_queues(mvm) & queues);
4797 mutex_unlock(&mvm->mutex);
4799 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4804 mutex_lock(&mvm->mutex);
4805 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
4806 struct ieee80211_sta *sta;
4808 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4809 lockdep_is_held(&mvm->mutex));
4810 if (IS_ERR_OR_NULL(sta))
4814 iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF);
4816 iwl_mvm_wait_sta_queues_empty(mvm,
4817 iwl_mvm_sta_from_mac80211(sta));
4819 mutex_unlock(&mvm->mutex);
4822 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4823 struct ieee80211_vif *vif, u32 queues, bool drop)
4825 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4826 struct iwl_mvm_vif *mvmvif;
4827 struct iwl_mvm_sta *mvmsta;
4828 struct ieee80211_sta *sta;
4833 iwl_mvm_flush_no_vif(mvm, queues, drop);
4837 if (vif->type != NL80211_IFTYPE_STATION)
4840 /* Make sure we're done with the deferred traffic before flushing */
4841 flush_work(&mvm->add_stream_wk);
4843 mutex_lock(&mvm->mutex);
4844 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4846 /* flush the AP-station and all TDLS peers */
4847 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
4848 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4849 lockdep_is_held(&mvm->mutex));
4850 if (IS_ERR_OR_NULL(sta))
4853 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4854 if (mvmsta->vif != vif)
4857 /* make sure only TDLS peers or the AP are flushed */
4858 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4861 if (iwl_mvm_flush_sta(mvm, mvmsta, false))
4862 IWL_ERR(mvm, "flush request fail\n");
4864 msk |= mvmsta->tfd_queue_msk;
4865 if (iwl_mvm_has_new_tx_api(mvm))
4866 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4870 mutex_unlock(&mvm->mutex);
4872 /* this can take a while, and we may need/want other operations
4873 * to succeed while doing this, so do it without the mutex held
4875 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4876 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4879 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4880 struct survey_info *survey)
4882 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4885 memset(survey, 0, sizeof(*survey));
4887 /* only support global statistics right now */
4891 if (!fw_has_capa(&mvm->fw->ucode_capa,
4892 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4895 mutex_lock(&mvm->mutex);
4897 if (iwl_mvm_firmware_running(mvm)) {
4898 ret = iwl_mvm_request_statistics(mvm, false);
4903 survey->filled = SURVEY_INFO_TIME |
4904 SURVEY_INFO_TIME_RX |
4905 SURVEY_INFO_TIME_TX |
4906 SURVEY_INFO_TIME_SCAN;
4907 survey->time = mvm->accu_radio_stats.on_time_rf +
4908 mvm->radio_stats.on_time_rf;
4909 do_div(survey->time, USEC_PER_MSEC);
4911 survey->time_rx = mvm->accu_radio_stats.rx_time +
4912 mvm->radio_stats.rx_time;
4913 do_div(survey->time_rx, USEC_PER_MSEC);
4915 survey->time_tx = mvm->accu_radio_stats.tx_time +
4916 mvm->radio_stats.tx_time;
4917 do_div(survey->time_tx, USEC_PER_MSEC);
4919 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4920 mvm->radio_stats.on_time_scan;
4921 do_div(survey->time_scan, USEC_PER_MSEC);
4925 mutex_unlock(&mvm->mutex);
4929 static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo)
4931 u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
4933 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
4934 case RATE_MCS_CHAN_WIDTH_20:
4935 rinfo->bw = RATE_INFO_BW_20;
4937 case RATE_MCS_CHAN_WIDTH_40:
4938 rinfo->bw = RATE_INFO_BW_40;
4940 case RATE_MCS_CHAN_WIDTH_80:
4941 rinfo->bw = RATE_INFO_BW_80;
4943 case RATE_MCS_CHAN_WIDTH_160:
4944 rinfo->bw = RATE_INFO_BW_160;
4948 if (format == RATE_MCS_CCK_MSK ||
4949 format == RATE_MCS_LEGACY_OFDM_MSK) {
4950 int rate = u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK);
4952 /* add the offset needed to get to the legacy ofdm indices */
4953 if (format == RATE_MCS_LEGACY_OFDM_MSK)
4954 rate += IWL_FIRST_OFDM_RATE;
4957 case IWL_RATE_1M_INDEX:
4960 case IWL_RATE_2M_INDEX:
4963 case IWL_RATE_5M_INDEX:
4966 case IWL_RATE_11M_INDEX:
4967 rinfo->legacy = 110;
4969 case IWL_RATE_6M_INDEX:
4972 case IWL_RATE_9M_INDEX:
4975 case IWL_RATE_12M_INDEX:
4976 rinfo->legacy = 120;
4978 case IWL_RATE_18M_INDEX:
4979 rinfo->legacy = 180;
4981 case IWL_RATE_24M_INDEX:
4982 rinfo->legacy = 240;
4984 case IWL_RATE_36M_INDEX:
4985 rinfo->legacy = 360;
4987 case IWL_RATE_48M_INDEX:
4988 rinfo->legacy = 480;
4990 case IWL_RATE_54M_INDEX:
4991 rinfo->legacy = 540;
4996 rinfo->nss = u32_get_bits(rate_n_flags,
4997 RATE_MCS_NSS_MSK) + 1;
4998 rinfo->mcs = format == RATE_MCS_HT_MSK ?
4999 RATE_HT_MCS_INDEX(rate_n_flags) :
5000 u32_get_bits(rate_n_flags, RATE_MCS_CODE_MSK);
5002 if (format == RATE_MCS_HE_MSK) {
5003 u32 gi_ltf = u32_get_bits(rate_n_flags,
5004 RATE_MCS_HE_GI_LTF_MSK);
5006 rinfo->flags |= RATE_INFO_FLAGS_HE_MCS;
5008 if (rate_n_flags & RATE_MCS_HE_106T_MSK) {
5009 rinfo->bw = RATE_INFO_BW_HE_RU;
5010 rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106;
5013 switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) {
5014 case RATE_MCS_HE_TYPE_SU:
5015 case RATE_MCS_HE_TYPE_EXT_SU:
5016 if (gi_ltf == 0 || gi_ltf == 1)
5017 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
5018 else if (gi_ltf == 2)
5019 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
5020 else if (gi_ltf == 3)
5021 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
5023 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
5025 case RATE_MCS_HE_TYPE_MU:
5026 if (gi_ltf == 0 || gi_ltf == 1)
5027 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
5028 else if (gi_ltf == 2)
5029 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
5031 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
5033 case RATE_MCS_HE_TYPE_TRIG:
5034 if (gi_ltf == 0 || gi_ltf == 1)
5035 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
5037 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
5041 if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK)
5046 if (rate_n_flags & RATE_MCS_SGI_MSK)
5047 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
5049 if (format == RATE_MCS_HT_MSK) {
5050 rinfo->flags |= RATE_INFO_FLAGS_MCS;
5052 } else if (format == RATE_MCS_VHT_MSK) {
5053 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
5058 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
5059 struct ieee80211_vif *vif,
5060 struct ieee80211_sta *sta,
5061 struct station_info *sinfo)
5063 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5064 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5065 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
5067 if (mvmsta->avg_energy) {
5068 sinfo->signal_avg = -(s8)mvmsta->avg_energy;
5069 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
5072 if (iwl_mvm_has_tlc_offload(mvm)) {
5073 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
5075 iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate);
5076 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
5079 /* if beacon filtering isn't on mac80211 does it anyway */
5080 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
5083 if (!vif->bss_conf.assoc)
5086 mutex_lock(&mvm->mutex);
5088 if (mvmvif->ap_sta_id != mvmsta->sta_id)
5091 if (iwl_mvm_request_statistics(mvm, false))
5094 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
5095 mvmvif->beacon_stats.accu_num_beacons;
5096 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
5097 if (mvmvif->beacon_stats.avg_signal) {
5098 /* firmware only reports a value after RXing a few beacons */
5099 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
5100 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
5103 mutex_unlock(&mvm->mutex);
5106 static void iwl_mvm_event_mlme_callback_ini(struct iwl_mvm *mvm,
5107 struct ieee80211_vif *vif,
5108 const struct ieee80211_mlme_event *mlme)
5110 if ((mlme->data == ASSOC_EVENT || mlme->data == AUTH_EVENT) &&
5111 (mlme->status == MLME_DENIED || mlme->status == MLME_TIMEOUT)) {
5112 iwl_dbg_tlv_time_point(&mvm->fwrt,
5113 IWL_FW_INI_TIME_POINT_ASSOC_FAILED,
5118 if (mlme->data == DEAUTH_RX_EVENT || mlme->data == DEAUTH_TX_EVENT) {
5119 iwl_dbg_tlv_time_point(&mvm->fwrt,
5120 IWL_FW_INI_TIME_POINT_DEASSOC,
5126 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
5127 struct ieee80211_vif *vif,
5128 const struct ieee80211_event *event)
5130 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
5132 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
5134 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
5137 struct iwl_fw_dbg_trigger_tlv *trig;
5138 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
5140 if (iwl_trans_dbg_ini_valid(mvm->trans)) {
5141 iwl_mvm_event_mlme_callback_ini(mvm, vif, &event->u.mlme);
5145 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5146 FW_DBG_TRIGGER_MLME);
5150 trig_mlme = (void *)trig->data;
5152 if (event->u.mlme.data == ASSOC_EVENT) {
5153 if (event->u.mlme.status == MLME_DENIED)
5154 CHECK_MLME_TRIGGER(stop_assoc_denied,
5155 "DENIED ASSOC: reason %d",
5156 event->u.mlme.reason);
5157 else if (event->u.mlme.status == MLME_TIMEOUT)
5158 CHECK_MLME_TRIGGER(stop_assoc_timeout,
5160 } else if (event->u.mlme.data == AUTH_EVENT) {
5161 if (event->u.mlme.status == MLME_DENIED)
5162 CHECK_MLME_TRIGGER(stop_auth_denied,
5163 "DENIED AUTH: reason %d",
5164 event->u.mlme.reason);
5165 else if (event->u.mlme.status == MLME_TIMEOUT)
5166 CHECK_MLME_TRIGGER(stop_auth_timeout,
5168 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
5169 CHECK_MLME_TRIGGER(stop_rx_deauth,
5170 "DEAUTH RX %d", event->u.mlme.reason);
5171 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
5172 CHECK_MLME_TRIGGER(stop_tx_deauth,
5173 "DEAUTH TX %d", event->u.mlme.reason);
5175 #undef CHECK_MLME_TRIGGER
5178 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
5179 struct ieee80211_vif *vif,
5180 const struct ieee80211_event *event)
5182 struct iwl_fw_dbg_trigger_tlv *trig;
5183 struct iwl_fw_dbg_trigger_ba *ba_trig;
5185 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5190 ba_trig = (void *)trig->data;
5192 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
5195 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
5196 "BAR received from %pM, tid %d, ssn %d",
5197 event->u.ba.sta->addr, event->u.ba.tid,
5201 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
5202 struct ieee80211_vif *vif,
5203 const struct ieee80211_event *event)
5205 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5207 switch (event->type) {
5209 iwl_mvm_event_mlme_callback(mvm, vif, event);
5212 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
5214 case BA_FRAME_TIMEOUT:
5215 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
5223 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
5224 enum iwl_mvm_rxq_notif_type type,
5226 const void *data, u32 size)
5229 struct iwl_rxq_sync_cmd cmd;
5230 struct iwl_mvm_internal_rxq_notif notif;
5232 .cmd.rxq_mask = cpu_to_le32(BIT(mvm->trans->num_rx_queues) - 1),
5234 cpu_to_le32(sizeof(struct iwl_mvm_internal_rxq_notif) +
5239 struct iwl_host_cmd hcmd = {
5240 .id = WIDE_ID(DATA_PATH_GROUP, TRIGGER_RX_QUEUES_NOTIF_CMD),
5242 .len[0] = sizeof(cmd),
5245 .flags = sync ? 0 : CMD_ASYNC,
5249 /* size must be a multiple of DWORD */
5250 if (WARN_ON(cmd.cmd.count & cpu_to_le32(3)))
5253 if (!iwl_mvm_has_new_rx_api(mvm))
5257 cmd.notif.cookie = mvm->queue_sync_cookie;
5258 mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1;
5261 ret = iwl_mvm_send_cmd(mvm, &hcmd);
5263 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
5268 lockdep_assert_held(&mvm->mutex);
5269 ret = wait_event_timeout(mvm->rx_sync_waitq,
5270 READ_ONCE(mvm->queue_sync_state) == 0 ||
5271 iwl_mvm_is_radio_killed(mvm),
5273 WARN_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm),
5274 "queue sync: failed to sync, state is 0x%lx\n",
5275 mvm->queue_sync_state);
5280 mvm->queue_sync_state = 0;
5281 mvm->queue_sync_cookie++;
5285 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
5287 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5289 mutex_lock(&mvm->mutex);
5290 iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_EMPTY, true, NULL, 0);
5291 mutex_unlock(&mvm->mutex);
5295 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw,
5296 struct ieee80211_vif *vif,
5297 struct cfg80211_ftm_responder_stats *stats)
5299 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5300 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5302 if (vif->p2p || vif->type != NL80211_IFTYPE_AP ||
5303 !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder)
5306 mutex_lock(&mvm->mutex);
5307 *stats = mvm->ftm_resp_stats;
5308 mutex_unlock(&mvm->mutex);
5310 stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) |
5311 BIT(NL80211_FTM_STATS_PARTIAL_NUM) |
5312 BIT(NL80211_FTM_STATS_FAILED_NUM) |
5313 BIT(NL80211_FTM_STATS_ASAP_NUM) |
5314 BIT(NL80211_FTM_STATS_NON_ASAP_NUM) |
5315 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) |
5316 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) |
5317 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) |
5318 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM);
5323 static int iwl_mvm_start_pmsr(struct ieee80211_hw *hw,
5324 struct ieee80211_vif *vif,
5325 struct cfg80211_pmsr_request *request)
5327 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5330 mutex_lock(&mvm->mutex);
5331 ret = iwl_mvm_ftm_start(mvm, vif, request);
5332 mutex_unlock(&mvm->mutex);
5337 static void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw,
5338 struct ieee80211_vif *vif,
5339 struct cfg80211_pmsr_request *request)
5341 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5343 mutex_lock(&mvm->mutex);
5344 iwl_mvm_ftm_abort(mvm, request);
5345 mutex_unlock(&mvm->mutex);
5348 static bool iwl_mvm_can_hw_csum(struct sk_buff *skb)
5350 u8 protocol = ip_hdr(skb)->protocol;
5352 if (!IS_ENABLED(CONFIG_INET))
5355 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
5358 static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw,
5359 struct sk_buff *head,
5360 struct sk_buff *skb)
5362 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5364 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_BZ)
5365 return iwl_mvm_tx_csum_bz(mvm, head, true) ==
5366 iwl_mvm_tx_csum_bz(mvm, skb, true);
5368 /* For now don't aggregate IPv6 in AMSDU */
5369 if (skb->protocol != htons(ETH_P_IP))
5372 if (!iwl_mvm_is_csum_supported(mvm))
5375 return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head);
5378 const struct ieee80211_ops iwl_mvm_hw_ops = {
5379 .tx = iwl_mvm_mac_tx,
5380 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue,
5381 .ampdu_action = iwl_mvm_mac_ampdu_action,
5382 .get_antenna = iwl_mvm_op_get_antenna,
5383 .start = iwl_mvm_mac_start,
5384 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
5385 .stop = iwl_mvm_mac_stop,
5386 .add_interface = iwl_mvm_mac_add_interface,
5387 .remove_interface = iwl_mvm_mac_remove_interface,
5388 .config = iwl_mvm_mac_config,
5389 .prepare_multicast = iwl_mvm_prepare_multicast,
5390 .configure_filter = iwl_mvm_configure_filter,
5391 .config_iface_filter = iwl_mvm_config_iface_filter,
5392 .bss_info_changed = iwl_mvm_bss_info_changed,
5393 .hw_scan = iwl_mvm_mac_hw_scan,
5394 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
5395 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
5396 .sta_state = iwl_mvm_mac_sta_state,
5397 .sta_notify = iwl_mvm_mac_sta_notify,
5398 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
5399 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
5400 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
5401 .sta_rc_update = iwl_mvm_sta_rc_update,
5402 .conf_tx = iwl_mvm_mac_conf_tx,
5403 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
5404 .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx,
5405 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
5406 .flush = iwl_mvm_mac_flush,
5407 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
5408 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
5409 .set_key = iwl_mvm_mac_set_key,
5410 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
5411 .remain_on_channel = iwl_mvm_roc,
5412 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
5413 .add_chanctx = iwl_mvm_add_chanctx,
5414 .remove_chanctx = iwl_mvm_remove_chanctx,
5415 .change_chanctx = iwl_mvm_change_chanctx,
5416 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
5417 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
5418 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
5420 .start_ap = iwl_mvm_start_ap_ibss,
5421 .stop_ap = iwl_mvm_stop_ap_ibss,
5422 .join_ibss = iwl_mvm_start_ap_ibss,
5423 .leave_ibss = iwl_mvm_stop_ap_ibss,
5425 .tx_last_beacon = iwl_mvm_tx_last_beacon,
5427 .set_tim = iwl_mvm_set_tim,
5429 .channel_switch = iwl_mvm_channel_switch,
5430 .pre_channel_switch = iwl_mvm_pre_channel_switch,
5431 .post_channel_switch = iwl_mvm_post_channel_switch,
5432 .abort_channel_switch = iwl_mvm_abort_channel_switch,
5433 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon,
5435 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
5436 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
5437 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
5439 .event_callback = iwl_mvm_mac_event_callback,
5441 .sync_rx_queues = iwl_mvm_sync_rx_queues,
5443 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
5445 #ifdef CONFIG_PM_SLEEP
5447 .suspend = iwl_mvm_suspend,
5448 .resume = iwl_mvm_resume,
5449 .set_wakeup = iwl_mvm_set_wakeup,
5450 .set_rekey_data = iwl_mvm_set_rekey_data,
5451 #if IS_ENABLED(CONFIG_IPV6)
5452 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
5454 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
5456 .get_survey = iwl_mvm_mac_get_survey,
5457 .sta_statistics = iwl_mvm_mac_sta_statistics,
5458 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats,
5459 .start_pmsr = iwl_mvm_start_pmsr,
5460 .abort_pmsr = iwl_mvm_abort_pmsr,
5462 .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate,
5463 #ifdef CONFIG_IWLWIFI_DEBUGFS
5464 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,