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 rtnl_dereference(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_rtnl(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 ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS);
476 hw->wiphy->features |=
477 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR |
478 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR |
479 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
481 hw->sta_data_size = sizeof(struct iwl_mvm_sta);
482 hw->vif_data_size = sizeof(struct iwl_mvm_vif);
483 hw->chanctx_data_size = sizeof(u16);
484 hw->txq_data_size = sizeof(struct iwl_mvm_txq);
486 hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
487 BIT(NL80211_IFTYPE_P2P_CLIENT) |
488 BIT(NL80211_IFTYPE_AP) |
489 BIT(NL80211_IFTYPE_P2P_GO) |
490 BIT(NL80211_IFTYPE_P2P_DEVICE) |
491 BIT(NL80211_IFTYPE_ADHOC);
493 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
494 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
496 /* The new Tx API does not allow to pass the key or keyid of a MPDU to
497 * the hw, preventing us to control which key(id) to use per MPDU.
498 * Till that's fixed we can't use Extended Key ID for the newer cards.
500 if (!iwl_mvm_has_new_tx_api(mvm))
501 wiphy_ext_feature_set(hw->wiphy,
502 NL80211_EXT_FEATURE_EXT_KEY_ID);
503 hw->wiphy->features |= NL80211_FEATURE_HT_IBSS;
505 hw->wiphy->regulatory_flags |= REGULATORY_ENABLE_RELAX_NO_IR;
506 if (iwl_mvm_is_lar_supported(mvm))
507 hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
509 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG |
510 REGULATORY_DISABLE_BEACON_HINTS;
512 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
513 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
514 hw->wiphy->flags |= WIPHY_FLAG_SPLIT_SCAN_6GHZ;
516 hw->wiphy->iface_combinations = iwl_mvm_iface_combinations;
517 hw->wiphy->n_iface_combinations =
518 ARRAY_SIZE(iwl_mvm_iface_combinations);
520 hw->wiphy->max_remain_on_channel_duration = 10000;
521 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
523 /* Extract MAC address */
524 memcpy(mvm->addresses[0].addr, mvm->nvm_data->hw_addr, ETH_ALEN);
525 hw->wiphy->addresses = mvm->addresses;
526 hw->wiphy->n_addresses = 1;
528 /* Extract additional MAC addresses if available */
529 num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
530 min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
532 for (i = 1; i < num_mac; i++) {
533 memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
535 mvm->addresses[i].addr[5]++;
536 hw->wiphy->n_addresses++;
539 iwl_mvm_reset_phy_ctxts(mvm);
541 hw->wiphy->max_scan_ie_len = iwl_mvm_max_scan_ie_len(mvm);
543 hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
545 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK & IWL_MVM_SCAN_MASK);
546 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK) ||
547 IWL_MVM_MAX_LMAC_SCANS > HWEIGHT32(IWL_MVM_SCAN_MASK));
549 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN))
550 mvm->max_scans = IWL_MVM_MAX_UMAC_SCANS;
552 mvm->max_scans = IWL_MVM_MAX_LMAC_SCANS;
554 if (mvm->nvm_data->bands[NL80211_BAND_2GHZ].n_channels)
555 hw->wiphy->bands[NL80211_BAND_2GHZ] =
556 &mvm->nvm_data->bands[NL80211_BAND_2GHZ];
557 if (mvm->nvm_data->bands[NL80211_BAND_5GHZ].n_channels) {
558 hw->wiphy->bands[NL80211_BAND_5GHZ] =
559 &mvm->nvm_data->bands[NL80211_BAND_5GHZ];
561 if (fw_has_capa(&mvm->fw->ucode_capa,
562 IWL_UCODE_TLV_CAPA_BEAMFORMER) &&
563 fw_has_api(&mvm->fw->ucode_capa,
564 IWL_UCODE_TLV_API_LQ_SS_PARAMS))
565 hw->wiphy->bands[NL80211_BAND_5GHZ]->vht_cap.cap |=
566 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE;
568 if (fw_has_capa(&mvm->fw->ucode_capa,
569 IWL_UCODE_TLV_CAPA_PSC_CHAN_SUPPORT) &&
570 mvm->nvm_data->bands[NL80211_BAND_6GHZ].n_channels)
571 hw->wiphy->bands[NL80211_BAND_6GHZ] =
572 &mvm->nvm_data->bands[NL80211_BAND_6GHZ];
574 hw->wiphy->hw_version = mvm->trans->hw_id;
576 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
577 hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
579 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
581 hw->wiphy->max_sched_scan_reqs = 1;
582 hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
583 hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw);
584 /* we create the 802.11 header and zero length SSID IE. */
585 hw->wiphy->max_sched_scan_ie_len =
586 SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
587 hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
588 hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
591 * the firmware uses u8 for num of iterations, but 0xff is saved for
592 * infinite loop, so the maximum number of iterations is actually 254.
594 hw->wiphy->max_sched_scan_plan_iterations = 254;
596 hw->wiphy->features |= NL80211_FEATURE_P2P_GO_CTWIN |
597 NL80211_FEATURE_LOW_PRIORITY_SCAN |
598 NL80211_FEATURE_P2P_GO_OPPPS |
599 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
600 NL80211_FEATURE_DYNAMIC_SMPS |
601 NL80211_FEATURE_STATIC_SMPS |
602 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION;
604 if (fw_has_capa(&mvm->fw->ucode_capa,
605 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
606 hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION;
607 if (fw_has_capa(&mvm->fw->ucode_capa,
608 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
609 hw->wiphy->features |= NL80211_FEATURE_QUIET;
611 if (fw_has_capa(&mvm->fw->ucode_capa,
612 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
613 hw->wiphy->features |=
614 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
616 if (fw_has_capa(&mvm->fw->ucode_capa,
617 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
618 hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
620 if (iwl_fw_lookup_cmd_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP,
621 WOWLAN_KEK_KCK_MATERIAL,
622 IWL_FW_CMD_VER_UNKNOWN) == 3)
623 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK;
625 if (fw_has_api(&mvm->fw->ucode_capa,
626 IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
627 wiphy_ext_feature_set(hw->wiphy,
628 NL80211_EXT_FEATURE_SCAN_START_TIME);
629 wiphy_ext_feature_set(hw->wiphy,
630 NL80211_EXT_FEATURE_BSS_PARENT_TSF);
633 if (iwl_mvm_is_oce_supported(mvm)) {
634 wiphy_ext_feature_set(hw->wiphy,
635 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP);
636 wiphy_ext_feature_set(hw->wiphy,
637 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME);
638 wiphy_ext_feature_set(hw->wiphy,
639 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
640 wiphy_ext_feature_set(hw->wiphy,
641 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE);
644 if (mvm->nvm_data->sku_cap_11ax_enable &&
645 !iwlwifi_mod_params.disable_11ax) {
646 hw->wiphy->iftype_ext_capab = he_iftypes_ext_capa;
647 hw->wiphy->num_iftype_ext_capab =
648 ARRAY_SIZE(he_iftypes_ext_capa);
650 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
651 ieee80211_hw_set(hw, SUPPORTS_ONLY_HE_MULTI_BSSID);
654 mvm->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
656 #ifdef CONFIG_PM_SLEEP
657 if ((unified || mvm->fw->img[IWL_UCODE_WOWLAN].num_sec) &&
658 mvm->trans->ops->d3_suspend &&
659 mvm->trans->ops->d3_resume &&
660 device_can_wakeup(mvm->trans->dev)) {
661 mvm->wowlan.flags |= WIPHY_WOWLAN_MAGIC_PKT |
662 WIPHY_WOWLAN_DISCONNECT |
663 WIPHY_WOWLAN_EAP_IDENTITY_REQ |
664 WIPHY_WOWLAN_RFKILL_RELEASE |
665 WIPHY_WOWLAN_NET_DETECT;
666 mvm->wowlan.flags |= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
667 WIPHY_WOWLAN_GTK_REKEY_FAILURE |
668 WIPHY_WOWLAN_4WAY_HANDSHAKE;
670 mvm->wowlan.n_patterns = IWL_WOWLAN_MAX_PATTERNS;
671 mvm->wowlan.pattern_min_len = IWL_WOWLAN_MIN_PATTERN_LEN;
672 mvm->wowlan.pattern_max_len = IWL_WOWLAN_MAX_PATTERN_LEN;
673 mvm->wowlan.max_nd_match_sets =
674 iwl_umac_scan_get_max_profiles(mvm->fw);
675 hw->wiphy->wowlan = &mvm->wowlan;
679 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
680 /* assign default bcast filtering configuration */
681 mvm->bcast_filters = iwl_mvm_default_bcast_filters;
684 ret = iwl_mvm_leds_init(mvm);
688 if (fw_has_capa(&mvm->fw->ucode_capa,
689 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT)) {
690 IWL_DEBUG_TDLS(mvm, "TDLS supported\n");
691 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
692 ieee80211_hw_set(hw, TDLS_WIDER_BW);
695 if (fw_has_capa(&mvm->fw->ucode_capa,
696 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH)) {
697 IWL_DEBUG_TDLS(mvm, "TDLS channel switch supported\n");
698 hw->wiphy->features |= NL80211_FEATURE_TDLS_CHANNEL_SWITCH;
701 hw->netdev_features |= mvm->cfg->features;
702 if (!iwl_mvm_is_csum_supported(mvm))
703 hw->netdev_features &= ~(IWL_TX_CSUM_NETIF_FLAGS |
706 if (mvm->cfg->vht_mu_mimo_supported)
707 wiphy_ext_feature_set(hw->wiphy,
708 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER);
710 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_PROTECTED_TWT))
711 wiphy_ext_feature_set(hw->wiphy,
712 NL80211_EXT_FEATURE_PROTECTED_TWT);
714 hw->wiphy->available_antennas_tx = iwl_mvm_get_valid_tx_ant(mvm);
715 hw->wiphy->available_antennas_rx = iwl_mvm_get_valid_rx_ant(mvm);
717 ret = ieee80211_register_hw(mvm->hw);
719 iwl_mvm_leds_exit(mvm);
725 static void iwl_mvm_tx_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
726 struct ieee80211_sta *sta)
729 if (likely(iwl_mvm_tx_skb_sta(mvm, skb, sta) == 0))
732 if (likely(iwl_mvm_tx_skb_non_sta(mvm, skb) == 0))
736 ieee80211_free_txskb(mvm->hw, skb);
739 static void iwl_mvm_mac_tx(struct ieee80211_hw *hw,
740 struct ieee80211_tx_control *control,
743 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
744 struct ieee80211_sta *sta = control->sta;
745 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
746 struct ieee80211_hdr *hdr = (void *)skb->data;
747 bool offchannel = IEEE80211_SKB_CB(skb)->flags &
748 IEEE80211_TX_CTL_TX_OFFCHAN;
750 if (iwl_mvm_is_radio_killed(mvm)) {
751 IWL_DEBUG_DROP(mvm, "Dropping - RF/CT KILL\n");
756 !test_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status) &&
757 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status))
760 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
761 if ((info->control.vif->type == NL80211_IFTYPE_AP ||
762 info->control.vif->type == NL80211_IFTYPE_ADHOC) &&
763 ieee80211_is_mgmt(hdr->frame_control) &&
764 !ieee80211_is_bufferable_mmpdu(hdr->frame_control))
767 /* If there is no sta, and it's not offchannel - send through AP */
768 if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION &&
770 struct iwl_mvm_vif *mvmvif =
771 iwl_mvm_vif_from_mac80211(info->control.vif);
772 u8 ap_sta_id = READ_ONCE(mvmvif->ap_sta_id);
774 if (ap_sta_id < mvm->fw->ucode_capa.num_stations) {
775 /* mac80211 holds rcu read lock */
776 sta = rcu_dereference(mvm->fw_id_to_mac_id[ap_sta_id]);
777 if (IS_ERR_OR_NULL(sta))
782 iwl_mvm_tx_skb(mvm, skb, sta);
785 ieee80211_free_txskb(hw, skb);
788 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
790 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
791 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
792 struct sk_buff *skb = NULL;
795 * No need for threads to be pending here, they can leave the first
796 * taker all the work.
798 * mvmtxq->tx_request logic:
800 * If 0, no one is currently TXing, set to 1 to indicate current thread
801 * will now start TX and other threads should quit.
803 * If 1, another thread is currently TXing, set to 2 to indicate to
804 * that thread that there was another request. Since that request may
805 * have raced with the check whether the queue is empty, the TXing
806 * thread should check the queue's status one more time before leaving.
807 * This check is done in order to not leave any TX hanging in the queue
808 * until the next TX invocation (which may not even happen).
810 * If 2, another thread is currently TXing, and it will already double
811 * check the queue, so do nothing.
813 if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2))
818 while (likely(!mvmtxq->stopped &&
819 (mvm->trans->system_pm_mode ==
820 IWL_PLAT_PM_MODE_DISABLED))) {
821 skb = ieee80211_tx_dequeue(hw, txq);
826 "TXQ of sta %pM tid %d is now empty\n",
832 iwl_mvm_tx_skb(mvm, skb, txq->sta);
834 } while (atomic_dec_return(&mvmtxq->tx_request));
838 static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw,
839 struct ieee80211_txq *txq)
841 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
842 struct iwl_mvm_txq *mvmtxq = iwl_mvm_txq_from_mac80211(txq);
845 * Please note that racing is handled very carefully here:
846 * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is
847 * deleted afterwards.
848 * This means that if:
849 * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list):
850 * queue is allocated and we can TX.
851 * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list):
852 * a race, should defer the frame.
853 * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list):
854 * need to allocate the queue and defer the frame.
855 * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list):
856 * queue is already scheduled for allocation, no need to allocate,
857 * should defer the frame.
860 /* If the queue is allocated TX and return. */
861 if (!txq->sta || mvmtxq->txq_id != IWL_MVM_INVALID_QUEUE) {
863 * Check that list is empty to avoid a race where txq_id is
864 * already updated, but the queue allocation work wasn't
867 if (unlikely(txq->sta && !list_empty(&mvmtxq->list)))
870 iwl_mvm_mac_itxq_xmit(hw, txq);
874 /* The list is being deleted only after the queue is fully allocated. */
875 if (!list_empty(&mvmtxq->list))
878 list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs);
879 schedule_work(&mvm->add_stream_wk);
882 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
884 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
886 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
890 iwl_mvm_ampdu_check_trigger(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
891 struct ieee80211_sta *sta, u16 tid, u16 rx_ba_ssn,
892 enum ieee80211_ampdu_mlme_action action)
894 struct iwl_fw_dbg_trigger_tlv *trig;
895 struct iwl_fw_dbg_trigger_ba *ba_trig;
897 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
902 ba_trig = (void *)trig->data;
905 case IEEE80211_AMPDU_TX_OPERATIONAL: {
906 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
907 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
909 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_start, tid,
910 "TX AGG START: MAC %pM tid %d ssn %d\n",
911 sta->addr, tid, tid_data->ssn);
914 case IEEE80211_AMPDU_TX_STOP_CONT:
915 CHECK_BA_TRIGGER(mvm, trig, ba_trig->tx_ba_stop, tid,
916 "TX AGG STOP: MAC %pM tid %d\n",
919 case IEEE80211_AMPDU_RX_START:
920 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_start, tid,
921 "RX AGG START: MAC %pM tid %d ssn %d\n",
922 sta->addr, tid, rx_ba_ssn);
924 case IEEE80211_AMPDU_RX_STOP:
925 CHECK_BA_TRIGGER(mvm, trig, ba_trig->rx_ba_stop, tid,
926 "RX AGG STOP: MAC %pM tid %d\n",
934 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw *hw,
935 struct ieee80211_vif *vif,
936 struct ieee80211_ampdu_params *params)
938 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
940 struct ieee80211_sta *sta = params->sta;
941 enum ieee80211_ampdu_mlme_action action = params->action;
942 u16 tid = params->tid;
943 u16 *ssn = ¶ms->ssn;
944 u16 buf_size = params->buf_size;
945 bool amsdu = params->amsdu;
946 u16 timeout = params->timeout;
948 IWL_DEBUG_HT(mvm, "A-MPDU action on addr %pM tid %d: action %d\n",
949 sta->addr, tid, action);
951 if (!(mvm->nvm_data->sku_cap_11n_enable))
954 mutex_lock(&mvm->mutex);
957 case IEEE80211_AMPDU_RX_START:
958 if (iwl_mvm_vif_from_mac80211(vif)->ap_sta_id ==
959 iwl_mvm_sta_from_mac80211(sta)->sta_id) {
960 struct iwl_mvm_vif *mvmvif;
961 u16 macid = iwl_mvm_vif_from_mac80211(vif)->id;
962 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[macid];
964 mdata->opened_rx_ba_sessions = true;
965 mvmvif = iwl_mvm_vif_from_mac80211(vif);
966 cancel_delayed_work(&mvmvif->uapsd_nonagg_detected_wk);
968 if (!iwl_enable_rx_ampdu()) {
972 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, *ssn, true, buf_size,
975 case IEEE80211_AMPDU_RX_STOP:
976 ret = iwl_mvm_sta_rx_agg(mvm, sta, tid, 0, false, buf_size,
979 case IEEE80211_AMPDU_TX_START:
980 if (!iwl_enable_tx_ampdu()) {
984 ret = iwl_mvm_sta_tx_agg_start(mvm, vif, sta, tid, ssn);
986 case IEEE80211_AMPDU_TX_STOP_CONT:
987 ret = iwl_mvm_sta_tx_agg_stop(mvm, vif, sta, tid);
989 case IEEE80211_AMPDU_TX_STOP_FLUSH:
990 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
991 ret = iwl_mvm_sta_tx_agg_flush(mvm, vif, sta, tid);
993 case IEEE80211_AMPDU_TX_OPERATIONAL:
994 ret = iwl_mvm_sta_tx_agg_oper(mvm, vif, sta, tid,
1006 if (action == IEEE80211_AMPDU_RX_START)
1009 iwl_mvm_ampdu_check_trigger(mvm, vif, sta, tid,
1012 mutex_unlock(&mvm->mutex);
1017 static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,
1018 struct ieee80211_vif *vif)
1020 struct iwl_mvm *mvm = data;
1021 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1023 mvmvif->uploaded = false;
1024 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1026 spin_lock_bh(&mvm->time_event_lock);
1027 iwl_mvm_te_clear_data(mvm, &mvmvif->time_event_data);
1028 spin_unlock_bh(&mvm->time_event_lock);
1030 mvmvif->phy_ctxt = NULL;
1031 memset(&mvmvif->bf_data, 0, sizeof(mvmvif->bf_data));
1032 memset(&mvmvif->probe_resp_data, 0, sizeof(mvmvif->probe_resp_data));
1035 static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
1037 iwl_mvm_stop_device(mvm);
1041 mvm->scan_status = 0;
1042 mvm->ps_disabled = false;
1043 mvm->rfkill_safe_init_done = false;
1045 /* just in case one was running */
1046 iwl_mvm_cleanup_roc_te(mvm);
1047 ieee80211_remain_on_channel_expired(mvm->hw);
1049 iwl_mvm_ftm_restart(mvm);
1052 * cleanup all interfaces, even inactive ones, as some might have
1053 * gone down during the HW restart
1055 ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
1057 mvm->p2p_device_vif = NULL;
1059 iwl_mvm_reset_phy_ctxts(mvm);
1060 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
1061 memset(&mvm->last_bt_notif, 0, sizeof(mvm->last_bt_notif));
1062 memset(&mvm->last_bt_ci_cmd, 0, sizeof(mvm->last_bt_ci_cmd));
1064 ieee80211_wake_queues(mvm->hw);
1067 mvm->rx_ba_sessions = 0;
1068 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1069 mvm->monitor_on = false;
1071 /* keep statistics ticking */
1072 iwl_mvm_accu_radio_stats(mvm);
1075 int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
1079 lockdep_assert_held(&mvm->mutex);
1081 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) {
1083 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1084 * so later code will - from now on - see that we're doing it.
1086 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1087 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1088 /* Clean up some internal and mac80211 state on restart */
1089 iwl_mvm_restart_cleanup(mvm);
1091 ret = iwl_mvm_up(mvm);
1093 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_POST_INIT,
1095 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_PERIODIC,
1098 if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1099 /* Something went wrong - we need to finish some cleanup
1100 * that normally iwl_mvm_mac_restart_complete() below
1103 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1109 static int iwl_mvm_mac_start(struct ieee80211_hw *hw)
1111 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1114 mutex_lock(&mvm->mutex);
1115 ret = __iwl_mvm_mac_start(mvm);
1116 mutex_unlock(&mvm->mutex);
1121 static void iwl_mvm_restart_complete(struct iwl_mvm *mvm)
1125 mutex_lock(&mvm->mutex);
1127 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1129 ret = iwl_mvm_update_quotas(mvm, true, NULL);
1131 IWL_ERR(mvm, "Failed to update quotas after restart (%d)\n",
1134 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_END_OF_RECOVERY);
1137 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1138 * of packets the FW sent out, so we must reconnect.
1140 iwl_mvm_teardown_tdls_peers(mvm);
1142 mutex_unlock(&mvm->mutex);
1146 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw *hw,
1147 enum ieee80211_reconfig_type reconfig_type)
1149 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1151 switch (reconfig_type) {
1152 case IEEE80211_RECONFIG_TYPE_RESTART:
1153 iwl_mvm_restart_complete(mvm);
1155 case IEEE80211_RECONFIG_TYPE_SUSPEND:
1160 void __iwl_mvm_mac_stop(struct iwl_mvm *mvm)
1162 lockdep_assert_held(&mvm->mutex);
1164 iwl_mvm_ftm_initiator_smooth_stop(mvm);
1166 /* firmware counters are obviously reset now, but we shouldn't
1167 * partially track so also clear the fw_reset_accu counters.
1169 memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
1171 /* async_handlers_wk is now blocked */
1173 if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP, ADD_STA, 0) < 12)
1174 iwl_mvm_rm_aux_sta(mvm);
1176 iwl_mvm_stop_device(mvm);
1178 iwl_mvm_async_handlers_purge(mvm);
1179 /* async_handlers_list is empty and will stay empty: HW is stopped */
1182 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1183 * hw (as restart_complete() won't be called in this case) and mac80211
1184 * won't execute the restart.
1185 * But make sure to cleanup interfaces that have gone down before/during
1186 * HW restart was requested.
1188 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1189 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1191 ieee80211_iterate_interfaces(mvm->hw, 0,
1192 iwl_mvm_cleanup_iterator, mvm);
1194 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1195 * make sure there's nothing left there and warn if any is found.
1197 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1200 for (i = 0; i < mvm->max_scans; i++) {
1201 if (WARN_ONCE(mvm->scan_uid_status[i],
1202 "UMAC scan UID %d status was not cleaned\n",
1204 mvm->scan_uid_status[i] = 0;
1209 static void iwl_mvm_mac_stop(struct ieee80211_hw *hw)
1211 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1213 flush_work(&mvm->async_handlers_wk);
1214 flush_work(&mvm->add_stream_wk);
1217 * Lock and clear the firmware running bit here already, so that
1218 * new commands coming in elsewhere, e.g. from debugfs, will not
1219 * be able to proceed. This is important here because one of those
1220 * debugfs files causes the firmware dump to be triggered, and if we
1221 * don't stop debugfs accesses before canceling that it could be
1222 * retriggered after we flush it but before we've cleared the bit.
1224 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1226 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork);
1227 cancel_delayed_work_sync(&mvm->scan_timeout_dwork);
1230 * The work item could be running or queued if the
1231 * ROC time event stops just as we get here.
1233 flush_work(&mvm->roc_done_wk);
1235 mutex_lock(&mvm->mutex);
1236 __iwl_mvm_mac_stop(mvm);
1237 mutex_unlock(&mvm->mutex);
1240 * The worker might have been waiting for the mutex, let it run and
1241 * discover that its list is now empty.
1243 cancel_work_sync(&mvm->async_handlers_wk);
1246 static struct iwl_mvm_phy_ctxt *iwl_mvm_get_free_phy_ctxt(struct iwl_mvm *mvm)
1250 lockdep_assert_held(&mvm->mutex);
1252 for (i = 0; i < NUM_PHY_CTX; i++)
1253 if (!mvm->phy_ctxts[i].ref)
1254 return &mvm->phy_ctxts[i];
1256 IWL_ERR(mvm, "No available PHY context\n");
1260 static int iwl_mvm_set_tx_power(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1264 struct iwl_dev_tx_power_cmd cmd = {
1265 .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC),
1266 .common.mac_context_id =
1267 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif)->id),
1268 .common.pwr_restriction = cpu_to_le16(8 * tx_power),
1270 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
1271 REDUCE_TX_POWER_CMD,
1272 IWL_FW_CMD_VER_UNKNOWN);
1274 if (tx_power == IWL_DEFAULT_MAX_TX_POWER)
1275 cmd.common.pwr_restriction = cpu_to_le16(IWL_DEV_MAX_TX_POWER);
1278 len = sizeof(cmd.v6);
1279 else if (fw_has_api(&mvm->fw->ucode_capa,
1280 IWL_UCODE_TLV_API_REDUCE_TX_POWER))
1281 len = sizeof(cmd.v5);
1282 else if (fw_has_capa(&mvm->fw->ucode_capa,
1283 IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
1284 len = sizeof(cmd.v4);
1286 len = sizeof(cmd.v3);
1288 /* all structs have the same common part, add it */
1289 len += sizeof(cmd.common);
1291 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
1294 static int iwl_mvm_post_channel_switch(struct ieee80211_hw *hw,
1295 struct ieee80211_vif *vif)
1297 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1298 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1301 mutex_lock(&mvm->mutex);
1303 if (vif->type == NL80211_IFTYPE_STATION) {
1304 struct iwl_mvm_sta *mvmsta;
1306 mvmvif->csa_bcn_pending = false;
1307 mvmsta = iwl_mvm_sta_from_staid_protected(mvm,
1310 if (WARN_ON(!mvmsta)) {
1315 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, false);
1317 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1319 if (!fw_has_capa(&mvm->fw->ucode_capa,
1320 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
1321 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
1325 iwl_mvm_stop_session_protection(mvm, vif);
1329 mvmvif->ps_disabled = false;
1331 ret = iwl_mvm_power_update_ps(mvm);
1334 if (mvmvif->csa_failed)
1336 mutex_unlock(&mvm->mutex);
1341 static void iwl_mvm_abort_channel_switch(struct ieee80211_hw *hw,
1342 struct ieee80211_vif *vif)
1344 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1345 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1346 struct iwl_chan_switch_te_cmd cmd = {
1347 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
1349 .action = cpu_to_le32(FW_CTXT_ACTION_REMOVE),
1352 IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id);
1354 mutex_lock(&mvm->mutex);
1355 if (!fw_has_capa(&mvm->fw->ucode_capa,
1356 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
1357 iwl_mvm_remove_csa_period(mvm, vif);
1359 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
1360 WIDE_ID(MAC_CONF_GROUP,
1361 CHANNEL_SWITCH_TIME_EVENT_CMD),
1362 0, sizeof(cmd), &cmd));
1363 mvmvif->csa_failed = true;
1364 mutex_unlock(&mvm->mutex);
1366 iwl_mvm_post_channel_switch(hw, vif);
1369 static void iwl_mvm_channel_switch_disconnect_wk(struct work_struct *wk)
1371 struct iwl_mvm *mvm;
1372 struct iwl_mvm_vif *mvmvif;
1373 struct ieee80211_vif *vif;
1375 mvmvif = container_of(wk, struct iwl_mvm_vif, csa_work.work);
1376 vif = container_of((void *)mvmvif, struct ieee80211_vif, drv_priv);
1379 iwl_mvm_abort_channel_switch(mvm->hw, vif);
1380 ieee80211_chswitch_done(vif, false);
1383 static int iwl_mvm_mac_add_interface(struct ieee80211_hw *hw,
1384 struct ieee80211_vif *vif)
1386 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1387 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1391 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1394 * Not much to do here. The stack will not allow interface
1395 * types or combinations that we didn't advertise, so we
1396 * don't really have to check the types.
1399 mutex_lock(&mvm->mutex);
1401 /* make sure that beacon statistics don't go backwards with FW reset */
1402 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1403 mvmvif->beacon_stats.accu_num_beacons +=
1404 mvmvif->beacon_stats.num_beacons;
1406 /* Allocate resources for the MAC context, and add it to the fw */
1407 ret = iwl_mvm_mac_ctxt_init(mvm, vif);
1411 rcu_assign_pointer(mvm->vif_id_to_mac[mvmvif->id], vif);
1413 /* Counting number of interfaces is needed for legacy PM */
1414 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1418 * The AP binding flow can be done only after the beacon
1419 * template is configured (which happens only in the mac80211
1420 * start_ap() flow), and adding the broadcast station can happen
1421 * only after the binding.
1422 * In addition, since modifying the MAC before adding a bcast
1423 * station is not allowed by the FW, delay the adding of MAC context to
1424 * the point where we can also add the bcast station.
1425 * In short: there's not much we can do at this point, other than
1426 * allocating resources :)
1428 if (vif->type == NL80211_IFTYPE_AP ||
1429 vif->type == NL80211_IFTYPE_ADHOC) {
1430 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1432 IWL_ERR(mvm, "Failed to allocate bcast sta\n");
1437 * Only queue for this station is the mcast queue,
1438 * which shouldn't be in TFD mask anyway
1440 ret = iwl_mvm_allocate_int_sta(mvm, &mvmvif->mcast_sta,
1446 iwl_mvm_vif_dbgfs_register(mvm, vif);
1450 mvmvif->features |= hw->netdev_features;
1452 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
1456 ret = iwl_mvm_power_update_mac(mvm);
1458 goto out_remove_mac;
1460 /* beacon filtering */
1461 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
1463 goto out_remove_mac;
1465 if (!mvm->bf_allowed_vif &&
1466 vif->type == NL80211_IFTYPE_STATION && !vif->p2p) {
1467 mvm->bf_allowed_vif = mvmvif;
1468 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
1469 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
1473 * P2P_DEVICE interface does not have a channel context assigned to it,
1474 * so a dedicated PHY context is allocated to it and the corresponding
1475 * MAC context is bound to it at this stage.
1477 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1479 mvmvif->phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
1480 if (!mvmvif->phy_ctxt) {
1485 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
1486 ret = iwl_mvm_binding_add_vif(mvm, vif);
1490 ret = iwl_mvm_add_p2p_bcast_sta(mvm, vif);
1494 /* Save a pointer to p2p device vif, so it can later be used to
1495 * update the p2p device MAC when a GO is started/stopped */
1496 mvm->p2p_device_vif = vif;
1499 iwl_mvm_tcm_add_vif(mvm, vif);
1500 INIT_DELAYED_WORK(&mvmvif->csa_work,
1501 iwl_mvm_channel_switch_disconnect_wk);
1503 if (vif->type == NL80211_IFTYPE_MONITOR)
1504 mvm->monitor_on = true;
1506 iwl_mvm_vif_dbgfs_register(mvm, vif);
1510 iwl_mvm_binding_remove_vif(mvm, vif);
1512 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1514 if (mvm->bf_allowed_vif == mvmvif) {
1515 mvm->bf_allowed_vif = NULL;
1516 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1517 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1520 mvmvif->phy_ctxt = NULL;
1521 iwl_mvm_mac_ctxt_remove(mvm, vif);
1523 if (vif->type != NL80211_IFTYPE_P2P_DEVICE)
1526 mutex_unlock(&mvm->mutex);
1531 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm *mvm,
1532 struct ieee80211_vif *vif)
1534 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1536 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1537 * We assume here that all the packets sent to the OFFCHANNEL
1538 * queue are sent in ROC session.
1540 flush_work(&mvm->roc_done_wk);
1544 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw *hw,
1545 struct ieee80211_vif *vif)
1547 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1548 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1549 struct iwl_probe_resp_data *probe_data;
1551 iwl_mvm_prepare_mac_removal(mvm, vif);
1553 if (!(vif->type == NL80211_IFTYPE_AP ||
1554 vif->type == NL80211_IFTYPE_ADHOC))
1555 iwl_mvm_tcm_rm_vif(mvm, vif);
1557 mutex_lock(&mvm->mutex);
1559 probe_data = rcu_dereference_protected(mvmvif->probe_resp_data,
1560 lockdep_is_held(&mvm->mutex));
1561 RCU_INIT_POINTER(mvmvif->probe_resp_data, NULL);
1563 kfree_rcu(probe_data, rcu_head);
1565 if (mvm->bf_allowed_vif == mvmvif) {
1566 mvm->bf_allowed_vif = NULL;
1567 vif->driver_flags &= ~(IEEE80211_VIF_BEACON_FILTER |
1568 IEEE80211_VIF_SUPPORTS_CQM_RSSI);
1571 if (vif->bss_conf.ftm_responder)
1572 memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
1574 iwl_mvm_vif_dbgfs_clean(mvm, vif);
1577 * For AP/GO interface, the tear down of the resources allocated to the
1578 * interface is be handled as part of the stop_ap flow.
1580 if (vif->type == NL80211_IFTYPE_AP ||
1581 vif->type == NL80211_IFTYPE_ADHOC) {
1582 #ifdef CONFIG_NL80211_TESTMODE
1583 if (vif == mvm->noa_vif) {
1584 mvm->noa_vif = NULL;
1585 mvm->noa_duration = 0;
1588 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->mcast_sta);
1589 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1593 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1594 mvm->p2p_device_vif = NULL;
1595 iwl_mvm_rm_p2p_bcast_sta(mvm, vif);
1596 iwl_mvm_binding_remove_vif(mvm, vif);
1597 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
1598 mvmvif->phy_ctxt = NULL;
1601 if (mvm->vif_count && vif->type != NL80211_IFTYPE_P2P_DEVICE)
1604 iwl_mvm_power_update_mac(mvm);
1605 iwl_mvm_mac_ctxt_remove(mvm, vif);
1607 RCU_INIT_POINTER(mvm->vif_id_to_mac[mvmvif->id], NULL);
1609 if (vif->type == NL80211_IFTYPE_MONITOR)
1610 mvm->monitor_on = false;
1613 mutex_unlock(&mvm->mutex);
1616 static int iwl_mvm_mac_config(struct ieee80211_hw *hw, u32 changed)
1621 struct iwl_mvm_mc_iter_data {
1622 struct iwl_mvm *mvm;
1626 static void iwl_mvm_mc_iface_iterator(void *_data, u8 *mac,
1627 struct ieee80211_vif *vif)
1629 struct iwl_mvm_mc_iter_data *data = _data;
1630 struct iwl_mvm *mvm = data->mvm;
1631 struct iwl_mcast_filter_cmd *cmd = mvm->mcast_filter_cmd;
1632 struct iwl_host_cmd hcmd = {
1633 .id = MCAST_FILTER_CMD,
1635 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
1639 /* if we don't have free ports, mcast frames will be dropped */
1640 if (WARN_ON_ONCE(data->port_id >= MAX_PORT_ID_NUM))
1643 if (vif->type != NL80211_IFTYPE_STATION ||
1644 !vif->bss_conf.assoc)
1647 cmd->port_id = data->port_id++;
1648 memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
1649 len = roundup(sizeof(*cmd) + cmd->count * ETH_ALEN, 4);
1654 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1656 IWL_ERR(mvm, "mcast filter cmd error. ret=%d\n", ret);
1659 static void iwl_mvm_recalc_multicast(struct iwl_mvm *mvm)
1661 struct iwl_mvm_mc_iter_data iter_data = {
1665 lockdep_assert_held(&mvm->mutex);
1667 if (WARN_ON_ONCE(!mvm->mcast_filter_cmd))
1670 ieee80211_iterate_active_interfaces_atomic(
1671 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1672 iwl_mvm_mc_iface_iterator, &iter_data);
1675 static u64 iwl_mvm_prepare_multicast(struct ieee80211_hw *hw,
1676 struct netdev_hw_addr_list *mc_list)
1678 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1679 struct iwl_mcast_filter_cmd *cmd;
1680 struct netdev_hw_addr *addr;
1685 addr_count = netdev_hw_addr_list_count(mc_list);
1686 pass_all = addr_count > MAX_MCAST_FILTERING_ADDRESSES ||
1687 IWL_MVM_FW_MCAST_FILTER_PASS_ALL;
1691 len = roundup(sizeof(*cmd) + addr_count * ETH_ALEN, 4);
1692 cmd = kzalloc(len, GFP_ATOMIC);
1698 return (u64)(unsigned long)cmd;
1701 netdev_hw_addr_list_for_each(addr, mc_list) {
1702 IWL_DEBUG_MAC80211(mvm, "mcast addr (%d): %pM\n",
1703 cmd->count, addr->addr);
1704 memcpy(&cmd->addr_list[cmd->count * ETH_ALEN],
1705 addr->addr, ETH_ALEN);
1709 return (u64)(unsigned long)cmd;
1712 static void iwl_mvm_configure_filter(struct ieee80211_hw *hw,
1713 unsigned int changed_flags,
1714 unsigned int *total_flags,
1717 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1718 struct iwl_mcast_filter_cmd *cmd = (void *)(unsigned long)multicast;
1720 mutex_lock(&mvm->mutex);
1722 /* replace previous configuration */
1723 kfree(mvm->mcast_filter_cmd);
1724 mvm->mcast_filter_cmd = cmd;
1729 if (changed_flags & FIF_ALLMULTI)
1730 cmd->pass_all = !!(*total_flags & FIF_ALLMULTI);
1735 iwl_mvm_recalc_multicast(mvm);
1737 mutex_unlock(&mvm->mutex);
1741 static void iwl_mvm_config_iface_filter(struct ieee80211_hw *hw,
1742 struct ieee80211_vif *vif,
1743 unsigned int filter_flags,
1744 unsigned int changed_flags)
1746 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1748 /* We support only filter for probe requests */
1749 if (!(changed_flags & FIF_PROBE_REQ))
1752 /* Supported only for p2p client interfaces */
1753 if (vif->type != NL80211_IFTYPE_STATION || !vif->bss_conf.assoc ||
1757 mutex_lock(&mvm->mutex);
1758 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
1759 mutex_unlock(&mvm->mutex);
1762 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1763 struct iwl_bcast_iter_data {
1764 struct iwl_mvm *mvm;
1765 struct iwl_bcast_filter_cmd *cmd;
1770 iwl_mvm_set_bcast_filter(struct ieee80211_vif *vif,
1771 const struct iwl_fw_bcast_filter *in_filter,
1772 struct iwl_fw_bcast_filter *out_filter)
1774 struct iwl_fw_bcast_filter_attr *attr;
1777 memcpy(out_filter, in_filter, sizeof(*out_filter));
1779 for (i = 0; i < ARRAY_SIZE(out_filter->attrs); i++) {
1780 attr = &out_filter->attrs[i];
1785 switch (attr->reserved1) {
1786 case cpu_to_le16(BC_FILTER_MAGIC_IP):
1787 if (vif->bss_conf.arp_addr_cnt != 1) {
1792 attr->val = vif->bss_conf.arp_addr_list[0];
1794 case cpu_to_le16(BC_FILTER_MAGIC_MAC):
1795 attr->val = *(__be32 *)&vif->addr[2];
1800 attr->reserved1 = 0;
1801 out_filter->num_attrs++;
1805 static void iwl_mvm_bcast_filter_iterator(void *_data, u8 *mac,
1806 struct ieee80211_vif *vif)
1808 struct iwl_bcast_iter_data *data = _data;
1809 struct iwl_mvm *mvm = data->mvm;
1810 struct iwl_bcast_filter_cmd *cmd = data->cmd;
1811 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1812 struct iwl_fw_bcast_mac *bcast_mac;
1815 if (WARN_ON(mvmvif->id >= ARRAY_SIZE(cmd->macs)))
1818 bcast_mac = &cmd->macs[mvmvif->id];
1821 * enable filtering only for associated stations, but not for P2P
1824 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p ||
1825 !vif->bss_conf.assoc)
1828 bcast_mac->default_discard = 1;
1830 /* copy all configured filters */
1831 for (i = 0; mvm->bcast_filters[i].attrs[0].mask; i++) {
1833 * Make sure we don't exceed our filters limit.
1834 * if there is still a valid filter to be configured,
1835 * be on the safe side and just allow bcast for this mac.
1837 if (WARN_ON_ONCE(data->current_filter >=
1838 ARRAY_SIZE(cmd->filters))) {
1839 bcast_mac->default_discard = 0;
1840 bcast_mac->attached_filters = 0;
1844 iwl_mvm_set_bcast_filter(vif,
1845 &mvm->bcast_filters[i],
1846 &cmd->filters[data->current_filter]);
1848 /* skip current filter if it contains no attributes */
1849 if (!cmd->filters[data->current_filter].num_attrs)
1852 /* attach the filter to current mac */
1853 bcast_mac->attached_filters |=
1854 cpu_to_le16(BIT(data->current_filter));
1856 data->current_filter++;
1860 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm *mvm,
1861 struct iwl_bcast_filter_cmd *cmd)
1863 struct iwl_bcast_iter_data iter_data = {
1868 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL)
1871 memset(cmd, 0, sizeof(*cmd));
1872 cmd->max_bcast_filters = ARRAY_SIZE(cmd->filters);
1873 cmd->max_macs = ARRAY_SIZE(cmd->macs);
1875 #ifdef CONFIG_IWLWIFI_DEBUGFS
1876 /* use debugfs filters/macs if override is configured */
1877 if (mvm->dbgfs_bcast_filtering.override) {
1878 memcpy(cmd->filters, &mvm->dbgfs_bcast_filtering.cmd.filters,
1879 sizeof(cmd->filters));
1880 memcpy(cmd->macs, &mvm->dbgfs_bcast_filtering.cmd.macs,
1886 /* if no filters are configured, do nothing */
1887 if (!mvm->bcast_filters)
1890 /* configure and attach these filters for each associated sta vif */
1891 ieee80211_iterate_active_interfaces(
1892 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1893 iwl_mvm_bcast_filter_iterator, &iter_data);
1898 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1900 struct iwl_bcast_filter_cmd cmd;
1902 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BCAST_FILTERING))
1905 if (!iwl_mvm_bcast_filter_build_cmd(mvm, &cmd))
1908 return iwl_mvm_send_cmd_pdu(mvm, BCAST_FILTER_CMD, 0,
1912 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm *mvm)
1918 static int iwl_mvm_update_mu_groups(struct iwl_mvm *mvm,
1919 struct ieee80211_vif *vif)
1921 struct iwl_mu_group_mgmt_cmd cmd = {};
1923 memcpy(cmd.membership_status, vif->bss_conf.mu_group.membership,
1924 WLAN_MEMBERSHIP_LEN);
1925 memcpy(cmd.user_position, vif->bss_conf.mu_group.position,
1926 WLAN_USER_POSITION_LEN);
1928 return iwl_mvm_send_cmd_pdu(mvm,
1929 WIDE_ID(DATA_PATH_GROUP,
1930 UPDATE_MU_GROUPS_CMD),
1931 0, sizeof(cmd), &cmd);
1934 static void iwl_mvm_mu_mimo_iface_iterator(void *_data, u8 *mac,
1935 struct ieee80211_vif *vif)
1937 if (vif->mu_mimo_owner) {
1938 struct iwl_mu_group_mgmt_notif *notif = _data;
1941 * MU-MIMO Group Id action frame is little endian. We treat
1942 * the data received from firmware as if it came from the
1943 * action frame, so no conversion is needed.
1945 ieee80211_update_mu_groups(vif,
1946 (u8 *)¬if->membership_status,
1947 (u8 *)¬if->user_position);
1951 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm *mvm,
1952 struct iwl_rx_cmd_buffer *rxb)
1954 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1955 struct iwl_mu_group_mgmt_notif *notif = (void *)pkt->data;
1957 ieee80211_iterate_active_interfaces_atomic(
1958 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
1959 iwl_mvm_mu_mimo_iface_iterator, notif);
1962 static u8 iwl_mvm_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit)
1964 u8 byte_num = ppe_pos_bit / 8;
1965 u8 bit_num = ppe_pos_bit % 8;
1970 return (ppe[byte_num] >> bit_num) &
1971 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE) - 1);
1974 * If bit_num > 5, we have to combine bits with next byte.
1975 * Calculate how many bits we need to take from current byte (called
1976 * here "residue_bits"), and add them to bits from next byte.
1979 residue_bits = 8 - bit_num;
1981 res = (ppe[byte_num + 1] &
1982 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE - residue_bits) - 1)) <<
1984 res += (ppe[byte_num] >> bit_num) & (BIT(residue_bits) - 1);
1989 static void iwl_mvm_cfg_he_sta(struct iwl_mvm *mvm,
1990 struct ieee80211_vif *vif, u8 sta_id)
1992 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1993 struct iwl_he_sta_context_cmd sta_ctxt_cmd = {
1995 .tid_limit = IWL_MAX_TID_COUNT,
1996 .bss_color = vif->bss_conf.he_bss_color.color,
1997 .htc_trig_based_pkt_ext = vif->bss_conf.htc_trig_based_pkt_ext,
1998 .frame_time_rts_th =
1999 cpu_to_le16(vif->bss_conf.frame_time_rts_th),
2001 int size = fw_has_api(&mvm->fw->ucode_capa,
2002 IWL_UCODE_TLV_API_MBSSID_HE) ?
2003 sizeof(sta_ctxt_cmd) :
2004 sizeof(struct iwl_he_sta_context_cmd_v1);
2005 struct ieee80211_sta *sta;
2011 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]);
2012 if (IS_ERR_OR_NULL(sta)) {
2014 WARN(1, "Can't find STA to configure HE\n");
2018 if (!sta->he_cap.has_he) {
2025 /* Block 26-tone RU OFDMA transmissions */
2026 if (mvmvif->he_ru_2mhz_block)
2027 flags |= STA_CTXT_HE_RU_2MHZ_BLOCK;
2030 if (sta->he_cap.he_cap_elem.mac_cap_info[0] &
2031 IEEE80211_HE_MAC_CAP0_HTC_HE)
2032 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_SUPPORT);
2033 if ((sta->he_cap.he_cap_elem.mac_cap_info[1] &
2034 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION) ||
2035 (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2036 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION)) {
2038 ((sta->he_cap.he_cap_elem.mac_cap_info[2] &
2039 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION) << 1) +
2040 (sta->he_cap.he_cap_elem.mac_cap_info[1] &
2041 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION);
2044 sta_ctxt_cmd.htc_flags |=
2045 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED);
2046 else if (link_adap == 3)
2047 sta_ctxt_cmd.htc_flags |=
2048 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH);
2050 if (sta->he_cap.he_cap_elem.mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR)
2051 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BSR_SUPP);
2052 if (sta->he_cap.he_cap_elem.mac_cap_info[3] &
2053 IEEE80211_HE_MAC_CAP3_OMI_CONTROL)
2054 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_OMI_SUPP);
2055 if (sta->he_cap.he_cap_elem.mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR)
2056 sta_ctxt_cmd.htc_flags |= cpu_to_le32(IWL_HE_HTC_BQR_SUPP);
2059 * Initialize the PPE thresholds to "None" (7), as described in Table
2060 * 9-262ac of 80211.ax/D3.0.
2062 memset(&sta_ctxt_cmd.pkt_ext, 7, sizeof(sta_ctxt_cmd.pkt_ext));
2064 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2065 if (sta->he_cap.he_cap_elem.phy_cap_info[6] &
2066 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2067 u8 nss = (sta->he_cap.ppe_thres[0] &
2068 IEEE80211_PPE_THRES_NSS_MASK) + 1;
2069 u8 ru_index_bitmap =
2070 (sta->he_cap.ppe_thres[0] &
2071 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2072 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2073 u8 *ppe = &sta->he_cap.ppe_thres[0];
2074 u8 ppe_pos_bit = 7; /* Starting after PPE header */
2077 * FW currently supports only nss == MAX_HE_SUPP_NSS
2079 * If nss > MAX: we can ignore values we don't support
2080 * If nss < MAX: we can set zeros in other streams
2082 if (nss > MAX_HE_SUPP_NSS) {
2083 IWL_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
2085 nss = MAX_HE_SUPP_NSS;
2088 for (i = 0; i < nss; i++) {
2089 u8 ru_index_tmp = ru_index_bitmap << 1;
2092 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX; bw++) {
2094 if (!(ru_index_tmp & 1))
2097 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][1] =
2098 iwl_mvm_he_get_ppe_val(ppe,
2101 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2102 sta_ctxt_cmd.pkt_ext.pkt_ext_qam_th[i][bw][0] =
2103 iwl_mvm_he_get_ppe_val(ppe,
2106 IEEE80211_PPE_THRES_INFO_PPET_SIZE;
2110 flags |= STA_CTXT_HE_PACKET_EXT;
2111 } else if ((sta->he_cap.he_cap_elem.phy_cap_info[9] &
2112 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) !=
2113 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_RESERVED) {
2117 /* Take the PPE thresholds from the nominal padding info */
2118 switch (sta->he_cap.he_cap_elem.phy_cap_info[9] &
2119 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK) {
2120 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_0US:
2121 low_th = IWL_HE_PKT_EXT_NONE;
2122 high_th = IWL_HE_PKT_EXT_NONE;
2124 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_8US:
2125 low_th = IWL_HE_PKT_EXT_BPSK;
2126 high_th = IWL_HE_PKT_EXT_NONE;
2128 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US:
2129 low_th = IWL_HE_PKT_EXT_NONE;
2130 high_th = IWL_HE_PKT_EXT_BPSK;
2134 /* Set the PPE thresholds accordingly */
2135 if (low_th >= 0 && high_th >= 0) {
2136 struct iwl_he_pkt_ext *pkt_ext =
2137 (struct iwl_he_pkt_ext *)&sta_ctxt_cmd.pkt_ext;
2139 for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
2142 for (bw = 0; bw < MAX_HE_CHANNEL_BW_INDX;
2144 pkt_ext->pkt_ext_qam_th[i][bw][0] =
2146 pkt_ext->pkt_ext_qam_th[i][bw][1] =
2151 flags |= STA_CTXT_HE_PACKET_EXT;
2155 if (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2156 IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP)
2157 flags |= STA_CTXT_HE_32BIT_BA_BITMAP;
2159 if (sta->he_cap.he_cap_elem.mac_cap_info[2] &
2160 IEEE80211_HE_MAC_CAP2_ACK_EN)
2161 flags |= STA_CTXT_HE_ACK_ENABLED;
2165 /* Mark MU EDCA as enabled, unless none detected on some AC */
2166 flags |= STA_CTXT_HE_MU_EDCA_CW;
2167 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
2168 struct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
2169 &mvmvif->queue_params[i].mu_edca_param_rec;
2170 u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
2172 if (!mvmvif->queue_params[i].mu_edca) {
2173 flags &= ~STA_CTXT_HE_MU_EDCA_CW;
2177 sta_ctxt_cmd.trig_based_txf[ac].cwmin =
2178 cpu_to_le16(mu_edca->ecw_min_max & 0xf);
2179 sta_ctxt_cmd.trig_based_txf[ac].cwmax =
2180 cpu_to_le16((mu_edca->ecw_min_max & 0xf0) >> 4);
2181 sta_ctxt_cmd.trig_based_txf[ac].aifsn =
2182 cpu_to_le16(mu_edca->aifsn);
2183 sta_ctxt_cmd.trig_based_txf[ac].mu_time =
2184 cpu_to_le16(mu_edca->mu_edca_timer);
2188 if (vif->bss_conf.uora_exists) {
2189 flags |= STA_CTXT_HE_TRIG_RND_ALLOC;
2191 sta_ctxt_cmd.rand_alloc_ecwmin =
2192 vif->bss_conf.uora_ocw_range & 0x7;
2193 sta_ctxt_cmd.rand_alloc_ecwmax =
2194 (vif->bss_conf.uora_ocw_range >> 3) & 0x7;
2197 if (vif->bss_conf.nontransmitted) {
2198 flags |= STA_CTXT_HE_REF_BSSID_VALID;
2199 ether_addr_copy(sta_ctxt_cmd.ref_bssid_addr,
2200 vif->bss_conf.transmitter_bssid);
2201 sta_ctxt_cmd.max_bssid_indicator =
2202 vif->bss_conf.bssid_indicator;
2203 sta_ctxt_cmd.bssid_index = vif->bss_conf.bssid_index;
2204 sta_ctxt_cmd.ema_ap = vif->bss_conf.ema_ap;
2205 sta_ctxt_cmd.profile_periodicity =
2206 vif->bss_conf.profile_periodicity;
2209 sta_ctxt_cmd.flags = cpu_to_le32(flags);
2211 if (iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(STA_HE_CTXT_CMD,
2212 DATA_PATH_GROUP, 0),
2213 0, size, &sta_ctxt_cmd))
2214 IWL_ERR(mvm, "Failed to config FW to work HE!\n");
2217 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm *mvm,
2218 struct ieee80211_vif *vif,
2219 struct ieee80211_bss_conf *bss_conf,
2222 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2226 * Re-calculate the tsf id, as the leader-follower relations depend
2227 * on the beacon interval, which was not known when the station
2228 * interface was added.
2230 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
2231 if (vif->bss_conf.he_support &&
2232 !iwlwifi_mod_params.disable_11ax)
2233 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2235 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2238 /* Update MU EDCA params */
2239 if (changes & BSS_CHANGED_QOS && mvmvif->associated &&
2240 bss_conf->assoc && vif->bss_conf.he_support &&
2241 !iwlwifi_mod_params.disable_11ax)
2242 iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->ap_sta_id);
2245 * If we're not associated yet, take the (new) BSSID before associating
2246 * so the firmware knows. If we're already associated, then use the old
2247 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2248 * branch for disassociation below.
2250 if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
2251 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2253 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->bssid);
2255 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2257 /* after sending it once, adopt mac80211 data */
2258 memcpy(mvmvif->bssid, bss_conf->bssid, ETH_ALEN);
2259 mvmvif->associated = bss_conf->assoc;
2261 if (changes & BSS_CHANGED_ASSOC) {
2262 if (bss_conf->assoc) {
2263 /* clear statistics to get clean beacon counter */
2264 iwl_mvm_request_statistics(mvm, true);
2265 memset(&mvmvif->beacon_stats, 0,
2266 sizeof(mvmvif->beacon_stats));
2268 /* add quota for this interface */
2269 ret = iwl_mvm_update_quotas(mvm, true, NULL);
2271 IWL_ERR(mvm, "failed to update quotas\n");
2275 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2277 !fw_has_capa(&mvm->fw->ucode_capa,
2278 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) {
2280 * If we're restarting then the firmware will
2281 * obviously have lost synchronisation with
2282 * the AP. It will attempt to synchronise by
2283 * itself, but we can make it more reliable by
2284 * scheduling a session protection time event.
2286 * The firmware needs to receive a beacon to
2287 * catch up with synchronisation, use 110% of
2288 * the beacon interval.
2290 * Set a large maximum delay to allow for more
2291 * than a single interface.
2293 * For new firmware versions, rely on the
2294 * firmware. This is relevant for DCM scenarios
2297 u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
2298 iwl_mvm_protect_session(mvm, vif, dur, dur,
2302 iwl_mvm_sf_update(mvm, vif, false);
2303 iwl_mvm_power_vif_assoc(mvm, vif);
2305 iwl_mvm_update_smps(mvm, vif,
2306 IWL_MVM_SMPS_REQ_PROT,
2307 IEEE80211_SMPS_DYNAMIC);
2309 } else if (mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
2311 * If update fails - SF might be running in associated
2312 * mode while disassociated - which is forbidden.
2314 ret = iwl_mvm_sf_update(mvm, vif, false);
2316 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
2318 "Failed to update SF upon disassociation\n");
2321 * If we get an assert during the connection (after the
2322 * station has been added, but before the vif is set
2323 * to associated), mac80211 will re-add the station and
2324 * then configure the vif. Since the vif is not
2325 * associated, we would remove the station here and
2326 * this would fail the recovery.
2328 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
2331 * Remove AP station now that
2332 * the MAC is unassoc
2334 ret = iwl_mvm_rm_sta_id(mvm, vif,
2338 "failed to remove AP station\n");
2340 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
2343 /* remove quota for this interface */
2344 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2346 IWL_ERR(mvm, "failed to update quotas\n");
2348 /* this will take the cleared BSSID from bss_conf */
2349 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
2352 "failed to update MAC %pM (clear after unassoc)\n",
2357 * The firmware tracks the MU-MIMO group on its own.
2358 * However, on HW restart we should restore this data.
2360 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2361 (changes & BSS_CHANGED_MU_GROUPS) && vif->mu_mimo_owner) {
2362 ret = iwl_mvm_update_mu_groups(mvm, vif);
2365 "failed to update VHT MU_MIMO groups\n");
2368 iwl_mvm_recalc_multicast(mvm);
2369 iwl_mvm_configure_bcast_filter(mvm);
2371 /* reset rssi values */
2372 mvmvif->bf_data.ave_beacon_signal = 0;
2374 iwl_mvm_bt_coex_vif_change(mvm);
2375 iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_TT,
2376 IEEE80211_SMPS_AUTOMATIC);
2377 if (fw_has_capa(&mvm->fw->ucode_capa,
2378 IWL_UCODE_TLV_CAPA_UMAC_SCAN))
2379 iwl_mvm_config_scan(mvm);
2382 if (changes & BSS_CHANGED_BEACON_INFO) {
2384 * We received a beacon from the associated AP so
2385 * remove the session protection.
2386 * A firmware with the new API will remove it automatically.
2388 if (!fw_has_capa(&mvm->fw->ucode_capa,
2389 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD))
2390 iwl_mvm_stop_session_protection(mvm, vif);
2392 iwl_mvm_sf_update(mvm, vif, false);
2393 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
2396 if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS |
2398 * Send power command on every beacon change,
2399 * because we may have not enabled beacon abort yet.
2401 BSS_CHANGED_BEACON_INFO)) {
2402 ret = iwl_mvm_power_update_mac(mvm);
2404 IWL_ERR(mvm, "failed to update power mode\n");
2407 if (changes & BSS_CHANGED_TXPOWER) {
2408 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2410 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2413 if (changes & BSS_CHANGED_CQM) {
2414 IWL_DEBUG_MAC80211(mvm, "cqm info_changed\n");
2415 /* reset cqm events tracking */
2416 mvmvif->bf_data.last_cqm_event = 0;
2417 if (mvmvif->bf_data.bf_enabled) {
2418 ret = iwl_mvm_enable_beacon_filter(mvm, vif, 0);
2421 "failed to update CQM thresholds\n");
2425 if (changes & BSS_CHANGED_ARP_FILTER) {
2426 IWL_DEBUG_MAC80211(mvm, "arp filter changed\n");
2427 iwl_mvm_configure_bcast_filter(mvm);
2431 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw *hw,
2432 struct ieee80211_vif *vif)
2434 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2435 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2438 mutex_lock(&mvm->mutex);
2440 /* Send the beacon template */
2441 ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif);
2446 * Re-calculate the tsf id, as the leader-follower relations depend on
2447 * the beacon interval, which was not known when the AP interface
2450 if (vif->type == NL80211_IFTYPE_AP)
2451 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
2453 mvmvif->ap_assoc_sta_count = 0;
2455 /* Add the mac context */
2456 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
2460 /* Perform the binding */
2461 ret = iwl_mvm_binding_add_vif(mvm, vif);
2466 * This is not very nice, but the simplest:
2467 * For older FWs adding the mcast sta before the bcast station may
2468 * cause assert 0x2b00.
2469 * This is fixed in later FW so make the order of removal depend on
2472 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2473 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2477 * Send the bcast station. At this stage the TBTT and DTIM time
2478 * events are added and applied to the scheduler
2480 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2482 iwl_mvm_rm_mcast_sta(mvm, vif);
2487 * Send the bcast station. At this stage the TBTT and DTIM time
2488 * events are added and applied to the scheduler
2490 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2493 ret = iwl_mvm_add_mcast_sta(mvm, vif);
2495 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2500 /* must be set before quota calculations */
2501 mvmvif->ap_ibss_active = true;
2503 /* send all the early keys to the device now */
2504 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
2505 struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i];
2510 mvmvif->ap_early_keys[i] = NULL;
2512 ret = __iwl_mvm_mac_set_key(hw, SET_KEY, vif, NULL, key);
2514 goto out_quota_failed;
2517 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2518 iwl_mvm_vif_set_low_latency(mvmvif, true,
2519 LOW_LATENCY_VIF_TYPE);
2520 iwl_mvm_send_low_latency_cmd(mvm, true, mvmvif->id);
2523 /* power updated needs to be done before quotas */
2524 iwl_mvm_power_update_mac(mvm);
2526 ret = iwl_mvm_update_quotas(mvm, false, NULL);
2528 goto out_quota_failed;
2530 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2531 if (vif->p2p && mvm->p2p_device_vif)
2532 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2534 iwl_mvm_bt_coex_vif_change(mvm);
2536 /* we don't support TDLS during DCM */
2537 if (iwl_mvm_phy_ctx_count(mvm) > 1)
2538 iwl_mvm_teardown_tdls_peers(mvm);
2540 iwl_mvm_ftm_restart_responder(mvm, vif);
2545 iwl_mvm_power_update_mac(mvm);
2546 mvmvif->ap_ibss_active = false;
2547 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2548 iwl_mvm_rm_mcast_sta(mvm, vif);
2550 iwl_mvm_binding_remove_vif(mvm, vif);
2552 iwl_mvm_mac_ctxt_remove(mvm, vif);
2554 mutex_unlock(&mvm->mutex);
2558 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw *hw,
2559 struct ieee80211_vif *vif)
2561 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2562 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2564 iwl_mvm_prepare_mac_removal(mvm, vif);
2566 mutex_lock(&mvm->mutex);
2568 /* Handle AP stop while in CSA */
2569 if (rcu_access_pointer(mvm->csa_vif) == vif) {
2570 iwl_mvm_remove_time_event(mvm, mvmvif,
2571 &mvmvif->time_event_data);
2572 RCU_INIT_POINTER(mvm->csa_vif, NULL);
2573 mvmvif->csa_countdown = false;
2576 if (rcu_access_pointer(mvm->csa_tx_blocked_vif) == vif) {
2577 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2578 mvm->csa_tx_block_bcn_timeout = 0;
2581 mvmvif->ap_ibss_active = false;
2582 mvm->ap_last_beacon_gp2 = 0;
2584 if (vif->type == NL80211_IFTYPE_AP && !vif->p2p) {
2585 iwl_mvm_vif_set_low_latency(mvmvif, false,
2586 LOW_LATENCY_VIF_TYPE);
2587 iwl_mvm_send_low_latency_cmd(mvm, false, mvmvif->id);
2590 iwl_mvm_bt_coex_vif_change(mvm);
2592 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2593 if (vif->p2p && mvm->p2p_device_vif)
2594 iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
2596 iwl_mvm_update_quotas(mvm, false, NULL);
2598 iwl_mvm_ftm_responder_clear(mvm, vif);
2601 * This is not very nice, but the simplest:
2602 * For older FWs removing the mcast sta before the bcast station may
2603 * cause assert 0x2b00.
2604 * This is fixed in later FW (which will stop beaconing when removing
2606 * So make the order of removal depend on the TLV
2608 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2609 iwl_mvm_rm_mcast_sta(mvm, vif);
2610 iwl_mvm_send_rm_bcast_sta(mvm, vif);
2611 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
2612 iwl_mvm_rm_mcast_sta(mvm, vif);
2613 iwl_mvm_binding_remove_vif(mvm, vif);
2615 iwl_mvm_power_update_mac(mvm);
2617 iwl_mvm_mac_ctxt_remove(mvm, vif);
2619 mutex_unlock(&mvm->mutex);
2623 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm *mvm,
2624 struct ieee80211_vif *vif,
2625 struct ieee80211_bss_conf *bss_conf,
2628 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2630 /* Changes will be applied when the AP/IBSS is started */
2631 if (!mvmvif->ap_ibss_active)
2634 if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
2635 BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
2636 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
2637 IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
2639 /* Need to send a new beacon template to the FW */
2640 if (changes & BSS_CHANGED_BEACON &&
2641 iwl_mvm_mac_ctxt_beacon_changed(mvm, vif))
2642 IWL_WARN(mvm, "Failed updating beacon data\n");
2644 if (changes & BSS_CHANGED_TXPOWER) {
2645 IWL_DEBUG_CALIB(mvm, "Changing TX Power to %d\n",
2647 iwl_mvm_set_tx_power(mvm, vif, bss_conf->txpower);
2650 if (changes & BSS_CHANGED_FTM_RESPONDER) {
2651 int ret = iwl_mvm_ftm_start_responder(mvm, vif);
2654 IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
2660 static void iwl_mvm_bss_info_changed(struct ieee80211_hw *hw,
2661 struct ieee80211_vif *vif,
2662 struct ieee80211_bss_conf *bss_conf,
2665 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2667 mutex_lock(&mvm->mutex);
2669 if (changes & BSS_CHANGED_IDLE && !bss_conf->idle)
2670 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
2672 switch (vif->type) {
2673 case NL80211_IFTYPE_STATION:
2674 iwl_mvm_bss_info_changed_station(mvm, vif, bss_conf, changes);
2676 case NL80211_IFTYPE_AP:
2677 case NL80211_IFTYPE_ADHOC:
2678 iwl_mvm_bss_info_changed_ap_ibss(mvm, vif, bss_conf, changes);
2680 case NL80211_IFTYPE_MONITOR:
2681 if (changes & BSS_CHANGED_MU_GROUPS)
2682 iwl_mvm_update_mu_groups(mvm, vif);
2685 /* shouldn't happen */
2689 mutex_unlock(&mvm->mutex);
2692 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw *hw,
2693 struct ieee80211_vif *vif,
2694 struct ieee80211_scan_request *hw_req)
2696 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2699 if (hw_req->req.n_channels == 0 ||
2700 hw_req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
2703 mutex_lock(&mvm->mutex);
2704 ret = iwl_mvm_reg_scan_start(mvm, vif, &hw_req->req, &hw_req->ies);
2705 mutex_unlock(&mvm->mutex);
2710 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw *hw,
2711 struct ieee80211_vif *vif)
2713 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2715 mutex_lock(&mvm->mutex);
2717 /* Due to a race condition, it's possible that mac80211 asks
2718 * us to stop a hw_scan when it's already stopped. This can
2719 * happen, for instance, if we stopped the scan ourselves,
2720 * called ieee80211_scan_completed() and the userspace called
2721 * cancel scan scan before ieee80211_scan_work() could run.
2722 * To handle that, simply return if the scan is not running.
2724 if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
2725 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
2727 mutex_unlock(&mvm->mutex);
2731 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw *hw,
2732 struct ieee80211_sta *sta, u16 tids,
2734 enum ieee80211_frame_release_type reason,
2737 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2739 /* Called when we need to transmit (a) frame(s) from mac80211 */
2741 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2742 tids, more_data, false);
2746 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw *hw,
2747 struct ieee80211_sta *sta, u16 tids,
2749 enum ieee80211_frame_release_type reason,
2752 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2754 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2756 iwl_mvm_sta_modify_sleep_tx_count(mvm, sta, reason, num_frames,
2757 tids, more_data, true);
2760 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2761 enum sta_notify_cmd cmd,
2762 struct ieee80211_sta *sta)
2764 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2765 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2766 unsigned long txqs = 0, tids = 0;
2770 * If we have TVQM then we get too high queue numbers - luckily
2771 * we really shouldn't get here with that because such hardware
2772 * should have firmware supporting buffer station offload.
2774 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
2777 spin_lock_bh(&mvmsta->lock);
2778 for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) {
2779 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2781 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE)
2784 __set_bit(tid_data->txq_id, &txqs);
2786 if (iwl_mvm_tid_queued(mvm, tid_data) == 0)
2789 __set_bit(tid, &tids);
2793 case STA_NOTIFY_SLEEP:
2794 for_each_set_bit(tid, &tids, IWL_MAX_TID_COUNT)
2795 ieee80211_sta_set_buffered(sta, tid, true);
2798 iwl_trans_freeze_txq_timer(mvm->trans, txqs, true);
2800 * The fw updates the STA to be asleep. Tx packets on the Tx
2801 * queues to this station will not be transmitted. The fw will
2802 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2805 case STA_NOTIFY_AWAKE:
2806 if (WARN_ON(mvmsta->sta_id == IWL_MVM_INVALID_STA))
2810 iwl_trans_freeze_txq_timer(mvm->trans, txqs, false);
2811 iwl_mvm_sta_modify_ps_wake(mvm, sta);
2816 spin_unlock_bh(&mvmsta->lock);
2819 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw *hw,
2820 struct ieee80211_vif *vif,
2821 enum sta_notify_cmd cmd,
2822 struct ieee80211_sta *sta)
2824 __iwl_mvm_mac_sta_notify(hw, cmd, sta);
2827 void iwl_mvm_sta_pm_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
2829 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2830 struct iwl_mvm_pm_state_notification *notif = (void *)pkt->data;
2831 struct ieee80211_sta *sta;
2832 struct iwl_mvm_sta *mvmsta;
2833 bool sleeping = (notif->type != IWL_MVM_PM_EVENT_AWAKE);
2835 if (WARN_ON(notif->sta_id >= mvm->fw->ucode_capa.num_stations))
2839 sta = rcu_dereference(mvm->fw_id_to_mac_id[notif->sta_id]);
2840 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
2845 mvmsta = iwl_mvm_sta_from_mac80211(sta);
2848 mvmsta->vif->type != NL80211_IFTYPE_AP) {
2853 if (mvmsta->sleeping != sleeping) {
2854 mvmsta->sleeping = sleeping;
2855 __iwl_mvm_mac_sta_notify(mvm->hw,
2856 sleeping ? STA_NOTIFY_SLEEP : STA_NOTIFY_AWAKE,
2858 ieee80211_sta_ps_transition(sta, sleeping);
2862 switch (notif->type) {
2863 case IWL_MVM_PM_EVENT_AWAKE:
2864 case IWL_MVM_PM_EVENT_ASLEEP:
2866 case IWL_MVM_PM_EVENT_UAPSD:
2867 ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS);
2869 case IWL_MVM_PM_EVENT_PS_POLL:
2870 ieee80211_sta_pspoll(sta);
2880 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw *hw,
2881 struct ieee80211_vif *vif,
2882 struct ieee80211_sta *sta)
2884 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2885 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2888 * This is called before mac80211 does RCU synchronisation,
2889 * so here we already invalidate our internal RCU-protected
2890 * station pointer. The rest of the code will thus no longer
2891 * be able to find the station this way, and we don't rely
2892 * on further RCU synchronisation after the sta_state()
2893 * callback deleted the station.
2895 mutex_lock(&mvm->mutex);
2896 if (sta == rcu_access_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id]))
2897 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
2900 mutex_unlock(&mvm->mutex);
2903 static void iwl_mvm_check_uapsd(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2908 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2909 struct iwl_mvm_tcm_mac *mdata;
2911 mdata = &mvm->tcm.data[iwl_mvm_vif_from_mac80211(vif)->id];
2912 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
2913 mdata->opened_rx_ba_sessions = false;
2916 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT))
2919 if (vif->p2p && !iwl_mvm_is_p2p_scm_uapsd_supported(mvm)) {
2920 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2925 (iwlwifi_mod_params.uapsd_disable & IWL_DISABLE_UAPSD_BSS)) {
2926 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2930 for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) {
2931 if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
2932 vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
2937 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
2941 iwl_mvm_tdls_check_trigger(struct iwl_mvm *mvm,
2942 struct ieee80211_vif *vif, u8 *peer_addr,
2943 enum nl80211_tdls_operation action)
2945 struct iwl_fw_dbg_trigger_tlv *trig;
2946 struct iwl_fw_dbg_trigger_tdls *tdls_trig;
2948 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
2949 FW_DBG_TRIGGER_TDLS);
2953 tdls_trig = (void *)trig->data;
2955 if (!(tdls_trig->action_bitmap & BIT(action)))
2958 if (tdls_trig->peer_mode &&
2959 memcmp(tdls_trig->peer, peer_addr, ETH_ALEN) != 0)
2962 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2963 "TDLS event occurred, peer %pM, action %d",
2967 struct iwl_mvm_he_obss_narrow_bw_ru_data {
2971 static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy,
2972 struct cfg80211_bss *bss,
2975 struct iwl_mvm_he_obss_narrow_bw_ru_data *data = _data;
2976 const struct element *elem;
2978 elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY, bss->ies->data,
2981 if (!elem || elem->datalen < 10 ||
2983 WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) {
2984 data->tolerated = false;
2988 static void iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw,
2989 struct ieee80211_vif *vif)
2991 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2992 struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data = {
2996 if (!(vif->bss_conf.chandef.chan->flags & IEEE80211_CHAN_RADAR)) {
2997 mvmvif->he_ru_2mhz_block = false;
3001 cfg80211_bss_iter(hw->wiphy, &vif->bss_conf.chandef,
3002 iwl_mvm_check_he_obss_narrow_bw_ru_iter,
3006 * If there is at least one AP on radar channel that cannot
3007 * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
3009 mvmvif->he_ru_2mhz_block = !iter_data.tolerated;
3012 static int iwl_mvm_mac_sta_state(struct ieee80211_hw *hw,
3013 struct ieee80211_vif *vif,
3014 struct ieee80211_sta *sta,
3015 enum ieee80211_sta_state old_state,
3016 enum ieee80211_sta_state new_state)
3018 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3019 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3020 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3023 IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
3024 sta->addr, old_state, new_state);
3026 /* this would be a mac80211 bug ... but don't crash */
3027 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
3028 return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) ? 0 : -EINVAL;
3031 * If we are in a STA removal flow and in DQA mode:
3033 * This is after the sync_rcu part, so the queues have already been
3034 * flushed. No more TXs on their way in mac80211's path, and no more in
3036 * Also, we won't be getting any new TX frames for this station.
3037 * What we might have are deferred TX frames that need to be taken care
3040 * Drop any still-queued deferred-frame before removing the STA, and
3041 * make sure the worker is no longer handling frames for this STA.
3043 if (old_state == IEEE80211_STA_NONE &&
3044 new_state == IEEE80211_STA_NOTEXIST) {
3045 flush_work(&mvm->add_stream_wk);
3048 * No need to make sure deferred TX indication is off since the
3049 * worker will already remove it if it was on
3053 mutex_lock(&mvm->mutex);
3054 /* track whether or not the station is associated */
3055 mvm_sta->sta_state = new_state;
3057 if (old_state == IEEE80211_STA_NOTEXIST &&
3058 new_state == IEEE80211_STA_NONE) {
3060 * Firmware bug - it'll crash if the beacon interval is less
3061 * than 16. We can't avoid connecting at all, so refuse the
3062 * station state change, this will cause mac80211 to abandon
3063 * attempts to connect to this AP, and eventually wpa_s will
3064 * blocklist the AP...
3066 if (vif->type == NL80211_IFTYPE_STATION &&
3067 vif->bss_conf.beacon_int < 16) {
3069 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
3070 sta->addr, vif->bss_conf.beacon_int);
3075 if (vif->type == NL80211_IFTYPE_STATION)
3076 vif->bss_conf.he_support = sta->he_cap.has_he;
3080 iwl_mvm_tdls_sta_count(mvm, NULL) ==
3081 IWL_MVM_TDLS_STA_COUNT ||
3082 iwl_mvm_phy_ctx_count(mvm) > 1)) {
3083 IWL_DEBUG_MAC80211(mvm, "refusing TDLS sta\n");
3088 ret = iwl_mvm_add_sta(mvm, vif, sta);
3089 if (sta->tdls && ret == 0) {
3090 iwl_mvm_recalc_tdls_state(mvm, vif, true);
3091 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3092 NL80211_TDLS_SETUP);
3095 sta->max_rc_amsdu_len = 1;
3096 } else if (old_state == IEEE80211_STA_NONE &&
3097 new_state == IEEE80211_STA_AUTH) {
3099 * EBS may be disabled due to previous failures reported by FW.
3100 * Reset EBS status here assuming environment has been changed.
3102 mvm->last_ebs_successful = true;
3103 iwl_mvm_check_uapsd(mvm, vif, sta->addr);
3105 } else if (old_state == IEEE80211_STA_AUTH &&
3106 new_state == IEEE80211_STA_ASSOC) {
3107 if (vif->type == NL80211_IFTYPE_AP) {
3108 vif->bss_conf.he_support = sta->he_cap.has_he;
3109 mvmvif->ap_assoc_sta_count++;
3110 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3111 if (vif->bss_conf.he_support &&
3112 !iwlwifi_mod_params.disable_11ax)
3113 iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->sta_id);
3114 } else if (vif->type == NL80211_IFTYPE_STATION) {
3115 vif->bss_conf.he_support = sta->he_cap.has_he;
3117 mvmvif->he_ru_2mhz_block = false;
3118 if (sta->he_cap.has_he)
3119 iwl_mvm_check_he_obss_narrow_bw_ru(hw, vif);
3121 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3124 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3126 ret = iwl_mvm_update_sta(mvm, vif, sta);
3127 } else if (old_state == IEEE80211_STA_ASSOC &&
3128 new_state == IEEE80211_STA_AUTHORIZED) {
3131 /* we don't support TDLS during DCM */
3132 if (iwl_mvm_phy_ctx_count(mvm) > 1)
3133 iwl_mvm_teardown_tdls_peers(mvm);
3136 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3137 NL80211_TDLS_ENABLE_LINK);
3139 /* enable beacon filtering */
3140 WARN_ON(iwl_mvm_enable_beacon_filter(mvm, vif, 0));
3143 * Now that the station is authorized, i.e., keys were already
3144 * installed, need to indicate to the FW that
3145 * multicast data frames can be forwarded to the driver
3147 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3149 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3151 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
3152 new_state == IEEE80211_STA_ASSOC) {
3153 /* Multicast data frames are no longer allowed */
3154 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3156 /* disable beacon filtering */
3157 ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
3159 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3162 } else if (old_state == IEEE80211_STA_ASSOC &&
3163 new_state == IEEE80211_STA_AUTH) {
3164 if (vif->type == NL80211_IFTYPE_AP) {
3165 mvmvif->ap_assoc_sta_count--;
3166 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3169 } else if (old_state == IEEE80211_STA_AUTH &&
3170 new_state == IEEE80211_STA_NONE) {
3172 } else if (old_state == IEEE80211_STA_NONE &&
3173 new_state == IEEE80211_STA_NOTEXIST) {
3174 ret = iwl_mvm_rm_sta(mvm, vif, sta);
3176 iwl_mvm_recalc_tdls_state(mvm, vif, false);
3177 iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
3178 NL80211_TDLS_DISABLE_LINK);
3182 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
3189 mutex_unlock(&mvm->mutex);
3191 if (sta->tdls && ret == 0) {
3192 if (old_state == IEEE80211_STA_NOTEXIST &&
3193 new_state == IEEE80211_STA_NONE)
3194 ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3195 else if (old_state == IEEE80211_STA_NONE &&
3196 new_state == IEEE80211_STA_NOTEXIST)
3197 ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
3203 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3205 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3207 mvm->rts_threshold = value;
3212 static void iwl_mvm_sta_rc_update(struct ieee80211_hw *hw,
3213 struct ieee80211_vif *vif,
3214 struct ieee80211_sta *sta, u32 changed)
3216 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3217 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3219 if (changed & (IEEE80211_RC_BW_CHANGED |
3220 IEEE80211_RC_SUPP_RATES_CHANGED |
3221 IEEE80211_RC_NSS_CHANGED))
3222 iwl_mvm_rs_rate_init(mvm, sta, mvmvif->phy_ctxt->channel->band,
3225 if (vif->type == NL80211_IFTYPE_STATION &&
3226 changed & IEEE80211_RC_NSS_CHANGED)
3227 iwl_mvm_sf_update(mvm, vif, false);
3230 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw *hw,
3231 struct ieee80211_vif *vif, u16 ac,
3232 const struct ieee80211_tx_queue_params *params)
3234 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3235 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3237 mvmvif->queue_params[ac] = *params;
3240 * No need to update right away, we'll get BSS_CHANGED_QOS
3241 * The exception is P2P_DEVICE interface which needs immediate update.
3243 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
3246 mutex_lock(&mvm->mutex);
3247 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
3248 mutex_unlock(&mvm->mutex);
3254 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw *hw,
3255 struct ieee80211_vif *vif,
3258 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3259 u32 duration = IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS;
3260 u32 min_duration = IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS;
3262 if (req_duration > duration)
3263 duration = req_duration;
3265 mutex_lock(&mvm->mutex);
3266 /* Try really hard to protect the session and hear a beacon
3267 * The new session protection command allows us to protect the
3268 * session for a much longer time since the firmware will internally
3269 * create two events: a 300TU one with a very high priority that
3270 * won't be fragmented which should be enough for 99% of the cases,
3271 * and another one (which we configure here to be 900TU long) which
3272 * will have a slightly lower priority, but more importantly, can be
3273 * fragmented so that it'll allow other activities to run.
3275 if (fw_has_capa(&mvm->fw->ucode_capa,
3276 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD))
3277 iwl_mvm_schedule_session_protection(mvm, vif, 900,
3278 min_duration, false);
3280 iwl_mvm_protect_session(mvm, vif, duration,
3281 min_duration, 500, false);
3282 mutex_unlock(&mvm->mutex);
3285 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw *hw,
3286 struct ieee80211_vif *vif,
3287 struct cfg80211_sched_scan_request *req,
3288 struct ieee80211_scan_ies *ies)
3290 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3294 mutex_lock(&mvm->mutex);
3296 if (!vif->bss_conf.idle) {
3301 ret = iwl_mvm_sched_scan_start(mvm, vif, req, ies, IWL_MVM_SCAN_SCHED);
3304 mutex_unlock(&mvm->mutex);
3308 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw,
3309 struct ieee80211_vif *vif)
3311 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3314 mutex_lock(&mvm->mutex);
3316 /* Due to a race condition, it's possible that mac80211 asks
3317 * us to stop a sched_scan when it's already stopped. This
3318 * can happen, for instance, if we stopped the scan ourselves,
3319 * called ieee80211_sched_scan_stopped() and the userspace called
3320 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3321 * could run. To handle this, simply return if the scan is
3324 if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
3325 mutex_unlock(&mvm->mutex);
3329 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
3330 mutex_unlock(&mvm->mutex);
3331 iwl_mvm_wait_for_async_handlers(mvm);
3336 static int __iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3337 enum set_key_cmd cmd,
3338 struct ieee80211_vif *vif,
3339 struct ieee80211_sta *sta,
3340 struct ieee80211_key_conf *key)
3342 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3343 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3344 struct iwl_mvm_sta *mvmsta;
3345 struct iwl_mvm_key_pn *ptk_pn;
3346 int keyidx = key->keyidx;
3350 switch (key->cipher) {
3351 case WLAN_CIPHER_SUITE_TKIP:
3352 if (!mvm->trans->trans_cfg->gen2) {
3353 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3354 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3355 } else if (vif->type == NL80211_IFTYPE_STATION) {
3356 key->flags |= IEEE80211_KEY_FLAG_PUT_MIC_SPACE;
3358 IWL_DEBUG_MAC80211(mvm, "Use SW encryption for TKIP\n");
3362 case WLAN_CIPHER_SUITE_CCMP:
3363 case WLAN_CIPHER_SUITE_GCMP:
3364 case WLAN_CIPHER_SUITE_GCMP_256:
3365 if (!iwl_mvm_has_new_tx_api(mvm))
3366 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3368 case WLAN_CIPHER_SUITE_AES_CMAC:
3369 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3370 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3371 WARN_ON_ONCE(!ieee80211_hw_check(hw, MFP_CAPABLE));
3373 case WLAN_CIPHER_SUITE_WEP40:
3374 case WLAN_CIPHER_SUITE_WEP104:
3375 if (vif->type == NL80211_IFTYPE_STATION)
3377 if (iwl_mvm_has_new_tx_api(mvm))
3379 /* support HW crypto on TX */
3382 /* currently FW supports only one optional cipher scheme */
3383 if (hw->n_cipher_schemes &&
3384 hw->cipher_schemes->cipher == key->cipher)
3385 key->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3392 if ((vif->type == NL80211_IFTYPE_ADHOC ||
3393 vif->type == NL80211_IFTYPE_AP) && !sta) {
3395 * GTK on AP interface is a TX-only key, return 0;
3396 * on IBSS they're per-station and because we're lazy
3397 * we don't support them for RX, so do the same.
3398 * CMAC/GMAC in AP/IBSS modes must be done in software.
3400 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3401 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3402 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) {
3407 if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
3408 key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
3409 !iwl_mvm_has_new_tx_api(mvm)) {
3410 key->hw_key_idx = STA_KEY_IDX_INVALID;
3415 if (!mvmvif->ap_ibss_active) {
3417 i < ARRAY_SIZE(mvmvif->ap_early_keys);
3419 if (!mvmvif->ap_early_keys[i]) {
3420 mvmvif->ap_early_keys[i] = key;
3425 if (i >= ARRAY_SIZE(mvmvif->ap_early_keys))
3434 /* During FW restart, in order to restore the state as it was,
3435 * don't try to reprogram keys we previously failed for.
3437 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3438 key->hw_key_idx == STA_KEY_IDX_INVALID) {
3439 IWL_DEBUG_MAC80211(mvm,
3440 "skip invalid idx key programming during restart\n");
3445 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
3446 sta && iwl_mvm_has_new_rx_api(mvm) &&
3447 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3448 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3449 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3450 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3451 struct ieee80211_key_seq seq;
3454 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3455 WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
3456 ptk_pn = kzalloc(struct_size(ptk_pn, q,
3457 mvm->trans->num_rx_queues),
3464 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
3465 ieee80211_get_key_rx_seq(key, tid, &seq);
3466 for (q = 0; q < mvm->trans->num_rx_queues; q++)
3467 memcpy(ptk_pn->q[q].pn[tid],
3469 IEEE80211_CCMP_PN_LEN);
3472 rcu_assign_pointer(mvmsta->ptk_pn[keyidx], ptk_pn);
3475 /* in HW restart reuse the index, otherwise request a new one */
3476 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
3477 key_offset = key->hw_key_idx;
3479 key_offset = STA_KEY_IDX_INVALID;
3481 IWL_DEBUG_MAC80211(mvm, "set hwcrypto key\n");
3482 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
3484 IWL_WARN(mvm, "set key failed\n");
3485 key->hw_key_idx = STA_KEY_IDX_INVALID;
3487 * can't add key for RX, but we don't need it
3488 * in the device for TX so still return 0,
3489 * unless we have new TX API where we cannot
3490 * put key material into the TX_CMD
3492 if (iwl_mvm_has_new_tx_api(mvm))
3501 for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) {
3502 if (mvmvif->ap_early_keys[i] == key) {
3503 mvmvif->ap_early_keys[i] = NULL;
3508 /* found in pending list - don't do anything else */
3512 if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
3517 if (sta && iwl_mvm_has_new_rx_api(mvm) &&
3518 key->flags & IEEE80211_KEY_FLAG_PAIRWISE &&
3519 (key->cipher == WLAN_CIPHER_SUITE_CCMP ||
3520 key->cipher == WLAN_CIPHER_SUITE_GCMP ||
3521 key->cipher == WLAN_CIPHER_SUITE_GCMP_256)) {
3522 mvmsta = iwl_mvm_sta_from_mac80211(sta);
3523 ptk_pn = rcu_dereference_protected(
3524 mvmsta->ptk_pn[keyidx],
3525 lockdep_is_held(&mvm->mutex));
3526 RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
3528 kfree_rcu(ptk_pn, rcu_head);
3531 IWL_DEBUG_MAC80211(mvm, "disable hwcrypto key\n");
3532 ret = iwl_mvm_remove_sta_key(mvm, vif, sta, key);
3541 static int iwl_mvm_mac_set_key(struct ieee80211_hw *hw,
3542 enum set_key_cmd cmd,
3543 struct ieee80211_vif *vif,
3544 struct ieee80211_sta *sta,
3545 struct ieee80211_key_conf *key)
3547 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3550 mutex_lock(&mvm->mutex);
3551 ret = __iwl_mvm_mac_set_key(hw, cmd, vif, sta, key);
3552 mutex_unlock(&mvm->mutex);
3557 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw *hw,
3558 struct ieee80211_vif *vif,
3559 struct ieee80211_key_conf *keyconf,
3560 struct ieee80211_sta *sta,
3561 u32 iv32, u16 *phase1key)
3563 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3565 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
3568 iwl_mvm_update_tkip_key(mvm, vif, keyconf, sta, iv32, phase1key);
3572 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data *notif_wait,
3573 struct iwl_rx_packet *pkt, void *data)
3575 struct iwl_mvm *mvm =
3576 container_of(notif_wait, struct iwl_mvm, notif_wait);
3577 struct iwl_hs20_roc_res *resp;
3578 int resp_len = iwl_rx_packet_payload_len(pkt);
3579 struct iwl_mvm_time_event_data *te_data = data;
3581 if (WARN_ON(pkt->hdr.cmd != HOT_SPOT_CMD))
3584 if (WARN_ON_ONCE(resp_len != sizeof(*resp))) {
3585 IWL_ERR(mvm, "Invalid HOT_SPOT_CMD response\n");
3589 resp = (void *)pkt->data;
3592 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
3593 resp->status, resp->event_unique_id);
3595 te_data->uid = le32_to_cpu(resp->event_unique_id);
3596 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
3599 spin_lock_bh(&mvm->time_event_lock);
3600 list_add_tail(&te_data->list, &mvm->aux_roc_te_list);
3601 spin_unlock_bh(&mvm->time_event_lock);
3606 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3607 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3608 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3609 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3610 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3611 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm *mvm,
3612 struct ieee80211_channel *channel,
3613 struct ieee80211_vif *vif,
3617 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3618 struct iwl_mvm_time_event_data *te_data = &mvmvif->hs_time_event_data;
3619 static const u16 time_event_response[] = { HOT_SPOT_CMD };
3620 struct iwl_notification_wait wait_time_event;
3621 u32 dtim_interval = vif->bss_conf.dtim_period *
3622 vif->bss_conf.beacon_int;
3624 struct iwl_hs20_roc_req aux_roc_req = {
3625 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
3627 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX, 0)),
3628 .sta_id_and_color = cpu_to_le32(mvm->aux_sta.sta_id),
3630 struct iwl_hs20_roc_req_tail *tail = iwl_mvm_chan_info_cmd_tail(mvm,
3631 &aux_roc_req.channel_info);
3632 u16 len = sizeof(aux_roc_req) - iwl_mvm_chan_info_padding(mvm);
3634 /* Set the channel info data */
3635 iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value,
3636 iwl_mvm_phy_band_from_nl80211(channel->band),
3637 PHY_VHT_CHANNEL_MODE20,
3640 /* Set the time and duration */
3641 tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm));
3643 delay = AUX_ROC_MIN_DELAY;
3644 req_dur = MSEC_TO_TU(duration);
3647 * If we are associated we want the delay time to be at least one
3648 * dtim interval so that the FW can wait until after the DTIM and
3649 * then start the time event, this will potentially allow us to
3650 * remain off-channel for the max duration.
3651 * Since we want to use almost a whole dtim interval we would also
3652 * like the delay to be for 2-3 dtim intervals, in case there are
3653 * other time events with higher priority.
3655 if (vif->bss_conf.assoc) {
3656 delay = min_t(u32, dtim_interval * 3, AUX_ROC_MAX_DELAY);
3657 /* We cannot remain off-channel longer than the DTIM interval */
3658 if (dtim_interval <= req_dur) {
3659 req_dur = dtim_interval - AUX_ROC_SAFETY_BUFFER;
3660 if (req_dur <= AUX_ROC_MIN_DURATION)
3661 req_dur = dtim_interval -
3662 AUX_ROC_MIN_SAFETY_BUFFER;
3666 tail->duration = cpu_to_le32(req_dur);
3667 tail->apply_time_max_delay = cpu_to_le32(delay);
3670 "ROC: Requesting to remain on channel %u for %ums\n",
3671 channel->hw_value, req_dur);
3673 "\t(requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3674 duration, delay, dtim_interval);
3676 /* Set the node address */
3677 memcpy(tail->node_addr, vif->addr, ETH_ALEN);
3679 lockdep_assert_held(&mvm->mutex);
3681 spin_lock_bh(&mvm->time_event_lock);
3683 if (WARN_ON(te_data->id == HOT_SPOT_CMD)) {
3684 spin_unlock_bh(&mvm->time_event_lock);
3689 te_data->duration = duration;
3690 te_data->id = HOT_SPOT_CMD;
3692 spin_unlock_bh(&mvm->time_event_lock);
3695 * Use a notification wait, which really just processes the
3696 * command response and doesn't wait for anything, in order
3697 * to be able to process the response and get the UID inside
3698 * the RX path. Using CMD_WANT_SKB doesn't work because it
3699 * stores the buffer and then wakes up this thread, by which
3700 * time another notification (that the time event started)
3701 * might already be processed unsuccessfully.
3703 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
3704 time_event_response,
3705 ARRAY_SIZE(time_event_response),
3706 iwl_mvm_rx_aux_roc, te_data);
3708 res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len,
3712 IWL_ERR(mvm, "Couldn't send HOT_SPOT_CMD: %d\n", res);
3713 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
3717 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3718 res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
3719 /* should never fail */
3724 spin_lock_bh(&mvm->time_event_lock);
3725 iwl_mvm_te_clear_data(mvm, te_data);
3726 spin_unlock_bh(&mvm->time_event_lock);
3732 static int iwl_mvm_roc(struct ieee80211_hw *hw,
3733 struct ieee80211_vif *vif,
3734 struct ieee80211_channel *channel,
3736 enum ieee80211_roc_type type)
3738 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3739 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3740 struct cfg80211_chan_def chandef;
3741 struct iwl_mvm_phy_ctxt *phy_ctxt;
3744 IWL_DEBUG_MAC80211(mvm, "enter (%d, %d, %d)\n", channel->hw_value,
3748 * Flush the done work, just in case it's still pending, so that
3749 * the work it does can complete and we can accept new frames.
3751 flush_work(&mvm->roc_done_wk);
3753 mutex_lock(&mvm->mutex);
3755 switch (vif->type) {
3756 case NL80211_IFTYPE_STATION:
3757 if (fw_has_capa(&mvm->fw->ucode_capa,
3758 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
3759 /* Use aux roc framework (HS20) */
3760 if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
3761 ADD_STA, 0) >= 12) {
3764 lmac_id = iwl_mvm_get_lmac_id(mvm->fw,
3766 ret = iwl_mvm_add_aux_sta(mvm, lmac_id);
3768 "Failed to allocate aux station"))
3771 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
3775 IWL_ERR(mvm, "hotspot not supported\n");
3778 case NL80211_IFTYPE_P2P_DEVICE:
3782 IWL_ERR(mvm, "vif isn't P2P_DEVICE: %d\n", vif->type);
3787 for (i = 0; i < NUM_PHY_CTX; i++) {
3788 phy_ctxt = &mvm->phy_ctxts[i];
3789 if (phy_ctxt->ref == 0 || mvmvif->phy_ctxt == phy_ctxt)
3792 if (phy_ctxt->ref && channel == phy_ctxt->channel) {
3794 * Unbind the P2P_DEVICE from the current PHY context,
3795 * and if the PHY context is not used remove it.
3797 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3798 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3801 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3803 /* Bind the P2P_DEVICE to the current PHY Context */
3804 mvmvif->phy_ctxt = phy_ctxt;
3806 ret = iwl_mvm_binding_add_vif(mvm, vif);
3807 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3810 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3811 goto schedule_time_event;
3815 /* Need to update the PHY context only if the ROC channel changed */
3816 if (channel == mvmvif->phy_ctxt->channel)
3817 goto schedule_time_event;
3819 cfg80211_chandef_create(&chandef, channel, NL80211_CHAN_NO_HT);
3822 * Change the PHY context configuration as it is currently referenced
3823 * only by the P2P Device MAC
3825 if (mvmvif->phy_ctxt->ref == 1) {
3826 ret = iwl_mvm_phy_ctxt_changed(mvm, mvmvif->phy_ctxt,
3832 * The PHY context is shared with other MACs. Need to remove the
3833 * P2P Device from the binding, allocate an new PHY context and
3834 * create a new binding
3836 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3842 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, &chandef,
3845 IWL_ERR(mvm, "Failed to change PHY context\n");
3849 /* Unbind the P2P_DEVICE from the current PHY context */
3850 ret = iwl_mvm_binding_remove_vif(mvm, vif);
3851 if (WARN(ret, "Failed unbinding P2P_DEVICE\n"))
3854 iwl_mvm_phy_ctxt_unref(mvm, mvmvif->phy_ctxt);
3856 /* Bind the P2P_DEVICE to the new allocated PHY context */
3857 mvmvif->phy_ctxt = phy_ctxt;
3859 ret = iwl_mvm_binding_add_vif(mvm, vif);
3860 if (WARN(ret, "Failed binding P2P_DEVICE\n"))
3863 iwl_mvm_phy_ctxt_ref(mvm, mvmvif->phy_ctxt);
3866 schedule_time_event:
3867 /* Schedule the time events */
3868 ret = iwl_mvm_start_p2p_roc(mvm, vif, duration, type);
3871 mutex_unlock(&mvm->mutex);
3872 IWL_DEBUG_MAC80211(mvm, "leave\n");
3876 static int iwl_mvm_cancel_roc(struct ieee80211_hw *hw,
3877 struct ieee80211_vif *vif)
3879 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3881 IWL_DEBUG_MAC80211(mvm, "enter\n");
3883 mutex_lock(&mvm->mutex);
3884 iwl_mvm_stop_roc(mvm, vif);
3885 mutex_unlock(&mvm->mutex);
3887 IWL_DEBUG_MAC80211(mvm, "leave\n");
3891 struct iwl_mvm_ftm_responder_iter_data {
3893 struct ieee80211_chanctx_conf *ctx;
3896 static void iwl_mvm_ftm_responder_chanctx_iter(void *_data, u8 *mac,
3897 struct ieee80211_vif *vif)
3899 struct iwl_mvm_ftm_responder_iter_data *data = _data;
3901 if (rcu_access_pointer(vif->chanctx_conf) == data->ctx &&
3902 vif->type == NL80211_IFTYPE_AP && vif->bss_conf.ftmr_params)
3903 data->responder = true;
3906 static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm *mvm,
3907 struct ieee80211_chanctx_conf *ctx)
3909 struct iwl_mvm_ftm_responder_iter_data data = {
3914 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
3915 IEEE80211_IFACE_ITER_NORMAL,
3916 iwl_mvm_ftm_responder_chanctx_iter,
3918 return data.responder;
3921 static int __iwl_mvm_add_chanctx(struct iwl_mvm *mvm,
3922 struct ieee80211_chanctx_conf *ctx)
3924 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3925 struct iwl_mvm_phy_ctxt *phy_ctxt;
3926 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
3927 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
3930 lockdep_assert_held(&mvm->mutex);
3932 IWL_DEBUG_MAC80211(mvm, "Add channel context\n");
3934 phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm);
3940 ret = iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
3941 ctx->rx_chains_static,
3942 ctx->rx_chains_dynamic);
3944 IWL_ERR(mvm, "Failed to add PHY context\n");
3948 iwl_mvm_phy_ctxt_ref(mvm, phy_ctxt);
3949 *phy_ctxt_id = phy_ctxt->id;
3954 static int iwl_mvm_add_chanctx(struct ieee80211_hw *hw,
3955 struct ieee80211_chanctx_conf *ctx)
3957 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3960 mutex_lock(&mvm->mutex);
3961 ret = __iwl_mvm_add_chanctx(mvm, ctx);
3962 mutex_unlock(&mvm->mutex);
3967 static void __iwl_mvm_remove_chanctx(struct iwl_mvm *mvm,
3968 struct ieee80211_chanctx_conf *ctx)
3970 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3971 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3973 lockdep_assert_held(&mvm->mutex);
3975 iwl_mvm_phy_ctxt_unref(mvm, phy_ctxt);
3978 static void iwl_mvm_remove_chanctx(struct ieee80211_hw *hw,
3979 struct ieee80211_chanctx_conf *ctx)
3981 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3983 mutex_lock(&mvm->mutex);
3984 __iwl_mvm_remove_chanctx(mvm, ctx);
3985 mutex_unlock(&mvm->mutex);
3988 static void iwl_mvm_change_chanctx(struct ieee80211_hw *hw,
3989 struct ieee80211_chanctx_conf *ctx,
3992 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
3993 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
3994 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
3995 bool responder = iwl_mvm_is_ftm_responder_chanctx(mvm, ctx);
3996 struct cfg80211_chan_def *def = responder ? &ctx->def : &ctx->min_def;
3998 if (WARN_ONCE((phy_ctxt->ref > 1) &&
3999 (changed & ~(IEEE80211_CHANCTX_CHANGE_WIDTH |
4000 IEEE80211_CHANCTX_CHANGE_RX_CHAINS |
4001 IEEE80211_CHANCTX_CHANGE_RADAR |
4002 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH)),
4003 "Cannot change PHY. Ref=%d, changed=0x%X\n",
4004 phy_ctxt->ref, changed))
4007 mutex_lock(&mvm->mutex);
4009 /* we are only changing the min_width, may be a noop */
4010 if (changed == IEEE80211_CHANCTX_CHANGE_MIN_WIDTH) {
4011 if (phy_ctxt->width == def->width)
4014 /* we are just toggling between 20_NOHT and 20 */
4015 if (phy_ctxt->width <= NL80211_CHAN_WIDTH_20 &&
4016 def->width <= NL80211_CHAN_WIDTH_20)
4020 iwl_mvm_bt_coex_vif_change(mvm);
4021 iwl_mvm_phy_ctxt_changed(mvm, phy_ctxt, def,
4022 ctx->rx_chains_static,
4023 ctx->rx_chains_dynamic);
4026 mutex_unlock(&mvm->mutex);
4029 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm *mvm,
4030 struct ieee80211_vif *vif,
4031 struct ieee80211_chanctx_conf *ctx,
4032 bool switching_chanctx)
4034 u16 *phy_ctxt_id = (u16 *)ctx->drv_priv;
4035 struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id];
4036 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4039 lockdep_assert_held(&mvm->mutex);
4041 mvmvif->phy_ctxt = phy_ctxt;
4043 switch (vif->type) {
4044 case NL80211_IFTYPE_AP:
4045 /* only needed if we're switching chanctx (i.e. during CSA) */
4046 if (switching_chanctx) {
4047 mvmvif->ap_ibss_active = true;
4051 case NL80211_IFTYPE_ADHOC:
4053 * The AP binding flow is handled as part of the start_ap flow
4054 * (in bss_info_changed), similarly for IBSS.
4058 case NL80211_IFTYPE_STATION:
4059 mvmvif->csa_bcn_pending = false;
4061 case NL80211_IFTYPE_MONITOR:
4062 /* always disable PS when a monitor interface is active */
4063 mvmvif->ps_disabled = true;
4070 ret = iwl_mvm_binding_add_vif(mvm, vif);
4075 * Power state must be updated before quotas,
4076 * otherwise fw will complain.
4078 iwl_mvm_power_update_mac(mvm);
4080 /* Setting the quota at this stage is only required for monitor
4081 * interfaces. For the other types, the bss_info changed flow
4082 * will handle quota settings.
4084 if (vif->type == NL80211_IFTYPE_MONITOR) {
4085 mvmvif->monitor_active = true;
4086 ret = iwl_mvm_update_quotas(mvm, false, NULL);
4088 goto out_remove_binding;
4090 ret = iwl_mvm_add_snif_sta(mvm, vif);
4092 goto out_remove_binding;
4096 /* Handle binding during CSA */
4097 if (vif->type == NL80211_IFTYPE_AP) {
4098 iwl_mvm_update_quotas(mvm, false, NULL);
4099 iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
4102 if (switching_chanctx && vif->type == NL80211_IFTYPE_STATION) {
4103 mvmvif->csa_bcn_pending = true;
4105 if (!fw_has_capa(&mvm->fw->ucode_capa,
4106 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4107 u32 duration = 3 * vif->bss_conf.beacon_int;
4109 /* Protect the session to make sure we hear the first
4110 * beacon on the new channel.
4112 iwl_mvm_protect_session(mvm, vif, duration, duration,
4113 vif->bss_conf.beacon_int / 2,
4117 iwl_mvm_update_quotas(mvm, false, NULL);
4123 iwl_mvm_binding_remove_vif(mvm, vif);
4124 iwl_mvm_power_update_mac(mvm);
4127 mvmvif->phy_ctxt = NULL;
4130 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw *hw,
4131 struct ieee80211_vif *vif,
4132 struct ieee80211_chanctx_conf *ctx)
4134 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4137 mutex_lock(&mvm->mutex);
4138 ret = __iwl_mvm_assign_vif_chanctx(mvm, vif, ctx, false);
4139 mutex_unlock(&mvm->mutex);
4144 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm *mvm,
4145 struct ieee80211_vif *vif,
4146 struct ieee80211_chanctx_conf *ctx,
4147 bool switching_chanctx)
4149 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4150 struct ieee80211_vif *disabled_vif = NULL;
4152 lockdep_assert_held(&mvm->mutex);
4154 iwl_mvm_remove_time_event(mvm, mvmvif, &mvmvif->time_event_data);
4156 switch (vif->type) {
4157 case NL80211_IFTYPE_ADHOC:
4159 case NL80211_IFTYPE_MONITOR:
4160 mvmvif->monitor_active = false;
4161 mvmvif->ps_disabled = false;
4162 iwl_mvm_rm_snif_sta(mvm, vif);
4164 case NL80211_IFTYPE_AP:
4165 /* This part is triggered only during CSA */
4166 if (!switching_chanctx || !mvmvif->ap_ibss_active)
4169 mvmvif->csa_countdown = false;
4171 /* Set CS bit on all the stations */
4172 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
4174 /* Save blocked iface, the timeout is set on the next beacon */
4175 rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
4177 mvmvif->ap_ibss_active = false;
4179 case NL80211_IFTYPE_STATION:
4180 if (!switching_chanctx)
4185 if (!fw_has_capa(&mvm->fw->ucode_capa,
4186 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD))
4187 iwl_mvm_mac_ctxt_changed(mvm, vif, true, NULL);
4193 iwl_mvm_update_quotas(mvm, false, disabled_vif);
4194 iwl_mvm_binding_remove_vif(mvm, vif);
4197 mvmvif->phy_ctxt = NULL;
4198 iwl_mvm_power_update_mac(mvm);
4201 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw *hw,
4202 struct ieee80211_vif *vif,
4203 struct ieee80211_chanctx_conf *ctx)
4205 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4207 mutex_lock(&mvm->mutex);
4208 __iwl_mvm_unassign_vif_chanctx(mvm, vif, ctx, false);
4209 mutex_unlock(&mvm->mutex);
4213 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm *mvm,
4214 struct ieee80211_vif_chanctx_switch *vifs)
4218 mutex_lock(&mvm->mutex);
4219 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4220 __iwl_mvm_remove_chanctx(mvm, vifs[0].old_ctx);
4222 ret = __iwl_mvm_add_chanctx(mvm, vifs[0].new_ctx);
4224 IWL_ERR(mvm, "failed to add new_ctx during channel switch\n");
4228 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4232 "failed to assign new_ctx during channel switch\n");
4236 /* we don't support TDLS during DCM - can be caused by channel switch */
4237 if (iwl_mvm_phy_ctx_count(mvm) > 1)
4238 iwl_mvm_teardown_tdls_peers(mvm);
4243 __iwl_mvm_remove_chanctx(mvm, vifs[0].new_ctx);
4246 if (__iwl_mvm_add_chanctx(mvm, vifs[0].old_ctx)) {
4247 IWL_ERR(mvm, "failed to add old_ctx back after failure.\n");
4251 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4253 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4260 /* things keep failing, better restart the hw */
4261 iwl_mvm_nic_restart(mvm, false);
4264 mutex_unlock(&mvm->mutex);
4270 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm *mvm,
4271 struct ieee80211_vif_chanctx_switch *vifs)
4275 mutex_lock(&mvm->mutex);
4276 __iwl_mvm_unassign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx, true);
4278 ret = __iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].new_ctx,
4282 "failed to assign new_ctx during channel switch\n");
4289 if (__iwl_mvm_assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].old_ctx,
4291 IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n");
4298 /* things keep failing, better restart the hw */
4299 iwl_mvm_nic_restart(mvm, false);
4302 mutex_unlock(&mvm->mutex);
4307 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw *hw,
4308 struct ieee80211_vif_chanctx_switch *vifs,
4310 enum ieee80211_chanctx_switch_mode mode)
4312 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4315 /* we only support a single-vif right now */
4320 case CHANCTX_SWMODE_SWAP_CONTEXTS:
4321 ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs);
4323 case CHANCTX_SWMODE_REASSIGN_VIF:
4324 ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs);
4334 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw *hw)
4336 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4338 return mvm->ibss_manager;
4341 static int iwl_mvm_set_tim(struct ieee80211_hw *hw,
4342 struct ieee80211_sta *sta,
4345 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4346 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4348 if (!mvm_sta || !mvm_sta->vif) {
4349 IWL_ERR(mvm, "Station is not associated to a vif\n");
4353 return iwl_mvm_mac_ctxt_beacon_changed(mvm, mvm_sta->vif);
4356 #ifdef CONFIG_NL80211_TESTMODE
4357 static const struct nla_policy iwl_mvm_tm_policy[IWL_MVM_TM_ATTR_MAX + 1] = {
4358 [IWL_MVM_TM_ATTR_CMD] = { .type = NLA_U32 },
4359 [IWL_MVM_TM_ATTR_NOA_DURATION] = { .type = NLA_U32 },
4360 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE] = { .type = NLA_U32 },
4363 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm *mvm,
4364 struct ieee80211_vif *vif,
4365 void *data, int len)
4367 struct nlattr *tb[IWL_MVM_TM_ATTR_MAX + 1];
4371 err = nla_parse_deprecated(tb, IWL_MVM_TM_ATTR_MAX, data, len,
4372 iwl_mvm_tm_policy, NULL);
4376 if (!tb[IWL_MVM_TM_ATTR_CMD])
4379 switch (nla_get_u32(tb[IWL_MVM_TM_ATTR_CMD])) {
4380 case IWL_MVM_TM_CMD_SET_NOA:
4381 if (!vif || vif->type != NL80211_IFTYPE_AP || !vif->p2p ||
4382 !vif->bss_conf.enable_beacon ||
4383 !tb[IWL_MVM_TM_ATTR_NOA_DURATION])
4386 noa_duration = nla_get_u32(tb[IWL_MVM_TM_ATTR_NOA_DURATION]);
4387 if (noa_duration >= vif->bss_conf.beacon_int)
4390 mvm->noa_duration = noa_duration;
4393 return iwl_mvm_update_quotas(mvm, true, NULL);
4394 case IWL_MVM_TM_CMD_SET_BEACON_FILTER:
4395 /* must be associated client vif - ignore authorized */
4396 if (!vif || vif->type != NL80211_IFTYPE_STATION ||
4397 !vif->bss_conf.assoc || !vif->bss_conf.dtim_period ||
4398 !tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE])
4401 if (nla_get_u32(tb[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE]))
4402 return iwl_mvm_enable_beacon_filter(mvm, vif, 0);
4403 return iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4409 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw *hw,
4410 struct ieee80211_vif *vif,
4411 void *data, int len)
4413 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4416 mutex_lock(&mvm->mutex);
4417 err = __iwl_mvm_mac_testmode_cmd(mvm, vif, data, len);
4418 mutex_unlock(&mvm->mutex);
4424 static void iwl_mvm_channel_switch(struct ieee80211_hw *hw,
4425 struct ieee80211_vif *vif,
4426 struct ieee80211_channel_switch *chsw)
4428 /* By implementing this operation, we prevent mac80211 from
4429 * starting its own channel switch timer, so that we can call
4430 * ieee80211_chswitch_done() ourselves at the right time
4431 * (which is when the absence time event starts).
4434 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw),
4435 "dummy channel switch op\n");
4438 static int iwl_mvm_schedule_client_csa(struct iwl_mvm *mvm,
4439 struct ieee80211_vif *vif,
4440 struct ieee80211_channel_switch *chsw)
4442 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4443 struct iwl_chan_switch_te_cmd cmd = {
4444 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4446 .action = cpu_to_le32(FW_CTXT_ACTION_ADD),
4447 .tsf = cpu_to_le32(chsw->timestamp),
4448 .cs_count = chsw->count,
4449 .cs_mode = chsw->block_tx,
4452 lockdep_assert_held(&mvm->mutex);
4455 cmd.cs_delayed_bcn_count =
4456 DIV_ROUND_UP(chsw->delay, vif->bss_conf.beacon_int);
4458 return iwl_mvm_send_cmd_pdu(mvm,
4459 WIDE_ID(MAC_CONF_GROUP,
4460 CHANNEL_SWITCH_TIME_EVENT_CMD),
4461 0, sizeof(cmd), &cmd);
4464 static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm *mvm,
4465 struct ieee80211_vif *vif,
4466 struct ieee80211_channel_switch *chsw)
4468 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4471 /* Schedule the time event to a bit before beacon 1,
4472 * to make sure we're in the new channel when the
4473 * GO/AP arrives. In case count <= 1 immediately schedule the
4474 * TE (this might result with some packet loss or connection
4477 if (chsw->count <= 1)
4480 apply_time = chsw->device_timestamp +
4481 ((vif->bss_conf.beacon_int * (chsw->count - 1) -
4482 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
4485 iwl_mvm_csa_client_absent(mvm, vif);
4487 if (mvmvif->bf_data.bf_enabled) {
4488 int ret = iwl_mvm_disable_beacon_filter(mvm, vif, 0);
4494 iwl_mvm_schedule_csa_period(mvm, vif, vif->bss_conf.beacon_int,
4500 #define IWL_MAX_CSA_BLOCK_TX 1500
4501 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw *hw,
4502 struct ieee80211_vif *vif,
4503 struct ieee80211_channel_switch *chsw)
4505 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4506 struct ieee80211_vif *csa_vif;
4507 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4510 mutex_lock(&mvm->mutex);
4512 mvmvif->csa_failed = false;
4514 IWL_DEBUG_MAC80211(mvm, "pre CSA to freq %d\n",
4515 chsw->chandef.center_freq1);
4517 iwl_fw_dbg_trigger_simple_stop(&mvm->fwrt,
4518 ieee80211_vif_to_wdev(vif),
4519 FW_DBG_TRIGGER_CHANNEL_SWITCH);
4521 switch (vif->type) {
4522 case NL80211_IFTYPE_AP:
4524 rcu_dereference_protected(mvm->csa_vif,
4525 lockdep_is_held(&mvm->mutex));
4526 if (WARN_ONCE(csa_vif && csa_vif->csa_active,
4527 "Another CSA is already in progress")) {
4532 /* we still didn't unblock tx. prevent new CS meanwhile */
4533 if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
4534 lockdep_is_held(&mvm->mutex))) {
4539 rcu_assign_pointer(mvm->csa_vif, vif);
4541 if (WARN_ONCE(mvmvif->csa_countdown,
4542 "Previous CSA countdown didn't complete")) {
4547 mvmvif->csa_target_freq = chsw->chandef.chan->center_freq;
4550 case NL80211_IFTYPE_STATION:
4551 if (chsw->delay > IWL_MAX_CSA_BLOCK_TX)
4552 schedule_delayed_work(&mvmvif->csa_work, 0);
4554 if (chsw->block_tx) {
4556 * In case of undetermined / long time with immediate
4557 * quiet monitor status to gracefully disconnect
4560 chsw->count * vif->bss_conf.beacon_int >
4561 IWL_MAX_CSA_BLOCK_TX)
4562 schedule_delayed_work(&mvmvif->csa_work,
4563 msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX));
4566 if (!fw_has_capa(&mvm->fw->ucode_capa,
4567 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
4568 ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw);
4572 iwl_mvm_schedule_client_csa(mvm, vif, chsw);
4575 mvmvif->csa_count = chsw->count;
4576 mvmvif->csa_misbehave = false;
4582 mvmvif->ps_disabled = true;
4584 ret = iwl_mvm_power_update_ps(mvm);
4588 /* we won't be on this channel any longer */
4589 iwl_mvm_teardown_tdls_peers(mvm);
4592 mutex_unlock(&mvm->mutex);
4597 static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw *hw,
4598 struct ieee80211_vif *vif,
4599 struct ieee80211_channel_switch *chsw)
4601 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4602 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4603 struct iwl_chan_switch_te_cmd cmd = {
4604 .mac_id = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
4606 .action = cpu_to_le32(FW_CTXT_ACTION_MODIFY),
4607 .tsf = cpu_to_le32(chsw->timestamp),
4608 .cs_count = chsw->count,
4609 .cs_mode = chsw->block_tx,
4612 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY))
4615 if (chsw->count >= mvmvif->csa_count && chsw->block_tx) {
4616 if (mvmvif->csa_misbehave) {
4617 /* Second time, give up on this AP*/
4618 iwl_mvm_abort_channel_switch(hw, vif);
4619 ieee80211_chswitch_done(vif, false);
4620 mvmvif->csa_misbehave = false;
4623 mvmvif->csa_misbehave = true;
4625 mvmvif->csa_count = chsw->count;
4627 mutex_lock(&mvm->mutex);
4628 if (mvmvif->csa_failed)
4631 IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d\n", mvmvif->id);
4632 WARN_ON(iwl_mvm_send_cmd_pdu(mvm,
4633 WIDE_ID(MAC_CONF_GROUP,
4634 CHANNEL_SWITCH_TIME_EVENT_CMD),
4635 0, sizeof(cmd), &cmd));
4637 mutex_unlock(&mvm->mutex);
4640 static void iwl_mvm_flush_no_vif(struct iwl_mvm *mvm, u32 queues, bool drop)
4644 if (!iwl_mvm_has_new_tx_api(mvm)) {
4646 mutex_lock(&mvm->mutex);
4647 iwl_mvm_flush_tx_path(mvm,
4648 iwl_mvm_flushable_queues(mvm) & queues, 0);
4649 mutex_unlock(&mvm->mutex);
4651 iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
4656 mutex_lock(&mvm->mutex);
4657 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
4658 struct ieee80211_sta *sta;
4660 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4661 lockdep_is_held(&mvm->mutex));
4662 if (IS_ERR_OR_NULL(sta))
4666 iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF, 0);
4668 iwl_mvm_wait_sta_queues_empty(mvm,
4669 iwl_mvm_sta_from_mac80211(sta));
4671 mutex_unlock(&mvm->mutex);
4674 static void iwl_mvm_mac_flush(struct ieee80211_hw *hw,
4675 struct ieee80211_vif *vif, u32 queues, bool drop)
4677 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4678 struct iwl_mvm_vif *mvmvif;
4679 struct iwl_mvm_sta *mvmsta;
4680 struct ieee80211_sta *sta;
4685 iwl_mvm_flush_no_vif(mvm, queues, drop);
4689 if (vif->type != NL80211_IFTYPE_STATION)
4692 /* Make sure we're done with the deferred traffic before flushing */
4693 flush_work(&mvm->add_stream_wk);
4695 mutex_lock(&mvm->mutex);
4696 mvmvif = iwl_mvm_vif_from_mac80211(vif);
4698 /* flush the AP-station and all TDLS peers */
4699 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
4700 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
4701 lockdep_is_held(&mvm->mutex));
4702 if (IS_ERR_OR_NULL(sta))
4705 mvmsta = iwl_mvm_sta_from_mac80211(sta);
4706 if (mvmsta->vif != vif)
4709 /* make sure only TDLS peers or the AP are flushed */
4710 WARN_ON(i != mvmvif->ap_sta_id && !sta->tdls);
4713 if (iwl_mvm_flush_sta(mvm, mvmsta, false))
4714 IWL_ERR(mvm, "flush request fail\n");
4716 msk |= mvmsta->tfd_queue_msk;
4717 if (iwl_mvm_has_new_tx_api(mvm))
4718 iwl_mvm_wait_sta_queues_empty(mvm, mvmsta);
4722 mutex_unlock(&mvm->mutex);
4724 /* this can take a while, and we may need/want other operations
4725 * to succeed while doing this, so do it without the mutex held
4727 if (!drop && !iwl_mvm_has_new_tx_api(mvm))
4728 iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
4731 static int iwl_mvm_mac_get_survey(struct ieee80211_hw *hw, int idx,
4732 struct survey_info *survey)
4734 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4737 memset(survey, 0, sizeof(*survey));
4739 /* only support global statistics right now */
4743 if (!fw_has_capa(&mvm->fw->ucode_capa,
4744 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
4747 mutex_lock(&mvm->mutex);
4749 if (iwl_mvm_firmware_running(mvm)) {
4750 ret = iwl_mvm_request_statistics(mvm, false);
4755 survey->filled = SURVEY_INFO_TIME |
4756 SURVEY_INFO_TIME_RX |
4757 SURVEY_INFO_TIME_TX |
4758 SURVEY_INFO_TIME_SCAN;
4759 survey->time = mvm->accu_radio_stats.on_time_rf +
4760 mvm->radio_stats.on_time_rf;
4761 do_div(survey->time, USEC_PER_MSEC);
4763 survey->time_rx = mvm->accu_radio_stats.rx_time +
4764 mvm->radio_stats.rx_time;
4765 do_div(survey->time_rx, USEC_PER_MSEC);
4767 survey->time_tx = mvm->accu_radio_stats.tx_time +
4768 mvm->radio_stats.tx_time;
4769 do_div(survey->time_tx, USEC_PER_MSEC);
4771 survey->time_scan = mvm->accu_radio_stats.on_time_scan +
4772 mvm->radio_stats.on_time_scan;
4773 do_div(survey->time_scan, USEC_PER_MSEC);
4777 mutex_unlock(&mvm->mutex);
4781 static void iwl_mvm_set_sta_rate(u32 rate_n_flags, struct rate_info *rinfo)
4783 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
4784 case RATE_MCS_CHAN_WIDTH_20:
4785 rinfo->bw = RATE_INFO_BW_20;
4787 case RATE_MCS_CHAN_WIDTH_40:
4788 rinfo->bw = RATE_INFO_BW_40;
4790 case RATE_MCS_CHAN_WIDTH_80:
4791 rinfo->bw = RATE_INFO_BW_80;
4793 case RATE_MCS_CHAN_WIDTH_160:
4794 rinfo->bw = RATE_INFO_BW_160;
4798 if (rate_n_flags & RATE_MCS_HT_MSK) {
4799 rinfo->flags |= RATE_INFO_FLAGS_MCS;
4800 rinfo->mcs = u32_get_bits(rate_n_flags, RATE_HT_MCS_INDEX_MSK);
4801 rinfo->nss = u32_get_bits(rate_n_flags,
4802 RATE_HT_MCS_NSS_MSK) + 1;
4803 if (rate_n_flags & RATE_MCS_SGI_MSK)
4804 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
4805 } else if (rate_n_flags & RATE_MCS_VHT_MSK) {
4806 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
4807 rinfo->mcs = u32_get_bits(rate_n_flags,
4808 RATE_VHT_MCS_RATE_CODE_MSK);
4809 rinfo->nss = u32_get_bits(rate_n_flags,
4810 RATE_VHT_MCS_NSS_MSK) + 1;
4811 if (rate_n_flags & RATE_MCS_SGI_MSK)
4812 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
4813 } else if (rate_n_flags & RATE_MCS_HE_MSK) {
4814 u32 gi_ltf = u32_get_bits(rate_n_flags,
4815 RATE_MCS_HE_GI_LTF_MSK);
4817 rinfo->flags |= RATE_INFO_FLAGS_HE_MCS;
4818 rinfo->mcs = u32_get_bits(rate_n_flags,
4819 RATE_VHT_MCS_RATE_CODE_MSK);
4820 rinfo->nss = u32_get_bits(rate_n_flags,
4821 RATE_VHT_MCS_NSS_MSK) + 1;
4823 if (rate_n_flags & RATE_MCS_HE_106T_MSK) {
4824 rinfo->bw = RATE_INFO_BW_HE_RU;
4825 rinfo->he_ru_alloc = NL80211_RATE_INFO_HE_RU_ALLOC_106;
4828 switch (rate_n_flags & RATE_MCS_HE_TYPE_MSK) {
4829 case RATE_MCS_HE_TYPE_SU:
4830 case RATE_MCS_HE_TYPE_EXT_SU:
4831 if (gi_ltf == 0 || gi_ltf == 1)
4832 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
4833 else if (gi_ltf == 2)
4834 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
4835 else if (rate_n_flags & RATE_MCS_SGI_MSK)
4836 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
4838 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
4840 case RATE_MCS_HE_TYPE_MU:
4841 if (gi_ltf == 0 || gi_ltf == 1)
4842 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
4843 else if (gi_ltf == 2)
4844 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
4846 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
4848 case RATE_MCS_HE_TYPE_TRIG:
4849 if (gi_ltf == 0 || gi_ltf == 1)
4850 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
4852 rinfo->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
4856 if (rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK)
4859 switch (u32_get_bits(rate_n_flags, RATE_LEGACY_RATE_MSK)) {
4860 case IWL_RATE_1M_PLCP:
4863 case IWL_RATE_2M_PLCP:
4866 case IWL_RATE_5M_PLCP:
4869 case IWL_RATE_11M_PLCP:
4870 rinfo->legacy = 110;
4872 case IWL_RATE_6M_PLCP:
4875 case IWL_RATE_9M_PLCP:
4878 case IWL_RATE_12M_PLCP:
4879 rinfo->legacy = 120;
4881 case IWL_RATE_18M_PLCP:
4882 rinfo->legacy = 180;
4884 case IWL_RATE_24M_PLCP:
4885 rinfo->legacy = 240;
4887 case IWL_RATE_36M_PLCP:
4888 rinfo->legacy = 360;
4890 case IWL_RATE_48M_PLCP:
4891 rinfo->legacy = 480;
4893 case IWL_RATE_54M_PLCP:
4894 rinfo->legacy = 540;
4900 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
4901 struct ieee80211_vif *vif,
4902 struct ieee80211_sta *sta,
4903 struct station_info *sinfo)
4905 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
4906 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
4907 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
4909 if (mvmsta->avg_energy) {
4910 sinfo->signal_avg = -(s8)mvmsta->avg_energy;
4911 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
4914 if (iwl_mvm_has_tlc_offload(mvm)) {
4915 struct iwl_lq_sta_rs_fw *lq_sta = &mvmsta->lq_sta.rs_fw;
4917 iwl_mvm_set_sta_rate(lq_sta->last_rate_n_flags, &sinfo->txrate);
4918 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
4921 /* if beacon filtering isn't on mac80211 does it anyway */
4922 if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
4925 if (!vif->bss_conf.assoc)
4928 mutex_lock(&mvm->mutex);
4930 if (mvmvif->ap_sta_id != mvmsta->sta_id)
4933 if (iwl_mvm_request_statistics(mvm, false))
4936 sinfo->rx_beacon = mvmvif->beacon_stats.num_beacons +
4937 mvmvif->beacon_stats.accu_num_beacons;
4938 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX);
4939 if (mvmvif->beacon_stats.avg_signal) {
4940 /* firmware only reports a value after RXing a few beacons */
4941 sinfo->rx_beacon_signal_avg = mvmvif->beacon_stats.avg_signal;
4942 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
4945 mutex_unlock(&mvm->mutex);
4948 static void iwl_mvm_event_mlme_callback(struct iwl_mvm *mvm,
4949 struct ieee80211_vif *vif,
4950 const struct ieee80211_event *event)
4952 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4954 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4956 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4959 struct iwl_fw_dbg_trigger_tlv *trig;
4960 struct iwl_fw_dbg_trigger_mlme *trig_mlme;
4962 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
4963 FW_DBG_TRIGGER_MLME);
4967 trig_mlme = (void *)trig->data;
4969 if (event->u.mlme.data == ASSOC_EVENT) {
4970 if (event->u.mlme.status == MLME_DENIED)
4971 CHECK_MLME_TRIGGER(stop_assoc_denied,
4972 "DENIED ASSOC: reason %d",
4973 event->u.mlme.reason);
4974 else if (event->u.mlme.status == MLME_TIMEOUT)
4975 CHECK_MLME_TRIGGER(stop_assoc_timeout,
4977 } else if (event->u.mlme.data == AUTH_EVENT) {
4978 if (event->u.mlme.status == MLME_DENIED)
4979 CHECK_MLME_TRIGGER(stop_auth_denied,
4980 "DENIED AUTH: reason %d",
4981 event->u.mlme.reason);
4982 else if (event->u.mlme.status == MLME_TIMEOUT)
4983 CHECK_MLME_TRIGGER(stop_auth_timeout,
4985 } else if (event->u.mlme.data == DEAUTH_RX_EVENT) {
4986 CHECK_MLME_TRIGGER(stop_rx_deauth,
4987 "DEAUTH RX %d", event->u.mlme.reason);
4988 } else if (event->u.mlme.data == DEAUTH_TX_EVENT) {
4989 CHECK_MLME_TRIGGER(stop_tx_deauth,
4990 "DEAUTH TX %d", event->u.mlme.reason);
4992 #undef CHECK_MLME_TRIGGER
4995 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm *mvm,
4996 struct ieee80211_vif *vif,
4997 const struct ieee80211_event *event)
4999 struct iwl_fw_dbg_trigger_tlv *trig;
5000 struct iwl_fw_dbg_trigger_ba *ba_trig;
5002 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, ieee80211_vif_to_wdev(vif),
5007 ba_trig = (void *)trig->data;
5009 if (!(le16_to_cpu(ba_trig->rx_bar) & BIT(event->u.ba.tid)))
5012 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
5013 "BAR received from %pM, tid %d, ssn %d",
5014 event->u.ba.sta->addr, event->u.ba.tid,
5018 static void iwl_mvm_mac_event_callback(struct ieee80211_hw *hw,
5019 struct ieee80211_vif *vif,
5020 const struct ieee80211_event *event)
5022 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5024 switch (event->type) {
5026 iwl_mvm_event_mlme_callback(mvm, vif, event);
5029 iwl_mvm_event_bar_rx_callback(mvm, vif, event);
5031 case BA_FRAME_TIMEOUT:
5032 iwl_mvm_event_frame_timeout_callback(mvm, vif, event->u.ba.sta,
5040 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm *mvm,
5041 struct iwl_mvm_internal_rxq_notif *notif,
5044 u32 qmask = BIT(mvm->trans->num_rx_queues) - 1;
5048 if (!iwl_mvm_has_new_rx_api(mvm))
5052 notif->cookie = mvm->queue_sync_cookie;
5053 mvm->queue_sync_state = (1 << mvm->trans->num_rx_queues) - 1;
5056 ret = iwl_mvm_notify_rx_queue(mvm, qmask, notif, size, !notif->sync);
5058 IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret);
5063 lockdep_assert_held(&mvm->mutex);
5064 ret = wait_event_timeout(mvm->rx_sync_waitq,
5065 READ_ONCE(mvm->queue_sync_state) == 0 ||
5066 iwl_mvm_is_radio_killed(mvm),
5068 WARN_ONCE(!ret && !iwl_mvm_is_radio_killed(mvm),
5069 "queue sync: failed to sync, state is 0x%lx\n",
5070 mvm->queue_sync_state);
5074 mvm->queue_sync_state = 0;
5076 mvm->queue_sync_cookie++;
5079 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw *hw)
5081 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5082 struct iwl_mvm_internal_rxq_notif data = {
5083 .type = IWL_MVM_RXQ_EMPTY,
5087 mutex_lock(&mvm->mutex);
5088 iwl_mvm_sync_rx_queues_internal(mvm, &data, sizeof(data));
5089 mutex_unlock(&mvm->mutex);
5093 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw *hw,
5094 struct ieee80211_vif *vif,
5095 struct cfg80211_ftm_responder_stats *stats)
5097 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5098 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
5100 if (vif->p2p || vif->type != NL80211_IFTYPE_AP ||
5101 !mvmvif->ap_ibss_active || !vif->bss_conf.ftm_responder)
5104 mutex_lock(&mvm->mutex);
5105 *stats = mvm->ftm_resp_stats;
5106 mutex_unlock(&mvm->mutex);
5108 stats->filled = BIT(NL80211_FTM_STATS_SUCCESS_NUM) |
5109 BIT(NL80211_FTM_STATS_PARTIAL_NUM) |
5110 BIT(NL80211_FTM_STATS_FAILED_NUM) |
5111 BIT(NL80211_FTM_STATS_ASAP_NUM) |
5112 BIT(NL80211_FTM_STATS_NON_ASAP_NUM) |
5113 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC) |
5114 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM) |
5115 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM) |
5116 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM);
5121 static int iwl_mvm_start_pmsr(struct ieee80211_hw *hw,
5122 struct ieee80211_vif *vif,
5123 struct cfg80211_pmsr_request *request)
5125 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5128 mutex_lock(&mvm->mutex);
5129 ret = iwl_mvm_ftm_start(mvm, vif, request);
5130 mutex_unlock(&mvm->mutex);
5135 static void iwl_mvm_abort_pmsr(struct ieee80211_hw *hw,
5136 struct ieee80211_vif *vif,
5137 struct cfg80211_pmsr_request *request)
5139 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5141 mutex_lock(&mvm->mutex);
5142 iwl_mvm_ftm_abort(mvm, request);
5143 mutex_unlock(&mvm->mutex);
5146 static bool iwl_mvm_can_hw_csum(struct sk_buff *skb)
5148 u8 protocol = ip_hdr(skb)->protocol;
5150 if (!IS_ENABLED(CONFIG_INET))
5153 return protocol == IPPROTO_TCP || protocol == IPPROTO_UDP;
5156 static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw *hw,
5157 struct sk_buff *head,
5158 struct sk_buff *skb)
5160 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
5162 /* For now don't aggregate IPv6 in AMSDU */
5163 if (skb->protocol != htons(ETH_P_IP))
5166 if (!iwl_mvm_is_csum_supported(mvm))
5169 return iwl_mvm_can_hw_csum(skb) == iwl_mvm_can_hw_csum(head);
5172 const struct ieee80211_ops iwl_mvm_hw_ops = {
5173 .tx = iwl_mvm_mac_tx,
5174 .wake_tx_queue = iwl_mvm_mac_wake_tx_queue,
5175 .ampdu_action = iwl_mvm_mac_ampdu_action,
5176 .get_antenna = iwl_mvm_op_get_antenna,
5177 .start = iwl_mvm_mac_start,
5178 .reconfig_complete = iwl_mvm_mac_reconfig_complete,
5179 .stop = iwl_mvm_mac_stop,
5180 .add_interface = iwl_mvm_mac_add_interface,
5181 .remove_interface = iwl_mvm_mac_remove_interface,
5182 .config = iwl_mvm_mac_config,
5183 .prepare_multicast = iwl_mvm_prepare_multicast,
5184 .configure_filter = iwl_mvm_configure_filter,
5185 .config_iface_filter = iwl_mvm_config_iface_filter,
5186 .bss_info_changed = iwl_mvm_bss_info_changed,
5187 .hw_scan = iwl_mvm_mac_hw_scan,
5188 .cancel_hw_scan = iwl_mvm_mac_cancel_hw_scan,
5189 .sta_pre_rcu_remove = iwl_mvm_sta_pre_rcu_remove,
5190 .sta_state = iwl_mvm_mac_sta_state,
5191 .sta_notify = iwl_mvm_mac_sta_notify,
5192 .allow_buffered_frames = iwl_mvm_mac_allow_buffered_frames,
5193 .release_buffered_frames = iwl_mvm_mac_release_buffered_frames,
5194 .set_rts_threshold = iwl_mvm_mac_set_rts_threshold,
5195 .sta_rc_update = iwl_mvm_sta_rc_update,
5196 .conf_tx = iwl_mvm_mac_conf_tx,
5197 .mgd_prepare_tx = iwl_mvm_mac_mgd_prepare_tx,
5198 .mgd_protect_tdls_discover = iwl_mvm_mac_mgd_protect_tdls_discover,
5199 .flush = iwl_mvm_mac_flush,
5200 .sched_scan_start = iwl_mvm_mac_sched_scan_start,
5201 .sched_scan_stop = iwl_mvm_mac_sched_scan_stop,
5202 .set_key = iwl_mvm_mac_set_key,
5203 .update_tkip_key = iwl_mvm_mac_update_tkip_key,
5204 .remain_on_channel = iwl_mvm_roc,
5205 .cancel_remain_on_channel = iwl_mvm_cancel_roc,
5206 .add_chanctx = iwl_mvm_add_chanctx,
5207 .remove_chanctx = iwl_mvm_remove_chanctx,
5208 .change_chanctx = iwl_mvm_change_chanctx,
5209 .assign_vif_chanctx = iwl_mvm_assign_vif_chanctx,
5210 .unassign_vif_chanctx = iwl_mvm_unassign_vif_chanctx,
5211 .switch_vif_chanctx = iwl_mvm_switch_vif_chanctx,
5213 .start_ap = iwl_mvm_start_ap_ibss,
5214 .stop_ap = iwl_mvm_stop_ap_ibss,
5215 .join_ibss = iwl_mvm_start_ap_ibss,
5216 .leave_ibss = iwl_mvm_stop_ap_ibss,
5218 .tx_last_beacon = iwl_mvm_tx_last_beacon,
5220 .set_tim = iwl_mvm_set_tim,
5222 .channel_switch = iwl_mvm_channel_switch,
5223 .pre_channel_switch = iwl_mvm_pre_channel_switch,
5224 .post_channel_switch = iwl_mvm_post_channel_switch,
5225 .abort_channel_switch = iwl_mvm_abort_channel_switch,
5226 .channel_switch_rx_beacon = iwl_mvm_channel_switch_rx_beacon,
5228 .tdls_channel_switch = iwl_mvm_tdls_channel_switch,
5229 .tdls_cancel_channel_switch = iwl_mvm_tdls_cancel_channel_switch,
5230 .tdls_recv_channel_switch = iwl_mvm_tdls_recv_channel_switch,
5232 .event_callback = iwl_mvm_mac_event_callback,
5234 .sync_rx_queues = iwl_mvm_sync_rx_queues,
5236 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd)
5238 #ifdef CONFIG_PM_SLEEP
5240 .suspend = iwl_mvm_suspend,
5241 .resume = iwl_mvm_resume,
5242 .set_wakeup = iwl_mvm_set_wakeup,
5243 .set_rekey_data = iwl_mvm_set_rekey_data,
5244 #if IS_ENABLED(CONFIG_IPV6)
5245 .ipv6_addr_change = iwl_mvm_ipv6_addr_change,
5247 .set_default_unicast_key = iwl_mvm_set_default_unicast_key,
5249 .get_survey = iwl_mvm_mac_get_survey,
5250 .sta_statistics = iwl_mvm_mac_sta_statistics,
5251 .get_ftm_responder_stats = iwl_mvm_mac_get_ftm_responder_stats,
5252 .start_pmsr = iwl_mvm_start_pmsr,
5253 .abort_pmsr = iwl_mvm_abort_pmsr,
5255 .can_aggregate_in_amsdu = iwl_mvm_mac_can_aggregate,
5256 #ifdef CONFIG_IWLWIFI_DEBUGFS
5257 .sta_add_debugfs = iwl_mvm_sta_add_debugfs,