1 // SPDX-License-Identifier: BSD-3-Clause-Clear
3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
7 #include <net/mac80211.h>
8 #include <linux/etherdevice.h>
9 #include <linux/bitfield.h>
10 #include <linux/inetdevice.h>
11 #include <net/if_inet6.h>
23 #include "debugfs_sta.h"
27 #define CHAN2G(_channel, _freq, _flags) { \
28 .band = NL80211_BAND_2GHZ, \
29 .hw_value = (_channel), \
30 .center_freq = (_freq), \
32 .max_antenna_gain = 0, \
36 #define CHAN5G(_channel, _freq, _flags) { \
37 .band = NL80211_BAND_5GHZ, \
38 .hw_value = (_channel), \
39 .center_freq = (_freq), \
41 .max_antenna_gain = 0, \
45 #define CHAN6G(_channel, _freq, _flags) { \
46 .band = NL80211_BAND_6GHZ, \
47 .hw_value = (_channel), \
48 .center_freq = (_freq), \
50 .max_antenna_gain = 0, \
54 static const struct ieee80211_channel ath11k_2ghz_channels[] = {
71 static const struct ieee80211_channel ath11k_5ghz_channels[] = {
101 static const struct ieee80211_channel ath11k_6ghz_channels[] = {
127 CHAN6G(101, 6455, 0),
128 CHAN6G(105, 6475, 0),
129 CHAN6G(109, 6495, 0),
130 CHAN6G(113, 6515, 0),
131 CHAN6G(117, 6535, 0),
132 CHAN6G(121, 6555, 0),
133 CHAN6G(125, 6575, 0),
134 CHAN6G(129, 6595, 0),
135 CHAN6G(133, 6615, 0),
136 CHAN6G(137, 6635, 0),
137 CHAN6G(141, 6655, 0),
138 CHAN6G(145, 6675, 0),
139 CHAN6G(149, 6695, 0),
140 CHAN6G(153, 6715, 0),
141 CHAN6G(157, 6735, 0),
142 CHAN6G(161, 6755, 0),
143 CHAN6G(165, 6775, 0),
144 CHAN6G(169, 6795, 0),
145 CHAN6G(173, 6815, 0),
146 CHAN6G(177, 6835, 0),
147 CHAN6G(181, 6855, 0),
148 CHAN6G(185, 6875, 0),
149 CHAN6G(189, 6895, 0),
150 CHAN6G(193, 6915, 0),
151 CHAN6G(197, 6935, 0),
152 CHAN6G(201, 6955, 0),
153 CHAN6G(205, 6975, 0),
154 CHAN6G(209, 6995, 0),
155 CHAN6G(213, 7015, 0),
156 CHAN6G(217, 7035, 0),
157 CHAN6G(221, 7055, 0),
158 CHAN6G(225, 7075, 0),
159 CHAN6G(229, 7095, 0),
160 CHAN6G(233, 7115, 0),
162 /* new addition in IEEE Std 802.11ax-2021 */
166 static struct ieee80211_rate ath11k_legacy_rates[] = {
168 .hw_value = ATH11K_HW_RATE_CCK_LP_1M },
170 .hw_value = ATH11K_HW_RATE_CCK_LP_2M,
171 .hw_value_short = ATH11K_HW_RATE_CCK_SP_2M,
172 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
174 .hw_value = ATH11K_HW_RATE_CCK_LP_5_5M,
175 .hw_value_short = ATH11K_HW_RATE_CCK_SP_5_5M,
176 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
178 .hw_value = ATH11K_HW_RATE_CCK_LP_11M,
179 .hw_value_short = ATH11K_HW_RATE_CCK_SP_11M,
180 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
182 { .bitrate = 60, .hw_value = ATH11K_HW_RATE_OFDM_6M },
183 { .bitrate = 90, .hw_value = ATH11K_HW_RATE_OFDM_9M },
184 { .bitrate = 120, .hw_value = ATH11K_HW_RATE_OFDM_12M },
185 { .bitrate = 180, .hw_value = ATH11K_HW_RATE_OFDM_18M },
186 { .bitrate = 240, .hw_value = ATH11K_HW_RATE_OFDM_24M },
187 { .bitrate = 360, .hw_value = ATH11K_HW_RATE_OFDM_36M },
188 { .bitrate = 480, .hw_value = ATH11K_HW_RATE_OFDM_48M },
189 { .bitrate = 540, .hw_value = ATH11K_HW_RATE_OFDM_54M },
193 ath11k_phymodes[NUM_NL80211_BANDS][ATH11K_CHAN_WIDTH_NUM] = {
194 [NL80211_BAND_2GHZ] = {
195 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
196 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
197 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20_2G,
198 [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20_2G,
199 [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40_2G,
200 [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80_2G,
201 [NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN,
202 [NL80211_CHAN_WIDTH_160] = MODE_UNKNOWN,
204 [NL80211_BAND_5GHZ] = {
205 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
206 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
207 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20,
208 [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20,
209 [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40,
210 [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80,
211 [NL80211_CHAN_WIDTH_160] = MODE_11AX_HE160,
212 [NL80211_CHAN_WIDTH_80P80] = MODE_11AX_HE80_80,
214 [NL80211_BAND_6GHZ] = {
215 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
216 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
217 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20,
218 [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20,
219 [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40,
220 [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80,
221 [NL80211_CHAN_WIDTH_160] = MODE_11AX_HE160,
222 [NL80211_CHAN_WIDTH_80P80] = MODE_11AX_HE80_80,
227 const struct htt_rx_ring_tlv_filter ath11k_mac_mon_status_filter_default = {
228 .rx_filter = HTT_RX_FILTER_TLV_FLAGS_MPDU_START |
229 HTT_RX_FILTER_TLV_FLAGS_PPDU_END |
230 HTT_RX_FILTER_TLV_FLAGS_PPDU_END_STATUS_DONE,
231 .pkt_filter_flags0 = HTT_RX_FP_MGMT_FILTER_FLAGS0,
232 .pkt_filter_flags1 = HTT_RX_FP_MGMT_FILTER_FLAGS1,
233 .pkt_filter_flags2 = HTT_RX_FP_CTRL_FILTER_FLASG2,
234 .pkt_filter_flags3 = HTT_RX_FP_DATA_FILTER_FLASG3 |
235 HTT_RX_FP_CTRL_FILTER_FLASG3
238 #define ATH11K_MAC_FIRST_OFDM_RATE_IDX 4
239 #define ath11k_g_rates ath11k_legacy_rates
240 #define ath11k_g_rates_size (ARRAY_SIZE(ath11k_legacy_rates))
241 #define ath11k_a_rates (ath11k_legacy_rates + 4)
242 #define ath11k_a_rates_size (ARRAY_SIZE(ath11k_legacy_rates) - 4)
244 #define ATH11K_MAC_SCAN_TIMEOUT_MSECS 200 /* in msecs */
246 static const u32 ath11k_smps_map[] = {
247 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
248 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
249 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
250 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
253 static int ath11k_start_vdev_delay(struct ieee80211_hw *hw,
254 struct ieee80211_vif *vif);
256 enum nl80211_he_ru_alloc ath11k_mac_phy_he_ru_to_nl80211_he_ru_alloc(u16 ru_phy)
258 enum nl80211_he_ru_alloc ret;
262 ret = NL80211_RATE_INFO_HE_RU_ALLOC_26;
265 ret = NL80211_RATE_INFO_HE_RU_ALLOC_52;
268 ret = NL80211_RATE_INFO_HE_RU_ALLOC_106;
271 ret = NL80211_RATE_INFO_HE_RU_ALLOC_242;
274 ret = NL80211_RATE_INFO_HE_RU_ALLOC_484;
277 ret = NL80211_RATE_INFO_HE_RU_ALLOC_996;
280 ret = NL80211_RATE_INFO_HE_RU_ALLOC_26;
287 enum nl80211_he_ru_alloc ath11k_mac_he_ru_tones_to_nl80211_he_ru_alloc(u16 ru_tones)
289 enum nl80211_he_ru_alloc ret;
293 ret = NL80211_RATE_INFO_HE_RU_ALLOC_26;
296 ret = NL80211_RATE_INFO_HE_RU_ALLOC_52;
299 ret = NL80211_RATE_INFO_HE_RU_ALLOC_106;
302 ret = NL80211_RATE_INFO_HE_RU_ALLOC_242;
305 ret = NL80211_RATE_INFO_HE_RU_ALLOC_484;
308 ret = NL80211_RATE_INFO_HE_RU_ALLOC_996;
311 ret = NL80211_RATE_INFO_HE_RU_ALLOC_2x996;
314 ret = NL80211_RATE_INFO_HE_RU_ALLOC_26;
321 enum nl80211_he_gi ath11k_mac_he_gi_to_nl80211_he_gi(u8 sgi)
323 enum nl80211_he_gi ret;
326 case RX_MSDU_START_SGI_0_8_US:
327 ret = NL80211_RATE_INFO_HE_GI_0_8;
329 case RX_MSDU_START_SGI_1_6_US:
330 ret = NL80211_RATE_INFO_HE_GI_1_6;
332 case RX_MSDU_START_SGI_3_2_US:
333 ret = NL80211_RATE_INFO_HE_GI_3_2;
336 ret = NL80211_RATE_INFO_HE_GI_0_8;
343 u8 ath11k_mac_bw_to_mac80211_bw(u8 bw)
349 ret = RATE_INFO_BW_20;
352 ret = RATE_INFO_BW_40;
355 ret = RATE_INFO_BW_80;
358 ret = RATE_INFO_BW_160;
365 enum ath11k_supported_bw ath11k_mac_mac80211_bw_to_ath11k_bw(enum rate_info_bw bw)
368 case RATE_INFO_BW_20:
370 case RATE_INFO_BW_40:
372 case RATE_INFO_BW_80:
374 case RATE_INFO_BW_160:
375 return ATH11K_BW_160;
381 int ath11k_mac_hw_ratecode_to_legacy_rate(u8 hw_rc, u8 preamble, u8 *rateidx,
384 /* As default, it is OFDM rates */
385 int i = ATH11K_MAC_FIRST_OFDM_RATE_IDX;
386 int max_rates_idx = ath11k_g_rates_size;
388 if (preamble == WMI_RATE_PREAMBLE_CCK) {
389 hw_rc &= ~ATH11k_HW_RATECODE_CCK_SHORT_PREAM_MASK;
391 max_rates_idx = ATH11K_MAC_FIRST_OFDM_RATE_IDX;
394 while (i < max_rates_idx) {
395 if (hw_rc == ath11k_legacy_rates[i].hw_value) {
397 *rate = ath11k_legacy_rates[i].bitrate;
406 static int get_num_chains(u32 mask)
419 u8 ath11k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
424 for (i = 0; i < sband->n_bitrates; i++)
425 if (sband->bitrates[i].bitrate == bitrate)
432 ath11k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
436 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
437 if (ht_mcs_mask[nss])
444 ath11k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
448 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
449 if (vht_mcs_mask[nss])
456 ath11k_mac_max_he_nss(const u16 he_mcs_mask[NL80211_HE_NSS_MAX])
460 for (nss = NL80211_HE_NSS_MAX - 1; nss >= 0; nss--)
461 if (he_mcs_mask[nss])
467 static u8 ath11k_parse_mpdudensity(u8 mpdudensity)
469 /* 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
470 * 0 for no restriction
479 switch (mpdudensity) {
485 /* Our lower layer calculations limit our precision to
502 static int ath11k_mac_vif_chan(struct ieee80211_vif *vif,
503 struct cfg80211_chan_def *def)
505 struct ieee80211_chanctx_conf *conf;
508 conf = rcu_dereference(vif->bss_conf.chanctx_conf);
520 static bool ath11k_mac_bitrate_is_cck(int bitrate)
533 u8 ath11k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
534 u8 hw_rate, bool cck)
536 const struct ieee80211_rate *rate;
539 for (i = 0; i < sband->n_bitrates; i++) {
540 rate = &sband->bitrates[i];
542 if (ath11k_mac_bitrate_is_cck(rate->bitrate) != cck)
545 if (rate->hw_value == hw_rate)
547 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
548 rate->hw_value_short == hw_rate)
555 static u8 ath11k_mac_bitrate_to_rate(int bitrate)
557 return DIV_ROUND_UP(bitrate, 5) |
558 (ath11k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
561 static void ath11k_get_arvif_iter(void *data, u8 *mac,
562 struct ieee80211_vif *vif)
564 struct ath11k_vif_iter *arvif_iter = data;
565 struct ath11k_vif *arvif = (void *)vif->drv_priv;
567 if (arvif->vdev_id == arvif_iter->vdev_id)
568 arvif_iter->arvif = arvif;
571 struct ath11k_vif *ath11k_mac_get_arvif(struct ath11k *ar, u32 vdev_id)
573 struct ath11k_vif_iter arvif_iter;
576 memset(&arvif_iter, 0, sizeof(struct ath11k_vif_iter));
577 arvif_iter.vdev_id = vdev_id;
579 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
580 ieee80211_iterate_active_interfaces_atomic(ar->hw,
582 ath11k_get_arvif_iter,
584 if (!arvif_iter.arvif) {
585 ath11k_warn(ar->ab, "No VIF found for vdev %d\n", vdev_id);
589 return arvif_iter.arvif;
592 struct ath11k_vif *ath11k_mac_get_arvif_by_vdev_id(struct ath11k_base *ab,
596 struct ath11k_pdev *pdev;
597 struct ath11k_vif *arvif;
599 for (i = 0; i < ab->num_radios; i++) {
600 pdev = rcu_dereference(ab->pdevs_active[i]);
601 if (pdev && pdev->ar &&
602 (pdev->ar->allocated_vdev_map & (1LL << vdev_id))) {
603 arvif = ath11k_mac_get_arvif(pdev->ar, vdev_id);
612 struct ath11k *ath11k_mac_get_ar_by_vdev_id(struct ath11k_base *ab, u32 vdev_id)
615 struct ath11k_pdev *pdev;
617 for (i = 0; i < ab->num_radios; i++) {
618 pdev = rcu_dereference(ab->pdevs_active[i]);
619 if (pdev && pdev->ar) {
620 if (pdev->ar->allocated_vdev_map & (1LL << vdev_id))
628 struct ath11k *ath11k_mac_get_ar_by_pdev_id(struct ath11k_base *ab, u32 pdev_id)
631 struct ath11k_pdev *pdev;
633 if (ab->hw_params.single_pdev_only) {
634 pdev = rcu_dereference(ab->pdevs_active[0]);
635 return pdev ? pdev->ar : NULL;
638 if (WARN_ON(pdev_id > ab->num_radios))
641 for (i = 0; i < ab->num_radios; i++) {
642 pdev = rcu_dereference(ab->pdevs_active[i]);
644 if (pdev && pdev->pdev_id == pdev_id)
645 return (pdev->ar ? pdev->ar : NULL);
651 struct ath11k_vif *ath11k_mac_get_vif_up(struct ath11k_base *ab)
654 struct ath11k_pdev *pdev;
655 struct ath11k_vif *arvif;
658 for (i = 0; i < ab->num_radios; i++) {
659 pdev = &ab->pdevs[i];
661 list_for_each_entry(arvif, &ar->arvifs, list) {
670 static bool ath11k_mac_band_match(enum nl80211_band band1, enum WMI_HOST_WLAN_BAND band2)
672 return (((band1 == NL80211_BAND_2GHZ) && (band2 & WMI_HOST_WLAN_2G_CAP)) ||
673 (((band1 == NL80211_BAND_5GHZ) || (band1 == NL80211_BAND_6GHZ)) &&
674 (band2 & WMI_HOST_WLAN_5G_CAP)));
677 u8 ath11k_mac_get_target_pdev_id_from_vif(struct ath11k_vif *arvif)
679 struct ath11k *ar = arvif->ar;
680 struct ath11k_base *ab = ar->ab;
681 struct ieee80211_vif *vif = arvif->vif;
682 struct cfg80211_chan_def def;
683 enum nl80211_band band;
684 u8 pdev_id = ab->target_pdev_ids[0].pdev_id;
687 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
690 band = def.chan->band;
692 for (i = 0; i < ab->target_pdev_count; i++) {
693 if (ath11k_mac_band_match(band, ab->target_pdev_ids[i].supported_bands))
694 return ab->target_pdev_ids[i].pdev_id;
700 u8 ath11k_mac_get_target_pdev_id(struct ath11k *ar)
702 struct ath11k_vif *arvif;
704 arvif = ath11k_mac_get_vif_up(ar->ab);
707 return ath11k_mac_get_target_pdev_id_from_vif(arvif);
709 return ar->ab->target_pdev_ids[0].pdev_id;
712 static void ath11k_pdev_caps_update(struct ath11k *ar)
714 struct ath11k_base *ab = ar->ab;
716 ar->max_tx_power = ab->target_caps.hw_max_tx_power;
718 /* FIXME Set min_tx_power to ab->target_caps.hw_min_tx_power.
719 * But since the received value in svcrdy is same as hw_max_tx_power,
720 * we can set ar->min_tx_power to 0 currently until
721 * this is fixed in firmware
723 ar->min_tx_power = 0;
725 ar->txpower_limit_2g = ar->max_tx_power;
726 ar->txpower_limit_5g = ar->max_tx_power;
727 ar->txpower_scale = WMI_HOST_TP_SCALE_MAX;
730 static int ath11k_mac_txpower_recalc(struct ath11k *ar)
732 struct ath11k_pdev *pdev = ar->pdev;
733 struct ath11k_vif *arvif;
734 int ret, txpower = -1;
737 lockdep_assert_held(&ar->conf_mutex);
739 list_for_each_entry(arvif, &ar->arvifs, list) {
740 if (arvif->txpower <= 0)
744 txpower = arvif->txpower;
746 txpower = min(txpower, arvif->txpower);
752 /* txpwr is set as 2 units per dBm in FW*/
753 txpower = min_t(u32, max_t(u32, ar->min_tx_power, txpower),
754 ar->max_tx_power) * 2;
756 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "txpower to set in hw %d\n",
759 if ((pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) &&
760 ar->txpower_limit_2g != txpower) {
761 param = WMI_PDEV_PARAM_TXPOWER_LIMIT2G;
762 ret = ath11k_wmi_pdev_set_param(ar, param,
763 txpower, ar->pdev->pdev_id);
766 ar->txpower_limit_2g = txpower;
769 if ((pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) &&
770 ar->txpower_limit_5g != txpower) {
771 param = WMI_PDEV_PARAM_TXPOWER_LIMIT5G;
772 ret = ath11k_wmi_pdev_set_param(ar, param,
773 txpower, ar->pdev->pdev_id);
776 ar->txpower_limit_5g = txpower;
782 ath11k_warn(ar->ab, "failed to recalc txpower limit %d using pdev param %d: %d\n",
783 txpower / 2, param, ret);
787 static int ath11k_recalc_rtscts_prot(struct ath11k_vif *arvif)
789 struct ath11k *ar = arvif->ar;
790 u32 vdev_param, rts_cts = 0;
793 lockdep_assert_held(&ar->conf_mutex);
795 vdev_param = WMI_VDEV_PARAM_ENABLE_RTSCTS;
797 /* Enable RTS/CTS protection for sw retries (when legacy stations
798 * are in BSS) or by default only for second rate series.
799 * TODO: Check if we need to enable CTS 2 Self in any case
801 rts_cts = WMI_USE_RTS_CTS;
803 if (arvif->num_legacy_stations > 0)
804 rts_cts |= WMI_RTSCTS_ACROSS_SW_RETRIES << 4;
806 rts_cts |= WMI_RTSCTS_FOR_SECOND_RATESERIES << 4;
808 /* Need not send duplicate param value to firmware */
809 if (arvif->rtscts_prot_mode == rts_cts)
812 arvif->rtscts_prot_mode = rts_cts;
814 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
815 arvif->vdev_id, rts_cts);
817 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
818 vdev_param, rts_cts);
820 ath11k_warn(ar->ab, "failed to recalculate rts/cts prot for vdev %d: %d\n",
821 arvif->vdev_id, ret);
826 static int ath11k_mac_set_kickout(struct ath11k_vif *arvif)
828 struct ath11k *ar = arvif->ar;
832 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_STA_KICKOUT_TH,
833 ATH11K_KICKOUT_THRESHOLD,
836 ath11k_warn(ar->ab, "failed to set kickout threshold on vdev %i: %d\n",
837 arvif->vdev_id, ret);
841 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS;
842 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
843 ATH11K_KEEPALIVE_MIN_IDLE);
845 ath11k_warn(ar->ab, "failed to set keepalive minimum idle time on vdev %i: %d\n",
846 arvif->vdev_id, ret);
850 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS;
851 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
852 ATH11K_KEEPALIVE_MAX_IDLE);
854 ath11k_warn(ar->ab, "failed to set keepalive maximum idle time on vdev %i: %d\n",
855 arvif->vdev_id, ret);
859 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS;
860 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
861 ATH11K_KEEPALIVE_MAX_UNRESPONSIVE);
863 ath11k_warn(ar->ab, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
864 arvif->vdev_id, ret);
871 void ath11k_mac_peer_cleanup_all(struct ath11k *ar)
873 struct ath11k_peer *peer, *tmp;
874 struct ath11k_base *ab = ar->ab;
876 lockdep_assert_held(&ar->conf_mutex);
878 mutex_lock(&ab->tbl_mtx_lock);
879 spin_lock_bh(&ab->base_lock);
880 list_for_each_entry_safe(peer, tmp, &ab->peers, list) {
881 ath11k_peer_rx_tid_cleanup(ar, peer);
882 ath11k_peer_rhash_delete(ab, peer);
883 list_del(&peer->list);
886 spin_unlock_bh(&ab->base_lock);
887 mutex_unlock(&ab->tbl_mtx_lock);
890 ar->num_stations = 0;
893 static inline int ath11k_mac_vdev_setup_sync(struct ath11k *ar)
895 lockdep_assert_held(&ar->conf_mutex);
897 if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))
900 if (!wait_for_completion_timeout(&ar->vdev_setup_done,
901 ATH11K_VDEV_SETUP_TIMEOUT_HZ))
904 return ar->last_wmi_vdev_start_status ? -EINVAL : 0;
908 ath11k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
909 struct ieee80211_chanctx_conf *conf,
912 struct cfg80211_chan_def **def = data;
917 static int ath11k_mac_monitor_vdev_start(struct ath11k *ar, int vdev_id,
918 struct cfg80211_chan_def *chandef)
920 struct ieee80211_channel *channel;
921 struct wmi_vdev_start_req_arg arg = {};
924 lockdep_assert_held(&ar->conf_mutex);
926 channel = chandef->chan;
928 arg.vdev_id = vdev_id;
929 arg.channel.freq = channel->center_freq;
930 arg.channel.band_center_freq1 = chandef->center_freq1;
931 arg.channel.band_center_freq2 = chandef->center_freq2;
933 arg.channel.mode = ath11k_phymodes[chandef->chan->band][chandef->width];
934 arg.channel.chan_radar = !!(channel->flags & IEEE80211_CHAN_RADAR);
936 arg.channel.min_power = 0;
937 arg.channel.max_power = channel->max_power;
938 arg.channel.max_reg_power = channel->max_reg_power;
939 arg.channel.max_antenna_gain = channel->max_antenna_gain;
941 arg.pref_tx_streams = ar->num_tx_chains;
942 arg.pref_rx_streams = ar->num_rx_chains;
944 arg.channel.passive = !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR);
946 reinit_completion(&ar->vdev_setup_done);
947 reinit_completion(&ar->vdev_delete_done);
949 ret = ath11k_wmi_vdev_start(ar, &arg, false);
951 ath11k_warn(ar->ab, "failed to request monitor vdev %i start: %d\n",
956 ret = ath11k_mac_vdev_setup_sync(ar);
958 ath11k_warn(ar->ab, "failed to synchronize setup for monitor vdev %i start: %d\n",
963 ret = ath11k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
965 ath11k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n",
970 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor vdev %i started\n",
976 reinit_completion(&ar->vdev_setup_done);
978 ret = ath11k_wmi_vdev_stop(ar, vdev_id);
980 ath11k_warn(ar->ab, "failed to stop monitor vdev %i after start failure: %d\n",
985 ret = ath11k_mac_vdev_setup_sync(ar);
987 ath11k_warn(ar->ab, "failed to synchronize setup for vdev %i stop: %d\n",
995 static int ath11k_mac_monitor_vdev_stop(struct ath11k *ar)
999 lockdep_assert_held(&ar->conf_mutex);
1001 reinit_completion(&ar->vdev_setup_done);
1003 ret = ath11k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
1005 ath11k_warn(ar->ab, "failed to request monitor vdev %i stop: %d\n",
1006 ar->monitor_vdev_id, ret);
1010 ret = ath11k_mac_vdev_setup_sync(ar);
1012 ath11k_warn(ar->ab, "failed to synchronize monitor vdev %i stop: %d\n",
1013 ar->monitor_vdev_id, ret);
1017 ret = ath11k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1019 ath11k_warn(ar->ab, "failed to put down monitor vdev %i: %d\n",
1020 ar->monitor_vdev_id, ret);
1024 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor vdev %i stopped\n",
1025 ar->monitor_vdev_id);
1030 static int ath11k_mac_monitor_vdev_create(struct ath11k *ar)
1032 struct ath11k_pdev *pdev = ar->pdev;
1033 struct vdev_create_params param = {};
1035 u8 tmp_addr[6] = {0};
1038 lockdep_assert_held(&ar->conf_mutex);
1040 if (test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags))
1043 if (ar->ab->free_vdev_map == 0) {
1044 ath11k_warn(ar->ab, "failed to find free vdev id for monitor vdev\n");
1048 bit = __ffs64(ar->ab->free_vdev_map);
1050 ar->monitor_vdev_id = bit;
1052 param.if_id = ar->monitor_vdev_id;
1053 param.type = WMI_VDEV_TYPE_MONITOR;
1054 param.subtype = WMI_VDEV_SUBTYPE_NONE;
1055 param.pdev_id = pdev->pdev_id;
1057 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) {
1058 param.chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains;
1059 param.chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains;
1061 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) {
1062 param.chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains;
1063 param.chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains;
1066 ret = ath11k_wmi_vdev_create(ar, tmp_addr, ¶m);
1068 ath11k_warn(ar->ab, "failed to request monitor vdev %i creation: %d\n",
1069 ar->monitor_vdev_id, ret);
1070 ar->monitor_vdev_id = -1;
1074 nss = get_num_chains(ar->cfg_tx_chainmask) ? : 1;
1075 ret = ath11k_wmi_vdev_set_param_cmd(ar, ar->monitor_vdev_id,
1076 WMI_VDEV_PARAM_NSS, nss);
1078 ath11k_warn(ar->ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n",
1079 ar->monitor_vdev_id, ar->cfg_tx_chainmask, nss, ret);
1083 ret = ath11k_mac_txpower_recalc(ar);
1085 ath11k_warn(ar->ab, "failed to recalc txpower for monitor vdev %d: %d\n",
1086 ar->monitor_vdev_id, ret);
1090 ar->allocated_vdev_map |= 1LL << ar->monitor_vdev_id;
1091 ar->ab->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1092 ar->num_created_vdevs++;
1093 set_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags);
1095 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor vdev %d created\n",
1096 ar->monitor_vdev_id);
1101 ath11k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1102 ar->monitor_vdev_id = -1;
1106 static int ath11k_mac_monitor_vdev_delete(struct ath11k *ar)
1109 unsigned long time_left;
1111 lockdep_assert_held(&ar->conf_mutex);
1113 if (!test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags))
1116 reinit_completion(&ar->vdev_delete_done);
1118 ret = ath11k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1120 ath11k_warn(ar->ab, "failed to request wmi monitor vdev %i removal: %d\n",
1121 ar->monitor_vdev_id, ret);
1125 time_left = wait_for_completion_timeout(&ar->vdev_delete_done,
1126 ATH11K_VDEV_DELETE_TIMEOUT_HZ);
1127 if (time_left == 0) {
1128 ath11k_warn(ar->ab, "Timeout in receiving vdev delete response\n");
1130 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor vdev %d deleted\n",
1131 ar->monitor_vdev_id);
1133 ar->allocated_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1134 ar->ab->free_vdev_map |= 1LL << (ar->monitor_vdev_id);
1135 ar->num_created_vdevs--;
1136 ar->monitor_vdev_id = -1;
1137 clear_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags);
1143 static int ath11k_mac_monitor_start(struct ath11k *ar)
1145 struct cfg80211_chan_def *chandef = NULL;
1148 lockdep_assert_held(&ar->conf_mutex);
1150 if (test_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags))
1153 ieee80211_iter_chan_contexts_atomic(ar->hw,
1154 ath11k_mac_get_any_chandef_iter,
1159 ret = ath11k_mac_monitor_vdev_start(ar, ar->monitor_vdev_id, chandef);
1161 ath11k_warn(ar->ab, "failed to start monitor vdev: %d\n", ret);
1162 ath11k_mac_monitor_vdev_delete(ar);
1166 set_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags);
1168 ar->num_started_vdevs++;
1169 ret = ath11k_dp_tx_htt_monitor_mode_ring_config(ar, false);
1171 ath11k_warn(ar->ab, "failed to configure htt monitor mode ring during start: %d",
1176 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor started\n");
1181 static int ath11k_mac_monitor_stop(struct ath11k *ar)
1185 lockdep_assert_held(&ar->conf_mutex);
1187 if (!test_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags))
1190 ret = ath11k_mac_monitor_vdev_stop(ar);
1192 ath11k_warn(ar->ab, "failed to stop monitor vdev: %d\n", ret);
1196 clear_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags);
1197 ar->num_started_vdevs--;
1199 ret = ath11k_dp_tx_htt_monitor_mode_ring_config(ar, true);
1201 ath11k_warn(ar->ab, "failed to configure htt monitor mode ring during stop: %d",
1206 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor stopped ret %d\n", ret);
1211 static int ath11k_mac_vif_setup_ps(struct ath11k_vif *arvif)
1213 struct ath11k *ar = arvif->ar;
1214 struct ieee80211_vif *vif = arvif->vif;
1215 struct ieee80211_conf *conf = &ar->hw->conf;
1216 enum wmi_sta_powersave_param param;
1217 enum wmi_sta_ps_mode psmode;
1222 lockdep_assert_held(&arvif->ar->conf_mutex);
1224 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1227 enable_ps = arvif->ps;
1229 if (!arvif->is_started) {
1230 /* mac80211 can update vif powersave state while disconnected.
1231 * Firmware doesn't behave nicely and consumes more power than
1232 * necessary if PS is disabled on a non-started vdev. Hence
1233 * force-enable PS for non-running vdevs.
1235 psmode = WMI_STA_PS_MODE_ENABLED;
1236 } else if (enable_ps) {
1237 psmode = WMI_STA_PS_MODE_ENABLED;
1238 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1240 timeout = conf->dynamic_ps_timeout;
1242 /* firmware doesn't like 0 */
1243 timeout = ieee80211_tu_to_usec(vif->bss_conf.beacon_int) / 1000;
1246 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1249 ath11k_warn(ar->ab, "failed to set inactivity time for vdev %d: %i\n",
1250 arvif->vdev_id, ret);
1254 psmode = WMI_STA_PS_MODE_DISABLED;
1257 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d psmode %s\n",
1258 arvif->vdev_id, psmode ? "enable" : "disable");
1260 ret = ath11k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, psmode);
1262 ath11k_warn(ar->ab, "failed to set sta power save mode %d for vdev %d: %d\n",
1263 psmode, arvif->vdev_id, ret);
1270 static int ath11k_mac_config_ps(struct ath11k *ar)
1272 struct ath11k_vif *arvif;
1275 lockdep_assert_held(&ar->conf_mutex);
1277 list_for_each_entry(arvif, &ar->arvifs, list) {
1278 ret = ath11k_mac_vif_setup_ps(arvif);
1280 ath11k_warn(ar->ab, "failed to setup powersave: %d\n", ret);
1288 static int ath11k_mac_op_config(struct ieee80211_hw *hw, u32 changed)
1290 struct ath11k *ar = hw->priv;
1291 struct ieee80211_conf *conf = &hw->conf;
1294 mutex_lock(&ar->conf_mutex);
1296 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1297 if (conf->flags & IEEE80211_CONF_MONITOR) {
1298 set_bit(ATH11K_FLAG_MONITOR_CONF_ENABLED, &ar->monitor_flags);
1300 if (test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED,
1301 &ar->monitor_flags))
1304 ret = ath11k_mac_monitor_vdev_create(ar);
1306 ath11k_warn(ar->ab, "failed to create monitor vdev: %d",
1311 ret = ath11k_mac_monitor_start(ar);
1313 ath11k_warn(ar->ab, "failed to start monitor: %d",
1318 clear_bit(ATH11K_FLAG_MONITOR_CONF_ENABLED, &ar->monitor_flags);
1320 if (!test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED,
1321 &ar->monitor_flags))
1324 ret = ath11k_mac_monitor_stop(ar);
1326 ath11k_warn(ar->ab, "failed to stop monitor: %d",
1331 ret = ath11k_mac_monitor_vdev_delete(ar);
1333 ath11k_warn(ar->ab, "failed to delete monitor vdev: %d",
1341 mutex_unlock(&ar->conf_mutex);
1345 ath11k_mac_monitor_vdev_delete(ar);
1346 mutex_unlock(&ar->conf_mutex);
1350 static int ath11k_mac_setup_bcn_tmpl(struct ath11k_vif *arvif)
1352 struct ath11k *ar = arvif->ar;
1353 struct ath11k_base *ab = ar->ab;
1354 struct ieee80211_hw *hw = ar->hw;
1355 struct ieee80211_vif *vif = arvif->vif;
1356 struct ieee80211_mutable_offsets offs = {};
1357 struct sk_buff *bcn;
1358 struct ieee80211_mgmt *mgmt;
1362 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1365 bcn = ieee80211_beacon_get_template(hw, vif, &offs, 0);
1367 ath11k_warn(ab, "failed to get beacon template from mac80211\n");
1371 ies = bcn->data + ieee80211_get_hdrlen_from_skb(bcn);
1372 ies += sizeof(mgmt->u.beacon);
1374 if (cfg80211_find_ie(WLAN_EID_RSN, ies, (skb_tail_pointer(bcn) - ies)))
1375 arvif->rsnie_present = true;
1377 arvif->rsnie_present = false;
1379 if (cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1380 WLAN_OUI_TYPE_MICROSOFT_WPA,
1381 ies, (skb_tail_pointer(bcn) - ies)))
1382 arvif->wpaie_present = true;
1384 arvif->wpaie_present = false;
1386 ret = ath11k_wmi_bcn_tmpl(ar, arvif->vdev_id, &offs, bcn);
1391 ath11k_warn(ab, "failed to submit beacon template command: %d\n",
1397 void ath11k_mac_bcn_tx_event(struct ath11k_vif *arvif)
1399 struct ieee80211_vif *vif = arvif->vif;
1401 if (!vif->bss_conf.color_change_active && !arvif->bcca_zero_sent)
1404 if (vif->bss_conf.color_change_active &&
1405 ieee80211_beacon_cntdwn_is_complete(vif)) {
1406 arvif->bcca_zero_sent = true;
1407 ieee80211_color_change_finish(vif);
1411 arvif->bcca_zero_sent = false;
1413 if (vif->bss_conf.color_change_active)
1414 ieee80211_beacon_update_cntdwn(vif);
1415 ath11k_mac_setup_bcn_tmpl(arvif);
1418 static void ath11k_control_beaconing(struct ath11k_vif *arvif,
1419 struct ieee80211_bss_conf *info)
1421 struct ath11k *ar = arvif->ar;
1424 lockdep_assert_held(&arvif->ar->conf_mutex);
1426 if (!info->enable_beacon) {
1427 ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id);
1429 ath11k_warn(ar->ab, "failed to down vdev_id %i: %d\n",
1430 arvif->vdev_id, ret);
1432 arvif->is_up = false;
1436 /* Install the beacon template to the FW */
1437 ret = ath11k_mac_setup_bcn_tmpl(arvif);
1439 ath11k_warn(ar->ab, "failed to update bcn tmpl during vdev up: %d\n",
1444 arvif->tx_seq_no = 0x1000;
1448 ether_addr_copy(arvif->bssid, info->bssid);
1450 ret = ath11k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1453 ath11k_warn(ar->ab, "failed to bring up vdev %d: %i\n",
1454 arvif->vdev_id, ret);
1458 arvif->is_up = true;
1460 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1463 static void ath11k_mac_handle_beacon_iter(void *data, u8 *mac,
1464 struct ieee80211_vif *vif)
1466 struct sk_buff *skb = data;
1467 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1468 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1470 if (vif->type != NL80211_IFTYPE_STATION)
1473 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1476 cancel_delayed_work(&arvif->connection_loss_work);
1479 void ath11k_mac_handle_beacon(struct ath11k *ar, struct sk_buff *skb)
1481 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1482 IEEE80211_IFACE_ITER_NORMAL,
1483 ath11k_mac_handle_beacon_iter,
1487 static void ath11k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1488 struct ieee80211_vif *vif)
1490 u32 *vdev_id = data;
1491 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1492 struct ath11k *ar = arvif->ar;
1493 struct ieee80211_hw *hw = ar->hw;
1495 if (arvif->vdev_id != *vdev_id)
1501 ieee80211_beacon_loss(vif);
1503 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1504 * (done by mac80211) succeeds but beacons do not resume then it
1505 * doesn't make sense to continue operation. Queue connection loss work
1506 * which can be cancelled when beacon is received.
1508 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1509 ATH11K_CONNECTION_LOSS_HZ);
1512 void ath11k_mac_handle_beacon_miss(struct ath11k *ar, u32 vdev_id)
1514 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1515 IEEE80211_IFACE_ITER_NORMAL,
1516 ath11k_mac_handle_beacon_miss_iter,
1520 static void ath11k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1522 struct ath11k_vif *arvif = container_of(work, struct ath11k_vif,
1523 connection_loss_work.work);
1524 struct ieee80211_vif *vif = arvif->vif;
1529 ieee80211_connection_loss(vif);
1532 static void ath11k_peer_assoc_h_basic(struct ath11k *ar,
1533 struct ieee80211_vif *vif,
1534 struct ieee80211_sta *sta,
1535 struct peer_assoc_params *arg)
1537 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1540 lockdep_assert_held(&ar->conf_mutex);
1542 if (vif->type == NL80211_IFTYPE_STATION)
1547 ether_addr_copy(arg->peer_mac, sta->addr);
1548 arg->vdev_id = arvif->vdev_id;
1549 arg->peer_associd = aid;
1550 arg->auth_flag = true;
1551 /* TODO: STA WAR in ath10k for listen interval required? */
1552 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1554 arg->peer_caps = vif->bss_conf.assoc_capability;
1557 static void ath11k_peer_assoc_h_crypto(struct ath11k *ar,
1558 struct ieee80211_vif *vif,
1559 struct ieee80211_sta *sta,
1560 struct peer_assoc_params *arg)
1562 struct ieee80211_bss_conf *info = &vif->bss_conf;
1563 struct cfg80211_chan_def def;
1564 struct cfg80211_bss *bss;
1565 struct ath11k_vif *arvif = (struct ath11k_vif *)vif->drv_priv;
1566 const u8 *rsnie = NULL;
1567 const u8 *wpaie = NULL;
1569 lockdep_assert_held(&ar->conf_mutex);
1571 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1574 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1575 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
1577 if (arvif->rsnie_present || arvif->wpaie_present) {
1578 arg->need_ptk_4_way = true;
1579 if (arvif->wpaie_present)
1580 arg->need_gtk_2_way = true;
1582 const struct cfg80211_bss_ies *ies;
1585 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1587 ies = rcu_dereference(bss->ies);
1589 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1590 WLAN_OUI_TYPE_MICROSOFT_WPA,
1594 cfg80211_put_bss(ar->hw->wiphy, bss);
1597 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1598 if (rsnie || wpaie) {
1599 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1600 "%s: rsn ie found\n", __func__);
1601 arg->need_ptk_4_way = true;
1605 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1606 "%s: wpa ie found\n", __func__);
1607 arg->need_gtk_2_way = true;
1611 /* TODO: Need to check if FW supports PMF? */
1612 arg->is_pmf_enabled = true;
1615 /* TODO: safe_mode_enabled (bypass 4-way handshake) flag req? */
1618 static void ath11k_peer_assoc_h_rates(struct ath11k *ar,
1619 struct ieee80211_vif *vif,
1620 struct ieee80211_sta *sta,
1621 struct peer_assoc_params *arg)
1623 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1624 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1625 struct cfg80211_chan_def def;
1626 const struct ieee80211_supported_band *sband;
1627 const struct ieee80211_rate *rates;
1628 enum nl80211_band band;
1633 lockdep_assert_held(&ar->conf_mutex);
1635 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1638 band = def.chan->band;
1639 sband = ar->hw->wiphy->bands[band];
1640 ratemask = sta->deflink.supp_rates[band];
1641 ratemask &= arvif->bitrate_mask.control[band].legacy;
1642 rates = sband->bitrates;
1644 rateset->num_rates = 0;
1646 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1647 if (!(ratemask & 1))
1650 rate = ath11k_mac_bitrate_to_rate(rates->bitrate);
1651 rateset->rates[rateset->num_rates] = rate;
1652 rateset->num_rates++;
1657 ath11k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
1661 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
1662 if (ht_mcs_mask[nss])
1669 ath11k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[])
1673 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
1674 if (vht_mcs_mask[nss])
1680 static void ath11k_peer_assoc_h_ht(struct ath11k *ar,
1681 struct ieee80211_vif *vif,
1682 struct ieee80211_sta *sta,
1683 struct peer_assoc_params *arg)
1685 const struct ieee80211_sta_ht_cap *ht_cap = &sta->deflink.ht_cap;
1686 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1687 struct cfg80211_chan_def def;
1688 enum nl80211_band band;
1689 const u8 *ht_mcs_mask;
1694 lockdep_assert_held(&ar->conf_mutex);
1696 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1699 if (!ht_cap->ht_supported)
1702 band = def.chan->band;
1703 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
1705 if (ath11k_peer_assoc_h_ht_masked(ht_mcs_mask))
1708 arg->ht_flag = true;
1710 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1711 ht_cap->ampdu_factor)) - 1;
1713 arg->peer_mpdu_density =
1714 ath11k_parse_mpdudensity(ht_cap->ampdu_density);
1716 arg->peer_ht_caps = ht_cap->cap;
1717 arg->peer_rate_caps |= WMI_HOST_RC_HT_FLAG;
1719 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1720 arg->ldpc_flag = true;
1722 if (sta->deflink.bandwidth >= IEEE80211_STA_RX_BW_40) {
1724 arg->peer_rate_caps |= WMI_HOST_RC_CW40_FLAG;
1727 /* As firmware handles this two flags (IEEE80211_HT_CAP_SGI_20
1728 * and IEEE80211_HT_CAP_SGI_40) for enabling SGI, we reset
1729 * both flags if guard interval is Default GI
1731 if (arvif->bitrate_mask.control[band].gi == NL80211_TXRATE_DEFAULT_GI)
1732 arg->peer_ht_caps &= ~(IEEE80211_HT_CAP_SGI_20 |
1733 IEEE80211_HT_CAP_SGI_40);
1735 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
1736 if (ht_cap->cap & (IEEE80211_HT_CAP_SGI_20 |
1737 IEEE80211_HT_CAP_SGI_40))
1738 arg->peer_rate_caps |= WMI_HOST_RC_SGI_FLAG;
1741 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1742 arg->peer_rate_caps |= WMI_HOST_RC_TX_STBC_FLAG;
1743 arg->stbc_flag = true;
1746 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1747 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1748 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1749 stbc = stbc << WMI_HOST_RC_RX_STBC_FLAG_S;
1750 arg->peer_rate_caps |= stbc;
1751 arg->stbc_flag = true;
1754 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1755 arg->peer_rate_caps |= WMI_HOST_RC_TS_FLAG;
1756 else if (ht_cap->mcs.rx_mask[1])
1757 arg->peer_rate_caps |= WMI_HOST_RC_DS_FLAG;
1759 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
1760 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
1761 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
1762 max_nss = (i / 8) + 1;
1763 arg->peer_ht_rates.rates[n++] = i;
1766 /* This is a workaround for HT-enabled STAs which break the spec
1767 * and have no HT capabilities RX mask (no HT RX MCS map).
1769 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1770 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1772 * Firmware asserts if such situation occurs.
1775 arg->peer_ht_rates.num_rates = 8;
1776 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1777 arg->peer_ht_rates.rates[i] = i;
1779 arg->peer_ht_rates.num_rates = n;
1780 arg->peer_nss = min(sta->deflink.rx_nss, max_nss);
1783 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1785 arg->peer_ht_rates.num_rates,
1789 static int ath11k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
1791 switch ((mcs_map >> (2 * nss)) & 0x3) {
1792 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
1793 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
1794 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
1800 ath11k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
1801 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
1808 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
1809 mcs_map = ath11k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
1813 idx_limit = fls(mcs_map) - 1;
1817 switch (idx_limit) {
1826 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
1829 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
1832 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
1838 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
1842 tx_mcs_set &= ~(0x3 << (nss * 2));
1843 tx_mcs_set |= mcs << (nss * 2);
1849 static u8 ath11k_get_nss_160mhz(struct ath11k *ar,
1852 u8 nss_ratio_info = ar->pdev->cap.nss_ratio_info;
1855 switch (nss_ratio_info) {
1856 case WMI_NSS_RATIO_1BY2_NSS:
1857 max_sup_nss = max_nss >> 1;
1859 case WMI_NSS_RATIO_3BY4_NSS:
1860 ath11k_warn(ar->ab, "WMI_NSS_RATIO_3BY4_NSS not supported\n");
1862 case WMI_NSS_RATIO_1_NSS:
1863 max_sup_nss = max_nss;
1865 case WMI_NSS_RATIO_2_NSS:
1866 ath11k_warn(ar->ab, "WMI_NSS_RATIO_2_NSS not supported\n");
1869 ath11k_warn(ar->ab, "invalid nss ratio received from firmware: %d\n",
1877 static void ath11k_peer_assoc_h_vht(struct ath11k *ar,
1878 struct ieee80211_vif *vif,
1879 struct ieee80211_sta *sta,
1880 struct peer_assoc_params *arg)
1882 const struct ieee80211_sta_vht_cap *vht_cap = &sta->deflink.vht_cap;
1883 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1884 struct cfg80211_chan_def def;
1885 enum nl80211_band band;
1888 u8 max_nss, vht_mcs;
1889 int i, vht_nss, nss_idx;
1890 bool user_rate_valid = true;
1891 u32 rx_nss, tx_nss, nss_160;
1893 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1896 if (!vht_cap->vht_supported)
1899 band = def.chan->band;
1900 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
1902 if (ath11k_peer_assoc_h_vht_masked(vht_mcs_mask))
1905 arg->vht_flag = true;
1907 /* TODO: similar flags required? */
1908 arg->vht_capable = true;
1910 if (def.chan->band == NL80211_BAND_2GHZ)
1911 arg->vht_ng_flag = true;
1913 arg->peer_vht_caps = vht_cap->cap;
1915 ampdu_factor = (vht_cap->cap &
1916 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1917 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1919 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1920 * zero in VHT IE. Using it would result in degraded throughput.
1921 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1922 * it if VHT max_mpdu is smaller.
1924 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1925 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1926 ampdu_factor)) - 1);
1928 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_80)
1931 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_160)
1934 vht_nss = ath11k_mac_max_vht_nss(vht_mcs_mask);
1936 if (vht_nss > sta->deflink.rx_nss) {
1937 user_rate_valid = false;
1938 for (nss_idx = sta->deflink.rx_nss - 1; nss_idx >= 0; nss_idx--) {
1939 if (vht_mcs_mask[nss_idx]) {
1940 user_rate_valid = true;
1946 if (!user_rate_valid) {
1947 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac setting vht range mcs value to peer supported nss %d for peer %pM\n",
1948 sta->deflink.rx_nss, sta->addr);
1949 vht_mcs_mask[sta->deflink.rx_nss - 1] = vht_mcs_mask[vht_nss - 1];
1952 /* Calculate peer NSS capability from VHT capabilities if STA
1955 for (i = 0, max_nss = 0; i < NL80211_VHT_NSS_MAX; i++) {
1956 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
1959 if (vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED &&
1963 arg->peer_nss = min(sta->deflink.rx_nss, max_nss);
1964 arg->rx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1965 arg->rx_mcs_set = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1966 arg->tx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1967 arg->tx_mcs_set = ath11k_peer_assoc_h_vht_limit(
1968 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
1970 /* In IPQ8074 platform, VHT mcs rate 10 and 11 is enabled by default.
1971 * VHT mcs rate 10 and 11 is not suppoerted in 11ac standard.
1972 * so explicitly disable the VHT MCS rate 10 and 11 in 11ac mode.
1974 arg->tx_mcs_set &= ~IEEE80211_VHT_MCS_SUPPORT_0_11_MASK;
1975 arg->tx_mcs_set |= IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11;
1977 if ((arg->tx_mcs_set & IEEE80211_VHT_MCS_NOT_SUPPORTED) ==
1978 IEEE80211_VHT_MCS_NOT_SUPPORTED)
1979 arg->peer_vht_caps &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1982 arg->tx_max_mcs_nss = 0xFF;
1984 if (arg->peer_phymode == MODE_11AC_VHT160 ||
1985 arg->peer_phymode == MODE_11AC_VHT80_80) {
1986 tx_nss = ath11k_get_nss_160mhz(ar, max_nss);
1987 rx_nss = min(arg->peer_nss, tx_nss);
1988 arg->peer_bw_rxnss_override = ATH11K_BW_NSS_MAP_ENABLE;
1991 ath11k_warn(ar->ab, "invalid max_nss\n");
1995 if (arg->peer_phymode == MODE_11AC_VHT160)
1996 nss_160 = FIELD_PREP(ATH11K_PEER_RX_NSS_160MHZ, rx_nss - 1);
1998 nss_160 = FIELD_PREP(ATH11K_PEER_RX_NSS_80_80MHZ, rx_nss - 1);
2000 arg->peer_bw_rxnss_override |= nss_160;
2003 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2004 "mac vht peer %pM max_mpdu %d flags 0x%x nss_override 0x%x\n",
2005 sta->addr, arg->peer_max_mpdu, arg->peer_flags,
2006 arg->peer_bw_rxnss_override);
2009 static int ath11k_mac_get_max_he_mcs_map(u16 mcs_map, int nss)
2011 switch ((mcs_map >> (2 * nss)) & 0x3) {
2012 case IEEE80211_HE_MCS_SUPPORT_0_7: return BIT(8) - 1;
2013 case IEEE80211_HE_MCS_SUPPORT_0_9: return BIT(10) - 1;
2014 case IEEE80211_HE_MCS_SUPPORT_0_11: return BIT(12) - 1;
2019 static u16 ath11k_peer_assoc_h_he_limit(u16 tx_mcs_set,
2020 const u16 he_mcs_limit[NL80211_HE_NSS_MAX])
2027 for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) {
2028 mcs_map = ath11k_mac_get_max_he_mcs_map(tx_mcs_set, nss) &
2032 idx_limit = fls(mcs_map) - 1;
2036 switch (idx_limit) {
2038 mcs = IEEE80211_HE_MCS_SUPPORT_0_7;
2042 mcs = IEEE80211_HE_MCS_SUPPORT_0_9;
2046 mcs = IEEE80211_HE_MCS_SUPPORT_0_11;
2052 mcs = IEEE80211_HE_MCS_NOT_SUPPORTED;
2056 tx_mcs_set &= ~(0x3 << (nss * 2));
2057 tx_mcs_set |= mcs << (nss * 2);
2064 ath11k_peer_assoc_h_he_masked(const u16 he_mcs_mask[NL80211_HE_NSS_MAX])
2068 for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++)
2069 if (he_mcs_mask[nss])
2075 static void ath11k_peer_assoc_h_he(struct ath11k *ar,
2076 struct ieee80211_vif *vif,
2077 struct ieee80211_sta *sta,
2078 struct peer_assoc_params *arg)
2080 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2081 struct cfg80211_chan_def def;
2082 const struct ieee80211_sta_he_cap *he_cap = &sta->deflink.he_cap;
2083 enum nl80211_band band;
2086 u16 he_tx_mcs = 0, v = 0;
2087 int i, he_nss, nss_idx;
2088 bool user_rate_valid = true;
2089 u32 rx_nss, tx_nss, nss_160;
2090 u8 ampdu_factor, rx_mcs_80, rx_mcs_160;
2091 u16 mcs_160_map, mcs_80_map;
2094 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
2097 if (!he_cap->has_he)
2100 band = def.chan->band;
2101 he_mcs_mask = arvif->bitrate_mask.control[band].he_mcs;
2103 if (ath11k_peer_assoc_h_he_masked(he_mcs_mask))
2106 arg->he_flag = true;
2107 support_160 = !!(he_cap->he_cap_elem.phy_cap_info[0] &
2108 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G);
2110 /* Supported HE-MCS and NSS Set of peer he_cap is intersection with self he_cp */
2111 mcs_160_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160);
2112 mcs_80_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80);
2115 for (i = 7; i >= 0; i--) {
2116 u8 mcs_160 = (mcs_160_map >> (2 * i)) & 3;
2118 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
2125 for (i = 7; i >= 0; i--) {
2126 u8 mcs_80 = (mcs_80_map >> (2 * i)) & 3;
2128 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
2135 max_nss = min(rx_mcs_80, rx_mcs_160);
2137 max_nss = rx_mcs_80;
2139 arg->peer_nss = min(sta->deflink.rx_nss, max_nss);
2141 memcpy_and_pad(&arg->peer_he_cap_macinfo,
2142 sizeof(arg->peer_he_cap_macinfo),
2143 he_cap->he_cap_elem.mac_cap_info,
2144 sizeof(he_cap->he_cap_elem.mac_cap_info),
2146 memcpy_and_pad(&arg->peer_he_cap_phyinfo,
2147 sizeof(arg->peer_he_cap_phyinfo),
2148 he_cap->he_cap_elem.phy_cap_info,
2149 sizeof(he_cap->he_cap_elem.phy_cap_info),
2151 arg->peer_he_ops = vif->bss_conf.he_oper.params;
2153 /* the top most byte is used to indicate BSS color info */
2154 arg->peer_he_ops &= 0xffffff;
2156 /* As per section 26.6.1 11ax Draft5.0, if the Max AMPDU Exponent Extension
2157 * in HE cap is zero, use the arg->peer_max_mpdu as calculated while parsing
2158 * VHT caps(if VHT caps is present) or HT caps (if VHT caps is not present).
2160 * For non-zero value of Max AMPDU Extponent Extension in HE MAC caps,
2161 * if a HE STA sends VHT cap and HE cap IE in assoc request then, use
2162 * MAX_AMPDU_LEN_FACTOR as 20 to calculate max_ampdu length.
2163 * If a HE STA that does not send VHT cap, but HE and HT cap in assoc
2164 * request, then use MAX_AMPDU_LEN_FACTOR as 16 to calculate max_ampdu
2167 ampdu_factor = u8_get_bits(he_cap->he_cap_elem.mac_cap_info[3],
2168 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK);
2171 if (sta->deflink.vht_cap.vht_supported)
2172 arg->peer_max_mpdu = (1 << (IEEE80211_HE_VHT_MAX_AMPDU_FACTOR +
2174 else if (sta->deflink.ht_cap.ht_supported)
2175 arg->peer_max_mpdu = (1 << (IEEE80211_HE_HT_MAX_AMPDU_FACTOR +
2179 if (he_cap->he_cap_elem.phy_cap_info[6] &
2180 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2184 arg->peer_ppet.numss_m1 = he_cap->ppe_thres[0] &
2185 IEEE80211_PPE_THRES_NSS_MASK;
2186 arg->peer_ppet.ru_bit_mask =
2187 (he_cap->ppe_thres[0] &
2188 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2189 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2191 for (nss = 0; nss <= arg->peer_ppet.numss_m1; nss++) {
2192 for (ru = 0; ru < 4; ru++) {
2196 if ((arg->peer_ppet.ru_bit_mask & BIT(ru)) == 0)
2198 for (i = 0; i < 6; i++) {
2200 val |= ((he_cap->ppe_thres[bit / 8] >>
2201 (bit % 8)) & 0x1) << 5;
2204 arg->peer_ppet.ppet16_ppet8_ru3_ru0[nss] |=
2210 if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_RES)
2211 arg->twt_responder = true;
2212 if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_REQ)
2213 arg->twt_requester = true;
2215 he_nss = ath11k_mac_max_he_nss(he_mcs_mask);
2217 if (he_nss > sta->deflink.rx_nss) {
2218 user_rate_valid = false;
2219 for (nss_idx = sta->deflink.rx_nss - 1; nss_idx >= 0; nss_idx--) {
2220 if (he_mcs_mask[nss_idx]) {
2221 user_rate_valid = true;
2227 if (!user_rate_valid) {
2228 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac setting he range mcs value to peer supported nss %d for peer %pM\n",
2229 sta->deflink.rx_nss, sta->addr);
2230 he_mcs_mask[sta->deflink.rx_nss - 1] = he_mcs_mask[he_nss - 1];
2233 switch (sta->deflink.bandwidth) {
2234 case IEEE80211_STA_RX_BW_160:
2235 if (he_cap->he_cap_elem.phy_cap_info[0] &
2236 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) {
2237 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80p80);
2238 v = ath11k_peer_assoc_h_he_limit(v, he_mcs_mask);
2239 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v;
2241 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80p80);
2242 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v;
2244 arg->peer_he_mcs_count++;
2247 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160);
2248 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v;
2250 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_160);
2251 v = ath11k_peer_assoc_h_he_limit(v, he_mcs_mask);
2252 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v;
2254 arg->peer_he_mcs_count++;
2260 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80);
2261 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v;
2263 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80);
2264 v = ath11k_peer_assoc_h_he_limit(v, he_mcs_mask);
2265 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v;
2267 arg->peer_he_mcs_count++;
2273 /* Calculate peer NSS capability from HE capabilities if STA
2276 for (i = 0, max_nss = 0; i < NL80211_HE_NSS_MAX; i++) {
2277 he_mcs = he_tx_mcs >> (2 * i) & 3;
2279 /* In case of fixed rates, MCS Range in he_tx_mcs might have
2280 * unsupported range, with he_mcs_mask set, so check either of them
2283 if (he_mcs != IEEE80211_HE_MCS_NOT_SUPPORTED ||
2287 arg->peer_nss = min(sta->deflink.rx_nss, max_nss);
2289 if (arg->peer_phymode == MODE_11AX_HE160 ||
2290 arg->peer_phymode == MODE_11AX_HE80_80) {
2291 tx_nss = ath11k_get_nss_160mhz(ar, max_nss);
2292 rx_nss = min(arg->peer_nss, tx_nss);
2293 arg->peer_bw_rxnss_override = ATH11K_BW_NSS_MAP_ENABLE;
2296 ath11k_warn(ar->ab, "invalid max_nss\n");
2300 if (arg->peer_phymode == MODE_11AX_HE160)
2301 nss_160 = FIELD_PREP(ATH11K_PEER_RX_NSS_160MHZ, rx_nss - 1);
2303 nss_160 = FIELD_PREP(ATH11K_PEER_RX_NSS_80_80MHZ, rx_nss - 1);
2305 arg->peer_bw_rxnss_override |= nss_160;
2308 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2309 "mac he peer %pM nss %d mcs cnt %d nss_override 0x%x\n",
2310 sta->addr, arg->peer_nss,
2311 arg->peer_he_mcs_count,
2312 arg->peer_bw_rxnss_override);
2315 static void ath11k_peer_assoc_h_he_6ghz(struct ath11k *ar,
2316 struct ieee80211_vif *vif,
2317 struct ieee80211_sta *sta,
2318 struct peer_assoc_params *arg)
2320 const struct ieee80211_sta_he_cap *he_cap = &sta->deflink.he_cap;
2321 struct cfg80211_chan_def def;
2322 enum nl80211_band band;
2325 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
2328 band = def.chan->band;
2330 if (!arg->he_flag || band != NL80211_BAND_6GHZ || !sta->deflink.he_6ghz_capa.capa)
2333 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40)
2336 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_80)
2339 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_160)
2342 arg->peer_he_caps_6ghz = le16_to_cpu(sta->deflink.he_6ghz_capa.capa);
2343 arg->peer_mpdu_density =
2344 ath11k_parse_mpdudensity(FIELD_GET(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START,
2345 arg->peer_he_caps_6ghz));
2347 /* From IEEE Std 802.11ax-2021 - Section 10.12.2: An HE STA shall be capable of
2348 * receiving A-MPDU where the A-MPDU pre-EOF padding length is up to the value
2349 * indicated by the Maximum A-MPDU Length Exponent Extension field in the HE
2350 * Capabilities element and the Maximum A-MPDU Length Exponent field in HE 6 GHz
2351 * Band Capabilities element in the 6 GHz band.
2353 * Here, we are extracting the Max A-MPDU Exponent Extension from HE caps and
2354 * factor is the Maximum A-MPDU Length Exponent from HE 6 GHZ Band capability.
2356 ampdu_factor = FIELD_GET(IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK,
2357 he_cap->he_cap_elem.mac_cap_info[3]) +
2358 FIELD_GET(IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP,
2359 arg->peer_he_caps_6ghz);
2361 arg->peer_max_mpdu = (1u << (IEEE80211_HE_6GHZ_MAX_AMPDU_FACTOR +
2365 static void ath11k_peer_assoc_h_smps(struct ieee80211_sta *sta,
2366 struct peer_assoc_params *arg)
2368 const struct ieee80211_sta_ht_cap *ht_cap = &sta->deflink.ht_cap;
2371 if (!ht_cap->ht_supported && !sta->deflink.he_6ghz_capa.capa)
2374 if (ht_cap->ht_supported) {
2375 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2376 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2378 smps = le16_get_bits(sta->deflink.he_6ghz_capa.capa,
2379 IEEE80211_HE_6GHZ_CAP_SM_PS);
2383 case WLAN_HT_CAP_SM_PS_STATIC:
2384 arg->static_mimops_flag = true;
2386 case WLAN_HT_CAP_SM_PS_DYNAMIC:
2387 arg->dynamic_mimops_flag = true;
2389 case WLAN_HT_CAP_SM_PS_DISABLED:
2390 arg->spatial_mux_flag = true;
2397 static void ath11k_peer_assoc_h_qos(struct ath11k *ar,
2398 struct ieee80211_vif *vif,
2399 struct ieee80211_sta *sta,
2400 struct peer_assoc_params *arg)
2402 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2404 switch (arvif->vdev_type) {
2405 case WMI_VDEV_TYPE_AP:
2407 /* TODO: Check WME vs QoS */
2408 arg->is_wme_set = true;
2409 arg->qos_flag = true;
2412 if (sta->wme && sta->uapsd_queues) {
2413 /* TODO: Check WME vs QoS */
2414 arg->is_wme_set = true;
2415 arg->apsd_flag = true;
2416 arg->peer_rate_caps |= WMI_HOST_RC_UAPSD_FLAG;
2419 case WMI_VDEV_TYPE_STA:
2421 arg->is_wme_set = true;
2422 arg->qos_flag = true;
2429 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac peer %pM qos %d\n",
2430 sta->addr, arg->qos_flag);
2433 static int ath11k_peer_assoc_qos_ap(struct ath11k *ar,
2434 struct ath11k_vif *arvif,
2435 struct ieee80211_sta *sta)
2437 struct ap_ps_params params;
2442 lockdep_assert_held(&ar->conf_mutex);
2444 params.vdev_id = arvif->vdev_id;
2446 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2447 sta->uapsd_queues, sta->max_sp);
2450 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2451 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2452 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2453 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2454 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2455 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2456 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2457 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2458 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2459 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2460 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2461 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2464 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2465 max_sp = sta->max_sp;
2467 params.param = WMI_AP_PS_PEER_PARAM_UAPSD;
2468 params.value = uapsd;
2469 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
2473 params.param = WMI_AP_PS_PEER_PARAM_MAX_SP;
2474 params.value = max_sp;
2475 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
2479 /* TODO revisit during testing */
2480 params.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_FRMTYPE;
2481 params.value = DISABLE_SIFS_RESPONSE_TRIGGER;
2482 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
2486 params.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_UAPSD;
2487 params.value = DISABLE_SIFS_RESPONSE_TRIGGER;
2488 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
2495 ath11k_warn(ar->ab, "failed to set ap ps peer param %d for vdev %i: %d\n",
2496 params.param, arvif->vdev_id, ret);
2500 static bool ath11k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2502 return sta->deflink.supp_rates[NL80211_BAND_2GHZ] >>
2503 ATH11K_MAC_FIRST_OFDM_RATE_IDX;
2506 static enum wmi_phy_mode ath11k_mac_get_phymode_vht(struct ath11k *ar,
2507 struct ieee80211_sta *sta)
2509 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_160) {
2510 switch (sta->deflink.vht_cap.cap &
2511 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
2512 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
2513 return MODE_11AC_VHT160;
2514 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
2515 return MODE_11AC_VHT80_80;
2517 /* not sure if this is a valid case? */
2518 return MODE_11AC_VHT160;
2522 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_80)
2523 return MODE_11AC_VHT80;
2525 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40)
2526 return MODE_11AC_VHT40;
2528 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_20)
2529 return MODE_11AC_VHT20;
2531 return MODE_UNKNOWN;
2534 static enum wmi_phy_mode ath11k_mac_get_phymode_he(struct ath11k *ar,
2535 struct ieee80211_sta *sta)
2537 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_160) {
2538 if (sta->deflink.he_cap.he_cap_elem.phy_cap_info[0] &
2539 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
2540 return MODE_11AX_HE160;
2541 else if (sta->deflink.he_cap.he_cap_elem.phy_cap_info[0] &
2542 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)
2543 return MODE_11AX_HE80_80;
2544 /* not sure if this is a valid case? */
2545 return MODE_11AX_HE160;
2548 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_80)
2549 return MODE_11AX_HE80;
2551 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40)
2552 return MODE_11AX_HE40;
2554 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_20)
2555 return MODE_11AX_HE20;
2557 return MODE_UNKNOWN;
2560 static void ath11k_peer_assoc_h_phymode(struct ath11k *ar,
2561 struct ieee80211_vif *vif,
2562 struct ieee80211_sta *sta,
2563 struct peer_assoc_params *arg)
2565 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2566 struct cfg80211_chan_def def;
2567 enum nl80211_band band;
2568 const u8 *ht_mcs_mask;
2569 const u16 *vht_mcs_mask;
2570 const u16 *he_mcs_mask;
2571 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2573 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
2576 band = def.chan->band;
2577 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2578 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2579 he_mcs_mask = arvif->bitrate_mask.control[band].he_mcs;
2582 case NL80211_BAND_2GHZ:
2583 if (sta->deflink.he_cap.has_he &&
2584 !ath11k_peer_assoc_h_he_masked(he_mcs_mask)) {
2585 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_80)
2586 phymode = MODE_11AX_HE80_2G;
2587 else if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40)
2588 phymode = MODE_11AX_HE40_2G;
2590 phymode = MODE_11AX_HE20_2G;
2591 } else if (sta->deflink.vht_cap.vht_supported &&
2592 !ath11k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2593 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40)
2594 phymode = MODE_11AC_VHT40;
2596 phymode = MODE_11AC_VHT20;
2597 } else if (sta->deflink.ht_cap.ht_supported &&
2598 !ath11k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2599 if (sta->deflink.bandwidth == IEEE80211_STA_RX_BW_40)
2600 phymode = MODE_11NG_HT40;
2602 phymode = MODE_11NG_HT20;
2603 } else if (ath11k_mac_sta_has_ofdm_only(sta)) {
2609 case NL80211_BAND_5GHZ:
2610 case NL80211_BAND_6GHZ:
2611 /* Check HE first */
2612 if (sta->deflink.he_cap.has_he &&
2613 !ath11k_peer_assoc_h_he_masked(he_mcs_mask)) {
2614 phymode = ath11k_mac_get_phymode_he(ar, sta);
2615 } else if (sta->deflink.vht_cap.vht_supported &&
2616 !ath11k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2617 phymode = ath11k_mac_get_phymode_vht(ar, sta);
2618 } else if (sta->deflink.ht_cap.ht_supported &&
2619 !ath11k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2620 if (sta->deflink.bandwidth >= IEEE80211_STA_RX_BW_40)
2621 phymode = MODE_11NA_HT40;
2623 phymode = MODE_11NA_HT20;
2632 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac peer %pM phymode %s\n",
2633 sta->addr, ath11k_wmi_phymode_str(phymode));
2635 arg->peer_phymode = phymode;
2636 WARN_ON(phymode == MODE_UNKNOWN);
2639 static void ath11k_peer_assoc_prepare(struct ath11k *ar,
2640 struct ieee80211_vif *vif,
2641 struct ieee80211_sta *sta,
2642 struct peer_assoc_params *arg,
2645 struct ath11k_sta *arsta;
2647 lockdep_assert_held(&ar->conf_mutex);
2649 arsta = (struct ath11k_sta *)sta->drv_priv;
2651 memset(arg, 0, sizeof(*arg));
2653 reinit_completion(&ar->peer_assoc_done);
2655 arg->peer_new_assoc = !reassoc;
2656 ath11k_peer_assoc_h_basic(ar, vif, sta, arg);
2657 ath11k_peer_assoc_h_crypto(ar, vif, sta, arg);
2658 ath11k_peer_assoc_h_rates(ar, vif, sta, arg);
2659 ath11k_peer_assoc_h_phymode(ar, vif, sta, arg);
2660 ath11k_peer_assoc_h_ht(ar, vif, sta, arg);
2661 ath11k_peer_assoc_h_vht(ar, vif, sta, arg);
2662 ath11k_peer_assoc_h_he(ar, vif, sta, arg);
2663 ath11k_peer_assoc_h_he_6ghz(ar, vif, sta, arg);
2664 ath11k_peer_assoc_h_qos(ar, vif, sta, arg);
2665 ath11k_peer_assoc_h_smps(sta, arg);
2667 arsta->peer_nss = arg->peer_nss;
2669 /* TODO: amsdu_disable req? */
2672 static int ath11k_setup_peer_smps(struct ath11k *ar, struct ath11k_vif *arvif,
2674 const struct ieee80211_sta_ht_cap *ht_cap,
2679 if (!ht_cap->ht_supported && !he_6ghz_capa)
2682 if (ht_cap->ht_supported) {
2683 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2684 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2686 smps = FIELD_GET(IEEE80211_HE_6GHZ_CAP_SM_PS, he_6ghz_capa);
2689 if (smps >= ARRAY_SIZE(ath11k_smps_map))
2692 return ath11k_wmi_set_peer_param(ar, addr, arvif->vdev_id,
2693 WMI_PEER_MIMO_PS_STATE,
2694 ath11k_smps_map[smps]);
2697 static void ath11k_bss_assoc(struct ieee80211_hw *hw,
2698 struct ieee80211_vif *vif,
2699 struct ieee80211_bss_conf *bss_conf)
2701 struct ath11k *ar = hw->priv;
2702 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2703 struct peer_assoc_params peer_arg;
2704 struct ieee80211_sta *ap_sta;
2705 struct ath11k_peer *peer;
2706 bool is_auth = false;
2709 lockdep_assert_held(&ar->conf_mutex);
2711 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2712 arvif->vdev_id, arvif->bssid, arvif->aid);
2716 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2718 ath11k_warn(ar->ab, "failed to find station entry for bss %pM vdev %i\n",
2719 bss_conf->bssid, arvif->vdev_id);
2724 ath11k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg, false);
2728 peer_arg.is_assoc = true;
2729 ret = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
2731 ath11k_warn(ar->ab, "failed to run peer assoc for %pM vdev %i: %d\n",
2732 bss_conf->bssid, arvif->vdev_id, ret);
2736 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
2737 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
2738 bss_conf->bssid, arvif->vdev_id);
2742 ret = ath11k_setup_peer_smps(ar, arvif, bss_conf->bssid,
2743 &ap_sta->deflink.ht_cap,
2744 le16_to_cpu(ap_sta->deflink.he_6ghz_capa.capa));
2746 ath11k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n",
2747 arvif->vdev_id, ret);
2751 WARN_ON(arvif->is_up);
2753 arvif->aid = vif->cfg.aid;
2754 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2756 ret = ath11k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2758 ath11k_warn(ar->ab, "failed to set vdev %d up: %d\n",
2759 arvif->vdev_id, ret);
2763 arvif->is_up = true;
2764 arvif->rekey_data.enable_offload = false;
2766 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2767 "mac vdev %d up (associated) bssid %pM aid %d\n",
2768 arvif->vdev_id, bss_conf->bssid, vif->cfg.aid);
2770 spin_lock_bh(&ar->ab->base_lock);
2772 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, arvif->bssid);
2773 if (peer && peer->is_authorized)
2776 spin_unlock_bh(&ar->ab->base_lock);
2779 ret = ath11k_wmi_set_peer_param(ar, arvif->bssid,
2784 ath11k_warn(ar->ab, "Unable to authorize BSS peer: %d\n", ret);
2787 ret = ath11k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id,
2788 &bss_conf->he_obss_pd);
2790 ath11k_warn(ar->ab, "failed to set vdev %i OBSS PD parameters: %d\n",
2791 arvif->vdev_id, ret);
2793 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2794 WMI_VDEV_PARAM_DTIM_POLICY,
2795 WMI_DTIM_POLICY_STICK);
2797 ath11k_warn(ar->ab, "failed to set vdev %d dtim policy: %d\n",
2798 arvif->vdev_id, ret);
2800 ath11k_mac_11d_scan_stop_all(ar->ab);
2803 static void ath11k_bss_disassoc(struct ieee80211_hw *hw,
2804 struct ieee80211_vif *vif)
2806 struct ath11k *ar = hw->priv;
2807 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2810 lockdep_assert_held(&ar->conf_mutex);
2812 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2813 arvif->vdev_id, arvif->bssid);
2815 ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id);
2817 ath11k_warn(ar->ab, "failed to down vdev %i: %d\n",
2818 arvif->vdev_id, ret);
2820 arvif->is_up = false;
2822 memset(&arvif->rekey_data, 0, sizeof(arvif->rekey_data));
2824 cancel_delayed_work_sync(&arvif->connection_loss_work);
2827 static u32 ath11k_mac_get_rate_hw_value(int bitrate)
2834 if (ath11k_mac_bitrate_is_cck(bitrate))
2835 preamble = WMI_RATE_PREAMBLE_CCK;
2837 preamble = WMI_RATE_PREAMBLE_OFDM;
2839 for (i = 0; i < ARRAY_SIZE(ath11k_legacy_rates); i++) {
2840 if (ath11k_legacy_rates[i].bitrate != bitrate)
2843 hw_value = ath11k_legacy_rates[i].hw_value;
2844 rate = ATH11K_HW_RATE_CODE(hw_value, 0, preamble);
2852 static void ath11k_recalculate_mgmt_rate(struct ath11k *ar,
2853 struct ieee80211_vif *vif,
2854 struct cfg80211_chan_def *def)
2856 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2857 const struct ieee80211_supported_band *sband;
2864 lockdep_assert_held(&ar->conf_mutex);
2866 sband = ar->hw->wiphy->bands[def->chan->band];
2867 basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
2868 bitrate = sband->bitrates[basic_rate_idx].bitrate;
2870 hw_rate_code = ath11k_mac_get_rate_hw_value(bitrate);
2871 if (hw_rate_code < 0) {
2872 ath11k_warn(ar->ab, "bitrate not supported %d\n", bitrate);
2876 vdev_param = WMI_VDEV_PARAM_MGMT_RATE;
2877 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
2880 ath11k_warn(ar->ab, "failed to set mgmt tx rate %d\n", ret);
2882 /* For WCN6855, firmware will clear this param when vdev starts, hence
2883 * cache it here so that we can reconfigure it once vdev starts.
2885 ar->hw_rate_code = hw_rate_code;
2887 vdev_param = WMI_VDEV_PARAM_BEACON_RATE;
2888 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
2891 ath11k_warn(ar->ab, "failed to set beacon tx rate %d\n", ret);
2894 static int ath11k_mac_fils_discovery(struct ath11k_vif *arvif,
2895 struct ieee80211_bss_conf *info)
2897 struct ath11k *ar = arvif->ar;
2898 struct sk_buff *tmpl;
2901 bool unsol_bcast_probe_resp_enabled = false;
2903 if (info->fils_discovery.max_interval) {
2904 interval = info->fils_discovery.max_interval;
2906 tmpl = ieee80211_get_fils_discovery_tmpl(ar->hw, arvif->vif);
2908 ret = ath11k_wmi_fils_discovery_tmpl(ar, arvif->vdev_id,
2910 } else if (info->unsol_bcast_probe_resp_interval) {
2911 unsol_bcast_probe_resp_enabled = 1;
2912 interval = info->unsol_bcast_probe_resp_interval;
2914 tmpl = ieee80211_get_unsol_bcast_probe_resp_tmpl(ar->hw,
2917 ret = ath11k_wmi_probe_resp_tmpl(ar, arvif->vdev_id,
2919 } else { /* Disable */
2920 return ath11k_wmi_fils_discovery(ar, arvif->vdev_id, 0, false);
2925 "mac vdev %i failed to retrieve %s template\n",
2926 arvif->vdev_id, (unsol_bcast_probe_resp_enabled ?
2927 "unsolicited broadcast probe response" :
2934 ret = ath11k_wmi_fils_discovery(ar, arvif->vdev_id, interval,
2935 unsol_bcast_probe_resp_enabled);
2940 static int ath11k_mac_config_obss_pd(struct ath11k *ar,
2941 struct ieee80211_he_obss_pd *he_obss_pd)
2943 u32 bitmap[2], param_id, param_val, pdev_id;
2945 s8 non_srg_th = 0, srg_th = 0;
2947 pdev_id = ar->pdev->pdev_id;
2949 /* Set and enable SRG/non-SRG OBSS PD Threshold */
2950 param_id = WMI_PDEV_PARAM_SET_CMD_OBSS_PD_THRESHOLD;
2951 if (test_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags)) {
2952 ret = ath11k_wmi_pdev_set_param(ar, param_id, 0, pdev_id);
2955 "failed to set obss_pd_threshold for pdev: %u\n",
2960 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2961 "mac obss pd sr_ctrl %x non_srg_thres %u srg_max %u\n",
2962 he_obss_pd->sr_ctrl, he_obss_pd->non_srg_max_offset,
2963 he_obss_pd->max_offset);
2967 if (he_obss_pd->sr_ctrl &
2968 IEEE80211_HE_SPR_NON_SRG_OBSS_PD_SR_DISALLOWED) {
2969 non_srg_th = ATH11K_OBSS_PD_MAX_THRESHOLD;
2971 if (he_obss_pd->sr_ctrl & IEEE80211_HE_SPR_NON_SRG_OFFSET_PRESENT)
2972 non_srg_th = (ATH11K_OBSS_PD_MAX_THRESHOLD +
2973 he_obss_pd->non_srg_max_offset);
2975 non_srg_th = ATH11K_OBSS_PD_NON_SRG_MAX_THRESHOLD;
2977 param_val |= ATH11K_OBSS_PD_NON_SRG_EN;
2980 if (he_obss_pd->sr_ctrl & IEEE80211_HE_SPR_SRG_INFORMATION_PRESENT) {
2981 srg_th = ATH11K_OBSS_PD_MAX_THRESHOLD + he_obss_pd->max_offset;
2982 param_val |= ATH11K_OBSS_PD_SRG_EN;
2985 if (test_bit(WMI_TLV_SERVICE_SRG_SRP_SPATIAL_REUSE_SUPPORT,
2986 ar->ab->wmi_ab.svc_map)) {
2987 param_val |= ATH11K_OBSS_PD_THRESHOLD_IN_DBM;
2988 param_val |= FIELD_PREP(GENMASK(15, 8), srg_th);
2990 non_srg_th -= ATH11K_DEFAULT_NOISE_FLOOR;
2991 /* SRG not supported and threshold in dB */
2992 param_val &= ~(ATH11K_OBSS_PD_SRG_EN |
2993 ATH11K_OBSS_PD_THRESHOLD_IN_DBM);
2996 param_val |= (non_srg_th & GENMASK(7, 0));
2997 ret = ath11k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id);
3000 "failed to set obss_pd_threshold for pdev: %u\n",
3005 /* Enable OBSS PD for all access category */
3006 param_id = WMI_PDEV_PARAM_SET_CMD_OBSS_PD_PER_AC;
3008 ret = ath11k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id);
3011 "failed to set obss_pd_per_ac for pdev: %u\n",
3016 /* Set SR Prohibit */
3017 param_id = WMI_PDEV_PARAM_ENABLE_SR_PROHIBIT;
3018 param_val = !!(he_obss_pd->sr_ctrl &
3019 IEEE80211_HE_SPR_HESIGA_SR_VAL15_ALLOWED);
3020 ret = ath11k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id);
3022 ath11k_warn(ar->ab, "failed to set sr_prohibit for pdev: %u\n",
3027 if (!test_bit(WMI_TLV_SERVICE_SRG_SRP_SPATIAL_REUSE_SUPPORT,
3028 ar->ab->wmi_ab.svc_map))
3031 /* Set SRG BSS Color Bitmap */
3032 memcpy(bitmap, he_obss_pd->bss_color_bitmap, sizeof(bitmap));
3033 ret = ath11k_wmi_pdev_set_srg_bss_color_bitmap(ar, bitmap);
3036 "failed to set bss_color_bitmap for pdev: %u\n",
3041 /* Set SRG Partial BSSID Bitmap */
3042 memcpy(bitmap, he_obss_pd->partial_bssid_bitmap, sizeof(bitmap));
3043 ret = ath11k_wmi_pdev_set_srg_patial_bssid_bitmap(ar, bitmap);
3046 "failed to set partial_bssid_bitmap for pdev: %u\n",
3051 memset(bitmap, 0xff, sizeof(bitmap));
3053 /* Enable all BSS Colors for SRG */
3054 ret = ath11k_wmi_pdev_srg_obss_color_enable_bitmap(ar, bitmap);
3057 "failed to set srg_color_en_bitmap pdev: %u\n",
3062 /* Enable all patial BSSID mask for SRG */
3063 ret = ath11k_wmi_pdev_srg_obss_bssid_enable_bitmap(ar, bitmap);
3066 "failed to set srg_bssid_en_bitmap pdev: %u\n",
3071 /* Enable all BSS Colors for non-SRG */
3072 ret = ath11k_wmi_pdev_non_srg_obss_color_enable_bitmap(ar, bitmap);
3075 "failed to set non_srg_color_en_bitmap pdev: %u\n",
3080 /* Enable all patial BSSID mask for non-SRG */
3081 ret = ath11k_wmi_pdev_non_srg_obss_bssid_enable_bitmap(ar, bitmap);
3084 "failed to set non_srg_bssid_en_bitmap pdev: %u\n",
3092 static void ath11k_mac_op_bss_info_changed(struct ieee80211_hw *hw,
3093 struct ieee80211_vif *vif,
3094 struct ieee80211_bss_conf *info,
3097 struct ath11k *ar = hw->priv;
3098 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
3099 struct cfg80211_chan_def def;
3100 u32 param_id, param_value;
3101 enum nl80211_band band;
3112 mutex_lock(&ar->conf_mutex);
3114 if (changed & BSS_CHANGED_BEACON_INT) {
3115 arvif->beacon_interval = info->beacon_int;
3117 param_id = WMI_VDEV_PARAM_BEACON_INTERVAL;
3118 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3120 arvif->beacon_interval);
3122 ath11k_warn(ar->ab, "Failed to set beacon interval for VDEV: %d\n",
3125 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3126 "Beacon interval: %d set for VDEV: %d\n",
3127 arvif->beacon_interval, arvif->vdev_id);
3130 if (changed & BSS_CHANGED_BEACON) {
3131 param_id = WMI_PDEV_PARAM_BEACON_TX_MODE;
3132 param_value = WMI_BEACON_STAGGERED_MODE;
3133 ret = ath11k_wmi_pdev_set_param(ar, param_id,
3134 param_value, ar->pdev->pdev_id);
3136 ath11k_warn(ar->ab, "Failed to set beacon mode for VDEV: %d\n",
3139 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3140 "Set staggered beacon mode for VDEV: %d\n",
3143 if (!arvif->do_not_send_tmpl || !arvif->bcca_zero_sent) {
3144 ret = ath11k_mac_setup_bcn_tmpl(arvif);
3146 ath11k_warn(ar->ab, "failed to update bcn template: %d\n",
3150 if (arvif->bcca_zero_sent)
3151 arvif->do_not_send_tmpl = true;
3153 arvif->do_not_send_tmpl = false;
3155 if (vif->bss_conf.he_support) {
3156 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3157 WMI_VDEV_PARAM_BA_MODE,
3158 WMI_BA_MODE_BUFFER_SIZE_256);
3161 "failed to set BA BUFFER SIZE 256 for vdev: %d\n",
3164 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3165 "Set BA BUFFER SIZE 256 for VDEV: %d\n",
3170 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
3171 arvif->dtim_period = info->dtim_period;
3173 param_id = WMI_VDEV_PARAM_DTIM_PERIOD;
3174 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3176 arvif->dtim_period);
3179 ath11k_warn(ar->ab, "Failed to set dtim period for VDEV %d: %i\n",
3180 arvif->vdev_id, ret);
3182 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3183 "DTIM period: %d set for VDEV: %d\n",
3184 arvif->dtim_period, arvif->vdev_id);
3187 if (changed & BSS_CHANGED_SSID &&
3188 vif->type == NL80211_IFTYPE_AP) {
3189 arvif->u.ap.ssid_len = vif->cfg.ssid_len;
3190 if (vif->cfg.ssid_len)
3191 memcpy(arvif->u.ap.ssid, vif->cfg.ssid,
3193 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3196 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3197 ether_addr_copy(arvif->bssid, info->bssid);
3199 if (changed & BSS_CHANGED_BEACON_ENABLED) {
3200 ath11k_control_beaconing(arvif, info);
3202 if (arvif->is_up && vif->bss_conf.he_support &&
3203 vif->bss_conf.he_oper.params) {
3204 param_id = WMI_VDEV_PARAM_HEOPS_0_31;
3205 param_value = vif->bss_conf.he_oper.params;
3206 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3207 param_id, param_value);
3208 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3209 "he oper param: %x set for VDEV: %d\n",
3210 param_value, arvif->vdev_id);
3213 ath11k_warn(ar->ab, "Failed to set he oper params %x for VDEV %d: %i\n",
3214 param_value, arvif->vdev_id, ret);
3218 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3221 cts_prot = !!(info->use_cts_prot);
3222 param_id = WMI_VDEV_PARAM_PROTECTION_MODE;
3224 if (arvif->is_started) {
3225 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3226 param_id, cts_prot);
3228 ath11k_warn(ar->ab, "Failed to set CTS prot for VDEV: %d\n",
3231 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "Set CTS prot: %d for VDEV: %d\n",
3232 cts_prot, arvif->vdev_id);
3234 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "defer protection mode setup, vdev is not ready yet\n");
3238 if (changed & BSS_CHANGED_ERP_SLOT) {
3241 if (info->use_short_slot)
3242 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3245 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3247 param_id = WMI_VDEV_PARAM_SLOT_TIME;
3248 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3249 param_id, slottime);
3251 ath11k_warn(ar->ab, "Failed to set erp slot for VDEV: %d\n",
3254 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3255 "Set slottime: %d for VDEV: %d\n",
3256 slottime, arvif->vdev_id);
3259 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3262 if (info->use_short_preamble)
3263 preamble = WMI_VDEV_PREAMBLE_SHORT;
3265 preamble = WMI_VDEV_PREAMBLE_LONG;
3267 param_id = WMI_VDEV_PARAM_PREAMBLE;
3268 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3269 param_id, preamble);
3271 ath11k_warn(ar->ab, "Failed to set preamble for VDEV: %d\n",
3274 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3275 "Set preamble: %d for VDEV: %d\n",
3276 preamble, arvif->vdev_id);
3279 if (changed & BSS_CHANGED_ASSOC) {
3281 ath11k_bss_assoc(hw, vif, info);
3283 ath11k_bss_disassoc(hw, vif);
3286 if (changed & BSS_CHANGED_TXPOWER) {
3287 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3288 arvif->vdev_id, info->txpower);
3290 arvif->txpower = info->txpower;
3291 ath11k_mac_txpower_recalc(ar);
3294 if (changed & BSS_CHANGED_PS &&
3295 ar->ab->hw_params.supports_sta_ps) {
3296 arvif->ps = vif->cfg.ps;
3298 ret = ath11k_mac_config_ps(ar);
3300 ath11k_warn(ar->ab, "failed to setup ps on vdev %i: %d\n",
3301 arvif->vdev_id, ret);
3304 if (changed & BSS_CHANGED_MCAST_RATE &&
3305 !ath11k_mac_vif_chan(arvif->vif, &def)) {
3306 band = def.chan->band;
3307 mcast_rate = vif->bss_conf.mcast_rate[band];
3310 rateidx = mcast_rate - 1;
3312 rateidx = ffs(vif->bss_conf.basic_rates) - 1;
3314 if (ar->pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP)
3315 rateidx += ATH11K_MAC_FIRST_OFDM_RATE_IDX;
3317 bitrate = ath11k_legacy_rates[rateidx].bitrate;
3318 hw_value = ath11k_legacy_rates[rateidx].hw_value;
3320 if (ath11k_mac_bitrate_is_cck(bitrate))
3321 preamble = WMI_RATE_PREAMBLE_CCK;
3323 preamble = WMI_RATE_PREAMBLE_OFDM;
3325 rate = ATH11K_HW_RATE_CODE(hw_value, 0, preamble);
3327 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3328 "mac vdev %d mcast_rate %x\n",
3329 arvif->vdev_id, rate);
3331 vdev_param = WMI_VDEV_PARAM_MCAST_DATA_RATE;
3332 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3336 "failed to set mcast rate on vdev %i: %d\n",
3337 arvif->vdev_id, ret);
3339 vdev_param = WMI_VDEV_PARAM_BCAST_DATA_RATE;
3340 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3344 "failed to set bcast rate on vdev %i: %d\n",
3345 arvif->vdev_id, ret);
3348 if (changed & BSS_CHANGED_BASIC_RATES &&
3349 !ath11k_mac_vif_chan(arvif->vif, &def))
3350 ath11k_recalculate_mgmt_rate(ar, vif, &def);
3352 if (changed & BSS_CHANGED_TWT) {
3353 if (info->twt_requester || info->twt_responder)
3354 ath11k_wmi_send_twt_enable_cmd(ar, ar->pdev->pdev_id);
3356 ath11k_wmi_send_twt_disable_cmd(ar, ar->pdev->pdev_id);
3359 if (changed & BSS_CHANGED_HE_OBSS_PD)
3360 ath11k_mac_config_obss_pd(ar, &info->he_obss_pd);
3362 if (changed & BSS_CHANGED_HE_BSS_COLOR) {
3363 if (vif->type == NL80211_IFTYPE_AP) {
3364 ret = ath11k_wmi_send_obss_color_collision_cfg_cmd(
3365 ar, arvif->vdev_id, info->he_bss_color.color,
3366 ATH11K_BSS_COLOR_COLLISION_DETECTION_AP_PERIOD_MS,
3367 info->he_bss_color.enabled);
3369 ath11k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n",
3370 arvif->vdev_id, ret);
3372 param_id = WMI_VDEV_PARAM_BSS_COLOR;
3373 if (info->he_bss_color.enabled)
3374 param_value = info->he_bss_color.color <<
3375 IEEE80211_HE_OPERATION_BSS_COLOR_OFFSET;
3377 param_value = IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED;
3379 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3384 "failed to set bss color param on vdev %i: %d\n",
3385 arvif->vdev_id, ret);
3387 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3388 "bss color param 0x%x set on vdev %i\n",
3389 param_value, arvif->vdev_id);
3390 } else if (vif->type == NL80211_IFTYPE_STATION) {
3391 ret = ath11k_wmi_send_bss_color_change_enable_cmd(ar,
3395 ath11k_warn(ar->ab, "failed to enable bss color change on vdev %i: %d\n",
3396 arvif->vdev_id, ret);
3397 ret = ath11k_wmi_send_obss_color_collision_cfg_cmd(
3398 ar, arvif->vdev_id, 0,
3399 ATH11K_BSS_COLOR_COLLISION_DETECTION_STA_PERIOD_MS, 1);
3401 ath11k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n",
3402 arvif->vdev_id, ret);
3406 if (changed & BSS_CHANGED_FILS_DISCOVERY ||
3407 changed & BSS_CHANGED_UNSOL_BCAST_PROBE_RESP)
3408 ath11k_mac_fils_discovery(arvif, info);
3410 if (changed & BSS_CHANGED_ARP_FILTER) {
3411 ipv4_cnt = min(vif->cfg.arp_addr_cnt, ATH11K_IPV4_MAX_COUNT);
3412 memcpy(arvif->arp_ns_offload.ipv4_addr,
3413 vif->cfg.arp_addr_list,
3414 ipv4_cnt * sizeof(u32));
3415 memcpy(arvif->arp_ns_offload.mac_addr, vif->addr, ETH_ALEN);
3416 arvif->arp_ns_offload.ipv4_count = ipv4_cnt;
3418 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac arp_addr_cnt %d vif->addr %pM, offload_addr %pI4\n",
3419 vif->cfg.arp_addr_cnt,
3420 vif->addr, arvif->arp_ns_offload.ipv4_addr);
3423 mutex_unlock(&ar->conf_mutex);
3426 void __ath11k_mac_scan_finish(struct ath11k *ar)
3428 lockdep_assert_held(&ar->data_lock);
3430 switch (ar->scan.state) {
3431 case ATH11K_SCAN_IDLE:
3433 case ATH11K_SCAN_RUNNING:
3434 case ATH11K_SCAN_ABORTING:
3435 if (ar->scan.is_roc && ar->scan.roc_notify)
3436 ieee80211_remain_on_channel_expired(ar->hw);
3438 case ATH11K_SCAN_STARTING:
3439 if (!ar->scan.is_roc) {
3440 struct cfg80211_scan_info info = {
3441 .aborted = ((ar->scan.state ==
3442 ATH11K_SCAN_ABORTING) ||
3444 ATH11K_SCAN_STARTING)),
3447 ieee80211_scan_completed(ar->hw, &info);
3450 ar->scan.state = ATH11K_SCAN_IDLE;
3451 ar->scan_channel = NULL;
3452 ar->scan.roc_freq = 0;
3453 cancel_delayed_work(&ar->scan.timeout);
3454 complete(&ar->scan.completed);
3459 void ath11k_mac_scan_finish(struct ath11k *ar)
3461 spin_lock_bh(&ar->data_lock);
3462 __ath11k_mac_scan_finish(ar);
3463 spin_unlock_bh(&ar->data_lock);
3466 static int ath11k_scan_stop(struct ath11k *ar)
3468 struct scan_cancel_param arg = {
3469 .req_type = WLAN_SCAN_CANCEL_SINGLE,
3470 .scan_id = ATH11K_SCAN_ID,
3474 lockdep_assert_held(&ar->conf_mutex);
3476 /* TODO: Fill other STOP Params */
3477 arg.pdev_id = ar->pdev->pdev_id;
3479 ret = ath11k_wmi_send_scan_stop_cmd(ar, &arg);
3481 ath11k_warn(ar->ab, "failed to stop wmi scan: %d\n", ret);
3485 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
3488 "failed to receive scan abort comple: timed out\n");
3490 } else if (ret > 0) {
3495 /* Scan state should be updated upon scan completion but in case
3496 * firmware fails to deliver the event (for whatever reason) it is
3497 * desired to clean up scan state anyway. Firmware may have just
3498 * dropped the scan completion event delivery due to transport pipe
3499 * being overflown with data and/or it can recover on its own before
3500 * next scan request is submitted.
3502 spin_lock_bh(&ar->data_lock);
3503 if (ar->scan.state != ATH11K_SCAN_IDLE)
3504 __ath11k_mac_scan_finish(ar);
3505 spin_unlock_bh(&ar->data_lock);
3510 static void ath11k_scan_abort(struct ath11k *ar)
3514 lockdep_assert_held(&ar->conf_mutex);
3516 spin_lock_bh(&ar->data_lock);
3518 switch (ar->scan.state) {
3519 case ATH11K_SCAN_IDLE:
3520 /* This can happen if timeout worker kicked in and called
3521 * abortion while scan completion was being processed.
3524 case ATH11K_SCAN_STARTING:
3525 case ATH11K_SCAN_ABORTING:
3526 ath11k_warn(ar->ab, "refusing scan abortion due to invalid scan state: %d\n",
3529 case ATH11K_SCAN_RUNNING:
3530 ar->scan.state = ATH11K_SCAN_ABORTING;
3531 spin_unlock_bh(&ar->data_lock);
3533 ret = ath11k_scan_stop(ar);
3535 ath11k_warn(ar->ab, "failed to abort scan: %d\n", ret);
3537 spin_lock_bh(&ar->data_lock);
3541 spin_unlock_bh(&ar->data_lock);
3544 static void ath11k_scan_timeout_work(struct work_struct *work)
3546 struct ath11k *ar = container_of(work, struct ath11k,
3549 mutex_lock(&ar->conf_mutex);
3550 ath11k_scan_abort(ar);
3551 mutex_unlock(&ar->conf_mutex);
3554 static int ath11k_start_scan(struct ath11k *ar,
3555 struct scan_req_params *arg)
3558 unsigned long timeout = 1 * HZ;
3560 lockdep_assert_held(&ar->conf_mutex);
3562 if (ath11k_spectral_get_mode(ar) == ATH11K_SPECTRAL_BACKGROUND)
3563 ath11k_spectral_reset_buffer(ar);
3565 ret = ath11k_wmi_send_scan_start_cmd(ar, arg);
3569 if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map)) {
3572 if (ar->supports_6ghz)
3576 ret = wait_for_completion_timeout(&ar->scan.started, timeout);
3578 ret = ath11k_scan_stop(ar);
3580 ath11k_warn(ar->ab, "failed to stop scan: %d\n", ret);
3585 /* If we failed to start the scan, return error code at
3586 * this point. This is probably due to some issue in the
3587 * firmware, but no need to wedge the driver due to that...
3589 spin_lock_bh(&ar->data_lock);
3590 if (ar->scan.state == ATH11K_SCAN_IDLE) {
3591 spin_unlock_bh(&ar->data_lock);
3594 spin_unlock_bh(&ar->data_lock);
3599 static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
3600 struct ieee80211_vif *vif,
3601 struct ieee80211_scan_request *hw_req)
3603 struct ath11k *ar = hw->priv;
3604 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
3605 struct cfg80211_scan_request *req = &hw_req->req;
3606 struct scan_req_params arg;
3610 mutex_lock(&ar->conf_mutex);
3612 spin_lock_bh(&ar->data_lock);
3613 switch (ar->scan.state) {
3614 case ATH11K_SCAN_IDLE:
3615 reinit_completion(&ar->scan.started);
3616 reinit_completion(&ar->scan.completed);
3617 ar->scan.state = ATH11K_SCAN_STARTING;
3618 ar->scan.is_roc = false;
3619 ar->scan.vdev_id = arvif->vdev_id;
3622 case ATH11K_SCAN_STARTING:
3623 case ATH11K_SCAN_RUNNING:
3624 case ATH11K_SCAN_ABORTING:
3628 spin_unlock_bh(&ar->data_lock);
3633 memset(&arg, 0, sizeof(arg));
3634 ath11k_wmi_start_scan_init(ar, &arg);
3635 arg.vdev_id = arvif->vdev_id;
3636 arg.scan_id = ATH11K_SCAN_ID;
3639 arg.extraie.ptr = kmemdup(req->ie, req->ie_len, GFP_KERNEL);
3640 if (!arg.extraie.ptr) {
3644 arg.extraie.len = req->ie_len;
3648 arg.num_ssids = req->n_ssids;
3649 for (i = 0; i < arg.num_ssids; i++) {
3650 arg.ssid[i].length = req->ssids[i].ssid_len;
3651 memcpy(&arg.ssid[i].ssid, req->ssids[i].ssid,
3652 req->ssids[i].ssid_len);
3655 arg.scan_flags |= WMI_SCAN_FLAG_PASSIVE;
3658 if (req->n_channels) {
3659 arg.num_chan = req->n_channels;
3660 arg.chan_list = kcalloc(arg.num_chan, sizeof(*arg.chan_list),
3663 if (!arg.chan_list) {
3668 for (i = 0; i < arg.num_chan; i++)
3669 arg.chan_list[i] = req->channels[i]->center_freq;
3672 if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
3673 arg.scan_f_add_spoofed_mac_in_probe = 1;
3674 ether_addr_copy(arg.mac_addr.addr, req->mac_addr);
3675 ether_addr_copy(arg.mac_mask.addr, req->mac_addr_mask);
3678 ret = ath11k_start_scan(ar, &arg);
3680 ath11k_warn(ar->ab, "failed to start hw scan: %d\n", ret);
3681 spin_lock_bh(&ar->data_lock);
3682 ar->scan.state = ATH11K_SCAN_IDLE;
3683 spin_unlock_bh(&ar->data_lock);
3686 /* Add a 200ms margin to account for event/command processing */
3687 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3688 msecs_to_jiffies(arg.max_scan_time +
3689 ATH11K_MAC_SCAN_TIMEOUT_MSECS));
3692 kfree(arg.chan_list);
3695 kfree(arg.extraie.ptr);
3697 mutex_unlock(&ar->conf_mutex);
3699 if (ar->state_11d == ATH11K_11D_PREPARING)
3700 ath11k_mac_11d_scan_start(ar, arvif->vdev_id);
3705 static void ath11k_mac_op_cancel_hw_scan(struct ieee80211_hw *hw,
3706 struct ieee80211_vif *vif)
3708 struct ath11k *ar = hw->priv;
3710 mutex_lock(&ar->conf_mutex);
3711 ath11k_scan_abort(ar);
3712 mutex_unlock(&ar->conf_mutex);
3714 cancel_delayed_work_sync(&ar->scan.timeout);
3717 static int ath11k_install_key(struct ath11k_vif *arvif,
3718 struct ieee80211_key_conf *key,
3719 enum set_key_cmd cmd,
3720 const u8 *macaddr, u32 flags)
3723 struct ath11k *ar = arvif->ar;
3724 struct wmi_vdev_install_key_arg arg = {
3725 .vdev_id = arvif->vdev_id,
3726 .key_idx = key->keyidx,
3727 .key_len = key->keylen,
3728 .key_data = key->key,
3733 lockdep_assert_held(&arvif->ar->conf_mutex);
3735 reinit_completion(&ar->install_key_done);
3737 if (test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags))
3740 if (cmd == DISABLE_KEY) {
3741 arg.key_cipher = WMI_CIPHER_NONE;
3742 arg.key_data = NULL;
3746 switch (key->cipher) {
3747 case WLAN_CIPHER_SUITE_CCMP:
3748 arg.key_cipher = WMI_CIPHER_AES_CCM;
3749 /* TODO: Re-check if flag is valid */
3750 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
3752 case WLAN_CIPHER_SUITE_TKIP:
3753 arg.key_cipher = WMI_CIPHER_TKIP;
3754 arg.key_txmic_len = 8;
3755 arg.key_rxmic_len = 8;
3757 case WLAN_CIPHER_SUITE_CCMP_256:
3758 arg.key_cipher = WMI_CIPHER_AES_CCM;
3760 case WLAN_CIPHER_SUITE_GCMP:
3761 case WLAN_CIPHER_SUITE_GCMP_256:
3762 arg.key_cipher = WMI_CIPHER_AES_GCM;
3765 ath11k_warn(ar->ab, "cipher %d is not supported\n", key->cipher);
3769 if (test_bit(ATH11K_FLAG_RAW_MODE, &ar->ab->dev_flags))
3770 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV |
3771 IEEE80211_KEY_FLAG_RESERVE_TAILROOM;
3774 ret = ath11k_wmi_vdev_install_key(arvif->ar, &arg);
3779 if (!wait_for_completion_timeout(&ar->install_key_done, 1 * HZ))
3782 return ar->install_key_status ? -EINVAL : 0;
3785 static int ath11k_clear_peer_keys(struct ath11k_vif *arvif,
3788 struct ath11k *ar = arvif->ar;
3789 struct ath11k_base *ab = ar->ab;
3790 struct ath11k_peer *peer;
3791 int first_errno = 0;
3796 lockdep_assert_held(&ar->conf_mutex);
3798 spin_lock_bh(&ab->base_lock);
3799 peer = ath11k_peer_find(ab, arvif->vdev_id, addr);
3800 spin_unlock_bh(&ab->base_lock);
3805 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
3809 /* key flags are not required to delete the key */
3810 ret = ath11k_install_key(arvif, peer->keys[i],
3811 DISABLE_KEY, addr, flags);
3812 if (ret < 0 && first_errno == 0)
3816 ath11k_warn(ab, "failed to remove peer key %d: %d\n",
3819 spin_lock_bh(&ab->base_lock);
3820 peer->keys[i] = NULL;
3821 spin_unlock_bh(&ab->base_lock);
3827 static int ath11k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3828 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3829 struct ieee80211_key_conf *key)
3831 struct ath11k *ar = hw->priv;
3832 struct ath11k_base *ab = ar->ab;
3833 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
3834 struct ath11k_peer *peer;
3835 struct ath11k_sta *arsta;
3836 const u8 *peer_addr;
3840 /* BIP needs to be done in software */
3841 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3842 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3843 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 ||
3844 key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256)
3847 if (test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags))
3850 if (key->keyidx > WMI_MAX_KEY_INDEX)
3853 mutex_lock(&ar->conf_mutex);
3856 peer_addr = sta->addr;
3857 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3858 peer_addr = vif->bss_conf.bssid;
3860 peer_addr = vif->addr;
3862 key->hw_key_idx = key->keyidx;
3864 /* the peer should not disappear in mid-way (unless FW goes awry) since
3865 * we already hold conf_mutex. we just make sure its there now.
3867 spin_lock_bh(&ab->base_lock);
3868 peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr);
3870 /* flush the fragments cache during key (re)install to
3871 * ensure all frags in the new frag list belong to the same key.
3873 if (peer && sta && cmd == SET_KEY)
3874 ath11k_peer_frags_flush(ar, peer);
3875 spin_unlock_bh(&ab->base_lock);
3878 if (cmd == SET_KEY) {
3879 ath11k_warn(ab, "cannot install key for non-existent peer %pM\n",
3884 /* if the peer doesn't exist there is no key to disable
3891 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3892 flags |= WMI_KEY_PAIRWISE;
3894 flags |= WMI_KEY_GROUP;
3896 ret = ath11k_install_key(arvif, key, cmd, peer_addr, flags);
3898 ath11k_warn(ab, "ath11k_install_key failed (%d)\n", ret);
3902 ret = ath11k_dp_peer_rx_pn_replay_config(arvif, peer_addr, cmd, key);
3904 ath11k_warn(ab, "failed to offload PN replay detection %d\n", ret);
3908 spin_lock_bh(&ab->base_lock);
3909 peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr);
3910 if (peer && cmd == SET_KEY) {
3911 peer->keys[key->keyidx] = key;
3912 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
3913 peer->ucast_keyidx = key->keyidx;
3914 peer->sec_type = ath11k_dp_tx_get_encrypt_type(key->cipher);
3916 peer->mcast_keyidx = key->keyidx;
3917 peer->sec_type_grp = ath11k_dp_tx_get_encrypt_type(key->cipher);
3919 } else if (peer && cmd == DISABLE_KEY) {
3920 peer->keys[key->keyidx] = NULL;
3921 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3922 peer->ucast_keyidx = 0;
3924 peer->mcast_keyidx = 0;
3926 /* impossible unless FW goes crazy */
3927 ath11k_warn(ab, "peer %pM disappeared!\n", peer_addr);
3930 arsta = (struct ath11k_sta *)sta->drv_priv;
3932 switch (key->cipher) {
3933 case WLAN_CIPHER_SUITE_TKIP:
3934 case WLAN_CIPHER_SUITE_CCMP:
3935 case WLAN_CIPHER_SUITE_CCMP_256:
3936 case WLAN_CIPHER_SUITE_GCMP:
3937 case WLAN_CIPHER_SUITE_GCMP_256:
3939 arsta->pn_type = HAL_PN_TYPE_WPA;
3941 arsta->pn_type = HAL_PN_TYPE_NONE;
3944 arsta->pn_type = HAL_PN_TYPE_NONE;
3949 spin_unlock_bh(&ab->base_lock);
3952 mutex_unlock(&ar->conf_mutex);
3957 ath11k_mac_bitrate_mask_num_vht_rates(struct ath11k *ar,
3958 enum nl80211_band band,
3959 const struct cfg80211_bitrate_mask *mask)
3964 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
3965 num_rates += hweight16(mask->control[band].vht_mcs[i]);
3971 ath11k_mac_bitrate_mask_num_he_rates(struct ath11k *ar,
3972 enum nl80211_band band,
3973 const struct cfg80211_bitrate_mask *mask)
3978 for (i = 0; i < ARRAY_SIZE(mask->control[band].he_mcs); i++)
3979 num_rates += hweight16(mask->control[band].he_mcs[i]);
3985 ath11k_mac_set_peer_vht_fixed_rate(struct ath11k_vif *arvif,
3986 struct ieee80211_sta *sta,
3987 const struct cfg80211_bitrate_mask *mask,
3988 enum nl80211_band band)
3990 struct ath11k *ar = arvif->ar;
3995 lockdep_assert_held(&ar->conf_mutex);
3999 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
4000 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
4002 vht_rate = ffs(mask->control[band].vht_mcs[i]) - 1;
4007 ath11k_warn(ar->ab, "No single VHT Fixed rate found to set for %pM",
4012 /* Avoid updating invalid nss as fixed rate*/
4013 if (nss > sta->deflink.rx_nss)
4016 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
4017 "Setting Fixed VHT Rate for peer %pM. Device will not switch to any other selected rates",
4020 rate_code = ATH11K_HW_RATE_CODE(vht_rate, nss - 1,
4021 WMI_RATE_PREAMBLE_VHT);
4022 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
4024 WMI_PEER_PARAM_FIXED_RATE,
4028 "failed to update STA %pM Fixed Rate %d: %d\n",
4029 sta->addr, rate_code, ret);
4035 ath11k_mac_set_peer_he_fixed_rate(struct ath11k_vif *arvif,
4036 struct ieee80211_sta *sta,
4037 const struct cfg80211_bitrate_mask *mask,
4038 enum nl80211_band band)
4040 struct ath11k *ar = arvif->ar;
4045 lockdep_assert_held(&ar->conf_mutex);
4049 for (i = 0; i < ARRAY_SIZE(mask->control[band].he_mcs); i++) {
4050 if (hweight16(mask->control[band].he_mcs[i]) == 1) {
4052 he_rate = ffs(mask->control[band].he_mcs[i]) - 1;
4057 ath11k_warn(ar->ab, "No single he fixed rate found to set for %pM",
4062 /* Avoid updating invalid nss as fixed rate */
4063 if (nss > sta->deflink.rx_nss)
4066 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
4067 "mac setting fixed he rate for peer %pM, device will not switch to any other selected rates",
4070 rate_code = ATH11K_HW_RATE_CODE(he_rate, nss - 1,
4071 WMI_RATE_PREAMBLE_HE);
4073 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
4075 WMI_PEER_PARAM_FIXED_RATE,
4079 "failed to update sta %pM fixed rate %d: %d\n",
4080 sta->addr, rate_code, ret);
4085 static int ath11k_station_assoc(struct ath11k *ar,
4086 struct ieee80211_vif *vif,
4087 struct ieee80211_sta *sta,
4090 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4091 struct peer_assoc_params peer_arg;
4093 struct cfg80211_chan_def def;
4094 enum nl80211_band band;
4095 struct cfg80211_bitrate_mask *mask;
4096 u8 num_vht_rates, num_he_rates;
4098 lockdep_assert_held(&ar->conf_mutex);
4100 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
4103 band = def.chan->band;
4104 mask = &arvif->bitrate_mask;
4106 ath11k_peer_assoc_prepare(ar, vif, sta, &peer_arg, reassoc);
4108 peer_arg.is_assoc = true;
4109 ret = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
4111 ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n",
4112 sta->addr, arvif->vdev_id, ret);
4116 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
4117 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
4118 sta->addr, arvif->vdev_id);
4122 num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask);
4123 num_he_rates = ath11k_mac_bitrate_mask_num_he_rates(ar, band, mask);
4125 /* If single VHT/HE rate is configured (by set_bitrate_mask()),
4126 * peer_assoc will disable VHT/HE. This is now enabled by a peer specific
4128 * Note that all other rates and NSS will be disabled for this peer.
4130 if (sta->deflink.vht_cap.vht_supported && num_vht_rates == 1) {
4131 ret = ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask,
4135 } else if (sta->deflink.he_cap.has_he && num_he_rates == 1) {
4136 ret = ath11k_mac_set_peer_he_fixed_rate(arvif, sta, mask,
4142 /* Re-assoc is run only to update supported rates for given station. It
4143 * doesn't make much sense to reconfigure the peer completely.
4148 ret = ath11k_setup_peer_smps(ar, arvif, sta->addr,
4149 &sta->deflink.ht_cap,
4150 le16_to_cpu(sta->deflink.he_6ghz_capa.capa));
4152 ath11k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n",
4153 arvif->vdev_id, ret);
4158 arvif->num_legacy_stations++;
4159 ret = ath11k_recalc_rtscts_prot(arvif);
4164 if (sta->wme && sta->uapsd_queues) {
4165 ret = ath11k_peer_assoc_qos_ap(ar, arvif, sta);
4167 ath11k_warn(ar->ab, "failed to set qos params for STA %pM for vdev %i: %d\n",
4168 sta->addr, arvif->vdev_id, ret);
4176 static int ath11k_station_disassoc(struct ath11k *ar,
4177 struct ieee80211_vif *vif,
4178 struct ieee80211_sta *sta)
4180 struct ath11k_vif *arvif = (void *)vif->drv_priv;
4183 lockdep_assert_held(&ar->conf_mutex);
4186 arvif->num_legacy_stations--;
4187 ret = ath11k_recalc_rtscts_prot(arvif);
4192 ret = ath11k_clear_peer_keys(arvif, sta->addr);
4194 ath11k_warn(ar->ab, "failed to clear all peer keys for vdev %i: %d\n",
4195 arvif->vdev_id, ret);
4201 static void ath11k_sta_rc_update_wk(struct work_struct *wk)
4204 struct ath11k_vif *arvif;
4205 struct ath11k_sta *arsta;
4206 struct ieee80211_sta *sta;
4207 struct cfg80211_chan_def def;
4208 enum nl80211_band band;
4209 const u8 *ht_mcs_mask;
4210 const u16 *vht_mcs_mask;
4211 const u16 *he_mcs_mask;
4212 u32 changed, bw, nss, smps;
4213 int err, num_vht_rates, num_he_rates;
4214 const struct cfg80211_bitrate_mask *mask;
4215 struct peer_assoc_params peer_arg;
4217 arsta = container_of(wk, struct ath11k_sta, update_wk);
4218 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4219 arvif = arsta->arvif;
4222 if (WARN_ON(ath11k_mac_vif_chan(arvif->vif, &def)))
4225 band = def.chan->band;
4226 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
4227 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
4228 he_mcs_mask = arvif->bitrate_mask.control[band].he_mcs;
4230 spin_lock_bh(&ar->data_lock);
4232 changed = arsta->changed;
4239 spin_unlock_bh(&ar->data_lock);
4241 mutex_lock(&ar->conf_mutex);
4243 nss = max_t(u32, 1, nss);
4244 nss = min(nss, max(max(ath11k_mac_max_ht_nss(ht_mcs_mask),
4245 ath11k_mac_max_vht_nss(vht_mcs_mask)),
4246 ath11k_mac_max_he_nss(he_mcs_mask)));
4248 if (changed & IEEE80211_RC_BW_CHANGED) {
4249 /* Send peer assoc command before set peer bandwidth param to
4250 * avoid the mismatch between the peer phymode and the peer
4253 ath11k_peer_assoc_prepare(ar, arvif->vif, sta, &peer_arg, true);
4255 peer_arg.is_assoc = false;
4256 err = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
4258 ath11k_warn(ar->ab, "failed to send peer assoc for STA %pM vdev %i: %d\n",
4259 sta->addr, arvif->vdev_id, err);
4260 } else if (wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
4261 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
4262 WMI_PEER_CHWIDTH, bw);
4264 ath11k_warn(ar->ab, "failed to update STA %pM peer bw %d: %d\n",
4265 sta->addr, bw, err);
4267 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
4268 sta->addr, arvif->vdev_id);
4272 if (changed & IEEE80211_RC_NSS_CHANGED) {
4273 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM nss %d\n",
4276 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
4279 ath11k_warn(ar->ab, "failed to update STA %pM nss %d: %d\n",
4280 sta->addr, nss, err);
4283 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4284 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM smps %d\n",
4287 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
4288 WMI_PEER_MIMO_PS_STATE, smps);
4290 ath11k_warn(ar->ab, "failed to update STA %pM smps %d: %d\n",
4291 sta->addr, smps, err);
4294 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
4295 mask = &arvif->bitrate_mask;
4296 num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band,
4298 num_he_rates = ath11k_mac_bitrate_mask_num_he_rates(ar, band,
4301 /* Peer_assoc_prepare will reject vht rates in
4302 * bitrate_mask if its not available in range format and
4303 * sets vht tx_rateset as unsupported. So multiple VHT MCS
4304 * setting(eg. MCS 4,5,6) per peer is not supported here.
4305 * But, Single rate in VHT mask can be set as per-peer
4306 * fixed rate. But even if any HT rates are configured in
4307 * the bitrate mask, device will not switch to those rates
4308 * when per-peer Fixed rate is set.
4309 * TODO: Check RATEMASK_CMDID to support auto rates selection
4310 * across HT/VHT and for multiple VHT MCS support.
4312 if (sta->deflink.vht_cap.vht_supported && num_vht_rates == 1) {
4313 ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask,
4315 } else if (sta->deflink.he_cap.has_he && num_he_rates == 1) {
4316 ath11k_mac_set_peer_he_fixed_rate(arvif, sta, mask,
4319 /* If the peer is non-VHT/HE or no fixed VHT/HE rate
4320 * is provided in the new bitrate mask we set the
4321 * other rates using peer_assoc command. Also clear
4322 * the peer fixed rate settings as it has higher proprity
4325 err = ath11k_wmi_set_peer_param(ar, sta->addr,
4327 WMI_PEER_PARAM_FIXED_RATE,
4328 WMI_FIXED_RATE_NONE);
4331 "failed to disable peer fixed rate for sta %pM: %d\n",
4334 ath11k_peer_assoc_prepare(ar, arvif->vif, sta,
4337 peer_arg.is_assoc = false;
4338 err = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
4340 ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n",
4341 sta->addr, arvif->vdev_id, err);
4343 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ))
4344 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
4345 sta->addr, arvif->vdev_id);
4349 mutex_unlock(&ar->conf_mutex);
4352 static void ath11k_sta_set_4addr_wk(struct work_struct *wk)
4355 struct ath11k_vif *arvif;
4356 struct ath11k_sta *arsta;
4357 struct ieee80211_sta *sta;
4360 arsta = container_of(wk, struct ath11k_sta, set_4addr_wk);
4361 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4362 arvif = arsta->arvif;
4365 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
4366 "setting USE_4ADDR for peer %pM\n", sta->addr);
4368 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
4370 WMI_PEER_USE_4ADDR, 1);
4373 ath11k_warn(ar->ab, "failed to set peer %pM 4addr capability: %d\n",
4377 static int ath11k_mac_inc_num_stations(struct ath11k_vif *arvif,
4378 struct ieee80211_sta *sta)
4380 struct ath11k *ar = arvif->ar;
4382 lockdep_assert_held(&ar->conf_mutex);
4384 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
4387 if (ar->num_stations >= ar->max_num_stations)
4395 static void ath11k_mac_dec_num_stations(struct ath11k_vif *arvif,
4396 struct ieee80211_sta *sta)
4398 struct ath11k *ar = arvif->ar;
4400 lockdep_assert_held(&ar->conf_mutex);
4402 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
4408 static int ath11k_mac_station_add(struct ath11k *ar,
4409 struct ieee80211_vif *vif,
4410 struct ieee80211_sta *sta)
4412 struct ath11k_base *ab = ar->ab;
4413 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4414 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
4415 struct peer_create_params peer_param;
4418 lockdep_assert_held(&ar->conf_mutex);
4420 ret = ath11k_mac_inc_num_stations(arvif, sta);
4422 ath11k_warn(ab, "refusing to associate station: too many connected already (%d)\n",
4423 ar->max_num_stations);
4427 arsta->rx_stats = kzalloc(sizeof(*arsta->rx_stats), GFP_KERNEL);
4428 if (!arsta->rx_stats) {
4430 goto dec_num_station;
4433 peer_param.vdev_id = arvif->vdev_id;
4434 peer_param.peer_addr = sta->addr;
4435 peer_param.peer_type = WMI_PEER_TYPE_DEFAULT;
4437 ret = ath11k_peer_create(ar, arvif, sta, &peer_param);
4439 ath11k_warn(ab, "Failed to add peer: %pM for VDEV: %d\n",
4440 sta->addr, arvif->vdev_id);
4444 ath11k_dbg(ab, ATH11K_DBG_MAC, "Added peer: %pM for VDEV: %d\n",
4445 sta->addr, arvif->vdev_id);
4447 if (ath11k_debugfs_is_extd_tx_stats_enabled(ar)) {
4448 arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats), GFP_KERNEL);
4449 if (!arsta->tx_stats) {
4455 if (ieee80211_vif_is_mesh(vif)) {
4456 ath11k_dbg(ab, ATH11K_DBG_MAC,
4457 "setting USE_4ADDR for mesh STA %pM\n", sta->addr);
4458 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
4460 WMI_PEER_USE_4ADDR, 1);
4462 ath11k_warn(ab, "failed to set mesh STA %pM 4addr capability: %d\n",
4468 ret = ath11k_dp_peer_setup(ar, arvif->vdev_id, sta->addr);
4470 ath11k_warn(ab, "failed to setup dp for peer %pM on vdev %i (%d)\n",
4471 sta->addr, arvif->vdev_id, ret);
4475 if (ab->hw_params.vdev_start_delay &&
4476 !arvif->is_started &&
4477 arvif->vdev_type != WMI_VDEV_TYPE_AP) {
4478 ret = ath11k_start_vdev_delay(ar->hw, vif);
4480 ath11k_warn(ab, "failed to delay vdev start: %d\n", ret);
4485 ewma_avg_rssi_init(&arsta->avg_rssi);
4489 kfree(arsta->tx_stats);
4490 arsta->tx_stats = NULL;
4492 ath11k_peer_delete(ar, arvif->vdev_id, sta->addr);
4494 kfree(arsta->rx_stats);
4495 arsta->rx_stats = NULL;
4497 ath11k_mac_dec_num_stations(arvif, sta);
4502 static int ath11k_mac_op_sta_state(struct ieee80211_hw *hw,
4503 struct ieee80211_vif *vif,
4504 struct ieee80211_sta *sta,
4505 enum ieee80211_sta_state old_state,
4506 enum ieee80211_sta_state new_state)
4508 struct ath11k *ar = hw->priv;
4509 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4510 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
4511 struct ath11k_peer *peer;
4514 /* cancel must be done outside the mutex to avoid deadlock */
4515 if ((old_state == IEEE80211_STA_NONE &&
4516 new_state == IEEE80211_STA_NOTEXIST)) {
4517 cancel_work_sync(&arsta->update_wk);
4518 cancel_work_sync(&arsta->set_4addr_wk);
4521 mutex_lock(&ar->conf_mutex);
4523 if (old_state == IEEE80211_STA_NOTEXIST &&
4524 new_state == IEEE80211_STA_NONE) {
4525 memset(arsta, 0, sizeof(*arsta));
4526 arsta->arvif = arvif;
4527 INIT_WORK(&arsta->update_wk, ath11k_sta_rc_update_wk);
4528 INIT_WORK(&arsta->set_4addr_wk, ath11k_sta_set_4addr_wk);
4530 ret = ath11k_mac_station_add(ar, vif, sta);
4532 ath11k_warn(ar->ab, "Failed to add station: %pM for VDEV: %d\n",
4533 sta->addr, arvif->vdev_id);
4534 } else if ((old_state == IEEE80211_STA_NONE &&
4535 new_state == IEEE80211_STA_NOTEXIST)) {
4536 bool skip_peer_delete = ar->ab->hw_params.vdev_start_delay &&
4537 vif->type == NL80211_IFTYPE_STATION;
4539 ath11k_dp_peer_cleanup(ar, arvif->vdev_id, sta->addr);
4541 if (!skip_peer_delete) {
4542 ret = ath11k_peer_delete(ar, arvif->vdev_id, sta->addr);
4545 "Failed to delete peer: %pM for VDEV: %d\n",
4546 sta->addr, arvif->vdev_id);
4550 "Removed peer: %pM for VDEV: %d\n",
4551 sta->addr, arvif->vdev_id);
4554 ath11k_mac_dec_num_stations(arvif, sta);
4555 mutex_lock(&ar->ab->tbl_mtx_lock);
4556 spin_lock_bh(&ar->ab->base_lock);
4557 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
4558 if (skip_peer_delete && peer) {
4560 } else if (peer && peer->sta == sta) {
4561 ath11k_warn(ar->ab, "Found peer entry %pM n vdev %i after it was supposedly removed\n",
4562 vif->addr, arvif->vdev_id);
4563 ath11k_peer_rhash_delete(ar->ab, peer);
4565 list_del(&peer->list);
4569 spin_unlock_bh(&ar->ab->base_lock);
4570 mutex_unlock(&ar->ab->tbl_mtx_lock);
4572 kfree(arsta->tx_stats);
4573 arsta->tx_stats = NULL;
4575 kfree(arsta->rx_stats);
4576 arsta->rx_stats = NULL;
4577 } else if (old_state == IEEE80211_STA_AUTH &&
4578 new_state == IEEE80211_STA_ASSOC &&
4579 (vif->type == NL80211_IFTYPE_AP ||
4580 vif->type == NL80211_IFTYPE_MESH_POINT ||
4581 vif->type == NL80211_IFTYPE_ADHOC)) {
4582 ret = ath11k_station_assoc(ar, vif, sta, false);
4584 ath11k_warn(ar->ab, "Failed to associate station: %pM\n",
4586 } else if (old_state == IEEE80211_STA_ASSOC &&
4587 new_state == IEEE80211_STA_AUTHORIZED) {
4588 spin_lock_bh(&ar->ab->base_lock);
4590 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
4592 peer->is_authorized = true;
4594 spin_unlock_bh(&ar->ab->base_lock);
4596 if (vif->type == NL80211_IFTYPE_STATION && arvif->is_up) {
4597 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
4602 ath11k_warn(ar->ab, "Unable to authorize peer %pM vdev %d: %d\n",
4603 sta->addr, arvif->vdev_id, ret);
4605 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
4606 new_state == IEEE80211_STA_ASSOC) {
4607 spin_lock_bh(&ar->ab->base_lock);
4609 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
4611 peer->is_authorized = false;
4613 spin_unlock_bh(&ar->ab->base_lock);
4614 } else if (old_state == IEEE80211_STA_ASSOC &&
4615 new_state == IEEE80211_STA_AUTH &&
4616 (vif->type == NL80211_IFTYPE_AP ||
4617 vif->type == NL80211_IFTYPE_MESH_POINT ||
4618 vif->type == NL80211_IFTYPE_ADHOC)) {
4619 ret = ath11k_station_disassoc(ar, vif, sta);
4621 ath11k_warn(ar->ab, "Failed to disassociate station: %pM\n",
4625 mutex_unlock(&ar->conf_mutex);
4629 static int ath11k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw,
4630 struct ieee80211_vif *vif,
4631 struct ieee80211_sta *sta)
4633 struct ath11k *ar = hw->priv;
4634 struct ath11k_vif *arvif = (void *)vif->drv_priv;
4638 if (sta->deflink.txpwr.type == NL80211_TX_POWER_AUTOMATIC) {
4641 txpwr = sta->deflink.txpwr.power;
4646 if (txpwr > ATH11K_TX_POWER_MAX_VAL || txpwr < ATH11K_TX_POWER_MIN_VAL)
4649 mutex_lock(&ar->conf_mutex);
4651 ret = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
4652 WMI_PEER_USE_FIXED_PWR, txpwr);
4654 ath11k_warn(ar->ab, "failed to set tx power for station ret: %d\n",
4660 mutex_unlock(&ar->conf_mutex);
4664 static void ath11k_mac_op_sta_set_4addr(struct ieee80211_hw *hw,
4665 struct ieee80211_vif *vif,
4666 struct ieee80211_sta *sta, bool enabled)
4668 struct ath11k *ar = hw->priv;
4669 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
4671 if (enabled && !arsta->use_4addr_set) {
4672 ieee80211_queue_work(ar->hw, &arsta->set_4addr_wk);
4673 arsta->use_4addr_set = true;
4677 static void ath11k_mac_op_sta_rc_update(struct ieee80211_hw *hw,
4678 struct ieee80211_vif *vif,
4679 struct ieee80211_sta *sta,
4682 struct ath11k *ar = hw->priv;
4683 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
4684 struct ath11k_vif *arvif = (void *)vif->drv_priv;
4685 struct ath11k_peer *peer;
4688 spin_lock_bh(&ar->ab->base_lock);
4690 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
4692 spin_unlock_bh(&ar->ab->base_lock);
4693 ath11k_warn(ar->ab, "mac sta rc update failed to find peer %pM on vdev %i\n",
4694 sta->addr, arvif->vdev_id);
4698 spin_unlock_bh(&ar->ab->base_lock);
4700 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
4701 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4702 sta->addr, changed, sta->deflink.bandwidth,
4703 sta->deflink.rx_nss,
4706 spin_lock_bh(&ar->data_lock);
4708 if (changed & IEEE80211_RC_BW_CHANGED) {
4709 bw = WMI_PEER_CHWIDTH_20MHZ;
4711 switch (sta->deflink.bandwidth) {
4712 case IEEE80211_STA_RX_BW_20:
4713 bw = WMI_PEER_CHWIDTH_20MHZ;
4715 case IEEE80211_STA_RX_BW_40:
4716 bw = WMI_PEER_CHWIDTH_40MHZ;
4718 case IEEE80211_STA_RX_BW_80:
4719 bw = WMI_PEER_CHWIDTH_80MHZ;
4721 case IEEE80211_STA_RX_BW_160:
4722 bw = WMI_PEER_CHWIDTH_160MHZ;
4725 ath11k_warn(ar->ab, "Invalid bandwidth %d in rc update for %pM\n",
4726 sta->deflink.bandwidth, sta->addr);
4727 bw = WMI_PEER_CHWIDTH_20MHZ;
4734 if (changed & IEEE80211_RC_NSS_CHANGED)
4735 arsta->nss = sta->deflink.rx_nss;
4737 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4738 smps = WMI_PEER_SMPS_PS_NONE;
4740 switch (sta->smps_mode) {
4741 case IEEE80211_SMPS_AUTOMATIC:
4742 case IEEE80211_SMPS_OFF:
4743 smps = WMI_PEER_SMPS_PS_NONE;
4745 case IEEE80211_SMPS_STATIC:
4746 smps = WMI_PEER_SMPS_STATIC;
4748 case IEEE80211_SMPS_DYNAMIC:
4749 smps = WMI_PEER_SMPS_DYNAMIC;
4752 ath11k_warn(ar->ab, "Invalid smps %d in sta rc update for %pM\n",
4753 sta->smps_mode, sta->addr);
4754 smps = WMI_PEER_SMPS_PS_NONE;
4761 arsta->changed |= changed;
4763 spin_unlock_bh(&ar->data_lock);
4765 ieee80211_queue_work(hw, &arsta->update_wk);
4768 static int ath11k_conf_tx_uapsd(struct ath11k *ar, struct ieee80211_vif *vif,
4769 u16 ac, bool enable)
4771 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4775 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4779 case IEEE80211_AC_VO:
4780 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4781 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
4783 case IEEE80211_AC_VI:
4784 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4785 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
4787 case IEEE80211_AC_BE:
4788 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4789 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
4791 case IEEE80211_AC_BK:
4792 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4793 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
4798 arvif->u.sta.uapsd |= value;
4800 arvif->u.sta.uapsd &= ~value;
4802 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4803 WMI_STA_PS_PARAM_UAPSD,
4804 arvif->u.sta.uapsd);
4806 ath11k_warn(ar->ab, "could not set uapsd params %d\n", ret);
4810 if (arvif->u.sta.uapsd)
4811 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4813 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4815 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4816 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4819 ath11k_warn(ar->ab, "could not set rx wake param %d\n", ret);
4825 static int ath11k_mac_op_conf_tx(struct ieee80211_hw *hw,
4826 struct ieee80211_vif *vif,
4827 unsigned int link_id, u16 ac,
4828 const struct ieee80211_tx_queue_params *params)
4830 struct ath11k *ar = hw->priv;
4831 struct ath11k_vif *arvif = (void *)vif->drv_priv;
4832 struct wmi_wmm_params_arg *p = NULL;
4835 mutex_lock(&ar->conf_mutex);
4838 case IEEE80211_AC_VO:
4839 p = &arvif->wmm_params.ac_vo;
4841 case IEEE80211_AC_VI:
4842 p = &arvif->wmm_params.ac_vi;
4844 case IEEE80211_AC_BE:
4845 p = &arvif->wmm_params.ac_be;
4847 case IEEE80211_AC_BK:
4848 p = &arvif->wmm_params.ac_bk;
4857 p->cwmin = params->cw_min;
4858 p->cwmax = params->cw_max;
4859 p->aifs = params->aifs;
4860 p->txop = params->txop;
4862 ret = ath11k_wmi_send_wmm_update_cmd_tlv(ar, arvif->vdev_id,
4863 &arvif->wmm_params);
4865 ath11k_warn(ar->ab, "failed to set wmm params: %d\n", ret);
4869 ret = ath11k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4872 ath11k_warn(ar->ab, "failed to set sta uapsd: %d\n", ret);
4875 mutex_unlock(&ar->conf_mutex);
4879 static struct ieee80211_sta_ht_cap
4880 ath11k_create_ht_cap(struct ath11k *ar, u32 ar_ht_cap, u32 rate_cap_rx_chainmask)
4883 struct ieee80211_sta_ht_cap ht_cap = {0};
4884 u32 ar_vht_cap = ar->pdev->cap.vht_cap;
4886 if (!(ar_ht_cap & WMI_HT_CAP_ENABLED))
4889 ht_cap.ht_supported = 1;
4890 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4891 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
4892 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4893 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4894 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4896 if (ar_ht_cap & WMI_HT_CAP_HT20_SGI)
4897 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4899 if (ar_ht_cap & WMI_HT_CAP_HT40_SGI)
4900 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4902 if (ar_ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) {
4905 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4906 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4911 if (ar_ht_cap & WMI_HT_CAP_TX_STBC)
4912 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4914 if (ar_ht_cap & WMI_HT_CAP_RX_STBC) {
4918 stbc &= WMI_HT_CAP_RX_STBC;
4919 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4920 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4921 stbc &= IEEE80211_HT_CAP_RX_STBC;
4926 if (ar_ht_cap & WMI_HT_CAP_RX_LDPC)
4927 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4929 if (ar_ht_cap & WMI_HT_CAP_L_SIG_TXOP_PROT)
4930 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4932 if (ar_vht_cap & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4933 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4935 for (i = 0; i < ar->num_rx_chains; i++) {
4936 if (rate_cap_rx_chainmask & BIT(i))
4937 ht_cap.mcs.rx_mask[i] = 0xFF;
4940 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4945 static int ath11k_mac_set_txbf_conf(struct ath11k_vif *arvif)
4948 struct ath11k *ar = arvif->ar;
4951 u32 vht_cap = ar->pdev->cap.vht_cap;
4952 u32 vdev_param = WMI_VDEV_PARAM_TXBF;
4954 if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)) {
4955 nsts = vht_cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4956 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4957 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4960 if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) {
4961 sound_dim = vht_cap &
4962 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4963 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4964 if (sound_dim > (ar->num_tx_chains - 1))
4965 sound_dim = ar->num_tx_chains - 1;
4966 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4972 if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) {
4973 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4975 if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) &&
4976 arvif->vdev_type == WMI_VDEV_TYPE_AP)
4977 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
4980 /* TODO: SUBFEE not validated in HK, disable here until validated? */
4982 if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) {
4983 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4985 if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) &&
4986 arvif->vdev_type == WMI_VDEV_TYPE_STA)
4987 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
4990 return ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4994 static void ath11k_set_vht_txbf_cap(struct ath11k *ar, u32 *vht_cap)
4996 bool subfer, subfee;
4999 subfer = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE));
5000 subfee = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE));
5002 if (ar->num_tx_chains < 2) {
5003 *vht_cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
5007 /* If SU Beaformer is not set, then disable MU Beamformer Capability */
5009 *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE);
5011 /* If SU Beaformee is not set, then disable MU Beamformee Capability */
5013 *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
5015 sound_dim = (*vht_cap & IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK);
5016 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5017 *vht_cap &= ~IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5019 /* TODO: Need to check invalid STS and Sound_dim values set by FW? */
5021 /* Enable Sounding Dimension Field only if SU BF is enabled */
5023 if (sound_dim > (ar->num_tx_chains - 1))
5024 sound_dim = ar->num_tx_chains - 1;
5026 sound_dim <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
5027 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
5028 *vht_cap |= sound_dim;
5031 /* Use the STS advertised by FW unless SU Beamformee is not supported*/
5033 *vht_cap &= ~(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK);
5036 static struct ieee80211_sta_vht_cap
5037 ath11k_create_vht_cap(struct ath11k *ar, u32 rate_cap_tx_chainmask,
5038 u32 rate_cap_rx_chainmask)
5040 struct ieee80211_sta_vht_cap vht_cap = {0};
5041 u16 txmcs_map, rxmcs_map;
5044 vht_cap.vht_supported = 1;
5045 vht_cap.cap = ar->pdev->cap.vht_cap;
5047 if (ar->pdev->cap.nss_ratio_enabled)
5048 vht_cap.vht_mcs.tx_highest |=
5049 cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE);
5051 ath11k_set_vht_txbf_cap(ar, &vht_cap.cap);
5055 for (i = 0; i < 8; i++) {
5056 if (i < ar->num_tx_chains && rate_cap_tx_chainmask & BIT(i))
5057 txmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
5059 txmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
5061 if (i < ar->num_rx_chains && rate_cap_rx_chainmask & BIT(i))
5062 rxmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
5064 rxmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
5067 if (rate_cap_tx_chainmask <= 1)
5068 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
5070 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_map);
5071 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_map);
5076 static void ath11k_mac_setup_ht_vht_cap(struct ath11k *ar,
5077 struct ath11k_pdev_cap *cap,
5080 struct ieee80211_supported_band *band;
5081 u32 rate_cap_tx_chainmask;
5082 u32 rate_cap_rx_chainmask;
5085 rate_cap_tx_chainmask = ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift;
5086 rate_cap_rx_chainmask = ar->cfg_rx_chainmask >> cap->rx_chain_mask_shift;
5088 if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) {
5089 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
5090 ht_cap = cap->band[NL80211_BAND_2GHZ].ht_cap_info;
5092 *ht_cap_info = ht_cap;
5093 band->ht_cap = ath11k_create_ht_cap(ar, ht_cap,
5094 rate_cap_rx_chainmask);
5097 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP &&
5098 (ar->ab->hw_params.single_pdev_only ||
5099 !ar->supports_6ghz)) {
5100 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
5101 ht_cap = cap->band[NL80211_BAND_5GHZ].ht_cap_info;
5103 *ht_cap_info = ht_cap;
5104 band->ht_cap = ath11k_create_ht_cap(ar, ht_cap,
5105 rate_cap_rx_chainmask);
5106 band->vht_cap = ath11k_create_vht_cap(ar, rate_cap_tx_chainmask,
5107 rate_cap_rx_chainmask);
5111 static int ath11k_check_chain_mask(struct ath11k *ar, u32 ant, bool is_tx_ant)
5113 /* TODO: Check the request chainmask against the supported
5114 * chainmask table which is advertised in extented_service_ready event
5120 static void ath11k_gen_ppe_thresh(struct ath11k_ppe_threshold *fw_ppet,
5126 he_ppet[0] = fw_ppet->numss_m1 & IEEE80211_PPE_THRES_NSS_MASK;
5127 he_ppet[0] |= (fw_ppet->ru_bit_mask <<
5128 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS) &
5129 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK;
5130 for (nss = 0; nss <= fw_ppet->numss_m1; nss++) {
5131 for (ru = 0; ru < 4; ru++) {
5135 if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0)
5137 val = (fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> (ru * 6)) &
5139 val = ((val >> 3) & 0x7) | ((val & 0x7) << 3);
5140 for (i = 5; i >= 0; i--) {
5142 ((val >> i) & 0x1) << ((bit % 8));
5150 ath11k_mac_filter_he_cap_mesh(struct ieee80211_he_cap_elem *he_cap_elem)
5154 m = IEEE80211_HE_MAC_CAP0_TWT_RES |
5155 IEEE80211_HE_MAC_CAP0_TWT_REQ;
5156 he_cap_elem->mac_cap_info[0] &= ~m;
5158 m = IEEE80211_HE_MAC_CAP2_TRS |
5159 IEEE80211_HE_MAC_CAP2_BCAST_TWT |
5160 IEEE80211_HE_MAC_CAP2_MU_CASCADING;
5161 he_cap_elem->mac_cap_info[2] &= ~m;
5163 m = IEEE80211_HE_MAC_CAP3_FLEX_TWT_SCHED |
5164 IEEE80211_HE_MAC_CAP2_BCAST_TWT |
5165 IEEE80211_HE_MAC_CAP2_MU_CASCADING;
5166 he_cap_elem->mac_cap_info[3] &= ~m;
5168 m = IEEE80211_HE_MAC_CAP4_BSRP_BQRP_A_MPDU_AGG |
5169 IEEE80211_HE_MAC_CAP4_BQR;
5170 he_cap_elem->mac_cap_info[4] &= ~m;
5172 m = IEEE80211_HE_MAC_CAP5_SUBCHAN_SELECTIVE_TRANSMISSION |
5173 IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU |
5174 IEEE80211_HE_MAC_CAP5_PUNCTURED_SOUNDING |
5175 IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX;
5176 he_cap_elem->mac_cap_info[5] &= ~m;
5178 m = IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
5179 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO;
5180 he_cap_elem->phy_cap_info[2] &= ~m;
5182 m = IEEE80211_HE_PHY_CAP3_RX_PARTIAL_BW_SU_IN_20MHZ_MU |
5183 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK |
5184 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK;
5185 he_cap_elem->phy_cap_info[3] &= ~m;
5187 m = IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
5188 he_cap_elem->phy_cap_info[4] &= ~m;
5190 m = IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK;
5191 he_cap_elem->phy_cap_info[5] &= ~m;
5193 m = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU |
5194 IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB |
5195 IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB |
5196 IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO;
5197 he_cap_elem->phy_cap_info[6] &= ~m;
5199 m = IEEE80211_HE_PHY_CAP7_PSR_BASED_SR |
5200 IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP |
5201 IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ |
5202 IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ;
5203 he_cap_elem->phy_cap_info[7] &= ~m;
5205 m = IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI |
5206 IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
5207 IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
5208 IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU;
5209 he_cap_elem->phy_cap_info[8] &= ~m;
5211 m = IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM |
5212 IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK |
5213 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU |
5214 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
5215 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
5216 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB;
5217 he_cap_elem->phy_cap_info[9] &= ~m;
5220 static __le16 ath11k_mac_setup_he_6ghz_cap(struct ath11k_pdev_cap *pcap,
5221 struct ath11k_band_cap *bcap)
5225 bcap->he_6ghz_capa = IEEE80211_HT_MPDU_DENSITY_NONE;
5226 if (bcap->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
5227 bcap->he_6ghz_capa |=
5228 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_SM_PS,
5229 WLAN_HT_CAP_SM_PS_DYNAMIC);
5231 bcap->he_6ghz_capa |=
5232 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_SM_PS,
5233 WLAN_HT_CAP_SM_PS_DISABLED);
5234 val = FIELD_GET(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK,
5236 bcap->he_6ghz_capa |=
5237 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP, val);
5238 val = FIELD_GET(IEEE80211_VHT_CAP_MAX_MPDU_MASK, pcap->vht_cap);
5239 bcap->he_6ghz_capa |=
5240 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN, val);
5241 if (pcap->vht_cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN)
5242 bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS;
5243 if (pcap->vht_cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN)
5244 bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS;
5246 return cpu_to_le16(bcap->he_6ghz_capa);
5249 static int ath11k_mac_copy_he_cap(struct ath11k *ar,
5250 struct ath11k_pdev_cap *cap,
5251 struct ieee80211_sband_iftype_data *data,
5256 for (i = 0; i < NUM_NL80211_IFTYPES; i++) {
5257 struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap;
5258 struct ath11k_band_cap *band_cap = &cap->band[band];
5259 struct ieee80211_he_cap_elem *he_cap_elem =
5260 &he_cap->he_cap_elem;
5263 case NL80211_IFTYPE_STATION:
5264 case NL80211_IFTYPE_AP:
5265 case NL80211_IFTYPE_MESH_POINT:
5272 data[idx].types_mask = BIT(i);
5273 he_cap->has_he = true;
5274 memcpy(he_cap_elem->mac_cap_info, band_cap->he_cap_info,
5275 sizeof(he_cap_elem->mac_cap_info));
5276 memcpy(he_cap_elem->phy_cap_info, band_cap->he_cap_phy_info,
5277 sizeof(he_cap_elem->phy_cap_info));
5279 he_cap_elem->mac_cap_info[1] &=
5280 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_MASK;
5282 he_cap_elem->phy_cap_info[5] &=
5283 ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK;
5284 he_cap_elem->phy_cap_info[5] |= ar->num_tx_chains - 1;
5287 case NL80211_IFTYPE_AP:
5288 he_cap_elem->phy_cap_info[3] &=
5289 ~IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK;
5290 he_cap_elem->phy_cap_info[9] |=
5291 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU;
5293 case NL80211_IFTYPE_STATION:
5294 he_cap_elem->mac_cap_info[0] &=
5295 ~IEEE80211_HE_MAC_CAP0_TWT_RES;
5296 he_cap_elem->mac_cap_info[0] |=
5297 IEEE80211_HE_MAC_CAP0_TWT_REQ;
5298 he_cap_elem->phy_cap_info[9] |=
5299 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU;
5301 case NL80211_IFTYPE_MESH_POINT:
5302 ath11k_mac_filter_he_cap_mesh(he_cap_elem);
5306 he_cap->he_mcs_nss_supp.rx_mcs_80 =
5307 cpu_to_le16(band_cap->he_mcs & 0xffff);
5308 he_cap->he_mcs_nss_supp.tx_mcs_80 =
5309 cpu_to_le16(band_cap->he_mcs & 0xffff);
5310 he_cap->he_mcs_nss_supp.rx_mcs_160 =
5311 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
5312 he_cap->he_mcs_nss_supp.tx_mcs_160 =
5313 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
5314 he_cap->he_mcs_nss_supp.rx_mcs_80p80 =
5315 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
5316 he_cap->he_mcs_nss_supp.tx_mcs_80p80 =
5317 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
5319 memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
5320 if (he_cap_elem->phy_cap_info[6] &
5321 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
5322 ath11k_gen_ppe_thresh(&band_cap->he_ppet,
5325 if (band == NL80211_BAND_6GHZ) {
5326 data[idx].he_6ghz_capa.capa =
5327 ath11k_mac_setup_he_6ghz_cap(cap, band_cap);
5335 static void ath11k_mac_setup_he_cap(struct ath11k *ar,
5336 struct ath11k_pdev_cap *cap)
5338 struct ieee80211_supported_band *band;
5341 if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) {
5342 count = ath11k_mac_copy_he_cap(ar, cap,
5343 ar->mac.iftype[NL80211_BAND_2GHZ],
5345 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
5346 band->iftype_data = ar->mac.iftype[NL80211_BAND_2GHZ];
5347 band->n_iftype_data = count;
5350 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP) {
5351 count = ath11k_mac_copy_he_cap(ar, cap,
5352 ar->mac.iftype[NL80211_BAND_5GHZ],
5354 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
5355 band->iftype_data = ar->mac.iftype[NL80211_BAND_5GHZ];
5356 band->n_iftype_data = count;
5359 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP &&
5360 ar->supports_6ghz) {
5361 count = ath11k_mac_copy_he_cap(ar, cap,
5362 ar->mac.iftype[NL80211_BAND_6GHZ],
5364 band = &ar->mac.sbands[NL80211_BAND_6GHZ];
5365 band->iftype_data = ar->mac.iftype[NL80211_BAND_6GHZ];
5366 band->n_iftype_data = count;
5370 static int __ath11k_set_antenna(struct ath11k *ar, u32 tx_ant, u32 rx_ant)
5374 lockdep_assert_held(&ar->conf_mutex);
5376 if (ath11k_check_chain_mask(ar, tx_ant, true))
5379 if (ath11k_check_chain_mask(ar, rx_ant, false))
5382 ar->cfg_tx_chainmask = tx_ant;
5383 ar->cfg_rx_chainmask = rx_ant;
5385 if (ar->state != ATH11K_STATE_ON &&
5386 ar->state != ATH11K_STATE_RESTARTED)
5389 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_TX_CHAIN_MASK,
5390 tx_ant, ar->pdev->pdev_id);
5392 ath11k_warn(ar->ab, "failed to set tx-chainmask: %d, req 0x%x\n",
5397 ar->num_tx_chains = get_num_chains(tx_ant);
5399 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RX_CHAIN_MASK,
5400 rx_ant, ar->pdev->pdev_id);
5402 ath11k_warn(ar->ab, "failed to set rx-chainmask: %d, req 0x%x\n",
5407 ar->num_rx_chains = get_num_chains(rx_ant);
5409 /* Reload HT/VHT/HE capability */
5410 ath11k_mac_setup_ht_vht_cap(ar, &ar->pdev->cap, NULL);
5411 ath11k_mac_setup_he_cap(ar, &ar->pdev->cap);
5416 static void ath11k_mgmt_over_wmi_tx_drop(struct ath11k *ar, struct sk_buff *skb)
5420 ieee80211_free_txskb(ar->hw, skb);
5422 num_mgmt = atomic_dec_if_positive(&ar->num_pending_mgmt_tx);
5428 wake_up(&ar->txmgmt_empty_waitq);
5431 static void ath11k_mac_tx_mgmt_free(struct ath11k *ar, int buf_id)
5433 struct sk_buff *msdu;
5434 struct ieee80211_tx_info *info;
5436 spin_lock_bh(&ar->txmgmt_idr_lock);
5437 msdu = idr_remove(&ar->txmgmt_idr, buf_id);
5438 spin_unlock_bh(&ar->txmgmt_idr_lock);
5443 dma_unmap_single(ar->ab->dev, ATH11K_SKB_CB(msdu)->paddr, msdu->len,
5446 info = IEEE80211_SKB_CB(msdu);
5447 memset(&info->status, 0, sizeof(info->status));
5449 ath11k_mgmt_over_wmi_tx_drop(ar, msdu);
5452 int ath11k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx)
5454 struct ath11k *ar = ctx;
5456 ath11k_mac_tx_mgmt_free(ar, buf_id);
5461 static int ath11k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx)
5463 struct ieee80211_vif *vif = ctx;
5464 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb);
5465 struct ath11k *ar = skb_cb->ar;
5467 if (skb_cb->vif == vif)
5468 ath11k_mac_tx_mgmt_free(ar, buf_id);
5473 static int ath11k_mac_mgmt_tx_wmi(struct ath11k *ar, struct ath11k_vif *arvif,
5474 struct sk_buff *skb)
5476 struct ath11k_base *ab = ar->ab;
5477 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
5478 struct ieee80211_tx_info *info;
5483 ATH11K_SKB_CB(skb)->ar = ar;
5485 spin_lock_bh(&ar->txmgmt_idr_lock);
5486 buf_id = idr_alloc(&ar->txmgmt_idr, skb, 0,
5487 ATH11K_TX_MGMT_NUM_PENDING_MAX, GFP_ATOMIC);
5488 spin_unlock_bh(&ar->txmgmt_idr_lock);
5490 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
5491 "mac tx mgmt frame, buf id %d\n", buf_id);
5496 info = IEEE80211_SKB_CB(skb);
5497 if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) {
5498 if ((ieee80211_is_action(hdr->frame_control) ||
5499 ieee80211_is_deauth(hdr->frame_control) ||
5500 ieee80211_is_disassoc(hdr->frame_control)) &&
5501 ieee80211_has_protected(hdr->frame_control)) {
5502 skb_put(skb, IEEE80211_CCMP_MIC_LEN);
5506 paddr = dma_map_single(ab->dev, skb->data, skb->len, DMA_TO_DEVICE);
5507 if (dma_mapping_error(ab->dev, paddr)) {
5508 ath11k_warn(ab, "failed to DMA map mgmt Tx buffer\n");
5513 ATH11K_SKB_CB(skb)->paddr = paddr;
5515 ret = ath11k_wmi_mgmt_send(ar, arvif->vdev_id, buf_id, skb);
5517 ath11k_warn(ar->ab, "failed to send mgmt frame: %d\n", ret);
5524 dma_unmap_single(ab->dev, ATH11K_SKB_CB(skb)->paddr,
5525 skb->len, DMA_TO_DEVICE);
5527 spin_lock_bh(&ar->txmgmt_idr_lock);
5528 idr_remove(&ar->txmgmt_idr, buf_id);
5529 spin_unlock_bh(&ar->txmgmt_idr_lock);
5534 static void ath11k_mgmt_over_wmi_tx_purge(struct ath11k *ar)
5536 struct sk_buff *skb;
5538 while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL)
5539 ath11k_mgmt_over_wmi_tx_drop(ar, skb);
5542 static void ath11k_mgmt_over_wmi_tx_work(struct work_struct *work)
5544 struct ath11k *ar = container_of(work, struct ath11k, wmi_mgmt_tx_work);
5545 struct ath11k_skb_cb *skb_cb;
5546 struct ath11k_vif *arvif;
5547 struct sk_buff *skb;
5550 while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) {
5551 skb_cb = ATH11K_SKB_CB(skb);
5553 ath11k_warn(ar->ab, "no vif found for mgmt frame\n");
5554 ath11k_mgmt_over_wmi_tx_drop(ar, skb);
5558 arvif = ath11k_vif_to_arvif(skb_cb->vif);
5559 mutex_lock(&ar->conf_mutex);
5560 if (ar->allocated_vdev_map & (1LL << arvif->vdev_id)) {
5561 ret = ath11k_mac_mgmt_tx_wmi(ar, arvif, skb);
5563 ath11k_warn(ar->ab, "failed to tx mgmt frame, vdev_id %d :%d\n",
5564 arvif->vdev_id, ret);
5565 ath11k_mgmt_over_wmi_tx_drop(ar, skb);
5567 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
5568 "mac tx mgmt frame, vdev_id %d\n",
5573 "dropping mgmt frame for vdev %d, is_started %d\n",
5576 ath11k_mgmt_over_wmi_tx_drop(ar, skb);
5578 mutex_unlock(&ar->conf_mutex);
5582 static int ath11k_mac_mgmt_tx(struct ath11k *ar, struct sk_buff *skb,
5585 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
5587 if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))
5590 /* Drop probe response packets when the pending management tx
5591 * count has reached a certain threshold, so as to prioritize
5592 * other mgmt packets like auth and assoc to be sent on time
5593 * for establishing successful connections.
5596 atomic_read(&ar->num_pending_mgmt_tx) > ATH11K_PRB_RSP_DROP_THRESHOLD) {
5598 "dropping probe response as pending queue is almost full\n");
5602 if (skb_queue_len_lockless(q) >= ATH11K_TX_MGMT_NUM_PENDING_MAX) {
5603 ath11k_warn(ar->ab, "mgmt tx queue is full\n");
5607 skb_queue_tail(q, skb);
5608 atomic_inc(&ar->num_pending_mgmt_tx);
5609 queue_work(ar->ab->workqueue_aux, &ar->wmi_mgmt_tx_work);
5614 static void ath11k_mac_op_tx(struct ieee80211_hw *hw,
5615 struct ieee80211_tx_control *control,
5616 struct sk_buff *skb)
5618 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb);
5619 struct ath11k *ar = hw->priv;
5620 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
5621 struct ieee80211_vif *vif = info->control.vif;
5622 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
5623 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
5624 struct ieee80211_key_conf *key = info->control.hw_key;
5625 struct ath11k_sta *arsta = NULL;
5626 u32 info_flags = info->flags;
5630 memset(skb_cb, 0, sizeof(*skb_cb));
5634 skb_cb->cipher = key->cipher;
5635 skb_cb->flags |= ATH11K_SKB_CIPHER_SET;
5638 if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
5639 skb_cb->flags |= ATH11K_SKB_HW_80211_ENCAP;
5640 } else if (ieee80211_is_mgmt(hdr->frame_control)) {
5641 is_prb_rsp = ieee80211_is_probe_resp(hdr->frame_control);
5642 ret = ath11k_mac_mgmt_tx(ar, skb, is_prb_rsp);
5644 ath11k_warn(ar->ab, "failed to queue management frame %d\n",
5646 ieee80211_free_txskb(ar->hw, skb);
5652 arsta = (struct ath11k_sta *)control->sta->drv_priv;
5654 ret = ath11k_dp_tx(ar, arvif, arsta, skb);
5655 if (unlikely(ret)) {
5656 ath11k_warn(ar->ab, "failed to transmit frame %d\n", ret);
5657 ieee80211_free_txskb(ar->hw, skb);
5661 void ath11k_mac_drain_tx(struct ath11k *ar)
5663 /* make sure rcu-protected mac80211 tx path itself is drained */
5666 cancel_work_sync(&ar->wmi_mgmt_tx_work);
5667 ath11k_mgmt_over_wmi_tx_purge(ar);
5670 static int ath11k_mac_config_mon_status_default(struct ath11k *ar, bool enable)
5672 struct htt_rx_ring_tlv_filter tlv_filter = {0};
5673 struct ath11k_base *ab = ar->ab;
5678 tlv_filter = ath11k_mac_mon_status_filter_default;
5679 if (ath11k_debugfs_rx_filter(ar))
5680 tlv_filter.rx_filter = ath11k_debugfs_rx_filter(ar);
5683 for (i = 0; i < ab->hw_params.num_rxmda_per_pdev; i++) {
5684 ring_id = ar->dp.rx_mon_status_refill_ring[i].refill_buf_ring.ring_id;
5685 ret = ath11k_dp_tx_htt_rx_filter_setup(ar->ab, ring_id,
5687 HAL_RXDMA_MONITOR_STATUS,
5692 if (enable && !ar->ab->hw_params.rxdma1_enable)
5693 mod_timer(&ar->ab->mon_reap_timer, jiffies +
5694 msecs_to_jiffies(ATH11K_MON_TIMER_INTERVAL));
5699 static void ath11k_mac_wait_reconfigure(struct ath11k_base *ab)
5701 int recovery_start_count;
5706 recovery_start_count = atomic_inc_return(&ab->recovery_start_count);
5707 ath11k_dbg(ab, ATH11K_DBG_MAC, "recovery start count %d\n", recovery_start_count);
5709 if (recovery_start_count == ab->num_radios) {
5710 complete(&ab->recovery_start);
5711 ath11k_dbg(ab, ATH11K_DBG_MAC, "recovery started success\n");
5714 ath11k_dbg(ab, ATH11K_DBG_MAC, "waiting reconfigure...\n");
5716 wait_for_completion_timeout(&ab->reconfigure_complete,
5717 ATH11K_RECONFIGURE_TIMEOUT_HZ);
5720 static int ath11k_mac_op_start(struct ieee80211_hw *hw)
5722 struct ath11k *ar = hw->priv;
5723 struct ath11k_base *ab = ar->ab;
5724 struct ath11k_pdev *pdev = ar->pdev;
5727 ath11k_mac_drain_tx(ar);
5728 mutex_lock(&ar->conf_mutex);
5730 switch (ar->state) {
5731 case ATH11K_STATE_OFF:
5732 ar->state = ATH11K_STATE_ON;
5734 case ATH11K_STATE_RESTARTING:
5735 ar->state = ATH11K_STATE_RESTARTED;
5736 ath11k_mac_wait_reconfigure(ab);
5738 case ATH11K_STATE_RESTARTED:
5739 case ATH11K_STATE_WEDGED:
5740 case ATH11K_STATE_ON:
5746 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS,
5750 ath11k_err(ar->ab, "failed to enable PMF QOS: (%d\n", ret);
5754 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 1,
5757 ath11k_err(ar->ab, "failed to enable dynamic bw: %d\n", ret);
5761 if (test_bit(WMI_TLV_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi->wmi_ab->svc_map)) {
5762 ret = ath11k_wmi_scan_prob_req_oui(ar, ar->mac_addr);
5764 ath11k_err(ab, "failed to set prob req oui: %i\n", ret);
5769 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
5772 ath11k_err(ab, "failed to set ac override for ARP: %d\n",
5777 ret = ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(ar, pdev->pdev_id);
5779 ath11k_err(ab, "failed to offload radar detection: %d\n",
5784 ret = ath11k_dp_tx_htt_h2t_ppdu_stats_req(ar,
5785 HTT_PPDU_STATS_TAG_DEFAULT);
5787 ath11k_err(ab, "failed to req ppdu stats: %d\n", ret);
5791 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_MESH_MCAST_ENABLE,
5795 ath11k_err(ar->ab, "failed to enable MESH MCAST ENABLE: (%d\n", ret);
5799 __ath11k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
5801 /* TODO: Do we need to enable ANI? */
5803 ath11k_reg_update_chan_list(ar, false);
5805 ar->num_started_vdevs = 0;
5806 ar->num_created_vdevs = 0;
5808 ar->allocated_vdev_map = 0;
5810 /* Configure monitor status ring with default rx_filter to get rx status
5811 * such as rssi, rx_duration.
5813 ret = ath11k_mac_config_mon_status_default(ar, true);
5815 ath11k_err(ab, "failed to configure monitor status ring with default rx_filter: (%d)\n",
5820 /* Configure the hash seed for hash based reo dest ring selection */
5821 ath11k_wmi_pdev_lro_cfg(ar, ar->pdev->pdev_id);
5823 /* allow device to enter IMPS */
5824 if (ab->hw_params.idle_ps) {
5825 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_IDLE_PS_CONFIG,
5828 ath11k_err(ab, "failed to enable idle ps: %d\n", ret);
5833 mutex_unlock(&ar->conf_mutex);
5835 rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx],
5836 &ab->pdevs[ar->pdev_idx]);
5841 ar->state = ATH11K_STATE_OFF;
5842 mutex_unlock(&ar->conf_mutex);
5847 static void ath11k_mac_op_stop(struct ieee80211_hw *hw)
5849 struct ath11k *ar = hw->priv;
5850 struct htt_ppdu_stats_info *ppdu_stats, *tmp;
5853 ath11k_mac_drain_tx(ar);
5855 mutex_lock(&ar->conf_mutex);
5856 ret = ath11k_mac_config_mon_status_default(ar, false);
5858 ath11k_err(ar->ab, "failed to clear rx_filter for monitor status ring: (%d)\n",
5861 clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
5862 ar->state = ATH11K_STATE_OFF;
5863 mutex_unlock(&ar->conf_mutex);
5865 cancel_delayed_work_sync(&ar->scan.timeout);
5866 cancel_work_sync(&ar->regd_update_work);
5867 cancel_work_sync(&ar->ab->update_11d_work);
5869 if (ar->state_11d == ATH11K_11D_PREPARING) {
5870 ar->state_11d = ATH11K_11D_IDLE;
5871 complete(&ar->completed_11d_scan);
5874 spin_lock_bh(&ar->data_lock);
5875 list_for_each_entry_safe(ppdu_stats, tmp, &ar->ppdu_stats_info, list) {
5876 list_del(&ppdu_stats->list);
5879 spin_unlock_bh(&ar->data_lock);
5881 rcu_assign_pointer(ar->ab->pdevs_active[ar->pdev_idx], NULL);
5885 atomic_set(&ar->num_pending_mgmt_tx, 0);
5889 ath11k_mac_setup_vdev_create_params(struct ath11k_vif *arvif,
5890 struct vdev_create_params *params)
5892 struct ath11k *ar = arvif->ar;
5893 struct ath11k_pdev *pdev = ar->pdev;
5895 params->if_id = arvif->vdev_id;
5896 params->type = arvif->vdev_type;
5897 params->subtype = arvif->vdev_subtype;
5898 params->pdev_id = pdev->pdev_id;
5900 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) {
5901 params->chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains;
5902 params->chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains;
5904 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) {
5905 params->chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains;
5906 params->chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains;
5908 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP &&
5909 ar->supports_6ghz) {
5910 params->chains[NL80211_BAND_6GHZ].tx = ar->num_tx_chains;
5911 params->chains[NL80211_BAND_6GHZ].rx = ar->num_rx_chains;
5916 ath11k_mac_prepare_he_mode(struct ath11k_pdev *pdev, u32 viftype)
5918 struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
5919 struct ath11k_band_cap *cap_band = NULL;
5920 u32 *hecap_phy_ptr = NULL;
5923 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP)
5924 cap_band = &pdev_cap->band[NL80211_BAND_2GHZ];
5926 cap_band = &pdev_cap->band[NL80211_BAND_5GHZ];
5928 hecap_phy_ptr = &cap_band->he_cap_phy_info[0];
5930 hemode = FIELD_PREP(HE_MODE_SU_TX_BFEE, HE_SU_BFEE_ENABLE) |
5931 FIELD_PREP(HE_MODE_SU_TX_BFER, HECAP_PHY_SUBFMR_GET(hecap_phy_ptr)) |
5932 FIELD_PREP(HE_MODE_UL_MUMIMO, HECAP_PHY_ULMUMIMO_GET(hecap_phy_ptr));
5934 /* TODO WDS and other modes */
5935 if (viftype == NL80211_IFTYPE_AP) {
5936 hemode |= FIELD_PREP(HE_MODE_MU_TX_BFER,
5937 HECAP_PHY_MUBFMR_GET(hecap_phy_ptr)) |
5938 FIELD_PREP(HE_MODE_DL_OFDMA, HE_DL_MUOFDMA_ENABLE) |
5939 FIELD_PREP(HE_MODE_UL_OFDMA, HE_UL_MUOFDMA_ENABLE);
5941 hemode |= FIELD_PREP(HE_MODE_MU_TX_BFEE, HE_MU_BFEE_ENABLE);
5947 static int ath11k_set_he_mu_sounding_mode(struct ath11k *ar,
5948 struct ath11k_vif *arvif)
5950 u32 param_id, param_value;
5951 struct ath11k_base *ab = ar->ab;
5954 param_id = WMI_VDEV_PARAM_SET_HEMU_MODE;
5955 param_value = ath11k_mac_prepare_he_mode(ar->pdev, arvif->vif->type);
5956 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5957 param_id, param_value);
5959 ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d param_value %x\n",
5960 arvif->vdev_id, ret, param_value);
5963 param_id = WMI_VDEV_PARAM_SET_HE_SOUNDING_MODE;
5965 FIELD_PREP(HE_VHT_SOUNDING_MODE, HE_VHT_SOUNDING_MODE_ENABLE) |
5966 FIELD_PREP(HE_TRIG_NONTRIG_SOUNDING_MODE,
5967 HE_TRIG_NONTRIG_SOUNDING_MODE_ENABLE);
5968 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5969 param_id, param_value);
5971 ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d\n",
5972 arvif->vdev_id, ret);
5978 static void ath11k_mac_op_update_vif_offload(struct ieee80211_hw *hw,
5979 struct ieee80211_vif *vif)
5981 struct ath11k *ar = hw->priv;
5982 struct ath11k_base *ab = ar->ab;
5983 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
5984 u32 param_id, param_value;
5987 param_id = WMI_VDEV_PARAM_TX_ENCAP_TYPE;
5988 if (ath11k_frame_mode != ATH11K_HW_TXRX_ETHERNET ||
5989 (vif->type != NL80211_IFTYPE_STATION &&
5990 vif->type != NL80211_IFTYPE_AP))
5991 vif->offload_flags &= ~(IEEE80211_OFFLOAD_ENCAP_ENABLED |
5992 IEEE80211_OFFLOAD_DECAP_ENABLED);
5994 if (vif->offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED)
5995 param_value = ATH11K_HW_TXRX_ETHERNET;
5996 else if (test_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags))
5997 param_value = ATH11K_HW_TXRX_RAW;
5999 param_value = ATH11K_HW_TXRX_NATIVE_WIFI;
6001 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
6002 param_id, param_value);
6004 ath11k_warn(ab, "failed to set vdev %d tx encap mode: %d\n",
6005 arvif->vdev_id, ret);
6006 vif->offload_flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
6009 param_id = WMI_VDEV_PARAM_RX_DECAP_TYPE;
6010 if (vif->offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED)
6011 param_value = ATH11K_HW_TXRX_ETHERNET;
6012 else if (test_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags))
6013 param_value = ATH11K_HW_TXRX_RAW;
6015 param_value = ATH11K_HW_TXRX_NATIVE_WIFI;
6017 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
6018 param_id, param_value);
6020 ath11k_warn(ab, "failed to set vdev %d rx decap mode: %d\n",
6021 arvif->vdev_id, ret);
6022 vif->offload_flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED;
6026 static bool ath11k_mac_vif_ap_active_any(struct ath11k_base *ab)
6029 struct ath11k_pdev *pdev;
6030 struct ath11k_vif *arvif;
6033 for (i = 0; i < ab->num_radios; i++) {
6034 pdev = &ab->pdevs[i];
6036 list_for_each_entry(arvif, &ar->arvifs, list) {
6037 if (arvif->is_up && arvif->vdev_type == WMI_VDEV_TYPE_AP)
6044 void ath11k_mac_11d_scan_start(struct ath11k *ar, u32 vdev_id)
6046 struct wmi_11d_scan_start_params param;
6049 mutex_lock(&ar->ab->vdev_id_11d_lock);
6051 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev id for 11d scan %d\n",
6052 ar->vdev_id_11d_scan);
6054 if (ar->regdom_set_by_user)
6057 if (ar->vdev_id_11d_scan != ATH11K_11D_INVALID_VDEV_ID)
6060 if (!test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map))
6063 if (ath11k_mac_vif_ap_active_any(ar->ab))
6066 param.vdev_id = vdev_id;
6067 param.start_interval_msec = 0;
6068 param.scan_period_msec = ATH11K_SCAN_11D_INTERVAL;
6070 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac start 11d scan\n");
6072 ret = ath11k_wmi_send_11d_scan_start_cmd(ar, ¶m);
6074 ath11k_warn(ar->ab, "failed to start 11d scan vdev %d ret: %d\n",
6077 ar->vdev_id_11d_scan = vdev_id;
6078 if (ar->state_11d == ATH11K_11D_PREPARING)
6079 ar->state_11d = ATH11K_11D_RUNNING;
6083 if (ar->state_11d == ATH11K_11D_PREPARING) {
6084 ar->state_11d = ATH11K_11D_IDLE;
6085 complete(&ar->completed_11d_scan);
6088 mutex_unlock(&ar->ab->vdev_id_11d_lock);
6091 void ath11k_mac_11d_scan_stop(struct ath11k *ar)
6096 if (!test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map))
6099 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac stop 11d scan\n");
6101 mutex_lock(&ar->ab->vdev_id_11d_lock);
6103 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac stop 11d vdev id %d\n",
6104 ar->vdev_id_11d_scan);
6106 if (ar->state_11d == ATH11K_11D_PREPARING) {
6107 ar->state_11d = ATH11K_11D_IDLE;
6108 complete(&ar->completed_11d_scan);
6111 if (ar->vdev_id_11d_scan != ATH11K_11D_INVALID_VDEV_ID) {
6112 vdev_id = ar->vdev_id_11d_scan;
6114 ret = ath11k_wmi_send_11d_scan_stop_cmd(ar, vdev_id);
6117 "failed to stopt 11d scan vdev %d ret: %d\n",
6120 ar->vdev_id_11d_scan = ATH11K_11D_INVALID_VDEV_ID;
6121 ar->state_11d = ATH11K_11D_IDLE;
6122 complete(&ar->completed_11d_scan);
6125 mutex_unlock(&ar->ab->vdev_id_11d_lock);
6128 void ath11k_mac_11d_scan_stop_all(struct ath11k_base *ab)
6131 struct ath11k_pdev *pdev;
6134 ath11k_dbg(ab, ATH11K_DBG_MAC, "mac stop soc 11d scan\n");
6136 for (i = 0; i < ab->num_radios; i++) {
6137 pdev = &ab->pdevs[i];
6140 ath11k_mac_11d_scan_stop(ar);
6144 static int ath11k_mac_op_add_interface(struct ieee80211_hw *hw,
6145 struct ieee80211_vif *vif)
6147 struct ath11k *ar = hw->priv;
6148 struct ath11k_base *ab = ar->ab;
6149 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
6150 struct vdev_create_params vdev_param = {0};
6151 struct peer_create_params peer_param;
6152 u32 param_id, param_value;
6158 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
6160 mutex_lock(&ar->conf_mutex);
6162 if (vif->type == NL80211_IFTYPE_AP &&
6163 ar->num_peers > (ar->max_num_peers - 1)) {
6164 ath11k_warn(ab, "failed to create vdev due to insufficient peer entry resource in firmware\n");
6169 if (ar->num_created_vdevs > (TARGET_NUM_VDEVS(ab) - 1)) {
6170 ath11k_warn(ab, "failed to create vdev %u, reached max vdev limit %d\n",
6171 ar->num_created_vdevs, TARGET_NUM_VDEVS(ab));
6176 memset(arvif, 0, sizeof(*arvif));
6181 INIT_LIST_HEAD(&arvif->list);
6182 INIT_DELAYED_WORK(&arvif->connection_loss_work,
6183 ath11k_mac_vif_sta_connection_loss_work);
6185 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
6186 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
6187 arvif->bitrate_mask.control[i].gi = NL80211_TXRATE_FORCE_SGI;
6188 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
6189 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
6190 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
6191 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
6192 memset(arvif->bitrate_mask.control[i].he_mcs, 0xff,
6193 sizeof(arvif->bitrate_mask.control[i].he_mcs));
6196 bit = __ffs64(ab->free_vdev_map);
6198 arvif->vdev_id = bit;
6199 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
6201 switch (vif->type) {
6202 case NL80211_IFTYPE_UNSPECIFIED:
6203 case NL80211_IFTYPE_STATION:
6204 arvif->vdev_type = WMI_VDEV_TYPE_STA;
6206 case NL80211_IFTYPE_MESH_POINT:
6207 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_MESH_11S;
6209 case NL80211_IFTYPE_AP:
6210 arvif->vdev_type = WMI_VDEV_TYPE_AP;
6212 case NL80211_IFTYPE_MONITOR:
6213 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
6214 ar->monitor_vdev_id = bit;
6221 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac add interface id %d type %d subtype %d map %llx\n",
6222 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
6225 vif->cab_queue = arvif->vdev_id % (ATH11K_HW_MAX_QUEUES - 1);
6226 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
6227 vif->hw_queue[i] = i % (ATH11K_HW_MAX_QUEUES - 1);
6229 ath11k_mac_setup_vdev_create_params(arvif, &vdev_param);
6231 ret = ath11k_wmi_vdev_create(ar, vif->addr, &vdev_param);
6233 ath11k_warn(ab, "failed to create WMI vdev %d: %d\n",
6234 arvif->vdev_id, ret);
6238 ar->num_created_vdevs++;
6239 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM created, vdev_id %d\n",
6240 vif->addr, arvif->vdev_id);
6241 ar->allocated_vdev_map |= 1LL << arvif->vdev_id;
6242 ab->free_vdev_map &= ~(1LL << arvif->vdev_id);
6244 spin_lock_bh(&ar->data_lock);
6245 list_add(&arvif->list, &ar->arvifs);
6246 spin_unlock_bh(&ar->data_lock);
6248 ath11k_mac_op_update_vif_offload(hw, vif);
6250 nss = get_num_chains(ar->cfg_tx_chainmask) ? : 1;
6251 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
6252 WMI_VDEV_PARAM_NSS, nss);
6254 ath11k_warn(ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n",
6255 arvif->vdev_id, ar->cfg_tx_chainmask, nss, ret);
6259 switch (arvif->vdev_type) {
6260 case WMI_VDEV_TYPE_AP:
6261 peer_param.vdev_id = arvif->vdev_id;
6262 peer_param.peer_addr = vif->addr;
6263 peer_param.peer_type = WMI_PEER_TYPE_DEFAULT;
6264 ret = ath11k_peer_create(ar, arvif, NULL, &peer_param);
6266 ath11k_warn(ab, "failed to vdev %d create peer for AP: %d\n",
6267 arvif->vdev_id, ret);
6271 ret = ath11k_mac_set_kickout(arvif);
6273 ath11k_warn(ar->ab, "failed to set vdev %i kickout parameters: %d\n",
6274 arvif->vdev_id, ret);
6278 ath11k_mac_11d_scan_stop_all(ar->ab);
6280 case WMI_VDEV_TYPE_STA:
6281 param_id = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
6282 param_value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6283 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6284 param_id, param_value);
6286 ath11k_warn(ar->ab, "failed to set vdev %d RX wake policy: %d\n",
6287 arvif->vdev_id, ret);
6291 param_id = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
6292 param_value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
6293 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6294 param_id, param_value);
6296 ath11k_warn(ar->ab, "failed to set vdev %d TX wake threshold: %d\n",
6297 arvif->vdev_id, ret);
6301 param_id = WMI_STA_PS_PARAM_PSPOLL_COUNT;
6302 param_value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
6303 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6304 param_id, param_value);
6306 ath11k_warn(ar->ab, "failed to set vdev %d pspoll count: %d\n",
6307 arvif->vdev_id, ret);
6311 ret = ath11k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id,
6312 WMI_STA_PS_MODE_DISABLED);
6314 ath11k_warn(ar->ab, "failed to disable vdev %d ps mode: %d\n",
6315 arvif->vdev_id, ret);
6319 if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ab->wmi_ab.svc_map)) {
6320 reinit_completion(&ar->completed_11d_scan);
6321 ar->state_11d = ATH11K_11D_PREPARING;
6324 case WMI_VDEV_TYPE_MONITOR:
6325 set_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags);
6331 arvif->txpower = vif->bss_conf.txpower;
6332 ret = ath11k_mac_txpower_recalc(ar);
6336 param_id = WMI_VDEV_PARAM_RTS_THRESHOLD;
6337 param_value = ar->hw->wiphy->rts_threshold;
6338 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
6339 param_id, param_value);
6341 ath11k_warn(ar->ab, "failed to set rts threshold for vdev %d: %d\n",
6342 arvif->vdev_id, ret);
6345 ath11k_dp_vdev_tx_attach(ar, arvif);
6347 if (vif->type != NL80211_IFTYPE_MONITOR &&
6348 test_bit(ATH11K_FLAG_MONITOR_CONF_ENABLED, &ar->monitor_flags)) {
6349 ret = ath11k_mac_monitor_vdev_create(ar);
6351 ath11k_warn(ar->ab, "failed to create monitor vdev during add interface: %d",
6357 ret = ath11k_debugfs_add_interface(arvif);
6361 mutex_unlock(&ar->conf_mutex);
6366 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
6367 fbret = ath11k_peer_delete(ar, arvif->vdev_id, vif->addr);
6369 ath11k_warn(ar->ab, "fallback fail to delete peer addr %pM vdev_id %d ret %d\n",
6370 vif->addr, arvif->vdev_id, fbret);
6376 ath11k_wmi_vdev_delete(ar, arvif->vdev_id);
6377 ar->num_created_vdevs--;
6378 ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id);
6379 ab->free_vdev_map |= 1LL << arvif->vdev_id;
6380 spin_lock_bh(&ar->data_lock);
6381 list_del(&arvif->list);
6382 spin_unlock_bh(&ar->data_lock);
6385 ath11k_debugfs_remove_interface(arvif);
6386 mutex_unlock(&ar->conf_mutex);
6391 static int ath11k_mac_vif_unref(int buf_id, void *skb, void *ctx)
6393 struct ieee80211_vif *vif = (struct ieee80211_vif *)ctx;
6394 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb);
6396 if (skb_cb->vif == vif)
6402 static void ath11k_mac_op_remove_interface(struct ieee80211_hw *hw,
6403 struct ieee80211_vif *vif)
6405 struct ath11k *ar = hw->priv;
6406 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
6407 struct ath11k_base *ab = ar->ab;
6408 unsigned long time_left;
6412 cancel_delayed_work_sync(&arvif->connection_loss_work);
6414 mutex_lock(&ar->conf_mutex);
6416 ath11k_dbg(ab, ATH11K_DBG_MAC, "mac remove interface (vdev %d)\n",
6419 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
6420 ath11k_mac_11d_scan_stop(ar);
6422 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
6423 ret = ath11k_peer_delete(ar, arvif->vdev_id, vif->addr);
6425 ath11k_warn(ab, "failed to submit AP self-peer removal on vdev %d: %d\n",
6426 arvif->vdev_id, ret);
6429 reinit_completion(&ar->vdev_delete_done);
6431 ret = ath11k_wmi_vdev_delete(ar, arvif->vdev_id);
6433 ath11k_warn(ab, "failed to delete WMI vdev %d: %d\n",
6434 arvif->vdev_id, ret);
6438 time_left = wait_for_completion_timeout(&ar->vdev_delete_done,
6439 ATH11K_VDEV_DELETE_TIMEOUT_HZ);
6440 if (time_left == 0) {
6441 ath11k_warn(ab, "Timeout in receiving vdev delete response\n");
6445 ab->free_vdev_map |= 1LL << (arvif->vdev_id);
6446 ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id);
6447 ar->num_created_vdevs--;
6449 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM deleted, vdev_id %d\n",
6450 vif->addr, arvif->vdev_id);
6452 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
6453 clear_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags);
6454 ar->monitor_vdev_id = -1;
6455 } else if (test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags) &&
6456 !test_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags)) {
6457 ret = ath11k_mac_monitor_vdev_delete(ar);
6459 /* continue even if there's an error */
6460 ath11k_warn(ar->ab, "failed to delete vdev monitor during remove interface: %d",
6465 spin_lock_bh(&ar->data_lock);
6466 list_del(&arvif->list);
6467 spin_unlock_bh(&ar->data_lock);
6469 ath11k_peer_cleanup(ar, arvif->vdev_id);
6471 idr_for_each(&ar->txmgmt_idr,
6472 ath11k_mac_vif_txmgmt_idr_remove, vif);
6474 for (i = 0; i < ab->hw_params.max_tx_ring; i++) {
6475 spin_lock_bh(&ab->dp.tx_ring[i].tx_idr_lock);
6476 idr_for_each(&ab->dp.tx_ring[i].txbuf_idr,
6477 ath11k_mac_vif_unref, vif);
6478 spin_unlock_bh(&ab->dp.tx_ring[i].tx_idr_lock);
6481 /* Recalc txpower for remaining vdev */
6482 ath11k_mac_txpower_recalc(ar);
6484 ath11k_debugfs_remove_interface(arvif);
6486 /* TODO: recal traffic pause state based on the available vdevs */
6488 mutex_unlock(&ar->conf_mutex);
6491 /* FIXME: Has to be verified. */
6492 #define SUPPORTED_FILTERS \
6497 FIF_BCN_PRBRESP_PROMISC | \
6501 static void ath11k_mac_op_configure_filter(struct ieee80211_hw *hw,
6502 unsigned int changed_flags,
6503 unsigned int *total_flags,
6506 struct ath11k *ar = hw->priv;
6508 mutex_lock(&ar->conf_mutex);
6510 *total_flags &= SUPPORTED_FILTERS;
6511 ar->filter_flags = *total_flags;
6513 mutex_unlock(&ar->conf_mutex);
6516 static int ath11k_mac_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
6518 struct ath11k *ar = hw->priv;
6520 mutex_lock(&ar->conf_mutex);
6522 *tx_ant = ar->cfg_tx_chainmask;
6523 *rx_ant = ar->cfg_rx_chainmask;
6525 mutex_unlock(&ar->conf_mutex);
6530 static int ath11k_mac_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
6532 struct ath11k *ar = hw->priv;
6535 mutex_lock(&ar->conf_mutex);
6536 ret = __ath11k_set_antenna(ar, tx_ant, rx_ant);
6537 mutex_unlock(&ar->conf_mutex);
6542 static int ath11k_mac_op_ampdu_action(struct ieee80211_hw *hw,
6543 struct ieee80211_vif *vif,
6544 struct ieee80211_ampdu_params *params)
6546 struct ath11k *ar = hw->priv;
6549 mutex_lock(&ar->conf_mutex);
6551 switch (params->action) {
6552 case IEEE80211_AMPDU_RX_START:
6553 ret = ath11k_dp_rx_ampdu_start(ar, params);
6555 case IEEE80211_AMPDU_RX_STOP:
6556 ret = ath11k_dp_rx_ampdu_stop(ar, params);
6558 case IEEE80211_AMPDU_TX_START:
6559 case IEEE80211_AMPDU_TX_STOP_CONT:
6560 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6561 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6562 case IEEE80211_AMPDU_TX_OPERATIONAL:
6563 /* Tx A-MPDU aggregation offloaded to hw/fw so deny mac80211
6564 * Tx aggregation requests.
6570 mutex_unlock(&ar->conf_mutex);
6575 static int ath11k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6576 struct ieee80211_chanctx_conf *ctx)
6578 struct ath11k *ar = hw->priv;
6579 struct ath11k_base *ab = ar->ab;
6581 ath11k_dbg(ab, ATH11K_DBG_MAC,
6582 "mac chanctx add freq %u width %d ptr %pK\n",
6583 ctx->def.chan->center_freq, ctx->def.width, ctx);
6585 mutex_lock(&ar->conf_mutex);
6587 spin_lock_bh(&ar->data_lock);
6588 /* TODO: In case of multiple channel context, populate rx_channel from
6589 * Rx PPDU desc information.
6591 ar->rx_channel = ctx->def.chan;
6592 spin_unlock_bh(&ar->data_lock);
6594 mutex_unlock(&ar->conf_mutex);
6599 static void ath11k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6600 struct ieee80211_chanctx_conf *ctx)
6602 struct ath11k *ar = hw->priv;
6603 struct ath11k_base *ab = ar->ab;
6605 ath11k_dbg(ab, ATH11K_DBG_MAC,
6606 "mac chanctx remove freq %u width %d ptr %pK\n",
6607 ctx->def.chan->center_freq, ctx->def.width, ctx);
6609 mutex_lock(&ar->conf_mutex);
6611 spin_lock_bh(&ar->data_lock);
6612 /* TODO: In case of there is one more channel context left, populate
6613 * rx_channel with the channel of that remaining channel context.
6615 ar->rx_channel = NULL;
6616 spin_unlock_bh(&ar->data_lock);
6618 mutex_unlock(&ar->conf_mutex);
6622 ath11k_mac_vdev_start_restart(struct ath11k_vif *arvif,
6623 struct ieee80211_chanctx_conf *ctx,
6626 struct ath11k *ar = arvif->ar;
6627 struct ath11k_base *ab = ar->ab;
6628 struct wmi_vdev_start_req_arg arg = {};
6629 const struct cfg80211_chan_def *chandef = &ctx->def;
6630 int he_support = arvif->vif->bss_conf.he_support;
6633 lockdep_assert_held(&ar->conf_mutex);
6635 reinit_completion(&ar->vdev_setup_done);
6637 arg.vdev_id = arvif->vdev_id;
6638 arg.dtim_period = arvif->dtim_period;
6639 arg.bcn_intval = arvif->beacon_interval;
6641 arg.channel.freq = chandef->chan->center_freq;
6642 arg.channel.band_center_freq1 = chandef->center_freq1;
6643 arg.channel.band_center_freq2 = chandef->center_freq2;
6645 ath11k_phymodes[chandef->chan->band][chandef->width];
6647 arg.channel.min_power = 0;
6648 arg.channel.max_power = chandef->chan->max_power;
6649 arg.channel.max_reg_power = chandef->chan->max_reg_power;
6650 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain;
6652 arg.pref_tx_streams = ar->num_tx_chains;
6653 arg.pref_rx_streams = ar->num_rx_chains;
6655 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
6656 arg.ssid = arvif->u.ap.ssid;
6657 arg.ssid_len = arvif->u.ap.ssid_len;
6658 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
6660 /* For now allow DFS for AP mode */
6661 arg.channel.chan_radar =
6662 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
6664 arg.channel.freq2_radar = ctx->radar_enabled;
6666 arg.channel.passive = arg.channel.chan_radar;
6668 spin_lock_bh(&ab->base_lock);
6669 arg.regdomain = ar->ab->dfs_region;
6670 spin_unlock_bh(&ab->base_lock);
6673 ret = ath11k_set_he_mu_sounding_mode(ar, arvif);
6675 ath11k_warn(ar->ab, "failed to set he mode vdev %i\n",
6682 arg.channel.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR);
6684 ath11k_dbg(ab, ATH11K_DBG_MAC,
6685 "mac vdev %d start center_freq %d phymode %s\n",
6686 arg.vdev_id, arg.channel.freq,
6687 ath11k_wmi_phymode_str(arg.channel.mode));
6689 ret = ath11k_wmi_vdev_start(ar, &arg, restart);
6691 ath11k_warn(ar->ab, "failed to %s WMI vdev %i\n",
6692 restart ? "restart" : "start", arg.vdev_id);
6696 ret = ath11k_mac_vdev_setup_sync(ar);
6698 ath11k_warn(ab, "failed to synchronize setup for vdev %i %s: %d\n",
6699 arg.vdev_id, restart ? "restart" : "start", ret);
6704 ar->num_started_vdevs++;
6706 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM started, vdev_id %d\n",
6707 arvif->vif->addr, arvif->vdev_id);
6709 /* Enable CAC Flag in the driver by checking the channel DFS cac time,
6710 * i.e dfs_cac_ms value which will be valid only for radar channels
6711 * and state as NL80211_DFS_USABLE which indicates CAC needs to be
6712 * done before channel usage. This flags is used to drop rx packets.
6715 /* TODO Set the flag for other interface types as required */
6716 if (arvif->vdev_type == WMI_VDEV_TYPE_AP &&
6717 chandef->chan->dfs_cac_ms &&
6718 chandef->chan->dfs_state == NL80211_DFS_USABLE) {
6719 set_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
6720 ath11k_dbg(ab, ATH11K_DBG_MAC,
6721 "CAC Started in chan_freq %d for vdev %d\n",
6722 arg.channel.freq, arg.vdev_id);
6725 ret = ath11k_mac_set_txbf_conf(arvif);
6727 ath11k_warn(ab, "failed to set txbf conf for vdev %d: %d\n",
6728 arvif->vdev_id, ret);
6733 static int ath11k_mac_vdev_stop(struct ath11k_vif *arvif)
6735 struct ath11k *ar = arvif->ar;
6738 lockdep_assert_held(&ar->conf_mutex);
6740 reinit_completion(&ar->vdev_setup_done);
6742 ret = ath11k_wmi_vdev_stop(ar, arvif->vdev_id);
6744 ath11k_warn(ar->ab, "failed to stop WMI vdev %i: %d\n",
6745 arvif->vdev_id, ret);
6749 ret = ath11k_mac_vdev_setup_sync(ar);
6751 ath11k_warn(ar->ab, "failed to synchronize setup for vdev %i: %d\n",
6752 arvif->vdev_id, ret);
6756 WARN_ON(ar->num_started_vdevs == 0);
6758 ar->num_started_vdevs--;
6759 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "vdev %pM stopped, vdev_id %d\n",
6760 arvif->vif->addr, arvif->vdev_id);
6762 if (test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) {
6763 clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
6764 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "CAC Stopped for vdev %d\n",
6773 static int ath11k_mac_vdev_start(struct ath11k_vif *arvif,
6774 struct ieee80211_chanctx_conf *ctx)
6776 return ath11k_mac_vdev_start_restart(arvif, ctx, false);
6779 static int ath11k_mac_vdev_restart(struct ath11k_vif *arvif,
6780 struct ieee80211_chanctx_conf *ctx)
6782 return ath11k_mac_vdev_start_restart(arvif, ctx, true);
6785 struct ath11k_mac_change_chanctx_arg {
6786 struct ieee80211_chanctx_conf *ctx;
6787 struct ieee80211_vif_chanctx_switch *vifs;
6793 ath11k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
6794 struct ieee80211_vif *vif)
6796 struct ath11k_mac_change_chanctx_arg *arg = data;
6798 if (rcu_access_pointer(vif->bss_conf.chanctx_conf) != arg->ctx)
6805 ath11k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
6806 struct ieee80211_vif *vif)
6808 struct ath11k_mac_change_chanctx_arg *arg = data;
6809 struct ieee80211_chanctx_conf *ctx;
6811 ctx = rcu_access_pointer(vif->bss_conf.chanctx_conf);
6812 if (ctx != arg->ctx)
6815 if (WARN_ON(arg->next_vif == arg->n_vifs))
6818 arg->vifs[arg->next_vif].vif = vif;
6819 arg->vifs[arg->next_vif].old_ctx = ctx;
6820 arg->vifs[arg->next_vif].new_ctx = ctx;
6825 ath11k_mac_update_vif_chan(struct ath11k *ar,
6826 struct ieee80211_vif_chanctx_switch *vifs,
6829 struct ath11k_base *ab = ar->ab;
6830 struct ath11k_vif *arvif;
6833 bool monitor_vif = false;
6835 lockdep_assert_held(&ar->conf_mutex);
6837 /* Associated channel resources of all relevant vdevs
6838 * should be available for the channel switch now.
6841 /* TODO: Update ar->rx_channel */
6843 for (i = 0; i < n_vifs; i++) {
6844 arvif = (void *)vifs[i].vif->drv_priv;
6846 if (WARN_ON(!arvif->is_started))
6849 /* change_chanctx can be called even before vdev_up from
6850 * ieee80211_start_ap->ieee80211_vif_use_channel->
6851 * ieee80211_recalc_radar_chanctx.
6853 * Firmware expect vdev_restart only if vdev is up.
6854 * If vdev is down then it expect vdev_stop->vdev_start.
6857 ret = ath11k_mac_vdev_restart(arvif, vifs[i].new_ctx);
6859 ath11k_warn(ab, "failed to restart vdev %d: %d\n",
6860 arvif->vdev_id, ret);
6864 ret = ath11k_mac_vdev_stop(arvif);
6866 ath11k_warn(ab, "failed to stop vdev %d: %d\n",
6867 arvif->vdev_id, ret);
6871 ret = ath11k_mac_vdev_start(arvif, vifs[i].new_ctx);
6873 ath11k_warn(ab, "failed to start vdev %d: %d\n",
6874 arvif->vdev_id, ret);
6879 ret = ath11k_mac_setup_bcn_tmpl(arvif);
6881 ath11k_warn(ab, "failed to update bcn tmpl during csa: %d\n",
6884 ret = ath11k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
6887 ath11k_warn(ab, "failed to bring vdev up %d: %d\n",
6888 arvif->vdev_id, ret);
6893 /* Restart the internal monitor vdev on new channel */
6895 test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags)) {
6896 ret = ath11k_mac_monitor_stop(ar);
6898 ath11k_warn(ar->ab, "failed to stop monitor during vif channel update: %d",
6903 ret = ath11k_mac_monitor_start(ar);
6905 ath11k_warn(ar->ab, "failed to start monitor during vif channel update: %d",
6913 ath11k_mac_update_active_vif_chan(struct ath11k *ar,
6914 struct ieee80211_chanctx_conf *ctx)
6916 struct ath11k_mac_change_chanctx_arg arg = { .ctx = ctx };
6918 lockdep_assert_held(&ar->conf_mutex);
6920 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6921 IEEE80211_IFACE_ITER_NORMAL,
6922 ath11k_mac_change_chanctx_cnt_iter,
6924 if (arg.n_vifs == 0)
6927 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]), GFP_KERNEL);
6931 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6932 IEEE80211_IFACE_ITER_NORMAL,
6933 ath11k_mac_change_chanctx_fill_iter,
6936 ath11k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
6941 static void ath11k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6942 struct ieee80211_chanctx_conf *ctx,
6945 struct ath11k *ar = hw->priv;
6946 struct ath11k_base *ab = ar->ab;
6948 mutex_lock(&ar->conf_mutex);
6950 ath11k_dbg(ab, ATH11K_DBG_MAC,
6951 "mac chanctx change freq %u width %d ptr %pK changed %x\n",
6952 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
6954 /* This shouldn't really happen because channel switching should use
6955 * switch_vif_chanctx().
6957 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6960 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH ||
6961 changed & IEEE80211_CHANCTX_CHANGE_RADAR)
6962 ath11k_mac_update_active_vif_chan(ar, ctx);
6964 /* TODO: Recalc radar detection */
6967 mutex_unlock(&ar->conf_mutex);
6970 static int ath11k_start_vdev_delay(struct ieee80211_hw *hw,
6971 struct ieee80211_vif *vif)
6973 struct ath11k *ar = hw->priv;
6974 struct ath11k_base *ab = ar->ab;
6975 struct ath11k_vif *arvif = (void *)vif->drv_priv;
6978 if (WARN_ON(arvif->is_started))
6981 ret = ath11k_mac_vdev_start(arvif, &arvif->chanctx);
6983 ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
6984 arvif->vdev_id, vif->addr,
6985 arvif->chanctx.def.chan->center_freq, ret);
6989 /* Reconfigure hardware rate code since it is cleared by firmware.
6991 if (ar->hw_rate_code > 0) {
6992 u32 vdev_param = WMI_VDEV_PARAM_MGMT_RATE;
6994 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
6997 ath11k_warn(ar->ab, "failed to set mgmt tx rate %d\n", ret);
7002 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
7003 ret = ath11k_wmi_vdev_up(ar, arvif->vdev_id, 0, ar->mac_addr);
7005 ath11k_warn(ab, "failed put monitor up: %d\n", ret);
7010 arvif->is_started = true;
7012 /* TODO: Setup ps and cts/rts protection */
7017 ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7018 struct ieee80211_vif *vif,
7019 struct ieee80211_bss_conf *link_conf,
7020 struct ieee80211_chanctx_conf *ctx)
7022 struct ath11k *ar = hw->priv;
7023 struct ath11k_base *ab = ar->ab;
7024 struct ath11k_vif *arvif = (void *)vif->drv_priv;
7026 struct peer_create_params param;
7028 mutex_lock(&ar->conf_mutex);
7030 ath11k_dbg(ab, ATH11K_DBG_MAC,
7031 "mac chanctx assign ptr %pK vdev_id %i\n",
7032 ctx, arvif->vdev_id);
7034 /* for QCA6390 bss peer must be created before vdev_start */
7035 if (ab->hw_params.vdev_start_delay &&
7036 arvif->vdev_type != WMI_VDEV_TYPE_AP &&
7037 arvif->vdev_type != WMI_VDEV_TYPE_MONITOR &&
7038 !ath11k_peer_find_by_vdev_id(ab, arvif->vdev_id)) {
7039 memcpy(&arvif->chanctx, ctx, sizeof(*ctx));
7044 if (WARN_ON(arvif->is_started)) {
7049 if (ab->hw_params.vdev_start_delay &&
7050 arvif->vdev_type != WMI_VDEV_TYPE_AP &&
7051 arvif->vdev_type != WMI_VDEV_TYPE_MONITOR) {
7052 param.vdev_id = arvif->vdev_id;
7053 param.peer_type = WMI_PEER_TYPE_DEFAULT;
7054 param.peer_addr = ar->mac_addr;
7056 ret = ath11k_peer_create(ar, arvif, NULL, ¶m);
7058 ath11k_warn(ab, "failed to create peer after vdev start delay: %d",
7064 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
7065 ret = ath11k_mac_monitor_start(ar);
7067 ath11k_warn(ar->ab, "failed to start monitor during vif channel context assignment: %d",
7072 arvif->is_started = true;
7076 ret = ath11k_mac_vdev_start(arvif, ctx);
7078 ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
7079 arvif->vdev_id, vif->addr,
7080 ctx->def.chan->center_freq, ret);
7084 arvif->is_started = true;
7086 if (arvif->vdev_type != WMI_VDEV_TYPE_MONITOR &&
7087 test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags)) {
7088 ret = ath11k_mac_monitor_start(ar);
7090 ath11k_warn(ar->ab, "failed to start monitor during vif channel context assignment: %d",
7096 /* TODO: Setup ps and cts/rts protection */
7101 mutex_unlock(&ar->conf_mutex);
7107 ath11k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7108 struct ieee80211_vif *vif,
7109 struct ieee80211_bss_conf *link_conf,
7110 struct ieee80211_chanctx_conf *ctx)
7112 struct ath11k *ar = hw->priv;
7113 struct ath11k_base *ab = ar->ab;
7114 struct ath11k_vif *arvif = (void *)vif->drv_priv;
7115 struct ath11k_peer *peer;
7118 mutex_lock(&ar->conf_mutex);
7120 ath11k_dbg(ab, ATH11K_DBG_MAC,
7121 "mac chanctx unassign ptr %pK vdev_id %i\n",
7122 ctx, arvif->vdev_id);
7124 WARN_ON(!arvif->is_started);
7126 if (ab->hw_params.vdev_start_delay &&
7127 arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
7128 spin_lock_bh(&ab->base_lock);
7129 peer = ath11k_peer_find_by_addr(ab, ar->mac_addr);
7130 spin_unlock_bh(&ab->base_lock);
7132 ath11k_peer_delete(ar, arvif->vdev_id, ar->mac_addr);
7135 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
7136 ret = ath11k_mac_monitor_stop(ar);
7138 ath11k_warn(ar->ab, "failed to stop monitor during vif channel context unassignment: %d",
7140 mutex_unlock(&ar->conf_mutex);
7144 arvif->is_started = false;
7145 mutex_unlock(&ar->conf_mutex);
7149 ret = ath11k_mac_vdev_stop(arvif);
7151 ath11k_warn(ab, "failed to stop vdev %i: %d\n",
7152 arvif->vdev_id, ret);
7154 arvif->is_started = false;
7156 if (ab->hw_params.vdev_start_delay &&
7157 arvif->vdev_type == WMI_VDEV_TYPE_STA) {
7158 ret = ath11k_peer_delete(ar, arvif->vdev_id, arvif->bssid);
7161 "failed to delete peer %pM for vdev %d: %d\n",
7162 arvif->bssid, arvif->vdev_id, ret);
7164 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
7165 "mac removed peer %pM vdev %d after vdev stop\n",
7166 arvif->bssid, arvif->vdev_id);
7169 if (ab->hw_params.vdev_start_delay &&
7170 arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
7171 ath11k_wmi_vdev_down(ar, arvif->vdev_id);
7173 if (arvif->vdev_type != WMI_VDEV_TYPE_MONITOR &&
7174 ar->num_started_vdevs == 1 &&
7175 test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags)) {
7176 ret = ath11k_mac_monitor_stop(ar);
7178 /* continue even if there's an error */
7179 ath11k_warn(ar->ab, "failed to stop monitor during vif channel context unassignment: %d",
7183 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
7184 ath11k_mac_11d_scan_start(ar, arvif->vdev_id);
7186 mutex_unlock(&ar->conf_mutex);
7190 ath11k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7191 struct ieee80211_vif_chanctx_switch *vifs,
7193 enum ieee80211_chanctx_switch_mode mode)
7195 struct ath11k *ar = hw->priv;
7197 mutex_lock(&ar->conf_mutex);
7199 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
7200 "mac chanctx switch n_vifs %d mode %d\n",
7202 ath11k_mac_update_vif_chan(ar, vifs, n_vifs);
7204 mutex_unlock(&ar->conf_mutex);
7210 ath11k_set_vdev_param_to_all_vifs(struct ath11k *ar, int param, u32 value)
7212 struct ath11k_vif *arvif;
7215 mutex_lock(&ar->conf_mutex);
7216 list_for_each_entry(arvif, &ar->arvifs, list) {
7217 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "setting mac vdev %d param %d value %d\n",
7218 param, arvif->vdev_id, value);
7220 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7223 ath11k_warn(ar->ab, "failed to set param %d for vdev %d: %d\n",
7224 param, arvif->vdev_id, ret);
7228 mutex_unlock(&ar->conf_mutex);
7232 /* mac80211 stores device specific RTS/Fragmentation threshold value,
7233 * this is set interface specific to firmware from ath11k driver
7235 static int ath11k_mac_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
7237 struct ath11k *ar = hw->priv;
7238 int param_id = WMI_VDEV_PARAM_RTS_THRESHOLD;
7240 return ath11k_set_vdev_param_to_all_vifs(ar, param_id, value);
7243 static int ath11k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
7245 /* Even though there's a WMI vdev param for fragmentation threshold no
7246 * known firmware actually implements it. Moreover it is not possible to
7247 * rely frame fragmentation to mac80211 because firmware clears the
7248 * "more fragments" bit in frame control making it impossible for remote
7249 * devices to reassemble frames.
7251 * Hence implement a dummy callback just to say fragmentation isn't
7252 * supported. This effectively prevents mac80211 from doing frame
7253 * fragmentation in software.
7258 static int ath11k_mac_flush_tx_complete(struct ath11k *ar)
7263 time_left = wait_event_timeout(ar->dp.tx_empty_waitq,
7264 (atomic_read(&ar->dp.num_tx_pending) == 0),
7265 ATH11K_FLUSH_TIMEOUT);
7266 if (time_left == 0) {
7267 ath11k_warn(ar->ab, "failed to flush transmit queue, data pkts pending %d\n",
7268 atomic_read(&ar->dp.num_tx_pending));
7272 time_left = wait_event_timeout(ar->txmgmt_empty_waitq,
7273 (atomic_read(&ar->num_pending_mgmt_tx) == 0),
7274 ATH11K_FLUSH_TIMEOUT);
7275 if (time_left == 0) {
7276 ath11k_warn(ar->ab, "failed to flush mgmt transmit queue, mgmt pkts pending %d\n",
7277 atomic_read(&ar->num_pending_mgmt_tx));
7284 int ath11k_mac_wait_tx_complete(struct ath11k *ar)
7286 ath11k_mac_drain_tx(ar);
7287 return ath11k_mac_flush_tx_complete(ar);
7290 static void ath11k_mac_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
7291 u32 queues, bool drop)
7293 struct ath11k *ar = hw->priv;
7298 ath11k_mac_flush_tx_complete(ar);
7302 ath11k_mac_bitrate_mask_num_ht_rates(struct ath11k *ar,
7303 enum nl80211_band band,
7304 const struct cfg80211_bitrate_mask *mask)
7309 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
7310 num_rates += hweight16(mask->control[band].ht_mcs[i]);
7316 ath11k_mac_has_single_legacy_rate(struct ath11k *ar,
7317 enum nl80211_band band,
7318 const struct cfg80211_bitrate_mask *mask)
7322 num_rates = hweight32(mask->control[band].legacy);
7324 if (ath11k_mac_bitrate_mask_num_ht_rates(ar, band, mask))
7327 if (ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask))
7330 if (ath11k_mac_bitrate_mask_num_he_rates(ar, band, mask))
7333 return num_rates == 1;
7337 ath11k_mac_get_tx_mcs_map(const struct ieee80211_sta_he_cap *he_cap)
7339 if (he_cap->he_cap_elem.phy_cap_info[0] &
7340 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)
7341 return he_cap->he_mcs_nss_supp.tx_mcs_80p80;
7343 if (he_cap->he_cap_elem.phy_cap_info[0] &
7344 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
7345 return he_cap->he_mcs_nss_supp.tx_mcs_160;
7347 return he_cap->he_mcs_nss_supp.tx_mcs_80;
7351 ath11k_mac_bitrate_mask_get_single_nss(struct ath11k *ar,
7352 enum nl80211_band band,
7353 const struct cfg80211_bitrate_mask *mask,
7356 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
7357 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7360 u8 vht_nss_mask = 0;
7364 /* No need to consider legacy here. Basic rates are always present
7368 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
7369 if (mask->control[band].ht_mcs[i] == 0)
7371 else if (mask->control[band].ht_mcs[i] ==
7372 sband->ht_cap.mcs.rx_mask[i])
7373 ht_nss_mask |= BIT(i);
7378 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
7379 if (mask->control[band].vht_mcs[i] == 0)
7381 else if (mask->control[band].vht_mcs[i] ==
7382 ath11k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
7383 vht_nss_mask |= BIT(i);
7388 he_mcs_map = le16_to_cpu(ath11k_mac_get_tx_mcs_map(&sband->iftype_data->he_cap));
7390 for (i = 0; i < ARRAY_SIZE(mask->control[band].he_mcs); i++) {
7391 if (mask->control[band].he_mcs[i] == 0)
7394 if (mask->control[band].he_mcs[i] ==
7395 ath11k_mac_get_max_he_mcs_map(he_mcs_map, i))
7396 he_nss_mask |= BIT(i);
7401 if (ht_nss_mask != vht_nss_mask || ht_nss_mask != he_nss_mask)
7404 if (ht_nss_mask == 0)
7407 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
7410 *nss = fls(ht_nss_mask);
7416 ath11k_mac_get_single_legacy_rate(struct ath11k *ar,
7417 enum nl80211_band band,
7418 const struct cfg80211_bitrate_mask *mask,
7426 if (hweight32(mask->control[band].legacy) != 1)
7429 rate_idx = ffs(mask->control[band].legacy) - 1;
7431 if (band == NL80211_BAND_5GHZ || band == NL80211_BAND_6GHZ)
7432 rate_idx += ATH11K_MAC_FIRST_OFDM_RATE_IDX;
7434 hw_rate = ath11k_legacy_rates[rate_idx].hw_value;
7435 bitrate = ath11k_legacy_rates[rate_idx].bitrate;
7437 if (ath11k_mac_bitrate_is_cck(bitrate))
7438 preamble = WMI_RATE_PREAMBLE_CCK;
7440 preamble = WMI_RATE_PREAMBLE_OFDM;
7443 *rate = ATH11K_HW_RATE_CODE(hw_rate, 0, preamble);
7449 ath11k_mac_set_fixed_rate_gi_ltf(struct ath11k_vif *arvif, u8 he_gi, u8 he_ltf)
7451 struct ath11k *ar = arvif->ar;
7454 /* 0.8 = 0, 1.6 = 2 and 3.2 = 3. */
7455 if (he_gi && he_gi != 0xFF)
7458 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7459 WMI_VDEV_PARAM_SGI, he_gi);
7461 ath11k_warn(ar->ab, "failed to set he gi %d: %d\n",
7469 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7470 WMI_VDEV_PARAM_HE_LTF, he_ltf);
7472 ath11k_warn(ar->ab, "failed to set he ltf %d: %d\n",
7481 ath11k_mac_set_auto_rate_gi_ltf(struct ath11k_vif *arvif, u16 he_gi, u8 he_ltf)
7483 struct ath11k *ar = arvif->ar;
7487 if (he_gi != 0xFF) {
7489 case NL80211_RATE_INFO_HE_GI_0_8:
7490 he_gi = WMI_AUTORATE_800NS_GI;
7492 case NL80211_RATE_INFO_HE_GI_1_6:
7493 he_gi = WMI_AUTORATE_1600NS_GI;
7495 case NL80211_RATE_INFO_HE_GI_3_2:
7496 he_gi = WMI_AUTORATE_3200NS_GI;
7499 ath11k_warn(ar->ab, "invalid he gi: %d\n", he_gi);
7504 if (he_ltf != 0xFF) {
7506 case NL80211_RATE_INFO_HE_1XLTF:
7507 he_ltf = WMI_HE_AUTORATE_LTF_1X;
7509 case NL80211_RATE_INFO_HE_2XLTF:
7510 he_ltf = WMI_HE_AUTORATE_LTF_2X;
7512 case NL80211_RATE_INFO_HE_4XLTF:
7513 he_ltf = WMI_HE_AUTORATE_LTF_4X;
7516 ath11k_warn(ar->ab, "invalid he ltf: %d\n", he_ltf);
7521 he_ar_gi_ltf = he_gi | he_ltf;
7522 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7523 WMI_VDEV_PARAM_AUTORATE_MISC_CFG,
7527 "failed to set he autorate gi %u ltf %u: %d\n",
7528 he_gi, he_ltf, ret);
7535 static int ath11k_mac_set_rate_params(struct ath11k_vif *arvif,
7536 u32 rate, u8 nss, u8 sgi, u8 ldpc,
7537 u8 he_gi, u8 he_ltf, bool he_fixed_rate)
7539 struct ath11k *ar = arvif->ar;
7543 lockdep_assert_held(&ar->conf_mutex);
7545 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
7546 "mac set rate params vdev %i rate 0x%02x nss 0x%02x sgi 0x%02x ldpc 0x%02x he_gi 0x%02x he_ltf 0x%02x he_fixed_rate %d\n",
7547 arvif->vdev_id, rate, nss, sgi, ldpc, he_gi,
7548 he_ltf, he_fixed_rate);
7550 if (!arvif->vif->bss_conf.he_support) {
7551 vdev_param = WMI_VDEV_PARAM_FIXED_RATE;
7552 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7555 ath11k_warn(ar->ab, "failed to set fixed rate param 0x%02x: %d\n",
7561 vdev_param = WMI_VDEV_PARAM_NSS;
7562 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7565 ath11k_warn(ar->ab, "failed to set nss param %d: %d\n",
7570 vdev_param = WMI_VDEV_PARAM_LDPC;
7571 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7574 ath11k_warn(ar->ab, "failed to set ldpc param %d: %d\n",
7579 if (arvif->vif->bss_conf.he_support) {
7580 if (he_fixed_rate) {
7581 ret = ath11k_mac_set_fixed_rate_gi_ltf(arvif, he_gi,
7584 ath11k_warn(ar->ab, "failed to set fixed rate gi ltf: %d\n",
7589 ret = ath11k_mac_set_auto_rate_gi_ltf(arvif, he_gi,
7592 ath11k_warn(ar->ab, "failed to set auto rate gi ltf: %d\n",
7598 vdev_param = WMI_VDEV_PARAM_SGI;
7599 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7602 ath11k_warn(ar->ab, "failed to set sgi param %d: %d\n",
7612 ath11k_mac_vht_mcs_range_present(struct ath11k *ar,
7613 enum nl80211_band band,
7614 const struct cfg80211_bitrate_mask *mask)
7619 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7620 vht_mcs = mask->control[band].vht_mcs[i];
7637 ath11k_mac_he_mcs_range_present(struct ath11k *ar,
7638 enum nl80211_band band,
7639 const struct cfg80211_bitrate_mask *mask)
7644 for (i = 0; i < NL80211_HE_NSS_MAX; i++) {
7645 he_mcs = mask->control[band].he_mcs[i];
7661 static void ath11k_mac_set_bitrate_mask_iter(void *data,
7662 struct ieee80211_sta *sta)
7664 struct ath11k_vif *arvif = data;
7665 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
7666 struct ath11k *ar = arvif->ar;
7668 spin_lock_bh(&ar->data_lock);
7669 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
7670 spin_unlock_bh(&ar->data_lock);
7672 ieee80211_queue_work(ar->hw, &arsta->update_wk);
7675 static void ath11k_mac_disable_peer_fixed_rate(void *data,
7676 struct ieee80211_sta *sta)
7678 struct ath11k_vif *arvif = data;
7679 struct ath11k *ar = arvif->ar;
7682 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
7684 WMI_PEER_PARAM_FIXED_RATE,
7685 WMI_FIXED_RATE_NONE);
7688 "failed to disable peer fixed rate for STA %pM ret %d\n",
7693 ath11k_mac_validate_vht_he_fixed_rate_settings(struct ath11k *ar, enum nl80211_band band,
7694 const struct cfg80211_bitrate_mask *mask)
7696 bool he_fixed_rate = false, vht_fixed_rate = false;
7697 struct ath11k_peer *peer, *tmp;
7698 const u16 *vht_mcs_mask, *he_mcs_mask;
7699 struct ieee80211_link_sta *deflink;
7703 vht_mcs_mask = mask->control[band].vht_mcs;
7704 he_mcs_mask = mask->control[band].he_mcs;
7706 if (ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask) == 1)
7707 vht_fixed_rate = true;
7709 if (ath11k_mac_bitrate_mask_num_he_rates(ar, band, mask) == 1)
7710 he_fixed_rate = true;
7712 if (!vht_fixed_rate && !he_fixed_rate)
7715 vht_nss = ath11k_mac_max_vht_nss(vht_mcs_mask);
7716 he_nss = ath11k_mac_max_he_nss(he_mcs_mask);
7719 spin_lock_bh(&ar->ab->base_lock);
7720 list_for_each_entry_safe(peer, tmp, &ar->ab->peers, list) {
7722 deflink = &peer->sta->deflink;
7724 if (vht_fixed_rate && (!deflink->vht_cap.vht_supported ||
7725 deflink->rx_nss < vht_nss)) {
7730 if (he_fixed_rate && (!deflink->he_cap.has_he ||
7731 deflink->rx_nss < he_nss)) {
7739 spin_unlock_bh(&ar->ab->base_lock);
7745 ath11k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
7746 struct ieee80211_vif *vif,
7747 const struct cfg80211_bitrate_mask *mask)
7749 struct ath11k_vif *arvif = (void *)vif->drv_priv;
7750 struct cfg80211_chan_def def;
7751 struct ath11k_pdev_cap *cap;
7752 struct ath11k *ar = arvif->ar;
7753 enum nl80211_band band;
7754 const u8 *ht_mcs_mask;
7755 const u16 *vht_mcs_mask;
7756 const u16 *he_mcs_mask;
7766 bool he_fixed_rate = false;
7768 if (ath11k_mac_vif_chan(vif, &def))
7771 band = def.chan->band;
7772 cap = &ar->pdev->cap;
7773 ht_mcs_mask = mask->control[band].ht_mcs;
7774 vht_mcs_mask = mask->control[band].vht_mcs;
7775 he_mcs_mask = mask->control[band].he_mcs;
7776 ldpc = !!(cap->band[band].ht_cap_info & WMI_HT_CAP_TX_LDPC);
7778 sgi = mask->control[band].gi;
7779 if (sgi == NL80211_TXRATE_FORCE_LGI)
7782 he_gi = mask->control[band].he_gi;
7783 he_ltf = mask->control[band].he_ltf;
7785 /* mac80211 doesn't support sending a fixed HT/VHT MCS alone, rather it
7786 * requires passing at least one of used basic rates along with them.
7787 * Fixed rate setting across different preambles(legacy, HT, VHT) is
7788 * not supported by the FW. Hence use of FIXED_RATE vdev param is not
7789 * suitable for setting single HT/VHT rates.
7790 * But, there could be a single basic rate passed from userspace which
7791 * can be done through the FIXED_RATE param.
7793 if (ath11k_mac_has_single_legacy_rate(ar, band, mask)) {
7794 ret = ath11k_mac_get_single_legacy_rate(ar, band, mask, &rate,
7797 ath11k_warn(ar->ab, "failed to get single legacy rate for vdev %i: %d\n",
7798 arvif->vdev_id, ret);
7801 ieee80211_iterate_stations_atomic(ar->hw,
7802 ath11k_mac_disable_peer_fixed_rate,
7804 } else if (ath11k_mac_bitrate_mask_get_single_nss(ar, band, mask,
7806 rate = WMI_FIXED_RATE_NONE;
7808 mutex_lock(&ar->conf_mutex);
7809 arvif->bitrate_mask = *mask;
7810 ieee80211_iterate_stations_atomic(ar->hw,
7811 ath11k_mac_set_bitrate_mask_iter,
7813 mutex_unlock(&ar->conf_mutex);
7815 rate = WMI_FIXED_RATE_NONE;
7817 if (!ath11k_mac_validate_vht_he_fixed_rate_settings(ar, band, mask))
7819 "could not update fixed rate settings to all peers due to mcs/nss incompatibility\n");
7820 nss = min_t(u32, ar->num_tx_chains,
7821 max(max(ath11k_mac_max_ht_nss(ht_mcs_mask),
7822 ath11k_mac_max_vht_nss(vht_mcs_mask)),
7823 ath11k_mac_max_he_nss(he_mcs_mask)));
7825 /* If multiple rates across different preambles are given
7826 * we can reconfigure this info with all peers using PEER_ASSOC
7827 * command with the below exception cases.
7828 * - Single VHT Rate : peer_assoc command accommodates only MCS
7829 * range values i.e 0-7, 0-8, 0-9 for VHT. Though mac80211
7830 * mandates passing basic rates along with HT/VHT rates, FW
7831 * doesn't allow switching from VHT to Legacy. Hence instead of
7832 * setting legacy and VHT rates using RATEMASK_CMD vdev cmd,
7833 * we could set this VHT rate as peer fixed rate param, which
7834 * will override FIXED rate and FW rate control algorithm.
7835 * If single VHT rate is passed along with HT rates, we select
7836 * the VHT rate as fixed rate for vht peers.
7837 * - Multiple VHT Rates : When Multiple VHT rates are given,this
7838 * can be set using RATEMASK CMD which uses FW rate-ctl alg.
7839 * TODO: Setting multiple VHT MCS and replacing peer_assoc with
7840 * RATEMASK_CMDID can cover all use cases of setting rates
7841 * across multiple preambles and rates within same type.
7842 * But requires more validation of the command at this point.
7845 num_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band,
7848 if (!ath11k_mac_vht_mcs_range_present(ar, band, mask) &&
7850 /* TODO: Handle multiple VHT MCS values setting using
7854 "setting %d mcs values in bitrate mask not supported\n",
7859 num_rates = ath11k_mac_bitrate_mask_num_he_rates(ar, band,
7862 he_fixed_rate = true;
7864 if (!ath11k_mac_he_mcs_range_present(ar, band, mask) &&
7867 "Setting more than one HE MCS Value in bitrate mask not supported\n");
7871 mutex_lock(&ar->conf_mutex);
7872 ieee80211_iterate_stations_atomic(ar->hw,
7873 ath11k_mac_disable_peer_fixed_rate,
7876 arvif->bitrate_mask = *mask;
7877 ieee80211_iterate_stations_atomic(ar->hw,
7878 ath11k_mac_set_bitrate_mask_iter,
7881 mutex_unlock(&ar->conf_mutex);
7884 mutex_lock(&ar->conf_mutex);
7886 ret = ath11k_mac_set_rate_params(arvif, rate, nss, sgi, ldpc, he_gi,
7887 he_ltf, he_fixed_rate);
7889 ath11k_warn(ar->ab, "failed to set rate params on vdev %i: %d\n",
7890 arvif->vdev_id, ret);
7893 mutex_unlock(&ar->conf_mutex);
7899 ath11k_mac_op_reconfig_complete(struct ieee80211_hw *hw,
7900 enum ieee80211_reconfig_type reconfig_type)
7902 struct ath11k *ar = hw->priv;
7903 struct ath11k_base *ab = ar->ab;
7906 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
7909 mutex_lock(&ar->conf_mutex);
7911 if (ar->state == ATH11K_STATE_RESTARTED) {
7912 ath11k_warn(ar->ab, "pdev %d successfully recovered\n",
7914 ar->state = ATH11K_STATE_ON;
7915 ieee80211_wake_queues(ar->hw);
7917 if (ar->ab->hw_params.current_cc_support &&
7918 ar->alpha2[0] != 0 && ar->alpha2[1] != 0) {
7919 struct wmi_set_current_country_params set_current_param = {};
7921 memcpy(&set_current_param.alpha2, ar->alpha2, 2);
7922 ath11k_wmi_send_set_current_country_cmd(ar, &set_current_param);
7926 recovery_count = atomic_inc_return(&ab->recovery_count);
7927 ath11k_dbg(ab, ATH11K_DBG_BOOT,
7928 "recovery count %d\n", recovery_count);
7929 /* When there are multiple radios in an SOC,
7930 * the recovery has to be done for each radio
7932 if (recovery_count == ab->num_radios) {
7933 atomic_dec(&ab->reset_count);
7934 complete(&ab->reset_complete);
7935 ab->is_reset = false;
7936 atomic_set(&ab->fail_cont_count, 0);
7937 ath11k_dbg(ab, ATH11K_DBG_BOOT, "reset success\n");
7942 mutex_unlock(&ar->conf_mutex);
7946 ath11k_mac_update_bss_chan_survey(struct ath11k *ar,
7947 struct ieee80211_channel *channel)
7950 enum wmi_bss_chan_info_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
7952 lockdep_assert_held(&ar->conf_mutex);
7954 if (!test_bit(WMI_TLV_SERVICE_BSS_CHANNEL_INFO_64, ar->ab->wmi_ab.svc_map) ||
7955 ar->rx_channel != channel)
7958 if (ar->scan.state != ATH11K_SCAN_IDLE) {
7959 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
7960 "ignoring bss chan info req while scanning..\n");
7964 reinit_completion(&ar->bss_survey_done);
7966 ret = ath11k_wmi_pdev_bss_chan_info_request(ar, type);
7968 ath11k_warn(ar->ab, "failed to send pdev bss chan info request\n");
7972 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
7974 ath11k_warn(ar->ab, "bss channel survey timed out\n");
7977 static int ath11k_mac_op_get_survey(struct ieee80211_hw *hw, int idx,
7978 struct survey_info *survey)
7980 struct ath11k *ar = hw->priv;
7981 struct ieee80211_supported_band *sband;
7982 struct survey_info *ar_survey;
7985 if (idx >= ATH11K_NUM_CHANS)
7988 ar_survey = &ar->survey[idx];
7990 mutex_lock(&ar->conf_mutex);
7992 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
7993 if (sband && idx >= sband->n_channels) {
7994 idx -= sband->n_channels;
7999 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
8000 if (sband && idx >= sband->n_channels) {
8001 idx -= sband->n_channels;
8006 sband = hw->wiphy->bands[NL80211_BAND_6GHZ];
8007 if (!sband || idx >= sband->n_channels) {
8012 ath11k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
8014 spin_lock_bh(&ar->data_lock);
8015 memcpy(survey, ar_survey, sizeof(*survey));
8016 spin_unlock_bh(&ar->data_lock);
8018 survey->channel = &sband->channels[idx];
8020 if (ar->rx_channel == survey->channel)
8021 survey->filled |= SURVEY_INFO_IN_USE;
8024 mutex_unlock(&ar->conf_mutex);
8028 static void ath11k_mac_put_chain_rssi(struct station_info *sinfo,
8029 struct ath11k_sta *arsta,
8033 struct ath11k *ar = arsta->arvif->ar;
8037 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
8038 sinfo->chains &= ~BIT(i);
8039 rssi = arsta->chain_signal[i];
8041 arsta->chain_signal[i] = ATH11K_INVALID_RSSI_FULL;
8043 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
8044 "mac sta statistics %s rssi[%d] %d\n", pre, i, rssi);
8046 if (rssi != ATH11K_DEFAULT_NOISE_FLOOR &&
8047 rssi != ATH11K_INVALID_RSSI_FULL &&
8048 rssi != ATH11K_INVALID_RSSI_EMPTY &&
8050 sinfo->chain_signal[i] = rssi;
8051 sinfo->chains |= BIT(i);
8052 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
8057 static void ath11k_mac_op_sta_statistics(struct ieee80211_hw *hw,
8058 struct ieee80211_vif *vif,
8059 struct ieee80211_sta *sta,
8060 struct station_info *sinfo)
8062 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
8063 struct ath11k *ar = arsta->arvif->ar;
8065 bool db2dbm = test_bit(WMI_TLV_SERVICE_HW_DB2DBM_CONVERSION_SUPPORT,
8066 ar->ab->wmi_ab.svc_map);
8068 sinfo->rx_duration = arsta->rx_duration;
8069 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
8071 sinfo->tx_duration = arsta->tx_duration;
8072 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION);
8074 if (arsta->txrate.legacy || arsta->txrate.nss) {
8075 if (arsta->txrate.legacy) {
8076 sinfo->txrate.legacy = arsta->txrate.legacy;
8078 sinfo->txrate.mcs = arsta->txrate.mcs;
8079 sinfo->txrate.nss = arsta->txrate.nss;
8080 sinfo->txrate.bw = arsta->txrate.bw;
8081 sinfo->txrate.he_gi = arsta->txrate.he_gi;
8082 sinfo->txrate.he_dcm = arsta->txrate.he_dcm;
8083 sinfo->txrate.he_ru_alloc = arsta->txrate.he_ru_alloc;
8085 sinfo->txrate.flags = arsta->txrate.flags;
8086 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
8089 ath11k_mac_put_chain_rssi(sinfo, arsta, "ppdu", false);
8091 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) &&
8092 arsta->arvif->vdev_type == WMI_VDEV_TYPE_STA &&
8093 ar->ab->hw_params.supports_rssi_stats &&
8094 !ath11k_debugfs_get_fw_stats(ar, ar->pdev->pdev_id, 0,
8095 WMI_REQUEST_RSSI_PER_CHAIN_STAT)) {
8096 ath11k_mac_put_chain_rssi(sinfo, arsta, "fw stats", true);
8099 signal = arsta->rssi_comb;
8101 arsta->arvif->vdev_type == WMI_VDEV_TYPE_STA &&
8102 ar->ab->hw_params.supports_rssi_stats &&
8103 !(ath11k_debugfs_get_fw_stats(ar, ar->pdev->pdev_id, 0,
8104 WMI_REQUEST_VDEV_STAT)))
8105 signal = arsta->rssi_beacon;
8107 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
8108 "mac sta statistics db2dbm %u rssi comb %d rssi beacon %d\n",
8109 db2dbm, arsta->rssi_comb, arsta->rssi_beacon);
8112 sinfo->signal = db2dbm ? signal : signal + ATH11K_DEFAULT_NOISE_FLOOR;
8113 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
8116 sinfo->signal_avg = ewma_avg_rssi_read(&arsta->avg_rssi) +
8117 ATH11K_DEFAULT_NOISE_FLOOR;
8118 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
8121 #if IS_ENABLED(CONFIG_IPV6)
8122 static void ath11k_generate_ns_mc_addr(struct ath11k *ar,
8123 struct ath11k_arp_ns_offload *offload)
8127 for (i = 0; i < offload->ipv6_count; i++) {
8128 offload->self_ipv6_addr[i][0] = 0xff;
8129 offload->self_ipv6_addr[i][1] = 0x02;
8130 offload->self_ipv6_addr[i][11] = 0x01;
8131 offload->self_ipv6_addr[i][12] = 0xff;
8132 offload->self_ipv6_addr[i][13] =
8133 offload->ipv6_addr[i][13];
8134 offload->self_ipv6_addr[i][14] =
8135 offload->ipv6_addr[i][14];
8136 offload->self_ipv6_addr[i][15] =
8137 offload->ipv6_addr[i][15];
8138 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "NS solicited addr %pI6\n",
8139 offload->self_ipv6_addr[i]);
8143 static void ath11k_mac_op_ipv6_changed(struct ieee80211_hw *hw,
8144 struct ieee80211_vif *vif,
8145 struct inet6_dev *idev)
8147 struct ath11k *ar = hw->priv;
8148 struct ath11k_arp_ns_offload *offload;
8149 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
8150 struct inet6_ifaddr *ifa6;
8151 struct ifacaddr6 *ifaca6;
8152 struct list_head *p;
8155 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac op ipv6 changed\n");
8157 offload = &arvif->arp_ns_offload;
8160 read_lock_bh(&idev->lock);
8162 memset(offload->ipv6_addr, 0, sizeof(offload->ipv6_addr));
8163 memset(offload->self_ipv6_addr, 0, sizeof(offload->self_ipv6_addr));
8164 memcpy(offload->mac_addr, vif->addr, ETH_ALEN);
8166 /* get unicast address */
8167 list_for_each(p, &idev->addr_list) {
8168 if (count >= ATH11K_IPV6_MAX_COUNT)
8171 ifa6 = list_entry(p, struct inet6_ifaddr, if_list);
8172 if (ifa6->flags & IFA_F_DADFAILED)
8174 scope = ipv6_addr_src_scope(&ifa6->addr);
8175 if (scope == IPV6_ADDR_SCOPE_LINKLOCAL ||
8176 scope == IPV6_ADDR_SCOPE_GLOBAL) {
8177 memcpy(offload->ipv6_addr[count], &ifa6->addr.s6_addr,
8178 sizeof(ifa6->addr.s6_addr));
8179 offload->ipv6_type[count] = ATH11K_IPV6_UC_TYPE;
8180 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac count %d ipv6 uc %pI6 scope %d\n",
8181 count, offload->ipv6_addr[count],
8185 ath11k_warn(ar->ab, "Unsupported ipv6 scope: %d\n", scope);
8189 /* get anycast address */
8190 for (ifaca6 = idev->ac_list; ifaca6; ifaca6 = ifaca6->aca_next) {
8191 if (count >= ATH11K_IPV6_MAX_COUNT)
8194 scope = ipv6_addr_src_scope(&ifaca6->aca_addr);
8195 if (scope == IPV6_ADDR_SCOPE_LINKLOCAL ||
8196 scope == IPV6_ADDR_SCOPE_GLOBAL) {
8197 memcpy(offload->ipv6_addr[count], &ifaca6->aca_addr,
8198 sizeof(ifaca6->aca_addr));
8199 offload->ipv6_type[count] = ATH11K_IPV6_AC_TYPE;
8200 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac count %d ipv6 ac %pI6 scope %d\n",
8201 count, offload->ipv6_addr[count],
8205 ath11k_warn(ar->ab, "Unsupported ipv scope: %d\n", scope);
8210 offload->ipv6_count = count;
8211 read_unlock_bh(&idev->lock);
8213 /* generate ns multicast address */
8214 ath11k_generate_ns_mc_addr(ar, offload);
8218 static void ath11k_mac_op_set_rekey_data(struct ieee80211_hw *hw,
8219 struct ieee80211_vif *vif,
8220 struct cfg80211_gtk_rekey_data *data)
8222 struct ath11k *ar = hw->priv;
8223 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
8224 struct ath11k_rekey_data *rekey_data = &arvif->rekey_data;
8226 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac set rekey data vdev %d\n",
8229 mutex_lock(&ar->conf_mutex);
8231 memcpy(rekey_data->kck, data->kck, NL80211_KCK_LEN);
8232 memcpy(rekey_data->kek, data->kek, NL80211_KEK_LEN);
8234 /* The supplicant works on big-endian, the firmware expects it on
8237 rekey_data->replay_ctr = get_unaligned_be64(data->replay_ctr);
8239 arvif->rekey_data.enable_offload = true;
8241 ath11k_dbg_dump(ar->ab, ATH11K_DBG_MAC, "kck", NULL,
8242 rekey_data->kck, NL80211_KCK_LEN);
8243 ath11k_dbg_dump(ar->ab, ATH11K_DBG_MAC, "kek", NULL,
8244 rekey_data->kck, NL80211_KEK_LEN);
8245 ath11k_dbg_dump(ar->ab, ATH11K_DBG_MAC, "replay ctr", NULL,
8246 &rekey_data->replay_ctr, sizeof(rekey_data->replay_ctr));
8248 mutex_unlock(&ar->conf_mutex);
8251 static int ath11k_mac_op_set_bios_sar_specs(struct ieee80211_hw *hw,
8252 const struct cfg80211_sar_specs *sar)
8254 struct ath11k *ar = hw->priv;
8255 const struct cfg80211_sar_sub_specs *sspec;
8260 if (!sar || sar->type != NL80211_SAR_TYPE_POWER ||
8261 sar->num_sub_specs == 0)
8264 mutex_lock(&ar->conf_mutex);
8266 if (!test_bit(WMI_TLV_SERVICE_BIOS_SAR_SUPPORT, ar->ab->wmi_ab.svc_map) ||
8267 !ar->ab->hw_params.bios_sar_capa) {
8272 ret = ath11k_wmi_pdev_set_bios_geo_table_param(ar);
8274 ath11k_warn(ar->ab, "failed to set geo table: %d\n", ret);
8278 sar_tbl = kzalloc(BIOS_SAR_TABLE_LEN, GFP_KERNEL);
8284 sspec = sar->sub_specs;
8285 for (i = 0; i < sar->num_sub_specs; i++) {
8286 if (sspec->freq_range_index >= (BIOS_SAR_TABLE_LEN >> 1)) {
8287 ath11k_warn(ar->ab, "Ignore bad frequency index %u, max allowed %u\n",
8288 sspec->freq_range_index, BIOS_SAR_TABLE_LEN >> 1);
8292 /* chain0 and chain1 share same power setting */
8293 sar_tbl[sspec->freq_range_index] = sspec->power;
8294 index = sspec->freq_range_index + (BIOS_SAR_TABLE_LEN >> 1);
8295 sar_tbl[index] = sspec->power;
8296 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "sar tbl[%d] = %d\n",
8297 sspec->freq_range_index, sar_tbl[sspec->freq_range_index]);
8301 ret = ath11k_wmi_pdev_set_bios_sar_table_param(ar, sar_tbl);
8303 ath11k_warn(ar->ab, "failed to set sar power: %d", ret);
8307 mutex_unlock(&ar->conf_mutex);
8312 static int ath11k_mac_op_cancel_remain_on_channel(struct ieee80211_hw *hw,
8313 struct ieee80211_vif *vif)
8315 struct ath11k *ar = hw->priv;
8317 mutex_lock(&ar->conf_mutex);
8319 spin_lock_bh(&ar->data_lock);
8320 ar->scan.roc_notify = false;
8321 spin_unlock_bh(&ar->data_lock);
8323 ath11k_scan_abort(ar);
8325 mutex_unlock(&ar->conf_mutex);
8327 cancel_delayed_work_sync(&ar->scan.timeout);
8332 static int ath11k_mac_op_remain_on_channel(struct ieee80211_hw *hw,
8333 struct ieee80211_vif *vif,
8334 struct ieee80211_channel *chan,
8336 enum ieee80211_roc_type type)
8338 struct ath11k *ar = hw->priv;
8339 struct ath11k_vif *arvif = (void *)vif->drv_priv;
8340 struct scan_req_params arg;
8344 mutex_lock(&ar->conf_mutex);
8346 spin_lock_bh(&ar->data_lock);
8347 switch (ar->scan.state) {
8348 case ATH11K_SCAN_IDLE:
8349 reinit_completion(&ar->scan.started);
8350 reinit_completion(&ar->scan.completed);
8351 reinit_completion(&ar->scan.on_channel);
8352 ar->scan.state = ATH11K_SCAN_STARTING;
8353 ar->scan.is_roc = true;
8354 ar->scan.vdev_id = arvif->vdev_id;
8355 ar->scan.roc_freq = chan->center_freq;
8356 ar->scan.roc_notify = true;
8359 case ATH11K_SCAN_STARTING:
8360 case ATH11K_SCAN_RUNNING:
8361 case ATH11K_SCAN_ABORTING:
8365 spin_unlock_bh(&ar->data_lock);
8370 scan_time_msec = ar->hw->wiphy->max_remain_on_channel_duration * 2;
8372 memset(&arg, 0, sizeof(arg));
8373 ath11k_wmi_start_scan_init(ar, &arg);
8375 arg.chan_list = kcalloc(arg.num_chan, sizeof(*arg.chan_list),
8377 if (!arg.chan_list) {
8382 arg.vdev_id = arvif->vdev_id;
8383 arg.scan_id = ATH11K_SCAN_ID;
8384 arg.chan_list[0] = chan->center_freq;
8385 arg.dwell_time_active = scan_time_msec;
8386 arg.dwell_time_passive = scan_time_msec;
8387 arg.max_scan_time = scan_time_msec;
8388 arg.scan_flags |= WMI_SCAN_FLAG_PASSIVE;
8389 arg.scan_flags |= WMI_SCAN_FILTER_PROBE_REQ;
8390 arg.burst_duration = duration;
8392 ret = ath11k_start_scan(ar, &arg);
8394 ath11k_warn(ar->ab, "failed to start roc scan: %d\n", ret);
8396 spin_lock_bh(&ar->data_lock);
8397 ar->scan.state = ATH11K_SCAN_IDLE;
8398 spin_unlock_bh(&ar->data_lock);
8399 goto free_chan_list;
8402 ret = wait_for_completion_timeout(&ar->scan.on_channel, 3 * HZ);
8404 ath11k_warn(ar->ab, "failed to switch to channel for roc scan\n");
8405 ret = ath11k_scan_stop(ar);
8407 ath11k_warn(ar->ab, "failed to stop scan: %d\n", ret);
8409 goto free_chan_list;
8412 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
8413 msecs_to_jiffies(duration));
8418 kfree(arg.chan_list);
8420 mutex_unlock(&ar->conf_mutex);
8424 static const struct ieee80211_ops ath11k_ops = {
8425 .tx = ath11k_mac_op_tx,
8426 .start = ath11k_mac_op_start,
8427 .stop = ath11k_mac_op_stop,
8428 .reconfig_complete = ath11k_mac_op_reconfig_complete,
8429 .add_interface = ath11k_mac_op_add_interface,
8430 .remove_interface = ath11k_mac_op_remove_interface,
8431 .update_vif_offload = ath11k_mac_op_update_vif_offload,
8432 .config = ath11k_mac_op_config,
8433 .bss_info_changed = ath11k_mac_op_bss_info_changed,
8434 .configure_filter = ath11k_mac_op_configure_filter,
8435 .hw_scan = ath11k_mac_op_hw_scan,
8436 .cancel_hw_scan = ath11k_mac_op_cancel_hw_scan,
8437 .set_key = ath11k_mac_op_set_key,
8438 .set_rekey_data = ath11k_mac_op_set_rekey_data,
8439 .sta_state = ath11k_mac_op_sta_state,
8440 .sta_set_4addr = ath11k_mac_op_sta_set_4addr,
8441 .sta_set_txpwr = ath11k_mac_op_sta_set_txpwr,
8442 .sta_rc_update = ath11k_mac_op_sta_rc_update,
8443 .conf_tx = ath11k_mac_op_conf_tx,
8444 .set_antenna = ath11k_mac_op_set_antenna,
8445 .get_antenna = ath11k_mac_op_get_antenna,
8446 .ampdu_action = ath11k_mac_op_ampdu_action,
8447 .add_chanctx = ath11k_mac_op_add_chanctx,
8448 .remove_chanctx = ath11k_mac_op_remove_chanctx,
8449 .change_chanctx = ath11k_mac_op_change_chanctx,
8450 .assign_vif_chanctx = ath11k_mac_op_assign_vif_chanctx,
8451 .unassign_vif_chanctx = ath11k_mac_op_unassign_vif_chanctx,
8452 .switch_vif_chanctx = ath11k_mac_op_switch_vif_chanctx,
8453 .set_rts_threshold = ath11k_mac_op_set_rts_threshold,
8454 .set_frag_threshold = ath11k_mac_op_set_frag_threshold,
8455 .set_bitrate_mask = ath11k_mac_op_set_bitrate_mask,
8456 .get_survey = ath11k_mac_op_get_survey,
8457 .flush = ath11k_mac_op_flush,
8458 .sta_statistics = ath11k_mac_op_sta_statistics,
8459 CFG80211_TESTMODE_CMD(ath11k_tm_cmd)
8462 .suspend = ath11k_wow_op_suspend,
8463 .resume = ath11k_wow_op_resume,
8464 .set_wakeup = ath11k_wow_op_set_wakeup,
8467 #ifdef CONFIG_ATH11K_DEBUGFS
8468 .sta_add_debugfs = ath11k_debugfs_sta_op_add,
8471 #if IS_ENABLED(CONFIG_IPV6)
8472 .ipv6_addr_change = ath11k_mac_op_ipv6_changed,
8475 .set_sar_specs = ath11k_mac_op_set_bios_sar_specs,
8476 .remain_on_channel = ath11k_mac_op_remain_on_channel,
8477 .cancel_remain_on_channel = ath11k_mac_op_cancel_remain_on_channel,
8480 static void ath11k_mac_update_ch_list(struct ath11k *ar,
8481 struct ieee80211_supported_band *band,
8482 u32 freq_low, u32 freq_high)
8486 if (!(freq_low && freq_high))
8489 for (i = 0; i < band->n_channels; i++) {
8490 if (band->channels[i].center_freq < freq_low ||
8491 band->channels[i].center_freq > freq_high)
8492 band->channels[i].flags |= IEEE80211_CHAN_DISABLED;
8496 static u32 ath11k_get_phy_id(struct ath11k *ar, u32 band)
8498 struct ath11k_pdev *pdev = ar->pdev;
8499 struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
8501 if (band == WMI_HOST_WLAN_2G_CAP)
8502 return pdev_cap->band[NL80211_BAND_2GHZ].phy_id;
8504 if (band == WMI_HOST_WLAN_5G_CAP)
8505 return pdev_cap->band[NL80211_BAND_5GHZ].phy_id;
8507 ath11k_warn(ar->ab, "unsupported phy cap:%d\n", band);
8512 static int ath11k_mac_setup_channels_rates(struct ath11k *ar,
8513 u32 supported_bands)
8515 struct ieee80211_supported_band *band;
8516 struct ath11k_hal_reg_capabilities_ext *reg_cap, *temp_reg_cap;
8520 BUILD_BUG_ON((ARRAY_SIZE(ath11k_2ghz_channels) +
8521 ARRAY_SIZE(ath11k_5ghz_channels) +
8522 ARRAY_SIZE(ath11k_6ghz_channels)) !=
8525 reg_cap = &ar->ab->hal_reg_cap[ar->pdev_idx];
8526 temp_reg_cap = reg_cap;
8528 if (supported_bands & WMI_HOST_WLAN_2G_CAP) {
8529 channels = kmemdup(ath11k_2ghz_channels,
8530 sizeof(ath11k_2ghz_channels),
8535 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
8536 band->band = NL80211_BAND_2GHZ;
8537 band->n_channels = ARRAY_SIZE(ath11k_2ghz_channels);
8538 band->channels = channels;
8539 band->n_bitrates = ath11k_g_rates_size;
8540 band->bitrates = ath11k_g_rates;
8541 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
8543 if (ar->ab->hw_params.single_pdev_only) {
8544 phy_id = ath11k_get_phy_id(ar, WMI_HOST_WLAN_2G_CAP);
8545 temp_reg_cap = &ar->ab->hal_reg_cap[phy_id];
8547 ath11k_mac_update_ch_list(ar, band,
8548 temp_reg_cap->low_2ghz_chan,
8549 temp_reg_cap->high_2ghz_chan);
8552 if (supported_bands & WMI_HOST_WLAN_5G_CAP) {
8553 if (reg_cap->high_5ghz_chan >= ATH11K_MAX_6G_FREQ) {
8554 channels = kmemdup(ath11k_6ghz_channels,
8555 sizeof(ath11k_6ghz_channels), GFP_KERNEL);
8557 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8561 ar->supports_6ghz = true;
8562 band = &ar->mac.sbands[NL80211_BAND_6GHZ];
8563 band->band = NL80211_BAND_6GHZ;
8564 band->n_channels = ARRAY_SIZE(ath11k_6ghz_channels);
8565 band->channels = channels;
8566 band->n_bitrates = ath11k_a_rates_size;
8567 band->bitrates = ath11k_a_rates;
8568 ar->hw->wiphy->bands[NL80211_BAND_6GHZ] = band;
8570 if (ar->ab->hw_params.single_pdev_only) {
8571 phy_id = ath11k_get_phy_id(ar, WMI_HOST_WLAN_5G_CAP);
8572 temp_reg_cap = &ar->ab->hal_reg_cap[phy_id];
8575 ath11k_mac_update_ch_list(ar, band,
8576 temp_reg_cap->low_5ghz_chan,
8577 temp_reg_cap->high_5ghz_chan);
8580 if (reg_cap->low_5ghz_chan < ATH11K_MIN_6G_FREQ) {
8581 channels = kmemdup(ath11k_5ghz_channels,
8582 sizeof(ath11k_5ghz_channels),
8585 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8586 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
8590 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
8591 band->band = NL80211_BAND_5GHZ;
8592 band->n_channels = ARRAY_SIZE(ath11k_5ghz_channels);
8593 band->channels = channels;
8594 band->n_bitrates = ath11k_a_rates_size;
8595 band->bitrates = ath11k_a_rates;
8596 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
8598 if (ar->ab->hw_params.single_pdev_only) {
8599 phy_id = ath11k_get_phy_id(ar, WMI_HOST_WLAN_5G_CAP);
8600 temp_reg_cap = &ar->ab->hal_reg_cap[phy_id];
8603 ath11k_mac_update_ch_list(ar, band,
8604 temp_reg_cap->low_5ghz_chan,
8605 temp_reg_cap->high_5ghz_chan);
8612 static int ath11k_mac_setup_iface_combinations(struct ath11k *ar)
8614 struct ath11k_base *ab = ar->ab;
8615 struct ieee80211_iface_combination *combinations;
8616 struct ieee80211_iface_limit *limits;
8619 combinations = kzalloc(sizeof(*combinations), GFP_KERNEL);
8625 limits = kcalloc(n_limits, sizeof(*limits), GFP_KERNEL);
8627 kfree(combinations);
8632 limits[0].types |= BIT(NL80211_IFTYPE_STATION);
8635 limits[1].types |= BIT(NL80211_IFTYPE_AP);
8637 if (IS_ENABLED(CONFIG_MAC80211_MESH) &&
8638 ab->hw_params.interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
8639 limits[1].types |= BIT(NL80211_IFTYPE_MESH_POINT);
8641 combinations[0].limits = limits;
8642 combinations[0].n_limits = n_limits;
8643 combinations[0].max_interfaces = 16;
8644 combinations[0].num_different_channels = 1;
8645 combinations[0].beacon_int_infra_match = true;
8646 combinations[0].beacon_int_min_gcd = 100;
8647 combinations[0].radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8648 BIT(NL80211_CHAN_WIDTH_20) |
8649 BIT(NL80211_CHAN_WIDTH_40) |
8650 BIT(NL80211_CHAN_WIDTH_80) |
8651 BIT(NL80211_CHAN_WIDTH_80P80) |
8652 BIT(NL80211_CHAN_WIDTH_160);
8654 ar->hw->wiphy->iface_combinations = combinations;
8655 ar->hw->wiphy->n_iface_combinations = 1;
8660 static const u8 ath11k_if_types_ext_capa[] = {
8661 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
8662 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
8665 static const u8 ath11k_if_types_ext_capa_sta[] = {
8666 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
8667 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
8668 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
8671 static const u8 ath11k_if_types_ext_capa_ap[] = {
8672 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
8673 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
8674 [9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT,
8677 static const struct wiphy_iftype_ext_capab ath11k_iftypes_ext_capa[] = {
8679 .extended_capabilities = ath11k_if_types_ext_capa,
8680 .extended_capabilities_mask = ath11k_if_types_ext_capa,
8681 .extended_capabilities_len = sizeof(ath11k_if_types_ext_capa),
8683 .iftype = NL80211_IFTYPE_STATION,
8684 .extended_capabilities = ath11k_if_types_ext_capa_sta,
8685 .extended_capabilities_mask = ath11k_if_types_ext_capa_sta,
8686 .extended_capabilities_len =
8687 sizeof(ath11k_if_types_ext_capa_sta),
8689 .iftype = NL80211_IFTYPE_AP,
8690 .extended_capabilities = ath11k_if_types_ext_capa_ap,
8691 .extended_capabilities_mask = ath11k_if_types_ext_capa_ap,
8692 .extended_capabilities_len =
8693 sizeof(ath11k_if_types_ext_capa_ap),
8697 static void __ath11k_mac_unregister(struct ath11k *ar)
8699 cancel_work_sync(&ar->regd_update_work);
8701 ieee80211_unregister_hw(ar->hw);
8703 idr_for_each(&ar->txmgmt_idr, ath11k_mac_tx_mgmt_pending_free, ar);
8704 idr_destroy(&ar->txmgmt_idr);
8706 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8707 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8708 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
8710 kfree(ar->hw->wiphy->iface_combinations[0].limits);
8711 kfree(ar->hw->wiphy->iface_combinations);
8713 SET_IEEE80211_DEV(ar->hw, NULL);
8716 void ath11k_mac_unregister(struct ath11k_base *ab)
8719 struct ath11k_pdev *pdev;
8722 for (i = 0; i < ab->num_radios; i++) {
8723 pdev = &ab->pdevs[i];
8728 __ath11k_mac_unregister(ar);
8731 ath11k_peer_rhash_tbl_destroy(ab);
8734 static int __ath11k_mac_register(struct ath11k *ar)
8736 struct ath11k_base *ab = ar->ab;
8737 struct ath11k_pdev_cap *cap = &ar->pdev->cap;
8738 static const u32 cipher_suites[] = {
8739 WLAN_CIPHER_SUITE_TKIP,
8740 WLAN_CIPHER_SUITE_CCMP,
8741 WLAN_CIPHER_SUITE_AES_CMAC,
8742 WLAN_CIPHER_SUITE_BIP_CMAC_256,
8743 WLAN_CIPHER_SUITE_BIP_GMAC_128,
8744 WLAN_CIPHER_SUITE_BIP_GMAC_256,
8745 WLAN_CIPHER_SUITE_GCMP,
8746 WLAN_CIPHER_SUITE_GCMP_256,
8747 WLAN_CIPHER_SUITE_CCMP_256,
8752 ath11k_pdev_caps_update(ar);
8754 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8756 SET_IEEE80211_DEV(ar->hw, ab->dev);
8758 ret = ath11k_mac_setup_channels_rates(ar,
8759 cap->supported_bands);
8763 ath11k_mac_setup_ht_vht_cap(ar, cap, &ht_cap);
8764 ath11k_mac_setup_he_cap(ar, cap);
8766 ret = ath11k_mac_setup_iface_combinations(ar);
8768 ath11k_err(ar->ab, "failed to setup interface combinations: %d\n", ret);
8769 goto err_free_channels;
8772 ar->hw->wiphy->available_antennas_rx = cap->rx_chain_mask;
8773 ar->hw->wiphy->available_antennas_tx = cap->tx_chain_mask;
8775 ar->hw->wiphy->interface_modes = ab->hw_params.interface_modes;
8777 if (ab->hw_params.single_pdev_only && ar->supports_6ghz)
8778 ieee80211_hw_set(ar->hw, SINGLE_SCAN_ON_ALL_BANDS);
8780 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8781 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8782 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8783 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8784 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8785 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8786 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8787 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8788 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8789 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8790 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8791 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8792 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8793 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
8794 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
8796 if (ath11k_frame_mode == ATH11K_HW_TXRX_ETHERNET) {
8797 ieee80211_hw_set(ar->hw, SUPPORTS_TX_ENCAP_OFFLOAD);
8798 ieee80211_hw_set(ar->hw, SUPPORTS_RX_DECAP_OFFLOAD);
8801 if (cap->nss_ratio_enabled)
8802 ieee80211_hw_set(ar->hw, SUPPORTS_VHT_EXT_NSS_BW);
8804 if ((ht_cap & WMI_HT_CAP_ENABLED) || ar->supports_6ghz) {
8805 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8806 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8807 ieee80211_hw_set(ar->hw, SUPPORTS_REORDERING_BUFFER);
8808 ieee80211_hw_set(ar->hw, SUPPORTS_AMSDU_IN_AMPDU);
8809 ieee80211_hw_set(ar->hw, USES_RSS);
8812 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8813 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8815 /* TODO: Check if HT capability advertised from firmware is different
8816 * for each band for a dual band capable radio. It will be tricky to
8817 * handle it when the ht capability different for each band.
8819 if (ht_cap & WMI_HT_CAP_DYNAMIC_SMPS ||
8820 (ar->supports_6ghz && ab->hw_params.supports_dynamic_smps_6ghz))
8821 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8823 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8824 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8826 ar->hw->max_listen_interval = ATH11K_MAX_HW_LISTEN_INTERVAL;
8828 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8829 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8830 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8832 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8833 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8834 NL80211_FEATURE_AP_SCAN;
8836 ar->max_num_stations = TARGET_NUM_STATIONS(ab);
8837 ar->max_num_peers = TARGET_NUM_PEERS_PDEV(ab);
8839 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8841 if (test_bit(WMI_TLV_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi->wmi_ab->svc_map)) {
8842 ar->hw->wiphy->features |=
8843 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
8846 if (test_bit(WMI_TLV_SERVICE_NLO, ar->wmi->wmi_ab->svc_map)) {
8847 ar->hw->wiphy->max_sched_scan_ssids = WMI_PNO_MAX_SUPP_NETWORKS;
8848 ar->hw->wiphy->max_match_sets = WMI_PNO_MAX_SUPP_NETWORKS;
8849 ar->hw->wiphy->max_sched_scan_ie_len = WMI_PNO_MAX_IE_LENGTH;
8850 ar->hw->wiphy->max_sched_scan_plans = WMI_PNO_MAX_SCHED_SCAN_PLANS;
8851 ar->hw->wiphy->max_sched_scan_plan_interval =
8852 WMI_PNO_MAX_SCHED_SCAN_PLAN_INT;
8853 ar->hw->wiphy->max_sched_scan_plan_iterations =
8854 WMI_PNO_MAX_SCHED_SCAN_PLAN_ITRNS;
8855 ar->hw->wiphy->features |= NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
8858 ret = ath11k_wow_init(ar);
8860 ath11k_warn(ar->ab, "failed to init wow: %d\n", ret);
8861 goto err_free_if_combs;
8864 ar->hw->queues = ATH11K_HW_MAX_QUEUES;
8865 ar->hw->wiphy->tx_queue_len = ATH11K_QUEUE_LEN;
8866 ar->hw->offchannel_tx_hw_queue = ATH11K_HW_MAX_QUEUES - 1;
8867 ar->hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_HE;
8869 ar->hw->vif_data_size = sizeof(struct ath11k_vif);
8870 ar->hw->sta_data_size = sizeof(struct ath11k_sta);
8872 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
8873 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_STA_TX_PWR);
8874 if (test_bit(WMI_TLV_SERVICE_BSS_COLOR_OFFLOAD,
8875 ar->ab->wmi_ab.svc_map)) {
8876 wiphy_ext_feature_set(ar->hw->wiphy,
8877 NL80211_EXT_FEATURE_BSS_COLOR);
8878 ieee80211_hw_set(ar->hw, DETECTS_COLOR_COLLISION);
8881 ar->hw->wiphy->cipher_suites = cipher_suites;
8882 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
8884 ar->hw->wiphy->iftype_ext_capab = ath11k_iftypes_ext_capa;
8885 ar->hw->wiphy->num_iftype_ext_capab =
8886 ARRAY_SIZE(ath11k_iftypes_ext_capa);
8888 if (ar->supports_6ghz) {
8889 wiphy_ext_feature_set(ar->hw->wiphy,
8890 NL80211_EXT_FEATURE_FILS_DISCOVERY);
8891 wiphy_ext_feature_set(ar->hw->wiphy,
8892 NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP);
8895 ath11k_reg_init(ar);
8897 if (!test_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags)) {
8898 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8899 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8900 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8903 if (test_bit(WMI_TLV_SERVICE_BIOS_SAR_SUPPORT, ar->ab->wmi_ab.svc_map) &&
8904 ab->hw_params.bios_sar_capa)
8905 ar->hw->wiphy->sar_capa = ab->hw_params.bios_sar_capa;
8907 ret = ieee80211_register_hw(ar->hw);
8909 ath11k_err(ar->ab, "ieee80211 registration failed: %d\n", ret);
8910 goto err_free_if_combs;
8913 if (!ab->hw_params.supports_monitor)
8914 /* There's a race between calling ieee80211_register_hw()
8915 * and here where the monitor mode is enabled for a little
8916 * while. But that time is so short and in practise it make
8917 * a difference in real life.
8919 ar->hw->wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MONITOR);
8921 /* Apply the regd received during initialization */
8922 ret = ath11k_regd_update(ar);
8924 ath11k_err(ar->ab, "ath11k regd update failed: %d\n", ret);
8925 goto err_unregister_hw;
8928 if (ab->hw_params.current_cc_support && ab->new_alpha2[0]) {
8929 struct wmi_set_current_country_params set_current_param = {};
8931 memcpy(&set_current_param.alpha2, ab->new_alpha2, 2);
8932 memcpy(&ar->alpha2, ab->new_alpha2, 2);
8933 ret = ath11k_wmi_send_set_current_country_cmd(ar, &set_current_param);
8936 "failed set cc code for mac register: %d\n", ret);
8939 ret = ath11k_debugfs_register(ar);
8941 ath11k_err(ar->ab, "debugfs registration failed: %d\n", ret);
8942 goto err_unregister_hw;
8948 ieee80211_unregister_hw(ar->hw);
8951 kfree(ar->hw->wiphy->iface_combinations[0].limits);
8952 kfree(ar->hw->wiphy->iface_combinations);
8955 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8956 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8957 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
8960 SET_IEEE80211_DEV(ar->hw, NULL);
8964 int ath11k_mac_register(struct ath11k_base *ab)
8967 struct ath11k_pdev *pdev;
8971 if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags))
8974 /* Initialize channel counters frequency value in hertz */
8975 ab->cc_freq_hz = IPQ8074_CC_FREQ_HERTZ;
8976 ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS(ab))) - 1;
8978 ret = ath11k_peer_rhash_tbl_init(ab);
8982 for (i = 0; i < ab->num_radios; i++) {
8983 pdev = &ab->pdevs[i];
8985 if (ab->pdevs_macaddr_valid) {
8986 ether_addr_copy(ar->mac_addr, pdev->mac_addr);
8988 ether_addr_copy(ar->mac_addr, ab->mac_addr);
8989 ar->mac_addr[4] += i;
8992 idr_init(&ar->txmgmt_idr);
8993 spin_lock_init(&ar->txmgmt_idr_lock);
8995 ret = __ath11k_mac_register(ar);
8999 init_waitqueue_head(&ar->txmgmt_empty_waitq);
9005 for (i = i - 1; i >= 0; i--) {
9006 pdev = &ab->pdevs[i];
9008 __ath11k_mac_unregister(ar);
9011 ath11k_peer_rhash_tbl_destroy(ab);
9016 int ath11k_mac_allocate(struct ath11k_base *ab)
9018 struct ieee80211_hw *hw;
9020 struct ath11k_pdev *pdev;
9024 if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags))
9027 for (i = 0; i < ab->num_radios; i++) {
9028 pdev = &ab->pdevs[i];
9029 hw = ieee80211_alloc_hw(sizeof(struct ath11k), &ath11k_ops);
9031 ath11k_warn(ab, "failed to allocate mac80211 hw device\n");
9041 ar->lmac_id = ath11k_hw_get_mac_from_pdev_id(&ab->hw_params, i);
9043 ar->wmi = &ab->wmi_ab.wmi[i];
9044 /* FIXME wmi[0] is already initialized during attach,
9045 * Should we do this again?
9047 ath11k_wmi_pdev_attach(ab, i);
9049 ar->cfg_tx_chainmask = pdev->cap.tx_chain_mask;
9050 ar->cfg_rx_chainmask = pdev->cap.rx_chain_mask;
9051 ar->num_tx_chains = get_num_chains(pdev->cap.tx_chain_mask);
9052 ar->num_rx_chains = get_num_chains(pdev->cap.rx_chain_mask);
9055 spin_lock_init(&ar->data_lock);
9056 INIT_LIST_HEAD(&ar->arvifs);
9057 INIT_LIST_HEAD(&ar->ppdu_stats_info);
9058 mutex_init(&ar->conf_mutex);
9059 init_completion(&ar->vdev_setup_done);
9060 init_completion(&ar->vdev_delete_done);
9061 init_completion(&ar->peer_assoc_done);
9062 init_completion(&ar->peer_delete_done);
9063 init_completion(&ar->install_key_done);
9064 init_completion(&ar->bss_survey_done);
9065 init_completion(&ar->scan.started);
9066 init_completion(&ar->scan.completed);
9067 init_completion(&ar->scan.on_channel);
9068 init_completion(&ar->thermal.wmi_sync);
9070 INIT_DELAYED_WORK(&ar->scan.timeout, ath11k_scan_timeout_work);
9071 INIT_WORK(&ar->regd_update_work, ath11k_regd_update_work);
9073 INIT_WORK(&ar->wmi_mgmt_tx_work, ath11k_mgmt_over_wmi_tx_work);
9074 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
9076 clear_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags);
9078 ar->monitor_vdev_id = -1;
9079 clear_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags);
9080 ar->vdev_id_11d_scan = ATH11K_11D_INVALID_VDEV_ID;
9081 init_completion(&ar->completed_11d_scan);
9087 ath11k_mac_destroy(ab);
9092 void ath11k_mac_destroy(struct ath11k_base *ab)
9095 struct ath11k_pdev *pdev;
9098 for (i = 0; i < ab->num_radios; i++) {
9099 pdev = &ab->pdevs[i];
9104 ieee80211_free_hw(ar->hw);
9109 int ath11k_mac_vif_set_keepalive(struct ath11k_vif *arvif,
9110 enum wmi_sta_keepalive_method method,
9113 struct ath11k *ar = arvif->ar;
9114 struct wmi_sta_keepalive_arg arg = {};
9117 lockdep_assert_held(&ar->conf_mutex);
9119 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
9122 if (!test_bit(WMI_TLV_SERVICE_STA_KEEP_ALIVE, ar->ab->wmi_ab.svc_map))
9125 arg.vdev_id = arvif->vdev_id;
9127 arg.method = method;
9128 arg.interval = interval;
9130 ret = ath11k_wmi_sta_keepalive(ar, &arg);
9132 ath11k_warn(ar->ab, "failed to set keepalive on vdev %i: %d\n",
9133 arvif->vdev_id, ret);