1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
9 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
10 * Copyright(c) 2012 - 2014, 2018 - 2020 Intel Corporation
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * The full GNU General Public License is included in this distribution
22 * in the file called COPYING.
24 * Contact Information:
25 * Intel Linux Wireless <linuxwifi@intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
31 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
32 * Copyright(c) 2012 - 2014, 2018 - 2020 Intel Corporation
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
39 * * Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * * Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in
43 * the documentation and/or other materials provided with the
45 * * Neither the name Intel Corporation nor the names of its
46 * contributors may be used to endorse or promote products derived
47 * from this software without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
62 #include <linux/kernel.h>
63 #include <linux/slab.h>
64 #include <linux/skbuff.h>
65 #include <linux/netdevice.h>
66 #include <linux/etherdevice.h>
68 #include <linux/if_arp.h>
69 #include <linux/time.h>
70 #include <net/mac80211.h>
71 #include <net/ieee80211_radiotap.h>
74 #include "iwl-op-mode.h"
78 #include "time-event.h"
79 #include "iwl-eeprom-parse.h"
80 #include "iwl-phy-db.h"
82 #include "fw/error-dump.h"
84 #include "iwl-nvm-parse.h"
86 static const struct ieee80211_iface_limit iwl_mvm_limits
[] = {
89 .types
= BIT(NL80211_IFTYPE_STATION
),
93 .types
= BIT(NL80211_IFTYPE_AP
) |
94 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
95 BIT(NL80211_IFTYPE_P2P_GO
),
99 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
103 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations
[] = {
105 .num_different_channels
= 2,
107 .limits
= iwl_mvm_limits
,
108 .n_limits
= ARRAY_SIZE(iwl_mvm_limits
),
112 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
114 * Use the reserved field to indicate magic values.
115 * these values will only be used internally by the driver,
116 * and won't make it to the fw (reserved will be 0).
117 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
118 * be the vif's ip address. in case there is not a single
119 * ip address (0, or more than 1), this attribute will
121 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
122 * the LSB bytes of the vif's mac address
125 BC_FILTER_MAGIC_NONE
= 0,
130 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters
[] = {
134 .frame_type
= BCAST_FILTER_FRAME_TYPE_ALL
,
137 /* frame type - arp, hw type - ethernet */
139 BCAST_FILTER_OFFSET_PAYLOAD_START
,
140 .offset
= sizeof(rfc1042_header
),
141 .val
= cpu_to_be32(0x08060001),
142 .mask
= cpu_to_be32(0xffffffff),
147 BCAST_FILTER_OFFSET_PAYLOAD_START
,
148 .offset
= sizeof(rfc1042_header
) + 2 +
149 sizeof(struct arphdr
) +
150 ETH_ALEN
+ sizeof(__be32
) +
152 .mask
= cpu_to_be32(0xffffffff),
153 /* mark it as special field */
154 .reserved1
= cpu_to_le16(BC_FILTER_MAGIC_IP
),
159 /* dhcp offer bcast */
161 .frame_type
= BCAST_FILTER_FRAME_TYPE_IPV4
,
164 /* udp dest port - 68 (bootp client)*/
165 .offset_type
= BCAST_FILTER_OFFSET_IP_END
,
166 .offset
= offsetof(struct udphdr
, dest
),
167 .val
= cpu_to_be32(0x00440000),
168 .mask
= cpu_to_be32(0xffff0000),
171 /* dhcp - lsb bytes of client hw address */
172 .offset_type
= BCAST_FILTER_OFFSET_IP_END
,
174 .mask
= cpu_to_be32(0xffffffff),
175 /* mark it as special field */
176 .reserved1
= cpu_to_le16(BC_FILTER_MAGIC_MAC
),
180 /* last filter must be empty */
185 static const struct cfg80211_pmsr_capabilities iwl_mvm_pmsr_capa
= {
186 .max_peers
= IWL_MVM_TOF_MAX_APS
,
188 .randomize_mac_addr
= 1,
195 .request_civicloc
= 1,
196 .max_bursts_exponent
= -1, /* all supported */
197 .max_ftms_per_burst
= 0, /* no limits */
198 .bandwidths
= BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
199 BIT(NL80211_CHAN_WIDTH_20
) |
200 BIT(NL80211_CHAN_WIDTH_40
) |
201 BIT(NL80211_CHAN_WIDTH_80
),
202 .preambles
= BIT(NL80211_PREAMBLE_LEGACY
) |
203 BIT(NL80211_PREAMBLE_HT
) |
204 BIT(NL80211_PREAMBLE_VHT
),
208 static int __iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
209 enum set_key_cmd cmd
,
210 struct ieee80211_vif
*vif
,
211 struct ieee80211_sta
*sta
,
212 struct ieee80211_key_conf
*key
);
214 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm
*mvm
)
218 memset(mvm
->phy_ctxts
, 0, sizeof(mvm
->phy_ctxts
));
219 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
220 mvm
->phy_ctxts
[i
].id
= i
;
221 mvm
->phy_ctxts
[i
].ref
= 0;
225 struct ieee80211_regdomain
*iwl_mvm_get_regdomain(struct wiphy
*wiphy
,
227 enum iwl_mcc_source src_id
,
230 struct ieee80211_regdomain
*regd
= NULL
;
231 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
232 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
233 struct iwl_mcc_update_resp
*resp
;
235 IWL_DEBUG_LAR(mvm
, "Getting regdomain data for %s from FW\n", alpha2
);
237 lockdep_assert_held(&mvm
->mutex
);
239 resp
= iwl_mvm_update_mcc(mvm
, alpha2
, src_id
);
240 if (IS_ERR_OR_NULL(resp
)) {
241 IWL_DEBUG_LAR(mvm
, "Could not get update from FW %d\n",
242 PTR_ERR_OR_ZERO(resp
));
247 u32 status
= le32_to_cpu(resp
->status
);
249 *changed
= (status
== MCC_RESP_NEW_CHAN_PROFILE
||
250 status
== MCC_RESP_ILLEGAL
);
253 regd
= iwl_parse_nvm_mcc_info(mvm
->trans
->dev
, mvm
->cfg
,
254 __le32_to_cpu(resp
->n_channels
),
256 __le16_to_cpu(resp
->mcc
),
257 __le16_to_cpu(resp
->geo_info
),
258 __le16_to_cpu(resp
->cap
));
259 /* Store the return source id */
260 src_id
= resp
->source_id
;
262 if (IS_ERR_OR_NULL(regd
)) {
263 IWL_DEBUG_LAR(mvm
, "Could not get parse update from FW %d\n",
264 PTR_ERR_OR_ZERO(regd
));
268 IWL_DEBUG_LAR(mvm
, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
269 regd
->alpha2
, regd
->alpha2
[0], regd
->alpha2
[1], src_id
);
270 mvm
->lar_regdom_set
= true;
271 mvm
->mcc_src
= src_id
;
277 void iwl_mvm_update_changed_regdom(struct iwl_mvm
*mvm
)
280 struct ieee80211_regdomain
*regd
;
282 if (!iwl_mvm_is_lar_supported(mvm
))
285 regd
= iwl_mvm_get_current_regdomain(mvm
, &changed
);
286 if (!IS_ERR_OR_NULL(regd
)) {
287 /* only update the regulatory core if changed */
289 regulatory_set_wiphy_regd(mvm
->hw
->wiphy
, regd
);
295 struct ieee80211_regdomain
*iwl_mvm_get_current_regdomain(struct iwl_mvm
*mvm
,
298 return iwl_mvm_get_regdomain(mvm
->hw
->wiphy
, "ZZ",
299 iwl_mvm_is_wifi_mcc_supported(mvm
) ?
300 MCC_SOURCE_GET_CURRENT
:
301 MCC_SOURCE_OLD_FW
, changed
);
304 int iwl_mvm_init_fw_regd(struct iwl_mvm
*mvm
)
306 enum iwl_mcc_source used_src
;
307 struct ieee80211_regdomain
*regd
;
310 const struct ieee80211_regdomain
*r
=
311 rtnl_dereference(mvm
->hw
->wiphy
->regd
);
316 /* save the last source in case we overwrite it below */
317 used_src
= mvm
->mcc_src
;
318 if (iwl_mvm_is_wifi_mcc_supported(mvm
)) {
319 /* Notify the firmware we support wifi location updates */
320 regd
= iwl_mvm_get_current_regdomain(mvm
, NULL
);
321 if (!IS_ERR_OR_NULL(regd
))
325 /* Now set our last stored MCC and source */
326 regd
= iwl_mvm_get_regdomain(mvm
->hw
->wiphy
, r
->alpha2
, used_src
,
328 if (IS_ERR_OR_NULL(regd
))
331 /* update cfg80211 if the regdomain was changed */
333 ret
= regulatory_set_wiphy_regd_sync_rtnl(mvm
->hw
->wiphy
, regd
);
341 static const u8 he_if_types_ext_capa_sta
[] = {
342 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING
,
343 [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT
,
344 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF
,
345 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT
,
348 static const struct wiphy_iftype_ext_capab he_iftypes_ext_capa
[] = {
350 .iftype
= NL80211_IFTYPE_STATION
,
351 .extended_capabilities
= he_if_types_ext_capa_sta
,
352 .extended_capabilities_mask
= he_if_types_ext_capa_sta
,
353 .extended_capabilities_len
= sizeof(he_if_types_ext_capa_sta
),
358 iwl_mvm_op_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
, u32
*rx_ant
)
360 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
361 *tx_ant
= iwl_mvm_get_valid_tx_ant(mvm
);
362 *rx_ant
= iwl_mvm_get_valid_rx_ant(mvm
);
366 int iwl_mvm_mac_setup_register(struct iwl_mvm
*mvm
)
368 struct ieee80211_hw
*hw
= mvm
->hw
;
370 static const u32 mvm_ciphers
[] = {
371 WLAN_CIPHER_SUITE_WEP40
,
372 WLAN_CIPHER_SUITE_WEP104
,
373 WLAN_CIPHER_SUITE_TKIP
,
374 WLAN_CIPHER_SUITE_CCMP
,
376 #ifdef CONFIG_PM_SLEEP
377 bool unified
= fw_has_capa(&mvm
->fw
->ucode_capa
,
378 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG
);
381 /* Tell mac80211 our characteristics */
382 ieee80211_hw_set(hw
, SIGNAL_DBM
);
383 ieee80211_hw_set(hw
, SPECTRUM_MGMT
);
384 ieee80211_hw_set(hw
, REPORTS_TX_ACK_STATUS
);
385 ieee80211_hw_set(hw
, WANT_MONITOR_VIF
);
386 ieee80211_hw_set(hw
, SUPPORTS_PS
);
387 ieee80211_hw_set(hw
, SUPPORTS_DYNAMIC_PS
);
388 ieee80211_hw_set(hw
, AMPDU_AGGREGATION
);
389 ieee80211_hw_set(hw
, TIMING_BEACON_ONLY
);
390 ieee80211_hw_set(hw
, CONNECTION_MONITOR
);
391 ieee80211_hw_set(hw
, CHANCTX_STA_CSA
);
392 ieee80211_hw_set(hw
, SUPPORT_FAST_XMIT
);
393 ieee80211_hw_set(hw
, SUPPORTS_CLONED_SKBS
);
394 ieee80211_hw_set(hw
, SUPPORTS_AMSDU_IN_AMPDU
);
395 ieee80211_hw_set(hw
, NEEDS_UNIQUE_STA_ADDR
);
396 ieee80211_hw_set(hw
, DEAUTH_NEED_MGD_TX_PREP
);
397 ieee80211_hw_set(hw
, SUPPORTS_VHT_EXT_NSS_BW
);
398 ieee80211_hw_set(hw
, BUFF_MMPDU_TXQ
);
399 ieee80211_hw_set(hw
, STA_MMPDU_TXQ
);
401 * On older devices, enabling TX A-MSDU occasionally leads to
402 * something getting messed up, the command read from the FIFO
403 * gets out of sync and isn't a TX command, so that we have an
406 * It's not clear where the bug is, but since we didn't used to
407 * support A-MSDU until moving the mac80211 iTXQs, just leave it
408 * for older devices. We also don't see this issue on any newer
411 if (mvm
->trans
->trans_cfg
->device_family
>= IWL_DEVICE_FAMILY_9000
)
412 ieee80211_hw_set(hw
, TX_AMSDU
);
413 ieee80211_hw_set(hw
, TX_FRAG_LIST
);
415 if (iwl_mvm_has_tlc_offload(mvm
)) {
416 ieee80211_hw_set(hw
, TX_AMPDU_SETUP_IN_HW
);
417 ieee80211_hw_set(hw
, HAS_RATE_CONTROL
);
420 if (iwl_mvm_has_new_rx_api(mvm
))
421 ieee80211_hw_set(hw
, SUPPORTS_REORDERING_BUFFER
);
423 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
424 IWL_UCODE_TLV_CAPA_STA_PM_NOTIF
)) {
425 ieee80211_hw_set(hw
, AP_LINK_PS
);
426 } else if (WARN_ON(iwl_mvm_has_new_tx_api(mvm
))) {
428 * we absolutely need this for the new TX API since that comes
429 * with many more queues than the current code can deal with
430 * for station powersave
435 if (mvm
->trans
->num_rx_queues
> 1)
436 ieee80211_hw_set(hw
, USES_RSS
);
438 if (mvm
->trans
->max_skb_frags
)
439 hw
->netdev_features
= NETIF_F_HIGHDMA
| NETIF_F_SG
;
441 hw
->queues
= IEEE80211_MAX_QUEUES
;
442 hw
->offchannel_tx_hw_queue
= IWL_MVM_OFFCHANNEL_QUEUE
;
443 hw
->radiotap_mcs_details
|= IEEE80211_RADIOTAP_MCS_HAVE_FEC
|
444 IEEE80211_RADIOTAP_MCS_HAVE_STBC
;
445 hw
->radiotap_vht_details
|= IEEE80211_RADIOTAP_VHT_KNOWN_STBC
|
446 IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED
;
448 hw
->radiotap_timestamp
.units_pos
=
449 IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US
|
450 IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ
;
451 /* this is the case for CCK frames, it's better (only 8) for OFDM */
452 hw
->radiotap_timestamp
.accuracy
= 22;
454 if (!iwl_mvm_has_tlc_offload(mvm
))
455 hw
->rate_control_algorithm
= RS_NAME
;
457 hw
->uapsd_queues
= IWL_MVM_UAPSD_QUEUES
;
458 hw
->uapsd_max_sp_len
= IWL_UAPSD_MAX_SP
;
459 hw
->max_tx_fragments
= mvm
->trans
->max_skb_frags
;
461 BUILD_BUG_ON(ARRAY_SIZE(mvm
->ciphers
) < ARRAY_SIZE(mvm_ciphers
) + 6);
462 memcpy(mvm
->ciphers
, mvm_ciphers
, sizeof(mvm_ciphers
));
463 hw
->wiphy
->n_cipher_suites
= ARRAY_SIZE(mvm_ciphers
);
464 hw
->wiphy
->cipher_suites
= mvm
->ciphers
;
466 if (iwl_mvm_has_new_rx_api(mvm
)) {
467 mvm
->ciphers
[hw
->wiphy
->n_cipher_suites
] =
468 WLAN_CIPHER_SUITE_GCMP
;
469 hw
->wiphy
->n_cipher_suites
++;
470 mvm
->ciphers
[hw
->wiphy
->n_cipher_suites
] =
471 WLAN_CIPHER_SUITE_GCMP_256
;
472 hw
->wiphy
->n_cipher_suites
++;
475 /* Enable 11w if software crypto is not enabled (as the
476 * firmware will interpret some mgmt packets, so enabling it
477 * with software crypto isn't safe).
479 if (!iwlwifi_mod_params
.swcrypto
) {
480 ieee80211_hw_set(hw
, MFP_CAPABLE
);
481 mvm
->ciphers
[hw
->wiphy
->n_cipher_suites
] =
482 WLAN_CIPHER_SUITE_AES_CMAC
;
483 hw
->wiphy
->n_cipher_suites
++;
484 if (iwl_mvm_has_new_rx_api(mvm
)) {
485 mvm
->ciphers
[hw
->wiphy
->n_cipher_suites
] =
486 WLAN_CIPHER_SUITE_BIP_GMAC_128
;
487 hw
->wiphy
->n_cipher_suites
++;
488 mvm
->ciphers
[hw
->wiphy
->n_cipher_suites
] =
489 WLAN_CIPHER_SUITE_BIP_GMAC_256
;
490 hw
->wiphy
->n_cipher_suites
++;
494 /* currently FW API supports only one optional cipher scheme */
495 if (mvm
->fw
->cs
[0].cipher
) {
496 const struct iwl_fw_cipher_scheme
*fwcs
= &mvm
->fw
->cs
[0];
497 struct ieee80211_cipher_scheme
*cs
= &mvm
->cs
[0];
499 mvm
->hw
->n_cipher_schemes
= 1;
501 cs
->cipher
= le32_to_cpu(fwcs
->cipher
);
502 cs
->iftype
= BIT(NL80211_IFTYPE_STATION
);
503 cs
->hdr_len
= fwcs
->hdr_len
;
504 cs
->pn_len
= fwcs
->pn_len
;
505 cs
->pn_off
= fwcs
->pn_off
;
506 cs
->key_idx_off
= fwcs
->key_idx_off
;
507 cs
->key_idx_mask
= fwcs
->key_idx_mask
;
508 cs
->key_idx_shift
= fwcs
->key_idx_shift
;
509 cs
->mic_len
= fwcs
->mic_len
;
511 mvm
->hw
->cipher_schemes
= mvm
->cs
;
512 mvm
->ciphers
[hw
->wiphy
->n_cipher_suites
] = cs
->cipher
;
513 hw
->wiphy
->n_cipher_suites
++;
516 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
517 IWL_UCODE_TLV_CAPA_FTM_CALIBRATED
)) {
518 wiphy_ext_feature_set(hw
->wiphy
,
519 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER
);
520 hw
->wiphy
->pmsr_capa
= &iwl_mvm_pmsr_capa
;
523 ieee80211_hw_set(hw
, SINGLE_SCAN_ON_ALL_BANDS
);
524 hw
->wiphy
->features
|=
525 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR
|
526 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
|
527 NL80211_FEATURE_ND_RANDOM_MAC_ADDR
;
529 hw
->sta_data_size
= sizeof(struct iwl_mvm_sta
);
530 hw
->vif_data_size
= sizeof(struct iwl_mvm_vif
);
531 hw
->chanctx_data_size
= sizeof(u16
);
532 hw
->txq_data_size
= sizeof(struct iwl_mvm_txq
);
534 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
535 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
536 BIT(NL80211_IFTYPE_AP
) |
537 BIT(NL80211_IFTYPE_P2P_GO
) |
538 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
539 BIT(NL80211_IFTYPE_ADHOC
);
541 hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
542 wiphy_ext_feature_set(hw
->wiphy
, NL80211_EXT_FEATURE_VHT_IBSS
);
543 hw
->wiphy
->features
|= NL80211_FEATURE_HT_IBSS
;
545 hw
->wiphy
->regulatory_flags
|= REGULATORY_ENABLE_RELAX_NO_IR
;
546 if (iwl_mvm_is_lar_supported(mvm
))
547 hw
->wiphy
->regulatory_flags
|= REGULATORY_WIPHY_SELF_MANAGED
;
549 hw
->wiphy
->regulatory_flags
|= REGULATORY_CUSTOM_REG
|
550 REGULATORY_DISABLE_BEACON_HINTS
;
552 hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
553 hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
555 hw
->wiphy
->iface_combinations
= iwl_mvm_iface_combinations
;
556 hw
->wiphy
->n_iface_combinations
=
557 ARRAY_SIZE(iwl_mvm_iface_combinations
);
559 hw
->wiphy
->max_remain_on_channel_duration
= 10000;
560 hw
->max_listen_interval
= IWL_CONN_MAX_LISTEN_INTERVAL
;
562 /* Extract MAC address */
563 memcpy(mvm
->addresses
[0].addr
, mvm
->nvm_data
->hw_addr
, ETH_ALEN
);
564 hw
->wiphy
->addresses
= mvm
->addresses
;
565 hw
->wiphy
->n_addresses
= 1;
567 /* Extract additional MAC addresses if available */
568 num_mac
= (mvm
->nvm_data
->n_hw_addrs
> 1) ?
569 min(IWL_MVM_MAX_ADDRESSES
, mvm
->nvm_data
->n_hw_addrs
) : 1;
571 for (i
= 1; i
< num_mac
; i
++) {
572 memcpy(mvm
->addresses
[i
].addr
, mvm
->addresses
[i
-1].addr
,
574 mvm
->addresses
[i
].addr
[5]++;
575 hw
->wiphy
->n_addresses
++;
578 iwl_mvm_reset_phy_ctxts(mvm
);
580 hw
->wiphy
->max_scan_ie_len
= iwl_mvm_max_scan_ie_len(mvm
);
582 hw
->wiphy
->max_scan_ssids
= PROBE_OPTION_MAX
;
584 BUILD_BUG_ON(IWL_MVM_SCAN_STOPPING_MASK
& IWL_MVM_SCAN_MASK
);
585 BUILD_BUG_ON(IWL_MVM_MAX_UMAC_SCANS
> HWEIGHT32(IWL_MVM_SCAN_MASK
) ||
586 IWL_MVM_MAX_LMAC_SCANS
> HWEIGHT32(IWL_MVM_SCAN_MASK
));
588 if (fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_UMAC_SCAN
))
589 mvm
->max_scans
= IWL_MVM_MAX_UMAC_SCANS
;
591 mvm
->max_scans
= IWL_MVM_MAX_LMAC_SCANS
;
593 if (mvm
->nvm_data
->bands
[NL80211_BAND_2GHZ
].n_channels
)
594 hw
->wiphy
->bands
[NL80211_BAND_2GHZ
] =
595 &mvm
->nvm_data
->bands
[NL80211_BAND_2GHZ
];
596 if (mvm
->nvm_data
->bands
[NL80211_BAND_5GHZ
].n_channels
) {
597 hw
->wiphy
->bands
[NL80211_BAND_5GHZ
] =
598 &mvm
->nvm_data
->bands
[NL80211_BAND_5GHZ
];
600 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
601 IWL_UCODE_TLV_CAPA_BEAMFORMER
) &&
602 fw_has_api(&mvm
->fw
->ucode_capa
,
603 IWL_UCODE_TLV_API_LQ_SS_PARAMS
))
604 hw
->wiphy
->bands
[NL80211_BAND_5GHZ
]->vht_cap
.cap
|=
605 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE
;
608 hw
->wiphy
->hw_version
= mvm
->trans
->hw_id
;
610 if (iwlmvm_mod_params
.power_scheme
!= IWL_POWER_SCHEME_CAM
)
611 hw
->wiphy
->flags
|= WIPHY_FLAG_PS_ON_BY_DEFAULT
;
613 hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
615 hw
->wiphy
->max_sched_scan_reqs
= 1;
616 hw
->wiphy
->max_sched_scan_ssids
= PROBE_OPTION_MAX
;
617 hw
->wiphy
->max_match_sets
= IWL_SCAN_MAX_PROFILES
;
618 /* we create the 802.11 header and zero length SSID IE. */
619 hw
->wiphy
->max_sched_scan_ie_len
=
620 SCAN_OFFLOAD_PROBE_REQ_SIZE
- 24 - 2;
621 hw
->wiphy
->max_sched_scan_plans
= IWL_MAX_SCHED_SCAN_PLANS
;
622 hw
->wiphy
->max_sched_scan_plan_interval
= U16_MAX
;
625 * the firmware uses u8 for num of iterations, but 0xff is saved for
626 * infinite loop, so the maximum number of iterations is actually 254.
628 hw
->wiphy
->max_sched_scan_plan_iterations
= 254;
630 hw
->wiphy
->features
|= NL80211_FEATURE_P2P_GO_CTWIN
|
631 NL80211_FEATURE_LOW_PRIORITY_SCAN
|
632 NL80211_FEATURE_P2P_GO_OPPPS
|
633 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
|
634 NL80211_FEATURE_DYNAMIC_SMPS
|
635 NL80211_FEATURE_STATIC_SMPS
|
636 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION
;
638 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
639 IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT
))
640 hw
->wiphy
->features
|= NL80211_FEATURE_TX_POWER_INSERTION
;
641 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
642 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT
))
643 hw
->wiphy
->features
|= NL80211_FEATURE_QUIET
;
645 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
646 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT
))
647 hw
->wiphy
->features
|=
648 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES
;
650 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
651 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT
))
652 hw
->wiphy
->features
|= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES
;
654 if (fw_has_api(&mvm
->fw
->ucode_capa
,
655 IWL_UCODE_TLV_API_SCAN_TSF_REPORT
)) {
656 wiphy_ext_feature_set(hw
->wiphy
,
657 NL80211_EXT_FEATURE_SCAN_START_TIME
);
658 wiphy_ext_feature_set(hw
->wiphy
,
659 NL80211_EXT_FEATURE_BSS_PARENT_TSF
);
660 wiphy_ext_feature_set(hw
->wiphy
,
661 NL80211_EXT_FEATURE_SET_SCAN_DWELL
);
664 if (iwl_mvm_is_oce_supported(mvm
)) {
665 wiphy_ext_feature_set(hw
->wiphy
,
666 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP
);
667 wiphy_ext_feature_set(hw
->wiphy
,
668 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME
);
669 wiphy_ext_feature_set(hw
->wiphy
,
670 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION
);
671 wiphy_ext_feature_set(hw
->wiphy
,
672 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE
);
675 if (mvm
->nvm_data
->sku_cap_11ax_enable
&&
676 !iwlwifi_mod_params
.disable_11ax
) {
677 hw
->wiphy
->iftype_ext_capab
= he_iftypes_ext_capa
;
678 hw
->wiphy
->num_iftype_ext_capab
=
679 ARRAY_SIZE(he_iftypes_ext_capa
);
681 ieee80211_hw_set(hw
, SUPPORTS_MULTI_BSSID
);
682 ieee80211_hw_set(hw
, SUPPORTS_ONLY_HE_MULTI_BSSID
);
685 mvm
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
687 #ifdef CONFIG_PM_SLEEP
688 if ((unified
|| mvm
->fw
->img
[IWL_UCODE_WOWLAN
].num_sec
) &&
689 mvm
->trans
->ops
->d3_suspend
&&
690 mvm
->trans
->ops
->d3_resume
&&
691 device_can_wakeup(mvm
->trans
->dev
)) {
692 mvm
->wowlan
.flags
|= WIPHY_WOWLAN_MAGIC_PKT
|
693 WIPHY_WOWLAN_DISCONNECT
|
694 WIPHY_WOWLAN_EAP_IDENTITY_REQ
|
695 WIPHY_WOWLAN_RFKILL_RELEASE
|
696 WIPHY_WOWLAN_NET_DETECT
;
697 if (!iwlwifi_mod_params
.swcrypto
)
698 mvm
->wowlan
.flags
|= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
|
699 WIPHY_WOWLAN_GTK_REKEY_FAILURE
|
700 WIPHY_WOWLAN_4WAY_HANDSHAKE
;
702 mvm
->wowlan
.n_patterns
= IWL_WOWLAN_MAX_PATTERNS
;
703 mvm
->wowlan
.pattern_min_len
= IWL_WOWLAN_MIN_PATTERN_LEN
;
704 mvm
->wowlan
.pattern_max_len
= IWL_WOWLAN_MAX_PATTERN_LEN
;
705 mvm
->wowlan
.max_nd_match_sets
= IWL_SCAN_MAX_PROFILES
;
706 hw
->wiphy
->wowlan
= &mvm
->wowlan
;
710 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
711 /* assign default bcast filtering configuration */
712 mvm
->bcast_filters
= iwl_mvm_default_bcast_filters
;
715 ret
= iwl_mvm_leds_init(mvm
);
719 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
720 IWL_UCODE_TLV_CAPA_TDLS_SUPPORT
)) {
721 IWL_DEBUG_TDLS(mvm
, "TDLS supported\n");
722 hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_TDLS
;
723 ieee80211_hw_set(hw
, TDLS_WIDER_BW
);
726 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
727 IWL_UCODE_TLV_CAPA_TDLS_CHANNEL_SWITCH
)) {
728 IWL_DEBUG_TDLS(mvm
, "TDLS channel switch supported\n");
729 hw
->wiphy
->features
|= NL80211_FEATURE_TDLS_CHANNEL_SWITCH
;
732 hw
->netdev_features
|= mvm
->cfg
->features
;
733 if (!iwl_mvm_is_csum_supported(mvm
)) {
734 hw
->netdev_features
&= ~(IWL_TX_CSUM_NETIF_FLAGS
|
736 /* We may support SW TX CSUM */
737 if (IWL_MVM_SW_TX_CSUM_OFFLOAD
)
738 hw
->netdev_features
|= IWL_TX_CSUM_NETIF_FLAGS
;
741 if (mvm
->cfg
->vht_mu_mimo_supported
)
742 wiphy_ext_feature_set(hw
->wiphy
,
743 NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER
);
745 hw
->wiphy
->available_antennas_tx
= iwl_mvm_get_valid_tx_ant(mvm
);
746 hw
->wiphy
->available_antennas_rx
= iwl_mvm_get_valid_rx_ant(mvm
);
748 ret
= ieee80211_register_hw(mvm
->hw
);
750 iwl_mvm_leds_exit(mvm
);
756 static void iwl_mvm_tx_skb(struct iwl_mvm
*mvm
, struct sk_buff
*skb
,
757 struct ieee80211_sta
*sta
)
760 if (likely(iwl_mvm_tx_skb_sta(mvm
, skb
, sta
) == 0))
763 if (likely(iwl_mvm_tx_skb_non_sta(mvm
, skb
) == 0))
767 ieee80211_free_txskb(mvm
->hw
, skb
);
770 static void iwl_mvm_mac_tx(struct ieee80211_hw
*hw
,
771 struct ieee80211_tx_control
*control
,
774 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
775 struct ieee80211_sta
*sta
= control
->sta
;
776 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
777 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
778 bool offchannel
= IEEE80211_SKB_CB(skb
)->flags
&
779 IEEE80211_TX_CTL_TX_OFFCHAN
;
781 if (iwl_mvm_is_radio_killed(mvm
)) {
782 IWL_DEBUG_DROP(mvm
, "Dropping - RF/CT KILL\n");
787 !test_bit(IWL_MVM_STATUS_ROC_RUNNING
, &mvm
->status
) &&
788 !test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING
, &mvm
->status
))
791 /* treat non-bufferable MMPDUs on AP interfaces as broadcast */
792 if ((info
->control
.vif
->type
== NL80211_IFTYPE_AP
||
793 info
->control
.vif
->type
== NL80211_IFTYPE_ADHOC
) &&
794 ieee80211_is_mgmt(hdr
->frame_control
) &&
795 !ieee80211_is_bufferable_mmpdu(hdr
->frame_control
))
798 /* If there is no sta, and it's not offchannel - send through AP */
799 if (!sta
&& info
->control
.vif
->type
== NL80211_IFTYPE_STATION
&&
801 struct iwl_mvm_vif
*mvmvif
=
802 iwl_mvm_vif_from_mac80211(info
->control
.vif
);
803 u8 ap_sta_id
= READ_ONCE(mvmvif
->ap_sta_id
);
805 if (ap_sta_id
< IWL_MVM_STATION_COUNT
) {
806 /* mac80211 holds rcu read lock */
807 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[ap_sta_id
]);
808 if (IS_ERR_OR_NULL(sta
))
813 iwl_mvm_tx_skb(mvm
, skb
, sta
);
816 ieee80211_free_txskb(hw
, skb
);
819 void iwl_mvm_mac_itxq_xmit(struct ieee80211_hw
*hw
, struct ieee80211_txq
*txq
)
821 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
822 struct iwl_mvm_txq
*mvmtxq
= iwl_mvm_txq_from_mac80211(txq
);
823 struct sk_buff
*skb
= NULL
;
826 * No need for threads to be pending here, they can leave the first
827 * taker all the work.
829 * mvmtxq->tx_request logic:
831 * If 0, no one is currently TXing, set to 1 to indicate current thread
832 * will now start TX and other threads should quit.
834 * If 1, another thread is currently TXing, set to 2 to indicate to
835 * that thread that there was another request. Since that request may
836 * have raced with the check whether the queue is empty, the TXing
837 * thread should check the queue's status one more time before leaving.
838 * This check is done in order to not leave any TX hanging in the queue
839 * until the next TX invocation (which may not even happen).
841 * If 2, another thread is currently TXing, and it will already double
842 * check the queue, so do nothing.
844 if (atomic_fetch_add_unless(&mvmtxq
->tx_request
, 1, 2))
849 while (likely(!mvmtxq
->stopped
&&
850 (mvm
->trans
->system_pm_mode
==
851 IWL_PLAT_PM_MODE_DISABLED
))) {
852 skb
= ieee80211_tx_dequeue(hw
, txq
);
857 "TXQ of sta %pM tid %d is now empty\n",
863 iwl_mvm_tx_skb(mvm
, skb
, txq
->sta
);
865 } while (atomic_dec_return(&mvmtxq
->tx_request
));
869 static void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw
*hw
,
870 struct ieee80211_txq
*txq
)
872 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
873 struct iwl_mvm_txq
*mvmtxq
= iwl_mvm_txq_from_mac80211(txq
);
876 * Please note that racing is handled very carefully here:
877 * mvmtxq->txq_id is updated during allocation, and mvmtxq->list is
878 * deleted afterwards.
879 * This means that if:
880 * mvmtxq->txq_id != INVALID_QUEUE && list_empty(&mvmtxq->list):
881 * queue is allocated and we can TX.
882 * mvmtxq->txq_id != INVALID_QUEUE && !list_empty(&mvmtxq->list):
883 * a race, should defer the frame.
884 * mvmtxq->txq_id == INVALID_QUEUE && list_empty(&mvmtxq->list):
885 * need to allocate the queue and defer the frame.
886 * mvmtxq->txq_id == INVALID_QUEUE && !list_empty(&mvmtxq->list):
887 * queue is already scheduled for allocation, no need to allocate,
888 * should defer the frame.
891 /* If the queue is allocated TX and return. */
892 if (!txq
->sta
|| mvmtxq
->txq_id
!= IWL_MVM_INVALID_QUEUE
) {
894 * Check that list is empty to avoid a race where txq_id is
895 * already updated, but the queue allocation work wasn't
898 if (unlikely(txq
->sta
&& !list_empty(&mvmtxq
->list
)))
901 iwl_mvm_mac_itxq_xmit(hw
, txq
);
905 /* The list is being deleted only after the queue is fully allocated. */
906 if (!list_empty(&mvmtxq
->list
))
909 list_add_tail(&mvmtxq
->list
, &mvm
->add_stream_txqs
);
910 schedule_work(&mvm
->add_stream_wk
);
913 #define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \
915 if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \
917 iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
921 iwl_mvm_ampdu_check_trigger(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
922 struct ieee80211_sta
*sta
, u16 tid
, u16 rx_ba_ssn
,
923 enum ieee80211_ampdu_mlme_action action
)
925 struct iwl_fw_dbg_trigger_tlv
*trig
;
926 struct iwl_fw_dbg_trigger_ba
*ba_trig
;
928 trig
= iwl_fw_dbg_trigger_on(&mvm
->fwrt
, ieee80211_vif_to_wdev(vif
),
933 ba_trig
= (void *)trig
->data
;
936 case IEEE80211_AMPDU_TX_OPERATIONAL
: {
937 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
938 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
940 CHECK_BA_TRIGGER(mvm
, trig
, ba_trig
->tx_ba_start
, tid
,
941 "TX AGG START: MAC %pM tid %d ssn %d\n",
942 sta
->addr
, tid
, tid_data
->ssn
);
945 case IEEE80211_AMPDU_TX_STOP_CONT
:
946 CHECK_BA_TRIGGER(mvm
, trig
, ba_trig
->tx_ba_stop
, tid
,
947 "TX AGG STOP: MAC %pM tid %d\n",
950 case IEEE80211_AMPDU_RX_START
:
951 CHECK_BA_TRIGGER(mvm
, trig
, ba_trig
->rx_ba_start
, tid
,
952 "RX AGG START: MAC %pM tid %d ssn %d\n",
953 sta
->addr
, tid
, rx_ba_ssn
);
955 case IEEE80211_AMPDU_RX_STOP
:
956 CHECK_BA_TRIGGER(mvm
, trig
, ba_trig
->rx_ba_stop
, tid
,
957 "RX AGG STOP: MAC %pM tid %d\n",
965 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw
*hw
,
966 struct ieee80211_vif
*vif
,
967 struct ieee80211_ampdu_params
*params
)
969 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
971 struct ieee80211_sta
*sta
= params
->sta
;
972 enum ieee80211_ampdu_mlme_action action
= params
->action
;
973 u16 tid
= params
->tid
;
974 u16
*ssn
= ¶ms
->ssn
;
975 u16 buf_size
= params
->buf_size
;
976 bool amsdu
= params
->amsdu
;
977 u16 timeout
= params
->timeout
;
979 IWL_DEBUG_HT(mvm
, "A-MPDU action on addr %pM tid %d: action %d\n",
980 sta
->addr
, tid
, action
);
982 if (!(mvm
->nvm_data
->sku_cap_11n_enable
))
985 mutex_lock(&mvm
->mutex
);
988 case IEEE80211_AMPDU_RX_START
:
989 if (iwl_mvm_vif_from_mac80211(vif
)->ap_sta_id
==
990 iwl_mvm_sta_from_mac80211(sta
)->sta_id
) {
991 struct iwl_mvm_vif
*mvmvif
;
992 u16 macid
= iwl_mvm_vif_from_mac80211(vif
)->id
;
993 struct iwl_mvm_tcm_mac
*mdata
= &mvm
->tcm
.data
[macid
];
995 mdata
->opened_rx_ba_sessions
= true;
996 mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
997 cancel_delayed_work(&mvmvif
->uapsd_nonagg_detected_wk
);
999 if (!iwl_enable_rx_ampdu()) {
1003 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, *ssn
, true, buf_size
,
1006 case IEEE80211_AMPDU_RX_STOP
:
1007 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, 0, false, buf_size
,
1010 case IEEE80211_AMPDU_TX_START
:
1011 if (!iwl_enable_tx_ampdu()) {
1015 ret
= iwl_mvm_sta_tx_agg_start(mvm
, vif
, sta
, tid
, ssn
);
1017 case IEEE80211_AMPDU_TX_STOP_CONT
:
1018 ret
= iwl_mvm_sta_tx_agg_stop(mvm
, vif
, sta
, tid
);
1020 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1021 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1022 ret
= iwl_mvm_sta_tx_agg_flush(mvm
, vif
, sta
, tid
);
1024 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1025 ret
= iwl_mvm_sta_tx_agg_oper(mvm
, vif
, sta
, tid
,
1037 if (action
== IEEE80211_AMPDU_RX_START
)
1040 iwl_mvm_ampdu_check_trigger(mvm
, vif
, sta
, tid
,
1043 mutex_unlock(&mvm
->mutex
);
1048 static void iwl_mvm_cleanup_iterator(void *data
, u8
*mac
,
1049 struct ieee80211_vif
*vif
)
1051 struct iwl_mvm
*mvm
= data
;
1052 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1054 mvmvif
->uploaded
= false;
1055 mvmvif
->ap_sta_id
= IWL_MVM_INVALID_STA
;
1057 spin_lock_bh(&mvm
->time_event_lock
);
1058 iwl_mvm_te_clear_data(mvm
, &mvmvif
->time_event_data
);
1059 spin_unlock_bh(&mvm
->time_event_lock
);
1061 mvmvif
->phy_ctxt
= NULL
;
1062 memset(&mvmvif
->bf_data
, 0, sizeof(mvmvif
->bf_data
));
1063 memset(&mvmvif
->probe_resp_data
, 0, sizeof(mvmvif
->probe_resp_data
));
1066 static void iwl_mvm_restart_cleanup(struct iwl_mvm
*mvm
)
1068 iwl_mvm_stop_device(mvm
);
1072 mvm
->scan_status
= 0;
1073 mvm
->ps_disabled
= false;
1074 mvm
->rfkill_safe_init_done
= false;
1076 /* just in case one was running */
1077 iwl_mvm_cleanup_roc_te(mvm
);
1078 ieee80211_remain_on_channel_expired(mvm
->hw
);
1080 iwl_mvm_ftm_restart(mvm
);
1083 * cleanup all interfaces, even inactive ones, as some might have
1084 * gone down during the HW restart
1086 ieee80211_iterate_interfaces(mvm
->hw
, 0, iwl_mvm_cleanup_iterator
, mvm
);
1088 mvm
->p2p_device_vif
= NULL
;
1090 iwl_mvm_reset_phy_ctxts(mvm
);
1091 memset(mvm
->fw_key_table
, 0, sizeof(mvm
->fw_key_table
));
1092 memset(&mvm
->last_bt_notif
, 0, sizeof(mvm
->last_bt_notif
));
1093 memset(&mvm
->last_bt_ci_cmd
, 0, sizeof(mvm
->last_bt_ci_cmd
));
1095 ieee80211_wake_queues(mvm
->hw
);
1098 mvm
->rx_ba_sessions
= 0;
1099 mvm
->fwrt
.dump
.conf
= FW_DBG_INVALID
;
1100 mvm
->monitor_on
= false;
1102 /* keep statistics ticking */
1103 iwl_mvm_accu_radio_stats(mvm
);
1106 int __iwl_mvm_mac_start(struct iwl_mvm
*mvm
)
1110 lockdep_assert_held(&mvm
->mutex
);
1112 if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED
, &mvm
->status
)) {
1114 * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART
1115 * so later code will - from now on - see that we're doing it.
1117 set_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
1118 clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED
, &mvm
->status
);
1119 /* Clean up some internal and mac80211 state on restart */
1120 iwl_mvm_restart_cleanup(mvm
);
1122 ret
= iwl_mvm_up(mvm
);
1124 iwl_dbg_tlv_time_point(&mvm
->fwrt
, IWL_FW_INI_TIME_POINT_POST_INIT
,
1126 iwl_dbg_tlv_time_point(&mvm
->fwrt
, IWL_FW_INI_TIME_POINT_PERIODIC
,
1129 if (ret
&& test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
1130 /* Something went wrong - we need to finish some cleanup
1131 * that normally iwl_mvm_mac_restart_complete() below
1134 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
1140 static int iwl_mvm_mac_start(struct ieee80211_hw
*hw
)
1142 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1145 mutex_lock(&mvm
->mutex
);
1146 ret
= __iwl_mvm_mac_start(mvm
);
1147 mutex_unlock(&mvm
->mutex
);
1152 static void iwl_mvm_restart_complete(struct iwl_mvm
*mvm
)
1156 mutex_lock(&mvm
->mutex
);
1158 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
1160 ret
= iwl_mvm_update_quotas(mvm
, true, NULL
);
1162 IWL_ERR(mvm
, "Failed to update quotas after restart (%d)\n",
1165 iwl_mvm_send_recovery_cmd(mvm
, ERROR_RECOVERY_END_OF_RECOVERY
);
1168 * If we have TDLS peers, remove them. We don't know the last seqno/PN
1169 * of packets the FW sent out, so we must reconnect.
1171 iwl_mvm_teardown_tdls_peers(mvm
);
1173 mutex_unlock(&mvm
->mutex
);
1177 iwl_mvm_mac_reconfig_complete(struct ieee80211_hw
*hw
,
1178 enum ieee80211_reconfig_type reconfig_type
)
1180 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1182 switch (reconfig_type
) {
1183 case IEEE80211_RECONFIG_TYPE_RESTART
:
1184 iwl_mvm_restart_complete(mvm
);
1186 case IEEE80211_RECONFIG_TYPE_SUSPEND
:
1191 void __iwl_mvm_mac_stop(struct iwl_mvm
*mvm
)
1193 lockdep_assert_held(&mvm
->mutex
);
1195 /* firmware counters are obviously reset now, but we shouldn't
1196 * partially track so also clear the fw_reset_accu counters.
1198 memset(&mvm
->accu_radio_stats
, 0, sizeof(mvm
->accu_radio_stats
));
1200 /* async_handlers_wk is now blocked */
1203 * The work item could be running or queued if the
1204 * ROC time event stops just as we get here.
1206 flush_work(&mvm
->roc_done_wk
);
1208 iwl_mvm_stop_device(mvm
);
1210 iwl_mvm_async_handlers_purge(mvm
);
1211 /* async_handlers_list is empty and will stay empty: HW is stopped */
1213 /* the fw is stopped, the aux sta is dead: clean up driver state */
1214 iwl_mvm_del_aux_sta(mvm
);
1217 * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the
1218 * hw (as restart_complete() won't be called in this case) and mac80211
1219 * won't execute the restart.
1220 * But make sure to cleanup interfaces that have gone down before/during
1221 * HW restart was requested.
1223 if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
) ||
1224 test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED
,
1226 ieee80211_iterate_interfaces(mvm
->hw
, 0,
1227 iwl_mvm_cleanup_iterator
, mvm
);
1229 /* We shouldn't have any UIDs still set. Loop over all the UIDs to
1230 * make sure there's nothing left there and warn if any is found.
1232 if (fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_UMAC_SCAN
)) {
1235 for (i
= 0; i
< mvm
->max_scans
; i
++) {
1236 if (WARN_ONCE(mvm
->scan_uid_status
[i
],
1237 "UMAC scan UID %d status was not cleaned\n",
1239 mvm
->scan_uid_status
[i
] = 0;
1244 static void iwl_mvm_mac_stop(struct ieee80211_hw
*hw
)
1246 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1248 flush_work(&mvm
->async_handlers_wk
);
1249 flush_work(&mvm
->add_stream_wk
);
1252 * Lock and clear the firmware running bit here already, so that
1253 * new commands coming in elsewhere, e.g. from debugfs, will not
1254 * be able to proceed. This is important here because one of those
1255 * debugfs files causes the firmware dump to be triggered, and if we
1256 * don't stop debugfs accesses before canceling that it could be
1257 * retriggered after we flush it but before we've cleared the bit.
1259 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING
, &mvm
->status
);
1261 cancel_delayed_work_sync(&mvm
->cs_tx_unblock_dwork
);
1262 cancel_delayed_work_sync(&mvm
->scan_timeout_dwork
);
1263 iwl_fw_free_dump_desc(&mvm
->fwrt
);
1265 mutex_lock(&mvm
->mutex
);
1266 __iwl_mvm_mac_stop(mvm
);
1267 mutex_unlock(&mvm
->mutex
);
1270 * The worker might have been waiting for the mutex, let it run and
1271 * discover that its list is now empty.
1273 cancel_work_sync(&mvm
->async_handlers_wk
);
1276 static struct iwl_mvm_phy_ctxt
*iwl_mvm_get_free_phy_ctxt(struct iwl_mvm
*mvm
)
1280 lockdep_assert_held(&mvm
->mutex
);
1282 for (i
= 0; i
< NUM_PHY_CTX
; i
++)
1283 if (!mvm
->phy_ctxts
[i
].ref
)
1284 return &mvm
->phy_ctxts
[i
];
1286 IWL_ERR(mvm
, "No available PHY context\n");
1290 static int iwl_mvm_set_tx_power(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1295 struct iwl_dev_tx_power_cmd v5
;
1296 struct iwl_dev_tx_power_cmd_v4 v4
;
1298 .v5
.v3
.set_mode
= cpu_to_le32(IWL_TX_POWER_MODE_SET_MAC
),
1299 .v5
.v3
.mac_context_id
=
1300 cpu_to_le32(iwl_mvm_vif_from_mac80211(vif
)->id
),
1301 .v5
.v3
.pwr_restriction
= cpu_to_le16(8 * tx_power
),
1304 if (tx_power
== IWL_DEFAULT_MAX_TX_POWER
)
1305 cmd
.v5
.v3
.pwr_restriction
= cpu_to_le16(IWL_DEV_MAX_TX_POWER
);
1307 if (fw_has_api(&mvm
->fw
->ucode_capa
,
1308 IWL_UCODE_TLV_API_REDUCE_TX_POWER
))
1309 len
= sizeof(cmd
.v5
);
1310 else if (fw_has_capa(&mvm
->fw
->ucode_capa
,
1311 IWL_UCODE_TLV_CAPA_TX_POWER_ACK
))
1312 len
= sizeof(cmd
.v4
);
1314 len
= sizeof(cmd
.v4
.v3
);
1316 return iwl_mvm_send_cmd_pdu(mvm
, REDUCE_TX_POWER_CMD
, 0, len
, &cmd
);
1319 static int iwl_mvm_post_channel_switch(struct ieee80211_hw
*hw
,
1320 struct ieee80211_vif
*vif
)
1322 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1323 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1326 mutex_lock(&mvm
->mutex
);
1328 if (mvmvif
->csa_failed
) {
1329 mvmvif
->csa_failed
= false;
1334 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1335 struct iwl_mvm_sta
*mvmsta
;
1337 mvmvif
->csa_bcn_pending
= false;
1338 mvmsta
= iwl_mvm_sta_from_staid_protected(mvm
,
1341 if (WARN_ON(!mvmsta
)) {
1346 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
1347 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD
))
1348 iwl_mvm_sta_modify_disable_tx(mvm
, mvmsta
, false);
1350 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
1352 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
1353 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD
)) {
1354 ret
= iwl_mvm_enable_beacon_filter(mvm
, vif
, 0);
1358 iwl_mvm_stop_session_protection(mvm
, vif
);
1362 mvmvif
->ps_disabled
= false;
1364 ret
= iwl_mvm_power_update_ps(mvm
);
1367 mutex_unlock(&mvm
->mutex
);
1372 static void iwl_mvm_abort_channel_switch(struct ieee80211_hw
*hw
,
1373 struct ieee80211_vif
*vif
)
1375 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1376 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1377 struct iwl_chan_switch_te_cmd cmd
= {
1378 .mac_id
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->id
,
1380 .action
= cpu_to_le32(FW_CTXT_ACTION_REMOVE
),
1383 IWL_DEBUG_MAC80211(mvm
, "Abort CSA on mac %d\n", mvmvif
->id
);
1385 mutex_lock(&mvm
->mutex
);
1386 WARN_ON(iwl_mvm_send_cmd_pdu(mvm
,
1387 WIDE_ID(MAC_CONF_GROUP
,
1388 CHANNEL_SWITCH_TIME_EVENT_CMD
),
1389 0, sizeof(cmd
), &cmd
));
1390 mutex_unlock(&mvm
->mutex
);
1392 WARN_ON(iwl_mvm_post_channel_switch(hw
, vif
));
1395 static void iwl_mvm_channel_switch_disconnect_wk(struct work_struct
*wk
)
1397 struct iwl_mvm
*mvm
;
1398 struct iwl_mvm_vif
*mvmvif
;
1399 struct ieee80211_vif
*vif
;
1401 mvmvif
= container_of(wk
, struct iwl_mvm_vif
, csa_work
.work
);
1402 vif
= container_of((void *)mvmvif
, struct ieee80211_vif
, drv_priv
);
1405 iwl_mvm_abort_channel_switch(mvm
->hw
, vif
);
1406 ieee80211_chswitch_done(vif
, false);
1409 static int iwl_mvm_mac_add_interface(struct ieee80211_hw
*hw
,
1410 struct ieee80211_vif
*vif
)
1412 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1413 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1417 RCU_INIT_POINTER(mvmvif
->probe_resp_data
, NULL
);
1420 * Not much to do here. The stack will not allow interface
1421 * types or combinations that we didn't advertise, so we
1422 * don't really have to check the types.
1425 mutex_lock(&mvm
->mutex
);
1427 /* make sure that beacon statistics don't go backwards with FW reset */
1428 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
1429 mvmvif
->beacon_stats
.accu_num_beacons
+=
1430 mvmvif
->beacon_stats
.num_beacons
;
1432 /* Allocate resources for the MAC context, and add it to the fw */
1433 ret
= iwl_mvm_mac_ctxt_init(mvm
, vif
);
1437 rcu_assign_pointer(mvm
->vif_id_to_mac
[mvmvif
->id
], vif
);
1439 /* Counting number of interfaces is needed for legacy PM */
1440 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
1444 * The AP binding flow can be done only after the beacon
1445 * template is configured (which happens only in the mac80211
1446 * start_ap() flow), and adding the broadcast station can happen
1447 * only after the binding.
1448 * In addition, since modifying the MAC before adding a bcast
1449 * station is not allowed by the FW, delay the adding of MAC context to
1450 * the point where we can also add the bcast station.
1451 * In short: there's not much we can do at this point, other than
1452 * allocating resources :)
1454 if (vif
->type
== NL80211_IFTYPE_AP
||
1455 vif
->type
== NL80211_IFTYPE_ADHOC
) {
1456 ret
= iwl_mvm_alloc_bcast_sta(mvm
, vif
);
1458 IWL_ERR(mvm
, "Failed to allocate bcast sta\n");
1463 * Only queue for this station is the mcast queue,
1464 * which shouldn't be in TFD mask anyway
1466 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->mcast_sta
,
1472 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
1476 mvmvif
->features
|= hw
->netdev_features
;
1478 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
1482 ret
= iwl_mvm_power_update_mac(mvm
);
1484 goto out_remove_mac
;
1486 /* beacon filtering */
1487 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
, 0);
1489 goto out_remove_mac
;
1491 if (!mvm
->bf_allowed_vif
&&
1492 vif
->type
== NL80211_IFTYPE_STATION
&& !vif
->p2p
) {
1493 mvm
->bf_allowed_vif
= mvmvif
;
1494 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
1495 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
1499 * P2P_DEVICE interface does not have a channel context assigned to it,
1500 * so a dedicated PHY context is allocated to it and the corresponding
1501 * MAC context is bound to it at this stage.
1503 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1505 mvmvif
->phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1506 if (!mvmvif
->phy_ctxt
) {
1511 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1512 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1516 ret
= iwl_mvm_add_p2p_bcast_sta(mvm
, vif
);
1520 /* Save a pointer to p2p device vif, so it can later be used to
1521 * update the p2p device MAC when a GO is started/stopped */
1522 mvm
->p2p_device_vif
= vif
;
1525 iwl_mvm_tcm_add_vif(mvm
, vif
);
1526 INIT_DELAYED_WORK(&mvmvif
->csa_work
,
1527 iwl_mvm_channel_switch_disconnect_wk
);
1529 if (vif
->type
== NL80211_IFTYPE_MONITOR
)
1530 mvm
->monitor_on
= true;
1532 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
1536 iwl_mvm_binding_remove_vif(mvm
, vif
);
1538 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1540 if (mvm
->bf_allowed_vif
== mvmvif
) {
1541 mvm
->bf_allowed_vif
= NULL
;
1542 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
1543 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
1546 mvmvif
->phy_ctxt
= NULL
;
1547 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
1549 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
1552 mutex_unlock(&mvm
->mutex
);
1557 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm
*mvm
,
1558 struct ieee80211_vif
*vif
)
1560 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1562 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1563 * We assume here that all the packets sent to the OFFCHANNEL
1564 * queue are sent in ROC session.
1566 flush_work(&mvm
->roc_done_wk
);
1570 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw
*hw
,
1571 struct ieee80211_vif
*vif
)
1573 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1574 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1575 struct iwl_probe_resp_data
*probe_data
;
1577 iwl_mvm_prepare_mac_removal(mvm
, vif
);
1579 if (!(vif
->type
== NL80211_IFTYPE_AP
||
1580 vif
->type
== NL80211_IFTYPE_ADHOC
))
1581 iwl_mvm_tcm_rm_vif(mvm
, vif
);
1583 mutex_lock(&mvm
->mutex
);
1585 probe_data
= rcu_dereference_protected(mvmvif
->probe_resp_data
,
1586 lockdep_is_held(&mvm
->mutex
));
1587 RCU_INIT_POINTER(mvmvif
->probe_resp_data
, NULL
);
1589 kfree_rcu(probe_data
, rcu_head
);
1591 if (mvm
->bf_allowed_vif
== mvmvif
) {
1592 mvm
->bf_allowed_vif
= NULL
;
1593 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
1594 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
1597 if (vif
->bss_conf
.ftm_responder
)
1598 memset(&mvm
->ftm_resp_stats
, 0, sizeof(mvm
->ftm_resp_stats
));
1600 iwl_mvm_vif_dbgfs_clean(mvm
, vif
);
1603 * For AP/GO interface, the tear down of the resources allocated to the
1604 * interface is be handled as part of the stop_ap flow.
1606 if (vif
->type
== NL80211_IFTYPE_AP
||
1607 vif
->type
== NL80211_IFTYPE_ADHOC
) {
1608 #ifdef CONFIG_NL80211_TESTMODE
1609 if (vif
== mvm
->noa_vif
) {
1610 mvm
->noa_vif
= NULL
;
1611 mvm
->noa_duration
= 0;
1614 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->mcast_sta
);
1615 iwl_mvm_dealloc_bcast_sta(mvm
, vif
);
1619 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1620 mvm
->p2p_device_vif
= NULL
;
1621 iwl_mvm_rm_p2p_bcast_sta(mvm
, vif
);
1622 iwl_mvm_binding_remove_vif(mvm
, vif
);
1623 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1624 mvmvif
->phy_ctxt
= NULL
;
1627 if (mvm
->vif_count
&& vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
1630 iwl_mvm_power_update_mac(mvm
);
1631 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
1633 RCU_INIT_POINTER(mvm
->vif_id_to_mac
[mvmvif
->id
], NULL
);
1635 if (vif
->type
== NL80211_IFTYPE_MONITOR
)
1636 mvm
->monitor_on
= false;
1639 mutex_unlock(&mvm
->mutex
);
1642 static int iwl_mvm_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
1647 struct iwl_mvm_mc_iter_data
{
1648 struct iwl_mvm
*mvm
;
1652 static void iwl_mvm_mc_iface_iterator(void *_data
, u8
*mac
,
1653 struct ieee80211_vif
*vif
)
1655 struct iwl_mvm_mc_iter_data
*data
= _data
;
1656 struct iwl_mvm
*mvm
= data
->mvm
;
1657 struct iwl_mcast_filter_cmd
*cmd
= mvm
->mcast_filter_cmd
;
1658 struct iwl_host_cmd hcmd
= {
1659 .id
= MCAST_FILTER_CMD
,
1661 .dataflags
[0] = IWL_HCMD_DFL_NOCOPY
,
1665 /* if we don't have free ports, mcast frames will be dropped */
1666 if (WARN_ON_ONCE(data
->port_id
>= MAX_PORT_ID_NUM
))
1669 if (vif
->type
!= NL80211_IFTYPE_STATION
||
1670 !vif
->bss_conf
.assoc
)
1673 cmd
->port_id
= data
->port_id
++;
1674 memcpy(cmd
->bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1675 len
= roundup(sizeof(*cmd
) + cmd
->count
* ETH_ALEN
, 4);
1680 ret
= iwl_mvm_send_cmd(mvm
, &hcmd
);
1682 IWL_ERR(mvm
, "mcast filter cmd error. ret=%d\n", ret
);
1685 static void iwl_mvm_recalc_multicast(struct iwl_mvm
*mvm
)
1687 struct iwl_mvm_mc_iter_data iter_data
= {
1691 lockdep_assert_held(&mvm
->mutex
);
1693 if (WARN_ON_ONCE(!mvm
->mcast_filter_cmd
))
1696 ieee80211_iterate_active_interfaces_atomic(
1697 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1698 iwl_mvm_mc_iface_iterator
, &iter_data
);
1701 static u64
iwl_mvm_prepare_multicast(struct ieee80211_hw
*hw
,
1702 struct netdev_hw_addr_list
*mc_list
)
1704 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1705 struct iwl_mcast_filter_cmd
*cmd
;
1706 struct netdev_hw_addr
*addr
;
1711 addr_count
= netdev_hw_addr_list_count(mc_list
);
1712 pass_all
= addr_count
> MAX_MCAST_FILTERING_ADDRESSES
||
1713 IWL_MVM_FW_MCAST_FILTER_PASS_ALL
;
1717 len
= roundup(sizeof(*cmd
) + addr_count
* ETH_ALEN
, 4);
1718 cmd
= kzalloc(len
, GFP_ATOMIC
);
1724 return (u64
)(unsigned long)cmd
;
1727 netdev_hw_addr_list_for_each(addr
, mc_list
) {
1728 IWL_DEBUG_MAC80211(mvm
, "mcast addr (%d): %pM\n",
1729 cmd
->count
, addr
->addr
);
1730 memcpy(&cmd
->addr_list
[cmd
->count
* ETH_ALEN
],
1731 addr
->addr
, ETH_ALEN
);
1735 return (u64
)(unsigned long)cmd
;
1738 static void iwl_mvm_configure_filter(struct ieee80211_hw
*hw
,
1739 unsigned int changed_flags
,
1740 unsigned int *total_flags
,
1743 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1744 struct iwl_mcast_filter_cmd
*cmd
= (void *)(unsigned long)multicast
;
1746 mutex_lock(&mvm
->mutex
);
1748 /* replace previous configuration */
1749 kfree(mvm
->mcast_filter_cmd
);
1750 mvm
->mcast_filter_cmd
= cmd
;
1755 if (changed_flags
& FIF_ALLMULTI
)
1756 cmd
->pass_all
= !!(*total_flags
& FIF_ALLMULTI
);
1761 iwl_mvm_recalc_multicast(mvm
);
1763 mutex_unlock(&mvm
->mutex
);
1767 static void iwl_mvm_config_iface_filter(struct ieee80211_hw
*hw
,
1768 struct ieee80211_vif
*vif
,
1769 unsigned int filter_flags
,
1770 unsigned int changed_flags
)
1772 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1774 /* We support only filter for probe requests */
1775 if (!(changed_flags
& FIF_PROBE_REQ
))
1778 /* Supported only for p2p client interfaces */
1779 if (vif
->type
!= NL80211_IFTYPE_STATION
|| !vif
->bss_conf
.assoc
||
1783 mutex_lock(&mvm
->mutex
);
1784 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
1785 mutex_unlock(&mvm
->mutex
);
1788 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1789 struct iwl_bcast_iter_data
{
1790 struct iwl_mvm
*mvm
;
1791 struct iwl_bcast_filter_cmd
*cmd
;
1796 iwl_mvm_set_bcast_filter(struct ieee80211_vif
*vif
,
1797 const struct iwl_fw_bcast_filter
*in_filter
,
1798 struct iwl_fw_bcast_filter
*out_filter
)
1800 struct iwl_fw_bcast_filter_attr
*attr
;
1803 memcpy(out_filter
, in_filter
, sizeof(*out_filter
));
1805 for (i
= 0; i
< ARRAY_SIZE(out_filter
->attrs
); i
++) {
1806 attr
= &out_filter
->attrs
[i
];
1811 switch (attr
->reserved1
) {
1812 case cpu_to_le16(BC_FILTER_MAGIC_IP
):
1813 if (vif
->bss_conf
.arp_addr_cnt
!= 1) {
1818 attr
->val
= vif
->bss_conf
.arp_addr_list
[0];
1820 case cpu_to_le16(BC_FILTER_MAGIC_MAC
):
1821 attr
->val
= *(__be32
*)&vif
->addr
[2];
1826 attr
->reserved1
= 0;
1827 out_filter
->num_attrs
++;
1831 static void iwl_mvm_bcast_filter_iterator(void *_data
, u8
*mac
,
1832 struct ieee80211_vif
*vif
)
1834 struct iwl_bcast_iter_data
*data
= _data
;
1835 struct iwl_mvm
*mvm
= data
->mvm
;
1836 struct iwl_bcast_filter_cmd
*cmd
= data
->cmd
;
1837 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1838 struct iwl_fw_bcast_mac
*bcast_mac
;
1841 if (WARN_ON(mvmvif
->id
>= ARRAY_SIZE(cmd
->macs
)))
1844 bcast_mac
= &cmd
->macs
[mvmvif
->id
];
1847 * enable filtering only for associated stations, but not for P2P
1850 if (vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
||
1851 !vif
->bss_conf
.assoc
)
1854 bcast_mac
->default_discard
= 1;
1856 /* copy all configured filters */
1857 for (i
= 0; mvm
->bcast_filters
[i
].attrs
[0].mask
; i
++) {
1859 * Make sure we don't exceed our filters limit.
1860 * if there is still a valid filter to be configured,
1861 * be on the safe side and just allow bcast for this mac.
1863 if (WARN_ON_ONCE(data
->current_filter
>=
1864 ARRAY_SIZE(cmd
->filters
))) {
1865 bcast_mac
->default_discard
= 0;
1866 bcast_mac
->attached_filters
= 0;
1870 iwl_mvm_set_bcast_filter(vif
,
1871 &mvm
->bcast_filters
[i
],
1872 &cmd
->filters
[data
->current_filter
]);
1874 /* skip current filter if it contains no attributes */
1875 if (!cmd
->filters
[data
->current_filter
].num_attrs
)
1878 /* attach the filter to current mac */
1879 bcast_mac
->attached_filters
|=
1880 cpu_to_le16(BIT(data
->current_filter
));
1882 data
->current_filter
++;
1886 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm
*mvm
,
1887 struct iwl_bcast_filter_cmd
*cmd
)
1889 struct iwl_bcast_iter_data iter_data
= {
1894 if (IWL_MVM_FW_BCAST_FILTER_PASS_ALL
)
1897 memset(cmd
, 0, sizeof(*cmd
));
1898 cmd
->max_bcast_filters
= ARRAY_SIZE(cmd
->filters
);
1899 cmd
->max_macs
= ARRAY_SIZE(cmd
->macs
);
1901 #ifdef CONFIG_IWLWIFI_DEBUGFS
1902 /* use debugfs filters/macs if override is configured */
1903 if (mvm
->dbgfs_bcast_filtering
.override
) {
1904 memcpy(cmd
->filters
, &mvm
->dbgfs_bcast_filtering
.cmd
.filters
,
1905 sizeof(cmd
->filters
));
1906 memcpy(cmd
->macs
, &mvm
->dbgfs_bcast_filtering
.cmd
.macs
,
1912 /* if no filters are configured, do nothing */
1913 if (!mvm
->bcast_filters
)
1916 /* configure and attach these filters for each associated sta vif */
1917 ieee80211_iterate_active_interfaces(
1918 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1919 iwl_mvm_bcast_filter_iterator
, &iter_data
);
1924 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm
*mvm
)
1926 struct iwl_bcast_filter_cmd cmd
;
1928 if (!(mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BCAST_FILTERING
))
1931 if (!iwl_mvm_bcast_filter_build_cmd(mvm
, &cmd
))
1934 return iwl_mvm_send_cmd_pdu(mvm
, BCAST_FILTER_CMD
, 0,
1938 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm
*mvm
)
1944 static int iwl_mvm_update_mu_groups(struct iwl_mvm
*mvm
,
1945 struct ieee80211_vif
*vif
)
1947 struct iwl_mu_group_mgmt_cmd cmd
= {};
1949 memcpy(cmd
.membership_status
, vif
->bss_conf
.mu_group
.membership
,
1950 WLAN_MEMBERSHIP_LEN
);
1951 memcpy(cmd
.user_position
, vif
->bss_conf
.mu_group
.position
,
1952 WLAN_USER_POSITION_LEN
);
1954 return iwl_mvm_send_cmd_pdu(mvm
,
1955 WIDE_ID(DATA_PATH_GROUP
,
1956 UPDATE_MU_GROUPS_CMD
),
1957 0, sizeof(cmd
), &cmd
);
1960 static void iwl_mvm_mu_mimo_iface_iterator(void *_data
, u8
*mac
,
1961 struct ieee80211_vif
*vif
)
1963 if (vif
->mu_mimo_owner
) {
1964 struct iwl_mu_group_mgmt_notif
*notif
= _data
;
1967 * MU-MIMO Group Id action frame is little endian. We treat
1968 * the data received from firmware as if it came from the
1969 * action frame, so no conversion is needed.
1971 ieee80211_update_mu_groups(vif
,
1972 (u8
*)¬if
->membership_status
,
1973 (u8
*)¬if
->user_position
);
1977 void iwl_mvm_mu_mimo_grp_notif(struct iwl_mvm
*mvm
,
1978 struct iwl_rx_cmd_buffer
*rxb
)
1980 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1981 struct iwl_mu_group_mgmt_notif
*notif
= (void *)pkt
->data
;
1983 ieee80211_iterate_active_interfaces_atomic(
1984 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1985 iwl_mvm_mu_mimo_iface_iterator
, notif
);
1988 static u8
iwl_mvm_he_get_ppe_val(u8
*ppe
, u8 ppe_pos_bit
)
1990 u8 byte_num
= ppe_pos_bit
/ 8;
1991 u8 bit_num
= ppe_pos_bit
% 8;
1996 return (ppe
[byte_num
] >> bit_num
) &
1997 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE
) - 1);
2000 * If bit_num > 5, we have to combine bits with next byte.
2001 * Calculate how many bits we need to take from current byte (called
2002 * here "residue_bits"), and add them to bits from next byte.
2005 residue_bits
= 8 - bit_num
;
2007 res
= (ppe
[byte_num
+ 1] &
2008 (BIT(IEEE80211_PPE_THRES_INFO_PPET_SIZE
- residue_bits
) - 1)) <<
2010 res
+= (ppe
[byte_num
] >> bit_num
) & (BIT(residue_bits
) - 1);
2015 static void iwl_mvm_cfg_he_sta(struct iwl_mvm
*mvm
,
2016 struct ieee80211_vif
*vif
, u8 sta_id
)
2018 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2019 struct iwl_he_sta_context_cmd sta_ctxt_cmd
= {
2021 .tid_limit
= IWL_MAX_TID_COUNT
,
2022 .bss_color
= vif
->bss_conf
.he_bss_color
.color
,
2023 .htc_trig_based_pkt_ext
= vif
->bss_conf
.htc_trig_based_pkt_ext
,
2024 .frame_time_rts_th
=
2025 cpu_to_le16(vif
->bss_conf
.frame_time_rts_th
),
2027 int size
= fw_has_api(&mvm
->fw
->ucode_capa
,
2028 IWL_UCODE_TLV_API_MBSSID_HE
) ?
2029 sizeof(sta_ctxt_cmd
) :
2030 sizeof(struct iwl_he_sta_context_cmd_v1
);
2031 struct ieee80211_sta
*sta
;
2037 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_ctxt_cmd
.sta_id
]);
2038 if (IS_ERR_OR_NULL(sta
)) {
2040 WARN(1, "Can't find STA to configure HE\n");
2044 if (!sta
->he_cap
.has_he
) {
2051 /* Block 26-tone RU OFDMA transmissions */
2052 if (mvmvif
->he_ru_2mhz_block
)
2053 flags
|= STA_CTXT_HE_RU_2MHZ_BLOCK
;
2056 if (sta
->he_cap
.he_cap_elem
.mac_cap_info
[0] &
2057 IEEE80211_HE_MAC_CAP0_HTC_HE
)
2058 sta_ctxt_cmd
.htc_flags
|= cpu_to_le32(IWL_HE_HTC_SUPPORT
);
2059 if ((sta
->he_cap
.he_cap_elem
.mac_cap_info
[1] &
2060 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION
) ||
2061 (sta
->he_cap
.he_cap_elem
.mac_cap_info
[2] &
2062 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION
)) {
2064 ((sta
->he_cap
.he_cap_elem
.mac_cap_info
[2] &
2065 IEEE80211_HE_MAC_CAP2_LINK_ADAPTATION
) << 1) +
2066 (sta
->he_cap
.he_cap_elem
.mac_cap_info
[1] &
2067 IEEE80211_HE_MAC_CAP1_LINK_ADAPTATION
);
2070 sta_ctxt_cmd
.htc_flags
|=
2071 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_UNSOLICITED
);
2072 else if (link_adap
== 3)
2073 sta_ctxt_cmd
.htc_flags
|=
2074 cpu_to_le32(IWL_HE_HTC_LINK_ADAP_BOTH
);
2076 if (sta
->he_cap
.he_cap_elem
.mac_cap_info
[2] & IEEE80211_HE_MAC_CAP2_BSR
)
2077 sta_ctxt_cmd
.htc_flags
|= cpu_to_le32(IWL_HE_HTC_BSR_SUPP
);
2078 if (sta
->he_cap
.he_cap_elem
.mac_cap_info
[3] &
2079 IEEE80211_HE_MAC_CAP3_OMI_CONTROL
)
2080 sta_ctxt_cmd
.htc_flags
|= cpu_to_le32(IWL_HE_HTC_OMI_SUPP
);
2081 if (sta
->he_cap
.he_cap_elem
.mac_cap_info
[4] & IEEE80211_HE_MAC_CAP4_BQR
)
2082 sta_ctxt_cmd
.htc_flags
|= cpu_to_le32(IWL_HE_HTC_BQR_SUPP
);
2085 * Initialize the PPE thresholds to "None" (7), as described in Table
2086 * 9-262ac of 80211.ax/D3.0.
2088 memset(&sta_ctxt_cmd
.pkt_ext
, 7, sizeof(sta_ctxt_cmd
.pkt_ext
));
2090 /* If PPE Thresholds exist, parse them into a FW-familiar format. */
2091 if (sta
->he_cap
.he_cap_elem
.phy_cap_info
[6] &
2092 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT
) {
2093 u8 nss
= (sta
->he_cap
.ppe_thres
[0] &
2094 IEEE80211_PPE_THRES_NSS_MASK
) + 1;
2095 u8 ru_index_bitmap
=
2096 (sta
->he_cap
.ppe_thres
[0] &
2097 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK
) >>
2098 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS
;
2099 u8
*ppe
= &sta
->he_cap
.ppe_thres
[0];
2100 u8 ppe_pos_bit
= 7; /* Starting after PPE header */
2103 * FW currently supports only nss == MAX_HE_SUPP_NSS
2105 * If nss > MAX: we can ignore values we don't support
2106 * If nss < MAX: we can set zeros in other streams
2108 if (nss
> MAX_HE_SUPP_NSS
) {
2109 IWL_INFO(mvm
, "Got NSS = %d - trimming to %d\n", nss
,
2111 nss
= MAX_HE_SUPP_NSS
;
2114 for (i
= 0; i
< nss
; i
++) {
2115 u8 ru_index_tmp
= ru_index_bitmap
<< 1;
2118 for (bw
= 0; bw
< MAX_HE_CHANNEL_BW_INDX
; bw
++) {
2120 if (!(ru_index_tmp
& 1))
2123 sta_ctxt_cmd
.pkt_ext
.pkt_ext_qam_th
[i
][bw
][1] =
2124 iwl_mvm_he_get_ppe_val(ppe
,
2127 IEEE80211_PPE_THRES_INFO_PPET_SIZE
;
2128 sta_ctxt_cmd
.pkt_ext
.pkt_ext_qam_th
[i
][bw
][0] =
2129 iwl_mvm_he_get_ppe_val(ppe
,
2132 IEEE80211_PPE_THRES_INFO_PPET_SIZE
;
2136 flags
|= STA_CTXT_HE_PACKET_EXT
;
2137 } else if ((sta
->he_cap
.he_cap_elem
.phy_cap_info
[9] &
2138 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK
) !=
2139 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_RESERVED
) {
2143 /* Take the PPE thresholds from the nominal padding info */
2144 switch (sta
->he_cap
.he_cap_elem
.phy_cap_info
[9] &
2145 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_MASK
) {
2146 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_0US
:
2147 low_th
= IWL_HE_PKT_EXT_NONE
;
2148 high_th
= IWL_HE_PKT_EXT_NONE
;
2150 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_8US
:
2151 low_th
= IWL_HE_PKT_EXT_BPSK
;
2152 high_th
= IWL_HE_PKT_EXT_NONE
;
2154 case IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US
:
2155 low_th
= IWL_HE_PKT_EXT_NONE
;
2156 high_th
= IWL_HE_PKT_EXT_BPSK
;
2160 /* Set the PPE thresholds accordingly */
2161 if (low_th
>= 0 && high_th
>= 0) {
2162 struct iwl_he_pkt_ext
*pkt_ext
=
2163 (struct iwl_he_pkt_ext
*)&sta_ctxt_cmd
.pkt_ext
;
2165 for (i
= 0; i
< MAX_HE_SUPP_NSS
; i
++) {
2168 for (bw
= 0; bw
< MAX_HE_CHANNEL_BW_INDX
;
2170 pkt_ext
->pkt_ext_qam_th
[i
][bw
][0] =
2172 pkt_ext
->pkt_ext_qam_th
[i
][bw
][1] =
2177 flags
|= STA_CTXT_HE_PACKET_EXT
;
2182 /* Mark MU EDCA as enabled, unless none detected on some AC */
2183 flags
|= STA_CTXT_HE_MU_EDCA_CW
;
2184 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++) {
2185 struct ieee80211_he_mu_edca_param_ac_rec
*mu_edca
=
2186 &mvmvif
->queue_params
[i
].mu_edca_param_rec
;
2187 u8 ac
= iwl_mvm_mac80211_ac_to_ucode_ac(i
);
2189 if (!mvmvif
->queue_params
[i
].mu_edca
) {
2190 flags
&= ~STA_CTXT_HE_MU_EDCA_CW
;
2194 sta_ctxt_cmd
.trig_based_txf
[ac
].cwmin
=
2195 cpu_to_le16(mu_edca
->ecw_min_max
& 0xf);
2196 sta_ctxt_cmd
.trig_based_txf
[ac
].cwmax
=
2197 cpu_to_le16((mu_edca
->ecw_min_max
& 0xf0) >> 4);
2198 sta_ctxt_cmd
.trig_based_txf
[ac
].aifsn
=
2199 cpu_to_le16(mu_edca
->aifsn
);
2200 sta_ctxt_cmd
.trig_based_txf
[ac
].mu_time
=
2201 cpu_to_le16(mu_edca
->mu_edca_timer
);
2204 if (vif
->bss_conf
.multi_sta_back_32bit
)
2205 flags
|= STA_CTXT_HE_32BIT_BA_BITMAP
;
2207 if (vif
->bss_conf
.ack_enabled
)
2208 flags
|= STA_CTXT_HE_ACK_ENABLED
;
2210 if (vif
->bss_conf
.uora_exists
) {
2211 flags
|= STA_CTXT_HE_TRIG_RND_ALLOC
;
2213 sta_ctxt_cmd
.rand_alloc_ecwmin
=
2214 vif
->bss_conf
.uora_ocw_range
& 0x7;
2215 sta_ctxt_cmd
.rand_alloc_ecwmax
=
2216 (vif
->bss_conf
.uora_ocw_range
>> 3) & 0x7;
2219 if (vif
->bss_conf
.nontransmitted
) {
2220 flags
|= STA_CTXT_HE_REF_BSSID_VALID
;
2221 ether_addr_copy(sta_ctxt_cmd
.ref_bssid_addr
,
2222 vif
->bss_conf
.transmitter_bssid
);
2223 sta_ctxt_cmd
.max_bssid_indicator
=
2224 vif
->bss_conf
.bssid_indicator
;
2225 sta_ctxt_cmd
.bssid_index
= vif
->bss_conf
.bssid_index
;
2226 sta_ctxt_cmd
.ema_ap
= vif
->bss_conf
.ema_ap
;
2227 sta_ctxt_cmd
.profile_periodicity
=
2228 vif
->bss_conf
.profile_periodicity
;
2231 sta_ctxt_cmd
.flags
= cpu_to_le32(flags
);
2233 if (iwl_mvm_send_cmd_pdu(mvm
, iwl_cmd_id(STA_HE_CTXT_CMD
,
2234 DATA_PATH_GROUP
, 0),
2235 0, size
, &sta_ctxt_cmd
))
2236 IWL_ERR(mvm
, "Failed to config FW to work HE!\n");
2239 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm
*mvm
,
2240 struct ieee80211_vif
*vif
,
2241 struct ieee80211_bss_conf
*bss_conf
,
2244 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2248 * Re-calculate the tsf id, as the master-slave relations depend on the
2249 * beacon interval, which was not known when the station interface was
2252 if (changes
& BSS_CHANGED_ASSOC
&& bss_conf
->assoc
) {
2253 if (vif
->bss_conf
.he_support
&&
2254 !iwlwifi_mod_params
.disable_11ax
)
2255 iwl_mvm_cfg_he_sta(mvm
, vif
, mvmvif
->ap_sta_id
);
2257 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm
, vif
);
2260 /* Update MU EDCA params */
2261 if (changes
& BSS_CHANGED_QOS
&& mvmvif
->associated
&&
2262 bss_conf
->assoc
&& vif
->bss_conf
.he_support
&&
2263 !iwlwifi_mod_params
.disable_11ax
)
2264 iwl_mvm_cfg_he_sta(mvm
, vif
, mvmvif
->ap_sta_id
);
2267 * If we're not associated yet, take the (new) BSSID before associating
2268 * so the firmware knows. If we're already associated, then use the old
2269 * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC
2270 * branch for disassociation below.
2272 if (changes
& BSS_CHANGED_BSSID
&& !mvmvif
->associated
)
2273 memcpy(mvmvif
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
2275 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, mvmvif
->bssid
);
2277 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
2279 /* after sending it once, adopt mac80211 data */
2280 memcpy(mvmvif
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
2281 mvmvif
->associated
= bss_conf
->assoc
;
2283 if (changes
& BSS_CHANGED_ASSOC
) {
2284 if (bss_conf
->assoc
) {
2285 /* clear statistics to get clean beacon counter */
2286 iwl_mvm_request_statistics(mvm
, true);
2287 memset(&mvmvif
->beacon_stats
, 0,
2288 sizeof(mvmvif
->beacon_stats
));
2290 /* add quota for this interface */
2291 ret
= iwl_mvm_update_quotas(mvm
, true, NULL
);
2293 IWL_ERR(mvm
, "failed to update quotas\n");
2297 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
,
2299 !fw_has_capa(&mvm
->fw
->ucode_capa
,
2300 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD
)) {
2302 * If we're restarting then the firmware will
2303 * obviously have lost synchronisation with
2304 * the AP. It will attempt to synchronise by
2305 * itself, but we can make it more reliable by
2306 * scheduling a session protection time event.
2308 * The firmware needs to receive a beacon to
2309 * catch up with synchronisation, use 110% of
2310 * the beacon interval.
2312 * Set a large maximum delay to allow for more
2313 * than a single interface.
2315 * For new firmware versions, rely on the
2316 * firmware. This is relevant for DCM scenarios
2319 u32 dur
= (11 * vif
->bss_conf
.beacon_int
) / 10;
2320 iwl_mvm_protect_session(mvm
, vif
, dur
, dur
,
2324 iwl_mvm_sf_update(mvm
, vif
, false);
2325 iwl_mvm_power_vif_assoc(mvm
, vif
);
2327 iwl_mvm_update_smps(mvm
, vif
,
2328 IWL_MVM_SMPS_REQ_PROT
,
2329 IEEE80211_SMPS_DYNAMIC
);
2331 } else if (mvmvif
->ap_sta_id
!= IWL_MVM_INVALID_STA
) {
2333 * If update fails - SF might be running in associated
2334 * mode while disassociated - which is forbidden.
2336 ret
= iwl_mvm_sf_update(mvm
, vif
, false);
2338 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED
,
2340 "Failed to update SF upon disassociation\n");
2343 * If we get an assert during the connection (after the
2344 * station has been added, but before the vif is set
2345 * to associated), mac80211 will re-add the station and
2346 * then configure the vif. Since the vif is not
2347 * associated, we would remove the station here and
2348 * this would fail the recovery.
2350 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
,
2353 * Remove AP station now that
2354 * the MAC is unassoc
2356 ret
= iwl_mvm_rm_sta_id(mvm
, vif
,
2360 "failed to remove AP station\n");
2362 mvmvif
->ap_sta_id
= IWL_MVM_INVALID_STA
;
2365 /* remove quota for this interface */
2366 ret
= iwl_mvm_update_quotas(mvm
, false, NULL
);
2368 IWL_ERR(mvm
, "failed to update quotas\n");
2370 /* this will take the cleared BSSID from bss_conf */
2371 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
2374 "failed to update MAC %pM (clear after unassoc)\n",
2379 * The firmware tracks the MU-MIMO group on its own.
2380 * However, on HW restart we should restore this data.
2382 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
) &&
2383 (changes
& BSS_CHANGED_MU_GROUPS
) && vif
->mu_mimo_owner
) {
2384 ret
= iwl_mvm_update_mu_groups(mvm
, vif
);
2387 "failed to update VHT MU_MIMO groups\n");
2390 iwl_mvm_recalc_multicast(mvm
);
2391 iwl_mvm_configure_bcast_filter(mvm
);
2393 /* reset rssi values */
2394 mvmvif
->bf_data
.ave_beacon_signal
= 0;
2396 iwl_mvm_bt_coex_vif_change(mvm
);
2397 iwl_mvm_update_smps(mvm
, vif
, IWL_MVM_SMPS_REQ_TT
,
2398 IEEE80211_SMPS_AUTOMATIC
);
2399 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
2400 IWL_UCODE_TLV_CAPA_UMAC_SCAN
))
2401 iwl_mvm_config_scan(mvm
);
2404 if (changes
& BSS_CHANGED_BEACON_INFO
) {
2406 * We received a beacon from the associated AP so
2407 * remove the session protection.
2408 * A firmware with the new API will remove it automatically.
2410 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
2411 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD
))
2412 iwl_mvm_stop_session_protection(mvm
, vif
);
2414 iwl_mvm_sf_update(mvm
, vif
, false);
2415 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
, 0));
2418 if (changes
& (BSS_CHANGED_PS
| BSS_CHANGED_P2P_PS
| BSS_CHANGED_QOS
|
2420 * Send power command on every beacon change,
2421 * because we may have not enabled beacon abort yet.
2423 BSS_CHANGED_BEACON_INFO
)) {
2424 ret
= iwl_mvm_power_update_mac(mvm
);
2426 IWL_ERR(mvm
, "failed to update power mode\n");
2429 if (changes
& BSS_CHANGED_TXPOWER
) {
2430 IWL_DEBUG_CALIB(mvm
, "Changing TX Power to %d\n",
2432 iwl_mvm_set_tx_power(mvm
, vif
, bss_conf
->txpower
);
2435 if (changes
& BSS_CHANGED_CQM
) {
2436 IWL_DEBUG_MAC80211(mvm
, "cqm info_changed\n");
2437 /* reset cqm events tracking */
2438 mvmvif
->bf_data
.last_cqm_event
= 0;
2439 if (mvmvif
->bf_data
.bf_enabled
) {
2440 ret
= iwl_mvm_enable_beacon_filter(mvm
, vif
, 0);
2443 "failed to update CQM thresholds\n");
2447 if (changes
& BSS_CHANGED_ARP_FILTER
) {
2448 IWL_DEBUG_MAC80211(mvm
, "arp filter changed\n");
2449 iwl_mvm_configure_bcast_filter(mvm
);
2453 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw
*hw
,
2454 struct ieee80211_vif
*vif
)
2456 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2457 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2460 mutex_lock(&mvm
->mutex
);
2462 /* Send the beacon template */
2463 ret
= iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
);
2468 * Re-calculate the tsf id, as the master-slave relations depend on the
2469 * beacon interval, which was not known when the AP interface was added.
2471 if (vif
->type
== NL80211_IFTYPE_AP
)
2472 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm
, vif
);
2474 mvmvif
->ap_assoc_sta_count
= 0;
2476 /* Add the mac context */
2477 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
2481 /* Perform the binding */
2482 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
2487 * This is not very nice, but the simplest:
2488 * For older FWs adding the mcast sta before the bcast station may
2489 * cause assert 0x2b00.
2490 * This is fixed in later FW so make the order of removal depend on
2493 if (fw_has_api(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_API_STA_TYPE
)) {
2494 ret
= iwl_mvm_add_mcast_sta(mvm
, vif
);
2498 * Send the bcast station. At this stage the TBTT and DTIM time
2499 * events are added and applied to the scheduler
2501 ret
= iwl_mvm_send_add_bcast_sta(mvm
, vif
);
2503 iwl_mvm_rm_mcast_sta(mvm
, vif
);
2508 * Send the bcast station. At this stage the TBTT and DTIM time
2509 * events are added and applied to the scheduler
2511 ret
= iwl_mvm_send_add_bcast_sta(mvm
, vif
);
2514 ret
= iwl_mvm_add_mcast_sta(mvm
, vif
);
2516 iwl_mvm_send_rm_bcast_sta(mvm
, vif
);
2521 /* must be set before quota calculations */
2522 mvmvif
->ap_ibss_active
= true;
2524 /* send all the early keys to the device now */
2525 for (i
= 0; i
< ARRAY_SIZE(mvmvif
->ap_early_keys
); i
++) {
2526 struct ieee80211_key_conf
*key
= mvmvif
->ap_early_keys
[i
];
2531 mvmvif
->ap_early_keys
[i
] = NULL
;
2533 ret
= __iwl_mvm_mac_set_key(hw
, SET_KEY
, vif
, NULL
, key
);
2535 goto out_quota_failed
;
2538 if (vif
->type
== NL80211_IFTYPE_AP
&& !vif
->p2p
) {
2539 iwl_mvm_vif_set_low_latency(mvmvif
, true,
2540 LOW_LATENCY_VIF_TYPE
);
2541 iwl_mvm_send_low_latency_cmd(mvm
, true, mvmvif
->id
);
2544 /* power updated needs to be done before quotas */
2545 iwl_mvm_power_update_mac(mvm
);
2547 ret
= iwl_mvm_update_quotas(mvm
, false, NULL
);
2549 goto out_quota_failed
;
2551 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2552 if (vif
->p2p
&& mvm
->p2p_device_vif
)
2553 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
, false, NULL
);
2555 iwl_mvm_bt_coex_vif_change(mvm
);
2557 /* we don't support TDLS during DCM */
2558 if (iwl_mvm_phy_ctx_count(mvm
) > 1)
2559 iwl_mvm_teardown_tdls_peers(mvm
);
2561 iwl_mvm_ftm_restart_responder(mvm
, vif
);
2566 iwl_mvm_power_update_mac(mvm
);
2567 mvmvif
->ap_ibss_active
= false;
2568 iwl_mvm_send_rm_bcast_sta(mvm
, vif
);
2569 iwl_mvm_rm_mcast_sta(mvm
, vif
);
2571 iwl_mvm_binding_remove_vif(mvm
, vif
);
2573 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
2575 mutex_unlock(&mvm
->mutex
);
2579 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw
*hw
,
2580 struct ieee80211_vif
*vif
)
2582 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2583 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2585 iwl_mvm_prepare_mac_removal(mvm
, vif
);
2587 mutex_lock(&mvm
->mutex
);
2589 /* Handle AP stop while in CSA */
2590 if (rcu_access_pointer(mvm
->csa_vif
) == vif
) {
2591 iwl_mvm_remove_time_event(mvm
, mvmvif
,
2592 &mvmvif
->time_event_data
);
2593 RCU_INIT_POINTER(mvm
->csa_vif
, NULL
);
2594 mvmvif
->csa_countdown
= false;
2597 if (rcu_access_pointer(mvm
->csa_tx_blocked_vif
) == vif
) {
2598 RCU_INIT_POINTER(mvm
->csa_tx_blocked_vif
, NULL
);
2599 mvm
->csa_tx_block_bcn_timeout
= 0;
2602 mvmvif
->ap_ibss_active
= false;
2603 mvm
->ap_last_beacon_gp2
= 0;
2605 if (vif
->type
== NL80211_IFTYPE_AP
&& !vif
->p2p
) {
2606 iwl_mvm_vif_set_low_latency(mvmvif
, false,
2607 LOW_LATENCY_VIF_TYPE
);
2608 iwl_mvm_send_low_latency_cmd(mvm
, false, mvmvif
->id
);
2611 iwl_mvm_bt_coex_vif_change(mvm
);
2613 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
2614 if (vif
->p2p
&& mvm
->p2p_device_vif
)
2615 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
, false, NULL
);
2617 iwl_mvm_update_quotas(mvm
, false, NULL
);
2620 * This is not very nice, but the simplest:
2621 * For older FWs removing the mcast sta before the bcast station may
2622 * cause assert 0x2b00.
2623 * This is fixed in later FW (which will stop beaconing when removing
2625 * So make the order of removal depend on the TLV
2627 if (!fw_has_api(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_API_STA_TYPE
))
2628 iwl_mvm_rm_mcast_sta(mvm
, vif
);
2629 iwl_mvm_send_rm_bcast_sta(mvm
, vif
);
2630 if (fw_has_api(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_API_STA_TYPE
))
2631 iwl_mvm_rm_mcast_sta(mvm
, vif
);
2632 iwl_mvm_binding_remove_vif(mvm
, vif
);
2634 iwl_mvm_power_update_mac(mvm
);
2636 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
2638 mutex_unlock(&mvm
->mutex
);
2642 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm
*mvm
,
2643 struct ieee80211_vif
*vif
,
2644 struct ieee80211_bss_conf
*bss_conf
,
2647 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2649 /* Changes will be applied when the AP/IBSS is started */
2650 if (!mvmvif
->ap_ibss_active
)
2653 if (changes
& (BSS_CHANGED_ERP_CTS_PROT
| BSS_CHANGED_HT
|
2654 BSS_CHANGED_BANDWIDTH
| BSS_CHANGED_QOS
) &&
2655 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
))
2656 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
2658 /* Need to send a new beacon template to the FW */
2659 if (changes
& BSS_CHANGED_BEACON
&&
2660 iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
))
2661 IWL_WARN(mvm
, "Failed updating beacon data\n");
2663 if (changes
& BSS_CHANGED_TXPOWER
) {
2664 IWL_DEBUG_CALIB(mvm
, "Changing TX Power to %d\n",
2666 iwl_mvm_set_tx_power(mvm
, vif
, bss_conf
->txpower
);
2669 if (changes
& BSS_CHANGED_FTM_RESPONDER
) {
2670 int ret
= iwl_mvm_ftm_start_responder(mvm
, vif
);
2673 IWL_WARN(mvm
, "Failed to enable FTM responder (%d)\n",
2679 static void iwl_mvm_bss_info_changed(struct ieee80211_hw
*hw
,
2680 struct ieee80211_vif
*vif
,
2681 struct ieee80211_bss_conf
*bss_conf
,
2684 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2686 mutex_lock(&mvm
->mutex
);
2688 if (changes
& BSS_CHANGED_IDLE
&& !bss_conf
->idle
)
2689 iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_SCHED
, true);
2691 switch (vif
->type
) {
2692 case NL80211_IFTYPE_STATION
:
2693 iwl_mvm_bss_info_changed_station(mvm
, vif
, bss_conf
, changes
);
2695 case NL80211_IFTYPE_AP
:
2696 case NL80211_IFTYPE_ADHOC
:
2697 iwl_mvm_bss_info_changed_ap_ibss(mvm
, vif
, bss_conf
, changes
);
2699 case NL80211_IFTYPE_MONITOR
:
2700 if (changes
& BSS_CHANGED_MU_GROUPS
)
2701 iwl_mvm_update_mu_groups(mvm
, vif
);
2704 /* shouldn't happen */
2708 mutex_unlock(&mvm
->mutex
);
2711 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw
*hw
,
2712 struct ieee80211_vif
*vif
,
2713 struct ieee80211_scan_request
*hw_req
)
2715 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2718 if (hw_req
->req
.n_channels
== 0 ||
2719 hw_req
->req
.n_channels
> mvm
->fw
->ucode_capa
.n_scan_channels
)
2722 mutex_lock(&mvm
->mutex
);
2723 ret
= iwl_mvm_reg_scan_start(mvm
, vif
, &hw_req
->req
, &hw_req
->ies
);
2724 mutex_unlock(&mvm
->mutex
);
2729 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw
*hw
,
2730 struct ieee80211_vif
*vif
)
2732 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2734 mutex_lock(&mvm
->mutex
);
2736 /* Due to a race condition, it's possible that mac80211 asks
2737 * us to stop a hw_scan when it's already stopped. This can
2738 * happen, for instance, if we stopped the scan ourselves,
2739 * called ieee80211_scan_completed() and the userspace called
2740 * cancel scan scan before ieee80211_scan_work() could run.
2741 * To handle that, simply return if the scan is not running.
2743 if (mvm
->scan_status
& IWL_MVM_SCAN_REGULAR
)
2744 iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_REGULAR
, true);
2746 mutex_unlock(&mvm
->mutex
);
2750 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw
*hw
,
2751 struct ieee80211_sta
*sta
, u16 tids
,
2753 enum ieee80211_frame_release_type reason
,
2756 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2758 /* Called when we need to transmit (a) frame(s) from mac80211 */
2760 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
,
2761 tids
, more_data
, false);
2765 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw
*hw
,
2766 struct ieee80211_sta
*sta
, u16 tids
,
2768 enum ieee80211_frame_release_type reason
,
2771 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2773 /* Called when we need to transmit (a) frame(s) from agg or dqa queue */
2775 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
,
2776 tids
, more_data
, true);
2779 static void __iwl_mvm_mac_sta_notify(struct ieee80211_hw
*hw
,
2780 enum sta_notify_cmd cmd
,
2781 struct ieee80211_sta
*sta
)
2783 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2784 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
2785 unsigned long txqs
= 0, tids
= 0;
2789 * If we have TVQM then we get too high queue numbers - luckily
2790 * we really shouldn't get here with that because such hardware
2791 * should have firmware supporting buffer station offload.
2793 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm
)))
2796 spin_lock_bh(&mvmsta
->lock
);
2797 for (tid
= 0; tid
< ARRAY_SIZE(mvmsta
->tid_data
); tid
++) {
2798 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
2800 if (tid_data
->txq_id
== IWL_MVM_INVALID_QUEUE
)
2803 __set_bit(tid_data
->txq_id
, &txqs
);
2805 if (iwl_mvm_tid_queued(mvm
, tid_data
) == 0)
2808 __set_bit(tid
, &tids
);
2812 case STA_NOTIFY_SLEEP
:
2813 for_each_set_bit(tid
, &tids
, IWL_MAX_TID_COUNT
)
2814 ieee80211_sta_set_buffered(sta
, tid
, true);
2817 iwl_trans_freeze_txq_timer(mvm
->trans
, txqs
, true);
2819 * The fw updates the STA to be asleep. Tx packets on the Tx
2820 * queues to this station will not be transmitted. The fw will
2821 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
2824 case STA_NOTIFY_AWAKE
:
2825 if (WARN_ON(mvmsta
->sta_id
== IWL_MVM_INVALID_STA
))
2829 iwl_trans_freeze_txq_timer(mvm
->trans
, txqs
, false);
2830 iwl_mvm_sta_modify_ps_wake(mvm
, sta
);
2835 spin_unlock_bh(&mvmsta
->lock
);
2838 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw
*hw
,
2839 struct ieee80211_vif
*vif
,
2840 enum sta_notify_cmd cmd
,
2841 struct ieee80211_sta
*sta
)
2843 __iwl_mvm_mac_sta_notify(hw
, cmd
, sta
);
2846 void iwl_mvm_sta_pm_notif(struct iwl_mvm
*mvm
, struct iwl_rx_cmd_buffer
*rxb
)
2848 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
2849 struct iwl_mvm_pm_state_notification
*notif
= (void *)pkt
->data
;
2850 struct ieee80211_sta
*sta
;
2851 struct iwl_mvm_sta
*mvmsta
;
2852 bool sleeping
= (notif
->type
!= IWL_MVM_PM_EVENT_AWAKE
);
2854 if (WARN_ON(notif
->sta_id
>= ARRAY_SIZE(mvm
->fw_id_to_mac_id
)))
2858 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[notif
->sta_id
]);
2859 if (WARN_ON(IS_ERR_OR_NULL(sta
))) {
2864 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
2867 mvmsta
->vif
->type
!= NL80211_IFTYPE_AP
) {
2872 if (mvmsta
->sleeping
!= sleeping
) {
2873 mvmsta
->sleeping
= sleeping
;
2874 __iwl_mvm_mac_sta_notify(mvm
->hw
,
2875 sleeping
? STA_NOTIFY_SLEEP
: STA_NOTIFY_AWAKE
,
2877 ieee80211_sta_ps_transition(sta
, sleeping
);
2881 switch (notif
->type
) {
2882 case IWL_MVM_PM_EVENT_AWAKE
:
2883 case IWL_MVM_PM_EVENT_ASLEEP
:
2885 case IWL_MVM_PM_EVENT_UAPSD
:
2886 ieee80211_sta_uapsd_trigger(sta
, IEEE80211_NUM_TIDS
);
2888 case IWL_MVM_PM_EVENT_PS_POLL
:
2889 ieee80211_sta_pspoll(sta
);
2899 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw
*hw
,
2900 struct ieee80211_vif
*vif
,
2901 struct ieee80211_sta
*sta
)
2903 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2904 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
2907 * This is called before mac80211 does RCU synchronisation,
2908 * so here we already invalidate our internal RCU-protected
2909 * station pointer. The rest of the code will thus no longer
2910 * be able to find the station this way, and we don't rely
2911 * on further RCU synchronisation after the sta_state()
2912 * callback deleted the station.
2914 mutex_lock(&mvm
->mutex
);
2915 if (sta
== rcu_access_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
]))
2916 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
],
2919 mutex_unlock(&mvm
->mutex
);
2922 static void iwl_mvm_check_uapsd(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
2927 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
2928 struct iwl_mvm_tcm_mac
*mdata
;
2930 mdata
= &mvm
->tcm
.data
[iwl_mvm_vif_from_mac80211(vif
)->id
];
2931 ewma_rate_init(&mdata
->uapsd_nonagg_detect
.rate
);
2932 mdata
->opened_rx_ba_sessions
= false;
2935 if (!(mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT
))
2938 if (vif
->p2p
&& !iwl_mvm_is_p2p_scm_uapsd_supported(mvm
)) {
2939 vif
->driver_flags
&= ~IEEE80211_VIF_SUPPORTS_UAPSD
;
2944 (iwlwifi_mod_params
.uapsd_disable
& IWL_DISABLE_UAPSD_BSS
)) {
2945 vif
->driver_flags
&= ~IEEE80211_VIF_SUPPORTS_UAPSD
;
2949 for (i
= 0; i
< IWL_MVM_UAPSD_NOAGG_LIST_LEN
; i
++) {
2950 if (ether_addr_equal(mvm
->uapsd_noagg_bssids
[i
].addr
, bssid
)) {
2951 vif
->driver_flags
&= ~IEEE80211_VIF_SUPPORTS_UAPSD
;
2956 vif
->driver_flags
|= IEEE80211_VIF_SUPPORTS_UAPSD
;
2960 iwl_mvm_tdls_check_trigger(struct iwl_mvm
*mvm
,
2961 struct ieee80211_vif
*vif
, u8
*peer_addr
,
2962 enum nl80211_tdls_operation action
)
2964 struct iwl_fw_dbg_trigger_tlv
*trig
;
2965 struct iwl_fw_dbg_trigger_tdls
*tdls_trig
;
2967 trig
= iwl_fw_dbg_trigger_on(&mvm
->fwrt
, ieee80211_vif_to_wdev(vif
),
2968 FW_DBG_TRIGGER_TDLS
);
2972 tdls_trig
= (void *)trig
->data
;
2974 if (!(tdls_trig
->action_bitmap
& BIT(action
)))
2977 if (tdls_trig
->peer_mode
&&
2978 memcmp(tdls_trig
->peer
, peer_addr
, ETH_ALEN
) != 0)
2981 iwl_fw_dbg_collect_trig(&mvm
->fwrt
, trig
,
2982 "TDLS event occurred, peer %pM, action %d",
2986 struct iwl_mvm_he_obss_narrow_bw_ru_data
{
2990 static void iwl_mvm_check_he_obss_narrow_bw_ru_iter(struct wiphy
*wiphy
,
2991 struct cfg80211_bss
*bss
,
2994 struct iwl_mvm_he_obss_narrow_bw_ru_data
*data
= _data
;
2995 const struct element
*elem
;
2997 elem
= cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY
, bss
->ies
->data
,
3000 if (!elem
|| elem
->datalen
< 10 ||
3002 WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT
)) {
3003 data
->tolerated
= false;
3007 static void iwl_mvm_check_he_obss_narrow_bw_ru(struct ieee80211_hw
*hw
,
3008 struct ieee80211_vif
*vif
)
3010 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3011 struct iwl_mvm_he_obss_narrow_bw_ru_data iter_data
= {
3015 if (!(vif
->bss_conf
.chandef
.chan
->flags
& IEEE80211_CHAN_RADAR
)) {
3016 mvmvif
->he_ru_2mhz_block
= false;
3020 cfg80211_bss_iter(hw
->wiphy
, &vif
->bss_conf
.chandef
,
3021 iwl_mvm_check_he_obss_narrow_bw_ru_iter
,
3025 * If there is at least one AP on radar channel that cannot
3026 * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
3028 mvmvif
->he_ru_2mhz_block
= !iter_data
.tolerated
;
3031 static int iwl_mvm_mac_sta_state(struct ieee80211_hw
*hw
,
3032 struct ieee80211_vif
*vif
,
3033 struct ieee80211_sta
*sta
,
3034 enum ieee80211_sta_state old_state
,
3035 enum ieee80211_sta_state new_state
)
3037 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3038 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3039 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
3042 IWL_DEBUG_MAC80211(mvm
, "station %pM state change %d->%d\n",
3043 sta
->addr
, old_state
, new_state
);
3045 /* this would be a mac80211 bug ... but don't crash */
3046 if (WARN_ON_ONCE(!mvmvif
->phy_ctxt
))
3050 * If we are in a STA removal flow and in DQA mode:
3052 * This is after the sync_rcu part, so the queues have already been
3053 * flushed. No more TXs on their way in mac80211's path, and no more in
3055 * Also, we won't be getting any new TX frames for this station.
3056 * What we might have are deferred TX frames that need to be taken care
3059 * Drop any still-queued deferred-frame before removing the STA, and
3060 * make sure the worker is no longer handling frames for this STA.
3062 if (old_state
== IEEE80211_STA_NONE
&&
3063 new_state
== IEEE80211_STA_NOTEXIST
) {
3064 flush_work(&mvm
->add_stream_wk
);
3067 * No need to make sure deferred TX indication is off since the
3068 * worker will already remove it if it was on
3072 mutex_lock(&mvm
->mutex
);
3073 /* track whether or not the station is associated */
3074 mvm_sta
->sta_state
= new_state
;
3076 if (old_state
== IEEE80211_STA_NOTEXIST
&&
3077 new_state
== IEEE80211_STA_NONE
) {
3079 * Firmware bug - it'll crash if the beacon interval is less
3080 * than 16. We can't avoid connecting at all, so refuse the
3081 * station state change, this will cause mac80211 to abandon
3082 * attempts to connect to this AP, and eventually wpa_s will
3083 * blacklist the AP...
3085 if (vif
->type
== NL80211_IFTYPE_STATION
&&
3086 vif
->bss_conf
.beacon_int
< 16) {
3088 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
3089 sta
->addr
, vif
->bss_conf
.beacon_int
);
3096 iwl_mvm_tdls_sta_count(mvm
, NULL
) ==
3097 IWL_MVM_TDLS_STA_COUNT
||
3098 iwl_mvm_phy_ctx_count(mvm
) > 1)) {
3099 IWL_DEBUG_MAC80211(mvm
, "refusing TDLS sta\n");
3104 ret
= iwl_mvm_add_sta(mvm
, vif
, sta
);
3105 if (sta
->tdls
&& ret
== 0) {
3106 iwl_mvm_recalc_tdls_state(mvm
, vif
, true);
3107 iwl_mvm_tdls_check_trigger(mvm
, vif
, sta
->addr
,
3108 NL80211_TDLS_SETUP
);
3111 sta
->max_rc_amsdu_len
= 1;
3112 } else if (old_state
== IEEE80211_STA_NONE
&&
3113 new_state
== IEEE80211_STA_AUTH
) {
3115 * EBS may be disabled due to previous failures reported by FW.
3116 * Reset EBS status here assuming environment has been changed.
3118 mvm
->last_ebs_successful
= true;
3119 iwl_mvm_check_uapsd(mvm
, vif
, sta
->addr
);
3121 } else if (old_state
== IEEE80211_STA_AUTH
&&
3122 new_state
== IEEE80211_STA_ASSOC
) {
3123 if (vif
->type
== NL80211_IFTYPE_AP
) {
3124 vif
->bss_conf
.he_support
= sta
->he_cap
.has_he
;
3125 mvmvif
->ap_assoc_sta_count
++;
3126 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
3127 if (vif
->bss_conf
.he_support
&&
3128 !iwlwifi_mod_params
.disable_11ax
)
3129 iwl_mvm_cfg_he_sta(mvm
, vif
, mvm_sta
->sta_id
);
3130 } else if (vif
->type
== NL80211_IFTYPE_STATION
) {
3131 vif
->bss_conf
.he_support
= sta
->he_cap
.has_he
;
3133 mvmvif
->he_ru_2mhz_block
= false;
3134 if (sta
->he_cap
.has_he
)
3135 iwl_mvm_check_he_obss_narrow_bw_ru(hw
, vif
);
3137 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
3140 iwl_mvm_rs_rate_init(mvm
, sta
, mvmvif
->phy_ctxt
->channel
->band
,
3142 ret
= iwl_mvm_update_sta(mvm
, vif
, sta
);
3143 } else if (old_state
== IEEE80211_STA_ASSOC
&&
3144 new_state
== IEEE80211_STA_AUTHORIZED
) {
3147 /* we don't support TDLS during DCM */
3148 if (iwl_mvm_phy_ctx_count(mvm
) > 1)
3149 iwl_mvm_teardown_tdls_peers(mvm
);
3152 iwl_mvm_tdls_check_trigger(mvm
, vif
, sta
->addr
,
3153 NL80211_TDLS_ENABLE_LINK
);
3155 /* enable beacon filtering */
3156 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
, 0));
3159 * Now that the station is authorized, i.e., keys were already
3160 * installed, need to indicate to the FW that
3161 * multicast data frames can be forwarded to the driver
3163 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
3165 iwl_mvm_rs_rate_init(mvm
, sta
, mvmvif
->phy_ctxt
->channel
->band
,
3167 } else if (old_state
== IEEE80211_STA_AUTHORIZED
&&
3168 new_state
== IEEE80211_STA_ASSOC
) {
3169 /* Multicast data frames are no longer allowed */
3170 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
3172 /* disable beacon filtering */
3173 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
, 0);
3175 !test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED
,
3178 } else if (old_state
== IEEE80211_STA_ASSOC
&&
3179 new_state
== IEEE80211_STA_AUTH
) {
3180 if (vif
->type
== NL80211_IFTYPE_AP
) {
3181 mvmvif
->ap_assoc_sta_count
--;
3182 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
3185 } else if (old_state
== IEEE80211_STA_AUTH
&&
3186 new_state
== IEEE80211_STA_NONE
) {
3188 } else if (old_state
== IEEE80211_STA_NONE
&&
3189 new_state
== IEEE80211_STA_NOTEXIST
) {
3190 ret
= iwl_mvm_rm_sta(mvm
, vif
, sta
);
3192 iwl_mvm_recalc_tdls_state(mvm
, vif
, false);
3193 iwl_mvm_tdls_check_trigger(mvm
, vif
, sta
->addr
,
3194 NL80211_TDLS_DISABLE_LINK
);
3198 test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED
,
3205 mutex_unlock(&mvm
->mutex
);
3207 if (sta
->tdls
&& ret
== 0) {
3208 if (old_state
== IEEE80211_STA_NOTEXIST
&&
3209 new_state
== IEEE80211_STA_NONE
)
3210 ieee80211_reserve_tid(sta
, IWL_MVM_TDLS_FW_TID
);
3211 else if (old_state
== IEEE80211_STA_NONE
&&
3212 new_state
== IEEE80211_STA_NOTEXIST
)
3213 ieee80211_unreserve_tid(sta
, IWL_MVM_TDLS_FW_TID
);
3219 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3221 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3223 mvm
->rts_threshold
= value
;
3228 static void iwl_mvm_sta_rc_update(struct ieee80211_hw
*hw
,
3229 struct ieee80211_vif
*vif
,
3230 struct ieee80211_sta
*sta
, u32 changed
)
3232 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3233 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3235 if (changed
& (IEEE80211_RC_BW_CHANGED
|
3236 IEEE80211_RC_SUPP_RATES_CHANGED
|
3237 IEEE80211_RC_NSS_CHANGED
))
3238 iwl_mvm_rs_rate_init(mvm
, sta
, mvmvif
->phy_ctxt
->channel
->band
,
3241 if (vif
->type
== NL80211_IFTYPE_STATION
&&
3242 changed
& IEEE80211_RC_NSS_CHANGED
)
3243 iwl_mvm_sf_update(mvm
, vif
, false);
3246 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw
*hw
,
3247 struct ieee80211_vif
*vif
, u16 ac
,
3248 const struct ieee80211_tx_queue_params
*params
)
3250 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3251 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3253 mvmvif
->queue_params
[ac
] = *params
;
3256 * No need to update right away, we'll get BSS_CHANGED_QOS
3257 * The exception is P2P_DEVICE interface which needs immediate update.
3259 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
3262 mutex_lock(&mvm
->mutex
);
3263 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
3264 mutex_unlock(&mvm
->mutex
);
3270 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw
*hw
,
3271 struct ieee80211_vif
*vif
,
3274 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3275 u32 duration
= IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS
;
3276 u32 min_duration
= IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS
;
3278 if (req_duration
> duration
)
3279 duration
= req_duration
;
3281 mutex_lock(&mvm
->mutex
);
3282 /* Try really hard to protect the session and hear a beacon
3283 * The new session protection command allows us to protect the
3284 * session for a much longer time since the firmware will internally
3285 * create two events: a 300TU one with a very high priority that
3286 * won't be fragmented which should be enough for 99% of the cases,
3287 * and another one (which we configure here to be 900TU long) which
3288 * will have a slightly lower priority, but more importantly, can be
3289 * fragmented so that it'll allow other activities to run.
3291 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
3292 IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD
))
3293 iwl_mvm_schedule_session_protection(mvm
, vif
, 900,
3294 min_duration
, false);
3296 iwl_mvm_protect_session(mvm
, vif
, duration
,
3297 min_duration
, 500, false);
3298 mutex_unlock(&mvm
->mutex
);
3301 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw
*hw
,
3302 struct ieee80211_vif
*vif
,
3303 struct cfg80211_sched_scan_request
*req
,
3304 struct ieee80211_scan_ies
*ies
)
3306 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3310 mutex_lock(&mvm
->mutex
);
3312 if (!vif
->bss_conf
.idle
) {
3317 ret
= iwl_mvm_sched_scan_start(mvm
, vif
, req
, ies
, IWL_MVM_SCAN_SCHED
);
3320 mutex_unlock(&mvm
->mutex
);
3324 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw
*hw
,
3325 struct ieee80211_vif
*vif
)
3327 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3330 mutex_lock(&mvm
->mutex
);
3332 /* Due to a race condition, it's possible that mac80211 asks
3333 * us to stop a sched_scan when it's already stopped. This
3334 * can happen, for instance, if we stopped the scan ourselves,
3335 * called ieee80211_sched_scan_stopped() and the userspace called
3336 * stop sched scan scan before ieee80211_sched_scan_stopped_work()
3337 * could run. To handle this, simply return if the scan is
3340 if (!(mvm
->scan_status
& IWL_MVM_SCAN_SCHED
)) {
3341 mutex_unlock(&mvm
->mutex
);
3345 ret
= iwl_mvm_scan_stop(mvm
, IWL_MVM_SCAN_SCHED
, false);
3346 mutex_unlock(&mvm
->mutex
);
3347 iwl_mvm_wait_for_async_handlers(mvm
);
3352 static int __iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
3353 enum set_key_cmd cmd
,
3354 struct ieee80211_vif
*vif
,
3355 struct ieee80211_sta
*sta
,
3356 struct ieee80211_key_conf
*key
)
3358 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3359 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3360 struct iwl_mvm_sta
*mvmsta
;
3361 struct iwl_mvm_key_pn
*ptk_pn
;
3362 int keyidx
= key
->keyidx
;
3366 if (iwlwifi_mod_params
.swcrypto
) {
3367 IWL_DEBUG_MAC80211(mvm
, "leave - hwcrypto disabled\n");
3371 switch (key
->cipher
) {
3372 case WLAN_CIPHER_SUITE_TKIP
:
3373 if (!mvm
->trans
->trans_cfg
->gen2
) {
3374 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
3375 key
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
3376 } else if (vif
->type
== NL80211_IFTYPE_STATION
) {
3377 key
->flags
|= IEEE80211_KEY_FLAG_PUT_MIC_SPACE
;
3379 IWL_DEBUG_MAC80211(mvm
, "Use SW encryption for TKIP\n");
3383 case WLAN_CIPHER_SUITE_CCMP
:
3384 case WLAN_CIPHER_SUITE_GCMP
:
3385 case WLAN_CIPHER_SUITE_GCMP_256
:
3386 if (!iwl_mvm_has_new_tx_api(mvm
))
3387 key
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
3389 case WLAN_CIPHER_SUITE_AES_CMAC
:
3390 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
3391 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
3392 WARN_ON_ONCE(!ieee80211_hw_check(hw
, MFP_CAPABLE
));
3394 case WLAN_CIPHER_SUITE_WEP40
:
3395 case WLAN_CIPHER_SUITE_WEP104
:
3396 if (vif
->type
== NL80211_IFTYPE_STATION
)
3398 if (iwl_mvm_has_new_tx_api(mvm
))
3400 /* support HW crypto on TX */
3403 /* currently FW supports only one optional cipher scheme */
3404 if (hw
->n_cipher_schemes
&&
3405 hw
->cipher_schemes
->cipher
== key
->cipher
)
3406 key
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
3413 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
3414 vif
->type
== NL80211_IFTYPE_AP
) && !sta
) {
3416 * GTK on AP interface is a TX-only key, return 0;
3417 * on IBSS they're per-station and because we're lazy
3418 * we don't support them for RX, so do the same.
3419 * CMAC/GMAC in AP/IBSS modes must be done in software.
3421 if (key
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
||
3422 key
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_128
||
3423 key
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_256
)
3428 if (key
->cipher
!= WLAN_CIPHER_SUITE_GCMP
&&
3429 key
->cipher
!= WLAN_CIPHER_SUITE_GCMP_256
&&
3430 !iwl_mvm_has_new_tx_api(mvm
)) {
3431 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
3435 if (!mvmvif
->ap_ibss_active
) {
3437 i
< ARRAY_SIZE(mvmvif
->ap_early_keys
);
3439 if (!mvmvif
->ap_early_keys
[i
]) {
3440 mvmvif
->ap_early_keys
[i
] = key
;
3445 if (i
>= ARRAY_SIZE(mvmvif
->ap_early_keys
))
3452 /* During FW restart, in order to restore the state as it was,
3453 * don't try to reprogram keys we previously failed for.
3455 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
) &&
3456 key
->hw_key_idx
== STA_KEY_IDX_INVALID
) {
3457 IWL_DEBUG_MAC80211(mvm
,
3458 "skip invalid idx key programming during restart\n");
3463 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
) &&
3464 sta
&& iwl_mvm_has_new_rx_api(mvm
) &&
3465 key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
&&
3466 (key
->cipher
== WLAN_CIPHER_SUITE_CCMP
||
3467 key
->cipher
== WLAN_CIPHER_SUITE_GCMP
||
3468 key
->cipher
== WLAN_CIPHER_SUITE_GCMP_256
)) {
3469 struct ieee80211_key_seq seq
;
3472 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
3473 WARN_ON(rcu_access_pointer(mvmsta
->ptk_pn
[keyidx
]));
3474 ptk_pn
= kzalloc(struct_size(ptk_pn
, q
,
3475 mvm
->trans
->num_rx_queues
),
3482 for (tid
= 0; tid
< IWL_MAX_TID_COUNT
; tid
++) {
3483 ieee80211_get_key_rx_seq(key
, tid
, &seq
);
3484 for (q
= 0; q
< mvm
->trans
->num_rx_queues
; q
++)
3485 memcpy(ptk_pn
->q
[q
].pn
[tid
],
3487 IEEE80211_CCMP_PN_LEN
);
3490 rcu_assign_pointer(mvmsta
->ptk_pn
[keyidx
], ptk_pn
);
3493 /* in HW restart reuse the index, otherwise request a new one */
3494 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
3495 key_offset
= key
->hw_key_idx
;
3497 key_offset
= STA_KEY_IDX_INVALID
;
3499 IWL_DEBUG_MAC80211(mvm
, "set hwcrypto key\n");
3500 ret
= iwl_mvm_set_sta_key(mvm
, vif
, sta
, key
, key_offset
);
3502 IWL_WARN(mvm
, "set key failed\n");
3503 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
3505 * can't add key for RX, but we don't need it
3506 * in the device for TX so still return 0,
3507 * unless we have new TX API where we cannot
3508 * put key material into the TX_CMD
3510 if (iwl_mvm_has_new_tx_api(mvm
))
3519 for (i
= 0; i
< ARRAY_SIZE(mvmvif
->ap_early_keys
); i
++) {
3520 if (mvmvif
->ap_early_keys
[i
] == key
) {
3521 mvmvif
->ap_early_keys
[i
] = NULL
;
3526 /* found in pending list - don't do anything else */
3530 if (key
->hw_key_idx
== STA_KEY_IDX_INVALID
) {
3535 if (sta
&& iwl_mvm_has_new_rx_api(mvm
) &&
3536 key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
&&
3537 (key
->cipher
== WLAN_CIPHER_SUITE_CCMP
||
3538 key
->cipher
== WLAN_CIPHER_SUITE_GCMP
||
3539 key
->cipher
== WLAN_CIPHER_SUITE_GCMP_256
)) {
3540 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
3541 ptk_pn
= rcu_dereference_protected(
3542 mvmsta
->ptk_pn
[keyidx
],
3543 lockdep_is_held(&mvm
->mutex
));
3544 RCU_INIT_POINTER(mvmsta
->ptk_pn
[keyidx
], NULL
);
3546 kfree_rcu(ptk_pn
, rcu_head
);
3549 IWL_DEBUG_MAC80211(mvm
, "disable hwcrypto key\n");
3550 ret
= iwl_mvm_remove_sta_key(mvm
, vif
, sta
, key
);
3559 static int iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
3560 enum set_key_cmd cmd
,
3561 struct ieee80211_vif
*vif
,
3562 struct ieee80211_sta
*sta
,
3563 struct ieee80211_key_conf
*key
)
3565 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3568 mutex_lock(&mvm
->mutex
);
3569 ret
= __iwl_mvm_mac_set_key(hw
, cmd
, vif
, sta
, key
);
3570 mutex_unlock(&mvm
->mutex
);
3575 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw
*hw
,
3576 struct ieee80211_vif
*vif
,
3577 struct ieee80211_key_conf
*keyconf
,
3578 struct ieee80211_sta
*sta
,
3579 u32 iv32
, u16
*phase1key
)
3581 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3583 if (keyconf
->hw_key_idx
== STA_KEY_IDX_INVALID
)
3586 iwl_mvm_update_tkip_key(mvm
, vif
, keyconf
, sta
, iv32
, phase1key
);
3590 static bool iwl_mvm_rx_aux_roc(struct iwl_notif_wait_data
*notif_wait
,
3591 struct iwl_rx_packet
*pkt
, void *data
)
3593 struct iwl_mvm
*mvm
=
3594 container_of(notif_wait
, struct iwl_mvm
, notif_wait
);
3595 struct iwl_hs20_roc_res
*resp
;
3596 int resp_len
= iwl_rx_packet_payload_len(pkt
);
3597 struct iwl_mvm_time_event_data
*te_data
= data
;
3599 if (WARN_ON(pkt
->hdr
.cmd
!= HOT_SPOT_CMD
))
3602 if (WARN_ON_ONCE(resp_len
!= sizeof(*resp
))) {
3603 IWL_ERR(mvm
, "Invalid HOT_SPOT_CMD response\n");
3607 resp
= (void *)pkt
->data
;
3610 "Aux ROC: Received response from ucode: status=%d uid=%d\n",
3611 resp
->status
, resp
->event_unique_id
);
3613 te_data
->uid
= le32_to_cpu(resp
->event_unique_id
);
3614 IWL_DEBUG_TE(mvm
, "TIME_EVENT_CMD response - UID = 0x%x\n",
3617 spin_lock_bh(&mvm
->time_event_lock
);
3618 list_add_tail(&te_data
->list
, &mvm
->aux_roc_te_list
);
3619 spin_unlock_bh(&mvm
->time_event_lock
);
3624 #define AUX_ROC_MIN_DURATION MSEC_TO_TU(100)
3625 #define AUX_ROC_MIN_DELAY MSEC_TO_TU(200)
3626 #define AUX_ROC_MAX_DELAY MSEC_TO_TU(600)
3627 #define AUX_ROC_SAFETY_BUFFER MSEC_TO_TU(20)
3628 #define AUX_ROC_MIN_SAFETY_BUFFER MSEC_TO_TU(10)
3629 static int iwl_mvm_send_aux_roc_cmd(struct iwl_mvm
*mvm
,
3630 struct ieee80211_channel
*channel
,
3631 struct ieee80211_vif
*vif
,
3635 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3636 struct iwl_mvm_time_event_data
*te_data
= &mvmvif
->hs_time_event_data
;
3637 static const u16 time_event_response
[] = { HOT_SPOT_CMD
};
3638 struct iwl_notification_wait wait_time_event
;
3639 u32 dtim_interval
= vif
->bss_conf
.dtim_period
*
3640 vif
->bss_conf
.beacon_int
;
3642 struct iwl_hs20_roc_req aux_roc_req
= {
3643 .action
= cpu_to_le32(FW_CTXT_ACTION_ADD
),
3645 cpu_to_le32(FW_CMD_ID_AND_COLOR(MAC_INDEX_AUX
, 0)),
3646 .sta_id_and_color
= cpu_to_le32(mvm
->aux_sta
.sta_id
),
3648 struct iwl_hs20_roc_req_tail
*tail
= iwl_mvm_chan_info_cmd_tail(mvm
,
3649 &aux_roc_req
.channel_info
);
3650 u16 len
= sizeof(aux_roc_req
) - iwl_mvm_chan_info_padding(mvm
);
3652 /* Set the channel info data */
3653 iwl_mvm_set_chan_info(mvm
, &aux_roc_req
.channel_info
, channel
->hw_value
,
3654 iwl_mvm_phy_band_from_nl80211(channel
->band
),
3655 PHY_VHT_CHANNEL_MODE20
,
3658 /* Set the time and duration */
3659 tail
->apply_time
= cpu_to_le32(iwl_mvm_get_systime(mvm
));
3661 delay
= AUX_ROC_MIN_DELAY
;
3662 req_dur
= MSEC_TO_TU(duration
);
3665 * If we are associated we want the delay time to be at least one
3666 * dtim interval so that the FW can wait until after the DTIM and
3667 * then start the time event, this will potentially allow us to
3668 * remain off-channel for the max duration.
3669 * Since we want to use almost a whole dtim interval we would also
3670 * like the delay to be for 2-3 dtim intervals, in case there are
3671 * other time events with higher priority.
3673 if (vif
->bss_conf
.assoc
) {
3674 delay
= min_t(u32
, dtim_interval
* 3, AUX_ROC_MAX_DELAY
);
3675 /* We cannot remain off-channel longer than the DTIM interval */
3676 if (dtim_interval
<= req_dur
) {
3677 req_dur
= dtim_interval
- AUX_ROC_SAFETY_BUFFER
;
3678 if (req_dur
<= AUX_ROC_MIN_DURATION
)
3679 req_dur
= dtim_interval
-
3680 AUX_ROC_MIN_SAFETY_BUFFER
;
3684 tail
->duration
= cpu_to_le32(req_dur
);
3685 tail
->apply_time_max_delay
= cpu_to_le32(delay
);
3688 "ROC: Requesting to remain on channel %u for %ums (requested = %ums, max_delay = %ums, dtim_interval = %ums)\n",
3689 channel
->hw_value
, req_dur
, duration
, delay
,
3691 /* Set the node address */
3692 memcpy(tail
->node_addr
, vif
->addr
, ETH_ALEN
);
3694 lockdep_assert_held(&mvm
->mutex
);
3696 spin_lock_bh(&mvm
->time_event_lock
);
3698 if (WARN_ON(te_data
->id
== HOT_SPOT_CMD
)) {
3699 spin_unlock_bh(&mvm
->time_event_lock
);
3704 te_data
->duration
= duration
;
3705 te_data
->id
= HOT_SPOT_CMD
;
3707 spin_unlock_bh(&mvm
->time_event_lock
);
3710 * Use a notification wait, which really just processes the
3711 * command response and doesn't wait for anything, in order
3712 * to be able to process the response and get the UID inside
3713 * the RX path. Using CMD_WANT_SKB doesn't work because it
3714 * stores the buffer and then wakes up this thread, by which
3715 * time another notification (that the time event started)
3716 * might already be processed unsuccessfully.
3718 iwl_init_notification_wait(&mvm
->notif_wait
, &wait_time_event
,
3719 time_event_response
,
3720 ARRAY_SIZE(time_event_response
),
3721 iwl_mvm_rx_aux_roc
, te_data
);
3723 res
= iwl_mvm_send_cmd_pdu(mvm
, HOT_SPOT_CMD
, 0, len
,
3727 IWL_ERR(mvm
, "Couldn't send HOT_SPOT_CMD: %d\n", res
);
3728 iwl_remove_notification(&mvm
->notif_wait
, &wait_time_event
);
3732 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
3733 res
= iwl_wait_notification(&mvm
->notif_wait
, &wait_time_event
, 1);
3734 /* should never fail */
3739 spin_lock_bh(&mvm
->time_event_lock
);
3740 iwl_mvm_te_clear_data(mvm
, te_data
);
3741 spin_unlock_bh(&mvm
->time_event_lock
);
3747 static int iwl_mvm_roc(struct ieee80211_hw
*hw
,
3748 struct ieee80211_vif
*vif
,
3749 struct ieee80211_channel
*channel
,
3751 enum ieee80211_roc_type type
)
3753 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3754 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3755 struct cfg80211_chan_def chandef
;
3756 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
3759 IWL_DEBUG_MAC80211(mvm
, "enter (%d, %d, %d)\n", channel
->hw_value
,
3763 * Flush the done work, just in case it's still pending, so that
3764 * the work it does can complete and we can accept new frames.
3766 flush_work(&mvm
->roc_done_wk
);
3768 mutex_lock(&mvm
->mutex
);
3770 switch (vif
->type
) {
3771 case NL80211_IFTYPE_STATION
:
3772 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
3773 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT
)) {
3774 /* Use aux roc framework (HS20) */
3775 ret
= iwl_mvm_send_aux_roc_cmd(mvm
, channel
,
3779 IWL_ERR(mvm
, "hotspot not supported\n");
3782 case NL80211_IFTYPE_P2P_DEVICE
:
3786 IWL_ERR(mvm
, "vif isn't P2P_DEVICE: %d\n", vif
->type
);
3791 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
3792 phy_ctxt
= &mvm
->phy_ctxts
[i
];
3793 if (phy_ctxt
->ref
== 0 || mvmvif
->phy_ctxt
== phy_ctxt
)
3796 if (phy_ctxt
->ref
&& channel
== phy_ctxt
->channel
) {
3798 * Unbind the P2P_DEVICE from the current PHY context,
3799 * and if the PHY context is not used remove it.
3801 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
3802 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
3805 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
3807 /* Bind the P2P_DEVICE to the current PHY Context */
3808 mvmvif
->phy_ctxt
= phy_ctxt
;
3810 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
3811 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
3814 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
3815 goto schedule_time_event
;
3819 /* Need to update the PHY context only if the ROC channel changed */
3820 if (channel
== mvmvif
->phy_ctxt
->channel
)
3821 goto schedule_time_event
;
3823 cfg80211_chandef_create(&chandef
, channel
, NL80211_CHAN_NO_HT
);
3826 * Change the PHY context configuration as it is currently referenced
3827 * only by the P2P Device MAC
3829 if (mvmvif
->phy_ctxt
->ref
== 1) {
3830 ret
= iwl_mvm_phy_ctxt_changed(mvm
, mvmvif
->phy_ctxt
,
3836 * The PHY context is shared with other MACs. Need to remove the
3837 * P2P Device from the binding, allocate an new PHY context and
3838 * create a new binding
3840 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
3846 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &chandef
,
3849 IWL_ERR(mvm
, "Failed to change PHY context\n");
3853 /* Unbind the P2P_DEVICE from the current PHY context */
3854 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
3855 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
3858 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
3860 /* Bind the P2P_DEVICE to the new allocated PHY context */
3861 mvmvif
->phy_ctxt
= phy_ctxt
;
3863 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
3864 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
3867 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
3870 schedule_time_event
:
3871 /* Schedule the time events */
3872 ret
= iwl_mvm_start_p2p_roc(mvm
, vif
, duration
, type
);
3875 mutex_unlock(&mvm
->mutex
);
3876 IWL_DEBUG_MAC80211(mvm
, "leave\n");
3880 static int iwl_mvm_cancel_roc(struct ieee80211_hw
*hw
,
3881 struct ieee80211_vif
*vif
)
3883 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3885 IWL_DEBUG_MAC80211(mvm
, "enter\n");
3887 mutex_lock(&mvm
->mutex
);
3888 iwl_mvm_stop_roc(mvm
, vif
);
3889 mutex_unlock(&mvm
->mutex
);
3891 IWL_DEBUG_MAC80211(mvm
, "leave\n");
3895 struct iwl_mvm_ftm_responder_iter_data
{
3897 struct ieee80211_chanctx_conf
*ctx
;
3900 static void iwl_mvm_ftm_responder_chanctx_iter(void *_data
, u8
*mac
,
3901 struct ieee80211_vif
*vif
)
3903 struct iwl_mvm_ftm_responder_iter_data
*data
= _data
;
3905 if (rcu_access_pointer(vif
->chanctx_conf
) == data
->ctx
&&
3906 vif
->type
== NL80211_IFTYPE_AP
&& vif
->bss_conf
.ftmr_params
)
3907 data
->responder
= true;
3910 static bool iwl_mvm_is_ftm_responder_chanctx(struct iwl_mvm
*mvm
,
3911 struct ieee80211_chanctx_conf
*ctx
)
3913 struct iwl_mvm_ftm_responder_iter_data data
= {
3918 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
3919 IEEE80211_IFACE_ITER_NORMAL
,
3920 iwl_mvm_ftm_responder_chanctx_iter
,
3922 return data
.responder
;
3925 static int __iwl_mvm_add_chanctx(struct iwl_mvm
*mvm
,
3926 struct ieee80211_chanctx_conf
*ctx
)
3928 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
3929 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
3930 bool responder
= iwl_mvm_is_ftm_responder_chanctx(mvm
, ctx
);
3931 struct cfg80211_chan_def
*def
= responder
? &ctx
->def
: &ctx
->min_def
;
3934 lockdep_assert_held(&mvm
->mutex
);
3936 IWL_DEBUG_MAC80211(mvm
, "Add channel context\n");
3938 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
3944 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, def
,
3945 ctx
->rx_chains_static
,
3946 ctx
->rx_chains_dynamic
);
3948 IWL_ERR(mvm
, "Failed to add PHY context\n");
3952 iwl_mvm_phy_ctxt_ref(mvm
, phy_ctxt
);
3953 *phy_ctxt_id
= phy_ctxt
->id
;
3958 static int iwl_mvm_add_chanctx(struct ieee80211_hw
*hw
,
3959 struct ieee80211_chanctx_conf
*ctx
)
3961 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3964 mutex_lock(&mvm
->mutex
);
3965 ret
= __iwl_mvm_add_chanctx(mvm
, ctx
);
3966 mutex_unlock(&mvm
->mutex
);
3971 static void __iwl_mvm_remove_chanctx(struct iwl_mvm
*mvm
,
3972 struct ieee80211_chanctx_conf
*ctx
)
3974 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
3975 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
3977 lockdep_assert_held(&mvm
->mutex
);
3979 iwl_mvm_phy_ctxt_unref(mvm
, phy_ctxt
);
3982 static void iwl_mvm_remove_chanctx(struct ieee80211_hw
*hw
,
3983 struct ieee80211_chanctx_conf
*ctx
)
3985 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3987 mutex_lock(&mvm
->mutex
);
3988 __iwl_mvm_remove_chanctx(mvm
, ctx
);
3989 mutex_unlock(&mvm
->mutex
);
3992 static void iwl_mvm_change_chanctx(struct ieee80211_hw
*hw
,
3993 struct ieee80211_chanctx_conf
*ctx
,
3996 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
3997 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
3998 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
3999 bool responder
= iwl_mvm_is_ftm_responder_chanctx(mvm
, ctx
);
4000 struct cfg80211_chan_def
*def
= responder
? &ctx
->def
: &ctx
->min_def
;
4002 if (WARN_ONCE((phy_ctxt
->ref
> 1) &&
4003 (changed
& ~(IEEE80211_CHANCTX_CHANGE_WIDTH
|
4004 IEEE80211_CHANCTX_CHANGE_RX_CHAINS
|
4005 IEEE80211_CHANCTX_CHANGE_RADAR
|
4006 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH
)),
4007 "Cannot change PHY. Ref=%d, changed=0x%X\n",
4008 phy_ctxt
->ref
, changed
))
4011 mutex_lock(&mvm
->mutex
);
4013 /* we are only changing the min_width, may be a noop */
4014 if (changed
== IEEE80211_CHANCTX_CHANGE_MIN_WIDTH
) {
4015 if (phy_ctxt
->width
== def
->width
)
4018 /* we are just toggling between 20_NOHT and 20 */
4019 if (phy_ctxt
->width
<= NL80211_CHAN_WIDTH_20
&&
4020 def
->width
<= NL80211_CHAN_WIDTH_20
)
4024 iwl_mvm_bt_coex_vif_change(mvm
);
4025 iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, def
,
4026 ctx
->rx_chains_static
,
4027 ctx
->rx_chains_dynamic
);
4030 mutex_unlock(&mvm
->mutex
);
4033 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm
*mvm
,
4034 struct ieee80211_vif
*vif
,
4035 struct ieee80211_chanctx_conf
*ctx
,
4036 bool switching_chanctx
)
4038 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
4039 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
4040 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4043 lockdep_assert_held(&mvm
->mutex
);
4045 mvmvif
->phy_ctxt
= phy_ctxt
;
4047 switch (vif
->type
) {
4048 case NL80211_IFTYPE_AP
:
4049 /* only needed if we're switching chanctx (i.e. during CSA) */
4050 if (switching_chanctx
) {
4051 mvmvif
->ap_ibss_active
= true;
4055 case NL80211_IFTYPE_ADHOC
:
4057 * The AP binding flow is handled as part of the start_ap flow
4058 * (in bss_info_changed), similarly for IBSS.
4062 case NL80211_IFTYPE_STATION
:
4063 mvmvif
->csa_bcn_pending
= false;
4065 case NL80211_IFTYPE_MONITOR
:
4066 /* always disable PS when a monitor interface is active */
4067 mvmvif
->ps_disabled
= true;
4074 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
4079 * Power state must be updated before quotas,
4080 * otherwise fw will complain.
4082 iwl_mvm_power_update_mac(mvm
);
4084 /* Setting the quota at this stage is only required for monitor
4085 * interfaces. For the other types, the bss_info changed flow
4086 * will handle quota settings.
4088 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
4089 mvmvif
->monitor_active
= true;
4090 ret
= iwl_mvm_update_quotas(mvm
, false, NULL
);
4092 goto out_remove_binding
;
4094 ret
= iwl_mvm_add_snif_sta(mvm
, vif
);
4096 goto out_remove_binding
;
4100 /* Handle binding during CSA */
4101 if (vif
->type
== NL80211_IFTYPE_AP
) {
4102 iwl_mvm_update_quotas(mvm
, false, NULL
);
4103 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false, NULL
);
4106 if (switching_chanctx
&& vif
->type
== NL80211_IFTYPE_STATION
) {
4107 mvmvif
->csa_bcn_pending
= true;
4109 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
4110 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD
)) {
4111 u32 duration
= 3 * vif
->bss_conf
.beacon_int
;
4113 /* Protect the session to make sure we hear the first
4114 * beacon on the new channel.
4116 iwl_mvm_protect_session(mvm
, vif
, duration
, duration
,
4117 vif
->bss_conf
.beacon_int
/ 2,
4121 iwl_mvm_update_quotas(mvm
, false, NULL
);
4127 iwl_mvm_binding_remove_vif(mvm
, vif
);
4128 iwl_mvm_power_update_mac(mvm
);
4131 mvmvif
->phy_ctxt
= NULL
;
4134 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw
*hw
,
4135 struct ieee80211_vif
*vif
,
4136 struct ieee80211_chanctx_conf
*ctx
)
4138 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4141 mutex_lock(&mvm
->mutex
);
4142 ret
= __iwl_mvm_assign_vif_chanctx(mvm
, vif
, ctx
, false);
4143 mutex_unlock(&mvm
->mutex
);
4148 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm
*mvm
,
4149 struct ieee80211_vif
*vif
,
4150 struct ieee80211_chanctx_conf
*ctx
,
4151 bool switching_chanctx
)
4153 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4154 struct ieee80211_vif
*disabled_vif
= NULL
;
4156 lockdep_assert_held(&mvm
->mutex
);
4158 iwl_mvm_remove_time_event(mvm
, mvmvif
, &mvmvif
->time_event_data
);
4160 switch (vif
->type
) {
4161 case NL80211_IFTYPE_ADHOC
:
4163 case NL80211_IFTYPE_MONITOR
:
4164 mvmvif
->monitor_active
= false;
4165 mvmvif
->ps_disabled
= false;
4166 iwl_mvm_rm_snif_sta(mvm
, vif
);
4168 case NL80211_IFTYPE_AP
:
4169 /* This part is triggered only during CSA */
4170 if (!switching_chanctx
|| !mvmvif
->ap_ibss_active
)
4173 mvmvif
->csa_countdown
= false;
4175 /* Set CS bit on all the stations */
4176 iwl_mvm_modify_all_sta_disable_tx(mvm
, mvmvif
, true);
4178 /* Save blocked iface, the timeout is set on the next beacon */
4179 rcu_assign_pointer(mvm
->csa_tx_blocked_vif
, vif
);
4181 mvmvif
->ap_ibss_active
= false;
4183 case NL80211_IFTYPE_STATION
:
4184 if (!switching_chanctx
)
4189 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
4190 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD
))
4191 iwl_mvm_mac_ctxt_changed(mvm
, vif
, true, NULL
);
4197 iwl_mvm_update_quotas(mvm
, false, disabled_vif
);
4198 iwl_mvm_binding_remove_vif(mvm
, vif
);
4201 mvmvif
->phy_ctxt
= NULL
;
4202 iwl_mvm_power_update_mac(mvm
);
4205 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
4206 struct ieee80211_vif
*vif
,
4207 struct ieee80211_chanctx_conf
*ctx
)
4209 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4211 mutex_lock(&mvm
->mutex
);
4212 __iwl_mvm_unassign_vif_chanctx(mvm
, vif
, ctx
, false);
4213 mutex_unlock(&mvm
->mutex
);
4217 iwl_mvm_switch_vif_chanctx_swap(struct iwl_mvm
*mvm
,
4218 struct ieee80211_vif_chanctx_switch
*vifs
)
4222 mutex_lock(&mvm
->mutex
);
4223 __iwl_mvm_unassign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].old_ctx
, true);
4224 __iwl_mvm_remove_chanctx(mvm
, vifs
[0].old_ctx
);
4226 ret
= __iwl_mvm_add_chanctx(mvm
, vifs
[0].new_ctx
);
4228 IWL_ERR(mvm
, "failed to add new_ctx during channel switch\n");
4232 ret
= __iwl_mvm_assign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].new_ctx
,
4236 "failed to assign new_ctx during channel switch\n");
4240 /* we don't support TDLS during DCM - can be caused by channel switch */
4241 if (iwl_mvm_phy_ctx_count(mvm
) > 1)
4242 iwl_mvm_teardown_tdls_peers(mvm
);
4247 __iwl_mvm_remove_chanctx(mvm
, vifs
[0].new_ctx
);
4250 if (__iwl_mvm_add_chanctx(mvm
, vifs
[0].old_ctx
)) {
4251 IWL_ERR(mvm
, "failed to add old_ctx back after failure.\n");
4255 if (__iwl_mvm_assign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].old_ctx
,
4257 IWL_ERR(mvm
, "failed to reassign old_ctx after failure.\n");
4264 /* things keep failing, better restart the hw */
4265 iwl_mvm_nic_restart(mvm
, false);
4268 mutex_unlock(&mvm
->mutex
);
4274 iwl_mvm_switch_vif_chanctx_reassign(struct iwl_mvm
*mvm
,
4275 struct ieee80211_vif_chanctx_switch
*vifs
)
4279 mutex_lock(&mvm
->mutex
);
4280 __iwl_mvm_unassign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].old_ctx
, true);
4282 ret
= __iwl_mvm_assign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].new_ctx
,
4286 "failed to assign new_ctx during channel switch\n");
4293 if (__iwl_mvm_assign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].old_ctx
,
4295 IWL_ERR(mvm
, "failed to reassign old_ctx after failure.\n");
4302 /* things keep failing, better restart the hw */
4303 iwl_mvm_nic_restart(mvm
, false);
4306 mutex_unlock(&mvm
->mutex
);
4311 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw
*hw
,
4312 struct ieee80211_vif_chanctx_switch
*vifs
,
4314 enum ieee80211_chanctx_switch_mode mode
)
4316 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4319 /* we only support a single-vif right now */
4324 case CHANCTX_SWMODE_SWAP_CONTEXTS
:
4325 ret
= iwl_mvm_switch_vif_chanctx_swap(mvm
, vifs
);
4327 case CHANCTX_SWMODE_REASSIGN_VIF
:
4328 ret
= iwl_mvm_switch_vif_chanctx_reassign(mvm
, vifs
);
4338 static int iwl_mvm_tx_last_beacon(struct ieee80211_hw
*hw
)
4340 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4342 return mvm
->ibss_manager
;
4345 static int iwl_mvm_set_tim(struct ieee80211_hw
*hw
,
4346 struct ieee80211_sta
*sta
,
4349 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4350 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
4352 if (!mvm_sta
|| !mvm_sta
->vif
) {
4353 IWL_ERR(mvm
, "Station is not associated to a vif\n");
4357 return iwl_mvm_mac_ctxt_beacon_changed(mvm
, mvm_sta
->vif
);
4360 #ifdef CONFIG_NL80211_TESTMODE
4361 static const struct nla_policy iwl_mvm_tm_policy
[IWL_MVM_TM_ATTR_MAX
+ 1] = {
4362 [IWL_MVM_TM_ATTR_CMD
] = { .type
= NLA_U32
},
4363 [IWL_MVM_TM_ATTR_NOA_DURATION
] = { .type
= NLA_U32
},
4364 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
] = { .type
= NLA_U32
},
4367 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm
*mvm
,
4368 struct ieee80211_vif
*vif
,
4369 void *data
, int len
)
4371 struct nlattr
*tb
[IWL_MVM_TM_ATTR_MAX
+ 1];
4375 err
= nla_parse_deprecated(tb
, IWL_MVM_TM_ATTR_MAX
, data
, len
,
4376 iwl_mvm_tm_policy
, NULL
);
4380 if (!tb
[IWL_MVM_TM_ATTR_CMD
])
4383 switch (nla_get_u32(tb
[IWL_MVM_TM_ATTR_CMD
])) {
4384 case IWL_MVM_TM_CMD_SET_NOA
:
4385 if (!vif
|| vif
->type
!= NL80211_IFTYPE_AP
|| !vif
->p2p
||
4386 !vif
->bss_conf
.enable_beacon
||
4387 !tb
[IWL_MVM_TM_ATTR_NOA_DURATION
])
4390 noa_duration
= nla_get_u32(tb
[IWL_MVM_TM_ATTR_NOA_DURATION
]);
4391 if (noa_duration
>= vif
->bss_conf
.beacon_int
)
4394 mvm
->noa_duration
= noa_duration
;
4397 return iwl_mvm_update_quotas(mvm
, true, NULL
);
4398 case IWL_MVM_TM_CMD_SET_BEACON_FILTER
:
4399 /* must be associated client vif - ignore authorized */
4400 if (!vif
|| vif
->type
!= NL80211_IFTYPE_STATION
||
4401 !vif
->bss_conf
.assoc
|| !vif
->bss_conf
.dtim_period
||
4402 !tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
])
4405 if (nla_get_u32(tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
]))
4406 return iwl_mvm_enable_beacon_filter(mvm
, vif
, 0);
4407 return iwl_mvm_disable_beacon_filter(mvm
, vif
, 0);
4413 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw
*hw
,
4414 struct ieee80211_vif
*vif
,
4415 void *data
, int len
)
4417 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4420 mutex_lock(&mvm
->mutex
);
4421 err
= __iwl_mvm_mac_testmode_cmd(mvm
, vif
, data
, len
);
4422 mutex_unlock(&mvm
->mutex
);
4428 static void iwl_mvm_channel_switch(struct ieee80211_hw
*hw
,
4429 struct ieee80211_vif
*vif
,
4430 struct ieee80211_channel_switch
*chsw
)
4432 /* By implementing this operation, we prevent mac80211 from
4433 * starting its own channel switch timer, so that we can call
4434 * ieee80211_chswitch_done() ourselves at the right time
4435 * (which is when the absence time event starts).
4438 IWL_DEBUG_MAC80211(IWL_MAC80211_GET_MVM(hw
),
4439 "dummy channel switch op\n");
4442 static int iwl_mvm_schedule_client_csa(struct iwl_mvm
*mvm
,
4443 struct ieee80211_vif
*vif
,
4444 struct ieee80211_channel_switch
*chsw
)
4446 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4447 struct iwl_chan_switch_te_cmd cmd
= {
4448 .mac_id
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->id
,
4450 .action
= cpu_to_le32(FW_CTXT_ACTION_ADD
),
4451 .tsf
= cpu_to_le32(chsw
->timestamp
),
4452 .cs_count
= chsw
->count
,
4453 .cs_mode
= chsw
->block_tx
,
4456 lockdep_assert_held(&mvm
->mutex
);
4459 cmd
.cs_delayed_bcn_count
=
4460 DIV_ROUND_UP(chsw
->delay
, vif
->bss_conf
.beacon_int
);
4462 return iwl_mvm_send_cmd_pdu(mvm
,
4463 WIDE_ID(MAC_CONF_GROUP
,
4464 CHANNEL_SWITCH_TIME_EVENT_CMD
),
4465 0, sizeof(cmd
), &cmd
);
4468 static int iwl_mvm_old_pre_chan_sw_sta(struct iwl_mvm
*mvm
,
4469 struct ieee80211_vif
*vif
,
4470 struct ieee80211_channel_switch
*chsw
)
4472 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4475 /* Schedule the time event to a bit before beacon 1,
4476 * to make sure we're in the new channel when the
4477 * GO/AP arrives. In case count <= 1 immediately schedule the
4478 * TE (this might result with some packet loss or connection
4481 if (chsw
->count
<= 1)
4484 apply_time
= chsw
->device_timestamp
+
4485 ((vif
->bss_conf
.beacon_int
* (chsw
->count
- 1) -
4486 IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT
) * 1024);
4489 iwl_mvm_csa_client_absent(mvm
, vif
);
4491 if (mvmvif
->bf_data
.bf_enabled
) {
4492 int ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
, 0);
4498 iwl_mvm_schedule_csa_period(mvm
, vif
, vif
->bss_conf
.beacon_int
,
4504 #define IWL_MAX_CSA_BLOCK_TX 1500
4505 static int iwl_mvm_pre_channel_switch(struct ieee80211_hw
*hw
,
4506 struct ieee80211_vif
*vif
,
4507 struct ieee80211_channel_switch
*chsw
)
4509 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4510 struct ieee80211_vif
*csa_vif
;
4511 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4514 mutex_lock(&mvm
->mutex
);
4516 mvmvif
->csa_failed
= false;
4518 IWL_DEBUG_MAC80211(mvm
, "pre CSA to freq %d\n",
4519 chsw
->chandef
.center_freq1
);
4521 iwl_fw_dbg_trigger_simple_stop(&mvm
->fwrt
,
4522 ieee80211_vif_to_wdev(vif
),
4523 FW_DBG_TRIGGER_CHANNEL_SWITCH
);
4525 switch (vif
->type
) {
4526 case NL80211_IFTYPE_AP
:
4528 rcu_dereference_protected(mvm
->csa_vif
,
4529 lockdep_is_held(&mvm
->mutex
));
4530 if (WARN_ONCE(csa_vif
&& csa_vif
->csa_active
,
4531 "Another CSA is already in progress")) {
4536 /* we still didn't unblock tx. prevent new CS meanwhile */
4537 if (rcu_dereference_protected(mvm
->csa_tx_blocked_vif
,
4538 lockdep_is_held(&mvm
->mutex
))) {
4543 rcu_assign_pointer(mvm
->csa_vif
, vif
);
4545 if (WARN_ONCE(mvmvif
->csa_countdown
,
4546 "Previous CSA countdown didn't complete")) {
4551 mvmvif
->csa_target_freq
= chsw
->chandef
.chan
->center_freq
;
4554 case NL80211_IFTYPE_STATION
:
4555 if (chsw
->block_tx
) {
4557 * In case of undetermined / long time with immediate
4558 * quiet monitor status to gracefully disconnect
4561 chsw
->count
* vif
->bss_conf
.beacon_int
>
4562 IWL_MAX_CSA_BLOCK_TX
)
4563 schedule_delayed_work(&mvmvif
->csa_work
,
4564 msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX
));
4567 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
4568 IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD
)) {
4569 ret
= iwl_mvm_old_pre_chan_sw_sta(mvm
, vif
, chsw
);
4573 iwl_mvm_schedule_client_csa(mvm
, vif
, chsw
);
4576 mvmvif
->csa_count
= chsw
->count
;
4577 mvmvif
->csa_misbehave
= false;
4583 mvmvif
->ps_disabled
= true;
4585 ret
= iwl_mvm_power_update_ps(mvm
);
4589 /* we won't be on this channel any longer */
4590 iwl_mvm_teardown_tdls_peers(mvm
);
4593 mutex_unlock(&mvm
->mutex
);
4598 static void iwl_mvm_channel_switch_rx_beacon(struct ieee80211_hw
*hw
,
4599 struct ieee80211_vif
*vif
,
4600 struct ieee80211_channel_switch
*chsw
)
4602 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4603 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4604 struct iwl_chan_switch_te_cmd cmd
= {
4605 .mac_id
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->id
,
4607 .action
= cpu_to_le32(FW_CTXT_ACTION_MODIFY
),
4608 .tsf
= cpu_to_le32(chsw
->timestamp
),
4609 .cs_count
= chsw
->count
,
4610 .cs_mode
= chsw
->block_tx
,
4613 if (!fw_has_capa(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_CAPA_CS_MODIFY
))
4616 if (chsw
->count
>= mvmvif
->csa_count
&& chsw
->block_tx
) {
4617 if (mvmvif
->csa_misbehave
) {
4618 /* Second time, give up on this AP*/
4619 iwl_mvm_abort_channel_switch(hw
, vif
);
4620 ieee80211_chswitch_done(vif
, false);
4621 mvmvif
->csa_misbehave
= false;
4624 mvmvif
->csa_misbehave
= true;
4626 mvmvif
->csa_count
= chsw
->count
;
4628 IWL_DEBUG_MAC80211(mvm
, "Modify CSA on mac %d\n", mvmvif
->id
);
4630 WARN_ON(iwl_mvm_send_cmd_pdu(mvm
,
4631 WIDE_ID(MAC_CONF_GROUP
,
4632 CHANNEL_SWITCH_TIME_EVENT_CMD
),
4633 CMD_ASYNC
, sizeof(cmd
), &cmd
));
4636 static void iwl_mvm_flush_no_vif(struct iwl_mvm
*mvm
, u32 queues
, bool drop
)
4640 if (!iwl_mvm_has_new_tx_api(mvm
)) {
4642 mutex_lock(&mvm
->mutex
);
4643 iwl_mvm_flush_tx_path(mvm
,
4644 iwl_mvm_flushable_queues(mvm
) & queues
, 0);
4645 mutex_unlock(&mvm
->mutex
);
4647 iwl_trans_wait_tx_queues_empty(mvm
->trans
, queues
);
4652 mutex_lock(&mvm
->mutex
);
4653 for (i
= 0; i
< ARRAY_SIZE(mvm
->fw_id_to_mac_id
); i
++) {
4654 struct ieee80211_sta
*sta
;
4656 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
4657 lockdep_is_held(&mvm
->mutex
));
4658 if (IS_ERR_OR_NULL(sta
))
4662 iwl_mvm_flush_sta_tids(mvm
, i
, 0xFFFF, 0);
4664 iwl_mvm_wait_sta_queues_empty(mvm
,
4665 iwl_mvm_sta_from_mac80211(sta
));
4667 mutex_unlock(&mvm
->mutex
);
4670 static void iwl_mvm_mac_flush(struct ieee80211_hw
*hw
,
4671 struct ieee80211_vif
*vif
, u32 queues
, bool drop
)
4673 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4674 struct iwl_mvm_vif
*mvmvif
;
4675 struct iwl_mvm_sta
*mvmsta
;
4676 struct ieee80211_sta
*sta
;
4681 iwl_mvm_flush_no_vif(mvm
, queues
, drop
);
4685 if (vif
->type
!= NL80211_IFTYPE_STATION
)
4688 /* Make sure we're done with the deferred traffic before flushing */
4689 flush_work(&mvm
->add_stream_wk
);
4691 mutex_lock(&mvm
->mutex
);
4692 mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4694 /* flush the AP-station and all TDLS peers */
4695 for (i
= 0; i
< ARRAY_SIZE(mvm
->fw_id_to_mac_id
); i
++) {
4696 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
4697 lockdep_is_held(&mvm
->mutex
));
4698 if (IS_ERR_OR_NULL(sta
))
4701 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
4702 if (mvmsta
->vif
!= vif
)
4705 /* make sure only TDLS peers or the AP are flushed */
4706 WARN_ON(i
!= mvmvif
->ap_sta_id
&& !sta
->tdls
);
4709 if (iwl_mvm_flush_sta(mvm
, mvmsta
, false, 0))
4710 IWL_ERR(mvm
, "flush request fail\n");
4712 msk
|= mvmsta
->tfd_queue_msk
;
4713 if (iwl_mvm_has_new_tx_api(mvm
))
4714 iwl_mvm_wait_sta_queues_empty(mvm
, mvmsta
);
4718 mutex_unlock(&mvm
->mutex
);
4720 /* this can take a while, and we may need/want other operations
4721 * to succeed while doing this, so do it without the mutex held
4723 if (!drop
&& !iwl_mvm_has_new_tx_api(mvm
))
4724 iwl_trans_wait_tx_queues_empty(mvm
->trans
, msk
);
4727 static int iwl_mvm_mac_get_survey(struct ieee80211_hw
*hw
, int idx
,
4728 struct survey_info
*survey
)
4730 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4733 memset(survey
, 0, sizeof(*survey
));
4735 /* only support global statistics right now */
4739 if (!fw_has_capa(&mvm
->fw
->ucode_capa
,
4740 IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS
))
4743 mutex_lock(&mvm
->mutex
);
4745 if (iwl_mvm_firmware_running(mvm
)) {
4746 ret
= iwl_mvm_request_statistics(mvm
, false);
4751 survey
->filled
= SURVEY_INFO_TIME
|
4752 SURVEY_INFO_TIME_RX
|
4753 SURVEY_INFO_TIME_TX
|
4754 SURVEY_INFO_TIME_SCAN
;
4755 survey
->time
= mvm
->accu_radio_stats
.on_time_rf
+
4756 mvm
->radio_stats
.on_time_rf
;
4757 do_div(survey
->time
, USEC_PER_MSEC
);
4759 survey
->time_rx
= mvm
->accu_radio_stats
.rx_time
+
4760 mvm
->radio_stats
.rx_time
;
4761 do_div(survey
->time_rx
, USEC_PER_MSEC
);
4763 survey
->time_tx
= mvm
->accu_radio_stats
.tx_time
+
4764 mvm
->radio_stats
.tx_time
;
4765 do_div(survey
->time_tx
, USEC_PER_MSEC
);
4767 survey
->time_scan
= mvm
->accu_radio_stats
.on_time_scan
+
4768 mvm
->radio_stats
.on_time_scan
;
4769 do_div(survey
->time_scan
, USEC_PER_MSEC
);
4773 mutex_unlock(&mvm
->mutex
);
4777 static void iwl_mvm_set_sta_rate(u32 rate_n_flags
, struct rate_info
*rinfo
)
4779 switch (rate_n_flags
& RATE_MCS_CHAN_WIDTH_MSK
) {
4780 case RATE_MCS_CHAN_WIDTH_20
:
4781 rinfo
->bw
= RATE_INFO_BW_20
;
4783 case RATE_MCS_CHAN_WIDTH_40
:
4784 rinfo
->bw
= RATE_INFO_BW_40
;
4786 case RATE_MCS_CHAN_WIDTH_80
:
4787 rinfo
->bw
= RATE_INFO_BW_80
;
4789 case RATE_MCS_CHAN_WIDTH_160
:
4790 rinfo
->bw
= RATE_INFO_BW_160
;
4794 if (rate_n_flags
& RATE_MCS_HT_MSK
) {
4795 rinfo
->flags
|= RATE_INFO_FLAGS_MCS
;
4796 rinfo
->mcs
= u32_get_bits(rate_n_flags
, RATE_HT_MCS_INDEX_MSK
);
4797 rinfo
->nss
= u32_get_bits(rate_n_flags
,
4798 RATE_HT_MCS_NSS_MSK
) + 1;
4799 if (rate_n_flags
& RATE_MCS_SGI_MSK
)
4800 rinfo
->flags
|= RATE_INFO_FLAGS_SHORT_GI
;
4801 } else if (rate_n_flags
& RATE_MCS_VHT_MSK
) {
4802 rinfo
->flags
|= RATE_INFO_FLAGS_VHT_MCS
;
4803 rinfo
->mcs
= u32_get_bits(rate_n_flags
,
4804 RATE_VHT_MCS_RATE_CODE_MSK
);
4805 rinfo
->nss
= u32_get_bits(rate_n_flags
,
4806 RATE_VHT_MCS_NSS_MSK
) + 1;
4807 if (rate_n_flags
& RATE_MCS_SGI_MSK
)
4808 rinfo
->flags
|= RATE_INFO_FLAGS_SHORT_GI
;
4809 } else if (rate_n_flags
& RATE_MCS_HE_MSK
) {
4810 u32 gi_ltf
= u32_get_bits(rate_n_flags
,
4811 RATE_MCS_HE_GI_LTF_MSK
);
4813 rinfo
->flags
|= RATE_INFO_FLAGS_HE_MCS
;
4814 rinfo
->mcs
= u32_get_bits(rate_n_flags
,
4815 RATE_VHT_MCS_RATE_CODE_MSK
);
4816 rinfo
->nss
= u32_get_bits(rate_n_flags
,
4817 RATE_VHT_MCS_NSS_MSK
) + 1;
4819 if (rate_n_flags
& RATE_MCS_HE_106T_MSK
) {
4820 rinfo
->bw
= RATE_INFO_BW_HE_RU
;
4821 rinfo
->he_ru_alloc
= NL80211_RATE_INFO_HE_RU_ALLOC_106
;
4824 switch (rate_n_flags
& RATE_MCS_HE_TYPE_MSK
) {
4825 case RATE_MCS_HE_TYPE_SU
:
4826 case RATE_MCS_HE_TYPE_EXT_SU
:
4827 if (gi_ltf
== 0 || gi_ltf
== 1)
4828 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_0_8
;
4829 else if (gi_ltf
== 2)
4830 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_1_6
;
4831 else if (rate_n_flags
& RATE_MCS_SGI_MSK
)
4832 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_0_8
;
4834 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_3_2
;
4836 case RATE_MCS_HE_TYPE_MU
:
4837 if (gi_ltf
== 0 || gi_ltf
== 1)
4838 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_0_8
;
4839 else if (gi_ltf
== 2)
4840 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_1_6
;
4842 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_3_2
;
4844 case RATE_MCS_HE_TYPE_TRIG
:
4845 if (gi_ltf
== 0 || gi_ltf
== 1)
4846 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_1_6
;
4848 rinfo
->he_gi
= NL80211_RATE_INFO_HE_GI_3_2
;
4852 if (rate_n_flags
& RATE_HE_DUAL_CARRIER_MODE_MSK
)
4855 switch (u32_get_bits(rate_n_flags
, RATE_LEGACY_RATE_MSK
)) {
4856 case IWL_RATE_1M_PLCP
:
4859 case IWL_RATE_2M_PLCP
:
4862 case IWL_RATE_5M_PLCP
:
4865 case IWL_RATE_11M_PLCP
:
4866 rinfo
->legacy
= 110;
4868 case IWL_RATE_6M_PLCP
:
4871 case IWL_RATE_9M_PLCP
:
4874 case IWL_RATE_12M_PLCP
:
4875 rinfo
->legacy
= 120;
4877 case IWL_RATE_18M_PLCP
:
4878 rinfo
->legacy
= 180;
4880 case IWL_RATE_24M_PLCP
:
4881 rinfo
->legacy
= 240;
4883 case IWL_RATE_36M_PLCP
:
4884 rinfo
->legacy
= 360;
4886 case IWL_RATE_48M_PLCP
:
4887 rinfo
->legacy
= 480;
4889 case IWL_RATE_54M_PLCP
:
4890 rinfo
->legacy
= 540;
4896 static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw
*hw
,
4897 struct ieee80211_vif
*vif
,
4898 struct ieee80211_sta
*sta
,
4899 struct station_info
*sinfo
)
4901 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
4902 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
4903 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
4905 if (mvmsta
->avg_energy
) {
4906 sinfo
->signal_avg
= mvmsta
->avg_energy
;
4907 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG
);
4910 if (iwl_mvm_has_tlc_offload(mvm
)) {
4911 struct iwl_lq_sta_rs_fw
*lq_sta
= &mvmsta
->lq_sta
.rs_fw
;
4913 iwl_mvm_set_sta_rate(lq_sta
->last_rate_n_flags
, &sinfo
->txrate
);
4914 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_TX_BITRATE
);
4917 /* if beacon filtering isn't on mac80211 does it anyway */
4918 if (!(vif
->driver_flags
& IEEE80211_VIF_BEACON_FILTER
))
4921 if (!vif
->bss_conf
.assoc
)
4924 mutex_lock(&mvm
->mutex
);
4926 if (mvmvif
->ap_sta_id
!= mvmsta
->sta_id
)
4929 if (iwl_mvm_request_statistics(mvm
, false))
4932 sinfo
->rx_beacon
= mvmvif
->beacon_stats
.num_beacons
+
4933 mvmvif
->beacon_stats
.accu_num_beacons
;
4934 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_BEACON_RX
);
4935 if (mvmvif
->beacon_stats
.avg_signal
) {
4936 /* firmware only reports a value after RXing a few beacons */
4937 sinfo
->rx_beacon_signal_avg
= mvmvif
->beacon_stats
.avg_signal
;
4938 sinfo
->filled
|= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG
);
4941 mutex_unlock(&mvm
->mutex
);
4944 static void iwl_mvm_event_mlme_callback(struct iwl_mvm
*mvm
,
4945 struct ieee80211_vif
*vif
,
4946 const struct ieee80211_event
*event
)
4948 #define CHECK_MLME_TRIGGER(_cnt, _fmt...) \
4950 if ((trig_mlme->_cnt) && --(trig_mlme->_cnt)) \
4952 iwl_fw_dbg_collect_trig(&(mvm)->fwrt, trig, _fmt); \
4955 struct iwl_fw_dbg_trigger_tlv
*trig
;
4956 struct iwl_fw_dbg_trigger_mlme
*trig_mlme
;
4958 trig
= iwl_fw_dbg_trigger_on(&mvm
->fwrt
, ieee80211_vif_to_wdev(vif
),
4959 FW_DBG_TRIGGER_MLME
);
4963 trig_mlme
= (void *)trig
->data
;
4965 if (event
->u
.mlme
.data
== ASSOC_EVENT
) {
4966 if (event
->u
.mlme
.status
== MLME_DENIED
)
4967 CHECK_MLME_TRIGGER(stop_assoc_denied
,
4968 "DENIED ASSOC: reason %d",
4969 event
->u
.mlme
.reason
);
4970 else if (event
->u
.mlme
.status
== MLME_TIMEOUT
)
4971 CHECK_MLME_TRIGGER(stop_assoc_timeout
,
4973 } else if (event
->u
.mlme
.data
== AUTH_EVENT
) {
4974 if (event
->u
.mlme
.status
== MLME_DENIED
)
4975 CHECK_MLME_TRIGGER(stop_auth_denied
,
4976 "DENIED AUTH: reason %d",
4977 event
->u
.mlme
.reason
);
4978 else if (event
->u
.mlme
.status
== MLME_TIMEOUT
)
4979 CHECK_MLME_TRIGGER(stop_auth_timeout
,
4981 } else if (event
->u
.mlme
.data
== DEAUTH_RX_EVENT
) {
4982 CHECK_MLME_TRIGGER(stop_rx_deauth
,
4983 "DEAUTH RX %d", event
->u
.mlme
.reason
);
4984 } else if (event
->u
.mlme
.data
== DEAUTH_TX_EVENT
) {
4985 CHECK_MLME_TRIGGER(stop_tx_deauth
,
4986 "DEAUTH TX %d", event
->u
.mlme
.reason
);
4988 #undef CHECK_MLME_TRIGGER
4991 static void iwl_mvm_event_bar_rx_callback(struct iwl_mvm
*mvm
,
4992 struct ieee80211_vif
*vif
,
4993 const struct ieee80211_event
*event
)
4995 struct iwl_fw_dbg_trigger_tlv
*trig
;
4996 struct iwl_fw_dbg_trigger_ba
*ba_trig
;
4998 trig
= iwl_fw_dbg_trigger_on(&mvm
->fwrt
, ieee80211_vif_to_wdev(vif
),
5003 ba_trig
= (void *)trig
->data
;
5005 if (!(le16_to_cpu(ba_trig
->rx_bar
) & BIT(event
->u
.ba
.tid
)))
5008 iwl_fw_dbg_collect_trig(&mvm
->fwrt
, trig
,
5009 "BAR received from %pM, tid %d, ssn %d",
5010 event
->u
.ba
.sta
->addr
, event
->u
.ba
.tid
,
5014 static void iwl_mvm_mac_event_callback(struct ieee80211_hw
*hw
,
5015 struct ieee80211_vif
*vif
,
5016 const struct ieee80211_event
*event
)
5018 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
5020 switch (event
->type
) {
5022 iwl_mvm_event_mlme_callback(mvm
, vif
, event
);
5025 iwl_mvm_event_bar_rx_callback(mvm
, vif
, event
);
5027 case BA_FRAME_TIMEOUT
:
5028 iwl_mvm_event_frame_timeout_callback(mvm
, vif
, event
->u
.ba
.sta
,
5036 void iwl_mvm_sync_rx_queues_internal(struct iwl_mvm
*mvm
,
5037 struct iwl_mvm_internal_rxq_notif
*notif
,
5040 u32 qmask
= BIT(mvm
->trans
->num_rx_queues
) - 1;
5044 if (!iwl_mvm_has_new_rx_api(mvm
))
5048 notif
->cookie
= mvm
->queue_sync_cookie
;
5049 atomic_set(&mvm
->queue_sync_counter
,
5050 mvm
->trans
->num_rx_queues
);
5053 ret
= iwl_mvm_notify_rx_queue(mvm
, qmask
, (u8
*)notif
,
5054 size
, !notif
->sync
);
5056 IWL_ERR(mvm
, "Failed to trigger RX queues sync (%d)\n", ret
);
5061 lockdep_assert_held(&mvm
->mutex
);
5062 ret
= wait_event_timeout(mvm
->rx_sync_waitq
,
5063 atomic_read(&mvm
->queue_sync_counter
) == 0 ||
5064 iwl_mvm_is_radio_killed(mvm
),
5066 WARN_ON_ONCE(!ret
&& !iwl_mvm_is_radio_killed(mvm
));
5070 atomic_set(&mvm
->queue_sync_counter
, 0);
5072 mvm
->queue_sync_cookie
++;
5075 static void iwl_mvm_sync_rx_queues(struct ieee80211_hw
*hw
)
5077 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
5078 struct iwl_mvm_internal_rxq_notif data
= {
5079 .type
= IWL_MVM_RXQ_EMPTY
,
5083 mutex_lock(&mvm
->mutex
);
5084 iwl_mvm_sync_rx_queues_internal(mvm
, &data
, sizeof(data
));
5085 mutex_unlock(&mvm
->mutex
);
5089 iwl_mvm_mac_get_ftm_responder_stats(struct ieee80211_hw
*hw
,
5090 struct ieee80211_vif
*vif
,
5091 struct cfg80211_ftm_responder_stats
*stats
)
5093 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
5094 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
5096 if (vif
->p2p
|| vif
->type
!= NL80211_IFTYPE_AP
||
5097 !mvmvif
->ap_ibss_active
|| !vif
->bss_conf
.ftm_responder
)
5100 mutex_lock(&mvm
->mutex
);
5101 *stats
= mvm
->ftm_resp_stats
;
5102 mutex_unlock(&mvm
->mutex
);
5104 stats
->filled
= BIT(NL80211_FTM_STATS_SUCCESS_NUM
) |
5105 BIT(NL80211_FTM_STATS_PARTIAL_NUM
) |
5106 BIT(NL80211_FTM_STATS_FAILED_NUM
) |
5107 BIT(NL80211_FTM_STATS_ASAP_NUM
) |
5108 BIT(NL80211_FTM_STATS_NON_ASAP_NUM
) |
5109 BIT(NL80211_FTM_STATS_TOTAL_DURATION_MSEC
) |
5110 BIT(NL80211_FTM_STATS_UNKNOWN_TRIGGERS_NUM
) |
5111 BIT(NL80211_FTM_STATS_RESCHEDULE_REQUESTS_NUM
) |
5112 BIT(NL80211_FTM_STATS_OUT_OF_WINDOW_TRIGGERS_NUM
);
5117 static int iwl_mvm_start_pmsr(struct ieee80211_hw
*hw
,
5118 struct ieee80211_vif
*vif
,
5119 struct cfg80211_pmsr_request
*request
)
5121 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
5124 mutex_lock(&mvm
->mutex
);
5125 ret
= iwl_mvm_ftm_start(mvm
, vif
, request
);
5126 mutex_unlock(&mvm
->mutex
);
5131 static void iwl_mvm_abort_pmsr(struct ieee80211_hw
*hw
,
5132 struct ieee80211_vif
*vif
,
5133 struct cfg80211_pmsr_request
*request
)
5135 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
5137 mutex_lock(&mvm
->mutex
);
5138 iwl_mvm_ftm_abort(mvm
, request
);
5139 mutex_unlock(&mvm
->mutex
);
5142 static bool iwl_mvm_can_hw_csum(struct sk_buff
*skb
)
5144 u8 protocol
= ip_hdr(skb
)->protocol
;
5146 if (!IS_ENABLED(CONFIG_INET
))
5149 return protocol
== IPPROTO_TCP
|| protocol
== IPPROTO_UDP
;
5152 static bool iwl_mvm_mac_can_aggregate(struct ieee80211_hw
*hw
,
5153 struct sk_buff
*head
,
5154 struct sk_buff
*skb
)
5156 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
5158 /* For now don't aggregate IPv6 in AMSDU */
5159 if (skb
->protocol
!= htons(ETH_P_IP
))
5162 if (!iwl_mvm_is_csum_supported(mvm
))
5165 return iwl_mvm_can_hw_csum(skb
) == iwl_mvm_can_hw_csum(head
);
5168 const struct ieee80211_ops iwl_mvm_hw_ops
= {
5169 .tx
= iwl_mvm_mac_tx
,
5170 .wake_tx_queue
= iwl_mvm_mac_wake_tx_queue
,
5171 .ampdu_action
= iwl_mvm_mac_ampdu_action
,
5172 .get_antenna
= iwl_mvm_op_get_antenna
,
5173 .start
= iwl_mvm_mac_start
,
5174 .reconfig_complete
= iwl_mvm_mac_reconfig_complete
,
5175 .stop
= iwl_mvm_mac_stop
,
5176 .add_interface
= iwl_mvm_mac_add_interface
,
5177 .remove_interface
= iwl_mvm_mac_remove_interface
,
5178 .config
= iwl_mvm_mac_config
,
5179 .prepare_multicast
= iwl_mvm_prepare_multicast
,
5180 .configure_filter
= iwl_mvm_configure_filter
,
5181 .config_iface_filter
= iwl_mvm_config_iface_filter
,
5182 .bss_info_changed
= iwl_mvm_bss_info_changed
,
5183 .hw_scan
= iwl_mvm_mac_hw_scan
,
5184 .cancel_hw_scan
= iwl_mvm_mac_cancel_hw_scan
,
5185 .sta_pre_rcu_remove
= iwl_mvm_sta_pre_rcu_remove
,
5186 .sta_state
= iwl_mvm_mac_sta_state
,
5187 .sta_notify
= iwl_mvm_mac_sta_notify
,
5188 .allow_buffered_frames
= iwl_mvm_mac_allow_buffered_frames
,
5189 .release_buffered_frames
= iwl_mvm_mac_release_buffered_frames
,
5190 .set_rts_threshold
= iwl_mvm_mac_set_rts_threshold
,
5191 .sta_rc_update
= iwl_mvm_sta_rc_update
,
5192 .conf_tx
= iwl_mvm_mac_conf_tx
,
5193 .mgd_prepare_tx
= iwl_mvm_mac_mgd_prepare_tx
,
5194 .mgd_protect_tdls_discover
= iwl_mvm_mac_mgd_protect_tdls_discover
,
5195 .flush
= iwl_mvm_mac_flush
,
5196 .sched_scan_start
= iwl_mvm_mac_sched_scan_start
,
5197 .sched_scan_stop
= iwl_mvm_mac_sched_scan_stop
,
5198 .set_key
= iwl_mvm_mac_set_key
,
5199 .update_tkip_key
= iwl_mvm_mac_update_tkip_key
,
5200 .remain_on_channel
= iwl_mvm_roc
,
5201 .cancel_remain_on_channel
= iwl_mvm_cancel_roc
,
5202 .add_chanctx
= iwl_mvm_add_chanctx
,
5203 .remove_chanctx
= iwl_mvm_remove_chanctx
,
5204 .change_chanctx
= iwl_mvm_change_chanctx
,
5205 .assign_vif_chanctx
= iwl_mvm_assign_vif_chanctx
,
5206 .unassign_vif_chanctx
= iwl_mvm_unassign_vif_chanctx
,
5207 .switch_vif_chanctx
= iwl_mvm_switch_vif_chanctx
,
5209 .start_ap
= iwl_mvm_start_ap_ibss
,
5210 .stop_ap
= iwl_mvm_stop_ap_ibss
,
5211 .join_ibss
= iwl_mvm_start_ap_ibss
,
5212 .leave_ibss
= iwl_mvm_stop_ap_ibss
,
5214 .tx_last_beacon
= iwl_mvm_tx_last_beacon
,
5216 .set_tim
= iwl_mvm_set_tim
,
5218 .channel_switch
= iwl_mvm_channel_switch
,
5219 .pre_channel_switch
= iwl_mvm_pre_channel_switch
,
5220 .post_channel_switch
= iwl_mvm_post_channel_switch
,
5221 .abort_channel_switch
= iwl_mvm_abort_channel_switch
,
5222 .channel_switch_rx_beacon
= iwl_mvm_channel_switch_rx_beacon
,
5224 .tdls_channel_switch
= iwl_mvm_tdls_channel_switch
,
5225 .tdls_cancel_channel_switch
= iwl_mvm_tdls_cancel_channel_switch
,
5226 .tdls_recv_channel_switch
= iwl_mvm_tdls_recv_channel_switch
,
5228 .event_callback
= iwl_mvm_mac_event_callback
,
5230 .sync_rx_queues
= iwl_mvm_sync_rx_queues
,
5232 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd
)
5234 #ifdef CONFIG_PM_SLEEP
5236 .suspend
= iwl_mvm_suspend
,
5237 .resume
= iwl_mvm_resume
,
5238 .set_wakeup
= iwl_mvm_set_wakeup
,
5239 .set_rekey_data
= iwl_mvm_set_rekey_data
,
5240 #if IS_ENABLED(CONFIG_IPV6)
5241 .ipv6_addr_change
= iwl_mvm_ipv6_addr_change
,
5243 .set_default_unicast_key
= iwl_mvm_set_default_unicast_key
,
5245 .get_survey
= iwl_mvm_mac_get_survey
,
5246 .sta_statistics
= iwl_mvm_mac_sta_statistics
,
5247 .get_ftm_responder_stats
= iwl_mvm_mac_get_ftm_responder_stats
,
5248 .start_pmsr
= iwl_mvm_start_pmsr
,
5249 .abort_pmsr
= iwl_mvm_abort_pmsr
,
5251 .can_aggregate_in_amsdu
= iwl_mvm_mac_can_aggregate
,
5252 #ifdef CONFIG_IWLWIFI_DEBUGFS
5253 .sta_add_debugfs
= iwl_mvm_sta_add_debugfs
,