1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2012-2014, 2018-2020 Intel Corporation
4 * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5 * Copyright (C) 2016-2017 Intel Deutschland GmbH
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>
19 #include "iwl-op-mode.h"
23 #include "time-event.h"
24 #include "iwl-eeprom-parse.h"
25 #include "iwl-phy-db.h"
27 #include "fw/error-dump.h"
29 #include "iwl-nvm-parse.h"
31 static const struct ieee80211_iface_limit iwl_mvm_limits[] = {
34 .types = BIT(NL80211_IFTYPE_STATION),
38 .types = BIT(NL80211_IFTYPE_AP) |
39 BIT(NL80211_IFTYPE_P2P_CLIENT) |
40 BIT(NL80211_IFTYPE_P2P_GO),
44 .types = BIT(NL80211_IFTYPE_P2P_DEVICE),
48 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations[] = {
50 .num_different_channels = 2,
52 .limits = iwl_mvm_limits,
53 .n_limits = ARRAY_SIZE(iwl_mvm_limits),
57 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
59 * Use the reserved field to indicate magic values.
60 * these values will only be used internally by the driver,
61 * and won't make it to the fw (reserved will be 0).
62 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
63 * be the vif's ip address. in case there is not a single
64 * ip address (0, or more than 1), this attribute will
66 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
67 * the LSB bytes of the vif's mac address
70 BC_FILTER_MAGIC_NONE = 0,
75 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters[] = {
79 .frame_type = BCAST_FILTER_FRAME_TYPE_ALL,
82 /* frame type - arp, hw type - ethernet */
84 BCAST_FILTER_OFFSET_PAYLOAD_START,
85 .offset = sizeof(rfc1042_header),
86 .val = cpu_to_be32(0x08060001),
87 .mask = cpu_to_be32(0xffffffff),
92 BCAST_FILTER_OFFSET_PAYLOAD_START,
93 .offset = sizeof(rfc1042_header) + 2 +
94 sizeof(struct arphdr) +
95 ETH_ALEN + sizeof(__be32) +
97 .mask = cpu_to_be32(0xffffffff),
98 /* mark it as special field */
99 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_IP),
104 /* dhcp offer bcast */
106 .frame_type = BCAST_FILTER_FRAME_TYPE_IPV4,
109 /* udp dest port - 68 (bootp client)*/
110 .offset_type = BCAST_FILTER_OFFSET_IP_END,
111 .offset = offsetof(struct udphdr, dest),
112 .val = cpu_to_be32(0x00440000),
113 .mask = cpu_to_be32(0xffff0000),
116 /* dhcp - lsb bytes of client hw address */
117 .offset_type = BCAST_FILTER_OFFSET_IP_END,
119 .mask = cpu_to_be32(0xffffffff),
120 /* mark it as special field */
121 .reserved1 = cpu_to_le16(BC_FILTER_MAGIC_MAC),
125 /* last filter must be empty */
130 static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa = {
131 .max_peers = IWL_MVM_TOF_MAX_APS,
133 .randomize_mac_addr = 1,
140 .request_civicloc = 1,
142 .non_trigger_based = 1,
143 .max_bursts_exponent = -1, /* all supported */
144 .max_ftms_per_burst = 0, /* no limits */
145 .bandwidths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
146 BIT(NL80211_CHAN_WIDTH_20) |
147 BIT(NL80211_CHAN_WIDTH_40) |
148 BIT(NL80211_CHAN_WIDTH_80),
149 .preambles = BIT(NL80211_PREAMBLE_LEGACY) |
150 BIT(NL80211_PREAMBLE_HT) |
151 BIT(NL80211_PREAMBLE_VHT) |
152 BIT(NL80211_PREAMBLE_HE),
156 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
157 enum set_key_cmd cmd,
158 struct ieee80211_vif *vif,
159 struct ieee80211_sta *sta,
160 struct ieee80211_key_conf *key);
162 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm *mvm)
166 memset(mvm->phy_ctxts, 0, sizeof(mvm->phy_ctxts));
167 for (i = 0; i < NUM_PHY_CTX; i++) {
168 mvm->phy_ctxts[i].id = i;
169 mvm->phy_ctxts[i].ref = 0;
173 struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
175 enum iwl_mcc_source src_id,
178 struct ieee80211_regdomain *regd = NULL;
179 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
180 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
181 struct iwl_mcc_update_resp *resp;
184 IWL_DEBUG_LAR(mvm, "Getting regdomain data for %s from FW\n", alpha2);
186 lockdep_assert_held(&mvm->mutex);
188 resp = iwl_mvm_update_mcc(mvm, alpha2, src_id);
189 if (IS_ERR_OR_NULL(resp)) {
190 IWL_DEBUG_LAR(mvm, "Could not get update from FW %d\n",
191 PTR_ERR_OR_ZERO(resp));
196 u32 status = le32_to_cpu(resp->status);
198 *changed = (status == MCC_RESP_NEW_CHAN_PROFILE ||
199 status == MCC_RESP_ILLEGAL);
201 resp_ver = iwl_fw_lookup_notif_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP,
203 IWL_DEBUG_LAR(mvm, "MCC update response version: %d\n", resp_ver);
205 regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
206 __le32_to_cpu(resp->n_channels),
208 __le16_to_cpu(resp->mcc),
209 __le16_to_cpu(resp->geo_info),
210 __le16_to_cpu(resp->cap), resp_ver);
211 /* Store the return source id */
212 src_id = resp->source_id;
214 if (IS_ERR_OR_NULL(regd)) {
215 IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
216 PTR_ERR_OR_ZERO(regd));
220 IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
221 regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
222 mvm->lar_regdom_set = true;
223 mvm->mcc_src = src_id;
229 void iwl_mvm_update_changed_regdom(struct iwl_mvm *mvm)
232 struct ieee80211_regdomain *regd;
234 if (!iwl_mvm_is_lar_supported(mvm))
237 regd = iwl_mvm_get_current_regdomain(mvm, &changed);
238 if (!IS_ERR_OR_NULL(regd)) {
239 /* only update the regulatory core if changed */
241 regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
247 struct ieee80211_regdomain *iwl_mvm_get_current_regdomain(struct iwl_mvm *mvm,
250 return iwl_mvm_get_regdomain(mvm->hw->wiphy, "ZZ",
251 iwl_mvm_is_wifi_mcc_supported(mvm) ?
252 MCC_SOURCE_GET_CURRENT :
253 MCC_SOURCE_OLD_FW, changed);
256 int iwl_mvm_init_fw_regd(struct iwl_mvm *mvm)
258 enum iwl_mcc_source used_src;
259 struct ieee80211_regdomain *regd;
262 const struct ieee80211_regdomain *r =
263 wiphy_dereference(mvm->hw->wiphy, mvm->hw->wiphy->regd);
268 /* save the last source in case we overwrite it below */
269 used_src = mvm->mcc_src;
270 if (iwl_mvm_is_wifi_mcc_supported(mvm)) {
271 /* Notify the firmware we support wifi location updates */
272 regd = iwl_mvm_get_current_regdomain(mvm, NULL);
273 if (!IS_ERR_OR_NULL(regd))
277 /* Now set our last stored MCC and source */
278 regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
280 if (IS_ERR_OR_NULL(regd))
283 /* update cfg80211 if the regdomain was changed */
285 ret = regulatory_set_wiphy_regd_sync(mvm->hw->wiphy, regd);
293 static const u8 he_if_types_ext_capa_sta[] = {
294 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
295 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
296 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
297 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
300 static const struct wiphy_iftype_ext_capab he_iftypes_ext_capa[] = {
302 .iftype = NL80211_IFTYPE_STATION,
303 .extended_capabilities = he_if_types_ext_capa_sta,
304 .extended_capabilities_mask = he_if_types_ext_capa_sta,
305 .extended_capabilities_len = sizeof(he_if_types_ext_capa_sta),
310 iwl_mvm_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
312 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
313 *tx_ant = iwl_mvm_get_valid_tx_ant(mvm);
314 *rx_ant = iwl_mvm_get_valid_rx_ant(mvm);
318 int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
320 struct ieee80211_hw *hw = mvm->hw;
322 static const u32 mvm_ciphers[] = {
323 WLAN_CIPHER_SUITE_WEP40,
324 WLAN_CIPHER_SUITE_WEP104,
325 WLAN_CIPHER_SUITE_TKIP,
326 WLAN_CIPHER_SUITE_CCMP,
328 #ifdef CONFIG_PM_SLEEP
329 bool unified = fw_has_capa(&mvm->fw->ucode_capa,
330 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
333 /* Tell mac80211 our characteristics */
334 ieee80211_hw_set(hw, SIGNAL_DBM);
335 ieee80211_hw_set(hw, SPECTRUM_MGMT);
336 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
337 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
338 ieee80211_hw_set(hw, SUPPORTS_PS);
339 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
340 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
341 ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
342 ieee80211_hw_set(hw, CONNECTION_MONITOR);
343 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
344 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
345 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
346 ieee80211_hw_set(hw, SUPPORTS_AMSDU_IN_AMPDU);
347 ieee80211_hw_set(hw, NEEDS_UNIQUE_STA_ADDR);
348 ieee80211_hw_set(hw, DEAUTH_NEED_MGD_TX_PREP);
349 ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
350 ieee80211_hw_set(hw, BUFF_MMPDU_TXQ);
351 ieee80211_hw_set(hw, STA_MMPDU_TXQ);
353 * On older devices, enabling TX A-MSDU occasionally leads to
354 * something getting messed up, the command read from the FIFO
355 * gets out of sync and isn't a TX command, so that we have an
358 * It's not clear where the bug is, but since we didn't used to
359 * support A-MSDU until moving the mac80211 iTXQs, just leave it
360 * for older devices. We also don't see this issue on any newer
363 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_9000)
364 ieee80211_hw_set(hw, TX_AMSDU);
365 ieee80211_hw_set(hw, TX_FRAG_LIST);
367 if (iwl_mvm_has_tlc_offload(mvm)) {
368 ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
369 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
372 if (iwl_mvm_has_new_rx_api(mvm))
373 ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
375 if (fw_has_capa(&mvm->fw->ucode_capa,
376 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
377 ieee80211_hw_set(hw, AP_LINK_PS);
378 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) {
380 * we absolutely need this for the new TX API since that comes
381 * with many more queues than the current code can deal with
382 * for station powersave
387 if (mvm->trans->num_rx_queues > 1)
388 ieee80211_hw_set(hw, USES_RSS);
390 if (mvm->trans->max_skb_frags)
391 hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
393 hw->queues = IEEE80211_MAX_QUEUES;
394 hw->offchannel_tx_hw_queue = IWL_MVM_OFFCHANNEL_QUEUE;
395 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
396 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
397 hw->radiotap_vht_details |= IEEE80211_RADIOTAP_VHT_KNOWN_STBC |
398 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED;
400 hw->radiotap_timestamp.units_pos =
401 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
402 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ;
403 /* this is the case for CCK frames, it's better (only 8) for OFDM */
404 hw->radiotap_timestamp.accuracy = 22;
406 if (!iwl_mvm_has_tlc_offload(mvm))
407 hw->rate_control_algorithm = RS_NAME;
409 hw->uapsd_queues = IWL_MVM_UAPSD_QUEUES;
410 hw->uapsd_max_sp_len = IWL_UAPSD_MAX_SP;
411 hw->max_tx_fragments = mvm->trans->max_skb_frags;
413 BUILD_BUG_ON(ARRAY_SIZE(mvm->ciphers) < ARRAY_SIZE(mvm_ciphers) + 6);
414 memcpy(mvm->ciphers, mvm_ciphers, sizeof(mvm_ciphers));
415 hw->wiphy->n_cipher_suites = ARRAY_SIZE(mvm_ciphers);
416 hw->wiphy->cipher_suites = mvm->ciphers;
418 if (iwl_mvm_has_new_rx_api(mvm)) {
419 mvm->ciphers[hw->wiphy->n_cipher_suites] =
420 WLAN_CIPHER_SUITE_GCMP;
421 hw->wiphy->n_cipher_suites++;
422 mvm->ciphers[hw->wiphy->n_cipher_suites] =
423 WLAN_CIPHER_SUITE_GCMP_256;
424 hw->wiphy->n_cipher_suites++;
427 if (iwlwifi_mod_params.swcrypto)
429 "iwlmvm doesn't allow to disable HW crypto, check swcrypto module parameter\n");
430 if (!iwlwifi_mod_params.bt_coex_active)
432 "iwlmvm doesn't allow to disable BT Coex, check bt_coex_active module parameter\n");
434 ieee80211_hw_set(hw, MFP_CAPABLE);
435 mvm->ciphers[hw->wiphy->n_cipher_suites] = WLAN_CIPHER_SUITE_AES_CMAC;
436 hw->wiphy->n_cipher_suites++;
437 if (iwl_mvm_has_new_rx_api(mvm)) {
438 mvm->ciphers[hw->wiphy->n_cipher_suites] =
439 WLAN_CIPHER_SUITE_BIP_GMAC_128;
440 hw->wiphy->n_cipher_suites++;
441 mvm->ciphers[hw->wiphy->n_cipher_suites] =
442 WLAN_CIPHER_SUITE_BIP_GMAC_256;
443 hw->wiphy->n_cipher_suites++;
446 /* currently FW API supports only one optional cipher scheme */
447 if (mvm->fw->cs[0].cipher) {
448 const struct iwl_fw_cipher_scheme *fwcs = &mvm->fw->cs[0];
449 struct ieee80211_cipher_scheme *cs = &mvm->cs[0];
451 mvm->hw->n_cipher_schemes = 1;
453 cs->cipher = le32_to_cpu(fwcs->cipher);
454 cs->iftype = BIT(NL80211_IFTYPE_STATION);
455 cs->hdr_len = fwcs->hdr_len;
456 cs->pn_len = fwcs->pn_len;
457 cs->pn_off = fwcs->pn_off;
458 cs->key_idx_off = fwcs->key_idx_off;
459 cs->key_idx_mask = fwcs->key_idx_mask;
460 cs->key_idx_shift = fwcs->key_idx_shift;
461 cs->mic_len = fwcs->mic_len;
463 mvm->hw->cipher_schemes = mvm->cs;
464 mvm->ciphers[hw->wiphy->n_cipher_suites] = cs->cipher;
465 hw->wiphy->n_cipher_suites++;
468 if (fw_has_capa(&mvm->fw->ucode_capa,
469 IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) {
470 wiphy_ext_feature_set(hw->wiphy,
471 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
472 hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa;
475 if (fw_has_capa(&mvm->fw->ucode_capa,
476 IWL_UCODE_TLV_CAPA_BIGTK_SUPPORT))
477 wiphy_ext_feature_set(hw->wiphy,
478 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT);
480 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
481 hw->wiphy->features |=
482 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
483 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
484 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
486 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
487 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
488 hw->chanctx_data_size = sizeof(u16);
489 hw->txq_data_size = sizeof(struct iwl_mvm_txq);
491 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
492 BIT(NL80211_IFTYPE_P2P_CLIENT) |
493 BIT(NL80211_IFTYPE_AP) |
494 BIT(NL80211_IFTYPE_P2P_GO) |
495 BIT(NL80211_IFTYPE_P2P_DEVICE) |
496 BIT(NL80211_IFTYPE_ADHOC);
498 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
499 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
501 /* The new Tx API does not allow to pass the key or keyid of a MPDU to
502 * the hw, preventing us to control which key(id) to use per MPDU.
503 * Till that's fixed we can't use Extended Key ID for the newer cards.
505 if (!iwl_mvm_has_new_tx_api(mvm))
506 wiphy_ext_feature_set(hw->wiphy,
507 NL80211_EXT_FEATURE_EXT_KEY_ID);
508 hw->wiphy->features |= NL80211_FEATURE_HT_IBSS;
510 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
511 if (iwl_mvm_is_lar_supported(mvm))
512 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
514 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
515 REGULATORY_DISABLE_BEACON_HINTS;
517 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
518 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
519 hw->wiphy->flags |= WIPHY_FLAG_SPLIT_SCAN_6GHZ;
521 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
522 hw->wiphy->n_iface_combinations =
523 ARRAY_SIZE(iwl_mvm_iface_combinations);
525 hw->wiphy->max_remain_on_channel_duration = 10000;
526 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
528 /* Extract MAC address */
529 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
530 hw->wiphy->addresses = mvm->addresses;
531 hw->wiphy->n_addresses = 1;
533 /* Extract additional MAC addresses if available */
534 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
535 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
537 for (i = 1; i < num_mac; i++) {
538 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
540 mvm->addresses[i].addr[5]++;
541 hw->wiphy->n_addresses++;
544 iwl_mvm_reset_phy_ctxts(mvm);
546 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
548 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
550 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
551 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
552 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
554 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
555 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
557 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
559 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
560 hw->wiphy->bands[NL80211_BAND_2GHZ] =
561 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
562 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
563 hw->wiphy->bands[NL80211_BAND_5GHZ] =
564 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
566 if (fw_has_capa(&mvm->fw->ucode_capa,
567 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
568 fw_has_api(&mvm->fw->ucode_capa,
569 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
570 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
571 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
573 if (fw_has_capa(&mvm->fw->ucode_capa,
574 IWL_UCODE_TLV_CAPA_PSC_CHAN_SUPPORT) &&
575 mvm->nvm_data->bands[NL80211_BAND_6GHZ].n_channels)
576 hw->wiphy->bands[NL80211_BAND_6GHZ] =
577 &mvm->nvm_data->bands[NL80211_BAND_6GHZ];
579 hw->wiphy->hw_version = mvm->trans->hw_id;
581 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
582 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
584 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
586 hw->wiphy->max_sched_scan_reqs = 1;
587 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
588 hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw);
589 /* we create the 802.11 header and zero length SSID IE. */
590 hw->wiphy->max_sched_scan_ie_len =
591 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
592 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
593 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
596 * the firmware uses u8 for num of iterations, but 0xff is saved for
597 * infinite loop, so the maximum number of iterations is actually 254.
599 hw->wiphy->max_sched_scan_plan_iterations = 254;
601 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
602 NL80211_FEATURE_LOW_PRIORITY_SCAN |
603 NL80211_FEATURE_P2P_GO_OPPPS |
604 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
605 NL80211_FEATURE_DYNAMIC_SMPS |
606 NL80211_FEATURE_STATIC_SMPS |
607 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
609 if (fw_has_capa(&mvm->fw->ucode_capa,
610 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
611 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
612 if (fw_has_capa(&mvm->fw->ucode_capa,
613 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
614 hw->wiphy->features |= NL80211_FEATURE_QUIET;
616 if (fw_has_capa(&mvm->fw->ucode_capa,
617 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
618 hw->wiphy->features |=
619 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
621 if (fw_has_capa(&mvm->fw->ucode_capa,
622 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
623 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
625 if (iwl_fw_lookup_cmd_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP,
626 WOWLAN_KEK_KCK_MATERIAL,
627 IWL_FW_CMD_VER_UNKNOWN) == 3)
628 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK;
630 if (fw_has_api(&mvm->fw->ucode_capa,
631 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
632 wiphy_ext_feature_set(hw->wiphy,
633 NL80211_EXT_FEATURE_SCAN_START_TIME);
634 wiphy_ext_feature_set(hw->wiphy,
635 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
638 if (iwl_mvm_is_oce_supported(mvm)) {
639 wiphy_ext_feature_set(hw->wiphy,
640 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
641 wiphy_ext_feature_set(hw->wiphy,
642 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
643 wiphy_ext_feature_set(hw->wiphy,
644 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
645 wiphy_ext_feature_set(hw->wiphy,
646 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
649 if (mvm->nvm_data->sku_cap_11ax_enable &&
650 !iwlwifi_mod_params.disable_11ax) {
651 hw->wiphy->iftype_ext_capab = he_iftypes_ext_capa;
652 hw->wiphy->num_iftype_ext_capab =
653 ARRAY_SIZE(he_iftypes_ext_capa);
655 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
656 ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID);
659 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
661 #ifdef CONFIG_PM_SLEEP
662 if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) &&
663 mvm->trans->ops->d3_suspend &&
664 mvm->trans->ops->d3_resume &&
665 device_can_wakeup(mvm->trans->dev)) {
666 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
667 WIPHY_WOWLAN_DISCONNECT |
668 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
669 WIPHY_WOWLAN_RFKILL_RELEASE |
670 WIPHY_WOWLAN_NET_DETECT;
671 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
672 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
673 WIPHY_WOWLAN_4WAY_HANDSHAKE;
675 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
676 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
677 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
678 mvm->wowlan.max_nd_match_sets =
679 iwl_umac_scan_get_max_profiles(mvm->fw);
680 hw->wiphy->wowlan = &mvm->wowlan;
684 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
685 /* assign default bcast filtering configuration */
686 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
689 ret = iwl_mvm_leds_init(mvm);
693 if (fw_has_capa(&mvm->fw->ucode_capa,
694 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
695 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
696 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
697 ieee80211_hw_set(hw, TDLS_WIDER_BW);
700 if (fw_has_capa(&mvm->fw->ucode_capa,
701 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
702 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
703 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
706 hw->netdev_features |= mvm->cfg->features;
707 if (!iwl_mvm_is_csum_supported(mvm))
708 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
711 if (mvm->cfg->vht_mu_mimo_supported)
712 wiphy_ext_feature_set(hw->wiphy,
713 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
715 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT))
716 wiphy_ext_feature_set(hw->wiphy,
717 NL80211_EXT_FEATURE_PROTECTED_TWT);
719 hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm);
720 hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm);
722 ret = ieee80211_register_hw(mvm->hw);
724 iwl_mvm_leds_exit(mvm);
730 static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
731 struct ieee80211_sta *sta)
734 if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0))
737 if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0))
741 ieee80211_free_txskb(mvm->hw, skb);
744 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
745 struct ieee80211_tx_control *control,
748 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
749 struct ieee80211_sta *sta = control->sta;
750 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
751 struct ieee80211_hdr *hdr = (void *)skb->data;
752 bool offchannel = IEEE80211_SKB_CB(skb)->flags &
753 IEEE80211_TX_CTL_TX_OFFCHAN;
755 if (iwl_mvm_is_radio_killed(mvm)) {
756 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
761 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
762 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
765 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
766 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
767 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
768 ieee80211_is_mgmt(hdr->frame_control) &&
769 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
772 /* If there is no sta, and it's not offchannel - send through AP */
773 if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION &&
775 struct iwl_mvm_vif *mvmvif =
776 iwl_mvm_vif_from_mac80211(info->control.vif);
777 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
779 if (ap_sta_id < mvm->fw->ucode_capa.num_stations) {
780 /* mac80211 holds rcu read lock */
781 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
782 if (IS_ERR_OR_NULL(sta))
787 iwl_mvm_tx_skb(mvm, skb, sta);
790 ieee80211_free_txskb(hw, skb);
793 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
795 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
796 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
797 struct sk_buff *skb = NULL;
800 * No need for threads to be pending here, they can leave the first
801 * taker all the work.
803 * mvmtxq->tx_request logic:
805 * If 0, no one is currently TXing, set to 1 to indicate current thread
806 * will now start TX and other threads should quit.
808 * If 1, another thread is currently TXing, set to 2 to indicate to
809 * that thread that there was another request. Since that request may
810 * have raced with the check whether the queue is empty, the TXing
811 * thread should check the queue's status one more time before leaving.
812 * This check is done in order to not leave any TX hanging in the queue
813 * until the next TX invocation (which may not even happen).
815 * If 2, another thread is currently TXing, and it will already double
816 * check the queue, so do nothing.
818 if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2))
823 while (likely(!mvmtxq->stopped &&
824 !test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status))) {
825 skb = ieee80211_tx_dequeue(hw, txq);
830 "TXQ of sta %pM tid %d is now empty\n",
836 iwl_mvm_tx_skb(mvm, skb, txq->sta);
838 } while (atomic_dec_return(&mvmtxq->tx_request));
842 static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw,
843 struct ieee80211_txq *txq)
845 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
846 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
849 * Please note that racing is handled very carefully here:
850 * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is
851 * deleted afterwards.
852 * This means that if:
853 * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list):
854 * queue is allocated and we can TX.
855 * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list):
856 * a race, should defer the frame.
857 * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list):
858 * need to allocate the queue and defer the frame.
859 * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list):
860 * queue is already scheduled for allocation, no need to allocate,
861 * should defer the frame.
864 /* If the queue is allocated TX and return. */
865 if (!txq->sta || mvmtxq->txq_id != IWL_MVM_INVALID_QUEUE) {
867 * Check that list is empty to avoid a race where txq_id is
868 * already updated, but the queue allocation work wasn't
871 if (unlikely(txq->sta && !list_empty(&mvmtxq->list)))
874 iwl_mvm_mac_itxq_xmit(hw, txq);
878 /* The list is being deleted only after the queue is fully allocated. */
879 if (!list_empty(&mvmtxq->list))
882 list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs);
883 schedule_work(&mvm->add_stream_wk);
886 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
888 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
890 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
894 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
895 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
896 enum ieee80211_ampdu_mlme_action action)
898 struct iwl_fw_dbg_trigger_tlv *trig;
899 struct iwl_fw_dbg_trigger_ba *ba_trig;
901 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
906 ba_trig = (void *)trig->data;
909 case IEEE80211_AMPDU_TX_OPERATIONAL: {
910 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
911 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
913 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
914 "TX AGG START: MAC %pM tid %d ssn %d\n",
915 sta->addr, tid, tid_data->ssn);
918 case IEEE80211_AMPDU_TX_STOP_CONT:
919 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
920 "TX AGG STOP: MAC %pM tid %d\n",
923 case IEEE80211_AMPDU_RX_START:
924 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
925 "RX AGG START: MAC %pM tid %d ssn %d\n",
926 sta->addr, tid, rx_ba_ssn);
928 case IEEE80211_AMPDU_RX_STOP:
929 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
930 "RX AGG STOP: MAC %pM tid %d\n",
938 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
939 struct ieee80211_vif *vif,
940 struct ieee80211_ampdu_params *params)
942 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
944 struct ieee80211_sta *sta = params->sta;
945 enum ieee80211_ampdu_mlme_action action = params->action;
946 u16 tid = params->tid;
947 u16 *ssn = ¶ms->ssn;
948 u16 buf_size = params->buf_size;
949 bool amsdu = params->amsdu;
950 u16 timeout = params->timeout;
952 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
953 sta->addr, tid, action);
955 if (!(mvm->nvm_data->sku_cap_11n_enable))
958 mutex_lock(&mvm->mutex);
961 case IEEE80211_AMPDU_RX_START:
962 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
963 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
964 struct iwl_mvm_vif *mvmvif;
965 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
966 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
968 mdata->opened_rx_ba_sessions = true;
969 mvmvif = iwl_mvm_vif_from_mac80211(vif);
970 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
972 if (!iwl_enable_rx_ampdu()) {
976 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
979 case IEEE80211_AMPDU_RX_STOP:
980 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
983 case IEEE80211_AMPDU_TX_START:
984 if (!iwl_enable_tx_ampdu()) {
988 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
990 case IEEE80211_AMPDU_TX_STOP_CONT:
991 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
993 case IEEE80211_AMPDU_TX_STOP_FLUSH:
994 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
995 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
997 case IEEE80211_AMPDU_TX_OPERATIONAL:
998 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1010 if (action == IEEE80211_AMPDU_RX_START)
1013 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1016 mutex_unlock(&mvm->mutex);
1021 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1022 struct ieee80211_vif *vif)
1024 struct iwl_mvm *mvm = data;
1025 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1027 mvmvif->uploaded = false;
1028 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1030 spin_lock_bh(&mvm->time_event_lock);
1031 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1032 spin_unlock_bh(&mvm->time_event_lock);
1034 mvmvif->phy_ctxt = NULL;
1035 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1036 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
1039 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1041 iwl_mvm_stop_device(mvm);
1045 mvm->scan_status = 0;
1046 mvm->ps_disabled = false;
1047 mvm->rfkill_safe_init_done = false;
1049 /* just in case one was running */
1050 iwl_mvm_cleanup_roc_te(mvm);
1051 ieee80211_remain_on_channel_expired(mvm->hw);
1053 iwl_mvm_ftm_restart(mvm);
1056 * cleanup all interfaces, even inactive ones, as some might have
1057 * gone down during the HW restart
1059 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1061 mvm->p2p_device_vif = NULL;
1063 iwl_mvm_reset_phy_ctxts(mvm);
1064 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1065 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1066 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1068 ieee80211_wake_queues(mvm->hw);
1071 mvm->rx_ba_sessions = 0;
1072 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1073 mvm->monitor_on = false;
1075 /* keep statistics ticking */
1076 iwl_mvm_accu_radio_stats(mvm);
1079 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1083 lockdep_assert_held(&mvm->mutex);
1085 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1087 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1088 * so later code will - from now on - see that we're doing it.
1090 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1091 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1092 /* Clean up some internal and mac80211 state on restart */
1093 iwl_mvm_restart_cleanup(mvm);
1095 ret = iwl_mvm_up(mvm);
1097 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT,
1099 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC,
1102 mvm->last_reset_or_resume_time_jiffies = jiffies;
1104 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1105 /* Something went wrong - we need to finish some cleanup
1106 * that normally iwl_mvm_mac_restart_complete() below
1109 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1115 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1117 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1120 mutex_lock(&mvm->mutex);
1121 ret = __iwl_mvm_mac_start(mvm);
1122 mutex_unlock(&mvm->mutex);
1127 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1131 mutex_lock(&mvm->mutex);
1133 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1135 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1137 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1140 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY);
1143 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1144 * of packets the FW sent out, so we must reconnect.
1146 iwl_mvm_teardown_tdls_peers(mvm);
1148 mutex_unlock(&mvm->mutex);
1152 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1153 enum ieee80211_reconfig_type reconfig_type)
1155 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1157 switch (reconfig_type) {
1158 case IEEE80211_RECONFIG_TYPE_RESTART:
1159 iwl_mvm_restart_complete(mvm);
1161 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1166 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1168 lockdep_assert_held(&mvm->mutex);
1170 iwl_mvm_ftm_initiator_smooth_stop(mvm);
1172 /* firmware counters are obviously reset now, but we shouldn't
1173 * partially track so also clear the fw_reset_accu counters.
1175 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1177 /* async_handlers_wk is now blocked */
1179 if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP, ADD_STA, 0) < 12)
1180 iwl_mvm_rm_aux_sta(mvm);
1182 iwl_mvm_stop_device(mvm);
1184 iwl_mvm_async_handlers_purge(mvm);
1185 /* async_handlers_list is empty and will stay empty: HW is stopped */
1188 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1189 * hw (as restart_complete() won't be called in this case) and mac80211
1190 * won't execute the restart.
1191 * But make sure to cleanup interfaces that have gone down before/during
1192 * HW restart was requested.
1194 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1195 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1197 ieee80211_iterate_interfaces(mvm->hw, 0,
1198 iwl_mvm_cleanup_iterator, mvm);
1200 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1201 * make sure there's nothing left there and warn if any is found.
1203 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1206 for (i = 0; i < mvm->max_scans; i++) {
1207 if (WARN_ONCE(mvm->scan_uid_status[i],
1208 "UMAC scan UID %d status was not cleaned\n",
1210 mvm->scan_uid_status[i] = 0;
1215 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1217 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1219 flush_work(&mvm->async_handlers_wk);
1220 flush_work(&mvm->add_stream_wk);
1223 * Lock and clear the firmware running bit here already, so that
1224 * new commands coming in elsewhere, e.g. from debugfs, will not
1225 * be able to proceed. This is important here because one of those
1226 * debugfs files causes the firmware dump to be triggered, and if we
1227 * don't stop debugfs accesses before canceling that it could be
1228 * retriggered after we flush it but before we've cleared the bit.
1230 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1232 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1233 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1236 * The work item could be running or queued if the
1237 * ROC time event stops just as we get here.
1239 flush_work(&mvm->roc_done_wk);
1241 mutex_lock(&mvm->mutex);
1242 __iwl_mvm_mac_stop(mvm);
1243 mutex_unlock(&mvm->mutex);
1246 * The worker might have been waiting for the mutex, let it run and
1247 * discover that its list is now empty.
1249 cancel_work_sync(&mvm->async_handlers_wk);
1252 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1256 lockdep_assert_held(&mvm->mutex);
1258 for (i = 0; i < NUM_PHY_CTX; i++)
1259 if (!mvm->phy_ctxts[i].ref)
1260 return &mvm->phy_ctxts[i];
1262 IWL_ERR(mvm, "No available PHY context\n");
1266 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1270 struct iwl_dev_tx_power_cmd cmd = {
1271 .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1272 .common.mac_context_id =
1273 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1274 .common.pwr_restriction = cpu_to_le16(8 * tx_power),
1276 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
1277 REDUCE_TX_POWER_CMD,
1278 IWL_FW_CMD_VER_UNKNOWN);
1280 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1281 cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1284 len = sizeof(cmd.v6);
1285 else if (fw_has_api(&mvm->fw->ucode_capa,
1286 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1287 len = sizeof(cmd.v5);
1288 else if (fw_has_capa(&mvm->fw->ucode_capa,
1289 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1290 len = sizeof(cmd.v4);
1292 len = sizeof(cmd.v3);
1294 /* all structs have the same common part, add it */
1295 len += sizeof(cmd.common);
1297 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1300 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
1301 struct ieee80211_vif *vif)
1303 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1304 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1307 mutex_lock(&mvm->mutex);
1309 if (vif->type == NL80211_IFTYPE_STATION) {
1310 struct iwl_mvm_sta *mvmsta;
1312 mvmvif->csa_bcn_pending = false;
1313 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
1316 if (WARN_ON(!mvmsta)) {
1321 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
1323 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1325 if (!fw_has_capa(&mvm->fw->ucode_capa,
1326 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
1327 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1331 iwl_mvm_stop_session_protection(mvm, vif);
1335 mvmvif->ps_disabled = false;
1337 ret = iwl_mvm_power_update_ps(mvm);
1340 if (mvmvif->csa_failed)
1342 mutex_unlock(&mvm->mutex);
1347 static void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw,
1348 struct ieee80211_vif *vif)
1350 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1351 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1352 struct iwl_chan_switch_te_cmd cmd = {
1353 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1355 .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE),
1358 IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id);
1360 mutex_lock(&mvm->mutex);
1361 if (!fw_has_capa(&mvm->fw->ucode_capa,
1362 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
1363 iwl_mvm_remove_csa_period(mvm, vif);
1365 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
1366 WIDE_ID(MAC_CONF_GROUP,
1367 CHANNEL_SWITCH_TIME_EVENT_CMD),
1368 0, sizeof(cmd), &cmd));
1369 mvmvif->csa_failed = true;
1370 mutex_unlock(&mvm->mutex);
1372 iwl_mvm_post_channel_switch(hw, vif);
1375 static void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk)
1377 struct iwl_mvm_vif *mvmvif;
1378 struct ieee80211_vif *vif;
1380 mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work);
1381 vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);
1383 /* Trigger disconnect (should clear the CSA state) */
1384 ieee80211_chswitch_done(vif, false);
1387 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1388 struct ieee80211_vif *vif)
1390 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1391 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1395 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1398 * Not much to do here. The stack will not allow interface
1399 * types or combinations that we didn't advertise, so we
1400 * don't really have to check the types.
1403 mutex_lock(&mvm->mutex);
1405 /* make sure that beacon statistics don't go backwards with FW reset */
1406 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1407 mvmvif->beacon_stats.accu_num_beacons +=
1408 mvmvif->beacon_stats.num_beacons;
1410 /* Allocate resources for the MAC context, and add it to the fw */
1411 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1415 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif);
1417 /* Counting number of interfaces is needed for legacy PM */
1418 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1422 * The AP binding flow can be done only after the beacon
1423 * template is configured (which happens only in the mac80211
1424 * start_ap() flow), and adding the broadcast station can happen
1425 * only after the binding.
1426 * In addition, since modifying the MAC before adding a bcast
1427 * station is not allowed by the FW, delay the adding of MAC context to
1428 * the point where we can also add the bcast station.
1429 * In short: there's not much we can do at this point, other than
1430 * allocating resources :)
1432 if (vif->type == NL80211_IFTYPE_AP ||
1433 vif->type == NL80211_IFTYPE_ADHOC) {
1434 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1436 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1441 * Only queue for this station is the mcast queue,
1442 * which shouldn't be in TFD mask anyway
1444 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1450 iwl_mvm_vif_dbgfs_register(mvm, vif);
1454 mvmvif->features |= hw->netdev_features;
1456 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1460 ret = iwl_mvm_power_update_mac(mvm);
1462 goto out_remove_mac;
1464 /* beacon filtering */
1465 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1467 goto out_remove_mac;
1469 if (!mvm->bf_allowed_vif &&
1470 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1471 mvm->bf_allowed_vif = mvmvif;
1472 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1473 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1477 * P2P_DEVICE interface does not have a channel context assigned to it,
1478 * so a dedicated PHY context is allocated to it and the corresponding
1479 * MAC context is bound to it at this stage.
1481 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1483 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1484 if (!mvmvif->phy_ctxt) {
1489 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1490 ret = iwl_mvm_binding_add_vif(mvm, vif);
1494 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1498 /* Save a pointer to p2p device vif, so it can later be used to
1499 * update the p2p device MAC when a GO is started/stopped */
1500 mvm->p2p_device_vif = vif;
1503 iwl_mvm_tcm_add_vif(mvm, vif);
1504 INIT_DELAYED_WORK(&mvmvif->csa_work,
1505 iwl_mvm_channel_switch_disconnect_wk);
1507 if (vif->type == NL80211_IFTYPE_MONITOR)
1508 mvm->monitor_on = true;
1510 iwl_mvm_vif_dbgfs_register(mvm, vif);
1514 iwl_mvm_binding_remove_vif(mvm, vif);
1516 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1518 if (mvm->bf_allowed_vif == mvmvif) {
1519 mvm->bf_allowed_vif = NULL;
1520 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1521 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1524 mvmvif->phy_ctxt = NULL;
1525 iwl_mvm_mac_ctxt_remove(mvm, vif);
1527 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1530 mutex_unlock(&mvm->mutex);
1535 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1536 struct ieee80211_vif *vif)
1538 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1540 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1541 * We assume here that all the packets sent to the OFFCHANNEL
1542 * queue are sent in ROC session.
1544 flush_work(&mvm->roc_done_wk);
1548 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1549 struct ieee80211_vif *vif)
1551 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1552 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1553 struct iwl_probe_resp_data *probe_data;
1555 iwl_mvm_prepare_mac_removal(mvm, vif);
1557 if (!(vif->type == NL80211_IFTYPE_AP ||
1558 vif->type == NL80211_IFTYPE_ADHOC))
1559 iwl_mvm_tcm_rm_vif(mvm, vif);
1561 mutex_lock(&mvm->mutex);
1563 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1564 lockdep_is_held(&mvm->mutex));
1565 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1567 kfree_rcu(probe_data, rcu_head);
1569 if (mvm->bf_allowed_vif == mvmvif) {
1570 mvm->bf_allowed_vif = NULL;
1571 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1572 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1575 if (vif->bss_conf.ftm_responder)
1576 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
1578 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1581 * For AP/GO interface, the tear down of the resources allocated to the
1582 * interface is be handled as part of the stop_ap flow.
1584 if (vif->type == NL80211_IFTYPE_AP ||
1585 vif->type == NL80211_IFTYPE_ADHOC) {
1586 #ifdef CONFIG_NL80211_TESTMODE
1587 if (vif == mvm->noa_vif) {
1588 mvm->noa_vif = NULL;
1589 mvm->noa_duration = 0;
1592 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1593 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1597 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1598 mvm->p2p_device_vif = NULL;
1599 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1600 iwl_mvm_binding_remove_vif(mvm, vif);
1601 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1602 mvmvif->phy_ctxt = NULL;
1605 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1608 iwl_mvm_power_update_mac(mvm);
1609 iwl_mvm_mac_ctxt_remove(mvm, vif);
1611 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL);
1613 if (vif->type == NL80211_IFTYPE_MONITOR)
1614 mvm->monitor_on = false;
1617 mutex_unlock(&mvm->mutex);
1620 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1625 struct iwl_mvm_mc_iter_data {
1626 struct iwl_mvm *mvm;
1630 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1631 struct ieee80211_vif *vif)
1633 struct iwl_mvm_mc_iter_data *data = _data;
1634 struct iwl_mvm *mvm = data->mvm;
1635 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1636 struct iwl_host_cmd hcmd = {
1637 .id = MCAST_FILTER_CMD,
1639 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1643 /* if we don't have free ports, mcast frames will be dropped */
1644 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1647 if (vif->type != NL80211_IFTYPE_STATION ||
1648 !vif->bss_conf.assoc)
1651 cmd->port_id = data->port_id++;
1652 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1653 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1658 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1660 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1663 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1665 struct iwl_mvm_mc_iter_data iter_data = {
1669 lockdep_assert_held(&mvm->mutex);
1671 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1674 ieee80211_iterate_active_interfaces_atomic(
1675 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1676 iwl_mvm_mc_iface_iterator, &iter_data);
1679 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1680 struct netdev_hw_addr_list *mc_list)
1682 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1683 struct iwl_mcast_filter_cmd *cmd;
1684 struct netdev_hw_addr *addr;
1689 addr_count = netdev_hw_addr_list_count(mc_list);
1690 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1691 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1695 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1696 cmd = kzalloc(len, GFP_ATOMIC);
1702 return (u64)(unsigned long)cmd;
1705 netdev_hw_addr_list_for_each(addr, mc_list) {
1706 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1707 cmd->count, addr->addr);
1708 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1709 addr->addr, ETH_ALEN);
1713 return (u64)(unsigned long)cmd;
1716 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1717 unsigned int changed_flags,
1718 unsigned int *total_flags,
1721 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1722 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1724 mutex_lock(&mvm->mutex);
1726 /* replace previous configuration */
1727 kfree(mvm->mcast_filter_cmd);
1728 mvm->mcast_filter_cmd = cmd;
1733 if (changed_flags & FIF_ALLMULTI)
1734 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1739 iwl_mvm_recalc_multicast(mvm);
1741 mutex_unlock(&mvm->mutex);
1745 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1746 struct ieee80211_vif *vif,
1747 unsigned int filter_flags,
1748 unsigned int changed_flags)
1750 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1752 /* We support only filter for probe requests */
1753 if (!(changed_flags & FIF_PROBE_REQ))
1756 /* Supported only for p2p client interfaces */
1757 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1761 mutex_lock(&mvm->mutex);
1762 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1763 mutex_unlock(&mvm->mutex);
1766 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1767 struct iwl_bcast_iter_data {
1768 struct iwl_mvm *mvm;
1769 struct iwl_bcast_filter_cmd *cmd;
1774 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1775 const struct iwl_fw_bcast_filter *in_filter,
1776 struct iwl_fw_bcast_filter *out_filter)
1778 struct iwl_fw_bcast_filter_attr *attr;
1781 memcpy(out_filter, in_filter, sizeof(*out_filter));
1783 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1784 attr = &out_filter->attrs[i];
1789 switch (attr->reserved1) {
1790 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1791 if (vif->bss_conf.arp_addr_cnt != 1) {
1796 attr->val = vif->bss_conf.arp_addr_list[0];
1798 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1799 attr->val = *(__be32 *)&vif->addr[2];
1804 attr->reserved1 = 0;
1805 out_filter->num_attrs++;
1809 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1810 struct ieee80211_vif *vif)
1812 struct iwl_bcast_iter_data *data = _data;
1813 struct iwl_mvm *mvm = data->mvm;
1814 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1815 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1816 struct iwl_fw_bcast_mac *bcast_mac;
1819 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1822 bcast_mac = &cmd->macs[mvmvif->id];
1825 * enable filtering only for associated stations, but not for P2P
1828 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1829 !vif->bss_conf.assoc)
1832 bcast_mac->default_discard = 1;
1834 /* copy all configured filters */
1835 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1837 * Make sure we don't exceed our filters limit.
1838 * if there is still a valid filter to be configured,
1839 * be on the safe side and just allow bcast for this mac.
1841 if (WARN_ON_ONCE(data->current_filter >=
1842 ARRAY_SIZE(cmd->filters))) {
1843 bcast_mac->default_discard = 0;
1844 bcast_mac->attached_filters = 0;
1848 iwl_mvm_set_bcast_filter(vif,
1849 &mvm->bcast_filters[i],
1850 &cmd->filters[data->current_filter]);
1852 /* skip current filter if it contains no attributes */
1853 if (!cmd->filters[data->current_filter].num_attrs)
1856 /* attach the filter to current mac */
1857 bcast_mac->attached_filters |=
1858 cpu_to_le16(BIT(data->current_filter));
1860 data->current_filter++;
1864 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1865 struct iwl_bcast_filter_cmd *cmd)
1867 struct iwl_bcast_iter_data iter_data = {
1872 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1875 memset(cmd, 0, sizeof(*cmd));
1876 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1877 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1879 #ifdef CONFIG_IWLWIFI_DEBUGFS
1880 /* use debugfs filters/macs if override is configured */
1881 if (mvm->dbgfs_bcast_filtering.override) {
1882 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1883 sizeof(cmd->filters));
1884 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1890 /* if no filters are configured, do nothing */
1891 if (!mvm->bcast_filters)
1894 /* configure and attach these filters for each associated sta vif */
1895 ieee80211_iterate_active_interfaces(
1896 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1897 iwl_mvm_bcast_filter_iterator, &iter_data);
1902 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1904 struct iwl_bcast_filter_cmd cmd;
1906 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1909 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1912 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1916 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1922 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1923 struct ieee80211_vif *vif)
1925 struct iwl_mu_group_mgmt_cmd cmd = {};
1927 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1928 WLAN_MEMBERSHIP_LEN);
1929 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1930 WLAN_USER_POSITION_LEN);
1932 return iwl_mvm_send_cmd_pdu(mvm,
1933 WIDE_ID(DATA_PATH_GROUP,
1934 UPDATE_MU_GROUPS_CMD),
1935 0, sizeof(cmd), &cmd);
1938 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1939 struct ieee80211_vif *vif)
1941 if (vif->mu_mimo_owner) {
1942 struct iwl_mu_group_mgmt_notif *notif = _data;
1945 * MU-MIMO Group Id action frame is little endian. We treat
1946 * the data received from firmware as if it came from the
1947 * action frame, so no conversion is needed.
1949 ieee80211_update_mu_groups(vif,
1950 (u8 *)¬if->membership_status,
1951 (u8 *)¬if->user_position);
1955 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1956 struct iwl_rx_cmd_buffer *rxb)
1958 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1959 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1961 ieee80211_iterate_active_interfaces_atomic(
1962 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1963 iwl_mvm_mu_mimo_iface_iterator, notif);
1966 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1968 u8 byte_num = ppe_pos_bit / 8;
1969 u8 bit_num = ppe_pos_bit % 8;
1974 return (ppe[byte_num] >> bit_num) &
1975 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1978 * If bit_num > 5, we have to combine bits with next byte.
1979 * Calculate how many bits we need to take from current byte (called
1980 * here "residue_bits"), and add them to bits from next byte.
1983 residue_bits = 8 - bit_num;
1985 res = (ppe[byte_num + 1] &
1986 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1988 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1993 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1994 struct ieee80211_vif *vif, u8 sta_id)
1996 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1997 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
1999 .tid_limit = IWL_MAX_TID_COUNT,
2000 .bss_color = vif->bss_conf.he_bss_color.color,
2001 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
2002 .frame_time_rts_th =
2003 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
2005 int size = fw_has_api(&mvm->fw->ucode_capa,
2006 IWL_UCODE_TLV_API_MBSSID_HE) ?
2007 sizeof(sta_ctxt_cmd) :
2008 sizeof(struct iwl_he_sta_context_cmd_v1);
2009 struct ieee80211_sta *sta;
2012 const struct ieee80211_sta_he_cap *own_he_cap = NULL;
2013 struct ieee80211_chanctx_conf *chanctx_conf;
2014 const struct ieee80211_supported_band *sband;
2018 chanctx_conf = rcu_dereference(vif->chanctx_conf);
2019 if (WARN_ON(!chanctx_conf)) {
2024 sband = mvm->hw->wiphy->bands[chanctx_conf->def.chan->band];
2025 own_he_cap = ieee80211_get_he_iftype_cap(sband, vif->type);
2027 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
2028 if (IS_ERR_OR_NULL(sta)) {
2030 WARN(1, "Can't find STA to configure HE\n");
2034 if (!sta->he_cap.has_he) {
2041 /* Block 26-tone RU OFDMA transmissions */
2042 if (mvmvif->he_ru_2mhz_block)
2043 flags |= STA_CTXT_HE_RU_2MHZ_BLOCK;
2046 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
2047 IEEE80211_HE_MAC_CAP0_HTC_HE)
2048 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
2049 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
2050 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2051 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2052 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2054 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
2055 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2056 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
2057 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2060 sta_ctxt_cmd.htc_flags |=
2061 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2062 else if (link_adap == 3)
2063 sta_ctxt_cmd.htc_flags |=
2064 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2066 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2067 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2068 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2069 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2070 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2071 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2072 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2075 * Initialize the PPE thresholds to "None" (7), as described in Table
2076 * 9-262ac of 80211.ax/D3.0.
2078 memset(&sta_ctxt_cmd.pkt_ext, 7, sizeof(sta_ctxt_cmd.pkt_ext));
2080 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2081 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2082 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2083 u8 nss = (sta->he_cap.ppe_thres[0] &
2084 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2085 u8 ru_index_bitmap =
2086 (sta->he_cap.ppe_thres[0] &
2087 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2088 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2089 u8 *ppe = &sta->he_cap.ppe_thres[0];
2090 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2093 * FW currently supports only nss == MAX_HE_SUPP_NSS
2095 * If nss > MAX: we can ignore values we don't support
2096 * If nss < MAX: we can set zeros in other streams
2098 if (nss > MAX_HE_SUPP_NSS) {
2099 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2101 nss = MAX_HE_SUPP_NSS;
2104 for (i = 0; i < nss; i++) {
2105 u8 ru_index_tmp = ru_index_bitmap << 1;
2108 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2110 if (!(ru_index_tmp & 1))
2113 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2114 iwl_mvm_he_get_ppe_val(ppe,
2117 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2118 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2119 iwl_mvm_he_get_ppe_val(ppe,
2122 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2126 flags |= STA_CTXT_HE_PACKET_EXT;
2127 } else if ((sta->he_cap.he_cap_elem.phy_cap_info[9] &
2128 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) !=
2129 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_RESERVED) {
2133 /* Take the PPE thresholds from the nominal padding info */
2134 switch (sta->he_cap.he_cap_elem.phy_cap_info[9] &
2135 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) {
2136 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_0US:
2137 low_th = IWL_HE_PKT_EXT_NONE;
2138 high_th = IWL_HE_PKT_EXT_NONE;
2140 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_8US:
2141 low_th = IWL_HE_PKT_EXT_BPSK;
2142 high_th = IWL_HE_PKT_EXT_NONE;
2144 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US:
2145 low_th = IWL_HE_PKT_EXT_NONE;
2146 high_th = IWL_HE_PKT_EXT_BPSK;
2150 /* Set the PPE thresholds accordingly */
2151 if (low_th >= 0 && high_th >= 0) {
2152 struct iwl_he_pkt_ext *pkt_ext =
2153 (struct iwl_he_pkt_ext *)&sta_ctxt_cmd.pkt_ext;
2155 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
2158 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX;
2160 pkt_ext->pkt_ext_qam_th[i][bw][0] =
2162 pkt_ext->pkt_ext_qam_th[i][bw][1] =
2167 flags |= STA_CTXT_HE_PACKET_EXT;
2171 if (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2172 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP)
2173 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2175 if (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2176 IEEE80211_HE_MAC_CAP2_ACK_EN)
2177 flags |= STA_CTXT_HE_ACK_ENABLED;
2181 /* Mark MU EDCA as enabled, unless none detected on some AC */
2182 flags |= STA_CTXT_HE_MU_EDCA_CW;
2183 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
2184 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2185 &mvmvif->queue_params[i].mu_edca_param_rec;
2186 u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
2188 if (!mvmvif->queue_params[i].mu_edca) {
2189 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2193 sta_ctxt_cmd.trig_based_txf[ac].cwmin =
2194 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2195 sta_ctxt_cmd.trig_based_txf[ac].cwmax =
2196 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2197 sta_ctxt_cmd.trig_based_txf[ac].aifsn =
2198 cpu_to_le16(mu_edca->aifsn);
2199 sta_ctxt_cmd.trig_based_txf[ac].mu_time =
2200 cpu_to_le16(mu_edca->mu_edca_timer);
2204 if (vif->bss_conf.uora_exists) {
2205 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2207 sta_ctxt_cmd.rand_alloc_ecwmin =
2208 vif->bss_conf.uora_ocw_range & 0x7;
2209 sta_ctxt_cmd.rand_alloc_ecwmax =
2210 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2213 if (own_he_cap && !(own_he_cap->he_cap_elem.mac_cap_info[2] &
2214 IEEE80211_HE_MAC_CAP2_ACK_EN))
2215 flags |= STA_CTXT_HE_NIC_NOT_ACK_ENABLED;
2217 if (vif->bss_conf.nontransmitted) {
2218 flags |= STA_CTXT_HE_REF_BSSID_VALID;
2219 ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr,
2220 vif->bss_conf.transmitter_bssid);
2221 sta_ctxt_cmd.max_bssid_indicator =
2222 vif->bss_conf.bssid_indicator;
2223 sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index;
2224 sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap;
2225 sta_ctxt_cmd.profile_periodicity =
2226 vif->bss_conf.profile_periodicity;
2229 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2231 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2232 DATA_PATH_GROUP, 0),
2233 0, size, &sta_ctxt_cmd))
2234 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2237 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2238 struct ieee80211_vif *vif,
2239 struct ieee80211_bss_conf *bss_conf,
2242 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2246 * Re-calculate the tsf id, as the leader-follower relations depend
2247 * on the beacon interval, which was not known when the station
2248 * interface was added.
2250 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2251 if (vif->bss_conf.he_support &&
2252 !iwlwifi_mod_params.disable_11ax)
2253 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2255 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2258 /* Update MU EDCA params */
2259 if (changes & BSS_CHANGED_QOS && mvmvif->associated &&
2260 bss_conf->assoc && vif->bss_conf.he_support &&
2261 !iwlwifi_mod_params.disable_11ax)
2262 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2265 * If we're not associated yet, take the (new) BSSID before associating
2266 * so the firmware knows. If we're already associated, then use the old
2267 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2268 * branch for disassociation below.
2270 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2271 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2273 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2275 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2277 /* after sending it once, adopt mac80211 data */
2278 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2279 mvmvif->associated = bss_conf->assoc;
2281 if (changes & BSS_CHANGED_ASSOC) {
2282 if (bss_conf->assoc) {
2283 /* clear statistics to get clean beacon counter */
2284 iwl_mvm_request_statistics(mvm, true);
2285 memset(&mvmvif->beacon_stats, 0,
2286 sizeof(mvmvif->beacon_stats));
2288 /* add quota for this interface */
2289 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2291 IWL_ERR(mvm, "failed to update quotas\n");
2295 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2297 !fw_has_capa(&mvm->fw->ucode_capa,
2298 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) {
2300 * If we're restarting then the firmware will
2301 * obviously have lost synchronisation with
2302 * the AP. It will attempt to synchronise by
2303 * itself, but we can make it more reliable by
2304 * scheduling a session protection time event.
2306 * The firmware needs to receive a beacon to
2307 * catch up with synchronisation, use 110% of
2308 * the beacon interval.
2310 * Set a large maximum delay to allow for more
2311 * than a single interface.
2313 * For new firmware versions, rely on the
2314 * firmware. This is relevant for DCM scenarios
2317 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2318 iwl_mvm_protect_session(mvm, vif, dur, dur,
2322 iwl_mvm_sf_update(mvm, vif, false);
2323 iwl_mvm_power_vif_assoc(mvm, vif);
2325 iwl_mvm_update_smps(mvm, vif,
2326 IWL_MVM_SMPS_REQ_PROT,
2327 IEEE80211_SMPS_DYNAMIC);
2329 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2331 * If update fails - SF might be running in associated
2332 * mode while disassociated - which is forbidden.
2334 ret = iwl_mvm_sf_update(mvm, vif, false);
2336 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
2338 "Failed to update SF upon disassociation\n");
2341 * If we get an assert during the connection (after the
2342 * station has been added, but before the vif is set
2343 * to associated), mac80211 will re-add the station and
2344 * then configure the vif. Since the vif is not
2345 * associated, we would remove the station here and
2346 * this would fail the recovery.
2348 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2351 * Remove AP station now that
2352 * the MAC is unassoc
2354 ret = iwl_mvm_rm_sta_id(mvm, vif,
2358 "failed to remove AP station\n");
2360 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2363 /* remove quota for this interface */
2364 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2366 IWL_ERR(mvm, "failed to update quotas\n");
2368 /* this will take the cleared BSSID from bss_conf */
2369 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2372 "failed to update MAC %pM (clear after unassoc)\n",
2377 * The firmware tracks the MU-MIMO group on its own.
2378 * However, on HW restart we should restore this data.
2380 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2381 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2382 ret = iwl_mvm_update_mu_groups(mvm, vif);
2385 "failed to update VHT MU_MIMO groups\n");
2388 iwl_mvm_recalc_multicast(mvm);
2389 iwl_mvm_configure_bcast_filter(mvm);
2391 /* reset rssi values */
2392 mvmvif->bf_data.ave_beacon_signal = 0;
2394 iwl_mvm_bt_coex_vif_change(mvm);
2395 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2396 IEEE80211_SMPS_AUTOMATIC);
2397 if (fw_has_capa(&mvm->fw->ucode_capa,
2398 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2399 iwl_mvm_config_scan(mvm);
2402 if (changes & BSS_CHANGED_BEACON_INFO) {
2404 * We received a beacon from the associated AP so
2405 * remove the session protection.
2406 * A firmware with the new API will remove it automatically.
2408 if (!fw_has_capa(&mvm->fw->ucode_capa,
2409 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD))
2410 iwl_mvm_stop_session_protection(mvm, vif);
2412 iwl_mvm_sf_update(mvm, vif, false);
2413 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2416 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2418 * Send power command on every beacon change,
2419 * because we may have not enabled beacon abort yet.
2421 BSS_CHANGED_BEACON_INFO)) {
2422 ret = iwl_mvm_power_update_mac(mvm);
2424 IWL_ERR(mvm, "failed to update power mode\n");
2427 if (changes & BSS_CHANGED_CQM) {
2428 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2429 /* reset cqm events tracking */
2430 mvmvif->bf_data.last_cqm_event = 0;
2431 if (mvmvif->bf_data.bf_enabled) {
2432 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2435 "failed to update CQM thresholds\n");
2439 if (changes & BSS_CHANGED_ARP_FILTER) {
2440 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2441 iwl_mvm_configure_bcast_filter(mvm);
2445 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2446 struct ieee80211_vif *vif)
2448 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2449 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2452 mutex_lock(&mvm->mutex);
2454 /* Send the beacon template */
2455 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2460 * Re-calculate the tsf id, as the leader-follower relations depend on
2461 * the beacon interval, which was not known when the AP interface
2464 if (vif->type == NL80211_IFTYPE_AP)
2465 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2467 mvmvif->ap_assoc_sta_count = 0;
2469 /* Add the mac context */
2470 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2474 /* Perform the binding */
2475 ret = iwl_mvm_binding_add_vif(mvm, vif);
2480 * This is not very nice, but the simplest:
2481 * For older FWs adding the mcast sta before the bcast station may
2482 * cause assert 0x2b00.
2483 * This is fixed in later FW so make the order of removal depend on
2486 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2487 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2491 * Send the bcast station. At this stage the TBTT and DTIM time
2492 * events are added and applied to the scheduler
2494 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2496 iwl_mvm_rm_mcast_sta(mvm, vif);
2501 * Send the bcast station. At this stage the TBTT and DTIM time
2502 * events are added and applied to the scheduler
2504 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2507 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2509 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2514 /* must be set before quota calculations */
2515 mvmvif->ap_ibss_active = true;
2517 /* send all the early keys to the device now */
2518 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
2519 struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i];
2524 mvmvif->ap_early_keys[i] = NULL;
2526 ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key);
2528 goto out_quota_failed;
2531 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2532 iwl_mvm_vif_set_low_latency(mvmvif, true,
2533 LOW_LATENCY_VIF_TYPE);
2534 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2537 /* power updated needs to be done before quotas */
2538 iwl_mvm_power_update_mac(mvm);
2540 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2542 goto out_quota_failed;
2544 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2545 if (vif->p2p && mvm->p2p_device_vif)
2546 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2548 iwl_mvm_bt_coex_vif_change(mvm);
2550 /* we don't support TDLS during DCM */
2551 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2552 iwl_mvm_teardown_tdls_peers(mvm);
2554 iwl_mvm_ftm_restart_responder(mvm, vif);
2559 iwl_mvm_power_update_mac(mvm);
2560 mvmvif->ap_ibss_active = false;
2561 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2562 iwl_mvm_rm_mcast_sta(mvm, vif);
2564 iwl_mvm_binding_remove_vif(mvm, vif);
2566 iwl_mvm_mac_ctxt_remove(mvm, vif);
2568 mutex_unlock(&mvm->mutex);
2572 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2573 struct ieee80211_vif *vif)
2575 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2576 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2578 iwl_mvm_prepare_mac_removal(mvm, vif);
2580 mutex_lock(&mvm->mutex);
2582 /* Handle AP stop while in CSA */
2583 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2584 iwl_mvm_remove_time_event(mvm, mvmvif,
2585 &mvmvif->time_event_data);
2586 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2587 mvmvif->csa_countdown = false;
2590 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2591 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2592 mvm->csa_tx_block_bcn_timeout = 0;
2595 mvmvif->ap_ibss_active = false;
2596 mvm->ap_last_beacon_gp2 = 0;
2598 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2599 iwl_mvm_vif_set_low_latency(mvmvif, false,
2600 LOW_LATENCY_VIF_TYPE);
2601 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2604 iwl_mvm_bt_coex_vif_change(mvm);
2606 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2607 if (vif->p2p && mvm->p2p_device_vif)
2608 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2610 iwl_mvm_update_quotas(mvm, false, NULL);
2612 iwl_mvm_ftm_responder_clear(mvm, vif);
2615 * This is not very nice, but the simplest:
2616 * For older FWs removing the mcast sta before the bcast station may
2617 * cause assert 0x2b00.
2618 * This is fixed in later FW (which will stop beaconing when removing
2620 * So make the order of removal depend on the TLV
2622 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2623 iwl_mvm_rm_mcast_sta(mvm, vif);
2624 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2625 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2626 iwl_mvm_rm_mcast_sta(mvm, vif);
2627 iwl_mvm_binding_remove_vif(mvm, vif);
2629 iwl_mvm_power_update_mac(mvm);
2631 iwl_mvm_mac_ctxt_remove(mvm, vif);
2633 mutex_unlock(&mvm->mutex);
2637 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2638 struct ieee80211_vif *vif,
2639 struct ieee80211_bss_conf *bss_conf,
2642 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2644 /* Changes will be applied when the AP/IBSS is started */
2645 if (!mvmvif->ap_ibss_active)
2648 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2649 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2650 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2651 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2653 /* Need to send a new beacon template to the FW */
2654 if (changes & BSS_CHANGED_BEACON &&
2655 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2656 IWL_WARN(mvm, "Failed updating beacon data\n");
2658 if (changes & BSS_CHANGED_FTM_RESPONDER) {
2659 int ret = iwl_mvm_ftm_start_responder(mvm, vif);
2662 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
2668 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2669 struct ieee80211_vif *vif,
2670 struct ieee80211_bss_conf *bss_conf,
2673 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2675 mutex_lock(&mvm->mutex);
2677 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2678 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2680 switch (vif->type) {
2681 case NL80211_IFTYPE_STATION:
2682 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2684 case NL80211_IFTYPE_AP:
2685 case NL80211_IFTYPE_ADHOC:
2686 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2688 case NL80211_IFTYPE_MONITOR:
2689 if (changes & BSS_CHANGED_MU_GROUPS)
2690 iwl_mvm_update_mu_groups(mvm, vif);
2693 /* shouldn't happen */
2697 if (changes & BSS_CHANGED_TXPOWER) {
2698 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d dBm\n",
2700 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2703 mutex_unlock(&mvm->mutex);
2706 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2707 struct ieee80211_vif *vif,
2708 struct ieee80211_scan_request *hw_req)
2710 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2713 if (hw_req->req.n_channels == 0 ||
2714 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2717 mutex_lock(&mvm->mutex);
2718 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2719 mutex_unlock(&mvm->mutex);
2724 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2725 struct ieee80211_vif *vif)
2727 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2729 mutex_lock(&mvm->mutex);
2731 /* Due to a race condition, it's possible that mac80211 asks
2732 * us to stop a hw_scan when it's already stopped. This can
2733 * happen, for instance, if we stopped the scan ourselves,
2734 * called ieee80211_scan_completed() and the userspace called
2735 * cancel scan scan before ieee80211_scan_work() could run.
2736 * To handle that, simply return if the scan is not running.
2738 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2739 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2741 mutex_unlock(&mvm->mutex);
2745 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2746 struct ieee80211_sta *sta, u16 tids,
2748 enum ieee80211_frame_release_type reason,
2751 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2753 /* Called when we need to transmit (a) frame(s) from mac80211 */
2755 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2756 tids, more_data, false);
2760 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2761 struct ieee80211_sta *sta, u16 tids,
2763 enum ieee80211_frame_release_type reason,
2766 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2768 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2770 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2771 tids, more_data, true);
2774 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2775 enum sta_notify_cmd cmd,
2776 struct ieee80211_sta *sta)
2778 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2779 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2780 unsigned long txqs = 0, tids = 0;
2784 * If we have TVQM then we get too high queue numbers - luckily
2785 * we really shouldn't get here with that because such hardware
2786 * should have firmware supporting buffer station offload.
2788 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2791 spin_lock_bh(&mvmsta->lock);
2792 for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) {
2793 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2795 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2798 __set_bit(tid_data->txq_id, &txqs);
2800 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2803 __set_bit(tid, &tids);
2807 case STA_NOTIFY_SLEEP:
2808 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2809 ieee80211_sta_set_buffered(sta, tid, true);
2812 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2814 * The fw updates the STA to be asleep. Tx packets on the Tx
2815 * queues to this station will not be transmitted. The fw will
2816 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2819 case STA_NOTIFY_AWAKE:
2820 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2824 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2825 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2830 spin_unlock_bh(&mvmsta->lock);
2833 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2834 struct ieee80211_vif *vif,
2835 enum sta_notify_cmd cmd,
2836 struct ieee80211_sta *sta)
2838 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2841 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2843 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2844 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2845 struct ieee80211_sta *sta;
2846 struct iwl_mvm_sta *mvmsta;
2847 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2849 if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations))
2853 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2854 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2859 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2862 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2867 if (mvmsta->sleeping != sleeping) {
2868 mvmsta->sleeping = sleeping;
2869 __iwl_mvm_mac_sta_notify(mvm->hw,
2870 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2872 ieee80211_sta_ps_transition(sta, sleeping);
2876 switch (notif->type) {
2877 case IWL_MVM_PM_EVENT_AWAKE:
2878 case IWL_MVM_PM_EVENT_ASLEEP:
2880 case IWL_MVM_PM_EVENT_UAPSD:
2881 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2883 case IWL_MVM_PM_EVENT_PS_POLL:
2884 ieee80211_sta_pspoll(sta);
2894 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2895 struct ieee80211_vif *vif,
2896 struct ieee80211_sta *sta)
2898 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2899 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2902 * This is called before mac80211 does RCU synchronisation,
2903 * so here we already invalidate our internal RCU-protected
2904 * station pointer. The rest of the code will thus no longer
2905 * be able to find the station this way, and we don't rely
2906 * on further RCU synchronisation after the sta_state()
2907 * callback deleted the station.
2909 mutex_lock(&mvm->mutex);
2910 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2911 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2914 mutex_unlock(&mvm->mutex);
2917 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2922 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2923 struct iwl_mvm_tcm_mac *mdata;
2925 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2926 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2927 mdata->opened_rx_ba_sessions = false;
2930 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2933 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2934 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2939 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2940 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2944 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2945 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2946 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2951 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2955 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2956 struct ieee80211_vif *vif, u8 *peer_addr,
2957 enum nl80211_tdls_operation action)
2959 struct iwl_fw_dbg_trigger_tlv *trig;
2960 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2962 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
2963 FW_DBG_TRIGGER_TDLS);
2967 tdls_trig = (void *)trig->data;
2969 if (!(tdls_trig->action_bitmap & BIT(action)))
2972 if (tdls_trig->peer_mode &&
2973 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2976 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2977 "TDLS event occurred, peer %pM, action %d",
2981 struct iwl_mvm_he_obss_narrow_bw_ru_data {
2985 static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy,
2986 struct cfg80211_bss *bss,
2989 struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data;
2990 const struct element *elem;
2992 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, bss->ies->data,
2995 if (!elem || elem->datalen < 10 ||
2997 WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) {
2998 data->tolerated = false;
3002 static void iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw,
3003 struct ieee80211_vif *vif)
3005 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3006 struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = {
3010 if (!(vif->bss_conf.chandef.chan->flags & IEEE80211_CHAN_RADAR)) {
3011 mvmvif->he_ru_2mhz_block = false;
3015 cfg80211_bss_iter(hw->wiphy, &vif->bss_conf.chandef,
3016 iwl_mvm_check_he_obss_narrow_bw_ru_iter,
3020 * If there is at least one AP on radar channel that cannot
3021 * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
3023 mvmvif->he_ru_2mhz_block = !iter_data.tolerated;
3026 static void iwl_mvm_reset_cca_40mhz_workaround(struct iwl_mvm *mvm,
3027 struct ieee80211_vif *vif)
3029 struct ieee80211_supported_band *sband;
3030 const struct ieee80211_sta_he_cap *he_cap;
3032 if (vif->type != NL80211_IFTYPE_STATION)
3035 if (!mvm->cca_40mhz_workaround)
3038 /* decrement and check that we reached zero */
3039 mvm->cca_40mhz_workaround--;
3040 if (mvm->cca_40mhz_workaround)
3043 sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ];
3045 sband->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3047 he_cap = ieee80211_get_he_iftype_cap(sband,
3048 ieee80211_vif_type_p2p(vif));
3051 /* we know that ours is writable */
3052 struct ieee80211_sta_he_cap *he = (void *)he_cap;
3054 he->he_cap_elem.phy_cap_info[0] |=
3055 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
3059 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
3060 struct ieee80211_vif *vif,
3061 struct ieee80211_sta *sta,
3062 enum ieee80211_sta_state old_state,
3063 enum ieee80211_sta_state new_state)
3065 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3066 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3067 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3070 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
3071 sta->addr, old_state, new_state);
3073 /* this would be a mac80211 bug ... but don't crash */
3074 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
3075 return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL;
3078 * If we are in a STA removal flow and in DQA mode:
3080 * This is after the sync_rcu part, so the queues have already been
3081 * flushed. No more TXs on their way in mac80211's path, and no more in
3083 * Also, we won't be getting any new TX frames for this station.
3084 * What we might have are deferred TX frames that need to be taken care
3087 * Drop any still-queued deferred-frame before removing the STA, and
3088 * make sure the worker is no longer handling frames for this STA.
3090 if (old_state == IEEE80211_STA_NONE &&
3091 new_state == IEEE80211_STA_NOTEXIST) {
3092 flush_work(&mvm->add_stream_wk);
3095 * No need to make sure deferred TX indication is off since the
3096 * worker will already remove it if it was on
3100 * Additionally, reset the 40 MHz capability if we disconnected
3103 iwl_mvm_reset_cca_40mhz_workaround(mvm, vif);
3106 mutex_lock(&mvm->mutex);
3107 /* track whether or not the station is associated */
3108 mvm_sta->sta_state = new_state;
3110 if (old_state == IEEE80211_STA_NOTEXIST &&
3111 new_state == IEEE80211_STA_NONE) {
3113 * Firmware bug - it'll crash if the beacon interval is less
3114 * than 16. We can't avoid connecting at all, so refuse the
3115 * station state change, this will cause mac80211 to abandon
3116 * attempts to connect to this AP, and eventually wpa_s will
3117 * blocklist the AP...
3119 if (vif->type == NL80211_IFTYPE_STATION &&
3120 vif->bss_conf.beacon_int < 16) {
3122 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
3123 sta->addr, vif->bss_conf.beacon_int);
3128 if (vif->type == NL80211_IFTYPE_STATION)
3129 vif->bss_conf.he_support = sta->he_cap.has_he;
3133 iwl_mvm_tdls_sta_count(mvm, NULL) ==
3134 IWL_MVM_TDLS_STA_COUNT ||
3135 iwl_mvm_phy_ctx_count(mvm) > 1)) {
3136 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
3141 ret = iwl_mvm_add_sta(mvm, vif, sta);
3142 if (sta->tdls && ret == 0) {
3143 iwl_mvm_recalc_tdls_state(mvm, vif, true);
3144 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3145 NL80211_TDLS_SETUP);
3148 sta->max_rc_amsdu_len = 1;
3149 } else if (old_state == IEEE80211_STA_NONE &&
3150 new_state == IEEE80211_STA_AUTH) {
3152 * EBS may be disabled due to previous failures reported by FW.
3153 * Reset EBS status here assuming environment has been changed.
3155 mvm->last_ebs_successful = true;
3156 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
3158 } else if (old_state == IEEE80211_STA_AUTH &&
3159 new_state == IEEE80211_STA_ASSOC) {
3160 if (vif->type == NL80211_IFTYPE_AP) {
3161 vif->bss_conf.he_support = sta->he_cap.has_he;
3162 mvmvif->ap_assoc_sta_count++;
3163 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3164 if (vif->bss_conf.he_support &&
3165 !iwlwifi_mod_params.disable_11ax)
3166 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id);
3167 } else if (vif->type == NL80211_IFTYPE_STATION) {
3168 vif->bss_conf.he_support = sta->he_cap.has_he;
3170 mvmvif->he_ru_2mhz_block = false;
3171 if (sta->he_cap.has_he)
3172 iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif);
3174 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3177 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3179 ret = iwl_mvm_update_sta(mvm, vif, sta);
3180 } else if (old_state == IEEE80211_STA_ASSOC &&
3181 new_state == IEEE80211_STA_AUTHORIZED) {
3184 /* we don't support TDLS during DCM */
3185 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3186 iwl_mvm_teardown_tdls_peers(mvm);
3189 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3190 NL80211_TDLS_ENABLE_LINK);
3192 /* enable beacon filtering */
3193 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
3196 * Now that the station is authorized, i.e., keys were already
3197 * installed, need to indicate to the FW that
3198 * multicast data frames can be forwarded to the driver
3200 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3202 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3204 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3205 new_state == IEEE80211_STA_ASSOC) {
3206 /* Multicast data frames are no longer allowed */
3207 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3209 /* disable beacon filtering */
3210 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3212 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3215 } else if (old_state == IEEE80211_STA_ASSOC &&
3216 new_state == IEEE80211_STA_AUTH) {
3217 if (vif->type == NL80211_IFTYPE_AP) {
3218 mvmvif->ap_assoc_sta_count--;
3219 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3222 } else if (old_state == IEEE80211_STA_AUTH &&
3223 new_state == IEEE80211_STA_NONE) {
3225 } else if (old_state == IEEE80211_STA_NONE &&
3226 new_state == IEEE80211_STA_NOTEXIST) {
3227 ret = iwl_mvm_rm_sta(mvm, vif, sta);
3229 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3230 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3231 NL80211_TDLS_DISABLE_LINK);
3235 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3242 mutex_unlock(&mvm->mutex);
3244 if (sta->tdls && ret == 0) {
3245 if (old_state == IEEE80211_STA_NOTEXIST &&
3246 new_state == IEEE80211_STA_NONE)
3247 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3248 else if (old_state == IEEE80211_STA_NONE &&
3249 new_state == IEEE80211_STA_NOTEXIST)
3250 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3256 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3258 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3260 mvm->rts_threshold = value;
3265 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3266 struct ieee80211_vif *vif,
3267 struct ieee80211_sta *sta, u32 changed)
3269 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3270 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3272 if (changed & (IEEE80211_RC_BW_CHANGED |
3273 IEEE80211_RC_SUPP_RATES_CHANGED |
3274 IEEE80211_RC_NSS_CHANGED))
3275 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3278 if (vif->type == NL80211_IFTYPE_STATION &&
3279 changed & IEEE80211_RC_NSS_CHANGED)
3280 iwl_mvm_sf_update(mvm, vif, false);
3283 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3284 struct ieee80211_vif *vif, u16 ac,
3285 const struct ieee80211_tx_queue_params *params)
3287 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3288 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3290 mvmvif->queue_params[ac] = *params;
3293 * No need to update right away, we'll get BSS_CHANGED_QOS
3294 * The exception is P2P_DEVICE interface which needs immediate update.
3296 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3299 mutex_lock(&mvm->mutex);
3300 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3301 mutex_unlock(&mvm->mutex);
3307 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3308 struct ieee80211_vif *vif,
3311 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3312 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3313 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3315 if (req_duration > duration)
3316 duration = req_duration;
3318 mutex_lock(&mvm->mutex);
3319 /* Try really hard to protect the session and hear a beacon
3320 * The new session protection command allows us to protect the
3321 * session for a much longer time since the firmware will internally
3322 * create two events: a 300TU one with a very high priority that
3323 * won't be fragmented which should be enough for 99% of the cases,
3324 * and another one (which we configure here to be 900TU long) which
3325 * will have a slightly lower priority, but more importantly, can be
3326 * fragmented so that it'll allow other activities to run.
3328 if (fw_has_capa(&mvm->fw->ucode_capa,
3329 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD))
3330 iwl_mvm_schedule_session_protection(mvm, vif, 900,
3331 min_duration, false);
3333 iwl_mvm_protect_session(mvm, vif, duration,
3334 min_duration, 500, false);
3335 mutex_unlock(&mvm->mutex);
3338 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3339 struct ieee80211_vif *vif,
3340 struct cfg80211_sched_scan_request *req,
3341 struct ieee80211_scan_ies *ies)
3343 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3347 mutex_lock(&mvm->mutex);
3349 if (!vif->bss_conf.idle) {
3354 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3357 mutex_unlock(&mvm->mutex);
3361 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3362 struct ieee80211_vif *vif)
3364 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3367 mutex_lock(&mvm->mutex);
3369 /* Due to a race condition, it's possible that mac80211 asks
3370 * us to stop a sched_scan when it's already stopped. This
3371 * can happen, for instance, if we stopped the scan ourselves,
3372 * called ieee80211_sched_scan_stopped() and the userspace called
3373 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3374 * could run. To handle this, simply return if the scan is
3377 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3378 mutex_unlock(&mvm->mutex);
3382 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3383 mutex_unlock(&mvm->mutex);
3384 iwl_mvm_wait_for_async_handlers(mvm);
3389 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3390 enum set_key_cmd cmd,
3391 struct ieee80211_vif *vif,
3392 struct ieee80211_sta *sta,
3393 struct ieee80211_key_conf *key)
3395 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3396 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3397 struct iwl_mvm_sta *mvmsta;
3398 struct iwl_mvm_key_pn *ptk_pn;
3399 int keyidx = key->keyidx;
3403 switch (key->cipher) {
3404 case WLAN_CIPHER_SUITE_TKIP:
3405 if (!mvm->trans->trans_cfg->gen2) {
3406 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3407 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3408 } else if (vif->type == NL80211_IFTYPE_STATION) {
3409 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3411 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3415 case WLAN_CIPHER_SUITE_CCMP:
3416 case WLAN_CIPHER_SUITE_GCMP:
3417 case WLAN_CIPHER_SUITE_GCMP_256:
3418 if (!iwl_mvm_has_new_tx_api(mvm))
3419 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3421 case WLAN_CIPHER_SUITE_AES_CMAC:
3422 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3423 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3424 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3426 case WLAN_CIPHER_SUITE_WEP40:
3427 case WLAN_CIPHER_SUITE_WEP104:
3428 if (vif->type == NL80211_IFTYPE_STATION)
3430 if (iwl_mvm_has_new_tx_api(mvm))
3432 /* support HW crypto on TX */
3435 /* currently FW supports only one optional cipher scheme */
3436 if (hw->n_cipher_schemes &&
3437 hw->cipher_schemes->cipher == key->cipher)
3438 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3445 if (keyidx == 6 || keyidx == 7)
3446 rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6],
3449 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3450 vif->type == NL80211_IFTYPE_AP) && !sta) {
3452 * GTK on AP interface is a TX-only key, return 0;
3453 * on IBSS they're per-station and because we're lazy
3454 * we don't support them for RX, so do the same.
3455 * CMAC/GMAC in AP/IBSS modes must be done in software.
3457 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3458 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3459 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) {
3464 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3465 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3466 !iwl_mvm_has_new_tx_api(mvm)) {
3467 key->hw_key_idx = STA_KEY_IDX_INVALID;
3472 if (!mvmvif->ap_ibss_active) {
3474 i < ARRAY_SIZE(mvmvif->ap_early_keys);
3476 if (!mvmvif->ap_early_keys[i]) {
3477 mvmvif->ap_early_keys[i] = key;
3482 if (i >= ARRAY_SIZE(mvmvif->ap_early_keys))
3491 /* During FW restart, in order to restore the state as it was,
3492 * don't try to reprogram keys we previously failed for.
3494 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3495 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3496 IWL_DEBUG_MAC80211(mvm,
3497 "skip invalid idx key programming during restart\n");
3502 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3503 sta && iwl_mvm_has_new_rx_api(mvm) &&
3504 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3505 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3506 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3507 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3508 struct ieee80211_key_seq seq;
3511 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3512 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3513 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3514 mvm->trans->num_rx_queues),
3521 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3522 ieee80211_get_key_rx_seq(key, tid, &seq);
3523 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3524 memcpy(ptk_pn->q[q].pn[tid],
3526 IEEE80211_CCMP_PN_LEN);
3529 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3532 /* in HW restart reuse the index, otherwise request a new one */
3533 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3534 key_offset = key->hw_key_idx;
3536 key_offset = STA_KEY_IDX_INVALID;
3538 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3539 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3541 IWL_WARN(mvm, "set key failed\n");
3542 key->hw_key_idx = STA_KEY_IDX_INVALID;
3544 * can't add key for RX, but we don't need it
3545 * in the device for TX so still return 0,
3546 * unless we have new TX API where we cannot
3547 * put key material into the TX_CMD
3549 if (iwl_mvm_has_new_tx_api(mvm))
3557 if (keyidx == 6 || keyidx == 7)
3558 RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6],
3562 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
3563 if (mvmvif->ap_early_keys[i] == key) {
3564 mvmvif->ap_early_keys[i] = NULL;
3569 /* found in pending list - don't do anything else */
3573 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3578 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3579 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3580 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3581 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3582 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3583 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3584 ptk_pn = rcu_dereference_protected(
3585 mvmsta->ptk_pn[keyidx],
3586 lockdep_is_held(&mvm->mutex));
3587 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3589 kfree_rcu(ptk_pn, rcu_head);
3592 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3593 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3602 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3603 enum set_key_cmd cmd,
3604 struct ieee80211_vif *vif,
3605 struct ieee80211_sta *sta,
3606 struct ieee80211_key_conf *key)
3608 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3611 mutex_lock(&mvm->mutex);
3612 ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key);
3613 mutex_unlock(&mvm->mutex);
3618 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3619 struct ieee80211_vif *vif,
3620 struct ieee80211_key_conf *keyconf,
3621 struct ieee80211_sta *sta,
3622 u32 iv32, u16 *phase1key)
3624 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3626 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3629 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3633 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3634 struct iwl_rx_packet *pkt, void *data)
3636 struct iwl_mvm *mvm =
3637 container_of(notif_wait, struct iwl_mvm, notif_wait);
3638 struct iwl_hs20_roc_res *resp;
3639 int resp_len = iwl_rx_packet_payload_len(pkt);
3640 struct iwl_mvm_time_event_data *te_data = data;
3642 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3645 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3646 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3650 resp = (void *)pkt->data;
3653 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
3654 resp->status, resp->event_unique_id);
3656 te_data->uid = le32_to_cpu(resp->event_unique_id);
3657 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3660 spin_lock_bh(&mvm->time_event_lock);
3661 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3662 spin_unlock_bh(&mvm->time_event_lock);
3667 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3668 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3669 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3670 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3671 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3672 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3673 struct ieee80211_channel *channel,
3674 struct ieee80211_vif *vif,
3678 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3679 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3680 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3681 struct iwl_notification_wait wait_time_event;
3682 u32 dtim_interval = vif->bss_conf.dtim_period *
3683 vif->bss_conf.beacon_int;
3685 struct iwl_hs20_roc_req aux_roc_req = {
3686 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3688 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3689 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3691 struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm,
3692 &aux_roc_req.channel_info);
3693 u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm);
3695 /* Set the channel info data */
3696 iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value,
3697 iwl_mvm_phy_band_from_nl80211(channel->band),
3698 PHY_VHT_CHANNEL_MODE20,
3701 /* Set the time and duration */
3702 tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm));
3704 delay = AUX_ROC_MIN_DELAY;
3705 req_dur = MSEC_TO_TU(duration);
3708 * If we are associated we want the delay time to be at least one
3709 * dtim interval so that the FW can wait until after the DTIM and
3710 * then start the time event, this will potentially allow us to
3711 * remain off-channel for the max duration.
3712 * Since we want to use almost a whole dtim interval we would also
3713 * like the delay to be for 2-3 dtim intervals, in case there are
3714 * other time events with higher priority.
3716 if (vif->bss_conf.assoc) {
3717 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3718 /* We cannot remain off-channel longer than the DTIM interval */
3719 if (dtim_interval <= req_dur) {
3720 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3721 if (req_dur <= AUX_ROC_MIN_DURATION)
3722 req_dur = dtim_interval -
3723 AUX_ROC_MIN_SAFETY_BUFFER;
3727 tail->duration = cpu_to_le32(req_dur);
3728 tail->apply_time_max_delay = cpu_to_le32(delay);
3731 "ROC: Requesting to remain on channel %u for %ums\n",
3732 channel->hw_value, req_dur);
3734 "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3735 duration, delay, dtim_interval);
3737 /* Set the node address */
3738 memcpy(tail->node_addr, vif->addr, ETH_ALEN);
3740 lockdep_assert_held(&mvm->mutex);
3742 spin_lock_bh(&mvm->time_event_lock);
3744 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3745 spin_unlock_bh(&mvm->time_event_lock);
3750 te_data->duration = duration;
3751 te_data->id = HOT_SPOT_CMD;
3753 spin_unlock_bh(&mvm->time_event_lock);
3756 * Use a notification wait, which really just processes the
3757 * command response and doesn't wait for anything, in order
3758 * to be able to process the response and get the UID inside
3759 * the RX path. Using CMD_WANT_SKB doesn't work because it
3760 * stores the buffer and then wakes up this thread, by which
3761 * time another notification (that the time event started)
3762 * might already be processed unsuccessfully.
3764 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3765 time_event_response,
3766 ARRAY_SIZE(time_event_response),
3767 iwl_mvm_rx_aux_roc, te_data);
3769 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len,
3773 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3774 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3778 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3779 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3780 /* should never fail */
3785 spin_lock_bh(&mvm->time_event_lock);
3786 iwl_mvm_te_clear_data(mvm, te_data);
3787 spin_unlock_bh(&mvm->time_event_lock);
3793 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3794 struct ieee80211_vif *vif,
3795 struct ieee80211_channel *channel,
3797 enum ieee80211_roc_type type)
3799 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3800 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3801 struct cfg80211_chan_def chandef;
3802 struct iwl_mvm_phy_ctxt *phy_ctxt;
3805 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3809 * Flush the done work, just in case it's still pending, so that
3810 * the work it does can complete and we can accept new frames.
3812 flush_work(&mvm->roc_done_wk);
3814 mutex_lock(&mvm->mutex);
3816 switch (vif->type) {
3817 case NL80211_IFTYPE_STATION:
3818 if (fw_has_capa(&mvm->fw->ucode_capa,
3819 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3820 /* Use aux roc framework (HS20) */
3821 if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
3822 ADD_STA, 0) >= 12) {
3825 lmac_id = iwl_mvm_get_lmac_id(mvm->fw,
3827 ret = iwl_mvm_add_aux_sta(mvm, lmac_id);
3829 "Failed to allocate aux station"))
3832 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3836 IWL_ERR(mvm, "hotspot not supported\n");
3839 case NL80211_IFTYPE_P2P_DEVICE:
3843 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3848 for (i = 0; i < NUM_PHY_CTX; i++) {
3849 phy_ctxt = &mvm->phy_ctxts[i];
3850 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3853 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3855 * Unbind the P2P_DEVICE from the current PHY context,
3856 * and if the PHY context is not used remove it.
3858 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3859 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3862 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3864 /* Bind the P2P_DEVICE to the current PHY Context */
3865 mvmvif->phy_ctxt = phy_ctxt;
3867 ret = iwl_mvm_binding_add_vif(mvm, vif);
3868 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3871 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3872 goto schedule_time_event;
3876 /* Need to update the PHY context only if the ROC channel changed */
3877 if (channel == mvmvif->phy_ctxt->channel)
3878 goto schedule_time_event;
3880 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3883 * Change the PHY context configuration as it is currently referenced
3884 * only by the P2P Device MAC
3886 if (mvmvif->phy_ctxt->ref == 1) {
3887 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3893 * The PHY context is shared with other MACs. Need to remove the
3894 * P2P Device from the binding, allocate an new PHY context and
3895 * create a new binding
3897 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3903 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3906 IWL_ERR(mvm, "Failed to change PHY context\n");
3910 /* Unbind the P2P_DEVICE from the current PHY context */
3911 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3912 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3915 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3917 /* Bind the P2P_DEVICE to the new allocated PHY context */
3918 mvmvif->phy_ctxt = phy_ctxt;
3920 ret = iwl_mvm_binding_add_vif(mvm, vif);
3921 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3924 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3927 schedule_time_event:
3928 /* Schedule the time events */
3929 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3932 mutex_unlock(&mvm->mutex);
3933 IWL_DEBUG_MAC80211(mvm, "leave\n");
3937 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw,
3938 struct ieee80211_vif *vif)
3940 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3942 IWL_DEBUG_MAC80211(mvm, "enter\n");
3944 mutex_lock(&mvm->mutex);
3945 iwl_mvm_stop_roc(mvm, vif);
3946 mutex_unlock(&mvm->mutex);
3948 IWL_DEBUG_MAC80211(mvm, "leave\n");
3952 struct iwl_mvm_ftm_responder_iter_data {
3954 struct ieee80211_chanctx_conf *ctx;
3957 static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac,
3958 struct ieee80211_vif *vif)
3960 struct iwl_mvm_ftm_responder_iter_data *data = _data;
3962 if (rcu_access_pointer(vif->chanctx_conf) == data->ctx &&
3963 vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params)
3964 data->responder = true;
3967 static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm,
3968 struct ieee80211_chanctx_conf *ctx)
3970 struct iwl_mvm_ftm_responder_iter_data data = {
3975 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
3976 IEEE80211_IFACE_ITER_NORMAL,
3977 iwl_mvm_ftm_responder_chanctx_iter,
3979 return data.responder;
3982 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3983 struct ieee80211_chanctx_conf *ctx)
3985 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3986 struct iwl_mvm_phy_ctxt *phy_ctxt;
3987 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
3988 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
3991 lockdep_assert_held(&mvm->mutex);
3993 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3995 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
4001 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4002 ctx->rx_chains_static,
4003 ctx->rx_chains_dynamic);
4005 IWL_ERR(mvm, "Failed to add PHY context\n");
4009 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
4010 *phy_ctxt_id = phy_ctxt->id;
4015 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
4016 struct ieee80211_chanctx_conf *ctx)
4018 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4021 mutex_lock(&mvm->mutex);
4022 ret = __iwl_mvm_add_chanctx(mvm, ctx);
4023 mutex_unlock(&mvm->mutex);
4028 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
4029 struct ieee80211_chanctx_conf *ctx)
4031 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4032 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4034 lockdep_assert_held(&mvm->mutex);
4036 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
4039 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
4040 struct ieee80211_chanctx_conf *ctx)
4042 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4044 mutex_lock(&mvm->mutex);
4045 __iwl_mvm_remove_chanctx(mvm, ctx);
4046 mutex_unlock(&mvm->mutex);
4049 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
4050 struct ieee80211_chanctx_conf *ctx,
4053 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4054 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4055 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4056 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
4057 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
4059 if (WARN_ONCE((phy_ctxt->ref > 1) &&
4060 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
4061 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
4062 IEEE80211_CHANCTX_CHANGE_RADAR |
4063 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
4064 "Cannot change PHY. Ref=%d, changed=0x%X\n",
4065 phy_ctxt->ref, changed))
4068 mutex_lock(&mvm->mutex);
4070 /* we are only changing the min_width, may be a noop */
4071 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
4072 if (phy_ctxt->width == def->width)
4075 /* we are just toggling between 20_NOHT and 20 */
4076 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
4077 def->width <= NL80211_CHAN_WIDTH_20)
4081 iwl_mvm_bt_coex_vif_change(mvm);
4082 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4083 ctx->rx_chains_static,
4084 ctx->rx_chains_dynamic);
4087 mutex_unlock(&mvm->mutex);
4090 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
4091 struct ieee80211_vif *vif,
4092 struct ieee80211_chanctx_conf *ctx,
4093 bool switching_chanctx)
4095 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4096 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4097 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4100 lockdep_assert_held(&mvm->mutex);
4102 mvmvif->phy_ctxt = phy_ctxt;
4104 switch (vif->type) {
4105 case NL80211_IFTYPE_AP:
4106 /* only needed if we're switching chanctx (i.e. during CSA) */
4107 if (switching_chanctx) {
4108 mvmvif->ap_ibss_active = true;
4112 case NL80211_IFTYPE_ADHOC:
4114 * The AP binding flow is handled as part of the start_ap flow
4115 * (in bss_info_changed), similarly for IBSS.
4119 case NL80211_IFTYPE_STATION:
4120 mvmvif->csa_bcn_pending = false;
4122 case NL80211_IFTYPE_MONITOR:
4123 /* always disable PS when a monitor interface is active */
4124 mvmvif->ps_disabled = true;
4131 ret = iwl_mvm_binding_add_vif(mvm, vif);
4136 * Power state must be updated before quotas,
4137 * otherwise fw will complain.
4139 iwl_mvm_power_update_mac(mvm);
4141 /* Setting the quota at this stage is only required for monitor
4142 * interfaces. For the other types, the bss_info changed flow
4143 * will handle quota settings.
4145 if (vif->type == NL80211_IFTYPE_MONITOR) {
4146 mvmvif->monitor_active = true;
4147 ret = iwl_mvm_update_quotas(mvm, false, NULL);
4149 goto out_remove_binding;
4151 ret = iwl_mvm_add_snif_sta(mvm, vif);
4153 goto out_remove_binding;
4157 /* Handle binding during CSA */
4158 if (vif->type == NL80211_IFTYPE_AP) {
4159 iwl_mvm_update_quotas(mvm, false, NULL);
4160 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4163 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
4164 mvmvif->csa_bcn_pending = true;
4166 if (!fw_has_capa(&mvm->fw->ucode_capa,
4167 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4168 u32 duration = 3 * vif->bss_conf.beacon_int;
4170 /* Protect the session to make sure we hear the first
4171 * beacon on the new channel.
4173 iwl_mvm_protect_session(mvm, vif, duration, duration,
4174 vif->bss_conf.beacon_int / 2,
4178 iwl_mvm_update_quotas(mvm, false, NULL);
4184 iwl_mvm_binding_remove_vif(mvm, vif);
4185 iwl_mvm_power_update_mac(mvm);
4188 mvmvif->phy_ctxt = NULL;
4191 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
4192 struct ieee80211_vif *vif,
4193 struct ieee80211_chanctx_conf *ctx)
4195 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4198 mutex_lock(&mvm->mutex);
4199 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
4200 mutex_unlock(&mvm->mutex);
4205 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
4206 struct ieee80211_vif *vif,
4207 struct ieee80211_chanctx_conf *ctx,
4208 bool switching_chanctx)
4210 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4211 struct ieee80211_vif *disabled_vif = NULL;
4213 lockdep_assert_held(&mvm->mutex);
4215 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
4217 switch (vif->type) {
4218 case NL80211_IFTYPE_ADHOC:
4220 case NL80211_IFTYPE_MONITOR:
4221 mvmvif->monitor_active = false;
4222 mvmvif->ps_disabled = false;
4223 iwl_mvm_rm_snif_sta(mvm, vif);
4225 case NL80211_IFTYPE_AP:
4226 /* This part is triggered only during CSA */
4227 if (!switching_chanctx || !mvmvif->ap_ibss_active)
4230 mvmvif->csa_countdown = false;
4232 /* Set CS bit on all the stations */
4233 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
4235 /* Save blocked iface, the timeout is set on the next beacon */
4236 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
4238 mvmvif->ap_ibss_active = false;
4240 case NL80211_IFTYPE_STATION:
4241 if (!switching_chanctx)
4246 if (!fw_has_capa(&mvm->fw->ucode_capa,
4247 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
4248 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
4254 iwl_mvm_update_quotas(mvm, false, disabled_vif);
4255 iwl_mvm_binding_remove_vif(mvm, vif);
4258 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD) &&
4261 mvmvif->phy_ctxt = NULL;
4262 iwl_mvm_power_update_mac(mvm);
4265 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
4266 struct ieee80211_vif *vif,
4267 struct ieee80211_chanctx_conf *ctx)
4269 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4271 mutex_lock(&mvm->mutex);
4272 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
4273 mutex_unlock(&mvm->mutex);
4277 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
4278 struct ieee80211_vif_chanctx_switch *vifs)
4282 mutex_lock(&mvm->mutex);
4283 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4284 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
4286 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
4288 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
4292 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4296 "failed to assign new_ctx during channel switch\n");
4300 /* we don't support TDLS during DCM - can be caused by channel switch */
4301 if (iwl_mvm_phy_ctx_count(mvm) > 1)
4302 iwl_mvm_teardown_tdls_peers(mvm);
4307 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
4310 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
4311 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
4315 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4317 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4324 /* things keep failing, better restart the hw */
4325 iwl_mvm_nic_restart(mvm, false);
4328 mutex_unlock(&mvm->mutex);
4334 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
4335 struct ieee80211_vif_chanctx_switch *vifs)
4339 mutex_lock(&mvm->mutex);
4340 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4342 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4346 "failed to assign new_ctx during channel switch\n");
4353 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4355 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4362 /* things keep failing, better restart the hw */
4363 iwl_mvm_nic_restart(mvm, false);
4366 mutex_unlock(&mvm->mutex);
4371 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4372 struct ieee80211_vif_chanctx_switch *vifs,
4374 enum ieee80211_chanctx_switch_mode mode)
4376 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4379 /* we only support a single-vif right now */
4384 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4385 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4387 case CHANCTX_SWMODE_REASSIGN_VIF:
4388 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4398 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4400 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4402 return mvm->ibss_manager;
4405 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4406 struct ieee80211_sta *sta,
4409 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4410 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4412 if (!mvm_sta || !mvm_sta->vif) {
4413 IWL_ERR(mvm, "Station is not associated to a vif\n");
4417 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4420 #ifdef CONFIG_NL80211_TESTMODE
4421 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4422 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4423 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4424 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4427 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4428 struct ieee80211_vif *vif,
4429 void *data, int len)
4431 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4435 err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len,
4436 iwl_mvm_tm_policy, NULL);
4440 if (!tb[IWL_MVM_TM_ATTR_CMD])
4443 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4444 case IWL_MVM_TM_CMD_SET_NOA:
4445 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4446 !vif->bss_conf.enable_beacon ||
4447 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4450 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4451 if (noa_duration >= vif->bss_conf.beacon_int)
4454 mvm->noa_duration = noa_duration;
4457 return iwl_mvm_update_quotas(mvm, true, NULL);
4458 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4459 /* must be associated client vif - ignore authorized */
4460 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4461 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4462 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4465 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4466 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4467 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4473 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4474 struct ieee80211_vif *vif,
4475 void *data, int len)
4477 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4480 mutex_lock(&mvm->mutex);
4481 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4482 mutex_unlock(&mvm->mutex);
4488 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4489 struct ieee80211_vif *vif,
4490 struct ieee80211_channel_switch *chsw)
4492 /* By implementing this operation, we prevent mac80211 from
4493 * starting its own channel switch timer, so that we can call
4494 * ieee80211_chswitch_done() ourselves at the right time
4495 * (which is when the absence time event starts).
4498 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4499 "dummy channel switch op\n");
4502 static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm,
4503 struct ieee80211_vif *vif,
4504 struct ieee80211_channel_switch *chsw)
4506 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4507 struct iwl_chan_switch_te_cmd cmd = {
4508 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4510 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
4511 .tsf = cpu_to_le32(chsw->timestamp),
4512 .cs_count = chsw->count,
4513 .cs_mode = chsw->block_tx,
4516 lockdep_assert_held(&mvm->mutex);
4519 cmd.cs_delayed_bcn_count =
4520 DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int);
4522 return iwl_mvm_send_cmd_pdu(mvm,
4523 WIDE_ID(MAC_CONF_GROUP,
4524 CHANNEL_SWITCH_TIME_EVENT_CMD),
4525 0, sizeof(cmd), &cmd);
4528 static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm,
4529 struct ieee80211_vif *vif,
4530 struct ieee80211_channel_switch *chsw)
4532 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4535 /* Schedule the time event to a bit before beacon 1,
4536 * to make sure we're in the new channel when the
4537 * GO/AP arrives. In case count <= 1 immediately schedule the
4538 * TE (this might result with some packet loss or connection
4541 if (chsw->count <= 1)
4544 apply_time = chsw->device_timestamp +
4545 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4546 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4549 iwl_mvm_csa_client_absent(mvm, vif);
4551 if (mvmvif->bf_data.bf_enabled) {
4552 int ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4558 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4564 #define IWL_MAX_CSA_BLOCK_TX 1500
4565 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4566 struct ieee80211_vif *vif,
4567 struct ieee80211_channel_switch *chsw)
4569 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4570 struct ieee80211_vif *csa_vif;
4571 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4574 mutex_lock(&mvm->mutex);
4576 mvmvif->csa_failed = false;
4578 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4579 chsw->chandef.center_freq1);
4581 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4582 ieee80211_vif_to_wdev(vif),
4583 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4585 switch (vif->type) {
4586 case NL80211_IFTYPE_AP:
4588 rcu_dereference_protected(mvm->csa_vif,
4589 lockdep_is_held(&mvm->mutex));
4590 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4591 "Another CSA is already in progress")) {
4596 /* we still didn't unblock tx. prevent new CS meanwhile */
4597 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4598 lockdep_is_held(&mvm->mutex))) {
4603 rcu_assign_pointer(mvm->csa_vif, vif);
4605 if (WARN_ONCE(mvmvif->csa_countdown,
4606 "Previous CSA countdown didn't complete")) {
4611 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4614 case NL80211_IFTYPE_STATION:
4616 * We haven't configured the firmware to be associated yet since
4617 * we don't know the dtim period. In this case, the firmware can't
4618 * track the beacons.
4620 if (!vif->bss_conf.assoc || !vif->bss_conf.dtim_period) {
4625 if (chsw->delay > IWL_MAX_CSA_BLOCK_TX)
4626 schedule_delayed_work(&mvmvif->csa_work, 0);
4628 if (chsw->block_tx) {
4630 * In case of undetermined / long time with immediate
4631 * quiet monitor status to gracefully disconnect
4634 chsw->count * vif->bss_conf.beacon_int >
4635 IWL_MAX_CSA_BLOCK_TX)
4636 schedule_delayed_work(&mvmvif->csa_work,
4637 msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX));
4640 if (!fw_has_capa(&mvm->fw->ucode_capa,
4641 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4642 ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw);
4646 iwl_mvm_schedule_client_csa(mvm, vif, chsw);
4649 mvmvif->csa_count = chsw->count;
4650 mvmvif->csa_misbehave = false;
4656 mvmvif->ps_disabled = true;
4658 ret = iwl_mvm_power_update_ps(mvm);
4662 /* we won't be on this channel any longer */
4663 iwl_mvm_teardown_tdls_peers(mvm);
4666 mutex_unlock(&mvm->mutex);
4671 static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw,
4672 struct ieee80211_vif *vif,
4673 struct ieee80211_channel_switch *chsw)
4675 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4676 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4677 struct iwl_chan_switch_te_cmd cmd = {
4678 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4680 .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY),
4681 .tsf = cpu_to_le32(chsw->timestamp),
4682 .cs_count = chsw->count,
4683 .cs_mode = chsw->block_tx,
4686 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY))
4689 if (chsw->count >= mvmvif->csa_count && chsw->block_tx) {
4690 if (mvmvif->csa_misbehave) {
4691 /* Second time, give up on this AP*/
4692 iwl_mvm_abort_channel_switch(hw, vif);
4693 ieee80211_chswitch_done(vif, false);
4694 mvmvif->csa_misbehave = false;
4697 mvmvif->csa_misbehave = true;
4699 mvmvif->csa_count = chsw->count;
4701 mutex_lock(&mvm->mutex);
4702 if (mvmvif->csa_failed)
4705 IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d mode = %d\n",
4706 mvmvif->id, chsw->count, chsw->block_tx);
4707 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
4708 WIDE_ID(MAC_CONF_GROUP,
4709 CHANNEL_SWITCH_TIME_EVENT_CMD),
4710 0, sizeof(cmd), &cmd));
4712 mutex_unlock(&mvm->mutex);
4715 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4719 if (!iwl_mvm_has_new_tx_api(mvm)) {
4721 mutex_lock(&mvm->mutex);
4722 iwl_mvm_flush_tx_path(mvm,
4723 iwl_mvm_flushable_queues(mvm) & queues);
4724 mutex_unlock(&mvm->mutex);
4726 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4731 mutex_lock(&mvm->mutex);
4732 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
4733 struct ieee80211_sta *sta;
4735 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4736 lockdep_is_held(&mvm->mutex));
4737 if (IS_ERR_OR_NULL(sta))
4741 iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF);
4743 iwl_mvm_wait_sta_queues_empty(mvm,
4744 iwl_mvm_sta_from_mac80211(sta));
4746 mutex_unlock(&mvm->mutex);
4749 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4750 struct ieee80211_vif *vif, u32 queues, bool drop)
4752 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4753 struct iwl_mvm_vif *mvmvif;
4754 struct iwl_mvm_sta *mvmsta;
4755 struct ieee80211_sta *sta;
4760 iwl_mvm_flush_no_vif(mvm, queues, drop);
4764 if (vif->type != NL80211_IFTYPE_STATION)
4767 /* Make sure we're done with the deferred traffic before flushing */
4768 flush_work(&mvm->add_stream_wk);
4770 mutex_lock(&mvm->mutex);
4771 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4773 /* flush the AP-station and all TDLS peers */
4774 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
4775 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4776 lockdep_is_held(&mvm->mutex));
4777 if (IS_ERR_OR_NULL(sta))
4780 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4781 if (mvmsta->vif != vif)
4784 /* make sure only TDLS peers or the AP are flushed */
4785 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4788 if (iwl_mvm_flush_sta(mvm, mvmsta, false))
4789 IWL_ERR(mvm, "flush request fail\n");
4791 msk |= mvmsta->tfd_queue_msk;
4792 if (iwl_mvm_has_new_tx_api(mvm))
4793 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4797 mutex_unlock(&mvm->mutex);
4799 /* this can take a while, and we may need/want other operations
4800 * to succeed while doing this, so do it without the mutex held
4802 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4803 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4806 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4807 struct survey_info *survey)
4809 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4812 memset(survey, 0, sizeof(*survey));
4814 /* only support global statistics right now */
4818 if (!fw_has_capa(&mvm->fw->ucode_capa,
4819 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4822 mutex_lock(&mvm->mutex);
4824 if (iwl_mvm_firmware_running(mvm)) {
4825 ret = iwl_mvm_request_statistics(mvm, false);
4830 survey->filled = SURVEY_INFO_TIME |
4831 SURVEY_INFO_TIME_RX |
4832 SURVEY_INFO_TIME_TX |
4833 SURVEY_INFO_TIME_SCAN;
4834 survey->time = mvm->accu_radio_stats.on_time_rf +
4835 mvm->radio_stats.on_time_rf;
4836 do_div(survey->time, USEC_PER_MSEC);
4838 survey->time_rx = mvm->accu_radio_stats.rx_time +
4839 mvm->radio_stats.rx_time;
4840 do_div(survey->time_rx, USEC_PER_MSEC);
4842 survey->time_tx = mvm->accu_radio_stats.tx_time +
4843 mvm->radio_stats.tx_time;
4844 do_div(survey->time_tx, USEC_PER_MSEC);
4846 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4847 mvm->radio_stats.on_time_scan;
4848 do_div(survey->time_scan, USEC_PER_MSEC);
4852 mutex_unlock(&mvm->mutex);
4856 static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo)
4858 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
4859 case RATE_MCS_CHAN_WIDTH_20:
4860 rinfo->bw = RATE_INFO_BW_20;
4862 case RATE_MCS_CHAN_WIDTH_40:
4863 rinfo->bw = RATE_INFO_BW_40;
4865 case RATE_MCS_CHAN_WIDTH_80:
4866 rinfo->bw = RATE_INFO_BW_80;
4868 case RATE_MCS_CHAN_WIDTH_160:
4869 rinfo->bw = RATE_INFO_BW_160;
4873 if (rate_n_flags & RATE_MCS_HT_MSK) {
4874 rinfo->flags |= RATE_INFO_FLAGS_MCS;
4875 rinfo->mcs = u32_get_bits(rate_n_flags, RATE_HT_MCS_INDEX_MSK);
4876 rinfo->nss = u32_get_bits(rate_n_flags,
4877 RATE_HT_MCS_NSS_MSK) + 1;
4878 if (rate_n_flags & RATE_MCS_SGI_MSK)
4879 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
4880 } else if (rate_n_flags & RATE_MCS_VHT_MSK) {
4881 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
4882 rinfo->mcs = u32_get_bits(rate_n_flags,
4883 RATE_VHT_MCS_RATE_CODE_MSK);
4884 rinfo->nss = u32_get_bits(rate_n_flags,
4885 RATE_VHT_MCS_NSS_MSK) + 1;
4886 if (rate_n_flags & RATE_MCS_SGI_MSK)
4887 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
4888 } else if (rate_n_flags & RATE_MCS_HE_MSK) {
4889 u32 gi_ltf = u32_get_bits(rate_n_flags,
4890 RATE_MCS_HE_GI_LTF_MSK);
4892 rinfo->flags |= RATE_INFO_FLAGS_HE_MCS;
4893 rinfo->mcs = u32_get_bits(rate_n_flags,
4894 RATE_VHT_MCS_RATE_CODE_MSK);
4895 rinfo->nss = u32_get_bits(rate_n_flags,
4896 RATE_VHT_MCS_NSS_MSK) + 1;
4898 if (rate_n_flags & RATE_MCS_HE_106T_MSK) {
4899 rinfo->bw = RATE_INFO_BW_HE_RU;
4900 rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106;
4903 switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) {
4904 case RATE_MCS_HE_TYPE_SU:
4905 case RATE_MCS_HE_TYPE_EXT_SU:
4906 if (gi_ltf == 0 || gi_ltf == 1)
4907 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
4908 else if (gi_ltf == 2)
4909 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
4910 else if (rate_n_flags & RATE_MCS_SGI_MSK)
4911 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
4913 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
4915 case RATE_MCS_HE_TYPE_MU:
4916 if (gi_ltf == 0 || gi_ltf == 1)
4917 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
4918 else if (gi_ltf == 2)
4919 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
4921 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
4923 case RATE_MCS_HE_TYPE_TRIG:
4924 if (gi_ltf == 0 || gi_ltf == 1)
4925 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
4927 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
4931 if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK)
4934 switch (u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK)) {
4935 case IWL_RATE_1M_PLCP:
4938 case IWL_RATE_2M_PLCP:
4941 case IWL_RATE_5M_PLCP:
4944 case IWL_RATE_11M_PLCP:
4945 rinfo->legacy = 110;
4947 case IWL_RATE_6M_PLCP:
4950 case IWL_RATE_9M_PLCP:
4953 case IWL_RATE_12M_PLCP:
4954 rinfo->legacy = 120;
4956 case IWL_RATE_18M_PLCP:
4957 rinfo->legacy = 180;
4959 case IWL_RATE_24M_PLCP:
4960 rinfo->legacy = 240;
4962 case IWL_RATE_36M_PLCP:
4963 rinfo->legacy = 360;
4965 case IWL_RATE_48M_PLCP:
4966 rinfo->legacy = 480;
4968 case IWL_RATE_54M_PLCP:
4969 rinfo->legacy = 540;
4975 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4976 struct ieee80211_vif *vif,
4977 struct ieee80211_sta *sta,
4978 struct station_info *sinfo)
4980 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4981 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4982 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4984 if (mvmsta->avg_energy) {
4985 sinfo->signal_avg = -(s8)mvmsta->avg_energy;
4986 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4989 if (iwl_mvm_has_tlc_offload(mvm)) {
4990 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
4992 iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate);
4993 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
4996 /* if beacon filtering isn't on mac80211 does it anyway */
4997 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
5000 if (!vif->bss_conf.assoc)
5003 mutex_lock(&mvm->mutex);
5005 if (mvmvif->ap_sta_id != mvmsta->sta_id)
5008 if (iwl_mvm_request_statistics(mvm, false))
5011 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
5012 mvmvif->beacon_stats.accu_num_beacons;
5013 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
5014 if (mvmvif->beacon_stats.avg_signal) {
5015 /* firmware only reports a value after RXing a few beacons */
5016 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
5017 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
5020 mutex_unlock(&mvm->mutex);
5023 static void iwl_mvm_event_mlme_callback_ini(struct iwl_mvm *mvm,
5024 struct ieee80211_vif *vif,
5025 const struct ieee80211_mlme_event *mlme)
5027 if (mlme->data == ASSOC_EVENT && (mlme->status == MLME_DENIED ||
5028 mlme->status == MLME_TIMEOUT)) {
5029 iwl_dbg_tlv_time_point(&mvm->fwrt,
5030 IWL_FW_INI_TIME_POINT_ASSOC_FAILED,
5035 if (mlme->data == AUTH_EVENT && (mlme->status == MLME_DENIED ||
5036 mlme->status == MLME_TIMEOUT)) {
5037 iwl_dbg_tlv_time_point(&mvm->fwrt,
5038 IWL_FW_INI_TIME_POINT_EAPOL_FAILED,
5043 if (mlme->data == DEAUTH_RX_EVENT || mlme->data == DEAUTH_TX_EVENT) {
5044 iwl_dbg_tlv_time_point(&mvm->fwrt,
5045 IWL_FW_INI_TIME_POINT_DEASSOC,
5051 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
5052 struct ieee80211_vif *vif,
5053 const struct ieee80211_event *event)
5055 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
5057 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
5059 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
5062 struct iwl_fw_dbg_trigger_tlv *trig;
5063 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
5065 if (iwl_trans_dbg_ini_valid(mvm->trans)) {
5066 iwl_mvm_event_mlme_callback_ini(mvm, vif, &event->u.mlme);
5070 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5071 FW_DBG_TRIGGER_MLME);
5075 trig_mlme = (void *)trig->data;
5077 if (event->u.mlme.data == ASSOC_EVENT) {
5078 if (event->u.mlme.status == MLME_DENIED)
5079 CHECK_MLME_TRIGGER(stop_assoc_denied,
5080 "DENIED ASSOC: reason %d",
5081 event->u.mlme.reason);
5082 else if (event->u.mlme.status == MLME_TIMEOUT)
5083 CHECK_MLME_TRIGGER(stop_assoc_timeout,
5085 } else if (event->u.mlme.data == AUTH_EVENT) {
5086 if (event->u.mlme.status == MLME_DENIED)
5087 CHECK_MLME_TRIGGER(stop_auth_denied,
5088 "DENIED AUTH: reason %d",
5089 event->u.mlme.reason);
5090 else if (event->u.mlme.status == MLME_TIMEOUT)
5091 CHECK_MLME_TRIGGER(stop_auth_timeout,
5093 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
5094 CHECK_MLME_TRIGGER(stop_rx_deauth,
5095 "DEAUTH RX %d", event->u.mlme.reason);
5096 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
5097 CHECK_MLME_TRIGGER(stop_tx_deauth,
5098 "DEAUTH TX %d", event->u.mlme.reason);
5100 #undef CHECK_MLME_TRIGGER
5103 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
5104 struct ieee80211_vif *vif,
5105 const struct ieee80211_event *event)
5107 struct iwl_fw_dbg_trigger_tlv *trig;
5108 struct iwl_fw_dbg_trigger_ba *ba_trig;
5110 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5115 ba_trig = (void *)trig->data;
5117 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
5120 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
5121 "BAR received from %pM, tid %d, ssn %d",
5122 event->u.ba.sta->addr, event->u.ba.tid,
5126 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
5127 struct ieee80211_vif *vif,
5128 const struct ieee80211_event *event)
5130 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5132 switch (event->type) {
5134 iwl_mvm_event_mlme_callback(mvm, vif, event);
5137 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
5139 case BA_FRAME_TIMEOUT:
5140 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
5148 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
5149 enum iwl_mvm_rxq_notif_type type,
5151 const void *data, u32 size)
5154 struct iwl_rxq_sync_cmd cmd;
5155 struct iwl_mvm_internal_rxq_notif notif;
5157 .cmd.rxq_mask = cpu_to_le32(BIT(mvm->trans->num_rx_queues) - 1),
5159 cpu_to_le32(sizeof(struct iwl_mvm_internal_rxq_notif) +
5164 struct iwl_host_cmd hcmd = {
5165 .id = WIDE_ID(DATA_PATH_GROUP, TRIGGER_RX_QUEUES_NOTIF_CMD),
5167 .len[0] = sizeof(cmd),
5170 .flags = sync ? 0 : CMD_ASYNC,
5174 /* size must be a multiple of DWORD */
5175 if (WARN_ON(cmd.cmd.count & cpu_to_le32(3)))
5178 if (!iwl_mvm_has_new_rx_api(mvm))
5182 cmd.notif.cookie = mvm->queue_sync_cookie;
5183 mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1;
5186 ret = iwl_mvm_send_cmd(mvm, &hcmd);
5188 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
5193 lockdep_assert_held(&mvm->mutex);
5194 ret = wait_event_timeout(mvm->rx_sync_waitq,
5195 READ_ONCE(mvm->queue_sync_state) == 0 ||
5196 iwl_mvm_is_radio_killed(mvm),
5198 WARN_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm),
5199 "queue sync: failed to sync, state is 0x%lx\n",
5200 mvm->queue_sync_state);
5205 mvm->queue_sync_state = 0;
5206 mvm->queue_sync_cookie++;
5210 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
5212 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5214 mutex_lock(&mvm->mutex);
5215 iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_EMPTY, true, NULL, 0);
5216 mutex_unlock(&mvm->mutex);
5220 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw,
5221 struct ieee80211_vif *vif,
5222 struct cfg80211_ftm_responder_stats *stats)
5224 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5225 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5227 if (vif->p2p || vif->type != NL80211_IFTYPE_AP ||
5228 !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder)
5231 mutex_lock(&mvm->mutex);
5232 *stats = mvm->ftm_resp_stats;
5233 mutex_unlock(&mvm->mutex);
5235 stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) |
5236 BIT(NL80211_FTM_STATS_PARTIAL_NUM) |
5237 BIT(NL80211_FTM_STATS_FAILED_NUM) |
5238 BIT(NL80211_FTM_STATS_ASAP_NUM) |
5239 BIT(NL80211_FTM_STATS_NON_ASAP_NUM) |
5240 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) |
5241 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) |
5242 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) |
5243 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM);
5248 static int iwl_mvm_start_pmsr(struct ieee80211_hw *hw,
5249 struct ieee80211_vif *vif,
5250 struct cfg80211_pmsr_request *request)
5252 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5255 mutex_lock(&mvm->mutex);
5256 ret = iwl_mvm_ftm_start(mvm, vif, request);
5257 mutex_unlock(&mvm->mutex);
5262 static void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw,
5263 struct ieee80211_vif *vif,
5264 struct cfg80211_pmsr_request *request)
5266 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5268 mutex_lock(&mvm->mutex);
5269 iwl_mvm_ftm_abort(mvm, request);
5270 mutex_unlock(&mvm->mutex);
5273 static bool iwl_mvm_can_hw_csum(struct sk_buff *skb)
5275 u8 protocol = ip_hdr(skb)->protocol;
5277 if (!IS_ENABLED(CONFIG_INET))
5280 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
5283 static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw,
5284 struct sk_buff *head,
5285 struct sk_buff *skb)
5287 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5289 /* For now don't aggregate IPv6 in AMSDU */
5290 if (skb->protocol != htons(ETH_P_IP))
5293 if (!iwl_mvm_is_csum_supported(mvm))
5296 return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head);
5299 const struct ieee80211_ops iwl_mvm_hw_ops = {
5300 .tx = iwl_mvm_mac_tx,
5301 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue,
5302 .ampdu_action = iwl_mvm_mac_ampdu_action,
5303 .get_antenna = iwl_mvm_op_get_antenna,
5304 .start = iwl_mvm_mac_start,
5305 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
5306 .stop = iwl_mvm_mac_stop,
5307 .add_interface = iwl_mvm_mac_add_interface,
5308 .remove_interface = iwl_mvm_mac_remove_interface,
5309 .config = iwl_mvm_mac_config,
5310 .prepare_multicast = iwl_mvm_prepare_multicast,
5311 .configure_filter = iwl_mvm_configure_filter,
5312 .config_iface_filter = iwl_mvm_config_iface_filter,
5313 .bss_info_changed = iwl_mvm_bss_info_changed,
5314 .hw_scan = iwl_mvm_mac_hw_scan,
5315 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
5316 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
5317 .sta_state = iwl_mvm_mac_sta_state,
5318 .sta_notify = iwl_mvm_mac_sta_notify,
5319 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
5320 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
5321 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
5322 .sta_rc_update = iwl_mvm_sta_rc_update,
5323 .conf_tx = iwl_mvm_mac_conf_tx,
5324 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
5325 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
5326 .flush = iwl_mvm_mac_flush,
5327 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
5328 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
5329 .set_key = iwl_mvm_mac_set_key,
5330 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
5331 .remain_on_channel = iwl_mvm_roc,
5332 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
5333 .add_chanctx = iwl_mvm_add_chanctx,
5334 .remove_chanctx = iwl_mvm_remove_chanctx,
5335 .change_chanctx = iwl_mvm_change_chanctx,
5336 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
5337 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
5338 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
5340 .start_ap = iwl_mvm_start_ap_ibss,
5341 .stop_ap = iwl_mvm_stop_ap_ibss,
5342 .join_ibss = iwl_mvm_start_ap_ibss,
5343 .leave_ibss = iwl_mvm_stop_ap_ibss,
5345 .tx_last_beacon = iwl_mvm_tx_last_beacon,
5347 .set_tim = iwl_mvm_set_tim,
5349 .channel_switch = iwl_mvm_channel_switch,
5350 .pre_channel_switch = iwl_mvm_pre_channel_switch,
5351 .post_channel_switch = iwl_mvm_post_channel_switch,
5352 .abort_channel_switch = iwl_mvm_abort_channel_switch,
5353 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon,
5355 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
5356 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
5357 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
5359 .event_callback = iwl_mvm_mac_event_callback,
5361 .sync_rx_queues = iwl_mvm_sync_rx_queues,
5363 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
5365 #ifdef CONFIG_PM_SLEEP
5367 .suspend = iwl_mvm_suspend,
5368 .resume = iwl_mvm_resume,
5369 .set_wakeup = iwl_mvm_set_wakeup,
5370 .set_rekey_data = iwl_mvm_set_rekey_data,
5371 #if IS_ENABLED(CONFIG_IPV6)
5372 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
5374 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
5376 .get_survey = iwl_mvm_mac_get_survey,
5377 .sta_statistics = iwl_mvm_mac_sta_statistics,
5378 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats,
5379 .start_pmsr = iwl_mvm_start_pmsr,
5380 .abort_pmsr = iwl_mvm_abort_pmsr,
5382 .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate,
5383 #ifdef CONFIG_IWLWIFI_DEBUGFS
5384 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,