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);
979 mvm->rx_ba_sessions = 0;
980 mvm->fwrt.dump.conf = FW_DBG_INVALID;
981 mvm->monitor_on = false;
983 /* keep statistics ticking */
984 iwl_mvm_accu_radio_stats(mvm);
987 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
991 lockdep_assert_held(&mvm->mutex);
993 ret = iwl_mvm_mei_get_ownership(mvm);
997 if (mvm->mei_nvm_data) {
998 /* We got the NIC, we can now free the MEI NVM data */
999 kfree(mvm->mei_nvm_data);
1000 mvm->mei_nvm_data = NULL;
1003 * We can't free the nvm_data we allocated based on the SAP
1004 * data because we registered to cfg80211 with the channels
1005 * allocated on mvm->nvm_data. Keep a pointer in temp_nvm_data
1006 * just in order to be able free it later.
1007 * NULLify nvm_data so that we will read the NVM from the
1008 * firmware this time.
1010 mvm->temp_nvm_data = mvm->nvm_data;
1011 mvm->nvm_data = NULL;
1014 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1016 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1017 * so later code will - from now on - see that we're doing it.
1019 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1020 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1021 /* Clean up some internal and mac80211 state on restart */
1022 iwl_mvm_restart_cleanup(mvm);
1024 ret = iwl_mvm_up(mvm);
1026 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT,
1028 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC,
1031 mvm->last_reset_or_resume_time_jiffies = jiffies;
1033 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1034 /* Something went wrong - we need to finish some cleanup
1035 * that normally iwl_mvm_mac_restart_complete() below
1038 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1044 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1046 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1048 int retry, max_retry = 0;
1050 mutex_lock(&mvm->mutex);
1052 /* we are starting the mac not in error flow, and restart is enabled */
1053 if (!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) &&
1054 iwlwifi_mod_params.fw_restart) {
1055 max_retry = IWL_MAX_INIT_RETRY;
1057 * This will prevent mac80211 recovery flows to trigger during
1060 set_bit(IWL_MVM_STATUS_STARTING, &mvm->status);
1063 for (retry = 0; retry <= max_retry; retry++) {
1064 ret = __iwl_mvm_mac_start(mvm);
1068 IWL_ERR(mvm, "mac start retry %d\n", retry);
1070 clear_bit(IWL_MVM_STATUS_STARTING, &mvm->status);
1072 mutex_unlock(&mvm->mutex);
1074 iwl_mvm_mei_set_sw_rfkill_state(mvm);
1079 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1083 mutex_lock(&mvm->mutex);
1085 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1087 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1089 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1092 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY);
1095 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1096 * of packets the FW sent out, so we must reconnect.
1098 iwl_mvm_teardown_tdls_peers(mvm);
1100 mutex_unlock(&mvm->mutex);
1104 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1105 enum ieee80211_reconfig_type reconfig_type)
1107 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1109 switch (reconfig_type) {
1110 case IEEE80211_RECONFIG_TYPE_RESTART:
1111 iwl_mvm_restart_complete(mvm);
1113 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1118 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1120 lockdep_assert_held(&mvm->mutex);
1122 iwl_mvm_ftm_initiator_smooth_stop(mvm);
1124 /* firmware counters are obviously reset now, but we shouldn't
1125 * partially track so also clear the fw_reset_accu counters.
1127 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1129 /* async_handlers_wk is now blocked */
1131 if (iwl_fw_lookup_cmd_ver(mvm->fw, ADD_STA, 0) < 12)
1132 iwl_mvm_rm_aux_sta(mvm);
1134 iwl_mvm_stop_device(mvm);
1136 iwl_mvm_async_handlers_purge(mvm);
1137 /* async_handlers_list is empty and will stay empty: HW is stopped */
1140 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1141 * hw (as restart_complete() won't be called in this case) and mac80211
1142 * won't execute the restart.
1143 * But make sure to cleanup interfaces that have gone down before/during
1144 * HW restart was requested.
1146 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1147 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1149 ieee80211_iterate_interfaces(mvm->hw, 0,
1150 iwl_mvm_cleanup_iterator, mvm);
1152 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1153 * make sure there's nothing left there and warn if any is found.
1155 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1158 for (i = 0; i < mvm->max_scans; i++) {
1159 if (WARN_ONCE(mvm->scan_uid_status[i],
1160 "UMAC scan UID %d status was not cleaned\n",
1162 mvm->scan_uid_status[i] = 0;
1167 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1169 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1171 flush_work(&mvm->async_handlers_wk);
1172 flush_work(&mvm->add_stream_wk);
1175 * Lock and clear the firmware running bit here already, so that
1176 * new commands coming in elsewhere, e.g. from debugfs, will not
1177 * be able to proceed. This is important here because one of those
1178 * debugfs files causes the firmware dump to be triggered, and if we
1179 * don't stop debugfs accesses before canceling that it could be
1180 * retriggered after we flush it but before we've cleared the bit.
1182 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1184 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1185 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1188 * The work item could be running or queued if the
1189 * ROC time event stops just as we get here.
1191 flush_work(&mvm->roc_done_wk);
1193 iwl_mvm_mei_set_sw_rfkill_state(mvm);
1195 mutex_lock(&mvm->mutex);
1196 __iwl_mvm_mac_stop(mvm);
1197 mutex_unlock(&mvm->mutex);
1200 * The worker might have been waiting for the mutex, let it run and
1201 * discover that its list is now empty.
1203 cancel_work_sync(&mvm->async_handlers_wk);
1206 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1210 lockdep_assert_held(&mvm->mutex);
1212 for (i = 0; i < NUM_PHY_CTX; i++)
1213 if (!mvm->phy_ctxts[i].ref)
1214 return &mvm->phy_ctxts[i];
1216 IWL_ERR(mvm, "No available PHY context\n");
1220 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1223 u32 cmd_id = REDUCE_TX_POWER_CMD;
1225 struct iwl_dev_tx_power_cmd cmd = {
1226 .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1227 .common.mac_context_id =
1228 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1229 .common.pwr_restriction = cpu_to_le16(8 * tx_power),
1231 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id,
1232 IWL_FW_CMD_VER_UNKNOWN);
1234 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1235 cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1238 len = sizeof(cmd.v7);
1239 else if (cmd_ver == 6)
1240 len = sizeof(cmd.v6);
1241 else if (fw_has_api(&mvm->fw->ucode_capa,
1242 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1243 len = sizeof(cmd.v5);
1244 else if (fw_has_capa(&mvm->fw->ucode_capa,
1245 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1246 len = sizeof(cmd.v4);
1248 len = sizeof(cmd.v3);
1250 /* all structs have the same common part, add it */
1251 len += sizeof(cmd.common);
1253 return iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, len, &cmd);
1256 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
1257 struct ieee80211_vif *vif)
1259 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1260 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1263 mutex_lock(&mvm->mutex);
1265 if (vif->type == NL80211_IFTYPE_STATION) {
1266 struct iwl_mvm_sta *mvmsta;
1268 mvmvif->csa_bcn_pending = false;
1269 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
1272 if (WARN_ON(!mvmsta)) {
1277 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
1279 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1281 if (!fw_has_capa(&mvm->fw->ucode_capa,
1282 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
1283 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1287 iwl_mvm_stop_session_protection(mvm, vif);
1291 mvmvif->ps_disabled = false;
1293 ret = iwl_mvm_power_update_ps(mvm);
1296 if (mvmvif->csa_failed)
1298 mutex_unlock(&mvm->mutex);
1303 static void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw,
1304 struct ieee80211_vif *vif)
1306 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1307 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1308 struct iwl_chan_switch_te_cmd cmd = {
1309 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1311 .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE),
1315 * In the new flow since FW is in charge of the timing,
1316 * if driver has canceled the channel switch he will receive the
1317 * CHANNEL_SWITCH_START_NOTIF notification from FW and then cancel it
1319 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
1320 CHANNEL_SWITCH_ERROR_NOTIF, 0))
1323 IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id);
1325 mutex_lock(&mvm->mutex);
1326 if (!fw_has_capa(&mvm->fw->ucode_capa,
1327 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
1328 iwl_mvm_remove_csa_period(mvm, vif);
1330 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
1331 WIDE_ID(MAC_CONF_GROUP,
1332 CHANNEL_SWITCH_TIME_EVENT_CMD),
1333 0, sizeof(cmd), &cmd));
1334 mvmvif->csa_failed = true;
1335 mutex_unlock(&mvm->mutex);
1337 iwl_mvm_post_channel_switch(hw, vif);
1340 static void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk)
1342 struct iwl_mvm_vif *mvmvif;
1343 struct ieee80211_vif *vif;
1345 mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work);
1346 vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);
1348 /* Trigger disconnect (should clear the CSA state) */
1349 ieee80211_chswitch_done(vif, false);
1352 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1353 struct ieee80211_vif *vif)
1355 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1356 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1360 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1363 * Not much to do here. The stack will not allow interface
1364 * types or combinations that we didn't advertise, so we
1365 * don't really have to check the types.
1368 mutex_lock(&mvm->mutex);
1370 /* make sure that beacon statistics don't go backwards with FW reset */
1371 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1372 mvmvif->beacon_stats.accu_num_beacons +=
1373 mvmvif->beacon_stats.num_beacons;
1375 /* Allocate resources for the MAC context, and add it to the fw */
1376 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1380 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif);
1383 * The AP binding flow can be done only after the beacon
1384 * template is configured (which happens only in the mac80211
1385 * start_ap() flow), and adding the broadcast station can happen
1386 * only after the binding.
1387 * In addition, since modifying the MAC before adding a bcast
1388 * station is not allowed by the FW, delay the adding of MAC context to
1389 * the point where we can also add the bcast station.
1390 * In short: there's not much we can do at this point, other than
1391 * allocating resources :)
1393 if (vif->type == NL80211_IFTYPE_AP ||
1394 vif->type == NL80211_IFTYPE_ADHOC) {
1395 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1397 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1402 * Only queue for this station is the mcast queue,
1403 * which shouldn't be in TFD mask anyway
1405 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1411 iwl_mvm_vif_dbgfs_register(mvm, vif);
1415 mvmvif->features |= hw->netdev_features;
1417 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1421 ret = iwl_mvm_power_update_mac(mvm);
1423 goto out_remove_mac;
1425 /* beacon filtering */
1426 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1428 goto out_remove_mac;
1430 if (!mvm->bf_allowed_vif &&
1431 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1432 mvm->bf_allowed_vif = mvmvif;
1433 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1434 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1438 * P2P_DEVICE interface does not have a channel context assigned to it,
1439 * so a dedicated PHY context is allocated to it and the corresponding
1440 * MAC context is bound to it at this stage.
1442 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1444 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1445 if (!mvmvif->phy_ctxt) {
1450 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1451 ret = iwl_mvm_binding_add_vif(mvm, vif);
1455 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1459 /* Save a pointer to p2p device vif, so it can later be used to
1460 * update the p2p device MAC when a GO is started/stopped */
1461 mvm->p2p_device_vif = vif;
1464 iwl_mvm_tcm_add_vif(mvm, vif);
1465 INIT_DELAYED_WORK(&mvmvif->csa_work,
1466 iwl_mvm_channel_switch_disconnect_wk);
1468 if (vif->type == NL80211_IFTYPE_MONITOR)
1469 mvm->monitor_on = true;
1471 iwl_mvm_vif_dbgfs_register(mvm, vif);
1473 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
1474 vif->type == NL80211_IFTYPE_STATION && !vif->p2p &&
1475 !mvm->csme_vif && mvm->mei_registered) {
1476 iwl_mei_set_nic_info(vif->addr, mvm->nvm_data->hw_addr);
1477 iwl_mei_set_netdev(ieee80211_vif_to_wdev(vif)->netdev);
1478 mvm->csme_vif = vif;
1484 iwl_mvm_binding_remove_vif(mvm, vif);
1486 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1488 if (mvm->bf_allowed_vif == mvmvif) {
1489 mvm->bf_allowed_vif = NULL;
1490 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1491 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1494 mvmvif->phy_ctxt = NULL;
1495 iwl_mvm_mac_ctxt_remove(mvm, vif);
1497 mutex_unlock(&mvm->mutex);
1502 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1503 struct ieee80211_vif *vif)
1505 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1507 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1508 * We assume here that all the packets sent to the OFFCHANNEL
1509 * queue are sent in ROC session.
1511 flush_work(&mvm->roc_done_wk);
1515 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1516 struct ieee80211_vif *vif)
1518 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1519 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1520 struct iwl_probe_resp_data *probe_data;
1522 iwl_mvm_prepare_mac_removal(mvm, vif);
1524 if (!(vif->type == NL80211_IFTYPE_AP ||
1525 vif->type == NL80211_IFTYPE_ADHOC))
1526 iwl_mvm_tcm_rm_vif(mvm, vif);
1528 mutex_lock(&mvm->mutex);
1530 if (vif == mvm->csme_vif) {
1531 iwl_mei_set_netdev(NULL);
1532 mvm->csme_vif = NULL;
1535 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1536 lockdep_is_held(&mvm->mutex));
1537 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1539 kfree_rcu(probe_data, rcu_head);
1541 if (mvm->bf_allowed_vif == mvmvif) {
1542 mvm->bf_allowed_vif = NULL;
1543 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1544 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1547 if (vif->bss_conf.ftm_responder)
1548 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
1550 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1553 * For AP/GO interface, the tear down of the resources allocated to the
1554 * interface is be handled as part of the stop_ap flow.
1556 if (vif->type == NL80211_IFTYPE_AP ||
1557 vif->type == NL80211_IFTYPE_ADHOC) {
1558 #ifdef CONFIG_NL80211_TESTMODE
1559 if (vif == mvm->noa_vif) {
1560 mvm->noa_vif = NULL;
1561 mvm->noa_duration = 0;
1564 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1565 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1569 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1570 mvm->p2p_device_vif = NULL;
1571 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1572 iwl_mvm_binding_remove_vif(mvm, vif);
1573 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1574 mvmvif->phy_ctxt = NULL;
1577 iwl_mvm_power_update_mac(mvm);
1578 iwl_mvm_mac_ctxt_remove(mvm, vif);
1580 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL);
1582 if (vif->type == NL80211_IFTYPE_MONITOR)
1583 mvm->monitor_on = false;
1586 mutex_unlock(&mvm->mutex);
1589 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1594 struct iwl_mvm_mc_iter_data {
1595 struct iwl_mvm *mvm;
1599 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1600 struct ieee80211_vif *vif)
1602 struct iwl_mvm_mc_iter_data *data = _data;
1603 struct iwl_mvm *mvm = data->mvm;
1604 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1605 struct iwl_host_cmd hcmd = {
1606 .id = MCAST_FILTER_CMD,
1608 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1612 /* if we don't have free ports, mcast frames will be dropped */
1613 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1616 if (vif->type != NL80211_IFTYPE_STATION ||
1620 cmd->port_id = data->port_id++;
1621 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1622 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1627 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1629 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1632 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1634 struct iwl_mvm_mc_iter_data iter_data = {
1639 lockdep_assert_held(&mvm->mutex);
1641 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1644 ieee80211_iterate_active_interfaces_atomic(
1645 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1646 iwl_mvm_mc_iface_iterator, &iter_data);
1649 * Send a (synchronous) ech command so that we wait for the
1650 * multiple asynchronous MCAST_FILTER_CMD commands sent by
1651 * the interface iterator. Otherwise, we might get here over
1652 * and over again (by userspace just sending a lot of these)
1653 * and the CPU can send them faster than the firmware can
1655 * Note that the CPU is still faster - but with this we'll
1656 * actually send fewer commands overall because the CPU will
1657 * not schedule the work in mac80211 as frequently if it's
1658 * still running when rescheduled (possibly multiple times).
1660 ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL);
1662 IWL_ERR(mvm, "Failed to synchronize multicast groups update\n");
1665 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1666 struct netdev_hw_addr_list *mc_list)
1668 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1669 struct iwl_mcast_filter_cmd *cmd;
1670 struct netdev_hw_addr *addr;
1675 addr_count = netdev_hw_addr_list_count(mc_list);
1676 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1677 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1681 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1682 cmd = kzalloc(len, GFP_ATOMIC);
1688 return (u64)(unsigned long)cmd;
1691 netdev_hw_addr_list_for_each(addr, mc_list) {
1692 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1693 cmd->count, addr->addr);
1694 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1695 addr->addr, ETH_ALEN);
1699 return (u64)(unsigned long)cmd;
1702 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1703 unsigned int changed_flags,
1704 unsigned int *total_flags,
1707 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1708 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1710 mutex_lock(&mvm->mutex);
1712 /* replace previous configuration */
1713 kfree(mvm->mcast_filter_cmd);
1714 mvm->mcast_filter_cmd = cmd;
1719 if (changed_flags & FIF_ALLMULTI)
1720 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1725 iwl_mvm_recalc_multicast(mvm);
1727 mutex_unlock(&mvm->mutex);
1731 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1732 struct ieee80211_vif *vif,
1733 unsigned int filter_flags,
1734 unsigned int changed_flags)
1736 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1738 /* We support only filter for probe requests */
1739 if (!(changed_flags & FIF_PROBE_REQ))
1742 /* Supported only for p2p client interfaces */
1743 if (vif->type != NL80211_IFTYPE_STATION || !vif->cfg.assoc ||
1747 mutex_lock(&mvm->mutex);
1748 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1749 mutex_unlock(&mvm->mutex);
1752 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1753 struct ieee80211_vif *vif)
1755 struct iwl_mu_group_mgmt_cmd cmd = {};
1757 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1758 WLAN_MEMBERSHIP_LEN);
1759 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1760 WLAN_USER_POSITION_LEN);
1762 return iwl_mvm_send_cmd_pdu(mvm,
1763 WIDE_ID(DATA_PATH_GROUP,
1764 UPDATE_MU_GROUPS_CMD),
1765 0, sizeof(cmd), &cmd);
1768 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1769 struct ieee80211_vif *vif)
1771 if (vif->bss_conf.mu_mimo_owner) {
1772 struct iwl_mu_group_mgmt_notif *notif = _data;
1775 * MU-MIMO Group Id action frame is little endian. We treat
1776 * the data received from firmware as if it came from the
1777 * action frame, so no conversion is needed.
1779 ieee80211_update_mu_groups(vif, 0,
1780 (u8 *)¬if->membership_status,
1781 (u8 *)¬if->user_position);
1785 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1786 struct iwl_rx_cmd_buffer *rxb)
1788 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1789 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1791 ieee80211_iterate_active_interfaces_atomic(
1792 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1793 iwl_mvm_mu_mimo_iface_iterator, notif);
1796 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1798 u8 byte_num = ppe_pos_bit / 8;
1799 u8 bit_num = ppe_pos_bit % 8;
1804 return (ppe[byte_num] >> bit_num) &
1805 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1808 * If bit_num > 5, we have to combine bits with next byte.
1809 * Calculate how many bits we need to take from current byte (called
1810 * here "residue_bits"), and add them to bits from next byte.
1813 residue_bits = 8 - bit_num;
1815 res = (ppe[byte_num + 1] &
1816 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1818 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1823 static void iwl_mvm_parse_ppe(struct iwl_mvm *mvm,
1824 struct iwl_he_pkt_ext_v2 *pkt_ext, u8 nss,
1825 u8 ru_index_bitmap, u8 *ppe, u8 ppe_pos_bit)
1830 * FW currently supports only nss == MAX_HE_SUPP_NSS
1832 * If nss > MAX: we can ignore values we don't support
1833 * If nss < MAX: we can set zeros in other streams
1835 if (nss > MAX_HE_SUPP_NSS) {
1836 IWL_DEBUG_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
1838 nss = MAX_HE_SUPP_NSS;
1841 for (i = 0; i < nss; i++) {
1842 u8 ru_index_tmp = ru_index_bitmap << 1;
1843 u8 low_th = IWL_HE_PKT_EXT_NONE, high_th = IWL_HE_PKT_EXT_NONE;
1847 bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]);
1851 if (!(ru_index_tmp & 1))
1854 high_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit);
1855 ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE;
1856 low_th = iwl_mvm_he_get_ppe_val(ppe, ppe_pos_bit);
1857 ppe_pos_bit += IEEE80211_PPE_THRES_INFO_PPET_SIZE;
1859 pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th;
1860 pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th;
1865 static void iwl_mvm_set_pkt_ext_from_he_ppe(struct iwl_mvm *mvm,
1866 struct ieee80211_sta *sta,
1867 struct iwl_he_pkt_ext_v2 *pkt_ext)
1869 u8 nss = (sta->deflink.he_cap.ppe_thres[0] & IEEE80211_PPE_THRES_NSS_MASK) + 1;
1870 u8 *ppe = &sta->deflink.he_cap.ppe_thres[0];
1871 u8 ru_index_bitmap =
1873 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK);
1874 /* Starting after PPE header */
1875 u8 ppe_pos_bit = IEEE80211_HE_PPE_THRES_INFO_HEADER_SIZE;
1877 iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap, ppe, ppe_pos_bit);
1880 static void iwl_mvm_set_pkt_ext_from_nominal_padding(struct iwl_he_pkt_ext_v2 *pkt_ext,
1888 switch (nominal_padding) {
1889 case IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_0US:
1890 low_th = IWL_HE_PKT_EXT_NONE;
1891 high_th = IWL_HE_PKT_EXT_NONE;
1893 case IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_8US:
1894 low_th = IWL_HE_PKT_EXT_BPSK;
1895 high_th = IWL_HE_PKT_EXT_NONE;
1897 case IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_16US:
1898 low_th = IWL_HE_PKT_EXT_NONE;
1899 high_th = IWL_HE_PKT_EXT_BPSK;
1903 /* Set the PPE thresholds accordingly */
1904 if (low_th >= 0 && high_th >= 0) {
1905 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
1909 bw < ARRAY_SIZE(pkt_ext->pkt_ext_qam_th[i]);
1911 pkt_ext->pkt_ext_qam_th[i][bw][0] = low_th;
1912 pkt_ext->pkt_ext_qam_th[i][bw][1] = high_th;
1916 *flags |= STA_CTXT_HE_PACKET_EXT;
1920 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1921 struct ieee80211_vif *vif, u8 sta_id)
1923 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1924 struct iwl_he_sta_context_cmd_v3 sta_ctxt_cmd = {
1926 .tid_limit = IWL_MAX_TID_COUNT,
1927 .bss_color = vif->bss_conf.he_bss_color.color,
1928 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
1929 .frame_time_rts_th =
1930 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
1932 struct iwl_he_sta_context_cmd_v2 sta_ctxt_cmd_v2 = {};
1933 u32 cmd_id = WIDE_ID(DATA_PATH_GROUP, STA_HE_CTXT_CMD);
1934 u8 ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id, 2);
1936 struct ieee80211_sta *sta;
1939 const struct ieee80211_sta_he_cap *own_he_cap = NULL;
1940 struct ieee80211_chanctx_conf *chanctx_conf;
1941 const struct ieee80211_supported_band *sband;
1944 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_MBSSID_HE))
1949 /* same layout as v2 except some data at the end */
1950 cmd = &sta_ctxt_cmd_v2;
1951 size = sizeof(struct iwl_he_sta_context_cmd_v1);
1954 cmd = &sta_ctxt_cmd_v2;
1955 size = sizeof(struct iwl_he_sta_context_cmd_v2);
1958 cmd = &sta_ctxt_cmd;
1959 size = sizeof(struct iwl_he_sta_context_cmd_v3);
1962 IWL_ERR(mvm, "bad STA_HE_CTXT_CMD version %d\n", ver);
1968 chanctx_conf = rcu_dereference(vif->bss_conf.chanctx_conf);
1969 if (WARN_ON(!chanctx_conf)) {
1974 sband = mvm->hw->wiphy->bands[chanctx_conf->def.chan->band];
1975 own_he_cap = ieee80211_get_he_iftype_cap(sband,
1976 ieee80211_vif_type_p2p(vif));
1978 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
1979 if (IS_ERR_OR_NULL(sta)) {
1981 WARN(1, "Can't find STA to configure HE\n");
1985 if (!sta->deflink.he_cap.has_he) {
1992 /* Block 26-tone RU OFDMA transmissions */
1993 if (mvmvif->he_ru_2mhz_block)
1994 flags |= STA_CTXT_HE_RU_2MHZ_BLOCK;
1997 if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[0] &
1998 IEEE80211_HE_MAC_CAP0_HTC_HE)
1999 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
2000 if ((sta->deflink.he_cap.he_cap_elem.mac_cap_info[1] &
2001 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2002 (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] &
2003 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2005 ((sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] &
2006 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2007 (sta->deflink.he_cap.he_cap_elem.mac_cap_info[1] &
2008 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2011 sta_ctxt_cmd.htc_flags |=
2012 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2013 else if (link_adap == 3)
2014 sta_ctxt_cmd.htc_flags |=
2015 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2017 if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2018 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2019 if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[3] &
2020 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2021 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2022 if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2023 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2026 * Initialize the PPE thresholds to "None" (7), as described in Table
2027 * 9-262ac of 80211.ax/D3.0.
2029 memset(&sta_ctxt_cmd.pkt_ext, IWL_HE_PKT_EXT_NONE,
2030 sizeof(sta_ctxt_cmd.pkt_ext));
2032 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2033 if (sta->deflink.he_cap.he_cap_elem.phy_cap_info[6] &
2034 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2035 iwl_mvm_set_pkt_ext_from_he_ppe(mvm, sta,
2036 &sta_ctxt_cmd.pkt_ext);
2037 flags |= STA_CTXT_HE_PACKET_EXT;
2038 /* PPE Thresholds doesn't exist - set the API PPE values
2039 * according to Common Nominal Packet Padding fiels. */
2041 u8 nominal_padding =
2042 u8_get_bits(sta->deflink.he_cap.he_cap_elem.phy_cap_info[9],
2043 IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK);
2044 if (nominal_padding != IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED)
2045 iwl_mvm_set_pkt_ext_from_nominal_padding(&sta_ctxt_cmd.pkt_ext,
2050 if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] &
2051 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP)
2052 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2054 if (sta->deflink.he_cap.he_cap_elem.mac_cap_info[2] &
2055 IEEE80211_HE_MAC_CAP2_ACK_EN)
2056 flags |= STA_CTXT_HE_ACK_ENABLED;
2060 /* Mark MU EDCA as enabled, unless none detected on some AC */
2061 flags |= STA_CTXT_HE_MU_EDCA_CW;
2062 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
2063 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2064 &mvmvif->queue_params[i].mu_edca_param_rec;
2065 u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
2067 if (!mvmvif->queue_params[i].mu_edca) {
2068 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2072 sta_ctxt_cmd.trig_based_txf[ac].cwmin =
2073 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2074 sta_ctxt_cmd.trig_based_txf[ac].cwmax =
2075 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2076 sta_ctxt_cmd.trig_based_txf[ac].aifsn =
2077 cpu_to_le16(mu_edca->aifsn);
2078 sta_ctxt_cmd.trig_based_txf[ac].mu_time =
2079 cpu_to_le16(mu_edca->mu_edca_timer);
2083 if (vif->bss_conf.uora_exists) {
2084 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2086 sta_ctxt_cmd.rand_alloc_ecwmin =
2087 vif->bss_conf.uora_ocw_range & 0x7;
2088 sta_ctxt_cmd.rand_alloc_ecwmax =
2089 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2092 if (own_he_cap && !(own_he_cap->he_cap_elem.mac_cap_info[2] &
2093 IEEE80211_HE_MAC_CAP2_ACK_EN))
2094 flags |= STA_CTXT_HE_NIC_NOT_ACK_ENABLED;
2096 if (vif->bss_conf.nontransmitted) {
2097 flags |= STA_CTXT_HE_REF_BSSID_VALID;
2098 ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr,
2099 vif->bss_conf.transmitter_bssid);
2100 sta_ctxt_cmd.max_bssid_indicator =
2101 vif->bss_conf.bssid_indicator;
2102 sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index;
2103 sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap;
2104 sta_ctxt_cmd.profile_periodicity =
2105 vif->bss_conf.profile_periodicity;
2108 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2111 /* fields before pkt_ext */
2112 BUILD_BUG_ON(offsetof(typeof(sta_ctxt_cmd), pkt_ext) !=
2113 offsetof(typeof(sta_ctxt_cmd_v2), pkt_ext));
2114 memcpy(&sta_ctxt_cmd_v2, &sta_ctxt_cmd,
2115 offsetof(typeof(sta_ctxt_cmd), pkt_ext));
2119 i < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th);
2124 bw < ARRAY_SIZE(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i]);
2126 BUILD_BUG_ON(sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]) !=
2127 sizeof(sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw]));
2129 memcpy(&sta_ctxt_cmd_v2.pkt_ext.pkt_ext_qam_th[i][bw],
2130 &sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw],
2131 sizeof(sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw]));
2135 /* fields after pkt_ext */
2136 BUILD_BUG_ON(sizeof(sta_ctxt_cmd) -
2137 offsetofend(typeof(sta_ctxt_cmd), pkt_ext) !=
2138 sizeof(sta_ctxt_cmd_v2) -
2139 offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext));
2140 memcpy((u8 *)&sta_ctxt_cmd_v2 +
2141 offsetofend(typeof(sta_ctxt_cmd_v2), pkt_ext),
2142 (u8 *)&sta_ctxt_cmd +
2143 offsetofend(typeof(sta_ctxt_cmd), pkt_ext),
2144 sizeof(sta_ctxt_cmd) -
2145 offsetofend(typeof(sta_ctxt_cmd), pkt_ext));
2146 sta_ctxt_cmd_v2.reserved3 = 0;
2149 if (iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, size, cmd))
2150 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2153 static void iwl_mvm_protect_assoc(struct iwl_mvm *mvm,
2154 struct ieee80211_vif *vif,
2155 u32 duration_override)
2157 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
2158 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
2160 if (duration_override > duration)
2161 duration = duration_override;
2163 /* Try really hard to protect the session and hear a beacon
2164 * The new session protection command allows us to protect the
2165 * session for a much longer time since the firmware will internally
2166 * create two events: a 300TU one with a very high priority that
2167 * won't be fragmented which should be enough for 99% of the cases,
2168 * and another one (which we configure here to be 900TU long) which
2169 * will have a slightly lower priority, but more importantly, can be
2170 * fragmented so that it'll allow other activities to run.
2172 if (fw_has_capa(&mvm->fw->ucode_capa,
2173 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD))
2174 iwl_mvm_schedule_session_protection(mvm, vif, 900,
2175 min_duration, false);
2177 iwl_mvm_protect_session(mvm, vif, duration,
2178 min_duration, 500, false);
2181 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2182 struct ieee80211_vif *vif,
2183 struct ieee80211_bss_conf *bss_conf,
2186 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2190 * Re-calculate the tsf id, as the leader-follower relations depend
2191 * on the beacon interval, which was not known when the station
2192 * interface was added.
2194 if (changes & BSS_CHANGED_ASSOC && vif->cfg.assoc) {
2195 if (vif->bss_conf.he_support &&
2196 !iwlwifi_mod_params.disable_11ax)
2197 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2199 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2202 /* Update MU EDCA params */
2203 if (changes & BSS_CHANGED_QOS && mvmvif->associated &&
2204 vif->cfg.assoc && vif->bss_conf.he_support &&
2205 !iwlwifi_mod_params.disable_11ax)
2206 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2209 * If we're not associated yet, take the (new) BSSID before associating
2210 * so the firmware knows. If we're already associated, then use the old
2211 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2212 * branch for disassociation below.
2214 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2215 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2217 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2219 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2221 /* after sending it once, adopt mac80211 data */
2222 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2223 mvmvif->associated = vif->cfg.assoc;
2225 if (changes & BSS_CHANGED_ASSOC) {
2226 if (vif->cfg.assoc) {
2227 /* clear statistics to get clean beacon counter */
2228 iwl_mvm_request_statistics(mvm, true);
2229 memset(&mvmvif->beacon_stats, 0,
2230 sizeof(mvmvif->beacon_stats));
2232 /* add quota for this interface */
2233 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2235 IWL_ERR(mvm, "failed to update quotas\n");
2239 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2241 !fw_has_capa(&mvm->fw->ucode_capa,
2242 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) {
2244 * If we're restarting then the firmware will
2245 * obviously have lost synchronisation with
2246 * the AP. It will attempt to synchronise by
2247 * itself, but we can make it more reliable by
2248 * scheduling a session protection time event.
2250 * The firmware needs to receive a beacon to
2251 * catch up with synchronisation, use 110% of
2252 * the beacon interval.
2254 * Set a large maximum delay to allow for more
2255 * than a single interface.
2257 * For new firmware versions, rely on the
2258 * firmware. This is relevant for DCM scenarios
2261 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2262 iwl_mvm_protect_session(mvm, vif, dur, dur,
2264 } else if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2266 !vif->bss_conf.dtim_period) {
2268 * If we're not restarting and still haven't
2269 * heard a beacon (dtim period unknown) then
2270 * make sure we still have enough minimum time
2271 * remaining in the time event, since the auth
2272 * might actually have taken quite a while
2273 * (especially for SAE) and so the remaining
2274 * time could be small without us having heard
2277 iwl_mvm_protect_assoc(mvm, vif, 0);
2280 iwl_mvm_sf_update(mvm, vif, false);
2281 iwl_mvm_power_vif_assoc(mvm, vif);
2283 iwl_mvm_update_smps(mvm, vif,
2284 IWL_MVM_SMPS_REQ_PROT,
2285 IEEE80211_SMPS_DYNAMIC);
2287 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2288 iwl_mvm_mei_host_disassociated(mvm);
2290 * If update fails - SF might be running in associated
2291 * mode while disassociated - which is forbidden.
2293 ret = iwl_mvm_sf_update(mvm, vif, false);
2295 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
2297 "Failed to update SF upon disassociation\n");
2300 * If we get an assert during the connection (after the
2301 * station has been added, but before the vif is set
2302 * to associated), mac80211 will re-add the station and
2303 * then configure the vif. Since the vif is not
2304 * associated, we would remove the station here and
2305 * this would fail the recovery.
2307 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2310 * Remove AP station now that
2311 * the MAC is unassoc
2313 ret = iwl_mvm_rm_sta_id(mvm, vif,
2317 "failed to remove AP station\n");
2319 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2322 /* remove quota for this interface */
2323 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2325 IWL_ERR(mvm, "failed to update quotas\n");
2327 /* this will take the cleared BSSID from bss_conf */
2328 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2331 "failed to update MAC %pM (clear after unassoc)\n",
2336 * The firmware tracks the MU-MIMO group on its own.
2337 * However, on HW restart we should restore this data.
2339 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2340 (changes & BSS_CHANGED_MU_GROUPS) && vif->bss_conf.mu_mimo_owner) {
2341 ret = iwl_mvm_update_mu_groups(mvm, vif);
2344 "failed to update VHT MU_MIMO groups\n");
2347 iwl_mvm_recalc_multicast(mvm);
2349 /* reset rssi values */
2350 mvmvif->bf_data.ave_beacon_signal = 0;
2352 iwl_mvm_bt_coex_vif_change(mvm);
2353 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2354 IEEE80211_SMPS_AUTOMATIC);
2355 if (fw_has_capa(&mvm->fw->ucode_capa,
2356 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2357 iwl_mvm_config_scan(mvm);
2360 if (changes & BSS_CHANGED_BEACON_INFO) {
2362 * We received a beacon from the associated AP so
2363 * remove the session protection.
2365 iwl_mvm_stop_session_protection(mvm, vif);
2367 iwl_mvm_sf_update(mvm, vif, false);
2368 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2371 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2373 * Send power command on every beacon change,
2374 * because we may have not enabled beacon abort yet.
2376 BSS_CHANGED_BEACON_INFO)) {
2377 ret = iwl_mvm_power_update_mac(mvm);
2379 IWL_ERR(mvm, "failed to update power mode\n");
2382 if (changes & BSS_CHANGED_CQM) {
2383 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2384 /* reset cqm events tracking */
2385 mvmvif->bf_data.last_cqm_event = 0;
2386 if (mvmvif->bf_data.bf_enabled) {
2387 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2390 "failed to update CQM thresholds\n");
2394 if (changes & BSS_CHANGED_BANDWIDTH)
2395 iwl_mvm_apply_fw_smps_request(vif);
2398 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2399 struct ieee80211_vif *vif,
2400 struct ieee80211_bss_conf *link_conf)
2402 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2403 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2406 mutex_lock(&mvm->mutex);
2408 /* Send the beacon template */
2409 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2414 * Re-calculate the tsf id, as the leader-follower relations depend on
2415 * the beacon interval, which was not known when the AP interface
2418 if (vif->type == NL80211_IFTYPE_AP)
2419 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2421 mvmvif->ap_assoc_sta_count = 0;
2423 /* Add the mac context */
2424 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2428 /* Perform the binding */
2429 ret = iwl_mvm_binding_add_vif(mvm, vif);
2434 * This is not very nice, but the simplest:
2435 * For older FWs adding the mcast sta before the bcast station may
2436 * cause assert 0x2b00.
2437 * This is fixed in later FW so make the order of removal depend on
2440 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2441 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2445 * Send the bcast station. At this stage the TBTT and DTIM time
2446 * events are added and applied to the scheduler
2448 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2450 iwl_mvm_rm_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);
2461 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2463 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2468 /* must be set before quota calculations */
2469 mvmvif->ap_ibss_active = true;
2471 /* send all the early keys to the device now */
2472 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
2473 struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i];
2478 mvmvif->ap_early_keys[i] = NULL;
2480 ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key);
2482 goto out_quota_failed;
2485 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2486 iwl_mvm_vif_set_low_latency(mvmvif, true,
2487 LOW_LATENCY_VIF_TYPE);
2488 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2491 /* power updated needs to be done before quotas */
2492 iwl_mvm_power_update_mac(mvm);
2494 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2496 goto out_quota_failed;
2498 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2499 if (vif->p2p && mvm->p2p_device_vif)
2500 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2502 iwl_mvm_bt_coex_vif_change(mvm);
2504 /* we don't support TDLS during DCM */
2505 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2506 iwl_mvm_teardown_tdls_peers(mvm);
2508 iwl_mvm_ftm_restart_responder(mvm, vif);
2513 iwl_mvm_power_update_mac(mvm);
2514 mvmvif->ap_ibss_active = false;
2515 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2516 iwl_mvm_rm_mcast_sta(mvm, vif);
2518 iwl_mvm_binding_remove_vif(mvm, vif);
2520 iwl_mvm_mac_ctxt_remove(mvm, vif);
2522 mutex_unlock(&mvm->mutex);
2526 static int iwl_mvm_start_ap(struct ieee80211_hw *hw,
2527 struct ieee80211_vif *vif,
2528 struct ieee80211_bss_conf *link_conf)
2530 return iwl_mvm_start_ap_ibss(hw, vif, link_conf);
2533 static int iwl_mvm_start_ibss(struct ieee80211_hw *hw,
2534 struct ieee80211_vif *vif)
2536 return iwl_mvm_start_ap_ibss(hw, vif, &vif->bss_conf);
2539 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2540 struct ieee80211_vif *vif,
2541 struct ieee80211_bss_conf *link_conf)
2543 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2544 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2546 iwl_mvm_prepare_mac_removal(mvm, vif);
2548 mutex_lock(&mvm->mutex);
2550 /* Handle AP stop while in CSA */
2551 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2552 iwl_mvm_remove_time_event(mvm, mvmvif,
2553 &mvmvif->time_event_data);
2554 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2555 mvmvif->csa_countdown = false;
2558 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2559 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2560 mvm->csa_tx_block_bcn_timeout = 0;
2563 mvmvif->ap_ibss_active = false;
2564 mvm->ap_last_beacon_gp2 = 0;
2566 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2567 iwl_mvm_vif_set_low_latency(mvmvif, false,
2568 LOW_LATENCY_VIF_TYPE);
2569 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2572 iwl_mvm_bt_coex_vif_change(mvm);
2574 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2575 if (vif->p2p && mvm->p2p_device_vif)
2576 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2578 iwl_mvm_update_quotas(mvm, false, NULL);
2580 iwl_mvm_ftm_responder_clear(mvm, vif);
2583 * This is not very nice, but the simplest:
2584 * For older FWs removing the mcast sta before the bcast station may
2585 * cause assert 0x2b00.
2586 * This is fixed in later FW (which will stop beaconing when removing
2588 * So make the order of removal depend on the TLV
2590 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2591 iwl_mvm_rm_mcast_sta(mvm, vif);
2592 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2593 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2594 iwl_mvm_rm_mcast_sta(mvm, vif);
2595 iwl_mvm_binding_remove_vif(mvm, vif);
2597 iwl_mvm_power_update_mac(mvm);
2599 iwl_mvm_mac_ctxt_remove(mvm, vif);
2601 mutex_unlock(&mvm->mutex);
2604 static void iwl_mvm_stop_ap(struct ieee80211_hw *hw,
2605 struct ieee80211_vif *vif,
2606 struct ieee80211_bss_conf *link_conf)
2608 iwl_mvm_stop_ap_ibss(hw, vif, link_conf);
2611 static void iwl_mvm_stop_ibss(struct ieee80211_hw *hw,
2612 struct ieee80211_vif *vif)
2614 iwl_mvm_stop_ap_ibss(hw, vif, &vif->bss_conf);
2618 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2619 struct ieee80211_vif *vif,
2620 struct ieee80211_bss_conf *bss_conf,
2623 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2625 /* Changes will be applied when the AP/IBSS is started */
2626 if (!mvmvif->ap_ibss_active)
2629 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2630 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2631 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2632 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2634 /* Need to send a new beacon template to the FW */
2635 if (changes & BSS_CHANGED_BEACON &&
2636 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2637 IWL_WARN(mvm, "Failed updating beacon data\n");
2639 if (changes & BSS_CHANGED_FTM_RESPONDER) {
2640 int ret = iwl_mvm_ftm_start_responder(mvm, vif);
2643 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
2649 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2650 struct ieee80211_vif *vif,
2651 struct ieee80211_bss_conf *bss_conf,
2654 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2656 mutex_lock(&mvm->mutex);
2658 if (changes & BSS_CHANGED_IDLE && !vif->cfg.idle)
2659 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2661 switch (vif->type) {
2662 case NL80211_IFTYPE_STATION:
2663 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2665 case NL80211_IFTYPE_AP:
2666 case NL80211_IFTYPE_ADHOC:
2667 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2669 case NL80211_IFTYPE_MONITOR:
2670 if (changes & BSS_CHANGED_MU_GROUPS)
2671 iwl_mvm_update_mu_groups(mvm, vif);
2674 /* shouldn't happen */
2678 if (changes & BSS_CHANGED_TXPOWER) {
2679 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n",
2681 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2684 mutex_unlock(&mvm->mutex);
2687 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2688 struct ieee80211_vif *vif,
2689 struct ieee80211_scan_request *hw_req)
2691 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2694 if (hw_req->req.n_channels == 0 ||
2695 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2698 mutex_lock(&mvm->mutex);
2699 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2700 mutex_unlock(&mvm->mutex);
2705 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2706 struct ieee80211_vif *vif)
2708 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2710 mutex_lock(&mvm->mutex);
2712 /* Due to a race condition, it's possible that mac80211 asks
2713 * us to stop a hw_scan when it's already stopped. This can
2714 * happen, for instance, if we stopped the scan ourselves,
2715 * called ieee80211_scan_completed() and the userspace called
2716 * cancel scan scan before ieee80211_scan_work() could run.
2717 * To handle that, simply return if the scan is not running.
2719 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2720 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2722 mutex_unlock(&mvm->mutex);
2726 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2727 struct ieee80211_sta *sta, u16 tids,
2729 enum ieee80211_frame_release_type reason,
2732 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2734 /* Called when we need to transmit (a) frame(s) from mac80211 */
2736 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2737 tids, more_data, false);
2741 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2742 struct ieee80211_sta *sta, u16 tids,
2744 enum ieee80211_frame_release_type reason,
2747 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2749 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2751 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2752 tids, more_data, true);
2755 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2756 enum sta_notify_cmd cmd,
2757 struct ieee80211_sta *sta)
2759 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2760 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2761 unsigned long txqs = 0, tids = 0;
2765 * If we have TVQM then we get too high queue numbers - luckily
2766 * we really shouldn't get here with that because such hardware
2767 * should have firmware supporting buffer station offload.
2769 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2772 spin_lock_bh(&mvmsta->lock);
2773 for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) {
2774 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2776 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2779 __set_bit(tid_data->txq_id, &txqs);
2781 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2784 __set_bit(tid, &tids);
2788 case STA_NOTIFY_SLEEP:
2789 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2790 ieee80211_sta_set_buffered(sta, tid, true);
2793 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2795 * The fw updates the STA to be asleep. Tx packets on the Tx
2796 * queues to this station will not be transmitted. The fw will
2797 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2800 case STA_NOTIFY_AWAKE:
2801 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2805 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2806 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2811 spin_unlock_bh(&mvmsta->lock);
2814 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2815 struct ieee80211_vif *vif,
2816 enum sta_notify_cmd cmd,
2817 struct ieee80211_sta *sta)
2819 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2822 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2824 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2825 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2826 struct ieee80211_sta *sta;
2827 struct iwl_mvm_sta *mvmsta;
2828 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2830 if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations))
2834 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2835 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2840 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2843 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2848 if (mvmsta->sleeping != sleeping) {
2849 mvmsta->sleeping = sleeping;
2850 __iwl_mvm_mac_sta_notify(mvm->hw,
2851 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2853 ieee80211_sta_ps_transition(sta, sleeping);
2857 switch (notif->type) {
2858 case IWL_MVM_PM_EVENT_AWAKE:
2859 case IWL_MVM_PM_EVENT_ASLEEP:
2861 case IWL_MVM_PM_EVENT_UAPSD:
2862 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2864 case IWL_MVM_PM_EVENT_PS_POLL:
2865 ieee80211_sta_pspoll(sta);
2875 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2876 struct ieee80211_vif *vif,
2877 struct ieee80211_sta *sta)
2879 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2880 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2883 * This is called before mac80211 does RCU synchronisation,
2884 * so here we already invalidate our internal RCU-protected
2885 * station pointer. The rest of the code will thus no longer
2886 * be able to find the station this way, and we don't rely
2887 * on further RCU synchronisation after the sta_state()
2888 * callback deleted the station.
2890 mutex_lock(&mvm->mutex);
2891 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2892 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2895 mutex_unlock(&mvm->mutex);
2898 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2903 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2904 struct iwl_mvm_tcm_mac *mdata;
2906 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2907 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2908 mdata->opened_rx_ba_sessions = false;
2911 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2914 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2915 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2920 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2921 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2925 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2926 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2927 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2932 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2936 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2937 struct ieee80211_vif *vif, u8 *peer_addr,
2938 enum nl80211_tdls_operation action)
2940 struct iwl_fw_dbg_trigger_tlv *trig;
2941 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2943 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
2944 FW_DBG_TRIGGER_TDLS);
2948 tdls_trig = (void *)trig->data;
2950 if (!(tdls_trig->action_bitmap & BIT(action)))
2953 if (tdls_trig->peer_mode &&
2954 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2957 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2958 "TDLS event occurred, peer %pM, action %d",
2962 struct iwl_mvm_he_obss_narrow_bw_ru_data {
2966 static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy,
2967 struct cfg80211_bss *bss,
2970 struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data;
2971 const struct cfg80211_bss_ies *ies;
2972 const struct element *elem;
2975 ies = rcu_dereference(bss->ies);
2976 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, ies->data,
2979 if (!elem || elem->datalen < 10 ||
2981 WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) {
2982 data->tolerated = false;
2987 static void iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw,
2988 struct ieee80211_vif *vif)
2990 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2991 struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = {
2995 if (!(vif->bss_conf.chandef.chan->flags & IEEE80211_CHAN_RADAR)) {
2996 mvmvif->he_ru_2mhz_block = false;
3000 cfg80211_bss_iter(hw->wiphy, &vif->bss_conf.chandef,
3001 iwl_mvm_check_he_obss_narrow_bw_ru_iter,
3005 * If there is at least one AP on radar channel that cannot
3006 * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
3008 mvmvif->he_ru_2mhz_block = !iter_data.tolerated;
3011 static void iwl_mvm_reset_cca_40mhz_workaround(struct iwl_mvm *mvm,
3012 struct ieee80211_vif *vif)
3014 struct ieee80211_supported_band *sband;
3015 const struct ieee80211_sta_he_cap *he_cap;
3017 if (vif->type != NL80211_IFTYPE_STATION)
3020 if (!mvm->cca_40mhz_workaround)
3023 /* decrement and check that we reached zero */
3024 mvm->cca_40mhz_workaround--;
3025 if (mvm->cca_40mhz_workaround)
3028 sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ];
3030 sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3032 he_cap = ieee80211_get_he_iftype_cap(sband,
3033 ieee80211_vif_type_p2p(vif));
3036 /* we know that ours is writable */
3037 struct ieee80211_sta_he_cap *he = (void *)(uintptr_t)he_cap;
3039 he->he_cap_elem.phy_cap_info[0] |=
3040 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
3044 static void iwl_mvm_mei_host_associated(struct iwl_mvm *mvm,
3045 struct ieee80211_vif *vif,
3046 struct iwl_mvm_sta *mvm_sta)
3048 #if IS_ENABLED(CONFIG_IWLMEI)
3049 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3050 struct iwl_mei_conn_info conn_info = {
3051 .ssid_len = vif->cfg.ssid_len,
3052 .channel = vif->bss_conf.chandef.chan->hw_value,
3055 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3058 if (!mvm->mei_registered)
3061 switch (mvm_sta->pairwise_cipher) {
3062 case WLAN_CIPHER_SUITE_CCMP:
3063 conn_info.pairwise_cipher = IWL_MEI_CIPHER_CCMP;
3065 case WLAN_CIPHER_SUITE_GCMP:
3066 conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP;
3068 case WLAN_CIPHER_SUITE_GCMP_256:
3069 conn_info.pairwise_cipher = IWL_MEI_CIPHER_GCMP_256;
3075 /* cipher not supported, don't send anything to iwlmei */
3079 switch (mvmvif->rekey_data.akm) {
3080 case WLAN_AKM_SUITE_SAE & 0xff:
3081 conn_info.auth_mode = IWL_MEI_AKM_AUTH_SAE;
3083 case WLAN_AKM_SUITE_PSK & 0xff:
3084 conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA_PSK;
3086 case WLAN_AKM_SUITE_8021X & 0xff:
3087 conn_info.auth_mode = IWL_MEI_AKM_AUTH_RSNA;
3091 conn_info.auth_mode = IWL_MEI_AKM_AUTH_OPEN;
3094 /* auth method / AKM not supported */
3095 /* TODO: All the FT vesions of these? */
3099 memcpy(conn_info.ssid, vif->cfg.ssid, vif->cfg.ssid_len);
3100 memcpy(conn_info.bssid, vif->bss_conf.bssid, ETH_ALEN);
3102 /* TODO: add support for collocated AP data */
3103 iwl_mei_host_associated(&conn_info, NULL);
3107 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
3108 struct ieee80211_vif *vif,
3109 struct ieee80211_sta *sta,
3110 enum ieee80211_sta_state old_state,
3111 enum ieee80211_sta_state new_state)
3113 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3114 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3115 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3118 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
3119 sta->addr, old_state, new_state);
3121 /* this would be a mac80211 bug ... but don't crash */
3122 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
3123 return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL;
3126 * If we are in a STA removal flow and in DQA mode:
3128 * This is after the sync_rcu part, so the queues have already been
3129 * flushed. No more TXs on their way in mac80211's path, and no more in
3131 * Also, we won't be getting any new TX frames for this station.
3132 * What we might have are deferred TX frames that need to be taken care
3135 * Drop any still-queued deferred-frame before removing the STA, and
3136 * make sure the worker is no longer handling frames for this STA.
3138 if (old_state == IEEE80211_STA_NONE &&
3139 new_state == IEEE80211_STA_NOTEXIST) {
3140 flush_work(&mvm->add_stream_wk);
3143 * No need to make sure deferred TX indication is off since the
3144 * worker will already remove it if it was on
3148 * Additionally, reset the 40 MHz capability if we disconnected
3151 iwl_mvm_reset_cca_40mhz_workaround(mvm, vif);
3154 mutex_lock(&mvm->mutex);
3155 /* track whether or not the station is associated */
3156 mvm_sta->sta_state = new_state;
3158 if (old_state == IEEE80211_STA_NOTEXIST &&
3159 new_state == IEEE80211_STA_NONE) {
3161 * Firmware bug - it'll crash if the beacon interval is less
3162 * than 16. We can't avoid connecting at all, so refuse the
3163 * station state change, this will cause mac80211 to abandon
3164 * attempts to connect to this AP, and eventually wpa_s will
3165 * blocklist the AP...
3167 if (vif->type == NL80211_IFTYPE_STATION &&
3168 vif->bss_conf.beacon_int < 16) {
3170 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
3171 sta->addr, vif->bss_conf.beacon_int);
3176 if (vif->type == NL80211_IFTYPE_STATION)
3177 vif->bss_conf.he_support = sta->deflink.he_cap.has_he;
3181 iwl_mvm_tdls_sta_count(mvm, NULL) ==
3182 IWL_MVM_TDLS_STA_COUNT ||
3183 iwl_mvm_phy_ctx_count(mvm) > 1)) {
3184 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
3189 ret = iwl_mvm_add_sta(mvm, vif, sta);
3190 if (sta->tdls && ret == 0) {
3191 iwl_mvm_recalc_tdls_state(mvm, vif, true);
3192 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3193 NL80211_TDLS_SETUP);
3196 sta->deflink.agg.max_rc_amsdu_len = 1;
3197 } else if (old_state == IEEE80211_STA_NONE &&
3198 new_state == IEEE80211_STA_AUTH) {
3200 * EBS may be disabled due to previous failures reported by FW.
3201 * Reset EBS status here assuming environment has been changed.
3203 mvm->last_ebs_successful = true;
3204 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
3206 } else if (old_state == IEEE80211_STA_AUTH &&
3207 new_state == IEEE80211_STA_ASSOC) {
3208 if (vif->type == NL80211_IFTYPE_AP) {
3209 vif->bss_conf.he_support = sta->deflink.he_cap.has_he;
3210 mvmvif->ap_assoc_sta_count++;
3211 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3212 if (vif->bss_conf.he_support &&
3213 !iwlwifi_mod_params.disable_11ax)
3214 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id);
3215 } else if (vif->type == NL80211_IFTYPE_STATION) {
3216 vif->bss_conf.he_support = sta->deflink.he_cap.has_he;
3218 mvmvif->he_ru_2mhz_block = false;
3219 if (sta->deflink.he_cap.has_he)
3220 iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif);
3222 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3225 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3227 ret = iwl_mvm_update_sta(mvm, vif, sta);
3228 } else if (old_state == IEEE80211_STA_ASSOC &&
3229 new_state == IEEE80211_STA_AUTHORIZED) {
3232 /* we don't support TDLS during DCM */
3233 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3234 iwl_mvm_teardown_tdls_peers(mvm);
3237 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3238 NL80211_TDLS_ENABLE_LINK);
3240 /* enable beacon filtering */
3241 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
3243 mvmvif->authorized = 1;
3246 * Now that the station is authorized, i.e., keys were already
3247 * installed, need to indicate to the FW that
3248 * multicast data frames can be forwarded to the driver
3250 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3251 iwl_mvm_mei_host_associated(mvm, vif, mvm_sta);
3254 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3256 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3257 new_state == IEEE80211_STA_ASSOC) {
3258 /* once we move into assoc state, need to update rate scale to
3259 * disable using wide bandwidth
3261 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3264 /* Multicast data frames are no longer allowed */
3265 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3268 * Set this after the above iwl_mvm_mac_ctxt_changed()
3269 * to avoid sending high prio again for a little time.
3271 mvmvif->authorized = 0;
3273 /* disable beacon filtering */
3274 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3276 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3280 } else if (old_state == IEEE80211_STA_ASSOC &&
3281 new_state == IEEE80211_STA_AUTH) {
3282 if (vif->type == NL80211_IFTYPE_AP) {
3283 mvmvif->ap_assoc_sta_count--;
3284 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3285 } else if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
3286 iwl_mvm_stop_session_protection(mvm, vif);
3288 } else if (old_state == IEEE80211_STA_AUTH &&
3289 new_state == IEEE80211_STA_NONE) {
3291 } else if (old_state == IEEE80211_STA_NONE &&
3292 new_state == IEEE80211_STA_NOTEXIST) {
3293 if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
3294 iwl_mvm_stop_session_protection(mvm, vif);
3295 ret = iwl_mvm_rm_sta(mvm, vif, sta);
3297 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3298 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3299 NL80211_TDLS_DISABLE_LINK);
3303 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3310 mutex_unlock(&mvm->mutex);
3312 if (sta->tdls && ret == 0) {
3313 if (old_state == IEEE80211_STA_NOTEXIST &&
3314 new_state == IEEE80211_STA_NONE)
3315 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3316 else if (old_state == IEEE80211_STA_NONE &&
3317 new_state == IEEE80211_STA_NOTEXIST)
3318 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3324 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3326 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3328 mvm->rts_threshold = value;
3333 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3334 struct ieee80211_vif *vif,
3335 struct ieee80211_sta *sta, u32 changed)
3337 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3338 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3340 if (changed & (IEEE80211_RC_BW_CHANGED |
3341 IEEE80211_RC_SUPP_RATES_CHANGED |
3342 IEEE80211_RC_NSS_CHANGED))
3343 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3346 if (vif->type == NL80211_IFTYPE_STATION &&
3347 changed & IEEE80211_RC_NSS_CHANGED)
3348 iwl_mvm_sf_update(mvm, vif, false);
3351 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3352 struct ieee80211_vif *vif,
3353 unsigned int link_id, u16 ac,
3354 const struct ieee80211_tx_queue_params *params)
3356 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3357 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3359 mvmvif->queue_params[ac] = *params;
3362 * No need to update right away, we'll get BSS_CHANGED_QOS
3363 * The exception is P2P_DEVICE interface which needs immediate update.
3365 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3368 mutex_lock(&mvm->mutex);
3369 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3370 mutex_unlock(&mvm->mutex);
3376 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3377 struct ieee80211_vif *vif,
3378 struct ieee80211_prep_tx_info *info)
3380 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3382 mutex_lock(&mvm->mutex);
3383 iwl_mvm_protect_assoc(mvm, vif, info->duration);
3384 mutex_unlock(&mvm->mutex);
3387 static void iwl_mvm_mac_mgd_complete_tx(struct ieee80211_hw *hw,
3388 struct ieee80211_vif *vif,
3389 struct ieee80211_prep_tx_info *info)
3391 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3393 /* for successful cases (auth/assoc), don't cancel session protection */
3397 mutex_lock(&mvm->mutex);
3398 iwl_mvm_stop_session_protection(mvm, vif);
3399 mutex_unlock(&mvm->mutex);
3402 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3403 struct ieee80211_vif *vif,
3404 struct cfg80211_sched_scan_request *req,
3405 struct ieee80211_scan_ies *ies)
3407 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3411 mutex_lock(&mvm->mutex);
3413 if (!vif->cfg.idle) {
3418 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3421 mutex_unlock(&mvm->mutex);
3425 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3426 struct ieee80211_vif *vif)
3428 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3431 mutex_lock(&mvm->mutex);
3433 /* Due to a race condition, it's possible that mac80211 asks
3434 * us to stop a sched_scan when it's already stopped. This
3435 * can happen, for instance, if we stopped the scan ourselves,
3436 * called ieee80211_sched_scan_stopped() and the userspace called
3437 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3438 * could run. To handle this, simply return if the scan is
3441 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3442 mutex_unlock(&mvm->mutex);
3446 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3447 mutex_unlock(&mvm->mutex);
3448 iwl_mvm_wait_for_async_handlers(mvm);
3453 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3454 enum set_key_cmd cmd,
3455 struct ieee80211_vif *vif,
3456 struct ieee80211_sta *sta,
3457 struct ieee80211_key_conf *key)
3459 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3460 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3461 struct iwl_mvm_sta *mvmsta = NULL;
3462 struct iwl_mvm_key_pn *ptk_pn;
3463 int keyidx = key->keyidx;
3468 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3470 switch (key->cipher) {
3471 case WLAN_CIPHER_SUITE_TKIP:
3472 if (!mvm->trans->trans_cfg->gen2) {
3473 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3474 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3475 } else if (vif->type == NL80211_IFTYPE_STATION) {
3476 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3478 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3482 case WLAN_CIPHER_SUITE_CCMP:
3483 case WLAN_CIPHER_SUITE_GCMP:
3484 case WLAN_CIPHER_SUITE_GCMP_256:
3485 if (!iwl_mvm_has_new_tx_api(mvm))
3486 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3488 case WLAN_CIPHER_SUITE_AES_CMAC:
3489 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3490 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3491 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3493 case WLAN_CIPHER_SUITE_WEP40:
3494 case WLAN_CIPHER_SUITE_WEP104:
3495 if (vif->type == NL80211_IFTYPE_STATION)
3497 if (iwl_mvm_has_new_tx_api(mvm))
3499 /* support HW crypto on TX */
3507 if (keyidx == 6 || keyidx == 7)
3508 rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6],
3511 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3512 vif->type == NL80211_IFTYPE_AP) && !sta) {
3514 * GTK on AP interface is a TX-only key, return 0;
3515 * on IBSS they're per-station and because we're lazy
3516 * we don't support them for RX, so do the same.
3517 * CMAC/GMAC in AP/IBSS modes must be done in software.
3519 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3520 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3521 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) {
3526 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3527 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3528 !iwl_mvm_has_new_tx_api(mvm)) {
3529 key->hw_key_idx = STA_KEY_IDX_INVALID;
3534 if (!mvmvif->ap_ibss_active) {
3536 i < ARRAY_SIZE(mvmvif->ap_early_keys);
3538 if (!mvmvif->ap_early_keys[i]) {
3539 mvmvif->ap_early_keys[i] = key;
3544 if (i >= ARRAY_SIZE(mvmvif->ap_early_keys))
3553 /* During FW restart, in order to restore the state as it was,
3554 * don't try to reprogram keys we previously failed for.
3556 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3557 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3558 IWL_DEBUG_MAC80211(mvm,
3559 "skip invalid idx key programming during restart\n");
3564 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3565 mvmsta && iwl_mvm_has_new_rx_api(mvm) &&
3566 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3567 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3568 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3569 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3570 struct ieee80211_key_seq seq;
3573 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3574 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3575 mvm->trans->num_rx_queues),
3582 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3583 ieee80211_get_key_rx_seq(key, tid, &seq);
3584 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3585 memcpy(ptk_pn->q[q].pn[tid],
3587 IEEE80211_CCMP_PN_LEN);
3590 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3593 /* in HW restart reuse the index, otherwise request a new one */
3594 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3595 key_offset = key->hw_key_idx;
3597 key_offset = STA_KEY_IDX_INVALID;
3599 if (mvmsta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3600 mvmsta->pairwise_cipher = key->cipher;
3602 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3603 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3605 IWL_WARN(mvm, "set key failed\n");
3606 key->hw_key_idx = STA_KEY_IDX_INVALID;
3608 * can't add key for RX, but we don't need it
3609 * in the device for TX so still return 0,
3610 * unless we have new TX API where we cannot
3611 * put key material into the TX_CMD
3613 if (iwl_mvm_has_new_tx_api(mvm))
3621 if (keyidx == 6 || keyidx == 7)
3622 RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6],
3626 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
3627 if (mvmvif->ap_early_keys[i] == key) {
3628 mvmvif->ap_early_keys[i] = NULL;
3633 /* found in pending list - don't do anything else */
3637 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3642 if (mvmsta && iwl_mvm_has_new_rx_api(mvm) &&
3643 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3644 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3645 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3646 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3647 ptk_pn = rcu_dereference_protected(
3648 mvmsta->ptk_pn[keyidx],
3649 lockdep_is_held(&mvm->mutex));
3650 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3652 kfree_rcu(ptk_pn, rcu_head);
3655 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3656 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3665 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3666 enum set_key_cmd cmd,
3667 struct ieee80211_vif *vif,
3668 struct ieee80211_sta *sta,
3669 struct ieee80211_key_conf *key)
3671 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3674 mutex_lock(&mvm->mutex);
3675 ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key);
3676 mutex_unlock(&mvm->mutex);
3681 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3682 struct ieee80211_vif *vif,
3683 struct ieee80211_key_conf *keyconf,
3684 struct ieee80211_sta *sta,
3685 u32 iv32, u16 *phase1key)
3687 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3689 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3692 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3696 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3697 struct iwl_rx_packet *pkt, void *data)
3699 struct iwl_mvm *mvm =
3700 container_of(notif_wait, struct iwl_mvm, notif_wait);
3701 struct iwl_hs20_roc_res *resp;
3702 int resp_len = iwl_rx_packet_payload_len(pkt);
3703 struct iwl_mvm_time_event_data *te_data = data;
3705 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3708 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3709 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3713 resp = (void *)pkt->data;
3716 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
3717 resp->status, resp->event_unique_id);
3719 te_data->uid = le32_to_cpu(resp->event_unique_id);
3720 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3723 spin_lock_bh(&mvm->time_event_lock);
3724 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3725 spin_unlock_bh(&mvm->time_event_lock);
3730 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3731 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3732 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3733 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3734 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3735 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3736 struct ieee80211_channel *channel,
3737 struct ieee80211_vif *vif,
3741 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3742 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3743 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3744 struct iwl_notification_wait wait_time_event;
3745 u32 dtim_interval = vif->bss_conf.dtim_period *
3746 vif->bss_conf.beacon_int;
3748 struct iwl_hs20_roc_req aux_roc_req = {
3749 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3751 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3752 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3754 struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm,
3755 &aux_roc_req.channel_info);
3756 u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm);
3758 /* Set the channel info data */
3759 iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value,
3760 iwl_mvm_phy_band_from_nl80211(channel->band),
3761 PHY_VHT_CHANNEL_MODE20,
3764 /* Set the time and duration */
3765 tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm));
3767 delay = AUX_ROC_MIN_DELAY;
3768 req_dur = MSEC_TO_TU(duration);
3771 * If we are associated we want the delay time to be at least one
3772 * dtim interval so that the FW can wait until after the DTIM and
3773 * then start the time event, this will potentially allow us to
3774 * remain off-channel for the max duration.
3775 * Since we want to use almost a whole dtim interval we would also
3776 * like the delay to be for 2-3 dtim intervals, in case there are
3777 * other time events with higher priority.
3779 if (vif->cfg.assoc) {
3780 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3781 /* We cannot remain off-channel longer than the DTIM interval */
3782 if (dtim_interval <= req_dur) {
3783 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3784 if (req_dur <= AUX_ROC_MIN_DURATION)
3785 req_dur = dtim_interval -
3786 AUX_ROC_MIN_SAFETY_BUFFER;
3790 tail->duration = cpu_to_le32(req_dur);
3791 tail->apply_time_max_delay = cpu_to_le32(delay);
3794 "ROC: Requesting to remain on channel %u for %ums\n",
3795 channel->hw_value, req_dur);
3797 "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3798 duration, delay, dtim_interval);
3800 /* Set the node address */
3801 memcpy(tail->node_addr, vif->addr, ETH_ALEN);
3803 lockdep_assert_held(&mvm->mutex);
3805 spin_lock_bh(&mvm->time_event_lock);
3807 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3808 spin_unlock_bh(&mvm->time_event_lock);
3813 te_data->duration = duration;
3814 te_data->id = HOT_SPOT_CMD;
3816 spin_unlock_bh(&mvm->time_event_lock);
3819 * Use a notification wait, which really just processes the
3820 * command response and doesn't wait for anything, in order
3821 * to be able to process the response and get the UID inside
3822 * the RX path. Using CMD_WANT_SKB doesn't work because it
3823 * stores the buffer and then wakes up this thread, by which
3824 * time another notification (that the time event started)
3825 * might already be processed unsuccessfully.
3827 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3828 time_event_response,
3829 ARRAY_SIZE(time_event_response),
3830 iwl_mvm_rx_aux_roc, te_data);
3832 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len,
3836 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3837 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3841 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3842 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3843 /* should never fail */
3848 spin_lock_bh(&mvm->time_event_lock);
3849 iwl_mvm_te_clear_data(mvm, te_data);
3850 spin_unlock_bh(&mvm->time_event_lock);
3856 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3857 struct ieee80211_vif *vif,
3858 struct ieee80211_channel *channel,
3860 enum ieee80211_roc_type type)
3862 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3863 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3864 struct cfg80211_chan_def chandef;
3865 struct iwl_mvm_phy_ctxt *phy_ctxt;
3866 bool band_change_removal;
3869 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3873 * Flush the done work, just in case it's still pending, so that
3874 * the work it does can complete and we can accept new frames.
3876 flush_work(&mvm->roc_done_wk);
3878 mutex_lock(&mvm->mutex);
3880 switch (vif->type) {
3881 case NL80211_IFTYPE_STATION:
3882 if (fw_has_capa(&mvm->fw->ucode_capa,
3883 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3884 /* Use aux roc framework (HS20) */
3885 if (iwl_fw_lookup_cmd_ver(mvm->fw, ADD_STA, 0) >= 12) {
3888 lmac_id = iwl_mvm_get_lmac_id(mvm->fw,
3890 ret = iwl_mvm_add_aux_sta(mvm, lmac_id);
3892 "Failed to allocate aux station"))
3895 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3899 IWL_ERR(mvm, "hotspot not supported\n");
3902 case NL80211_IFTYPE_P2P_DEVICE:
3906 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3911 for (i = 0; i < NUM_PHY_CTX; i++) {
3912 phy_ctxt = &mvm->phy_ctxts[i];
3913 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3916 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3918 * Unbind the P2P_DEVICE from the current PHY context,
3919 * and if the PHY context is not used remove it.
3921 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3922 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3925 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3927 /* Bind the P2P_DEVICE to the current PHY Context */
3928 mvmvif->phy_ctxt = phy_ctxt;
3930 ret = iwl_mvm_binding_add_vif(mvm, vif);
3931 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3934 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3935 goto schedule_time_event;
3939 /* Need to update the PHY context only if the ROC channel changed */
3940 if (channel == mvmvif->phy_ctxt->channel)
3941 goto schedule_time_event;
3943 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3946 * Check if the remain-on-channel is on a different band and that
3947 * requires context removal, see iwl_mvm_phy_ctxt_changed(). If
3948 * so, we'll need to release and then re-configure here, since we
3949 * must not remove a PHY context that's part of a binding.
3951 band_change_removal =
3952 fw_has_capa(&mvm->fw->ucode_capa,
3953 IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT) &&
3954 mvmvif->phy_ctxt->channel->band != chandef.chan->band;
3956 if (mvmvif->phy_ctxt->ref == 1 && !band_change_removal) {
3958 * Change the PHY context configuration as it is currently
3959 * referenced only by the P2P Device MAC (and we can modify it)
3961 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3967 * The PHY context is shared with other MACs (or we're trying to
3968 * switch bands), so remove the P2P Device from the binding,
3969 * allocate an new PHY context and create a new binding.
3971 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3977 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3980 IWL_ERR(mvm, "Failed to change PHY context\n");
3984 /* Unbind the P2P_DEVICE from the current PHY context */
3985 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3986 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3989 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3991 /* Bind the P2P_DEVICE to the new allocated PHY context */
3992 mvmvif->phy_ctxt = phy_ctxt;
3994 ret = iwl_mvm_binding_add_vif(mvm, vif);
3995 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3998 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
4001 schedule_time_event:
4002 /* Schedule the time events */
4003 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
4006 mutex_unlock(&mvm->mutex);
4007 IWL_DEBUG_MAC80211(mvm, "leave\n");
4011 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw,
4012 struct ieee80211_vif *vif)
4014 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4016 IWL_DEBUG_MAC80211(mvm, "enter\n");
4018 mutex_lock(&mvm->mutex);
4019 iwl_mvm_stop_roc(mvm, vif);
4020 mutex_unlock(&mvm->mutex);
4022 IWL_DEBUG_MAC80211(mvm, "leave\n");
4026 struct iwl_mvm_ftm_responder_iter_data {
4028 struct ieee80211_chanctx_conf *ctx;
4031 static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac,
4032 struct ieee80211_vif *vif)
4034 struct iwl_mvm_ftm_responder_iter_data *data = _data;
4036 if (rcu_access_pointer(vif->bss_conf.chanctx_conf) == data->ctx &&
4037 vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params)
4038 data->responder = true;
4041 static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm,
4042 struct ieee80211_chanctx_conf *ctx)
4044 struct iwl_mvm_ftm_responder_iter_data data = {
4049 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
4050 IEEE80211_IFACE_ITER_NORMAL,
4051 iwl_mvm_ftm_responder_chanctx_iter,
4053 return data.responder;
4056 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
4057 struct ieee80211_chanctx_conf *ctx)
4059 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4060 struct iwl_mvm_phy_ctxt *phy_ctxt;
4061 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4062 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
4065 lockdep_assert_held(&mvm->mutex);
4067 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
4069 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
4075 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4076 ctx->rx_chains_static,
4077 ctx->rx_chains_dynamic);
4079 IWL_ERR(mvm, "Failed to add PHY context\n");
4083 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
4084 *phy_ctxt_id = phy_ctxt->id;
4089 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
4090 struct ieee80211_chanctx_conf *ctx)
4092 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4095 mutex_lock(&mvm->mutex);
4096 ret = __iwl_mvm_add_chanctx(mvm, ctx);
4097 mutex_unlock(&mvm->mutex);
4102 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
4103 struct ieee80211_chanctx_conf *ctx)
4105 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4106 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4108 lockdep_assert_held(&mvm->mutex);
4110 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
4113 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
4114 struct ieee80211_chanctx_conf *ctx)
4116 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4118 mutex_lock(&mvm->mutex);
4119 __iwl_mvm_remove_chanctx(mvm, ctx);
4120 mutex_unlock(&mvm->mutex);
4123 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
4124 struct ieee80211_chanctx_conf *ctx,
4127 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4128 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4129 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4130 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4131 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
4133 if (WARN_ONCE((phy_ctxt->ref > 1) &&
4134 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
4135 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
4136 IEEE80211_CHANCTX_CHANGE_RADAR |
4137 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
4138 "Cannot change PHY. Ref=%d, changed=0x%X\n",
4139 phy_ctxt->ref, changed))
4142 mutex_lock(&mvm->mutex);
4144 /* we are only changing the min_width, may be a noop */
4145 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
4146 if (phy_ctxt->width == def->width)
4149 /* we are just toggling between 20_NOHT and 20 */
4150 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
4151 def->width <= NL80211_CHAN_WIDTH_20)
4155 iwl_mvm_bt_coex_vif_change(mvm);
4156 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4157 ctx->rx_chains_static,
4158 ctx->rx_chains_dynamic);
4161 mutex_unlock(&mvm->mutex);
4164 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
4165 struct ieee80211_vif *vif,
4166 struct ieee80211_chanctx_conf *ctx,
4167 bool switching_chanctx)
4169 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4170 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4171 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4174 lockdep_assert_held(&mvm->mutex);
4176 mvmvif->phy_ctxt = phy_ctxt;
4178 switch (vif->type) {
4179 case NL80211_IFTYPE_AP:
4180 /* only needed if we're switching chanctx (i.e. during CSA) */
4181 if (switching_chanctx) {
4182 mvmvif->ap_ibss_active = true;
4186 case NL80211_IFTYPE_ADHOC:
4188 * The AP binding flow is handled as part of the start_ap flow
4189 * (in bss_info_changed), similarly for IBSS.
4193 case NL80211_IFTYPE_STATION:
4194 mvmvif->csa_bcn_pending = false;
4196 case NL80211_IFTYPE_MONITOR:
4197 /* always disable PS when a monitor interface is active */
4198 mvmvif->ps_disabled = true;
4205 ret = iwl_mvm_binding_add_vif(mvm, vif);
4210 * Power state must be updated before quotas,
4211 * otherwise fw will complain.
4213 iwl_mvm_power_update_mac(mvm);
4215 /* Setting the quota at this stage is only required for monitor
4216 * interfaces. For the other types, the bss_info changed flow
4217 * will handle quota settings.
4219 if (vif->type == NL80211_IFTYPE_MONITOR) {
4220 mvmvif->monitor_active = true;
4221 ret = iwl_mvm_update_quotas(mvm, false, NULL);
4223 goto out_remove_binding;
4225 ret = iwl_mvm_add_snif_sta(mvm, vif);
4227 goto out_remove_binding;
4231 /* Handle binding during CSA */
4232 if (vif->type == NL80211_IFTYPE_AP) {
4233 iwl_mvm_update_quotas(mvm, false, NULL);
4234 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4237 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
4238 mvmvif->csa_bcn_pending = true;
4240 if (!fw_has_capa(&mvm->fw->ucode_capa,
4241 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4242 u32 duration = 3 * vif->bss_conf.beacon_int;
4244 /* Protect the session to make sure we hear the first
4245 * beacon on the new channel.
4247 iwl_mvm_protect_session(mvm, vif, duration, duration,
4248 vif->bss_conf.beacon_int / 2,
4252 iwl_mvm_update_quotas(mvm, false, NULL);
4258 iwl_mvm_binding_remove_vif(mvm, vif);
4259 iwl_mvm_power_update_mac(mvm);
4262 mvmvif->phy_ctxt = NULL;
4265 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
4266 struct ieee80211_vif *vif,
4267 struct ieee80211_bss_conf *link_conf,
4268 struct ieee80211_chanctx_conf *ctx)
4270 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4273 mutex_lock(&mvm->mutex);
4274 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
4275 mutex_unlock(&mvm->mutex);
4280 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
4281 struct ieee80211_vif *vif,
4282 struct ieee80211_chanctx_conf *ctx,
4283 bool switching_chanctx)
4285 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4286 struct ieee80211_vif *disabled_vif = NULL;
4288 lockdep_assert_held(&mvm->mutex);
4289 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
4291 switch (vif->type) {
4292 case NL80211_IFTYPE_ADHOC:
4294 case NL80211_IFTYPE_MONITOR:
4295 mvmvif->monitor_active = false;
4296 mvmvif->ps_disabled = false;
4297 iwl_mvm_rm_snif_sta(mvm, vif);
4299 case NL80211_IFTYPE_AP:
4300 /* This part is triggered only during CSA */
4301 if (!switching_chanctx || !mvmvif->ap_ibss_active)
4304 mvmvif->csa_countdown = false;
4306 /* Set CS bit on all the stations */
4307 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
4309 /* Save blocked iface, the timeout is set on the next beacon */
4310 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
4312 mvmvif->ap_ibss_active = false;
4314 case NL80211_IFTYPE_STATION:
4315 if (!switching_chanctx)
4320 if (!fw_has_capa(&mvm->fw->ucode_capa,
4321 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
4322 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
4328 iwl_mvm_update_quotas(mvm, false, disabled_vif);
4329 iwl_mvm_binding_remove_vif(mvm, vif);
4332 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD) &&
4335 mvmvif->phy_ctxt = NULL;
4336 iwl_mvm_power_update_mac(mvm);
4339 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
4340 struct ieee80211_vif *vif,
4341 struct ieee80211_bss_conf *link_conf,
4342 struct ieee80211_chanctx_conf *ctx)
4344 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4346 mutex_lock(&mvm->mutex);
4347 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
4348 mutex_unlock(&mvm->mutex);
4352 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
4353 struct ieee80211_vif_chanctx_switch *vifs)
4357 mutex_lock(&mvm->mutex);
4358 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4359 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
4361 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
4363 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
4367 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4371 "failed to assign new_ctx during channel switch\n");
4375 /* we don't support TDLS during DCM - can be caused by channel switch */
4376 if (iwl_mvm_phy_ctx_count(mvm) > 1)
4377 iwl_mvm_teardown_tdls_peers(mvm);
4382 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
4385 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
4386 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
4390 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4392 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4399 /* things keep failing, better restart the hw */
4400 iwl_mvm_nic_restart(mvm, false);
4403 mutex_unlock(&mvm->mutex);
4409 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
4410 struct ieee80211_vif_chanctx_switch *vifs)
4414 mutex_lock(&mvm->mutex);
4415 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4417 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4421 "failed to assign new_ctx during channel switch\n");
4428 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4430 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4437 /* things keep failing, better restart the hw */
4438 iwl_mvm_nic_restart(mvm, false);
4441 mutex_unlock(&mvm->mutex);
4446 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4447 struct ieee80211_vif_chanctx_switch *vifs,
4449 enum ieee80211_chanctx_switch_mode mode)
4451 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4454 /* we only support a single-vif right now */
4459 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4460 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4462 case CHANCTX_SWMODE_REASSIGN_VIF:
4463 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4473 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4475 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4477 return mvm->ibss_manager;
4480 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4481 struct ieee80211_sta *sta,
4484 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4485 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4487 if (!mvm_sta || !mvm_sta->vif) {
4488 IWL_ERR(mvm, "Station is not associated to a vif\n");
4492 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4495 #ifdef CONFIG_NL80211_TESTMODE
4496 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4497 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4498 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4499 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4502 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4503 struct ieee80211_vif *vif,
4504 void *data, int len)
4506 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4510 err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len,
4511 iwl_mvm_tm_policy, NULL);
4515 if (!tb[IWL_MVM_TM_ATTR_CMD])
4518 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4519 case IWL_MVM_TM_CMD_SET_NOA:
4520 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4521 !vif->bss_conf.enable_beacon ||
4522 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4525 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4526 if (noa_duration >= vif->bss_conf.beacon_int)
4529 mvm->noa_duration = noa_duration;
4532 return iwl_mvm_update_quotas(mvm, true, NULL);
4533 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4534 /* must be associated client vif - ignore authorized */
4535 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4536 !vif->cfg.assoc || !vif->bss_conf.dtim_period ||
4537 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4540 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4541 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4542 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4548 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4549 struct ieee80211_vif *vif,
4550 void *data, int len)
4552 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4555 mutex_lock(&mvm->mutex);
4556 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4557 mutex_unlock(&mvm->mutex);
4563 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4564 struct ieee80211_vif *vif,
4565 struct ieee80211_channel_switch *chsw)
4567 /* By implementing this operation, we prevent mac80211 from
4568 * starting its own channel switch timer, so that we can call
4569 * ieee80211_chswitch_done() ourselves at the right time
4570 * (which is when the absence time event starts).
4573 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4574 "dummy channel switch op\n");
4577 static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm,
4578 struct ieee80211_vif *vif,
4579 struct ieee80211_channel_switch *chsw)
4581 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4582 struct iwl_chan_switch_te_cmd cmd = {
4583 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4585 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
4586 .tsf = cpu_to_le32(chsw->timestamp),
4587 .cs_count = chsw->count,
4588 .cs_mode = chsw->block_tx,
4591 lockdep_assert_held(&mvm->mutex);
4594 cmd.cs_delayed_bcn_count =
4595 DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int);
4597 return iwl_mvm_send_cmd_pdu(mvm,
4598 WIDE_ID(MAC_CONF_GROUP,
4599 CHANNEL_SWITCH_TIME_EVENT_CMD),
4600 0, sizeof(cmd), &cmd);
4603 static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm,
4604 struct ieee80211_vif *vif,
4605 struct ieee80211_channel_switch *chsw)
4607 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4610 /* Schedule the time event to a bit before beacon 1,
4611 * to make sure we're in the new channel when the
4612 * GO/AP arrives. In case count <= 1 immediately schedule the
4613 * TE (this might result with some packet loss or connection
4616 if (chsw->count <= 1)
4619 apply_time = chsw->device_timestamp +
4620 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4621 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4624 iwl_mvm_csa_client_absent(mvm, vif);
4626 if (mvmvif->bf_data.bf_enabled) {
4627 int ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4633 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4639 #define IWL_MAX_CSA_BLOCK_TX 1500
4640 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4641 struct ieee80211_vif *vif,
4642 struct ieee80211_channel_switch *chsw)
4644 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4645 struct ieee80211_vif *csa_vif;
4646 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4649 mutex_lock(&mvm->mutex);
4651 mvmvif->csa_failed = false;
4653 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4654 chsw->chandef.center_freq1);
4656 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4657 ieee80211_vif_to_wdev(vif),
4658 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4660 switch (vif->type) {
4661 case NL80211_IFTYPE_AP:
4663 rcu_dereference_protected(mvm->csa_vif,
4664 lockdep_is_held(&mvm->mutex));
4665 if (WARN_ONCE(csa_vif && csa_vif->bss_conf.csa_active,
4666 "Another CSA is already in progress")) {
4671 /* we still didn't unblock tx. prevent new CS meanwhile */
4672 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4673 lockdep_is_held(&mvm->mutex))) {
4678 rcu_assign_pointer(mvm->csa_vif, vif);
4680 if (WARN_ONCE(mvmvif->csa_countdown,
4681 "Previous CSA countdown didn't complete")) {
4686 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4689 case NL80211_IFTYPE_STATION:
4691 * In the new flow FW is in charge of timing the switch so there
4692 * is no need for all of this
4694 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
4695 CHANNEL_SWITCH_ERROR_NOTIF,
4700 * We haven't configured the firmware to be associated yet since
4701 * we don't know the dtim period. In this case, the firmware can't
4702 * track the beacons.
4704 if (!vif->cfg.assoc || !vif->bss_conf.dtim_period) {
4709 if (chsw->delay > IWL_MAX_CSA_BLOCK_TX)
4710 schedule_delayed_work(&mvmvif->csa_work, 0);
4712 if (chsw->block_tx) {
4714 * In case of undetermined / long time with immediate
4715 * quiet monitor status to gracefully disconnect
4718 chsw->count * vif->bss_conf.beacon_int >
4719 IWL_MAX_CSA_BLOCK_TX)
4720 schedule_delayed_work(&mvmvif->csa_work,
4721 msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX));
4724 if (!fw_has_capa(&mvm->fw->ucode_capa,
4725 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4726 ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw);
4730 iwl_mvm_schedule_client_csa(mvm, vif, chsw);
4733 mvmvif->csa_count = chsw->count;
4734 mvmvif->csa_misbehave = false;
4740 mvmvif->ps_disabled = true;
4742 ret = iwl_mvm_power_update_ps(mvm);
4746 /* we won't be on this channel any longer */
4747 iwl_mvm_teardown_tdls_peers(mvm);
4750 mutex_unlock(&mvm->mutex);
4755 static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw,
4756 struct ieee80211_vif *vif,
4757 struct ieee80211_channel_switch *chsw)
4759 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4760 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4761 struct iwl_chan_switch_te_cmd cmd = {
4762 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4764 .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY),
4765 .tsf = cpu_to_le32(chsw->timestamp),
4766 .cs_count = chsw->count,
4767 .cs_mode = chsw->block_tx,
4771 * In the new flow FW is in charge of timing the switch so there is no
4772 * need for all of this
4774 if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
4775 CHANNEL_SWITCH_ERROR_NOTIF, 0))
4778 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY))
4781 IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d (old %d) mode = %d\n",
4782 mvmvif->id, chsw->count, mvmvif->csa_count, chsw->block_tx);
4784 if (chsw->count >= mvmvif->csa_count && chsw->block_tx) {
4785 if (mvmvif->csa_misbehave) {
4786 /* Second time, give up on this AP*/
4787 iwl_mvm_abort_channel_switch(hw, vif);
4788 ieee80211_chswitch_done(vif, false);
4789 mvmvif->csa_misbehave = false;
4792 mvmvif->csa_misbehave = true;
4794 mvmvif->csa_count = chsw->count;
4796 mutex_lock(&mvm->mutex);
4797 if (mvmvif->csa_failed)
4800 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
4801 WIDE_ID(MAC_CONF_GROUP,
4802 CHANNEL_SWITCH_TIME_EVENT_CMD),
4803 0, sizeof(cmd), &cmd));
4805 mutex_unlock(&mvm->mutex);
4808 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4812 if (!iwl_mvm_has_new_tx_api(mvm)) {
4814 mutex_lock(&mvm->mutex);
4815 iwl_mvm_flush_tx_path(mvm,
4816 iwl_mvm_flushable_queues(mvm) & queues);
4817 mutex_unlock(&mvm->mutex);
4819 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4824 mutex_lock(&mvm->mutex);
4825 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
4826 struct ieee80211_sta *sta;
4828 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4829 lockdep_is_held(&mvm->mutex));
4830 if (IS_ERR_OR_NULL(sta))
4834 iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF);
4836 iwl_mvm_wait_sta_queues_empty(mvm,
4837 iwl_mvm_sta_from_mac80211(sta));
4839 mutex_unlock(&mvm->mutex);
4842 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4843 struct ieee80211_vif *vif, u32 queues, bool drop)
4845 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4846 struct iwl_mvm_vif *mvmvif;
4847 struct iwl_mvm_sta *mvmsta;
4848 struct ieee80211_sta *sta;
4853 iwl_mvm_flush_no_vif(mvm, queues, drop);
4857 if (vif->type != NL80211_IFTYPE_STATION)
4860 /* Make sure we're done with the deferred traffic before flushing */
4861 flush_work(&mvm->add_stream_wk);
4863 mutex_lock(&mvm->mutex);
4864 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4866 /* flush the AP-station and all TDLS peers */
4867 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
4868 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4869 lockdep_is_held(&mvm->mutex));
4870 if (IS_ERR_OR_NULL(sta))
4873 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4874 if (mvmsta->vif != vif)
4877 /* make sure only TDLS peers or the AP are flushed */
4878 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4881 if (iwl_mvm_flush_sta(mvm, mvmsta, false))
4882 IWL_ERR(mvm, "flush request fail\n");
4884 msk |= mvmsta->tfd_queue_msk;
4885 if (iwl_mvm_has_new_tx_api(mvm))
4886 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4890 mutex_unlock(&mvm->mutex);
4892 /* this can take a while, and we may need/want other operations
4893 * to succeed while doing this, so do it without the mutex held
4895 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4896 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4899 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4900 struct survey_info *survey)
4902 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4905 memset(survey, 0, sizeof(*survey));
4907 /* only support global statistics right now */
4911 if (!fw_has_capa(&mvm->fw->ucode_capa,
4912 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4915 mutex_lock(&mvm->mutex);
4917 if (iwl_mvm_firmware_running(mvm)) {
4918 ret = iwl_mvm_request_statistics(mvm, false);
4923 survey->filled = SURVEY_INFO_TIME |
4924 SURVEY_INFO_TIME_RX |
4925 SURVEY_INFO_TIME_TX |
4926 SURVEY_INFO_TIME_SCAN;
4927 survey->time = mvm->accu_radio_stats.on_time_rf +
4928 mvm->radio_stats.on_time_rf;
4929 do_div(survey->time, USEC_PER_MSEC);
4931 survey->time_rx = mvm->accu_radio_stats.rx_time +
4932 mvm->radio_stats.rx_time;
4933 do_div(survey->time_rx, USEC_PER_MSEC);
4935 survey->time_tx = mvm->accu_radio_stats.tx_time +
4936 mvm->radio_stats.tx_time;
4937 do_div(survey->time_tx, USEC_PER_MSEC);
4939 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4940 mvm->radio_stats.on_time_scan;
4941 do_div(survey->time_scan, USEC_PER_MSEC);
4945 mutex_unlock(&mvm->mutex);
4949 static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo)
4951 u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
4954 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
4955 case RATE_MCS_CHAN_WIDTH_20:
4956 rinfo->bw = RATE_INFO_BW_20;
4958 case RATE_MCS_CHAN_WIDTH_40:
4959 rinfo->bw = RATE_INFO_BW_40;
4961 case RATE_MCS_CHAN_WIDTH_80:
4962 rinfo->bw = RATE_INFO_BW_80;
4964 case RATE_MCS_CHAN_WIDTH_160:
4965 rinfo->bw = RATE_INFO_BW_160;
4969 if (format == RATE_MCS_CCK_MSK ||
4970 format == RATE_MCS_LEGACY_OFDM_MSK) {
4971 int rate = u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK);
4973 /* add the offset needed to get to the legacy ofdm indices */
4974 if (format == RATE_MCS_LEGACY_OFDM_MSK)
4975 rate += IWL_FIRST_OFDM_RATE;
4978 case IWL_RATE_1M_INDEX:
4981 case IWL_RATE_2M_INDEX:
4984 case IWL_RATE_5M_INDEX:
4987 case IWL_RATE_11M_INDEX:
4988 rinfo->legacy = 110;
4990 case IWL_RATE_6M_INDEX:
4993 case IWL_RATE_9M_INDEX:
4996 case IWL_RATE_12M_INDEX:
4997 rinfo->legacy = 120;
4999 case IWL_RATE_18M_INDEX:
5000 rinfo->legacy = 180;
5002 case IWL_RATE_24M_INDEX:
5003 rinfo->legacy = 240;
5005 case IWL_RATE_36M_INDEX:
5006 rinfo->legacy = 360;
5008 case IWL_RATE_48M_INDEX:
5009 rinfo->legacy = 480;
5011 case IWL_RATE_54M_INDEX:
5012 rinfo->legacy = 540;
5017 rinfo->nss = u32_get_bits(rate_n_flags,
5018 RATE_MCS_NSS_MSK) + 1;
5019 rinfo->mcs = format == RATE_MCS_HT_MSK ?
5020 RATE_HT_MCS_INDEX(rate_n_flags) :
5021 u32_get_bits(rate_n_flags, RATE_MCS_CODE_MSK);
5023 if (rate_n_flags & RATE_MCS_SGI_MSK)
5024 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
5027 case RATE_MCS_HE_MSK:
5028 gi_ltf = u32_get_bits(rate_n_flags, RATE_MCS_HE_GI_LTF_MSK);
5030 rinfo->flags |= RATE_INFO_FLAGS_HE_MCS;
5032 if (rate_n_flags & RATE_MCS_HE_106T_MSK) {
5033 rinfo->bw = RATE_INFO_BW_HE_RU;
5034 rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106;
5037 switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) {
5038 case RATE_MCS_HE_TYPE_SU:
5039 case RATE_MCS_HE_TYPE_EXT_SU:
5040 if (gi_ltf == 0 || gi_ltf == 1)
5041 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
5042 else if (gi_ltf == 2)
5043 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
5044 else if (gi_ltf == 3)
5045 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
5047 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
5049 case RATE_MCS_HE_TYPE_MU:
5050 if (gi_ltf == 0 || gi_ltf == 1)
5051 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
5052 else if (gi_ltf == 2)
5053 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
5055 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
5057 case RATE_MCS_HE_TYPE_TRIG:
5058 if (gi_ltf == 0 || gi_ltf == 1)
5059 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
5061 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
5065 if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK)
5068 case RATE_MCS_HT_MSK:
5069 rinfo->flags |= RATE_INFO_FLAGS_MCS;
5071 case RATE_MCS_VHT_MSK:
5072 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
5077 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
5078 struct ieee80211_vif *vif,
5079 struct ieee80211_sta *sta,
5080 struct station_info *sinfo)
5082 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5083 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5084 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
5086 if (mvmsta->avg_energy) {
5087 sinfo->signal_avg = -(s8)mvmsta->avg_energy;
5088 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
5091 if (iwl_mvm_has_tlc_offload(mvm)) {
5092 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
5094 iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate);
5095 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
5098 /* if beacon filtering isn't on mac80211 does it anyway */
5099 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
5102 if (!vif->cfg.assoc)
5105 mutex_lock(&mvm->mutex);
5107 if (mvmvif->ap_sta_id != mvmsta->sta_id)
5110 if (iwl_mvm_request_statistics(mvm, false))
5113 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
5114 mvmvif->beacon_stats.accu_num_beacons;
5115 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
5116 if (mvmvif->beacon_stats.avg_signal) {
5117 /* firmware only reports a value after RXing a few beacons */
5118 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
5119 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
5122 mutex_unlock(&mvm->mutex);
5125 static void iwl_mvm_event_mlme_callback_ini(struct iwl_mvm *mvm,
5126 struct ieee80211_vif *vif,
5127 const struct ieee80211_mlme_event *mlme)
5129 if ((mlme->data == ASSOC_EVENT || mlme->data == AUTH_EVENT) &&
5130 (mlme->status == MLME_DENIED || mlme->status == MLME_TIMEOUT)) {
5131 iwl_dbg_tlv_time_point(&mvm->fwrt,
5132 IWL_FW_INI_TIME_POINT_ASSOC_FAILED,
5137 if (mlme->data == DEAUTH_RX_EVENT || mlme->data == DEAUTH_TX_EVENT) {
5138 iwl_dbg_tlv_time_point(&mvm->fwrt,
5139 IWL_FW_INI_TIME_POINT_DEASSOC,
5145 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
5146 struct ieee80211_vif *vif,
5147 const struct ieee80211_event *event)
5149 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
5151 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
5153 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
5156 struct iwl_fw_dbg_trigger_tlv *trig;
5157 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
5159 if (iwl_trans_dbg_ini_valid(mvm->trans)) {
5160 iwl_mvm_event_mlme_callback_ini(mvm, vif, &event->u.mlme);
5164 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5165 FW_DBG_TRIGGER_MLME);
5169 trig_mlme = (void *)trig->data;
5171 if (event->u.mlme.data == ASSOC_EVENT) {
5172 if (event->u.mlme.status == MLME_DENIED)
5173 CHECK_MLME_TRIGGER(stop_assoc_denied,
5174 "DENIED ASSOC: reason %d",
5175 event->u.mlme.reason);
5176 else if (event->u.mlme.status == MLME_TIMEOUT)
5177 CHECK_MLME_TRIGGER(stop_assoc_timeout,
5179 } else if (event->u.mlme.data == AUTH_EVENT) {
5180 if (event->u.mlme.status == MLME_DENIED)
5181 CHECK_MLME_TRIGGER(stop_auth_denied,
5182 "DENIED AUTH: reason %d",
5183 event->u.mlme.reason);
5184 else if (event->u.mlme.status == MLME_TIMEOUT)
5185 CHECK_MLME_TRIGGER(stop_auth_timeout,
5187 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
5188 CHECK_MLME_TRIGGER(stop_rx_deauth,
5189 "DEAUTH RX %d", event->u.mlme.reason);
5190 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
5191 CHECK_MLME_TRIGGER(stop_tx_deauth,
5192 "DEAUTH TX %d", event->u.mlme.reason);
5194 #undef CHECK_MLME_TRIGGER
5197 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
5198 struct ieee80211_vif *vif,
5199 const struct ieee80211_event *event)
5201 struct iwl_fw_dbg_trigger_tlv *trig;
5202 struct iwl_fw_dbg_trigger_ba *ba_trig;
5204 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5209 ba_trig = (void *)trig->data;
5211 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
5214 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
5215 "BAR received from %pM, tid %d, ssn %d",
5216 event->u.ba.sta->addr, event->u.ba.tid,
5220 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
5221 struct ieee80211_vif *vif,
5222 const struct ieee80211_event *event)
5224 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5226 switch (event->type) {
5228 iwl_mvm_event_mlme_callback(mvm, vif, event);
5231 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
5233 case BA_FRAME_TIMEOUT:
5234 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
5242 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
5243 enum iwl_mvm_rxq_notif_type type,
5245 const void *data, u32 size)
5248 struct iwl_rxq_sync_cmd cmd;
5249 struct iwl_mvm_internal_rxq_notif notif;
5251 .cmd.rxq_mask = cpu_to_le32(BIT(mvm->trans->num_rx_queues) - 1),
5253 cpu_to_le32(sizeof(struct iwl_mvm_internal_rxq_notif) +
5258 struct iwl_host_cmd hcmd = {
5259 .id = WIDE_ID(DATA_PATH_GROUP, TRIGGER_RX_QUEUES_NOTIF_CMD),
5261 .len[0] = sizeof(cmd),
5264 .flags = sync ? 0 : CMD_ASYNC,
5268 /* size must be a multiple of DWORD */
5269 if (WARN_ON(cmd.cmd.count & cpu_to_le32(3)))
5272 if (!iwl_mvm_has_new_rx_api(mvm))
5276 cmd.notif.cookie = mvm->queue_sync_cookie;
5277 mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1;
5280 ret = iwl_mvm_send_cmd(mvm, &hcmd);
5282 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
5287 lockdep_assert_held(&mvm->mutex);
5288 ret = wait_event_timeout(mvm->rx_sync_waitq,
5289 READ_ONCE(mvm->queue_sync_state) == 0 ||
5290 iwl_mvm_is_radio_killed(mvm),
5292 WARN_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm),
5293 "queue sync: failed to sync, state is 0x%lx\n",
5294 mvm->queue_sync_state);
5299 mvm->queue_sync_state = 0;
5300 mvm->queue_sync_cookie++;
5304 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
5306 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5308 mutex_lock(&mvm->mutex);
5309 iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_EMPTY, true, NULL, 0);
5310 mutex_unlock(&mvm->mutex);
5314 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw,
5315 struct ieee80211_vif *vif,
5316 struct cfg80211_ftm_responder_stats *stats)
5318 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5319 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5321 if (vif->p2p || vif->type != NL80211_IFTYPE_AP ||
5322 !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder)
5325 mutex_lock(&mvm->mutex);
5326 *stats = mvm->ftm_resp_stats;
5327 mutex_unlock(&mvm->mutex);
5329 stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) |
5330 BIT(NL80211_FTM_STATS_PARTIAL_NUM) |
5331 BIT(NL80211_FTM_STATS_FAILED_NUM) |
5332 BIT(NL80211_FTM_STATS_ASAP_NUM) |
5333 BIT(NL80211_FTM_STATS_NON_ASAP_NUM) |
5334 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) |
5335 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) |
5336 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) |
5337 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM);
5342 static int iwl_mvm_start_pmsr(struct ieee80211_hw *hw,
5343 struct ieee80211_vif *vif,
5344 struct cfg80211_pmsr_request *request)
5346 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5349 mutex_lock(&mvm->mutex);
5350 ret = iwl_mvm_ftm_start(mvm, vif, request);
5351 mutex_unlock(&mvm->mutex);
5356 static void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw,
5357 struct ieee80211_vif *vif,
5358 struct cfg80211_pmsr_request *request)
5360 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5362 mutex_lock(&mvm->mutex);
5363 iwl_mvm_ftm_abort(mvm, request);
5364 mutex_unlock(&mvm->mutex);
5367 static bool iwl_mvm_can_hw_csum(struct sk_buff *skb)
5369 u8 protocol = ip_hdr(skb)->protocol;
5371 if (!IS_ENABLED(CONFIG_INET))
5374 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
5377 static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw,
5378 struct sk_buff *head,
5379 struct sk_buff *skb)
5381 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5383 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_BZ)
5384 return iwl_mvm_tx_csum_bz(mvm, head, true) ==
5385 iwl_mvm_tx_csum_bz(mvm, skb, true);
5387 /* For now don't aggregate IPv6 in AMSDU */
5388 if (skb->protocol != htons(ETH_P_IP))
5391 if (!iwl_mvm_is_csum_supported(mvm))
5394 return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head);
5397 const struct ieee80211_ops iwl_mvm_hw_ops = {
5398 .tx = iwl_mvm_mac_tx,
5399 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue,
5400 .ampdu_action = iwl_mvm_mac_ampdu_action,
5401 .get_antenna = iwl_mvm_op_get_antenna,
5402 .start = iwl_mvm_mac_start,
5403 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
5404 .stop = iwl_mvm_mac_stop,
5405 .add_interface = iwl_mvm_mac_add_interface,
5406 .remove_interface = iwl_mvm_mac_remove_interface,
5407 .config = iwl_mvm_mac_config,
5408 .prepare_multicast = iwl_mvm_prepare_multicast,
5409 .configure_filter = iwl_mvm_configure_filter,
5410 .config_iface_filter = iwl_mvm_config_iface_filter,
5411 .bss_info_changed = iwl_mvm_bss_info_changed,
5412 .hw_scan = iwl_mvm_mac_hw_scan,
5413 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
5414 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
5415 .sta_state = iwl_mvm_mac_sta_state,
5416 .sta_notify = iwl_mvm_mac_sta_notify,
5417 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
5418 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
5419 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
5420 .sta_rc_update = iwl_mvm_sta_rc_update,
5421 .conf_tx = iwl_mvm_mac_conf_tx,
5422 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
5423 .mgd_complete_tx = iwl_mvm_mac_mgd_complete_tx,
5424 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
5425 .flush = iwl_mvm_mac_flush,
5426 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
5427 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
5428 .set_key = iwl_mvm_mac_set_key,
5429 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
5430 .remain_on_channel = iwl_mvm_roc,
5431 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
5432 .add_chanctx = iwl_mvm_add_chanctx,
5433 .remove_chanctx = iwl_mvm_remove_chanctx,
5434 .change_chanctx = iwl_mvm_change_chanctx,
5435 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
5436 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
5437 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
5439 .start_ap = iwl_mvm_start_ap,
5440 .stop_ap = iwl_mvm_stop_ap,
5441 .join_ibss = iwl_mvm_start_ibss,
5442 .leave_ibss = iwl_mvm_stop_ibss,
5444 .tx_last_beacon = iwl_mvm_tx_last_beacon,
5446 .set_tim = iwl_mvm_set_tim,
5448 .channel_switch = iwl_mvm_channel_switch,
5449 .pre_channel_switch = iwl_mvm_pre_channel_switch,
5450 .post_channel_switch = iwl_mvm_post_channel_switch,
5451 .abort_channel_switch = iwl_mvm_abort_channel_switch,
5452 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon,
5454 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
5455 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
5456 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
5458 .event_callback = iwl_mvm_mac_event_callback,
5460 .sync_rx_queues = iwl_mvm_sync_rx_queues,
5462 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
5464 #ifdef CONFIG_PM_SLEEP
5466 .suspend = iwl_mvm_suspend,
5467 .resume = iwl_mvm_resume,
5468 .set_wakeup = iwl_mvm_set_wakeup,
5469 .set_rekey_data = iwl_mvm_set_rekey_data,
5470 #if IS_ENABLED(CONFIG_IPV6)
5471 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
5473 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
5475 .get_survey = iwl_mvm_mac_get_survey,
5476 .sta_statistics = iwl_mvm_mac_sta_statistics,
5477 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats,
5478 .start_pmsr = iwl_mvm_start_pmsr,
5479 .abort_pmsr = iwl_mvm_abort_pmsr,
5481 .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate,
5482 #ifdef CONFIG_IWLWIFI_DEBUGFS
5483 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,