1 // SPDX-License-Identifier: BSD-3-Clause-Clear
3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved.
7 #include <net/mac80211.h>
8 #include <linux/etherdevice.h>
18 #include "debugfs_sta.h"
20 #define CHAN2G(_channel, _freq, _flags) { \
21 .band = NL80211_BAND_2GHZ, \
22 .hw_value = (_channel), \
23 .center_freq = (_freq), \
25 .max_antenna_gain = 0, \
29 #define CHAN5G(_channel, _freq, _flags) { \
30 .band = NL80211_BAND_5GHZ, \
31 .hw_value = (_channel), \
32 .center_freq = (_freq), \
34 .max_antenna_gain = 0, \
38 #define CHAN6G(_channel, _freq, _flags) { \
39 .band = NL80211_BAND_6GHZ, \
40 .hw_value = (_channel), \
41 .center_freq = (_freq), \
43 .max_antenna_gain = 0, \
47 static const struct ieee80211_channel ath11k_2ghz_channels[] = {
64 static const struct ieee80211_channel ath11k_5ghz_channels[] = {
94 static const struct ieee80211_channel ath11k_6ghz_channels[] = {
120 CHAN6G(101, 6455, 0),
121 CHAN6G(105, 6475, 0),
122 CHAN6G(109, 6495, 0),
123 CHAN6G(113, 6515, 0),
124 CHAN6G(117, 6535, 0),
125 CHAN6G(121, 6555, 0),
126 CHAN6G(125, 6575, 0),
127 CHAN6G(129, 6595, 0),
128 CHAN6G(133, 6615, 0),
129 CHAN6G(137, 6635, 0),
130 CHAN6G(141, 6655, 0),
131 CHAN6G(145, 6675, 0),
132 CHAN6G(149, 6695, 0),
133 CHAN6G(153, 6715, 0),
134 CHAN6G(157, 6735, 0),
135 CHAN6G(161, 6755, 0),
136 CHAN6G(165, 6775, 0),
137 CHAN6G(169, 6795, 0),
138 CHAN6G(173, 6815, 0),
139 CHAN6G(177, 6835, 0),
140 CHAN6G(181, 6855, 0),
141 CHAN6G(185, 6875, 0),
142 CHAN6G(189, 6895, 0),
143 CHAN6G(193, 6915, 0),
144 CHAN6G(197, 6935, 0),
145 CHAN6G(201, 6955, 0),
146 CHAN6G(205, 6975, 0),
147 CHAN6G(209, 6995, 0),
148 CHAN6G(213, 7015, 0),
149 CHAN6G(217, 7035, 0),
150 CHAN6G(221, 7055, 0),
151 CHAN6G(225, 7075, 0),
152 CHAN6G(229, 7095, 0),
153 CHAN6G(233, 7115, 0),
155 /* new addition in IEEE Std 802.11ax-2021 */
159 static struct ieee80211_rate ath11k_legacy_rates[] = {
161 .hw_value = ATH11K_HW_RATE_CCK_LP_1M },
163 .hw_value = ATH11K_HW_RATE_CCK_LP_2M,
164 .hw_value_short = ATH11K_HW_RATE_CCK_SP_2M,
165 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
167 .hw_value = ATH11K_HW_RATE_CCK_LP_5_5M,
168 .hw_value_short = ATH11K_HW_RATE_CCK_SP_5_5M,
169 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
171 .hw_value = ATH11K_HW_RATE_CCK_LP_11M,
172 .hw_value_short = ATH11K_HW_RATE_CCK_SP_11M,
173 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
175 { .bitrate = 60, .hw_value = ATH11K_HW_RATE_OFDM_6M },
176 { .bitrate = 90, .hw_value = ATH11K_HW_RATE_OFDM_9M },
177 { .bitrate = 120, .hw_value = ATH11K_HW_RATE_OFDM_12M },
178 { .bitrate = 180, .hw_value = ATH11K_HW_RATE_OFDM_18M },
179 { .bitrate = 240, .hw_value = ATH11K_HW_RATE_OFDM_24M },
180 { .bitrate = 360, .hw_value = ATH11K_HW_RATE_OFDM_36M },
181 { .bitrate = 480, .hw_value = ATH11K_HW_RATE_OFDM_48M },
182 { .bitrate = 540, .hw_value = ATH11K_HW_RATE_OFDM_54M },
186 ath11k_phymodes[NUM_NL80211_BANDS][ATH11K_CHAN_WIDTH_NUM] = {
187 [NL80211_BAND_2GHZ] = {
188 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
189 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
190 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20_2G,
191 [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20_2G,
192 [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40_2G,
193 [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80_2G,
194 [NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN,
195 [NL80211_CHAN_WIDTH_160] = MODE_UNKNOWN,
197 [NL80211_BAND_5GHZ] = {
198 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
199 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
200 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20,
201 [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20,
202 [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40,
203 [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80,
204 [NL80211_CHAN_WIDTH_160] = MODE_11AX_HE160,
205 [NL80211_CHAN_WIDTH_80P80] = MODE_11AX_HE80_80,
207 [NL80211_BAND_6GHZ] = {
208 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
209 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
210 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20,
211 [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20,
212 [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40,
213 [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80,
214 [NL80211_CHAN_WIDTH_160] = MODE_11AX_HE160,
215 [NL80211_CHAN_WIDTH_80P80] = MODE_11AX_HE80_80,
220 const struct htt_rx_ring_tlv_filter ath11k_mac_mon_status_filter_default = {
221 .rx_filter = HTT_RX_FILTER_TLV_FLAGS_MPDU_START |
222 HTT_RX_FILTER_TLV_FLAGS_PPDU_END |
223 HTT_RX_FILTER_TLV_FLAGS_PPDU_END_STATUS_DONE,
224 .pkt_filter_flags0 = HTT_RX_FP_MGMT_FILTER_FLAGS0,
225 .pkt_filter_flags1 = HTT_RX_FP_MGMT_FILTER_FLAGS1,
226 .pkt_filter_flags2 = HTT_RX_FP_CTRL_FILTER_FLASG2,
227 .pkt_filter_flags3 = HTT_RX_FP_DATA_FILTER_FLASG3 |
228 HTT_RX_FP_CTRL_FILTER_FLASG3
231 #define ATH11K_MAC_FIRST_OFDM_RATE_IDX 4
232 #define ath11k_g_rates ath11k_legacy_rates
233 #define ath11k_g_rates_size (ARRAY_SIZE(ath11k_legacy_rates))
234 #define ath11k_a_rates (ath11k_legacy_rates + 4)
235 #define ath11k_a_rates_size (ARRAY_SIZE(ath11k_legacy_rates) - 4)
237 #define ATH11K_MAC_SCAN_TIMEOUT_MSECS 200 /* in msecs */
239 static const u32 ath11k_smps_map[] = {
240 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
241 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
242 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
243 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
246 static int ath11k_start_vdev_delay(struct ieee80211_hw *hw,
247 struct ieee80211_vif *vif);
249 enum nl80211_he_ru_alloc ath11k_mac_phy_he_ru_to_nl80211_he_ru_alloc(u16 ru_phy)
251 enum nl80211_he_ru_alloc ret;
255 ret = NL80211_RATE_INFO_HE_RU_ALLOC_26;
258 ret = NL80211_RATE_INFO_HE_RU_ALLOC_52;
261 ret = NL80211_RATE_INFO_HE_RU_ALLOC_106;
264 ret = NL80211_RATE_INFO_HE_RU_ALLOC_242;
267 ret = NL80211_RATE_INFO_HE_RU_ALLOC_484;
270 ret = NL80211_RATE_INFO_HE_RU_ALLOC_996;
273 ret = NL80211_RATE_INFO_HE_RU_ALLOC_26;
280 enum nl80211_he_ru_alloc ath11k_mac_he_ru_tones_to_nl80211_he_ru_alloc(u16 ru_tones)
282 enum nl80211_he_ru_alloc ret;
286 ret = NL80211_RATE_INFO_HE_RU_ALLOC_26;
289 ret = NL80211_RATE_INFO_HE_RU_ALLOC_52;
292 ret = NL80211_RATE_INFO_HE_RU_ALLOC_106;
295 ret = NL80211_RATE_INFO_HE_RU_ALLOC_242;
298 ret = NL80211_RATE_INFO_HE_RU_ALLOC_484;
301 ret = NL80211_RATE_INFO_HE_RU_ALLOC_996;
304 ret = NL80211_RATE_INFO_HE_RU_ALLOC_2x996;
307 ret = NL80211_RATE_INFO_HE_RU_ALLOC_26;
314 enum nl80211_he_gi ath11k_mac_he_gi_to_nl80211_he_gi(u8 sgi)
316 enum nl80211_he_gi ret;
319 case RX_MSDU_START_SGI_0_8_US:
320 ret = NL80211_RATE_INFO_HE_GI_0_8;
322 case RX_MSDU_START_SGI_1_6_US:
323 ret = NL80211_RATE_INFO_HE_GI_1_6;
325 case RX_MSDU_START_SGI_3_2_US:
326 ret = NL80211_RATE_INFO_HE_GI_3_2;
329 ret = NL80211_RATE_INFO_HE_GI_0_8;
336 u8 ath11k_mac_bw_to_mac80211_bw(u8 bw)
342 ret = RATE_INFO_BW_20;
345 ret = RATE_INFO_BW_40;
348 ret = RATE_INFO_BW_80;
351 ret = RATE_INFO_BW_160;
358 enum ath11k_supported_bw ath11k_mac_mac80211_bw_to_ath11k_bw(enum rate_info_bw bw)
361 case RATE_INFO_BW_20:
363 case RATE_INFO_BW_40:
365 case RATE_INFO_BW_80:
367 case RATE_INFO_BW_160:
368 return ATH11K_BW_160;
374 int ath11k_mac_hw_ratecode_to_legacy_rate(u8 hw_rc, u8 preamble, u8 *rateidx,
377 /* As default, it is OFDM rates */
378 int i = ATH11K_MAC_FIRST_OFDM_RATE_IDX;
379 int max_rates_idx = ath11k_g_rates_size;
381 if (preamble == WMI_RATE_PREAMBLE_CCK) {
382 hw_rc &= ~ATH11k_HW_RATECODE_CCK_SHORT_PREAM_MASK;
384 max_rates_idx = ATH11K_MAC_FIRST_OFDM_RATE_IDX;
387 while (i < max_rates_idx) {
388 if (hw_rc == ath11k_legacy_rates[i].hw_value) {
390 *rate = ath11k_legacy_rates[i].bitrate;
399 static int get_num_chains(u32 mask)
412 u8 ath11k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
417 for (i = 0; i < sband->n_bitrates; i++)
418 if (sband->bitrates[i].bitrate == bitrate)
425 ath11k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
429 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
430 if (ht_mcs_mask[nss])
437 ath11k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
441 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
442 if (vht_mcs_mask[nss])
449 ath11k_mac_max_he_nss(const u16 he_mcs_mask[NL80211_HE_NSS_MAX])
453 for (nss = NL80211_HE_NSS_MAX - 1; nss >= 0; nss--)
454 if (he_mcs_mask[nss])
460 static u8 ath11k_parse_mpdudensity(u8 mpdudensity)
462 /* 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
463 * 0 for no restriction
472 switch (mpdudensity) {
478 /* Our lower layer calculations limit our precision to
495 static int ath11k_mac_vif_chan(struct ieee80211_vif *vif,
496 struct cfg80211_chan_def *def)
498 struct ieee80211_chanctx_conf *conf;
501 conf = rcu_dereference(vif->chanctx_conf);
513 static bool ath11k_mac_bitrate_is_cck(int bitrate)
526 u8 ath11k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
527 u8 hw_rate, bool cck)
529 const struct ieee80211_rate *rate;
532 for (i = 0; i < sband->n_bitrates; i++) {
533 rate = &sband->bitrates[i];
535 if (ath11k_mac_bitrate_is_cck(rate->bitrate) != cck)
538 if (rate->hw_value == hw_rate)
540 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
541 rate->hw_value_short == hw_rate)
548 static u8 ath11k_mac_bitrate_to_rate(int bitrate)
550 return DIV_ROUND_UP(bitrate, 5) |
551 (ath11k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
554 static void ath11k_get_arvif_iter(void *data, u8 *mac,
555 struct ieee80211_vif *vif)
557 struct ath11k_vif_iter *arvif_iter = data;
558 struct ath11k_vif *arvif = (void *)vif->drv_priv;
560 if (arvif->vdev_id == arvif_iter->vdev_id)
561 arvif_iter->arvif = arvif;
564 struct ath11k_vif *ath11k_mac_get_arvif(struct ath11k *ar, u32 vdev_id)
566 struct ath11k_vif_iter arvif_iter;
569 memset(&arvif_iter, 0, sizeof(struct ath11k_vif_iter));
570 arvif_iter.vdev_id = vdev_id;
572 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
573 ieee80211_iterate_active_interfaces_atomic(ar->hw,
575 ath11k_get_arvif_iter,
577 if (!arvif_iter.arvif) {
578 ath11k_warn(ar->ab, "No VIF found for vdev %d\n", vdev_id);
582 return arvif_iter.arvif;
585 struct ath11k_vif *ath11k_mac_get_arvif_by_vdev_id(struct ath11k_base *ab,
589 struct ath11k_pdev *pdev;
590 struct ath11k_vif *arvif;
592 for (i = 0; i < ab->num_radios; i++) {
593 pdev = rcu_dereference(ab->pdevs_active[i]);
594 if (pdev && pdev->ar &&
595 (pdev->ar->allocated_vdev_map & (1LL << vdev_id))) {
596 arvif = ath11k_mac_get_arvif(pdev->ar, vdev_id);
605 struct ath11k *ath11k_mac_get_ar_by_vdev_id(struct ath11k_base *ab, u32 vdev_id)
608 struct ath11k_pdev *pdev;
610 for (i = 0; i < ab->num_radios; i++) {
611 pdev = rcu_dereference(ab->pdevs_active[i]);
612 if (pdev && pdev->ar) {
613 if (pdev->ar->allocated_vdev_map & (1LL << vdev_id))
621 struct ath11k *ath11k_mac_get_ar_by_pdev_id(struct ath11k_base *ab, u32 pdev_id)
624 struct ath11k_pdev *pdev;
626 if (ab->hw_params.single_pdev_only) {
627 pdev = rcu_dereference(ab->pdevs_active[0]);
628 return pdev ? pdev->ar : NULL;
631 if (WARN_ON(pdev_id > ab->num_radios))
634 for (i = 0; i < ab->num_radios; i++) {
635 pdev = rcu_dereference(ab->pdevs_active[i]);
637 if (pdev && pdev->pdev_id == pdev_id)
638 return (pdev->ar ? pdev->ar : NULL);
644 struct ath11k_vif *ath11k_mac_get_vif_up(struct ath11k_base *ab)
647 struct ath11k_pdev *pdev;
648 struct ath11k_vif *arvif;
651 for (i = 0; i < ab->num_radios; i++) {
652 pdev = &ab->pdevs[i];
654 list_for_each_entry(arvif, &ar->arvifs, list) {
663 static bool ath11k_mac_band_match(enum nl80211_band band1, enum WMI_HOST_WLAN_BAND band2)
665 return (((band1 == NL80211_BAND_2GHZ) && (band2 & WMI_HOST_WLAN_2G_CAP)) ||
666 (((band1 == NL80211_BAND_5GHZ) || (band1 == NL80211_BAND_6GHZ)) &&
667 (band2 & WMI_HOST_WLAN_5G_CAP)));
670 u8 ath11k_mac_get_target_pdev_id_from_vif(struct ath11k_vif *arvif)
672 struct ath11k *ar = arvif->ar;
673 struct ath11k_base *ab = ar->ab;
674 struct ieee80211_vif *vif = arvif->vif;
675 struct cfg80211_chan_def def;
676 enum nl80211_band band;
677 u8 pdev_id = ab->target_pdev_ids[0].pdev_id;
680 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
683 band = def.chan->band;
685 for (i = 0; i < ab->target_pdev_count; i++) {
686 if (ath11k_mac_band_match(band, ab->target_pdev_ids[i].supported_bands))
687 return ab->target_pdev_ids[i].pdev_id;
693 u8 ath11k_mac_get_target_pdev_id(struct ath11k *ar)
695 struct ath11k_vif *arvif;
697 arvif = ath11k_mac_get_vif_up(ar->ab);
700 return ath11k_mac_get_target_pdev_id_from_vif(arvif);
702 return ar->ab->target_pdev_ids[0].pdev_id;
705 static void ath11k_pdev_caps_update(struct ath11k *ar)
707 struct ath11k_base *ab = ar->ab;
709 ar->max_tx_power = ab->target_caps.hw_max_tx_power;
711 /* FIXME Set min_tx_power to ab->target_caps.hw_min_tx_power.
712 * But since the received value in svcrdy is same as hw_max_tx_power,
713 * we can set ar->min_tx_power to 0 currently until
714 * this is fixed in firmware
716 ar->min_tx_power = 0;
718 ar->txpower_limit_2g = ar->max_tx_power;
719 ar->txpower_limit_5g = ar->max_tx_power;
720 ar->txpower_scale = WMI_HOST_TP_SCALE_MAX;
723 static int ath11k_mac_txpower_recalc(struct ath11k *ar)
725 struct ath11k_pdev *pdev = ar->pdev;
726 struct ath11k_vif *arvif;
727 int ret, txpower = -1;
730 lockdep_assert_held(&ar->conf_mutex);
732 list_for_each_entry(arvif, &ar->arvifs, list) {
733 if (arvif->txpower <= 0)
737 txpower = arvif->txpower;
739 txpower = min(txpower, arvif->txpower);
745 /* txpwr is set as 2 units per dBm in FW*/
746 txpower = min_t(u32, max_t(u32, ar->min_tx_power, txpower),
747 ar->max_tx_power) * 2;
749 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "txpower to set in hw %d\n",
752 if ((pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) &&
753 ar->txpower_limit_2g != txpower) {
754 param = WMI_PDEV_PARAM_TXPOWER_LIMIT2G;
755 ret = ath11k_wmi_pdev_set_param(ar, param,
756 txpower, ar->pdev->pdev_id);
759 ar->txpower_limit_2g = txpower;
762 if ((pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) &&
763 ar->txpower_limit_5g != txpower) {
764 param = WMI_PDEV_PARAM_TXPOWER_LIMIT5G;
765 ret = ath11k_wmi_pdev_set_param(ar, param,
766 txpower, ar->pdev->pdev_id);
769 ar->txpower_limit_5g = txpower;
775 ath11k_warn(ar->ab, "failed to recalc txpower limit %d using pdev param %d: %d\n",
776 txpower / 2, param, ret);
780 static int ath11k_recalc_rtscts_prot(struct ath11k_vif *arvif)
782 struct ath11k *ar = arvif->ar;
783 u32 vdev_param, rts_cts = 0;
786 lockdep_assert_held(&ar->conf_mutex);
788 vdev_param = WMI_VDEV_PARAM_ENABLE_RTSCTS;
790 /* Enable RTS/CTS protection for sw retries (when legacy stations
791 * are in BSS) or by default only for second rate series.
792 * TODO: Check if we need to enable CTS 2 Self in any case
794 rts_cts = WMI_USE_RTS_CTS;
796 if (arvif->num_legacy_stations > 0)
797 rts_cts |= WMI_RTSCTS_ACROSS_SW_RETRIES << 4;
799 rts_cts |= WMI_RTSCTS_FOR_SECOND_RATESERIES << 4;
801 /* Need not send duplicate param value to firmware */
802 if (arvif->rtscts_prot_mode == rts_cts)
805 arvif->rtscts_prot_mode = rts_cts;
807 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
808 arvif->vdev_id, rts_cts);
810 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
811 vdev_param, rts_cts);
813 ath11k_warn(ar->ab, "failed to recalculate rts/cts prot for vdev %d: %d\n",
814 arvif->vdev_id, ret);
819 static int ath11k_mac_set_kickout(struct ath11k_vif *arvif)
821 struct ath11k *ar = arvif->ar;
825 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_STA_KICKOUT_TH,
826 ATH11K_KICKOUT_THRESHOLD,
829 ath11k_warn(ar->ab, "failed to set kickout threshold on vdev %i: %d\n",
830 arvif->vdev_id, ret);
834 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS;
835 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
836 ATH11K_KEEPALIVE_MIN_IDLE);
838 ath11k_warn(ar->ab, "failed to set keepalive minimum idle time on vdev %i: %d\n",
839 arvif->vdev_id, ret);
843 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS;
844 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
845 ATH11K_KEEPALIVE_MAX_IDLE);
847 ath11k_warn(ar->ab, "failed to set keepalive maximum idle time on vdev %i: %d\n",
848 arvif->vdev_id, ret);
852 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS;
853 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
854 ATH11K_KEEPALIVE_MAX_UNRESPONSIVE);
856 ath11k_warn(ar->ab, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
857 arvif->vdev_id, ret);
864 void ath11k_mac_peer_cleanup_all(struct ath11k *ar)
866 struct ath11k_peer *peer, *tmp;
867 struct ath11k_base *ab = ar->ab;
869 lockdep_assert_held(&ar->conf_mutex);
871 spin_lock_bh(&ab->base_lock);
872 list_for_each_entry_safe(peer, tmp, &ab->peers, list) {
873 ath11k_peer_rx_tid_cleanup(ar, peer);
874 list_del(&peer->list);
877 spin_unlock_bh(&ab->base_lock);
880 ar->num_stations = 0;
883 static inline int ath11k_mac_vdev_setup_sync(struct ath11k *ar)
885 lockdep_assert_held(&ar->conf_mutex);
887 if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))
890 if (!wait_for_completion_timeout(&ar->vdev_setup_done,
891 ATH11K_VDEV_SETUP_TIMEOUT_HZ))
894 return ar->last_wmi_vdev_start_status ? -EINVAL : 0;
898 ath11k_mac_get_any_chandef_iter(struct ieee80211_hw *hw,
899 struct ieee80211_chanctx_conf *conf,
902 struct cfg80211_chan_def **def = data;
907 static int ath11k_mac_monitor_vdev_start(struct ath11k *ar, int vdev_id,
908 struct cfg80211_chan_def *chandef)
910 struct ieee80211_channel *channel;
911 struct wmi_vdev_start_req_arg arg = {};
914 lockdep_assert_held(&ar->conf_mutex);
916 channel = chandef->chan;
918 arg.vdev_id = vdev_id;
919 arg.channel.freq = channel->center_freq;
920 arg.channel.band_center_freq1 = chandef->center_freq1;
921 arg.channel.band_center_freq2 = chandef->center_freq2;
923 arg.channel.mode = ath11k_phymodes[chandef->chan->band][chandef->width];
924 arg.channel.chan_radar = !!(channel->flags & IEEE80211_CHAN_RADAR);
926 arg.channel.min_power = 0;
927 arg.channel.max_power = channel->max_power;
928 arg.channel.max_reg_power = channel->max_reg_power;
929 arg.channel.max_antenna_gain = channel->max_antenna_gain;
931 arg.pref_tx_streams = ar->num_tx_chains;
932 arg.pref_rx_streams = ar->num_rx_chains;
934 arg.channel.passive = !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR);
936 reinit_completion(&ar->vdev_setup_done);
937 reinit_completion(&ar->vdev_delete_done);
939 ret = ath11k_wmi_vdev_start(ar, &arg, false);
941 ath11k_warn(ar->ab, "failed to request monitor vdev %i start: %d\n",
946 ret = ath11k_mac_vdev_setup_sync(ar);
948 ath11k_warn(ar->ab, "failed to synchronize setup for monitor vdev %i start: %d\n",
953 ret = ath11k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
955 ath11k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n",
960 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor vdev %i started\n",
966 reinit_completion(&ar->vdev_setup_done);
968 ret = ath11k_wmi_vdev_stop(ar, vdev_id);
970 ath11k_warn(ar->ab, "failed to stop monitor vdev %i after start failure: %d\n",
975 ret = ath11k_mac_vdev_setup_sync(ar);
977 ath11k_warn(ar->ab, "failed to synchronize setup for vdev %i stop: %d\n",
985 static int ath11k_mac_monitor_vdev_stop(struct ath11k *ar)
989 lockdep_assert_held(&ar->conf_mutex);
991 reinit_completion(&ar->vdev_setup_done);
993 ret = ath11k_wmi_vdev_stop(ar, ar->monitor_vdev_id);
995 ath11k_warn(ar->ab, "failed to request monitor vdev %i stop: %d\n",
996 ar->monitor_vdev_id, ret);
1000 ret = ath11k_mac_vdev_setup_sync(ar);
1002 ath11k_warn(ar->ab, "failed to synchronize monitor vdev %i stop: %d\n",
1003 ar->monitor_vdev_id, ret);
1007 ret = ath11k_wmi_vdev_down(ar, ar->monitor_vdev_id);
1009 ath11k_warn(ar->ab, "failed to put down monitor vdev %i: %d\n",
1010 ar->monitor_vdev_id, ret);
1014 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor vdev %i stopped\n",
1015 ar->monitor_vdev_id);
1020 static int ath11k_mac_monitor_vdev_create(struct ath11k *ar)
1022 struct ath11k_pdev *pdev = ar->pdev;
1023 struct vdev_create_params param = {};
1025 u8 tmp_addr[6] = {0};
1028 lockdep_assert_held(&ar->conf_mutex);
1030 if (test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags))
1033 if (ar->ab->free_vdev_map == 0) {
1034 ath11k_warn(ar->ab, "failed to find free vdev id for monitor vdev\n");
1038 bit = __ffs64(ar->ab->free_vdev_map);
1040 ar->monitor_vdev_id = bit;
1042 param.if_id = ar->monitor_vdev_id;
1043 param.type = WMI_VDEV_TYPE_MONITOR;
1044 param.subtype = WMI_VDEV_SUBTYPE_NONE;
1045 param.pdev_id = pdev->pdev_id;
1047 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) {
1048 param.chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains;
1049 param.chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains;
1051 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) {
1052 param.chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains;
1053 param.chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains;
1056 ret = ath11k_wmi_vdev_create(ar, tmp_addr, ¶m);
1058 ath11k_warn(ar->ab, "failed to request monitor vdev %i creation: %d\n",
1059 ar->monitor_vdev_id, ret);
1060 ar->monitor_vdev_id = -1;
1064 nss = get_num_chains(ar->cfg_tx_chainmask) ? : 1;
1065 ret = ath11k_wmi_vdev_set_param_cmd(ar, ar->monitor_vdev_id,
1066 WMI_VDEV_PARAM_NSS, nss);
1068 ath11k_warn(ar->ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n",
1069 ar->monitor_vdev_id, ar->cfg_tx_chainmask, nss, ret);
1073 ret = ath11k_mac_txpower_recalc(ar);
1075 ath11k_warn(ar->ab, "failed to recalc txpower for monitor vdev %d: %d\n",
1076 ar->monitor_vdev_id, ret);
1080 ar->allocated_vdev_map |= 1LL << ar->monitor_vdev_id;
1081 ar->ab->free_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1082 ar->num_created_vdevs++;
1083 set_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags);
1085 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor vdev %d created\n",
1086 ar->monitor_vdev_id);
1091 ath11k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1092 ar->monitor_vdev_id = -1;
1096 static int ath11k_mac_monitor_vdev_delete(struct ath11k *ar)
1099 unsigned long time_left;
1101 lockdep_assert_held(&ar->conf_mutex);
1103 if (!test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags))
1106 reinit_completion(&ar->vdev_delete_done);
1108 ret = ath11k_wmi_vdev_delete(ar, ar->monitor_vdev_id);
1110 ath11k_warn(ar->ab, "failed to request wmi monitor vdev %i removal: %d\n",
1111 ar->monitor_vdev_id, ret);
1115 time_left = wait_for_completion_timeout(&ar->vdev_delete_done,
1116 ATH11K_VDEV_DELETE_TIMEOUT_HZ);
1117 if (time_left == 0) {
1118 ath11k_warn(ar->ab, "Timeout in receiving vdev delete response\n");
1120 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor vdev %d deleted\n",
1121 ar->monitor_vdev_id);
1123 ar->allocated_vdev_map &= ~(1LL << ar->monitor_vdev_id);
1124 ar->ab->free_vdev_map |= 1LL << (ar->monitor_vdev_id);
1125 ar->num_created_vdevs--;
1126 ar->monitor_vdev_id = -1;
1127 clear_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags);
1133 static int ath11k_mac_monitor_start(struct ath11k *ar)
1135 struct cfg80211_chan_def *chandef = NULL;
1138 lockdep_assert_held(&ar->conf_mutex);
1140 if (test_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags))
1143 ieee80211_iter_chan_contexts_atomic(ar->hw,
1144 ath11k_mac_get_any_chandef_iter,
1149 ret = ath11k_mac_monitor_vdev_start(ar, ar->monitor_vdev_id, chandef);
1151 ath11k_warn(ar->ab, "failed to start monitor vdev: %d\n", ret);
1152 ath11k_mac_monitor_vdev_delete(ar);
1156 set_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags);
1158 ar->num_started_vdevs++;
1159 ret = ath11k_dp_tx_htt_monitor_mode_ring_config(ar, false);
1161 ath11k_warn(ar->ab, "failed to configure htt monitor mode ring during start: %d",
1166 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor started\n");
1171 static int ath11k_mac_monitor_stop(struct ath11k *ar)
1175 lockdep_assert_held(&ar->conf_mutex);
1177 if (!test_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags))
1180 ret = ath11k_mac_monitor_vdev_stop(ar);
1182 ath11k_warn(ar->ab, "failed to stop monitor vdev: %d\n", ret);
1186 clear_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags);
1187 ar->num_started_vdevs--;
1189 ret = ath11k_dp_tx_htt_monitor_mode_ring_config(ar, true);
1191 ath11k_warn(ar->ab, "failed to configure htt monitor mode ring during stop: %d",
1196 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor stopped ret %d\n", ret);
1201 static int ath11k_mac_vif_setup_ps(struct ath11k_vif *arvif)
1203 struct ath11k *ar = arvif->ar;
1204 struct ieee80211_vif *vif = arvif->vif;
1205 struct ieee80211_conf *conf = &ar->hw->conf;
1206 enum wmi_sta_powersave_param param;
1207 enum wmi_sta_ps_mode psmode;
1212 lockdep_assert_held(&arvif->ar->conf_mutex);
1214 if (arvif->vif->type != NL80211_IFTYPE_STATION)
1217 enable_ps = arvif->ps;
1219 if (!arvif->is_started) {
1220 /* mac80211 can update vif powersave state while disconnected.
1221 * Firmware doesn't behave nicely and consumes more power than
1222 * necessary if PS is disabled on a non-started vdev. Hence
1223 * force-enable PS for non-running vdevs.
1225 psmode = WMI_STA_PS_MODE_ENABLED;
1226 } else if (enable_ps) {
1227 psmode = WMI_STA_PS_MODE_ENABLED;
1228 param = WMI_STA_PS_PARAM_INACTIVITY_TIME;
1230 timeout = conf->dynamic_ps_timeout;
1232 /* firmware doesn't like 0 */
1233 timeout = ieee80211_tu_to_usec(vif->bss_conf.beacon_int) / 1000;
1236 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id, param,
1239 ath11k_warn(ar->ab, "failed to set inactivity time for vdev %d: %i\n",
1240 arvif->vdev_id, ret);
1244 psmode = WMI_STA_PS_MODE_DISABLED;
1247 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d psmode %s\n",
1248 arvif->vdev_id, psmode ? "enable" : "disable");
1250 ret = ath11k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, psmode);
1252 ath11k_warn(ar->ab, "failed to set sta power save mode %d for vdev %d: %d\n",
1253 psmode, arvif->vdev_id, ret);
1260 static int ath11k_mac_config_ps(struct ath11k *ar)
1262 struct ath11k_vif *arvif;
1265 lockdep_assert_held(&ar->conf_mutex);
1267 list_for_each_entry(arvif, &ar->arvifs, list) {
1268 ret = ath11k_mac_vif_setup_ps(arvif);
1270 ath11k_warn(ar->ab, "failed to setup powersave: %d\n", ret);
1278 static int ath11k_mac_op_config(struct ieee80211_hw *hw, u32 changed)
1280 struct ath11k *ar = hw->priv;
1281 struct ieee80211_conf *conf = &hw->conf;
1284 mutex_lock(&ar->conf_mutex);
1286 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1287 if (conf->flags & IEEE80211_CONF_MONITOR) {
1288 set_bit(ATH11K_FLAG_MONITOR_CONF_ENABLED, &ar->monitor_flags);
1290 if (test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED,
1291 &ar->monitor_flags))
1294 ret = ath11k_mac_monitor_vdev_create(ar);
1296 ath11k_warn(ar->ab, "failed to create monitor vdev: %d",
1301 ret = ath11k_mac_monitor_start(ar);
1303 ath11k_warn(ar->ab, "failed to start monitor: %d",
1308 clear_bit(ATH11K_FLAG_MONITOR_CONF_ENABLED, &ar->monitor_flags);
1310 if (!test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED,
1311 &ar->monitor_flags))
1314 ret = ath11k_mac_monitor_stop(ar);
1316 ath11k_warn(ar->ab, "failed to stop monitor: %d",
1321 ret = ath11k_mac_monitor_vdev_delete(ar);
1323 ath11k_warn(ar->ab, "failed to delete monitor vdev: %d",
1331 mutex_unlock(&ar->conf_mutex);
1335 ath11k_mac_monitor_vdev_delete(ar);
1336 mutex_unlock(&ar->conf_mutex);
1340 static int ath11k_mac_setup_bcn_tmpl(struct ath11k_vif *arvif)
1342 struct ath11k *ar = arvif->ar;
1343 struct ath11k_base *ab = ar->ab;
1344 struct ieee80211_hw *hw = ar->hw;
1345 struct ieee80211_vif *vif = arvif->vif;
1346 struct ieee80211_mutable_offsets offs = {};
1347 struct sk_buff *bcn;
1348 struct ieee80211_mgmt *mgmt;
1352 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
1355 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
1357 ath11k_warn(ab, "failed to get beacon template from mac80211\n");
1361 ies = bcn->data + ieee80211_get_hdrlen_from_skb(bcn);
1362 ies += sizeof(mgmt->u.beacon);
1364 if (cfg80211_find_ie(WLAN_EID_RSN, ies, (skb_tail_pointer(bcn) - ies)))
1365 arvif->rsnie_present = true;
1367 arvif->rsnie_present = false;
1369 if (cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1370 WLAN_OUI_TYPE_MICROSOFT_WPA,
1371 ies, (skb_tail_pointer(bcn) - ies)))
1372 arvif->wpaie_present = true;
1374 arvif->wpaie_present = false;
1376 ret = ath11k_wmi_bcn_tmpl(ar, arvif->vdev_id, &offs, bcn);
1381 ath11k_warn(ab, "failed to submit beacon template command: %d\n",
1387 void ath11k_mac_bcn_tx_event(struct ath11k_vif *arvif)
1389 struct ieee80211_vif *vif = arvif->vif;
1391 if (!vif->color_change_active && !arvif->bcca_zero_sent)
1394 if (vif->color_change_active && ieee80211_beacon_cntdwn_is_complete(vif)) {
1395 arvif->bcca_zero_sent = true;
1396 ieee80211_color_change_finish(vif);
1400 arvif->bcca_zero_sent = false;
1402 if (vif->color_change_active)
1403 ieee80211_beacon_update_cntdwn(vif);
1404 ath11k_mac_setup_bcn_tmpl(arvif);
1407 static void ath11k_control_beaconing(struct ath11k_vif *arvif,
1408 struct ieee80211_bss_conf *info)
1410 struct ath11k *ar = arvif->ar;
1413 lockdep_assert_held(&arvif->ar->conf_mutex);
1415 if (!info->enable_beacon) {
1416 ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id);
1418 ath11k_warn(ar->ab, "failed to down vdev_id %i: %d\n",
1419 arvif->vdev_id, ret);
1421 arvif->is_up = false;
1425 /* Install the beacon template to the FW */
1426 ret = ath11k_mac_setup_bcn_tmpl(arvif);
1428 ath11k_warn(ar->ab, "failed to update bcn tmpl during vdev up: %d\n",
1433 arvif->tx_seq_no = 0x1000;
1437 ether_addr_copy(arvif->bssid, info->bssid);
1439 ret = ath11k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
1442 ath11k_warn(ar->ab, "failed to bring up vdev %d: %i\n",
1443 arvif->vdev_id, ret);
1447 arvif->is_up = true;
1449 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
1452 static void ath11k_mac_handle_beacon_iter(void *data, u8 *mac,
1453 struct ieee80211_vif *vif)
1455 struct sk_buff *skb = data;
1456 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1457 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1459 if (vif->type != NL80211_IFTYPE_STATION)
1462 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
1465 cancel_delayed_work(&arvif->connection_loss_work);
1468 void ath11k_mac_handle_beacon(struct ath11k *ar, struct sk_buff *skb)
1470 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1471 IEEE80211_IFACE_ITER_NORMAL,
1472 ath11k_mac_handle_beacon_iter,
1476 static void ath11k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
1477 struct ieee80211_vif *vif)
1479 u32 *vdev_id = data;
1480 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1481 struct ath11k *ar = arvif->ar;
1482 struct ieee80211_hw *hw = ar->hw;
1484 if (arvif->vdev_id != *vdev_id)
1490 ieee80211_beacon_loss(vif);
1492 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
1493 * (done by mac80211) succeeds but beacons do not resume then it
1494 * doesn't make sense to continue operation. Queue connection loss work
1495 * which can be cancelled when beacon is received.
1497 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
1498 ATH11K_CONNECTION_LOSS_HZ);
1501 void ath11k_mac_handle_beacon_miss(struct ath11k *ar, u32 vdev_id)
1503 ieee80211_iterate_active_interfaces_atomic(ar->hw,
1504 IEEE80211_IFACE_ITER_NORMAL,
1505 ath11k_mac_handle_beacon_miss_iter,
1509 static void ath11k_mac_vif_sta_connection_loss_work(struct work_struct *work)
1511 struct ath11k_vif *arvif = container_of(work, struct ath11k_vif,
1512 connection_loss_work.work);
1513 struct ieee80211_vif *vif = arvif->vif;
1518 ieee80211_connection_loss(vif);
1521 static void ath11k_peer_assoc_h_basic(struct ath11k *ar,
1522 struct ieee80211_vif *vif,
1523 struct ieee80211_sta *sta,
1524 struct peer_assoc_params *arg)
1526 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1529 lockdep_assert_held(&ar->conf_mutex);
1531 if (vif->type == NL80211_IFTYPE_STATION)
1532 aid = vif->bss_conf.aid;
1536 ether_addr_copy(arg->peer_mac, sta->addr);
1537 arg->vdev_id = arvif->vdev_id;
1538 arg->peer_associd = aid;
1539 arg->auth_flag = true;
1540 /* TODO: STA WAR in ath10k for listen interval required? */
1541 arg->peer_listen_intval = ar->hw->conf.listen_interval;
1543 arg->peer_caps = vif->bss_conf.assoc_capability;
1546 static void ath11k_peer_assoc_h_crypto(struct ath11k *ar,
1547 struct ieee80211_vif *vif,
1548 struct ieee80211_sta *sta,
1549 struct peer_assoc_params *arg)
1551 struct ieee80211_bss_conf *info = &vif->bss_conf;
1552 struct cfg80211_chan_def def;
1553 struct cfg80211_bss *bss;
1554 struct ath11k_vif *arvif = (struct ath11k_vif *)vif->drv_priv;
1555 const u8 *rsnie = NULL;
1556 const u8 *wpaie = NULL;
1558 lockdep_assert_held(&ar->conf_mutex);
1560 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1563 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
1564 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
1566 if (arvif->rsnie_present || arvif->wpaie_present) {
1567 arg->need_ptk_4_way = true;
1568 if (arvif->wpaie_present)
1569 arg->need_gtk_2_way = true;
1571 const struct cfg80211_bss_ies *ies;
1574 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
1576 ies = rcu_dereference(bss->ies);
1578 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
1579 WLAN_OUI_TYPE_MICROSOFT_WPA,
1583 cfg80211_put_bss(ar->hw->wiphy, bss);
1586 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
1587 if (rsnie || wpaie) {
1588 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1589 "%s: rsn ie found\n", __func__);
1590 arg->need_ptk_4_way = true;
1594 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
1595 "%s: wpa ie found\n", __func__);
1596 arg->need_gtk_2_way = true;
1600 /* TODO: Need to check if FW supports PMF? */
1601 arg->is_pmf_enabled = true;
1604 /* TODO: safe_mode_enabled (bypass 4-way handshake) flag req? */
1607 static void ath11k_peer_assoc_h_rates(struct ath11k *ar,
1608 struct ieee80211_vif *vif,
1609 struct ieee80211_sta *sta,
1610 struct peer_assoc_params *arg)
1612 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1613 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
1614 struct cfg80211_chan_def def;
1615 const struct ieee80211_supported_band *sband;
1616 const struct ieee80211_rate *rates;
1617 enum nl80211_band band;
1622 lockdep_assert_held(&ar->conf_mutex);
1624 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1627 band = def.chan->band;
1628 sband = ar->hw->wiphy->bands[band];
1629 ratemask = sta->supp_rates[band];
1630 ratemask &= arvif->bitrate_mask.control[band].legacy;
1631 rates = sband->bitrates;
1633 rateset->num_rates = 0;
1635 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1636 if (!(ratemask & 1))
1639 rate = ath11k_mac_bitrate_to_rate(rates->bitrate);
1640 rateset->rates[rateset->num_rates] = rate;
1641 rateset->num_rates++;
1646 ath11k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
1650 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
1651 if (ht_mcs_mask[nss])
1658 ath11k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[])
1662 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
1663 if (vht_mcs_mask[nss])
1669 static void ath11k_peer_assoc_h_ht(struct ath11k *ar,
1670 struct ieee80211_vif *vif,
1671 struct ieee80211_sta *sta,
1672 struct peer_assoc_params *arg)
1674 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1675 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1676 struct cfg80211_chan_def def;
1677 enum nl80211_band band;
1678 const u8 *ht_mcs_mask;
1683 lockdep_assert_held(&ar->conf_mutex);
1685 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1688 if (!ht_cap->ht_supported)
1691 band = def.chan->band;
1692 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
1694 if (ath11k_peer_assoc_h_ht_masked(ht_mcs_mask))
1697 arg->ht_flag = true;
1699 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1700 ht_cap->ampdu_factor)) - 1;
1702 arg->peer_mpdu_density =
1703 ath11k_parse_mpdudensity(ht_cap->ampdu_density);
1705 arg->peer_ht_caps = ht_cap->cap;
1706 arg->peer_rate_caps |= WMI_HOST_RC_HT_FLAG;
1708 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1709 arg->ldpc_flag = true;
1711 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1713 arg->peer_rate_caps |= WMI_HOST_RC_CW40_FLAG;
1716 /* As firmware handles this two flags (IEEE80211_HT_CAP_SGI_20
1717 * and IEEE80211_HT_CAP_SGI_40) for enabling SGI, we reset
1718 * both flags if guard interval is Default GI
1720 if (arvif->bitrate_mask.control[band].gi == NL80211_TXRATE_DEFAULT_GI)
1721 arg->peer_ht_caps &= ~(IEEE80211_HT_CAP_SGI_20 |
1722 IEEE80211_HT_CAP_SGI_40);
1724 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
1725 if (ht_cap->cap & (IEEE80211_HT_CAP_SGI_20 |
1726 IEEE80211_HT_CAP_SGI_40))
1727 arg->peer_rate_caps |= WMI_HOST_RC_SGI_FLAG;
1730 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1731 arg->peer_rate_caps |= WMI_HOST_RC_TX_STBC_FLAG;
1732 arg->stbc_flag = true;
1735 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1736 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1737 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1738 stbc = stbc << WMI_HOST_RC_RX_STBC_FLAG_S;
1739 arg->peer_rate_caps |= stbc;
1740 arg->stbc_flag = true;
1743 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1744 arg->peer_rate_caps |= WMI_HOST_RC_TS_FLAG;
1745 else if (ht_cap->mcs.rx_mask[1])
1746 arg->peer_rate_caps |= WMI_HOST_RC_DS_FLAG;
1748 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
1749 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
1750 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
1751 max_nss = (i / 8) + 1;
1752 arg->peer_ht_rates.rates[n++] = i;
1755 /* This is a workaround for HT-enabled STAs which break the spec
1756 * and have no HT capabilities RX mask (no HT RX MCS map).
1758 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1759 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1761 * Firmware asserts if such situation occurs.
1764 arg->peer_ht_rates.num_rates = 8;
1765 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1766 arg->peer_ht_rates.rates[i] = i;
1768 arg->peer_ht_rates.num_rates = n;
1769 arg->peer_nss = min(sta->rx_nss, max_nss);
1772 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1774 arg->peer_ht_rates.num_rates,
1778 static int ath11k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
1780 switch ((mcs_map >> (2 * nss)) & 0x3) {
1781 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
1782 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
1783 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
1789 ath11k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
1790 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
1797 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
1798 mcs_map = ath11k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
1802 idx_limit = fls(mcs_map) - 1;
1806 switch (idx_limit) {
1815 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
1818 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
1821 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
1827 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
1831 tx_mcs_set &= ~(0x3 << (nss * 2));
1832 tx_mcs_set |= mcs << (nss * 2);
1838 static u8 ath11k_get_nss_160mhz(struct ath11k *ar,
1841 u8 nss_ratio_info = ar->pdev->cap.nss_ratio_info;
1844 switch (nss_ratio_info) {
1845 case WMI_NSS_RATIO_1BY2_NSS:
1846 max_sup_nss = max_nss >> 1;
1848 case WMI_NSS_RATIO_3BY4_NSS:
1849 ath11k_warn(ar->ab, "WMI_NSS_RATIO_3BY4_NSS not supported\n");
1851 case WMI_NSS_RATIO_1_NSS:
1852 max_sup_nss = max_nss;
1854 case WMI_NSS_RATIO_2_NSS:
1855 ath11k_warn(ar->ab, "WMI_NSS_RATIO_2_NSS not supported\n");
1858 ath11k_warn(ar->ab, "invalid nss ratio received from firmware: %d\n",
1866 static void ath11k_peer_assoc_h_vht(struct ath11k *ar,
1867 struct ieee80211_vif *vif,
1868 struct ieee80211_sta *sta,
1869 struct peer_assoc_params *arg)
1871 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1872 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1873 struct cfg80211_chan_def def;
1874 enum nl80211_band band;
1877 u8 max_nss, vht_mcs;
1878 int i, vht_nss, nss_idx;
1879 bool user_rate_valid = true;
1880 u32 rx_nss, tx_nss, nss_160;
1882 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1885 if (!vht_cap->vht_supported)
1888 band = def.chan->band;
1889 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
1891 if (ath11k_peer_assoc_h_vht_masked(vht_mcs_mask))
1894 arg->vht_flag = true;
1896 /* TODO: similar flags required? */
1897 arg->vht_capable = true;
1899 if (def.chan->band == NL80211_BAND_2GHZ)
1900 arg->vht_ng_flag = true;
1902 arg->peer_vht_caps = vht_cap->cap;
1904 ampdu_factor = (vht_cap->cap &
1905 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1906 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1908 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1909 * zero in VHT IE. Using it would result in degraded throughput.
1910 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1911 * it if VHT max_mpdu is smaller.
1913 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1914 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1915 ampdu_factor)) - 1);
1917 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1920 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
1923 vht_nss = ath11k_mac_max_vht_nss(vht_mcs_mask);
1925 if (vht_nss > sta->rx_nss) {
1926 user_rate_valid = false;
1927 for (nss_idx = sta->rx_nss - 1; nss_idx >= 0; nss_idx--) {
1928 if (vht_mcs_mask[nss_idx]) {
1929 user_rate_valid = true;
1935 if (!user_rate_valid) {
1936 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac setting vht range mcs value to peer supported nss %d for peer %pM\n",
1937 sta->rx_nss, sta->addr);
1938 vht_mcs_mask[sta->rx_nss - 1] = vht_mcs_mask[vht_nss - 1];
1941 /* Calculate peer NSS capability from VHT capabilities if STA
1944 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
1945 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
1948 if (vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED &&
1952 arg->peer_nss = min(sta->rx_nss, max_nss);
1953 arg->rx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1954 arg->rx_mcs_set = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1955 arg->tx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1956 arg->tx_mcs_set = ath11k_peer_assoc_h_vht_limit(
1957 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
1959 /* In IPQ8074 platform, VHT mcs rate 10 and 11 is enabled by default.
1960 * VHT mcs rate 10 and 11 is not suppoerted in 11ac standard.
1961 * so explicitly disable the VHT MCS rate 10 and 11 in 11ac mode.
1963 arg->tx_mcs_set &= ~IEEE80211_VHT_MCS_SUPPORT_0_11_MASK;
1964 arg->tx_mcs_set |= IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11;
1966 if ((arg->tx_mcs_set & IEEE80211_VHT_MCS_NOT_SUPPORTED) ==
1967 IEEE80211_VHT_MCS_NOT_SUPPORTED)
1968 arg->peer_vht_caps &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1971 arg->tx_max_mcs_nss = 0xFF;
1973 if (arg->peer_phymode == MODE_11AC_VHT160 ||
1974 arg->peer_phymode == MODE_11AC_VHT80_80) {
1975 tx_nss = ath11k_get_nss_160mhz(ar, max_nss);
1976 rx_nss = min(arg->peer_nss, tx_nss);
1977 arg->peer_bw_rxnss_override = ATH11K_BW_NSS_MAP_ENABLE;
1980 ath11k_warn(ar->ab, "invalid max_nss\n");
1984 if (arg->peer_phymode == MODE_11AC_VHT160)
1985 nss_160 = FIELD_PREP(ATH11K_PEER_RX_NSS_160MHZ, rx_nss - 1);
1987 nss_160 = FIELD_PREP(ATH11K_PEER_RX_NSS_80_80MHZ, rx_nss - 1);
1989 arg->peer_bw_rxnss_override |= nss_160;
1992 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1993 "mac vht peer %pM max_mpdu %d flags 0x%x nss_override 0x%x\n",
1994 sta->addr, arg->peer_max_mpdu, arg->peer_flags,
1995 arg->peer_bw_rxnss_override);
1998 static int ath11k_mac_get_max_he_mcs_map(u16 mcs_map, int nss)
2000 switch ((mcs_map >> (2 * nss)) & 0x3) {
2001 case IEEE80211_HE_MCS_SUPPORT_0_7: return BIT(8) - 1;
2002 case IEEE80211_HE_MCS_SUPPORT_0_9: return BIT(10) - 1;
2003 case IEEE80211_HE_MCS_SUPPORT_0_11: return BIT(12) - 1;
2008 static u16 ath11k_peer_assoc_h_he_limit(u16 tx_mcs_set,
2009 const u16 he_mcs_limit[NL80211_HE_NSS_MAX])
2016 for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) {
2017 mcs_map = ath11k_mac_get_max_he_mcs_map(tx_mcs_set, nss) &
2021 idx_limit = fls(mcs_map) - 1;
2025 switch (idx_limit) {
2027 mcs = IEEE80211_HE_MCS_SUPPORT_0_7;
2031 mcs = IEEE80211_HE_MCS_SUPPORT_0_9;
2035 mcs = IEEE80211_HE_MCS_SUPPORT_0_11;
2041 mcs = IEEE80211_HE_MCS_NOT_SUPPORTED;
2045 tx_mcs_set &= ~(0x3 << (nss * 2));
2046 tx_mcs_set |= mcs << (nss * 2);
2053 ath11k_peer_assoc_h_he_masked(const u16 he_mcs_mask[NL80211_HE_NSS_MAX])
2057 for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++)
2058 if (he_mcs_mask[nss])
2064 static void ath11k_peer_assoc_h_he(struct ath11k *ar,
2065 struct ieee80211_vif *vif,
2066 struct ieee80211_sta *sta,
2067 struct peer_assoc_params *arg)
2069 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2070 struct cfg80211_chan_def def;
2071 const struct ieee80211_sta_he_cap *he_cap = &sta->he_cap;
2072 enum nl80211_band band;
2075 u16 he_tx_mcs = 0, v = 0;
2076 int i, he_nss, nss_idx;
2077 bool user_rate_valid = true;
2078 u32 rx_nss, tx_nss, nss_160;
2079 u8 ampdu_factor, rx_mcs_80, rx_mcs_160;
2080 u16 mcs_160_map, mcs_80_map;
2083 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
2086 if (!he_cap->has_he)
2089 band = def.chan->band;
2090 he_mcs_mask = arvif->bitrate_mask.control[band].he_mcs;
2092 if (ath11k_peer_assoc_h_he_masked(he_mcs_mask))
2095 arg->he_flag = true;
2096 support_160 = !!(he_cap->he_cap_elem.phy_cap_info[0] &
2097 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G);
2099 /* Supported HE-MCS and NSS Set of peer he_cap is intersection with self he_cp */
2100 mcs_160_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160);
2101 mcs_80_map = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80);
2104 for (i = 7; i >= 0; i--) {
2105 u8 mcs_160 = (mcs_160_map >> (2 * i)) & 3;
2107 if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
2114 for (i = 7; i >= 0; i--) {
2115 u8 mcs_80 = (mcs_80_map >> (2 * i)) & 3;
2117 if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
2124 max_nss = min(rx_mcs_80, rx_mcs_160);
2126 max_nss = rx_mcs_80;
2128 arg->peer_nss = min(sta->rx_nss, max_nss);
2130 memcpy_and_pad(&arg->peer_he_cap_macinfo,
2131 sizeof(arg->peer_he_cap_macinfo),
2132 he_cap->he_cap_elem.mac_cap_info,
2133 sizeof(he_cap->he_cap_elem.mac_cap_info),
2135 memcpy_and_pad(&arg->peer_he_cap_phyinfo,
2136 sizeof(arg->peer_he_cap_phyinfo),
2137 he_cap->he_cap_elem.phy_cap_info,
2138 sizeof(he_cap->he_cap_elem.phy_cap_info),
2140 arg->peer_he_ops = vif->bss_conf.he_oper.params;
2142 /* the top most byte is used to indicate BSS color info */
2143 arg->peer_he_ops &= 0xffffff;
2145 /* As per section 26.6.1 11ax Draft5.0, if the Max AMPDU Exponent Extension
2146 * in HE cap is zero, use the arg->peer_max_mpdu as calculated while parsing
2147 * VHT caps(if VHT caps is present) or HT caps (if VHT caps is not present).
2149 * For non-zero value of Max AMPDU Extponent Extension in HE MAC caps,
2150 * if a HE STA sends VHT cap and HE cap IE in assoc request then, use
2151 * MAX_AMPDU_LEN_FACTOR as 20 to calculate max_ampdu length.
2152 * If a HE STA that does not send VHT cap, but HE and HT cap in assoc
2153 * request, then use MAX_AMPDU_LEN_FACTOR as 16 to calculate max_ampdu
2156 ampdu_factor = u8_get_bits(he_cap->he_cap_elem.mac_cap_info[3],
2157 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK);
2160 if (sta->vht_cap.vht_supported)
2161 arg->peer_max_mpdu = (1 << (IEEE80211_HE_VHT_MAX_AMPDU_FACTOR +
2163 else if (sta->ht_cap.ht_supported)
2164 arg->peer_max_mpdu = (1 << (IEEE80211_HE_HT_MAX_AMPDU_FACTOR +
2168 if (he_cap->he_cap_elem.phy_cap_info[6] &
2169 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
2173 arg->peer_ppet.numss_m1 = he_cap->ppe_thres[0] &
2174 IEEE80211_PPE_THRES_NSS_MASK;
2175 arg->peer_ppet.ru_bit_mask =
2176 (he_cap->ppe_thres[0] &
2177 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
2178 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
2180 for (nss = 0; nss <= arg->peer_ppet.numss_m1; nss++) {
2181 for (ru = 0; ru < 4; ru++) {
2185 if ((arg->peer_ppet.ru_bit_mask & BIT(ru)) == 0)
2187 for (i = 0; i < 6; i++) {
2189 val |= ((he_cap->ppe_thres[bit / 8] >>
2190 (bit % 8)) & 0x1) << 5;
2193 arg->peer_ppet.ppet16_ppet8_ru3_ru0[nss] |=
2199 if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_RES)
2200 arg->twt_responder = true;
2201 if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_REQ)
2202 arg->twt_requester = true;
2204 he_nss = ath11k_mac_max_he_nss(he_mcs_mask);
2206 if (he_nss > sta->rx_nss) {
2207 user_rate_valid = false;
2208 for (nss_idx = sta->rx_nss - 1; nss_idx >= 0; nss_idx--) {
2209 if (he_mcs_mask[nss_idx]) {
2210 user_rate_valid = true;
2216 if (!user_rate_valid) {
2217 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac setting he range mcs value to peer supported nss %d for peer %pM\n",
2218 sta->rx_nss, sta->addr);
2219 he_mcs_mask[sta->rx_nss - 1] = he_mcs_mask[he_nss - 1];
2222 switch (sta->bandwidth) {
2223 case IEEE80211_STA_RX_BW_160:
2224 if (he_cap->he_cap_elem.phy_cap_info[0] &
2225 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) {
2226 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80p80);
2227 v = ath11k_peer_assoc_h_he_limit(v, he_mcs_mask);
2228 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v;
2230 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80p80);
2231 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v;
2233 arg->peer_he_mcs_count++;
2236 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160);
2237 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v;
2239 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_160);
2240 v = ath11k_peer_assoc_h_he_limit(v, he_mcs_mask);
2241 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v;
2243 arg->peer_he_mcs_count++;
2249 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80);
2250 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v;
2252 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80);
2253 v = ath11k_peer_assoc_h_he_limit(v, he_mcs_mask);
2254 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v;
2256 arg->peer_he_mcs_count++;
2262 /* Calculate peer NSS capability from HE capabilities if STA
2265 for (i = 0, max_nss = 0, he_mcs = 0; i < NL80211_HE_NSS_MAX; i++) {
2266 he_mcs = he_tx_mcs >> (2 * i) & 3;
2268 /* In case of fixed rates, MCS Range in he_tx_mcs might have
2269 * unsupported range, with he_mcs_mask set, so check either of them
2272 if (he_mcs != IEEE80211_HE_MCS_NOT_SUPPORTED ||
2276 arg->peer_nss = min(sta->rx_nss, max_nss);
2278 if (arg->peer_phymode == MODE_11AX_HE160 ||
2279 arg->peer_phymode == MODE_11AX_HE80_80) {
2280 tx_nss = ath11k_get_nss_160mhz(ar, max_nss);
2281 rx_nss = min(arg->peer_nss, tx_nss);
2282 arg->peer_bw_rxnss_override = ATH11K_BW_NSS_MAP_ENABLE;
2285 ath11k_warn(ar->ab, "invalid max_nss\n");
2289 if (arg->peer_phymode == MODE_11AX_HE160)
2290 nss_160 = FIELD_PREP(ATH11K_PEER_RX_NSS_160MHZ, rx_nss - 1);
2292 nss_160 = FIELD_PREP(ATH11K_PEER_RX_NSS_80_80MHZ, rx_nss - 1);
2294 arg->peer_bw_rxnss_override |= nss_160;
2297 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2298 "mac he peer %pM nss %d mcs cnt %d nss_override 0x%x\n",
2299 sta->addr, arg->peer_nss,
2300 arg->peer_he_mcs_count,
2301 arg->peer_bw_rxnss_override);
2304 static void ath11k_peer_assoc_h_he_6ghz(struct ath11k *ar,
2305 struct ieee80211_vif *vif,
2306 struct ieee80211_sta *sta,
2307 struct peer_assoc_params *arg)
2309 const struct ieee80211_sta_he_cap *he_cap = &sta->he_cap;
2310 struct cfg80211_chan_def def;
2311 enum nl80211_band band;
2314 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
2317 band = def.chan->band;
2319 if (!arg->he_flag || band != NL80211_BAND_6GHZ || !sta->he_6ghz_capa.capa)
2322 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2325 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2328 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
2331 arg->peer_he_caps_6ghz = le16_to_cpu(sta->he_6ghz_capa.capa);
2332 arg->peer_mpdu_density =
2333 ath11k_parse_mpdudensity(FIELD_GET(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START,
2334 arg->peer_he_caps_6ghz));
2336 /* From IEEE Std 802.11ax-2021 - Section 10.12.2: An HE STA shall be capable of
2337 * receiving A-MPDU where the A-MPDU pre-EOF padding length is up to the value
2338 * indicated by the Maximum A-MPDU Length Exponent Extension field in the HE
2339 * Capabilities element and the Maximum A-MPDU Length Exponent field in HE 6 GHz
2340 * Band Capabilities element in the 6 GHz band.
2342 * Here, we are extracting the Max A-MPDU Exponent Extension from HE caps and
2343 * factor is the Maximum A-MPDU Length Exponent from HE 6 GHZ Band capability.
2345 ampdu_factor = FIELD_GET(IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK,
2346 he_cap->he_cap_elem.mac_cap_info[3]) +
2347 FIELD_GET(IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP,
2348 arg->peer_he_caps_6ghz);
2350 arg->peer_max_mpdu = (1u << (IEEE80211_HE_6GHZ_MAX_AMPDU_FACTOR +
2354 static void ath11k_peer_assoc_h_smps(struct ieee80211_sta *sta,
2355 struct peer_assoc_params *arg)
2357 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
2360 if (!ht_cap->ht_supported && !sta->he_6ghz_capa.capa)
2363 if (ht_cap->ht_supported) {
2364 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2365 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2367 smps = le16_get_bits(sta->he_6ghz_capa.capa,
2368 IEEE80211_HE_6GHZ_CAP_SM_PS);
2372 case WLAN_HT_CAP_SM_PS_STATIC:
2373 arg->static_mimops_flag = true;
2375 case WLAN_HT_CAP_SM_PS_DYNAMIC:
2376 arg->dynamic_mimops_flag = true;
2378 case WLAN_HT_CAP_SM_PS_DISABLED:
2379 arg->spatial_mux_flag = true;
2386 static void ath11k_peer_assoc_h_qos(struct ath11k *ar,
2387 struct ieee80211_vif *vif,
2388 struct ieee80211_sta *sta,
2389 struct peer_assoc_params *arg)
2391 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2393 switch (arvif->vdev_type) {
2394 case WMI_VDEV_TYPE_AP:
2396 /* TODO: Check WME vs QoS */
2397 arg->is_wme_set = true;
2398 arg->qos_flag = true;
2401 if (sta->wme && sta->uapsd_queues) {
2402 /* TODO: Check WME vs QoS */
2403 arg->is_wme_set = true;
2404 arg->apsd_flag = true;
2405 arg->peer_rate_caps |= WMI_HOST_RC_UAPSD_FLAG;
2408 case WMI_VDEV_TYPE_STA:
2410 arg->is_wme_set = true;
2411 arg->qos_flag = true;
2418 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac peer %pM qos %d\n",
2419 sta->addr, arg->qos_flag);
2422 static int ath11k_peer_assoc_qos_ap(struct ath11k *ar,
2423 struct ath11k_vif *arvif,
2424 struct ieee80211_sta *sta)
2426 struct ap_ps_params params;
2431 lockdep_assert_held(&ar->conf_mutex);
2433 params.vdev_id = arvif->vdev_id;
2435 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
2436 sta->uapsd_queues, sta->max_sp);
2439 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
2440 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
2441 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
2442 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
2443 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
2444 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
2445 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
2446 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
2447 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
2448 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
2449 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
2450 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
2453 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
2454 max_sp = sta->max_sp;
2456 params.param = WMI_AP_PS_PEER_PARAM_UAPSD;
2457 params.value = uapsd;
2458 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
2462 params.param = WMI_AP_PS_PEER_PARAM_MAX_SP;
2463 params.value = max_sp;
2464 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
2468 /* TODO revisit during testing */
2469 params.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_FRMTYPE;
2470 params.value = DISABLE_SIFS_RESPONSE_TRIGGER;
2471 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
2475 params.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_UAPSD;
2476 params.value = DISABLE_SIFS_RESPONSE_TRIGGER;
2477 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
2484 ath11k_warn(ar->ab, "failed to set ap ps peer param %d for vdev %i: %d\n",
2485 params.param, arvif->vdev_id, ret);
2489 static bool ath11k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
2491 return sta->supp_rates[NL80211_BAND_2GHZ] >>
2492 ATH11K_MAC_FIRST_OFDM_RATE_IDX;
2495 static enum wmi_phy_mode ath11k_mac_get_phymode_vht(struct ath11k *ar,
2496 struct ieee80211_sta *sta)
2498 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
2499 switch (sta->vht_cap.cap &
2500 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
2501 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
2502 return MODE_11AC_VHT160;
2503 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
2504 return MODE_11AC_VHT80_80;
2506 /* not sure if this is a valid case? */
2507 return MODE_11AC_VHT160;
2511 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2512 return MODE_11AC_VHT80;
2514 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2515 return MODE_11AC_VHT40;
2517 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2518 return MODE_11AC_VHT20;
2520 return MODE_UNKNOWN;
2523 static enum wmi_phy_mode ath11k_mac_get_phymode_he(struct ath11k *ar,
2524 struct ieee80211_sta *sta)
2526 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
2527 if (sta->he_cap.he_cap_elem.phy_cap_info[0] &
2528 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
2529 return MODE_11AX_HE160;
2530 else if (sta->he_cap.he_cap_elem.phy_cap_info[0] &
2531 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)
2532 return MODE_11AX_HE80_80;
2533 /* not sure if this is a valid case? */
2534 return MODE_11AX_HE160;
2537 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2538 return MODE_11AX_HE80;
2540 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2541 return MODE_11AX_HE40;
2543 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
2544 return MODE_11AX_HE20;
2546 return MODE_UNKNOWN;
2549 static void ath11k_peer_assoc_h_phymode(struct ath11k *ar,
2550 struct ieee80211_vif *vif,
2551 struct ieee80211_sta *sta,
2552 struct peer_assoc_params *arg)
2554 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2555 struct cfg80211_chan_def def;
2556 enum nl80211_band band;
2557 const u8 *ht_mcs_mask;
2558 const u16 *vht_mcs_mask;
2559 const u16 *he_mcs_mask;
2560 enum wmi_phy_mode phymode = MODE_UNKNOWN;
2562 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
2565 band = def.chan->band;
2566 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2567 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2568 he_mcs_mask = arvif->bitrate_mask.control[band].he_mcs;
2571 case NL80211_BAND_2GHZ:
2572 if (sta->he_cap.has_he &&
2573 !ath11k_peer_assoc_h_he_masked(he_mcs_mask)) {
2574 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
2575 phymode = MODE_11AX_HE80_2G;
2576 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2577 phymode = MODE_11AX_HE40_2G;
2579 phymode = MODE_11AX_HE20_2G;
2580 } else if (sta->vht_cap.vht_supported &&
2581 !ath11k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2582 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2583 phymode = MODE_11AC_VHT40;
2585 phymode = MODE_11AC_VHT20;
2586 } else if (sta->ht_cap.ht_supported &&
2587 !ath11k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2588 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
2589 phymode = MODE_11NG_HT40;
2591 phymode = MODE_11NG_HT20;
2592 } else if (ath11k_mac_sta_has_ofdm_only(sta)) {
2598 case NL80211_BAND_5GHZ:
2599 case NL80211_BAND_6GHZ:
2600 /* Check HE first */
2601 if (sta->he_cap.has_he &&
2602 !ath11k_peer_assoc_h_he_masked(he_mcs_mask)) {
2603 phymode = ath11k_mac_get_phymode_he(ar, sta);
2604 } else if (sta->vht_cap.vht_supported &&
2605 !ath11k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
2606 phymode = ath11k_mac_get_phymode_vht(ar, sta);
2607 } else if (sta->ht_cap.ht_supported &&
2608 !ath11k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
2609 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
2610 phymode = MODE_11NA_HT40;
2612 phymode = MODE_11NA_HT20;
2621 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac peer %pM phymode %s\n",
2622 sta->addr, ath11k_wmi_phymode_str(phymode));
2624 arg->peer_phymode = phymode;
2625 WARN_ON(phymode == MODE_UNKNOWN);
2628 static void ath11k_peer_assoc_prepare(struct ath11k *ar,
2629 struct ieee80211_vif *vif,
2630 struct ieee80211_sta *sta,
2631 struct peer_assoc_params *arg,
2634 struct ath11k_sta *arsta;
2636 lockdep_assert_held(&ar->conf_mutex);
2638 arsta = (struct ath11k_sta *)sta->drv_priv;
2640 memset(arg, 0, sizeof(*arg));
2642 reinit_completion(&ar->peer_assoc_done);
2644 arg->peer_new_assoc = !reassoc;
2645 ath11k_peer_assoc_h_basic(ar, vif, sta, arg);
2646 ath11k_peer_assoc_h_crypto(ar, vif, sta, arg);
2647 ath11k_peer_assoc_h_rates(ar, vif, sta, arg);
2648 ath11k_peer_assoc_h_phymode(ar, vif, sta, arg);
2649 ath11k_peer_assoc_h_ht(ar, vif, sta, arg);
2650 ath11k_peer_assoc_h_vht(ar, vif, sta, arg);
2651 ath11k_peer_assoc_h_he(ar, vif, sta, arg);
2652 ath11k_peer_assoc_h_he_6ghz(ar, vif, sta, arg);
2653 ath11k_peer_assoc_h_qos(ar, vif, sta, arg);
2654 ath11k_peer_assoc_h_smps(sta, arg);
2656 arsta->peer_nss = arg->peer_nss;
2658 /* TODO: amsdu_disable req? */
2661 static int ath11k_setup_peer_smps(struct ath11k *ar, struct ath11k_vif *arvif,
2663 const struct ieee80211_sta_ht_cap *ht_cap,
2668 if (!ht_cap->ht_supported && !he_6ghz_capa)
2671 if (ht_cap->ht_supported) {
2672 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
2673 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
2675 smps = FIELD_GET(IEEE80211_HE_6GHZ_CAP_SM_PS, he_6ghz_capa);
2678 if (smps >= ARRAY_SIZE(ath11k_smps_map))
2681 return ath11k_wmi_set_peer_param(ar, addr, arvif->vdev_id,
2682 WMI_PEER_MIMO_PS_STATE,
2683 ath11k_smps_map[smps]);
2686 static void ath11k_bss_assoc(struct ieee80211_hw *hw,
2687 struct ieee80211_vif *vif,
2688 struct ieee80211_bss_conf *bss_conf)
2690 struct ath11k *ar = hw->priv;
2691 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2692 struct peer_assoc_params peer_arg;
2693 struct ieee80211_sta *ap_sta;
2694 struct ath11k_peer *peer;
2695 bool is_auth = false;
2698 lockdep_assert_held(&ar->conf_mutex);
2700 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
2701 arvif->vdev_id, arvif->bssid, arvif->aid);
2705 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
2707 ath11k_warn(ar->ab, "failed to find station entry for bss %pM vdev %i\n",
2708 bss_conf->bssid, arvif->vdev_id);
2713 ath11k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg, false);
2717 peer_arg.is_assoc = true;
2718 ret = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
2720 ath11k_warn(ar->ab, "failed to run peer assoc for %pM vdev %i: %d\n",
2721 bss_conf->bssid, arvif->vdev_id, ret);
2725 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
2726 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
2727 bss_conf->bssid, arvif->vdev_id);
2731 ret = ath11k_setup_peer_smps(ar, arvif, bss_conf->bssid,
2733 le16_to_cpu(ap_sta->he_6ghz_capa.capa));
2735 ath11k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n",
2736 arvif->vdev_id, ret);
2740 WARN_ON(arvif->is_up);
2742 arvif->aid = bss_conf->aid;
2743 ether_addr_copy(arvif->bssid, bss_conf->bssid);
2745 ret = ath11k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
2747 ath11k_warn(ar->ab, "failed to set vdev %d up: %d\n",
2748 arvif->vdev_id, ret);
2752 arvif->is_up = true;
2754 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2755 "mac vdev %d up (associated) bssid %pM aid %d\n",
2756 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
2758 spin_lock_bh(&ar->ab->base_lock);
2760 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, arvif->bssid);
2761 if (peer && peer->is_authorized)
2764 spin_unlock_bh(&ar->ab->base_lock);
2767 ret = ath11k_wmi_set_peer_param(ar, arvif->bssid,
2772 ath11k_warn(ar->ab, "Unable to authorize BSS peer: %d\n", ret);
2775 ret = ath11k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id,
2776 &bss_conf->he_obss_pd);
2778 ath11k_warn(ar->ab, "failed to set vdev %i OBSS PD parameters: %d\n",
2779 arvif->vdev_id, ret);
2781 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2782 WMI_VDEV_PARAM_DTIM_POLICY,
2783 WMI_DTIM_POLICY_STICK);
2785 ath11k_warn(ar->ab, "failed to set vdev %d dtim policy: %d\n",
2786 arvif->vdev_id, ret);
2788 ath11k_mac_11d_scan_stop_all(ar->ab);
2791 static void ath11k_bss_disassoc(struct ieee80211_hw *hw,
2792 struct ieee80211_vif *vif)
2794 struct ath11k *ar = hw->priv;
2795 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2798 lockdep_assert_held(&ar->conf_mutex);
2800 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
2801 arvif->vdev_id, arvif->bssid);
2803 ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id);
2805 ath11k_warn(ar->ab, "failed to down vdev %i: %d\n",
2806 arvif->vdev_id, ret);
2808 arvif->is_up = false;
2810 cancel_delayed_work_sync(&arvif->connection_loss_work);
2813 static u32 ath11k_mac_get_rate_hw_value(int bitrate)
2820 if (ath11k_mac_bitrate_is_cck(bitrate))
2821 preamble = WMI_RATE_PREAMBLE_CCK;
2823 preamble = WMI_RATE_PREAMBLE_OFDM;
2825 for (i = 0; i < ARRAY_SIZE(ath11k_legacy_rates); i++) {
2826 if (ath11k_legacy_rates[i].bitrate != bitrate)
2829 hw_value = ath11k_legacy_rates[i].hw_value;
2830 rate = ATH11K_HW_RATE_CODE(hw_value, 0, preamble);
2838 static void ath11k_recalculate_mgmt_rate(struct ath11k *ar,
2839 struct ieee80211_vif *vif,
2840 struct cfg80211_chan_def *def)
2842 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2843 const struct ieee80211_supported_band *sband;
2850 lockdep_assert_held(&ar->conf_mutex);
2852 sband = ar->hw->wiphy->bands[def->chan->band];
2853 basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
2854 bitrate = sband->bitrates[basic_rate_idx].bitrate;
2856 hw_rate_code = ath11k_mac_get_rate_hw_value(bitrate);
2857 if (hw_rate_code < 0) {
2858 ath11k_warn(ar->ab, "bitrate not supported %d\n", bitrate);
2862 vdev_param = WMI_VDEV_PARAM_MGMT_RATE;
2863 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
2866 ath11k_warn(ar->ab, "failed to set mgmt tx rate %d\n", ret);
2868 /* For WCN6855, firmware will clear this param when vdev starts, hence
2869 * cache it here so that we can reconfigure it once vdev starts.
2871 ar->hw_rate_code = hw_rate_code;
2873 vdev_param = WMI_VDEV_PARAM_BEACON_RATE;
2874 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
2877 ath11k_warn(ar->ab, "failed to set beacon tx rate %d\n", ret);
2880 static int ath11k_mac_fils_discovery(struct ath11k_vif *arvif,
2881 struct ieee80211_bss_conf *info)
2883 struct ath11k *ar = arvif->ar;
2884 struct sk_buff *tmpl;
2887 bool unsol_bcast_probe_resp_enabled = false;
2889 if (info->fils_discovery.max_interval) {
2890 interval = info->fils_discovery.max_interval;
2892 tmpl = ieee80211_get_fils_discovery_tmpl(ar->hw, arvif->vif);
2894 ret = ath11k_wmi_fils_discovery_tmpl(ar, arvif->vdev_id,
2896 } else if (info->unsol_bcast_probe_resp_interval) {
2897 unsol_bcast_probe_resp_enabled = 1;
2898 interval = info->unsol_bcast_probe_resp_interval;
2900 tmpl = ieee80211_get_unsol_bcast_probe_resp_tmpl(ar->hw,
2903 ret = ath11k_wmi_probe_resp_tmpl(ar, arvif->vdev_id,
2905 } else { /* Disable */
2906 return ath11k_wmi_fils_discovery(ar, arvif->vdev_id, 0, false);
2911 "mac vdev %i failed to retrieve %s template\n",
2912 arvif->vdev_id, (unsol_bcast_probe_resp_enabled ?
2913 "unsolicited broadcast probe response" :
2920 ret = ath11k_wmi_fils_discovery(ar, arvif->vdev_id, interval,
2921 unsol_bcast_probe_resp_enabled);
2926 static int ath11k_mac_config_obss_pd(struct ath11k *ar,
2927 struct ieee80211_he_obss_pd *he_obss_pd)
2929 u32 bitmap[2], param_id, param_val, pdev_id;
2931 s8 non_srg_th = 0, srg_th = 0;
2933 pdev_id = ar->pdev->pdev_id;
2935 /* Set and enable SRG/non-SRG OBSS PD Threshold */
2936 param_id = WMI_PDEV_PARAM_SET_CMD_OBSS_PD_THRESHOLD;
2937 if (test_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags)) {
2938 ret = ath11k_wmi_pdev_set_param(ar, param_id, 0, pdev_id);
2941 "failed to set obss_pd_threshold for pdev: %u\n",
2946 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2947 "mac obss pd sr_ctrl %x non_srg_thres %u srg_max %u\n",
2948 he_obss_pd->sr_ctrl, he_obss_pd->non_srg_max_offset,
2949 he_obss_pd->max_offset);
2953 if (he_obss_pd->sr_ctrl &
2954 IEEE80211_HE_SPR_NON_SRG_OBSS_PD_SR_DISALLOWED) {
2955 non_srg_th = ATH11K_OBSS_PD_MAX_THRESHOLD;
2957 if (he_obss_pd->sr_ctrl & IEEE80211_HE_SPR_NON_SRG_OFFSET_PRESENT)
2958 non_srg_th = (ATH11K_OBSS_PD_MAX_THRESHOLD +
2959 he_obss_pd->non_srg_max_offset);
2961 non_srg_th = ATH11K_OBSS_PD_NON_SRG_MAX_THRESHOLD;
2963 param_val |= ATH11K_OBSS_PD_NON_SRG_EN;
2966 if (he_obss_pd->sr_ctrl & IEEE80211_HE_SPR_SRG_INFORMATION_PRESENT) {
2967 srg_th = ATH11K_OBSS_PD_MAX_THRESHOLD + he_obss_pd->max_offset;
2968 param_val |= ATH11K_OBSS_PD_SRG_EN;
2971 if (test_bit(WMI_TLV_SERVICE_SRG_SRP_SPATIAL_REUSE_SUPPORT,
2972 ar->ab->wmi_ab.svc_map)) {
2973 param_val |= ATH11K_OBSS_PD_THRESHOLD_IN_DBM;
2974 param_val |= FIELD_PREP(GENMASK(15, 8), srg_th);
2976 non_srg_th -= ATH11K_DEFAULT_NOISE_FLOOR;
2977 /* SRG not supported and threshold in dB */
2978 param_val &= ~(ATH11K_OBSS_PD_SRG_EN |
2979 ATH11K_OBSS_PD_THRESHOLD_IN_DBM);
2982 param_val |= (non_srg_th & GENMASK(7, 0));
2983 ret = ath11k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id);
2986 "failed to set obss_pd_threshold for pdev: %u\n",
2991 /* Enable OBSS PD for all access category */
2992 param_id = WMI_PDEV_PARAM_SET_CMD_OBSS_PD_PER_AC;
2994 ret = ath11k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id);
2997 "failed to set obss_pd_per_ac for pdev: %u\n",
3002 /* Set SR Prohibit */
3003 param_id = WMI_PDEV_PARAM_ENABLE_SR_PROHIBIT;
3004 param_val = !!(he_obss_pd->sr_ctrl &
3005 IEEE80211_HE_SPR_HESIGA_SR_VAL15_ALLOWED);
3006 ret = ath11k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id);
3008 ath11k_warn(ar->ab, "failed to set sr_prohibit for pdev: %u\n",
3013 if (!test_bit(WMI_TLV_SERVICE_SRG_SRP_SPATIAL_REUSE_SUPPORT,
3014 ar->ab->wmi_ab.svc_map))
3017 /* Set SRG BSS Color Bitmap */
3018 memcpy(bitmap, he_obss_pd->bss_color_bitmap, sizeof(bitmap));
3019 ret = ath11k_wmi_pdev_set_srg_bss_color_bitmap(ar, bitmap);
3022 "failed to set bss_color_bitmap for pdev: %u\n",
3027 /* Set SRG Partial BSSID Bitmap */
3028 memcpy(bitmap, he_obss_pd->partial_bssid_bitmap, sizeof(bitmap));
3029 ret = ath11k_wmi_pdev_set_srg_patial_bssid_bitmap(ar, bitmap);
3032 "failed to set partial_bssid_bitmap for pdev: %u\n",
3037 memset(bitmap, 0xff, sizeof(bitmap));
3039 /* Enable all BSS Colors for SRG */
3040 ret = ath11k_wmi_pdev_srg_obss_color_enable_bitmap(ar, bitmap);
3043 "failed to set srg_color_en_bitmap pdev: %u\n",
3048 /* Enable all patial BSSID mask for SRG */
3049 ret = ath11k_wmi_pdev_srg_obss_bssid_enable_bitmap(ar, bitmap);
3052 "failed to set srg_bssid_en_bitmap pdev: %u\n",
3057 /* Enable all BSS Colors for non-SRG */
3058 ret = ath11k_wmi_pdev_non_srg_obss_color_enable_bitmap(ar, bitmap);
3061 "failed to set non_srg_color_en_bitmap pdev: %u\n",
3066 /* Enable all patial BSSID mask for non-SRG */
3067 ret = ath11k_wmi_pdev_non_srg_obss_bssid_enable_bitmap(ar, bitmap);
3070 "failed to set non_srg_bssid_en_bitmap pdev: %u\n",
3078 static void ath11k_mac_op_bss_info_changed(struct ieee80211_hw *hw,
3079 struct ieee80211_vif *vif,
3080 struct ieee80211_bss_conf *info,
3083 struct ath11k *ar = hw->priv;
3084 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
3085 struct cfg80211_chan_def def;
3086 u32 param_id, param_value;
3087 enum nl80211_band band;
3097 mutex_lock(&ar->conf_mutex);
3099 if (changed & BSS_CHANGED_BEACON_INT) {
3100 arvif->beacon_interval = info->beacon_int;
3102 param_id = WMI_VDEV_PARAM_BEACON_INTERVAL;
3103 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3105 arvif->beacon_interval);
3107 ath11k_warn(ar->ab, "Failed to set beacon interval for VDEV: %d\n",
3110 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3111 "Beacon interval: %d set for VDEV: %d\n",
3112 arvif->beacon_interval, arvif->vdev_id);
3115 if (changed & BSS_CHANGED_BEACON) {
3116 param_id = WMI_PDEV_PARAM_BEACON_TX_MODE;
3117 param_value = WMI_BEACON_STAGGERED_MODE;
3118 ret = ath11k_wmi_pdev_set_param(ar, param_id,
3119 param_value, ar->pdev->pdev_id);
3121 ath11k_warn(ar->ab, "Failed to set beacon mode for VDEV: %d\n",
3124 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3125 "Set staggered beacon mode for VDEV: %d\n",
3128 if (!arvif->do_not_send_tmpl || !arvif->bcca_zero_sent) {
3129 ret = ath11k_mac_setup_bcn_tmpl(arvif);
3131 ath11k_warn(ar->ab, "failed to update bcn template: %d\n",
3135 if (arvif->bcca_zero_sent)
3136 arvif->do_not_send_tmpl = true;
3138 arvif->do_not_send_tmpl = false;
3140 if (vif->bss_conf.he_support) {
3141 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3142 WMI_VDEV_PARAM_BA_MODE,
3143 WMI_BA_MODE_BUFFER_SIZE_256);
3146 "failed to set BA BUFFER SIZE 256 for vdev: %d\n",
3149 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3150 "Set BA BUFFER SIZE 256 for VDEV: %d\n",
3155 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
3156 arvif->dtim_period = info->dtim_period;
3158 param_id = WMI_VDEV_PARAM_DTIM_PERIOD;
3159 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3161 arvif->dtim_period);
3164 ath11k_warn(ar->ab, "Failed to set dtim period for VDEV %d: %i\n",
3165 arvif->vdev_id, ret);
3167 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3168 "DTIM period: %d set for VDEV: %d\n",
3169 arvif->dtim_period, arvif->vdev_id);
3172 if (changed & BSS_CHANGED_SSID &&
3173 vif->type == NL80211_IFTYPE_AP) {
3174 arvif->u.ap.ssid_len = info->ssid_len;
3176 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
3177 arvif->u.ap.hidden_ssid = info->hidden_ssid;
3180 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
3181 ether_addr_copy(arvif->bssid, info->bssid);
3183 if (changed & BSS_CHANGED_BEACON_ENABLED) {
3184 ath11k_control_beaconing(arvif, info);
3186 if (arvif->is_up && vif->bss_conf.he_support &&
3187 vif->bss_conf.he_oper.params) {
3188 param_id = WMI_VDEV_PARAM_HEOPS_0_31;
3189 param_value = vif->bss_conf.he_oper.params;
3190 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3191 param_id, param_value);
3192 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3193 "he oper param: %x set for VDEV: %d\n",
3194 param_value, arvif->vdev_id);
3197 ath11k_warn(ar->ab, "Failed to set he oper params %x for VDEV %d: %i\n",
3198 param_value, arvif->vdev_id, ret);
3202 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3205 cts_prot = !!(info->use_cts_prot);
3206 param_id = WMI_VDEV_PARAM_PROTECTION_MODE;
3208 if (arvif->is_started) {
3209 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3210 param_id, cts_prot);
3212 ath11k_warn(ar->ab, "Failed to set CTS prot for VDEV: %d\n",
3215 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "Set CTS prot: %d for VDEV: %d\n",
3216 cts_prot, arvif->vdev_id);
3218 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "defer protection mode setup, vdev is not ready yet\n");
3222 if (changed & BSS_CHANGED_ERP_SLOT) {
3225 if (info->use_short_slot)
3226 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
3229 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
3231 param_id = WMI_VDEV_PARAM_SLOT_TIME;
3232 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3233 param_id, slottime);
3235 ath11k_warn(ar->ab, "Failed to set erp slot for VDEV: %d\n",
3238 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3239 "Set slottime: %d for VDEV: %d\n",
3240 slottime, arvif->vdev_id);
3243 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3246 if (info->use_short_preamble)
3247 preamble = WMI_VDEV_PREAMBLE_SHORT;
3249 preamble = WMI_VDEV_PREAMBLE_LONG;
3251 param_id = WMI_VDEV_PARAM_PREAMBLE;
3252 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3253 param_id, preamble);
3255 ath11k_warn(ar->ab, "Failed to set preamble for VDEV: %d\n",
3258 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3259 "Set preamble: %d for VDEV: %d\n",
3260 preamble, arvif->vdev_id);
3263 if (changed & BSS_CHANGED_ASSOC) {
3265 ath11k_bss_assoc(hw, vif, info);
3267 ath11k_bss_disassoc(hw, vif);
3270 if (changed & BSS_CHANGED_TXPOWER) {
3271 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev_id %i txpower %d\n",
3272 arvif->vdev_id, info->txpower);
3274 arvif->txpower = info->txpower;
3275 ath11k_mac_txpower_recalc(ar);
3278 if (changed & BSS_CHANGED_PS &&
3279 ar->ab->hw_params.supports_sta_ps) {
3280 arvif->ps = vif->bss_conf.ps;
3282 ret = ath11k_mac_config_ps(ar);
3284 ath11k_warn(ar->ab, "failed to setup ps on vdev %i: %d\n",
3285 arvif->vdev_id, ret);
3288 if (changed & BSS_CHANGED_MCAST_RATE &&
3289 !ath11k_mac_vif_chan(arvif->vif, &def)) {
3290 band = def.chan->band;
3291 mcast_rate = vif->bss_conf.mcast_rate[band];
3294 rateidx = mcast_rate - 1;
3296 rateidx = ffs(vif->bss_conf.basic_rates) - 1;
3298 if (ar->pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP)
3299 rateidx += ATH11K_MAC_FIRST_OFDM_RATE_IDX;
3301 bitrate = ath11k_legacy_rates[rateidx].bitrate;
3302 hw_value = ath11k_legacy_rates[rateidx].hw_value;
3304 if (ath11k_mac_bitrate_is_cck(bitrate))
3305 preamble = WMI_RATE_PREAMBLE_CCK;
3307 preamble = WMI_RATE_PREAMBLE_OFDM;
3309 rate = ATH11K_HW_RATE_CODE(hw_value, 0, preamble);
3311 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3312 "mac vdev %d mcast_rate %x\n",
3313 arvif->vdev_id, rate);
3315 vdev_param = WMI_VDEV_PARAM_MCAST_DATA_RATE;
3316 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3320 "failed to set mcast rate on vdev %i: %d\n",
3321 arvif->vdev_id, ret);
3323 vdev_param = WMI_VDEV_PARAM_BCAST_DATA_RATE;
3324 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3328 "failed to set bcast rate on vdev %i: %d\n",
3329 arvif->vdev_id, ret);
3332 if (changed & BSS_CHANGED_BASIC_RATES &&
3333 !ath11k_mac_vif_chan(arvif->vif, &def))
3334 ath11k_recalculate_mgmt_rate(ar, vif, &def);
3336 if (changed & BSS_CHANGED_TWT) {
3337 if (info->twt_requester || info->twt_responder)
3338 ath11k_wmi_send_twt_enable_cmd(ar, ar->pdev->pdev_id);
3340 ath11k_wmi_send_twt_disable_cmd(ar, ar->pdev->pdev_id);
3343 if (changed & BSS_CHANGED_HE_OBSS_PD)
3344 ath11k_mac_config_obss_pd(ar, &info->he_obss_pd);
3346 if (changed & BSS_CHANGED_HE_BSS_COLOR) {
3347 if (vif->type == NL80211_IFTYPE_AP) {
3348 ret = ath11k_wmi_send_obss_color_collision_cfg_cmd(
3349 ar, arvif->vdev_id, info->he_bss_color.color,
3350 ATH11K_BSS_COLOR_COLLISION_DETECTION_AP_PERIOD_MS,
3351 info->he_bss_color.enabled);
3353 ath11k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n",
3354 arvif->vdev_id, ret);
3356 param_id = WMI_VDEV_PARAM_BSS_COLOR;
3357 if (info->he_bss_color.enabled)
3358 param_value = info->he_bss_color.color <<
3359 IEEE80211_HE_OPERATION_BSS_COLOR_OFFSET;
3361 param_value = IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED;
3363 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3368 "failed to set bss color param on vdev %i: %d\n",
3369 arvif->vdev_id, ret);
3371 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3372 "bss color param 0x%x set on vdev %i\n",
3373 param_value, arvif->vdev_id);
3374 } else if (vif->type == NL80211_IFTYPE_STATION) {
3375 ret = ath11k_wmi_send_bss_color_change_enable_cmd(ar,
3379 ath11k_warn(ar->ab, "failed to enable bss color change on vdev %i: %d\n",
3380 arvif->vdev_id, ret);
3381 ret = ath11k_wmi_send_obss_color_collision_cfg_cmd(
3382 ar, arvif->vdev_id, 0,
3383 ATH11K_BSS_COLOR_COLLISION_DETECTION_STA_PERIOD_MS, 1);
3385 ath11k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n",
3386 arvif->vdev_id, ret);
3390 if (changed & BSS_CHANGED_FILS_DISCOVERY ||
3391 changed & BSS_CHANGED_UNSOL_BCAST_PROBE_RESP)
3392 ath11k_mac_fils_discovery(arvif, info);
3394 mutex_unlock(&ar->conf_mutex);
3397 void __ath11k_mac_scan_finish(struct ath11k *ar)
3399 lockdep_assert_held(&ar->data_lock);
3401 switch (ar->scan.state) {
3402 case ATH11K_SCAN_IDLE:
3404 case ATH11K_SCAN_RUNNING:
3405 case ATH11K_SCAN_ABORTING:
3406 if (ar->scan.is_roc && ar->scan.roc_notify)
3407 ieee80211_remain_on_channel_expired(ar->hw);
3409 case ATH11K_SCAN_STARTING:
3410 if (!ar->scan.is_roc) {
3411 struct cfg80211_scan_info info = {
3412 .aborted = ((ar->scan.state ==
3413 ATH11K_SCAN_ABORTING) ||
3415 ATH11K_SCAN_STARTING)),
3418 ieee80211_scan_completed(ar->hw, &info);
3421 ar->scan.state = ATH11K_SCAN_IDLE;
3422 ar->scan_channel = NULL;
3423 ar->scan.roc_freq = 0;
3424 cancel_delayed_work(&ar->scan.timeout);
3425 complete(&ar->scan.completed);
3430 void ath11k_mac_scan_finish(struct ath11k *ar)
3432 spin_lock_bh(&ar->data_lock);
3433 __ath11k_mac_scan_finish(ar);
3434 spin_unlock_bh(&ar->data_lock);
3437 static int ath11k_scan_stop(struct ath11k *ar)
3439 struct scan_cancel_param arg = {
3440 .req_type = WLAN_SCAN_CANCEL_SINGLE,
3441 .scan_id = ATH11K_SCAN_ID,
3445 lockdep_assert_held(&ar->conf_mutex);
3447 /* TODO: Fill other STOP Params */
3448 arg.pdev_id = ar->pdev->pdev_id;
3450 ret = ath11k_wmi_send_scan_stop_cmd(ar, &arg);
3452 ath11k_warn(ar->ab, "failed to stop wmi scan: %d\n", ret);
3456 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
3459 "failed to receive scan abort comple: timed out\n");
3461 } else if (ret > 0) {
3466 /* Scan state should be updated upon scan completion but in case
3467 * firmware fails to deliver the event (for whatever reason) it is
3468 * desired to clean up scan state anyway. Firmware may have just
3469 * dropped the scan completion event delivery due to transport pipe
3470 * being overflown with data and/or it can recover on its own before
3471 * next scan request is submitted.
3473 spin_lock_bh(&ar->data_lock);
3474 if (ar->scan.state != ATH11K_SCAN_IDLE)
3475 __ath11k_mac_scan_finish(ar);
3476 spin_unlock_bh(&ar->data_lock);
3481 static void ath11k_scan_abort(struct ath11k *ar)
3485 lockdep_assert_held(&ar->conf_mutex);
3487 spin_lock_bh(&ar->data_lock);
3489 switch (ar->scan.state) {
3490 case ATH11K_SCAN_IDLE:
3491 /* This can happen if timeout worker kicked in and called
3492 * abortion while scan completion was being processed.
3495 case ATH11K_SCAN_STARTING:
3496 case ATH11K_SCAN_ABORTING:
3497 ath11k_warn(ar->ab, "refusing scan abortion due to invalid scan state: %d\n",
3500 case ATH11K_SCAN_RUNNING:
3501 ar->scan.state = ATH11K_SCAN_ABORTING;
3502 spin_unlock_bh(&ar->data_lock);
3504 ret = ath11k_scan_stop(ar);
3506 ath11k_warn(ar->ab, "failed to abort scan: %d\n", ret);
3508 spin_lock_bh(&ar->data_lock);
3512 spin_unlock_bh(&ar->data_lock);
3515 static void ath11k_scan_timeout_work(struct work_struct *work)
3517 struct ath11k *ar = container_of(work, struct ath11k,
3520 mutex_lock(&ar->conf_mutex);
3521 ath11k_scan_abort(ar);
3522 mutex_unlock(&ar->conf_mutex);
3525 static int ath11k_start_scan(struct ath11k *ar,
3526 struct scan_req_params *arg)
3529 unsigned long timeout = 1 * HZ;
3531 lockdep_assert_held(&ar->conf_mutex);
3533 if (ath11k_spectral_get_mode(ar) == ATH11K_SPECTRAL_BACKGROUND)
3534 ath11k_spectral_reset_buffer(ar);
3536 ret = ath11k_wmi_send_scan_start_cmd(ar, arg);
3540 if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map)) {
3543 if (ar->supports_6ghz)
3547 ret = wait_for_completion_timeout(&ar->scan.started, timeout);
3549 ret = ath11k_scan_stop(ar);
3551 ath11k_warn(ar->ab, "failed to stop scan: %d\n", ret);
3556 /* If we failed to start the scan, return error code at
3557 * this point. This is probably due to some issue in the
3558 * firmware, but no need to wedge the driver due to that...
3560 spin_lock_bh(&ar->data_lock);
3561 if (ar->scan.state == ATH11K_SCAN_IDLE) {
3562 spin_unlock_bh(&ar->data_lock);
3565 spin_unlock_bh(&ar->data_lock);
3570 static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
3571 struct ieee80211_vif *vif,
3572 struct ieee80211_scan_request *hw_req)
3574 struct ath11k *ar = hw->priv;
3575 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
3576 struct cfg80211_scan_request *req = &hw_req->req;
3577 struct scan_req_params arg;
3581 mutex_lock(&ar->conf_mutex);
3583 spin_lock_bh(&ar->data_lock);
3584 switch (ar->scan.state) {
3585 case ATH11K_SCAN_IDLE:
3586 reinit_completion(&ar->scan.started);
3587 reinit_completion(&ar->scan.completed);
3588 ar->scan.state = ATH11K_SCAN_STARTING;
3589 ar->scan.is_roc = false;
3590 ar->scan.vdev_id = arvif->vdev_id;
3593 case ATH11K_SCAN_STARTING:
3594 case ATH11K_SCAN_RUNNING:
3595 case ATH11K_SCAN_ABORTING:
3599 spin_unlock_bh(&ar->data_lock);
3604 memset(&arg, 0, sizeof(arg));
3605 ath11k_wmi_start_scan_init(ar, &arg);
3606 arg.vdev_id = arvif->vdev_id;
3607 arg.scan_id = ATH11K_SCAN_ID;
3610 arg.extraie.ptr = kmemdup(req->ie, req->ie_len, GFP_KERNEL);
3611 if (!arg.extraie.ptr) {
3615 arg.extraie.len = req->ie_len;
3619 arg.num_ssids = req->n_ssids;
3620 for (i = 0; i < arg.num_ssids; i++) {
3621 arg.ssid[i].length = req->ssids[i].ssid_len;
3622 memcpy(&arg.ssid[i].ssid, req->ssids[i].ssid,
3623 req->ssids[i].ssid_len);
3626 arg.scan_flags |= WMI_SCAN_FLAG_PASSIVE;
3629 if (req->n_channels) {
3630 arg.num_chan = req->n_channels;
3631 arg.chan_list = kcalloc(arg.num_chan, sizeof(*arg.chan_list),
3634 if (!arg.chan_list) {
3639 for (i = 0; i < arg.num_chan; i++)
3640 arg.chan_list[i] = req->channels[i]->center_freq;
3643 if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
3644 arg.scan_f_add_spoofed_mac_in_probe = 1;
3645 ether_addr_copy(arg.mac_addr.addr, req->mac_addr);
3646 ether_addr_copy(arg.mac_mask.addr, req->mac_addr_mask);
3649 ret = ath11k_start_scan(ar, &arg);
3651 ath11k_warn(ar->ab, "failed to start hw scan: %d\n", ret);
3652 spin_lock_bh(&ar->data_lock);
3653 ar->scan.state = ATH11K_SCAN_IDLE;
3654 spin_unlock_bh(&ar->data_lock);
3657 /* Add a 200ms margin to account for event/command processing */
3658 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
3659 msecs_to_jiffies(arg.max_scan_time +
3660 ATH11K_MAC_SCAN_TIMEOUT_MSECS));
3663 kfree(arg.chan_list);
3666 kfree(arg.extraie.ptr);
3668 mutex_unlock(&ar->conf_mutex);
3670 if (ar->state_11d == ATH11K_11D_PREPARING)
3671 ath11k_mac_11d_scan_start(ar, arvif->vdev_id);
3676 static void ath11k_mac_op_cancel_hw_scan(struct ieee80211_hw *hw,
3677 struct ieee80211_vif *vif)
3679 struct ath11k *ar = hw->priv;
3681 mutex_lock(&ar->conf_mutex);
3682 ath11k_scan_abort(ar);
3683 mutex_unlock(&ar->conf_mutex);
3685 cancel_delayed_work_sync(&ar->scan.timeout);
3688 static int ath11k_install_key(struct ath11k_vif *arvif,
3689 struct ieee80211_key_conf *key,
3690 enum set_key_cmd cmd,
3691 const u8 *macaddr, u32 flags)
3694 struct ath11k *ar = arvif->ar;
3695 struct wmi_vdev_install_key_arg arg = {
3696 .vdev_id = arvif->vdev_id,
3697 .key_idx = key->keyidx,
3698 .key_len = key->keylen,
3699 .key_data = key->key,
3704 lockdep_assert_held(&arvif->ar->conf_mutex);
3706 reinit_completion(&ar->install_key_done);
3708 if (test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags))
3711 if (cmd == DISABLE_KEY) {
3712 arg.key_cipher = WMI_CIPHER_NONE;
3713 arg.key_data = NULL;
3717 switch (key->cipher) {
3718 case WLAN_CIPHER_SUITE_CCMP:
3719 arg.key_cipher = WMI_CIPHER_AES_CCM;
3720 /* TODO: Re-check if flag is valid */
3721 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
3723 case WLAN_CIPHER_SUITE_TKIP:
3724 arg.key_cipher = WMI_CIPHER_TKIP;
3725 arg.key_txmic_len = 8;
3726 arg.key_rxmic_len = 8;
3728 case WLAN_CIPHER_SUITE_CCMP_256:
3729 arg.key_cipher = WMI_CIPHER_AES_CCM;
3731 case WLAN_CIPHER_SUITE_GCMP:
3732 case WLAN_CIPHER_SUITE_GCMP_256:
3733 arg.key_cipher = WMI_CIPHER_AES_GCM;
3736 ath11k_warn(ar->ab, "cipher %d is not supported\n", key->cipher);
3740 if (test_bit(ATH11K_FLAG_RAW_MODE, &ar->ab->dev_flags))
3741 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV |
3742 IEEE80211_KEY_FLAG_RESERVE_TAILROOM;
3745 ret = ath11k_wmi_vdev_install_key(arvif->ar, &arg);
3750 if (!wait_for_completion_timeout(&ar->install_key_done, 1 * HZ))
3753 return ar->install_key_status ? -EINVAL : 0;
3756 static int ath11k_clear_peer_keys(struct ath11k_vif *arvif,
3759 struct ath11k *ar = arvif->ar;
3760 struct ath11k_base *ab = ar->ab;
3761 struct ath11k_peer *peer;
3762 int first_errno = 0;
3767 lockdep_assert_held(&ar->conf_mutex);
3769 spin_lock_bh(&ab->base_lock);
3770 peer = ath11k_peer_find(ab, arvif->vdev_id, addr);
3771 spin_unlock_bh(&ab->base_lock);
3776 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
3780 /* key flags are not required to delete the key */
3781 ret = ath11k_install_key(arvif, peer->keys[i],
3782 DISABLE_KEY, addr, flags);
3783 if (ret < 0 && first_errno == 0)
3787 ath11k_warn(ab, "failed to remove peer key %d: %d\n",
3790 spin_lock_bh(&ab->base_lock);
3791 peer->keys[i] = NULL;
3792 spin_unlock_bh(&ab->base_lock);
3798 static int ath11k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3799 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3800 struct ieee80211_key_conf *key)
3802 struct ath11k *ar = hw->priv;
3803 struct ath11k_base *ab = ar->ab;
3804 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
3805 struct ath11k_peer *peer;
3806 struct ath11k_sta *arsta;
3807 const u8 *peer_addr;
3811 /* BIP needs to be done in software */
3812 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3813 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3814 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 ||
3815 key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256)
3818 if (test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags))
3821 if (key->keyidx > WMI_MAX_KEY_INDEX)
3824 mutex_lock(&ar->conf_mutex);
3827 peer_addr = sta->addr;
3828 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
3829 peer_addr = vif->bss_conf.bssid;
3831 peer_addr = vif->addr;
3833 key->hw_key_idx = key->keyidx;
3835 /* the peer should not disappear in mid-way (unless FW goes awry) since
3836 * we already hold conf_mutex. we just make sure its there now.
3838 spin_lock_bh(&ab->base_lock);
3839 peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr);
3841 /* flush the fragments cache during key (re)install to
3842 * ensure all frags in the new frag list belong to the same key.
3844 if (peer && sta && cmd == SET_KEY)
3845 ath11k_peer_frags_flush(ar, peer);
3846 spin_unlock_bh(&ab->base_lock);
3849 if (cmd == SET_KEY) {
3850 ath11k_warn(ab, "cannot install key for non-existent peer %pM\n",
3855 /* if the peer doesn't exist there is no key to disable
3862 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3863 flags |= WMI_KEY_PAIRWISE;
3865 flags |= WMI_KEY_GROUP;
3867 ret = ath11k_install_key(arvif, key, cmd, peer_addr, flags);
3869 ath11k_warn(ab, "ath11k_install_key failed (%d)\n", ret);
3873 ret = ath11k_dp_peer_rx_pn_replay_config(arvif, peer_addr, cmd, key);
3875 ath11k_warn(ab, "failed to offload PN replay detection %d\n", ret);
3879 spin_lock_bh(&ab->base_lock);
3880 peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr);
3881 if (peer && cmd == SET_KEY) {
3882 peer->keys[key->keyidx] = key;
3883 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
3884 peer->ucast_keyidx = key->keyidx;
3885 peer->sec_type = ath11k_dp_tx_get_encrypt_type(key->cipher);
3887 peer->mcast_keyidx = key->keyidx;
3888 peer->sec_type_grp = ath11k_dp_tx_get_encrypt_type(key->cipher);
3890 } else if (peer && cmd == DISABLE_KEY) {
3891 peer->keys[key->keyidx] = NULL;
3892 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3893 peer->ucast_keyidx = 0;
3895 peer->mcast_keyidx = 0;
3897 /* impossible unless FW goes crazy */
3898 ath11k_warn(ab, "peer %pM disappeared!\n", peer_addr);
3901 arsta = (struct ath11k_sta *)sta->drv_priv;
3903 switch (key->cipher) {
3904 case WLAN_CIPHER_SUITE_TKIP:
3905 case WLAN_CIPHER_SUITE_CCMP:
3906 case WLAN_CIPHER_SUITE_CCMP_256:
3907 case WLAN_CIPHER_SUITE_GCMP:
3908 case WLAN_CIPHER_SUITE_GCMP_256:
3910 arsta->pn_type = HAL_PN_TYPE_WPA;
3912 arsta->pn_type = HAL_PN_TYPE_NONE;
3915 arsta->pn_type = HAL_PN_TYPE_NONE;
3920 spin_unlock_bh(&ab->base_lock);
3923 mutex_unlock(&ar->conf_mutex);
3928 ath11k_mac_bitrate_mask_num_vht_rates(struct ath11k *ar,
3929 enum nl80211_band band,
3930 const struct cfg80211_bitrate_mask *mask)
3935 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
3936 num_rates += hweight16(mask->control[band].vht_mcs[i]);
3942 ath11k_mac_bitrate_mask_num_he_rates(struct ath11k *ar,
3943 enum nl80211_band band,
3944 const struct cfg80211_bitrate_mask *mask)
3949 for (i = 0; i < ARRAY_SIZE(mask->control[band].he_mcs); i++)
3950 num_rates += hweight16(mask->control[band].he_mcs[i]);
3956 ath11k_mac_set_peer_vht_fixed_rate(struct ath11k_vif *arvif,
3957 struct ieee80211_sta *sta,
3958 const struct cfg80211_bitrate_mask *mask,
3959 enum nl80211_band band)
3961 struct ath11k *ar = arvif->ar;
3966 lockdep_assert_held(&ar->conf_mutex);
3970 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
3971 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
3973 vht_rate = ffs(mask->control[band].vht_mcs[i]) - 1;
3978 ath11k_warn(ar->ab, "No single VHT Fixed rate found to set for %pM",
3983 /* Avoid updating invalid nss as fixed rate*/
3984 if (nss > sta->rx_nss)
3987 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3988 "Setting Fixed VHT Rate for peer %pM. Device will not switch to any other selected rates",
3991 rate_code = ATH11K_HW_RATE_CODE(vht_rate, nss - 1,
3992 WMI_RATE_PREAMBLE_VHT);
3993 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
3995 WMI_PEER_PARAM_FIXED_RATE,
3999 "failed to update STA %pM Fixed Rate %d: %d\n",
4000 sta->addr, rate_code, ret);
4006 ath11k_mac_set_peer_he_fixed_rate(struct ath11k_vif *arvif,
4007 struct ieee80211_sta *sta,
4008 const struct cfg80211_bitrate_mask *mask,
4009 enum nl80211_band band)
4011 struct ath11k *ar = arvif->ar;
4016 lockdep_assert_held(&ar->conf_mutex);
4020 for (i = 0; i < ARRAY_SIZE(mask->control[band].he_mcs); i++) {
4021 if (hweight16(mask->control[band].he_mcs[i]) == 1) {
4023 he_rate = ffs(mask->control[band].he_mcs[i]) - 1;
4028 ath11k_warn(ar->ab, "No single he fixed rate found to set for %pM",
4033 /* Avoid updating invalid nss as fixed rate */
4034 if (nss > sta->rx_nss)
4037 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
4038 "mac setting fixed he rate for peer %pM, device will not switch to any other selected rates",
4041 rate_code = ATH11K_HW_RATE_CODE(he_rate, nss - 1,
4042 WMI_RATE_PREAMBLE_HE);
4044 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
4046 WMI_PEER_PARAM_FIXED_RATE,
4050 "failed to update sta %pM fixed rate %d: %d\n",
4051 sta->addr, rate_code, ret);
4056 static int ath11k_station_assoc(struct ath11k *ar,
4057 struct ieee80211_vif *vif,
4058 struct ieee80211_sta *sta,
4061 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4062 struct peer_assoc_params peer_arg;
4064 struct cfg80211_chan_def def;
4065 enum nl80211_band band;
4066 struct cfg80211_bitrate_mask *mask;
4067 u8 num_vht_rates, num_he_rates;
4069 lockdep_assert_held(&ar->conf_mutex);
4071 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
4074 band = def.chan->band;
4075 mask = &arvif->bitrate_mask;
4077 ath11k_peer_assoc_prepare(ar, vif, sta, &peer_arg, reassoc);
4079 peer_arg.is_assoc = true;
4080 ret = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
4082 ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n",
4083 sta->addr, arvif->vdev_id, ret);
4087 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
4088 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
4089 sta->addr, arvif->vdev_id);
4093 num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask);
4094 num_he_rates = ath11k_mac_bitrate_mask_num_he_rates(ar, band, mask);
4096 /* If single VHT/HE rate is configured (by set_bitrate_mask()),
4097 * peer_assoc will disable VHT/HE. This is now enabled by a peer specific
4099 * Note that all other rates and NSS will be disabled for this peer.
4101 if (sta->vht_cap.vht_supported && num_vht_rates == 1) {
4102 ret = ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask,
4106 } else if (sta->he_cap.has_he && num_he_rates == 1) {
4107 ret = ath11k_mac_set_peer_he_fixed_rate(arvif, sta, mask,
4113 /* Re-assoc is run only to update supported rates for given station. It
4114 * doesn't make much sense to reconfigure the peer completely.
4119 ret = ath11k_setup_peer_smps(ar, arvif, sta->addr,
4120 &sta->ht_cap, le16_to_cpu(sta->he_6ghz_capa.capa));
4122 ath11k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n",
4123 arvif->vdev_id, ret);
4128 arvif->num_legacy_stations++;
4129 ret = ath11k_recalc_rtscts_prot(arvif);
4134 if (sta->wme && sta->uapsd_queues) {
4135 ret = ath11k_peer_assoc_qos_ap(ar, arvif, sta);
4137 ath11k_warn(ar->ab, "failed to set qos params for STA %pM for vdev %i: %d\n",
4138 sta->addr, arvif->vdev_id, ret);
4146 static int ath11k_station_disassoc(struct ath11k *ar,
4147 struct ieee80211_vif *vif,
4148 struct ieee80211_sta *sta)
4150 struct ath11k_vif *arvif = (void *)vif->drv_priv;
4153 lockdep_assert_held(&ar->conf_mutex);
4156 arvif->num_legacy_stations--;
4157 ret = ath11k_recalc_rtscts_prot(arvif);
4162 ret = ath11k_clear_peer_keys(arvif, sta->addr);
4164 ath11k_warn(ar->ab, "failed to clear all peer keys for vdev %i: %d\n",
4165 arvif->vdev_id, ret);
4171 static void ath11k_sta_rc_update_wk(struct work_struct *wk)
4174 struct ath11k_vif *arvif;
4175 struct ath11k_sta *arsta;
4176 struct ieee80211_sta *sta;
4177 struct cfg80211_chan_def def;
4178 enum nl80211_band band;
4179 const u8 *ht_mcs_mask;
4180 const u16 *vht_mcs_mask;
4181 const u16 *he_mcs_mask;
4182 u32 changed, bw, nss, smps;
4183 int err, num_vht_rates, num_he_rates;
4184 const struct cfg80211_bitrate_mask *mask;
4185 struct peer_assoc_params peer_arg;
4187 arsta = container_of(wk, struct ath11k_sta, update_wk);
4188 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4189 arvif = arsta->arvif;
4192 if (WARN_ON(ath11k_mac_vif_chan(arvif->vif, &def)))
4195 band = def.chan->band;
4196 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
4197 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
4198 he_mcs_mask = arvif->bitrate_mask.control[band].he_mcs;
4200 spin_lock_bh(&ar->data_lock);
4202 changed = arsta->changed;
4209 spin_unlock_bh(&ar->data_lock);
4211 mutex_lock(&ar->conf_mutex);
4213 nss = max_t(u32, 1, nss);
4214 nss = min(nss, max(max(ath11k_mac_max_ht_nss(ht_mcs_mask),
4215 ath11k_mac_max_vht_nss(vht_mcs_mask)),
4216 ath11k_mac_max_he_nss(he_mcs_mask)));
4218 if (changed & IEEE80211_RC_BW_CHANGED) {
4219 /* Send peer assoc command before set peer bandwidth param to
4220 * avoid the mismatch between the peer phymode and the peer
4223 ath11k_peer_assoc_prepare(ar, arvif->vif, sta, &peer_arg, true);
4225 peer_arg.is_assoc = false;
4226 err = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
4228 ath11k_warn(ar->ab, "failed to send peer assoc for STA %pM vdev %i: %d\n",
4229 sta->addr, arvif->vdev_id, err);
4230 } else if (wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
4231 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
4232 WMI_PEER_CHWIDTH, bw);
4234 ath11k_warn(ar->ab, "failed to update STA %pM peer bw %d: %d\n",
4235 sta->addr, bw, err);
4237 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
4238 sta->addr, arvif->vdev_id);
4242 if (changed & IEEE80211_RC_NSS_CHANGED) {
4243 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM nss %d\n",
4246 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
4249 ath11k_warn(ar->ab, "failed to update STA %pM nss %d: %d\n",
4250 sta->addr, nss, err);
4253 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4254 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM smps %d\n",
4257 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
4258 WMI_PEER_MIMO_PS_STATE, smps);
4260 ath11k_warn(ar->ab, "failed to update STA %pM smps %d: %d\n",
4261 sta->addr, smps, err);
4264 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
4265 mask = &arvif->bitrate_mask;
4266 num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band,
4268 num_he_rates = ath11k_mac_bitrate_mask_num_he_rates(ar, band,
4271 /* Peer_assoc_prepare will reject vht rates in
4272 * bitrate_mask if its not available in range format and
4273 * sets vht tx_rateset as unsupported. So multiple VHT MCS
4274 * setting(eg. MCS 4,5,6) per peer is not supported here.
4275 * But, Single rate in VHT mask can be set as per-peer
4276 * fixed rate. But even if any HT rates are configured in
4277 * the bitrate mask, device will not switch to those rates
4278 * when per-peer Fixed rate is set.
4279 * TODO: Check RATEMASK_CMDID to support auto rates selection
4280 * across HT/VHT and for multiple VHT MCS support.
4282 if (sta->vht_cap.vht_supported && num_vht_rates == 1) {
4283 ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask,
4285 } else if (sta->he_cap.has_he && num_he_rates == 1) {
4286 ath11k_mac_set_peer_he_fixed_rate(arvif, sta, mask,
4289 /* If the peer is non-VHT/HE or no fixed VHT/HE rate
4290 * is provided in the new bitrate mask we set the
4291 * other rates using peer_assoc command. Also clear
4292 * the peer fixed rate settings as it has higher proprity
4295 err = ath11k_wmi_set_peer_param(ar, sta->addr,
4297 WMI_PEER_PARAM_FIXED_RATE,
4298 WMI_FIXED_RATE_NONE);
4301 "failed to disable peer fixed rate for sta %pM: %d\n",
4304 ath11k_peer_assoc_prepare(ar, arvif->vif, sta,
4307 peer_arg.is_assoc = false;
4308 err = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
4310 ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n",
4311 sta->addr, arvif->vdev_id, err);
4313 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ))
4314 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
4315 sta->addr, arvif->vdev_id);
4319 mutex_unlock(&ar->conf_mutex);
4322 static void ath11k_sta_set_4addr_wk(struct work_struct *wk)
4325 struct ath11k_vif *arvif;
4326 struct ath11k_sta *arsta;
4327 struct ieee80211_sta *sta;
4330 arsta = container_of(wk, struct ath11k_sta, set_4addr_wk);
4331 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
4332 arvif = arsta->arvif;
4335 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
4336 "setting USE_4ADDR for peer %pM\n", sta->addr);
4338 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
4340 WMI_PEER_USE_4ADDR, 1);
4343 ath11k_warn(ar->ab, "failed to set peer %pM 4addr capability: %d\n",
4347 static int ath11k_mac_inc_num_stations(struct ath11k_vif *arvif,
4348 struct ieee80211_sta *sta)
4350 struct ath11k *ar = arvif->ar;
4352 lockdep_assert_held(&ar->conf_mutex);
4354 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
4357 if (ar->num_stations >= ar->max_num_stations)
4365 static void ath11k_mac_dec_num_stations(struct ath11k_vif *arvif,
4366 struct ieee80211_sta *sta)
4368 struct ath11k *ar = arvif->ar;
4370 lockdep_assert_held(&ar->conf_mutex);
4372 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
4378 static int ath11k_mac_station_add(struct ath11k *ar,
4379 struct ieee80211_vif *vif,
4380 struct ieee80211_sta *sta)
4382 struct ath11k_base *ab = ar->ab;
4383 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4384 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
4385 struct peer_create_params peer_param;
4388 lockdep_assert_held(&ar->conf_mutex);
4390 ret = ath11k_mac_inc_num_stations(arvif, sta);
4392 ath11k_warn(ab, "refusing to associate station: too many connected already (%d)\n",
4393 ar->max_num_stations);
4397 arsta->rx_stats = kzalloc(sizeof(*arsta->rx_stats), GFP_KERNEL);
4398 if (!arsta->rx_stats) {
4400 goto dec_num_station;
4403 peer_param.vdev_id = arvif->vdev_id;
4404 peer_param.peer_addr = sta->addr;
4405 peer_param.peer_type = WMI_PEER_TYPE_DEFAULT;
4407 ret = ath11k_peer_create(ar, arvif, sta, &peer_param);
4409 ath11k_warn(ab, "Failed to add peer: %pM for VDEV: %d\n",
4410 sta->addr, arvif->vdev_id);
4414 ath11k_dbg(ab, ATH11K_DBG_MAC, "Added peer: %pM for VDEV: %d\n",
4415 sta->addr, arvif->vdev_id);
4417 if (ath11k_debugfs_is_extd_tx_stats_enabled(ar)) {
4418 arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats), GFP_KERNEL);
4419 if (!arsta->tx_stats) {
4425 if (ieee80211_vif_is_mesh(vif)) {
4426 ath11k_dbg(ab, ATH11K_DBG_MAC,
4427 "setting USE_4ADDR for mesh STA %pM\n", sta->addr);
4428 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
4430 WMI_PEER_USE_4ADDR, 1);
4432 ath11k_warn(ab, "failed to set mesh STA %pM 4addr capability: %d\n",
4438 ret = ath11k_dp_peer_setup(ar, arvif->vdev_id, sta->addr);
4440 ath11k_warn(ab, "failed to setup dp for peer %pM on vdev %i (%d)\n",
4441 sta->addr, arvif->vdev_id, ret);
4445 if (ab->hw_params.vdev_start_delay &&
4446 !arvif->is_started &&
4447 arvif->vdev_type != WMI_VDEV_TYPE_AP) {
4448 ret = ath11k_start_vdev_delay(ar->hw, vif);
4450 ath11k_warn(ab, "failed to delay vdev start: %d\n", ret);
4458 kfree(arsta->tx_stats);
4459 arsta->tx_stats = NULL;
4461 ath11k_peer_delete(ar, arvif->vdev_id, sta->addr);
4463 kfree(arsta->rx_stats);
4464 arsta->rx_stats = NULL;
4466 ath11k_mac_dec_num_stations(arvif, sta);
4471 static int ath11k_mac_op_sta_state(struct ieee80211_hw *hw,
4472 struct ieee80211_vif *vif,
4473 struct ieee80211_sta *sta,
4474 enum ieee80211_sta_state old_state,
4475 enum ieee80211_sta_state new_state)
4477 struct ath11k *ar = hw->priv;
4478 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4479 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
4480 struct ath11k_peer *peer;
4483 /* cancel must be done outside the mutex to avoid deadlock */
4484 if ((old_state == IEEE80211_STA_NONE &&
4485 new_state == IEEE80211_STA_NOTEXIST)) {
4486 cancel_work_sync(&arsta->update_wk);
4487 cancel_work_sync(&arsta->set_4addr_wk);
4490 mutex_lock(&ar->conf_mutex);
4492 if (old_state == IEEE80211_STA_NOTEXIST &&
4493 new_state == IEEE80211_STA_NONE) {
4494 memset(arsta, 0, sizeof(*arsta));
4495 arsta->arvif = arvif;
4496 INIT_WORK(&arsta->update_wk, ath11k_sta_rc_update_wk);
4497 INIT_WORK(&arsta->set_4addr_wk, ath11k_sta_set_4addr_wk);
4499 ret = ath11k_mac_station_add(ar, vif, sta);
4501 ath11k_warn(ar->ab, "Failed to add station: %pM for VDEV: %d\n",
4502 sta->addr, arvif->vdev_id);
4503 } else if ((old_state == IEEE80211_STA_NONE &&
4504 new_state == IEEE80211_STA_NOTEXIST)) {
4505 bool skip_peer_delete = ar->ab->hw_params.vdev_start_delay &&
4506 vif->type == NL80211_IFTYPE_STATION;
4508 ath11k_dp_peer_cleanup(ar, arvif->vdev_id, sta->addr);
4510 if (!skip_peer_delete) {
4511 ret = ath11k_peer_delete(ar, arvif->vdev_id, sta->addr);
4514 "Failed to delete peer: %pM for VDEV: %d\n",
4515 sta->addr, arvif->vdev_id);
4519 "Removed peer: %pM for VDEV: %d\n",
4520 sta->addr, arvif->vdev_id);
4523 ath11k_mac_dec_num_stations(arvif, sta);
4524 spin_lock_bh(&ar->ab->base_lock);
4525 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
4526 if (skip_peer_delete && peer) {
4528 } else if (peer && peer->sta == sta) {
4529 ath11k_warn(ar->ab, "Found peer entry %pM n vdev %i after it was supposedly removed\n",
4530 vif->addr, arvif->vdev_id);
4532 list_del(&peer->list);
4536 spin_unlock_bh(&ar->ab->base_lock);
4538 kfree(arsta->tx_stats);
4539 arsta->tx_stats = NULL;
4541 kfree(arsta->rx_stats);
4542 arsta->rx_stats = NULL;
4543 } else if (old_state == IEEE80211_STA_AUTH &&
4544 new_state == IEEE80211_STA_ASSOC &&
4545 (vif->type == NL80211_IFTYPE_AP ||
4546 vif->type == NL80211_IFTYPE_MESH_POINT ||
4547 vif->type == NL80211_IFTYPE_ADHOC)) {
4548 ret = ath11k_station_assoc(ar, vif, sta, false);
4550 ath11k_warn(ar->ab, "Failed to associate station: %pM\n",
4552 } else if (old_state == IEEE80211_STA_ASSOC &&
4553 new_state == IEEE80211_STA_AUTHORIZED) {
4554 spin_lock_bh(&ar->ab->base_lock);
4556 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
4558 peer->is_authorized = true;
4560 spin_unlock_bh(&ar->ab->base_lock);
4562 if (vif->type == NL80211_IFTYPE_STATION && arvif->is_up) {
4563 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
4568 ath11k_warn(ar->ab, "Unable to authorize peer %pM vdev %d: %d\n",
4569 sta->addr, arvif->vdev_id, ret);
4571 } else if (old_state == IEEE80211_STA_AUTHORIZED &&
4572 new_state == IEEE80211_STA_ASSOC) {
4573 spin_lock_bh(&ar->ab->base_lock);
4575 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
4577 peer->is_authorized = false;
4579 spin_unlock_bh(&ar->ab->base_lock);
4580 } else if (old_state == IEEE80211_STA_ASSOC &&
4581 new_state == IEEE80211_STA_AUTH &&
4582 (vif->type == NL80211_IFTYPE_AP ||
4583 vif->type == NL80211_IFTYPE_MESH_POINT ||
4584 vif->type == NL80211_IFTYPE_ADHOC)) {
4585 ret = ath11k_station_disassoc(ar, vif, sta);
4587 ath11k_warn(ar->ab, "Failed to disassociate station: %pM\n",
4591 mutex_unlock(&ar->conf_mutex);
4595 static int ath11k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw,
4596 struct ieee80211_vif *vif,
4597 struct ieee80211_sta *sta)
4599 struct ath11k *ar = hw->priv;
4600 struct ath11k_vif *arvif = (void *)vif->drv_priv;
4604 if (sta->txpwr.type == NL80211_TX_POWER_AUTOMATIC) {
4607 txpwr = sta->txpwr.power;
4612 if (txpwr > ATH11K_TX_POWER_MAX_VAL || txpwr < ATH11K_TX_POWER_MIN_VAL)
4615 mutex_lock(&ar->conf_mutex);
4617 ret = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
4618 WMI_PEER_USE_FIXED_PWR, txpwr);
4620 ath11k_warn(ar->ab, "failed to set tx power for station ret: %d\n",
4626 mutex_unlock(&ar->conf_mutex);
4630 static void ath11k_mac_op_sta_set_4addr(struct ieee80211_hw *hw,
4631 struct ieee80211_vif *vif,
4632 struct ieee80211_sta *sta, bool enabled)
4634 struct ath11k *ar = hw->priv;
4635 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
4637 if (enabled && !arsta->use_4addr_set) {
4638 ieee80211_queue_work(ar->hw, &arsta->set_4addr_wk);
4639 arsta->use_4addr_set = true;
4643 static void ath11k_mac_op_sta_rc_update(struct ieee80211_hw *hw,
4644 struct ieee80211_vif *vif,
4645 struct ieee80211_sta *sta,
4648 struct ath11k *ar = hw->priv;
4649 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
4650 struct ath11k_vif *arvif = (void *)vif->drv_priv;
4651 struct ath11k_peer *peer;
4654 spin_lock_bh(&ar->ab->base_lock);
4656 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
4658 spin_unlock_bh(&ar->ab->base_lock);
4659 ath11k_warn(ar->ab, "mac sta rc update failed to find peer %pM on vdev %i\n",
4660 sta->addr, arvif->vdev_id);
4664 spin_unlock_bh(&ar->ab->base_lock);
4666 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
4667 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
4668 sta->addr, changed, sta->bandwidth, sta->rx_nss,
4671 spin_lock_bh(&ar->data_lock);
4673 if (changed & IEEE80211_RC_BW_CHANGED) {
4674 bw = WMI_PEER_CHWIDTH_20MHZ;
4676 switch (sta->bandwidth) {
4677 case IEEE80211_STA_RX_BW_20:
4678 bw = WMI_PEER_CHWIDTH_20MHZ;
4680 case IEEE80211_STA_RX_BW_40:
4681 bw = WMI_PEER_CHWIDTH_40MHZ;
4683 case IEEE80211_STA_RX_BW_80:
4684 bw = WMI_PEER_CHWIDTH_80MHZ;
4686 case IEEE80211_STA_RX_BW_160:
4687 bw = WMI_PEER_CHWIDTH_160MHZ;
4690 ath11k_warn(ar->ab, "Invalid bandwidth %d in rc update for %pM\n",
4691 sta->bandwidth, sta->addr);
4692 bw = WMI_PEER_CHWIDTH_20MHZ;
4699 if (changed & IEEE80211_RC_NSS_CHANGED)
4700 arsta->nss = sta->rx_nss;
4702 if (changed & IEEE80211_RC_SMPS_CHANGED) {
4703 smps = WMI_PEER_SMPS_PS_NONE;
4705 switch (sta->smps_mode) {
4706 case IEEE80211_SMPS_AUTOMATIC:
4707 case IEEE80211_SMPS_OFF:
4708 smps = WMI_PEER_SMPS_PS_NONE;
4710 case IEEE80211_SMPS_STATIC:
4711 smps = WMI_PEER_SMPS_STATIC;
4713 case IEEE80211_SMPS_DYNAMIC:
4714 smps = WMI_PEER_SMPS_DYNAMIC;
4717 ath11k_warn(ar->ab, "Invalid smps %d in sta rc update for %pM\n",
4718 sta->smps_mode, sta->addr);
4719 smps = WMI_PEER_SMPS_PS_NONE;
4726 arsta->changed |= changed;
4728 spin_unlock_bh(&ar->data_lock);
4730 ieee80211_queue_work(hw, &arsta->update_wk);
4733 static int ath11k_conf_tx_uapsd(struct ath11k *ar, struct ieee80211_vif *vif,
4734 u16 ac, bool enable)
4736 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4740 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
4744 case IEEE80211_AC_VO:
4745 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
4746 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
4748 case IEEE80211_AC_VI:
4749 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
4750 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
4752 case IEEE80211_AC_BE:
4753 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
4754 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
4756 case IEEE80211_AC_BK:
4757 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
4758 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
4763 arvif->u.sta.uapsd |= value;
4765 arvif->u.sta.uapsd &= ~value;
4767 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4768 WMI_STA_PS_PARAM_UAPSD,
4769 arvif->u.sta.uapsd);
4771 ath11k_warn(ar->ab, "could not set uapsd params %d\n", ret);
4775 if (arvif->u.sta.uapsd)
4776 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
4778 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4780 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4781 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
4784 ath11k_warn(ar->ab, "could not set rx wake param %d\n", ret);
4790 static int ath11k_mac_op_conf_tx(struct ieee80211_hw *hw,
4791 struct ieee80211_vif *vif, u16 ac,
4792 const struct ieee80211_tx_queue_params *params)
4794 struct ath11k *ar = hw->priv;
4795 struct ath11k_vif *arvif = (void *)vif->drv_priv;
4796 struct wmi_wmm_params_arg *p = NULL;
4799 mutex_lock(&ar->conf_mutex);
4802 case IEEE80211_AC_VO:
4803 p = &arvif->wmm_params.ac_vo;
4805 case IEEE80211_AC_VI:
4806 p = &arvif->wmm_params.ac_vi;
4808 case IEEE80211_AC_BE:
4809 p = &arvif->wmm_params.ac_be;
4811 case IEEE80211_AC_BK:
4812 p = &arvif->wmm_params.ac_bk;
4821 p->cwmin = params->cw_min;
4822 p->cwmax = params->cw_max;
4823 p->aifs = params->aifs;
4824 p->txop = params->txop;
4826 ret = ath11k_wmi_send_wmm_update_cmd_tlv(ar, arvif->vdev_id,
4827 &arvif->wmm_params);
4829 ath11k_warn(ar->ab, "failed to set wmm params: %d\n", ret);
4833 ret = ath11k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
4836 ath11k_warn(ar->ab, "failed to set sta uapsd: %d\n", ret);
4839 mutex_unlock(&ar->conf_mutex);
4843 static struct ieee80211_sta_ht_cap
4844 ath11k_create_ht_cap(struct ath11k *ar, u32 ar_ht_cap, u32 rate_cap_rx_chainmask)
4847 struct ieee80211_sta_ht_cap ht_cap = {0};
4848 u32 ar_vht_cap = ar->pdev->cap.vht_cap;
4850 if (!(ar_ht_cap & WMI_HT_CAP_ENABLED))
4853 ht_cap.ht_supported = 1;
4854 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
4855 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
4856 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
4857 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
4858 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
4860 if (ar_ht_cap & WMI_HT_CAP_HT20_SGI)
4861 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
4863 if (ar_ht_cap & WMI_HT_CAP_HT40_SGI)
4864 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
4866 if (ar_ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) {
4869 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
4870 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
4875 if (ar_ht_cap & WMI_HT_CAP_TX_STBC)
4876 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
4878 if (ar_ht_cap & WMI_HT_CAP_RX_STBC) {
4882 stbc &= WMI_HT_CAP_RX_STBC;
4883 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
4884 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
4885 stbc &= IEEE80211_HT_CAP_RX_STBC;
4890 if (ar_ht_cap & WMI_HT_CAP_RX_LDPC)
4891 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
4893 if (ar_ht_cap & WMI_HT_CAP_L_SIG_TXOP_PROT)
4894 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
4896 if (ar_vht_cap & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
4897 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
4899 for (i = 0; i < ar->num_rx_chains; i++) {
4900 if (rate_cap_rx_chainmask & BIT(i))
4901 ht_cap.mcs.rx_mask[i] = 0xFF;
4904 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
4909 static int ath11k_mac_set_txbf_conf(struct ath11k_vif *arvif)
4912 struct ath11k *ar = arvif->ar;
4915 u32 vht_cap = ar->pdev->cap.vht_cap;
4916 u32 vdev_param = WMI_VDEV_PARAM_TXBF;
4918 if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)) {
4919 nsts = vht_cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
4920 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
4921 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
4924 if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) {
4925 sound_dim = vht_cap &
4926 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4927 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4928 if (sound_dim > (ar->num_tx_chains - 1))
4929 sound_dim = ar->num_tx_chains - 1;
4930 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
4936 if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) {
4937 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
4939 if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) &&
4940 arvif->vdev_type == WMI_VDEV_TYPE_AP)
4941 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
4944 /* TODO: SUBFEE not validated in HK, disable here until validated? */
4946 if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) {
4947 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
4949 if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) &&
4950 arvif->vdev_type == WMI_VDEV_TYPE_STA)
4951 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
4954 return ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4958 static void ath11k_set_vht_txbf_cap(struct ath11k *ar, u32 *vht_cap)
4960 bool subfer, subfee;
4963 subfer = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE));
4964 subfee = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE));
4966 if (ar->num_tx_chains < 2) {
4967 *vht_cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
4971 /* If SU Beaformer is not set, then disable MU Beamformer Capability */
4973 *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE);
4975 /* If SU Beaformee is not set, then disable MU Beamformee Capability */
4977 *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
4979 sound_dim = (*vht_cap & IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK);
4980 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4981 *vht_cap &= ~IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4983 /* TODO: Need to check invalid STS and Sound_dim values set by FW? */
4985 /* Enable Sounding Dimension Field only if SU BF is enabled */
4987 if (sound_dim > (ar->num_tx_chains - 1))
4988 sound_dim = ar->num_tx_chains - 1;
4990 sound_dim <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
4991 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
4992 *vht_cap |= sound_dim;
4995 /* Use the STS advertised by FW unless SU Beamformee is not supported*/
4997 *vht_cap &= ~(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK);
5000 static struct ieee80211_sta_vht_cap
5001 ath11k_create_vht_cap(struct ath11k *ar, u32 rate_cap_tx_chainmask,
5002 u32 rate_cap_rx_chainmask)
5004 struct ieee80211_sta_vht_cap vht_cap = {0};
5005 u16 txmcs_map, rxmcs_map;
5008 vht_cap.vht_supported = 1;
5009 vht_cap.cap = ar->pdev->cap.vht_cap;
5011 if (ar->pdev->cap.nss_ratio_enabled)
5012 vht_cap.vht_mcs.tx_highest |=
5013 cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE);
5015 ath11k_set_vht_txbf_cap(ar, &vht_cap.cap);
5019 for (i = 0; i < 8; i++) {
5020 if (i < ar->num_tx_chains && rate_cap_tx_chainmask & BIT(i))
5021 txmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
5023 txmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
5025 if (i < ar->num_rx_chains && rate_cap_rx_chainmask & BIT(i))
5026 rxmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
5028 rxmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
5031 if (rate_cap_tx_chainmask <= 1)
5032 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
5034 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_map);
5035 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_map);
5040 static void ath11k_mac_setup_ht_vht_cap(struct ath11k *ar,
5041 struct ath11k_pdev_cap *cap,
5044 struct ieee80211_supported_band *band;
5045 u32 rate_cap_tx_chainmask;
5046 u32 rate_cap_rx_chainmask;
5049 rate_cap_tx_chainmask = ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift;
5050 rate_cap_rx_chainmask = ar->cfg_rx_chainmask >> cap->rx_chain_mask_shift;
5052 if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) {
5053 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
5054 ht_cap = cap->band[NL80211_BAND_2GHZ].ht_cap_info;
5056 *ht_cap_info = ht_cap;
5057 band->ht_cap = ath11k_create_ht_cap(ar, ht_cap,
5058 rate_cap_rx_chainmask);
5061 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP &&
5062 (ar->ab->hw_params.single_pdev_only ||
5063 !ar->supports_6ghz)) {
5064 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
5065 ht_cap = cap->band[NL80211_BAND_5GHZ].ht_cap_info;
5067 *ht_cap_info = ht_cap;
5068 band->ht_cap = ath11k_create_ht_cap(ar, ht_cap,
5069 rate_cap_rx_chainmask);
5070 band->vht_cap = ath11k_create_vht_cap(ar, rate_cap_tx_chainmask,
5071 rate_cap_rx_chainmask);
5075 static int ath11k_check_chain_mask(struct ath11k *ar, u32 ant, bool is_tx_ant)
5077 /* TODO: Check the request chainmask against the supported
5078 * chainmask table which is advertised in extented_service_ready event
5084 static void ath11k_gen_ppe_thresh(struct ath11k_ppe_threshold *fw_ppet,
5090 he_ppet[0] = fw_ppet->numss_m1 & IEEE80211_PPE_THRES_NSS_MASK;
5091 he_ppet[0] |= (fw_ppet->ru_bit_mask <<
5092 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS) &
5093 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK;
5094 for (nss = 0; nss <= fw_ppet->numss_m1; nss++) {
5095 for (ru = 0; ru < 4; ru++) {
5099 if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0)
5101 val = (fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> (ru * 6)) &
5103 val = ((val >> 3) & 0x7) | ((val & 0x7) << 3);
5104 for (i = 5; i >= 0; i--) {
5106 ((val >> i) & 0x1) << ((bit % 8));
5114 ath11k_mac_filter_he_cap_mesh(struct ieee80211_he_cap_elem *he_cap_elem)
5118 m = IEEE80211_HE_MAC_CAP0_TWT_RES |
5119 IEEE80211_HE_MAC_CAP0_TWT_REQ;
5120 he_cap_elem->mac_cap_info[0] &= ~m;
5122 m = IEEE80211_HE_MAC_CAP2_TRS |
5123 IEEE80211_HE_MAC_CAP2_BCAST_TWT |
5124 IEEE80211_HE_MAC_CAP2_MU_CASCADING;
5125 he_cap_elem->mac_cap_info[2] &= ~m;
5127 m = IEEE80211_HE_MAC_CAP3_FLEX_TWT_SCHED |
5128 IEEE80211_HE_MAC_CAP2_BCAST_TWT |
5129 IEEE80211_HE_MAC_CAP2_MU_CASCADING;
5130 he_cap_elem->mac_cap_info[3] &= ~m;
5132 m = IEEE80211_HE_MAC_CAP4_BSRP_BQRP_A_MPDU_AGG |
5133 IEEE80211_HE_MAC_CAP4_BQR;
5134 he_cap_elem->mac_cap_info[4] &= ~m;
5136 m = IEEE80211_HE_MAC_CAP5_SUBCHAN_SELECTIVE_TRANSMISSION |
5137 IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU |
5138 IEEE80211_HE_MAC_CAP5_PUNCTURED_SOUNDING |
5139 IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX;
5140 he_cap_elem->mac_cap_info[5] &= ~m;
5142 m = IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
5143 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO;
5144 he_cap_elem->phy_cap_info[2] &= ~m;
5146 m = IEEE80211_HE_PHY_CAP3_RX_PARTIAL_BW_SU_IN_20MHZ_MU |
5147 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK |
5148 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK;
5149 he_cap_elem->phy_cap_info[3] &= ~m;
5151 m = IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
5152 he_cap_elem->phy_cap_info[4] &= ~m;
5154 m = IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK;
5155 he_cap_elem->phy_cap_info[5] &= ~m;
5157 m = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU |
5158 IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB |
5159 IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB |
5160 IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO;
5161 he_cap_elem->phy_cap_info[6] &= ~m;
5163 m = IEEE80211_HE_PHY_CAP7_PSR_BASED_SR |
5164 IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP |
5165 IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ |
5166 IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ;
5167 he_cap_elem->phy_cap_info[7] &= ~m;
5169 m = IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI |
5170 IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
5171 IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
5172 IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU;
5173 he_cap_elem->phy_cap_info[8] &= ~m;
5175 m = IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM |
5176 IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK |
5177 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU |
5178 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
5179 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
5180 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB;
5181 he_cap_elem->phy_cap_info[9] &= ~m;
5184 static __le16 ath11k_mac_setup_he_6ghz_cap(struct ath11k_pdev_cap *pcap,
5185 struct ath11k_band_cap *bcap)
5189 bcap->he_6ghz_capa = IEEE80211_HT_MPDU_DENSITY_NONE;
5190 if (bcap->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
5191 bcap->he_6ghz_capa |=
5192 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_SM_PS,
5193 WLAN_HT_CAP_SM_PS_DYNAMIC);
5195 bcap->he_6ghz_capa |=
5196 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_SM_PS,
5197 WLAN_HT_CAP_SM_PS_DISABLED);
5198 val = FIELD_GET(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK,
5200 bcap->he_6ghz_capa |=
5201 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP, val);
5202 val = FIELD_GET(IEEE80211_VHT_CAP_MAX_MPDU_MASK, pcap->vht_cap);
5203 bcap->he_6ghz_capa |=
5204 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN, val);
5205 if (pcap->vht_cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN)
5206 bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS;
5207 if (pcap->vht_cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN)
5208 bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS;
5210 return cpu_to_le16(bcap->he_6ghz_capa);
5213 static int ath11k_mac_copy_he_cap(struct ath11k *ar,
5214 struct ath11k_pdev_cap *cap,
5215 struct ieee80211_sband_iftype_data *data,
5220 for (i = 0; i < NUM_NL80211_IFTYPES; i++) {
5221 struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap;
5222 struct ath11k_band_cap *band_cap = &cap->band[band];
5223 struct ieee80211_he_cap_elem *he_cap_elem =
5224 &he_cap->he_cap_elem;
5227 case NL80211_IFTYPE_STATION:
5228 case NL80211_IFTYPE_AP:
5229 case NL80211_IFTYPE_MESH_POINT:
5236 data[idx].types_mask = BIT(i);
5237 he_cap->has_he = true;
5238 memcpy(he_cap_elem->mac_cap_info, band_cap->he_cap_info,
5239 sizeof(he_cap_elem->mac_cap_info));
5240 memcpy(he_cap_elem->phy_cap_info, band_cap->he_cap_phy_info,
5241 sizeof(he_cap_elem->phy_cap_info));
5243 he_cap_elem->mac_cap_info[1] &=
5244 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_MASK;
5246 he_cap_elem->phy_cap_info[5] &=
5247 ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK;
5248 he_cap_elem->phy_cap_info[5] |= ar->num_tx_chains - 1;
5251 case NL80211_IFTYPE_AP:
5252 he_cap_elem->phy_cap_info[3] &=
5253 ~IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK;
5254 he_cap_elem->phy_cap_info[9] |=
5255 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU;
5257 case NL80211_IFTYPE_STATION:
5258 he_cap_elem->mac_cap_info[0] &=
5259 ~IEEE80211_HE_MAC_CAP0_TWT_RES;
5260 he_cap_elem->mac_cap_info[0] |=
5261 IEEE80211_HE_MAC_CAP0_TWT_REQ;
5262 he_cap_elem->phy_cap_info[9] |=
5263 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU;
5265 case NL80211_IFTYPE_MESH_POINT:
5266 ath11k_mac_filter_he_cap_mesh(he_cap_elem);
5270 he_cap->he_mcs_nss_supp.rx_mcs_80 =
5271 cpu_to_le16(band_cap->he_mcs & 0xffff);
5272 he_cap->he_mcs_nss_supp.tx_mcs_80 =
5273 cpu_to_le16(band_cap->he_mcs & 0xffff);
5274 he_cap->he_mcs_nss_supp.rx_mcs_160 =
5275 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
5276 he_cap->he_mcs_nss_supp.tx_mcs_160 =
5277 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
5278 he_cap->he_mcs_nss_supp.rx_mcs_80p80 =
5279 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
5280 he_cap->he_mcs_nss_supp.tx_mcs_80p80 =
5281 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
5283 memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
5284 if (he_cap_elem->phy_cap_info[6] &
5285 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
5286 ath11k_gen_ppe_thresh(&band_cap->he_ppet,
5289 if (band == NL80211_BAND_6GHZ) {
5290 data[idx].he_6ghz_capa.capa =
5291 ath11k_mac_setup_he_6ghz_cap(cap, band_cap);
5299 static void ath11k_mac_setup_he_cap(struct ath11k *ar,
5300 struct ath11k_pdev_cap *cap)
5302 struct ieee80211_supported_band *band;
5305 if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) {
5306 count = ath11k_mac_copy_he_cap(ar, cap,
5307 ar->mac.iftype[NL80211_BAND_2GHZ],
5309 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
5310 band->iftype_data = ar->mac.iftype[NL80211_BAND_2GHZ];
5311 band->n_iftype_data = count;
5314 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP) {
5315 count = ath11k_mac_copy_he_cap(ar, cap,
5316 ar->mac.iftype[NL80211_BAND_5GHZ],
5318 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
5319 band->iftype_data = ar->mac.iftype[NL80211_BAND_5GHZ];
5320 band->n_iftype_data = count;
5323 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP &&
5324 ar->supports_6ghz) {
5325 count = ath11k_mac_copy_he_cap(ar, cap,
5326 ar->mac.iftype[NL80211_BAND_6GHZ],
5328 band = &ar->mac.sbands[NL80211_BAND_6GHZ];
5329 band->iftype_data = ar->mac.iftype[NL80211_BAND_6GHZ];
5330 band->n_iftype_data = count;
5334 static int __ath11k_set_antenna(struct ath11k *ar, u32 tx_ant, u32 rx_ant)
5338 lockdep_assert_held(&ar->conf_mutex);
5340 if (ath11k_check_chain_mask(ar, tx_ant, true))
5343 if (ath11k_check_chain_mask(ar, rx_ant, false))
5346 ar->cfg_tx_chainmask = tx_ant;
5347 ar->cfg_rx_chainmask = rx_ant;
5349 if (ar->state != ATH11K_STATE_ON &&
5350 ar->state != ATH11K_STATE_RESTARTED)
5353 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_TX_CHAIN_MASK,
5354 tx_ant, ar->pdev->pdev_id);
5356 ath11k_warn(ar->ab, "failed to set tx-chainmask: %d, req 0x%x\n",
5361 ar->num_tx_chains = get_num_chains(tx_ant);
5363 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RX_CHAIN_MASK,
5364 rx_ant, ar->pdev->pdev_id);
5366 ath11k_warn(ar->ab, "failed to set rx-chainmask: %d, req 0x%x\n",
5371 ar->num_rx_chains = get_num_chains(rx_ant);
5373 /* Reload HT/VHT/HE capability */
5374 ath11k_mac_setup_ht_vht_cap(ar, &ar->pdev->cap, NULL);
5375 ath11k_mac_setup_he_cap(ar, &ar->pdev->cap);
5380 static void ath11k_mgmt_over_wmi_tx_drop(struct ath11k *ar, struct sk_buff *skb)
5384 ieee80211_free_txskb(ar->hw, skb);
5386 num_mgmt = atomic_dec_if_positive(&ar->num_pending_mgmt_tx);
5392 wake_up(&ar->txmgmt_empty_waitq);
5395 static void ath11k_mac_tx_mgmt_free(struct ath11k *ar, int buf_id)
5397 struct sk_buff *msdu;
5398 struct ieee80211_tx_info *info;
5400 spin_lock_bh(&ar->txmgmt_idr_lock);
5401 msdu = idr_remove(&ar->txmgmt_idr, buf_id);
5402 spin_unlock_bh(&ar->txmgmt_idr_lock);
5407 dma_unmap_single(ar->ab->dev, ATH11K_SKB_CB(msdu)->paddr, msdu->len,
5410 info = IEEE80211_SKB_CB(msdu);
5411 memset(&info->status, 0, sizeof(info->status));
5413 ath11k_mgmt_over_wmi_tx_drop(ar, msdu);
5416 int ath11k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx)
5418 struct ath11k *ar = ctx;
5420 ath11k_mac_tx_mgmt_free(ar, buf_id);
5425 static int ath11k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx)
5427 struct ieee80211_vif *vif = ctx;
5428 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb);
5429 struct ath11k *ar = skb_cb->ar;
5431 if (skb_cb->vif == vif)
5432 ath11k_mac_tx_mgmt_free(ar, buf_id);
5437 static int ath11k_mac_mgmt_tx_wmi(struct ath11k *ar, struct ath11k_vif *arvif,
5438 struct sk_buff *skb)
5440 struct ath11k_base *ab = ar->ab;
5441 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
5442 struct ieee80211_tx_info *info;
5447 ATH11K_SKB_CB(skb)->ar = ar;
5449 spin_lock_bh(&ar->txmgmt_idr_lock);
5450 buf_id = idr_alloc(&ar->txmgmt_idr, skb, 0,
5451 ATH11K_TX_MGMT_NUM_PENDING_MAX, GFP_ATOMIC);
5452 spin_unlock_bh(&ar->txmgmt_idr_lock);
5454 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
5455 "mac tx mgmt frame, buf id %d\n", buf_id);
5460 info = IEEE80211_SKB_CB(skb);
5461 if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) {
5462 if ((ieee80211_is_action(hdr->frame_control) ||
5463 ieee80211_is_deauth(hdr->frame_control) ||
5464 ieee80211_is_disassoc(hdr->frame_control)) &&
5465 ieee80211_has_protected(hdr->frame_control)) {
5466 skb_put(skb, IEEE80211_CCMP_MIC_LEN);
5470 paddr = dma_map_single(ab->dev, skb->data, skb->len, DMA_TO_DEVICE);
5471 if (dma_mapping_error(ab->dev, paddr)) {
5472 ath11k_warn(ab, "failed to DMA map mgmt Tx buffer\n");
5477 ATH11K_SKB_CB(skb)->paddr = paddr;
5479 ret = ath11k_wmi_mgmt_send(ar, arvif->vdev_id, buf_id, skb);
5481 ath11k_warn(ar->ab, "failed to send mgmt frame: %d\n", ret);
5488 dma_unmap_single(ab->dev, ATH11K_SKB_CB(skb)->paddr,
5489 skb->len, DMA_TO_DEVICE);
5491 spin_lock_bh(&ar->txmgmt_idr_lock);
5492 idr_remove(&ar->txmgmt_idr, buf_id);
5493 spin_unlock_bh(&ar->txmgmt_idr_lock);
5498 static void ath11k_mgmt_over_wmi_tx_purge(struct ath11k *ar)
5500 struct sk_buff *skb;
5502 while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL)
5503 ath11k_mgmt_over_wmi_tx_drop(ar, skb);
5506 static void ath11k_mgmt_over_wmi_tx_work(struct work_struct *work)
5508 struct ath11k *ar = container_of(work, struct ath11k, wmi_mgmt_tx_work);
5509 struct ath11k_skb_cb *skb_cb;
5510 struct ath11k_vif *arvif;
5511 struct sk_buff *skb;
5514 while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) {
5515 skb_cb = ATH11K_SKB_CB(skb);
5517 ath11k_warn(ar->ab, "no vif found for mgmt frame\n");
5518 ath11k_mgmt_over_wmi_tx_drop(ar, skb);
5522 arvif = ath11k_vif_to_arvif(skb_cb->vif);
5523 if (ar->allocated_vdev_map & (1LL << arvif->vdev_id) &&
5524 arvif->is_started) {
5525 ret = ath11k_mac_mgmt_tx_wmi(ar, arvif, skb);
5527 ath11k_warn(ar->ab, "failed to tx mgmt frame, vdev_id %d :%d\n",
5528 arvif->vdev_id, ret);
5529 ath11k_mgmt_over_wmi_tx_drop(ar, skb);
5531 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
5532 "mac tx mgmt frame, vdev_id %d\n",
5537 "dropping mgmt frame for vdev %d, is_started %d\n",
5540 ath11k_mgmt_over_wmi_tx_drop(ar, skb);
5545 static int ath11k_mac_mgmt_tx(struct ath11k *ar, struct sk_buff *skb,
5548 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
5550 if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))
5553 /* Drop probe response packets when the pending management tx
5554 * count has reached a certain threshold, so as to prioritize
5555 * other mgmt packets like auth and assoc to be sent on time
5556 * for establishing successful connections.
5559 atomic_read(&ar->num_pending_mgmt_tx) > ATH11K_PRB_RSP_DROP_THRESHOLD) {
5561 "dropping probe response as pending queue is almost full\n");
5565 if (skb_queue_len_lockless(q) >= ATH11K_TX_MGMT_NUM_PENDING_MAX) {
5566 ath11k_warn(ar->ab, "mgmt tx queue is full\n");
5570 skb_queue_tail(q, skb);
5571 atomic_inc(&ar->num_pending_mgmt_tx);
5572 queue_work(ar->ab->workqueue, &ar->wmi_mgmt_tx_work);
5577 int ath11k_mac_rfkill_config(struct ath11k *ar)
5579 struct ath11k_base *ab = ar->ab;
5583 if (ab->hw_params.rfkill_pin == 0)
5586 ath11k_dbg(ab, ATH11K_DBG_MAC,
5587 "mac rfkill_pin %d rfkill_cfg %d rfkill_on_level %d",
5588 ab->hw_params.rfkill_pin, ab->hw_params.rfkill_cfg,
5589 ab->hw_params.rfkill_on_level);
5591 param = FIELD_PREP(WMI_RFKILL_CFG_RADIO_LEVEL,
5592 ab->hw_params.rfkill_on_level) |
5593 FIELD_PREP(WMI_RFKILL_CFG_GPIO_PIN_NUM,
5594 ab->hw_params.rfkill_pin) |
5595 FIELD_PREP(WMI_RFKILL_CFG_PIN_AS_GPIO,
5596 ab->hw_params.rfkill_cfg);
5598 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_HW_RFKILL_CONFIG,
5599 param, ar->pdev->pdev_id);
5602 "failed to set rfkill config 0x%x: %d\n",
5610 int ath11k_mac_rfkill_enable_radio(struct ath11k *ar, bool enable)
5612 enum wmi_rfkill_enable_radio param;
5616 param = WMI_RFKILL_ENABLE_RADIO_ON;
5618 param = WMI_RFKILL_ENABLE_RADIO_OFF;
5620 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac %d rfkill enable %d",
5621 ar->pdev_idx, param);
5623 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RFKILL_ENABLE,
5624 param, ar->pdev->pdev_id);
5626 ath11k_warn(ar->ab, "failed to set rfkill enable param %d: %d\n",
5634 static void ath11k_mac_op_tx(struct ieee80211_hw *hw,
5635 struct ieee80211_tx_control *control,
5636 struct sk_buff *skb)
5638 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb);
5639 struct ath11k *ar = hw->priv;
5640 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
5641 struct ieee80211_vif *vif = info->control.vif;
5642 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
5643 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
5644 struct ieee80211_key_conf *key = info->control.hw_key;
5645 struct ath11k_sta *arsta = NULL;
5646 u32 info_flags = info->flags;
5650 memset(skb_cb, 0, sizeof(*skb_cb));
5654 skb_cb->cipher = key->cipher;
5655 skb_cb->flags |= ATH11K_SKB_CIPHER_SET;
5658 if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
5659 skb_cb->flags |= ATH11K_SKB_HW_80211_ENCAP;
5660 } else if (ieee80211_is_mgmt(hdr->frame_control)) {
5661 is_prb_rsp = ieee80211_is_probe_resp(hdr->frame_control);
5662 ret = ath11k_mac_mgmt_tx(ar, skb, is_prb_rsp);
5664 ath11k_warn(ar->ab, "failed to queue management frame %d\n",
5666 ieee80211_free_txskb(ar->hw, skb);
5672 arsta = (struct ath11k_sta *)control->sta->drv_priv;
5674 ret = ath11k_dp_tx(ar, arvif, arsta, skb);
5675 if (unlikely(ret)) {
5676 ath11k_warn(ar->ab, "failed to transmit frame %d\n", ret);
5677 ieee80211_free_txskb(ar->hw, skb);
5681 void ath11k_mac_drain_tx(struct ath11k *ar)
5683 /* make sure rcu-protected mac80211 tx path itself is drained */
5686 cancel_work_sync(&ar->wmi_mgmt_tx_work);
5687 ath11k_mgmt_over_wmi_tx_purge(ar);
5690 static int ath11k_mac_config_mon_status_default(struct ath11k *ar, bool enable)
5692 struct htt_rx_ring_tlv_filter tlv_filter = {0};
5693 struct ath11k_base *ab = ar->ab;
5698 tlv_filter = ath11k_mac_mon_status_filter_default;
5699 if (ath11k_debugfs_rx_filter(ar))
5700 tlv_filter.rx_filter = ath11k_debugfs_rx_filter(ar);
5703 for (i = 0; i < ab->hw_params.num_rxmda_per_pdev; i++) {
5704 ring_id = ar->dp.rx_mon_status_refill_ring[i].refill_buf_ring.ring_id;
5705 ret = ath11k_dp_tx_htt_rx_filter_setup(ar->ab, ring_id,
5707 HAL_RXDMA_MONITOR_STATUS,
5712 if (enable && !ar->ab->hw_params.rxdma1_enable)
5713 mod_timer(&ar->ab->mon_reap_timer, jiffies +
5714 msecs_to_jiffies(ATH11K_MON_TIMER_INTERVAL));
5719 static int ath11k_mac_op_start(struct ieee80211_hw *hw)
5721 struct ath11k *ar = hw->priv;
5722 struct ath11k_base *ab = ar->ab;
5723 struct ath11k_pdev *pdev = ar->pdev;
5726 ath11k_mac_drain_tx(ar);
5727 mutex_lock(&ar->conf_mutex);
5729 switch (ar->state) {
5730 case ATH11K_STATE_OFF:
5731 ar->state = ATH11K_STATE_ON;
5733 case ATH11K_STATE_RESTARTING:
5734 ar->state = ATH11K_STATE_RESTARTED;
5736 case ATH11K_STATE_RESTARTED:
5737 case ATH11K_STATE_WEDGED:
5738 case ATH11K_STATE_ON:
5744 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS,
5748 ath11k_err(ar->ab, "failed to enable PMF QOS: (%d\n", ret);
5752 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 1,
5755 ath11k_err(ar->ab, "failed to enable dynamic bw: %d\n", ret);
5759 if (test_bit(WMI_TLV_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi->wmi_ab->svc_map)) {
5760 ret = ath11k_wmi_scan_prob_req_oui(ar, ar->mac_addr);
5762 ath11k_err(ab, "failed to set prob req oui: %i\n", ret);
5767 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
5770 ath11k_err(ab, "failed to set ac override for ARP: %d\n",
5775 ret = ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(ar, pdev->pdev_id);
5777 ath11k_err(ab, "failed to offload radar detection: %d\n",
5782 ret = ath11k_dp_tx_htt_h2t_ppdu_stats_req(ar,
5783 HTT_PPDU_STATS_TAG_DEFAULT);
5785 ath11k_err(ab, "failed to req ppdu stats: %d\n", ret);
5789 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_MESH_MCAST_ENABLE,
5793 ath11k_err(ar->ab, "failed to enable MESH MCAST ENABLE: (%d\n", ret);
5797 __ath11k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
5799 /* TODO: Do we need to enable ANI? */
5801 ath11k_reg_update_chan_list(ar, false);
5803 ar->num_started_vdevs = 0;
5804 ar->num_created_vdevs = 0;
5806 ar->allocated_vdev_map = 0;
5808 /* Configure monitor status ring with default rx_filter to get rx status
5809 * such as rssi, rx_duration.
5811 ret = ath11k_mac_config_mon_status_default(ar, true);
5813 ath11k_err(ab, "failed to configure monitor status ring with default rx_filter: (%d)\n",
5818 /* Configure the hash seed for hash based reo dest ring selection */
5819 ath11k_wmi_pdev_lro_cfg(ar, ar->pdev->pdev_id);
5821 /* allow device to enter IMPS */
5822 if (ab->hw_params.idle_ps) {
5823 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_IDLE_PS_CONFIG,
5826 ath11k_err(ab, "failed to enable idle ps: %d\n", ret);
5831 mutex_unlock(&ar->conf_mutex);
5833 rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx],
5834 &ab->pdevs[ar->pdev_idx]);
5839 ar->state = ATH11K_STATE_OFF;
5840 mutex_unlock(&ar->conf_mutex);
5845 static void ath11k_mac_op_stop(struct ieee80211_hw *hw)
5847 struct ath11k *ar = hw->priv;
5848 struct htt_ppdu_stats_info *ppdu_stats, *tmp;
5851 ath11k_mac_drain_tx(ar);
5853 mutex_lock(&ar->conf_mutex);
5854 ret = ath11k_mac_config_mon_status_default(ar, false);
5856 ath11k_err(ar->ab, "failed to clear rx_filter for monitor status ring: (%d)\n",
5859 clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
5860 ar->state = ATH11K_STATE_OFF;
5861 mutex_unlock(&ar->conf_mutex);
5863 cancel_delayed_work_sync(&ar->scan.timeout);
5864 cancel_work_sync(&ar->regd_update_work);
5865 cancel_work_sync(&ar->ab->update_11d_work);
5866 cancel_work_sync(&ar->ab->rfkill_work);
5868 if (ar->state_11d == ATH11K_11D_PREPARING) {
5869 ar->state_11d = ATH11K_11D_IDLE;
5870 complete(&ar->completed_11d_scan);
5873 spin_lock_bh(&ar->data_lock);
5874 list_for_each_entry_safe(ppdu_stats, tmp, &ar->ppdu_stats_info, list) {
5875 list_del(&ppdu_stats->list);
5878 spin_unlock_bh(&ar->data_lock);
5880 rcu_assign_pointer(ar->ab->pdevs_active[ar->pdev_idx], NULL);
5884 atomic_set(&ar->num_pending_mgmt_tx, 0);
5888 ath11k_mac_setup_vdev_create_params(struct ath11k_vif *arvif,
5889 struct vdev_create_params *params)
5891 struct ath11k *ar = arvif->ar;
5892 struct ath11k_pdev *pdev = ar->pdev;
5894 params->if_id = arvif->vdev_id;
5895 params->type = arvif->vdev_type;
5896 params->subtype = arvif->vdev_subtype;
5897 params->pdev_id = pdev->pdev_id;
5899 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) {
5900 params->chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains;
5901 params->chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains;
5903 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) {
5904 params->chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains;
5905 params->chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains;
5907 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP &&
5908 ar->supports_6ghz) {
5909 params->chains[NL80211_BAND_6GHZ].tx = ar->num_tx_chains;
5910 params->chains[NL80211_BAND_6GHZ].rx = ar->num_rx_chains;
5915 ath11k_mac_prepare_he_mode(struct ath11k_pdev *pdev, u32 viftype)
5917 struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
5918 struct ath11k_band_cap *cap_band = NULL;
5919 u32 *hecap_phy_ptr = NULL;
5922 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP)
5923 cap_band = &pdev_cap->band[NL80211_BAND_2GHZ];
5925 cap_band = &pdev_cap->band[NL80211_BAND_5GHZ];
5927 hecap_phy_ptr = &cap_band->he_cap_phy_info[0];
5929 hemode = FIELD_PREP(HE_MODE_SU_TX_BFEE, HE_SU_BFEE_ENABLE) |
5930 FIELD_PREP(HE_MODE_SU_TX_BFER, HECAP_PHY_SUBFMR_GET(hecap_phy_ptr)) |
5931 FIELD_PREP(HE_MODE_UL_MUMIMO, HECAP_PHY_ULMUMIMO_GET(hecap_phy_ptr));
5933 /* TODO WDS and other modes */
5934 if (viftype == NL80211_IFTYPE_AP) {
5935 hemode |= FIELD_PREP(HE_MODE_MU_TX_BFER,
5936 HECAP_PHY_MUBFMR_GET(hecap_phy_ptr)) |
5937 FIELD_PREP(HE_MODE_DL_OFDMA, HE_DL_MUOFDMA_ENABLE) |
5938 FIELD_PREP(HE_MODE_UL_OFDMA, HE_UL_MUOFDMA_ENABLE);
5940 hemode |= FIELD_PREP(HE_MODE_MU_TX_BFEE, HE_MU_BFEE_ENABLE);
5946 static int ath11k_set_he_mu_sounding_mode(struct ath11k *ar,
5947 struct ath11k_vif *arvif)
5949 u32 param_id, param_value;
5950 struct ath11k_base *ab = ar->ab;
5953 param_id = WMI_VDEV_PARAM_SET_HEMU_MODE;
5954 param_value = ath11k_mac_prepare_he_mode(ar->pdev, arvif->vif->type);
5955 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5956 param_id, param_value);
5958 ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d param_value %x\n",
5959 arvif->vdev_id, ret, param_value);
5962 param_id = WMI_VDEV_PARAM_SET_HE_SOUNDING_MODE;
5964 FIELD_PREP(HE_VHT_SOUNDING_MODE, HE_VHT_SOUNDING_MODE_ENABLE) |
5965 FIELD_PREP(HE_TRIG_NONTRIG_SOUNDING_MODE,
5966 HE_TRIG_NONTRIG_SOUNDING_MODE_ENABLE);
5967 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5968 param_id, param_value);
5970 ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d\n",
5971 arvif->vdev_id, ret);
5977 static void ath11k_mac_op_update_vif_offload(struct ieee80211_hw *hw,
5978 struct ieee80211_vif *vif)
5980 struct ath11k *ar = hw->priv;
5981 struct ath11k_base *ab = ar->ab;
5982 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
5983 u32 param_id, param_value;
5986 param_id = WMI_VDEV_PARAM_TX_ENCAP_TYPE;
5987 if (ath11k_frame_mode != ATH11K_HW_TXRX_ETHERNET ||
5988 (vif->type != NL80211_IFTYPE_STATION &&
5989 vif->type != NL80211_IFTYPE_AP))
5990 vif->offload_flags &= ~(IEEE80211_OFFLOAD_ENCAP_ENABLED |
5991 IEEE80211_OFFLOAD_DECAP_ENABLED);
5993 if (vif->offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED)
5994 param_value = ATH11K_HW_TXRX_ETHERNET;
5995 else if (test_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags))
5996 param_value = ATH11K_HW_TXRX_RAW;
5998 param_value = ATH11K_HW_TXRX_NATIVE_WIFI;
6000 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
6001 param_id, param_value);
6003 ath11k_warn(ab, "failed to set vdev %d tx encap mode: %d\n",
6004 arvif->vdev_id, ret);
6005 vif->offload_flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
6008 param_id = WMI_VDEV_PARAM_RX_DECAP_TYPE;
6009 if (vif->offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED)
6010 param_value = ATH11K_HW_TXRX_ETHERNET;
6011 else if (test_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags))
6012 param_value = ATH11K_HW_TXRX_RAW;
6014 param_value = ATH11K_HW_TXRX_NATIVE_WIFI;
6016 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
6017 param_id, param_value);
6019 ath11k_warn(ab, "failed to set vdev %d rx decap mode: %d\n",
6020 arvif->vdev_id, ret);
6021 vif->offload_flags &= ~IEEE80211_OFFLOAD_DECAP_ENABLED;
6025 static bool ath11k_mac_vif_ap_active_any(struct ath11k_base *ab)
6028 struct ath11k_pdev *pdev;
6029 struct ath11k_vif *arvif;
6032 for (i = 0; i < ab->num_radios; i++) {
6033 pdev = &ab->pdevs[i];
6035 list_for_each_entry(arvif, &ar->arvifs, list) {
6036 if (arvif->is_up && arvif->vdev_type == WMI_VDEV_TYPE_AP)
6043 void ath11k_mac_11d_scan_start(struct ath11k *ar, u32 vdev_id)
6045 struct wmi_11d_scan_start_params param;
6048 mutex_lock(&ar->ab->vdev_id_11d_lock);
6050 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev id for 11d scan %d\n",
6051 ar->vdev_id_11d_scan);
6053 if (ar->regdom_set_by_user)
6056 if (ar->vdev_id_11d_scan != ATH11K_11D_INVALID_VDEV_ID)
6059 if (!test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map))
6062 if (ath11k_mac_vif_ap_active_any(ar->ab))
6065 param.vdev_id = vdev_id;
6066 param.start_interval_msec = 0;
6067 param.scan_period_msec = ATH11K_SCAN_11D_INTERVAL;
6069 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac start 11d scan\n");
6071 ret = ath11k_wmi_send_11d_scan_start_cmd(ar, ¶m);
6073 ath11k_warn(ar->ab, "failed to start 11d scan vdev %d ret: %d\n",
6076 ar->vdev_id_11d_scan = vdev_id;
6077 if (ar->state_11d == ATH11K_11D_PREPARING)
6078 ar->state_11d = ATH11K_11D_RUNNING;
6082 if (ar->state_11d == ATH11K_11D_PREPARING) {
6083 ar->state_11d = ATH11K_11D_IDLE;
6084 complete(&ar->completed_11d_scan);
6087 mutex_unlock(&ar->ab->vdev_id_11d_lock);
6090 void ath11k_mac_11d_scan_stop(struct ath11k *ar)
6095 if (!test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ar->ab->wmi_ab.svc_map))
6098 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac stop 11d scan\n");
6100 mutex_lock(&ar->ab->vdev_id_11d_lock);
6102 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac stop 11d vdev id %d\n",
6103 ar->vdev_id_11d_scan);
6105 if (ar->vdev_id_11d_scan != ATH11K_11D_INVALID_VDEV_ID) {
6106 vdev_id = ar->vdev_id_11d_scan;
6108 ret = ath11k_wmi_send_11d_scan_stop_cmd(ar, vdev_id);
6111 "failed to stopt 11d scan vdev %d ret: %d\n",
6114 ar->vdev_id_11d_scan = ATH11K_11D_INVALID_VDEV_ID;
6115 ar->state_11d = ATH11K_11D_IDLE;
6116 complete(&ar->completed_11d_scan);
6119 mutex_unlock(&ar->ab->vdev_id_11d_lock);
6122 void ath11k_mac_11d_scan_stop_all(struct ath11k_base *ab)
6125 struct ath11k_pdev *pdev;
6128 ath11k_dbg(ab, ATH11K_DBG_MAC, "mac stop soc 11d scan\n");
6130 for (i = 0; i < ab->num_radios; i++) {
6131 pdev = &ab->pdevs[i];
6134 ath11k_mac_11d_scan_stop(ar);
6138 static int ath11k_mac_op_add_interface(struct ieee80211_hw *hw,
6139 struct ieee80211_vif *vif)
6141 struct ath11k *ar = hw->priv;
6142 struct ath11k_base *ab = ar->ab;
6143 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
6144 struct vdev_create_params vdev_param = {0};
6145 struct peer_create_params peer_param;
6146 u32 param_id, param_value;
6152 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
6154 mutex_lock(&ar->conf_mutex);
6156 if (vif->type == NL80211_IFTYPE_AP &&
6157 ar->num_peers > (ar->max_num_peers - 1)) {
6158 ath11k_warn(ab, "failed to create vdev due to insufficient peer entry resource in firmware\n");
6163 if (ar->num_created_vdevs > (TARGET_NUM_VDEVS(ab) - 1)) {
6164 ath11k_warn(ab, "failed to create vdev %u, reached max vdev limit %d\n",
6165 ar->num_created_vdevs, TARGET_NUM_VDEVS(ab));
6170 memset(arvif, 0, sizeof(*arvif));
6175 INIT_LIST_HEAD(&arvif->list);
6176 INIT_DELAYED_WORK(&arvif->connection_loss_work,
6177 ath11k_mac_vif_sta_connection_loss_work);
6179 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
6180 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
6181 arvif->bitrate_mask.control[i].gi = NL80211_TXRATE_FORCE_SGI;
6182 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
6183 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
6184 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
6185 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
6186 memset(arvif->bitrate_mask.control[i].he_mcs, 0xff,
6187 sizeof(arvif->bitrate_mask.control[i].he_mcs));
6190 bit = __ffs64(ab->free_vdev_map);
6192 arvif->vdev_id = bit;
6193 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
6195 switch (vif->type) {
6196 case NL80211_IFTYPE_UNSPECIFIED:
6197 case NL80211_IFTYPE_STATION:
6198 arvif->vdev_type = WMI_VDEV_TYPE_STA;
6200 case NL80211_IFTYPE_MESH_POINT:
6201 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_MESH_11S;
6203 case NL80211_IFTYPE_AP:
6204 arvif->vdev_type = WMI_VDEV_TYPE_AP;
6206 case NL80211_IFTYPE_MONITOR:
6207 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
6208 ar->monitor_vdev_id = bit;
6215 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac add interface id %d type %d subtype %d map %llx\n",
6216 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
6219 vif->cab_queue = arvif->vdev_id % (ATH11K_HW_MAX_QUEUES - 1);
6220 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
6221 vif->hw_queue[i] = i % (ATH11K_HW_MAX_QUEUES - 1);
6223 ath11k_mac_setup_vdev_create_params(arvif, &vdev_param);
6225 ret = ath11k_wmi_vdev_create(ar, vif->addr, &vdev_param);
6227 ath11k_warn(ab, "failed to create WMI vdev %d: %d\n",
6228 arvif->vdev_id, ret);
6232 ar->num_created_vdevs++;
6233 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM created, vdev_id %d\n",
6234 vif->addr, arvif->vdev_id);
6235 ar->allocated_vdev_map |= 1LL << arvif->vdev_id;
6236 ab->free_vdev_map &= ~(1LL << arvif->vdev_id);
6238 spin_lock_bh(&ar->data_lock);
6239 list_add(&arvif->list, &ar->arvifs);
6240 spin_unlock_bh(&ar->data_lock);
6242 ath11k_mac_op_update_vif_offload(hw, vif);
6244 nss = get_num_chains(ar->cfg_tx_chainmask) ? : 1;
6245 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
6246 WMI_VDEV_PARAM_NSS, nss);
6248 ath11k_warn(ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n",
6249 arvif->vdev_id, ar->cfg_tx_chainmask, nss, ret);
6253 switch (arvif->vdev_type) {
6254 case WMI_VDEV_TYPE_AP:
6255 peer_param.vdev_id = arvif->vdev_id;
6256 peer_param.peer_addr = vif->addr;
6257 peer_param.peer_type = WMI_PEER_TYPE_DEFAULT;
6258 ret = ath11k_peer_create(ar, arvif, NULL, &peer_param);
6260 ath11k_warn(ab, "failed to vdev %d create peer for AP: %d\n",
6261 arvif->vdev_id, ret);
6265 ret = ath11k_mac_set_kickout(arvif);
6267 ath11k_warn(ar->ab, "failed to set vdev %i kickout parameters: %d\n",
6268 arvif->vdev_id, ret);
6272 ath11k_mac_11d_scan_stop_all(ar->ab);
6274 case WMI_VDEV_TYPE_STA:
6275 param_id = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
6276 param_value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
6277 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6278 param_id, param_value);
6280 ath11k_warn(ar->ab, "failed to set vdev %d RX wake policy: %d\n",
6281 arvif->vdev_id, ret);
6285 param_id = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
6286 param_value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
6287 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6288 param_id, param_value);
6290 ath11k_warn(ar->ab, "failed to set vdev %d TX wake threshold: %d\n",
6291 arvif->vdev_id, ret);
6295 param_id = WMI_STA_PS_PARAM_PSPOLL_COUNT;
6296 param_value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
6297 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
6298 param_id, param_value);
6300 ath11k_warn(ar->ab, "failed to set vdev %d pspoll count: %d\n",
6301 arvif->vdev_id, ret);
6305 ret = ath11k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id,
6306 WMI_STA_PS_MODE_DISABLED);
6308 ath11k_warn(ar->ab, "failed to disable vdev %d ps mode: %d\n",
6309 arvif->vdev_id, ret);
6313 if (test_bit(WMI_TLV_SERVICE_11D_OFFLOAD, ab->wmi_ab.svc_map)) {
6314 reinit_completion(&ar->completed_11d_scan);
6315 ar->state_11d = ATH11K_11D_PREPARING;
6318 case WMI_VDEV_TYPE_MONITOR:
6319 set_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags);
6325 arvif->txpower = vif->bss_conf.txpower;
6326 ret = ath11k_mac_txpower_recalc(ar);
6330 param_id = WMI_VDEV_PARAM_RTS_THRESHOLD;
6331 param_value = ar->hw->wiphy->rts_threshold;
6332 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
6333 param_id, param_value);
6335 ath11k_warn(ar->ab, "failed to set rts threshold for vdev %d: %d\n",
6336 arvif->vdev_id, ret);
6339 ath11k_dp_vdev_tx_attach(ar, arvif);
6341 if (vif->type != NL80211_IFTYPE_MONITOR &&
6342 test_bit(ATH11K_FLAG_MONITOR_CONF_ENABLED, &ar->monitor_flags)) {
6343 ret = ath11k_mac_monitor_vdev_create(ar);
6345 ath11k_warn(ar->ab, "failed to create monitor vdev during add interface: %d",
6351 ret = ath11k_debugfs_add_interface(arvif);
6355 mutex_unlock(&ar->conf_mutex);
6360 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
6361 reinit_completion(&ar->peer_delete_done);
6363 fbret = ath11k_wmi_send_peer_delete_cmd(ar, vif->addr,
6366 ath11k_warn(ar->ab, "failed to delete peer vdev_id %d addr %pM\n",
6367 arvif->vdev_id, vif->addr);
6371 fbret = ath11k_wait_for_peer_delete_done(ar, arvif->vdev_id,
6380 ath11k_wmi_vdev_delete(ar, arvif->vdev_id);
6381 ar->num_created_vdevs--;
6382 ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id);
6383 ab->free_vdev_map |= 1LL << arvif->vdev_id;
6384 spin_lock_bh(&ar->data_lock);
6385 list_del(&arvif->list);
6386 spin_unlock_bh(&ar->data_lock);
6389 ath11k_debugfs_remove_interface(arvif);
6390 mutex_unlock(&ar->conf_mutex);
6395 static int ath11k_mac_vif_unref(int buf_id, void *skb, void *ctx)
6397 struct ieee80211_vif *vif = (struct ieee80211_vif *)ctx;
6398 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb);
6400 if (skb_cb->vif == vif)
6406 static void ath11k_mac_op_remove_interface(struct ieee80211_hw *hw,
6407 struct ieee80211_vif *vif)
6409 struct ath11k *ar = hw->priv;
6410 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
6411 struct ath11k_base *ab = ar->ab;
6412 unsigned long time_left;
6416 cancel_delayed_work_sync(&arvif->connection_loss_work);
6418 mutex_lock(&ar->conf_mutex);
6420 ath11k_dbg(ab, ATH11K_DBG_MAC, "mac remove interface (vdev %d)\n",
6423 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
6424 ath11k_mac_11d_scan_stop(ar);
6426 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
6427 ret = ath11k_peer_delete(ar, arvif->vdev_id, vif->addr);
6429 ath11k_warn(ab, "failed to submit AP self-peer removal on vdev %d: %d\n",
6430 arvif->vdev_id, ret);
6433 reinit_completion(&ar->vdev_delete_done);
6435 ret = ath11k_wmi_vdev_delete(ar, arvif->vdev_id);
6437 ath11k_warn(ab, "failed to delete WMI vdev %d: %d\n",
6438 arvif->vdev_id, ret);
6442 time_left = wait_for_completion_timeout(&ar->vdev_delete_done,
6443 ATH11K_VDEV_DELETE_TIMEOUT_HZ);
6444 if (time_left == 0) {
6445 ath11k_warn(ab, "Timeout in receiving vdev delete response\n");
6449 ab->free_vdev_map |= 1LL << (arvif->vdev_id);
6450 ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id);
6451 ar->num_created_vdevs--;
6453 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM deleted, vdev_id %d\n",
6454 vif->addr, arvif->vdev_id);
6456 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
6457 clear_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags);
6458 ar->monitor_vdev_id = -1;
6459 } else if (test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags) &&
6460 !test_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags)) {
6461 ret = ath11k_mac_monitor_vdev_delete(ar);
6463 /* continue even if there's an error */
6464 ath11k_warn(ar->ab, "failed to delete vdev monitor during remove interface: %d",
6469 spin_lock_bh(&ar->data_lock);
6470 list_del(&arvif->list);
6471 spin_unlock_bh(&ar->data_lock);
6473 ath11k_peer_cleanup(ar, arvif->vdev_id);
6475 idr_for_each(&ar->txmgmt_idr,
6476 ath11k_mac_vif_txmgmt_idr_remove, vif);
6478 for (i = 0; i < ab->hw_params.max_tx_ring; i++) {
6479 spin_lock_bh(&ab->dp.tx_ring[i].tx_idr_lock);
6480 idr_for_each(&ab->dp.tx_ring[i].txbuf_idr,
6481 ath11k_mac_vif_unref, vif);
6482 spin_unlock_bh(&ab->dp.tx_ring[i].tx_idr_lock);
6485 /* Recalc txpower for remaining vdev */
6486 ath11k_mac_txpower_recalc(ar);
6488 ath11k_debugfs_remove_interface(arvif);
6490 /* TODO: recal traffic pause state based on the available vdevs */
6492 mutex_unlock(&ar->conf_mutex);
6495 /* FIXME: Has to be verified. */
6496 #define SUPPORTED_FILTERS \
6501 FIF_BCN_PRBRESP_PROMISC | \
6505 static void ath11k_mac_op_configure_filter(struct ieee80211_hw *hw,
6506 unsigned int changed_flags,
6507 unsigned int *total_flags,
6510 struct ath11k *ar = hw->priv;
6512 mutex_lock(&ar->conf_mutex);
6514 *total_flags &= SUPPORTED_FILTERS;
6515 ar->filter_flags = *total_flags;
6517 mutex_unlock(&ar->conf_mutex);
6520 static int ath11k_mac_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
6522 struct ath11k *ar = hw->priv;
6524 mutex_lock(&ar->conf_mutex);
6526 *tx_ant = ar->cfg_tx_chainmask;
6527 *rx_ant = ar->cfg_rx_chainmask;
6529 mutex_unlock(&ar->conf_mutex);
6534 static int ath11k_mac_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
6536 struct ath11k *ar = hw->priv;
6539 mutex_lock(&ar->conf_mutex);
6540 ret = __ath11k_set_antenna(ar, tx_ant, rx_ant);
6541 mutex_unlock(&ar->conf_mutex);
6546 static int ath11k_mac_op_ampdu_action(struct ieee80211_hw *hw,
6547 struct ieee80211_vif *vif,
6548 struct ieee80211_ampdu_params *params)
6550 struct ath11k *ar = hw->priv;
6553 mutex_lock(&ar->conf_mutex);
6555 switch (params->action) {
6556 case IEEE80211_AMPDU_RX_START:
6557 ret = ath11k_dp_rx_ampdu_start(ar, params);
6559 case IEEE80211_AMPDU_RX_STOP:
6560 ret = ath11k_dp_rx_ampdu_stop(ar, params);
6562 case IEEE80211_AMPDU_TX_START:
6563 case IEEE80211_AMPDU_TX_STOP_CONT:
6564 case IEEE80211_AMPDU_TX_STOP_FLUSH:
6565 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
6566 case IEEE80211_AMPDU_TX_OPERATIONAL:
6567 /* Tx A-MPDU aggregation offloaded to hw/fw so deny mac80211
6568 * Tx aggregation requests.
6574 mutex_unlock(&ar->conf_mutex);
6579 static int ath11k_mac_op_add_chanctx(struct ieee80211_hw *hw,
6580 struct ieee80211_chanctx_conf *ctx)
6582 struct ath11k *ar = hw->priv;
6583 struct ath11k_base *ab = ar->ab;
6585 ath11k_dbg(ab, ATH11K_DBG_MAC,
6586 "mac chanctx add freq %u width %d ptr %pK\n",
6587 ctx->def.chan->center_freq, ctx->def.width, ctx);
6589 mutex_lock(&ar->conf_mutex);
6591 spin_lock_bh(&ar->data_lock);
6592 /* TODO: In case of multiple channel context, populate rx_channel from
6593 * Rx PPDU desc information.
6595 ar->rx_channel = ctx->def.chan;
6596 spin_unlock_bh(&ar->data_lock);
6598 mutex_unlock(&ar->conf_mutex);
6603 static void ath11k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
6604 struct ieee80211_chanctx_conf *ctx)
6606 struct ath11k *ar = hw->priv;
6607 struct ath11k_base *ab = ar->ab;
6609 ath11k_dbg(ab, ATH11K_DBG_MAC,
6610 "mac chanctx remove freq %u width %d ptr %pK\n",
6611 ctx->def.chan->center_freq, ctx->def.width, ctx);
6613 mutex_lock(&ar->conf_mutex);
6615 spin_lock_bh(&ar->data_lock);
6616 /* TODO: In case of there is one more channel context left, populate
6617 * rx_channel with the channel of that remaining channel context.
6619 ar->rx_channel = NULL;
6620 spin_unlock_bh(&ar->data_lock);
6622 mutex_unlock(&ar->conf_mutex);
6626 ath11k_mac_vdev_start_restart(struct ath11k_vif *arvif,
6627 struct ieee80211_chanctx_conf *ctx,
6630 struct ath11k *ar = arvif->ar;
6631 struct ath11k_base *ab = ar->ab;
6632 struct wmi_vdev_start_req_arg arg = {};
6633 const struct cfg80211_chan_def *chandef = &ctx->def;
6634 int he_support = arvif->vif->bss_conf.he_support;
6637 lockdep_assert_held(&ar->conf_mutex);
6639 reinit_completion(&ar->vdev_setup_done);
6641 arg.vdev_id = arvif->vdev_id;
6642 arg.dtim_period = arvif->dtim_period;
6643 arg.bcn_intval = arvif->beacon_interval;
6645 arg.channel.freq = chandef->chan->center_freq;
6646 arg.channel.band_center_freq1 = chandef->center_freq1;
6647 arg.channel.band_center_freq2 = chandef->center_freq2;
6649 ath11k_phymodes[chandef->chan->band][chandef->width];
6651 arg.channel.min_power = 0;
6652 arg.channel.max_power = chandef->chan->max_power;
6653 arg.channel.max_reg_power = chandef->chan->max_reg_power;
6654 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain;
6656 arg.pref_tx_streams = ar->num_tx_chains;
6657 arg.pref_rx_streams = ar->num_rx_chains;
6659 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
6660 arg.ssid = arvif->u.ap.ssid;
6661 arg.ssid_len = arvif->u.ap.ssid_len;
6662 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
6664 /* For now allow DFS for AP mode */
6665 arg.channel.chan_radar =
6666 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
6668 arg.channel.freq2_radar = ctx->radar_enabled;
6670 arg.channel.passive = arg.channel.chan_radar;
6672 spin_lock_bh(&ab->base_lock);
6673 arg.regdomain = ar->ab->dfs_region;
6674 spin_unlock_bh(&ab->base_lock);
6677 ret = ath11k_set_he_mu_sounding_mode(ar, arvif);
6679 ath11k_warn(ar->ab, "failed to set he mode vdev %i\n",
6686 arg.channel.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR);
6688 ath11k_dbg(ab, ATH11K_DBG_MAC,
6689 "mac vdev %d start center_freq %d phymode %s\n",
6690 arg.vdev_id, arg.channel.freq,
6691 ath11k_wmi_phymode_str(arg.channel.mode));
6693 ret = ath11k_wmi_vdev_start(ar, &arg, restart);
6695 ath11k_warn(ar->ab, "failed to %s WMI vdev %i\n",
6696 restart ? "restart" : "start", arg.vdev_id);
6700 ret = ath11k_mac_vdev_setup_sync(ar);
6702 ath11k_warn(ab, "failed to synchronize setup for vdev %i %s: %d\n",
6703 arg.vdev_id, restart ? "restart" : "start", ret);
6708 ar->num_started_vdevs++;
6710 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM started, vdev_id %d\n",
6711 arvif->vif->addr, arvif->vdev_id);
6713 /* Enable CAC Flag in the driver by checking the channel DFS cac time,
6714 * i.e dfs_cac_ms value which will be valid only for radar channels
6715 * and state as NL80211_DFS_USABLE which indicates CAC needs to be
6716 * done before channel usage. This flags is used to drop rx packets.
6719 /* TODO Set the flag for other interface types as required */
6720 if (arvif->vdev_type == WMI_VDEV_TYPE_AP &&
6721 chandef->chan->dfs_cac_ms &&
6722 chandef->chan->dfs_state == NL80211_DFS_USABLE) {
6723 set_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
6724 ath11k_dbg(ab, ATH11K_DBG_MAC,
6725 "CAC Started in chan_freq %d for vdev %d\n",
6726 arg.channel.freq, arg.vdev_id);
6729 ret = ath11k_mac_set_txbf_conf(arvif);
6731 ath11k_warn(ab, "failed to set txbf conf for vdev %d: %d\n",
6732 arvif->vdev_id, ret);
6737 static int ath11k_mac_vdev_stop(struct ath11k_vif *arvif)
6739 struct ath11k *ar = arvif->ar;
6742 lockdep_assert_held(&ar->conf_mutex);
6744 reinit_completion(&ar->vdev_setup_done);
6746 ret = ath11k_wmi_vdev_stop(ar, arvif->vdev_id);
6748 ath11k_warn(ar->ab, "failed to stop WMI vdev %i: %d\n",
6749 arvif->vdev_id, ret);
6753 ret = ath11k_mac_vdev_setup_sync(ar);
6755 ath11k_warn(ar->ab, "failed to synchronize setup for vdev %i: %d\n",
6756 arvif->vdev_id, ret);
6760 WARN_ON(ar->num_started_vdevs == 0);
6762 ar->num_started_vdevs--;
6763 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "vdev %pM stopped, vdev_id %d\n",
6764 arvif->vif->addr, arvif->vdev_id);
6766 if (test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) {
6767 clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
6768 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "CAC Stopped for vdev %d\n",
6777 static int ath11k_mac_vdev_start(struct ath11k_vif *arvif,
6778 struct ieee80211_chanctx_conf *ctx)
6780 return ath11k_mac_vdev_start_restart(arvif, ctx, false);
6783 static int ath11k_mac_vdev_restart(struct ath11k_vif *arvif,
6784 struct ieee80211_chanctx_conf *ctx)
6786 return ath11k_mac_vdev_start_restart(arvif, ctx, true);
6789 struct ath11k_mac_change_chanctx_arg {
6790 struct ieee80211_chanctx_conf *ctx;
6791 struct ieee80211_vif_chanctx_switch *vifs;
6797 ath11k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
6798 struct ieee80211_vif *vif)
6800 struct ath11k_mac_change_chanctx_arg *arg = data;
6802 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
6809 ath11k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
6810 struct ieee80211_vif *vif)
6812 struct ath11k_mac_change_chanctx_arg *arg = data;
6813 struct ieee80211_chanctx_conf *ctx;
6815 ctx = rcu_access_pointer(vif->chanctx_conf);
6816 if (ctx != arg->ctx)
6819 if (WARN_ON(arg->next_vif == arg->n_vifs))
6822 arg->vifs[arg->next_vif].vif = vif;
6823 arg->vifs[arg->next_vif].old_ctx = ctx;
6824 arg->vifs[arg->next_vif].new_ctx = ctx;
6829 ath11k_mac_update_vif_chan(struct ath11k *ar,
6830 struct ieee80211_vif_chanctx_switch *vifs,
6833 struct ath11k_base *ab = ar->ab;
6834 struct ath11k_vif *arvif;
6837 bool monitor_vif = false;
6839 lockdep_assert_held(&ar->conf_mutex);
6841 /* Associated channel resources of all relevant vdevs
6842 * should be available for the channel switch now.
6845 /* TODO: Update ar->rx_channel */
6847 for (i = 0; i < n_vifs; i++) {
6848 arvif = (void *)vifs[i].vif->drv_priv;
6850 if (WARN_ON(!arvif->is_started))
6853 /* change_chanctx can be called even before vdev_up from
6854 * ieee80211_start_ap->ieee80211_vif_use_channel->
6855 * ieee80211_recalc_radar_chanctx.
6857 * Firmware expect vdev_restart only if vdev is up.
6858 * If vdev is down then it expect vdev_stop->vdev_start.
6861 ret = ath11k_mac_vdev_restart(arvif, vifs[i].new_ctx);
6863 ath11k_warn(ab, "failed to restart vdev %d: %d\n",
6864 arvif->vdev_id, ret);
6868 ret = ath11k_mac_vdev_stop(arvif);
6870 ath11k_warn(ab, "failed to stop vdev %d: %d\n",
6871 arvif->vdev_id, ret);
6875 ret = ath11k_mac_vdev_start(arvif, vifs[i].new_ctx);
6877 ath11k_warn(ab, "failed to start vdev %d: %d\n",
6878 arvif->vdev_id, ret);
6883 ret = ath11k_mac_setup_bcn_tmpl(arvif);
6885 ath11k_warn(ab, "failed to update bcn tmpl during csa: %d\n",
6888 ret = ath11k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
6891 ath11k_warn(ab, "failed to bring vdev up %d: %d\n",
6892 arvif->vdev_id, ret);
6897 /* Restart the internal monitor vdev on new channel */
6899 test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags)) {
6900 ret = ath11k_mac_monitor_stop(ar);
6902 ath11k_warn(ar->ab, "failed to stop monitor during vif channel update: %d",
6907 ret = ath11k_mac_monitor_start(ar);
6909 ath11k_warn(ar->ab, "failed to start monitor during vif channel update: %d",
6917 ath11k_mac_update_active_vif_chan(struct ath11k *ar,
6918 struct ieee80211_chanctx_conf *ctx)
6920 struct ath11k_mac_change_chanctx_arg arg = { .ctx = ctx };
6922 lockdep_assert_held(&ar->conf_mutex);
6924 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6925 IEEE80211_IFACE_ITER_NORMAL,
6926 ath11k_mac_change_chanctx_cnt_iter,
6928 if (arg.n_vifs == 0)
6931 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]), GFP_KERNEL);
6935 ieee80211_iterate_active_interfaces_atomic(ar->hw,
6936 IEEE80211_IFACE_ITER_NORMAL,
6937 ath11k_mac_change_chanctx_fill_iter,
6940 ath11k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
6945 static void ath11k_mac_op_change_chanctx(struct ieee80211_hw *hw,
6946 struct ieee80211_chanctx_conf *ctx,
6949 struct ath11k *ar = hw->priv;
6950 struct ath11k_base *ab = ar->ab;
6952 mutex_lock(&ar->conf_mutex);
6954 ath11k_dbg(ab, ATH11K_DBG_MAC,
6955 "mac chanctx change freq %u width %d ptr %pK changed %x\n",
6956 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
6958 /* This shouldn't really happen because channel switching should use
6959 * switch_vif_chanctx().
6961 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
6964 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH ||
6965 changed & IEEE80211_CHANCTX_CHANGE_RADAR)
6966 ath11k_mac_update_active_vif_chan(ar, ctx);
6968 /* TODO: Recalc radar detection */
6971 mutex_unlock(&ar->conf_mutex);
6974 static int ath11k_start_vdev_delay(struct ieee80211_hw *hw,
6975 struct ieee80211_vif *vif)
6977 struct ath11k *ar = hw->priv;
6978 struct ath11k_base *ab = ar->ab;
6979 struct ath11k_vif *arvif = (void *)vif->drv_priv;
6982 if (WARN_ON(arvif->is_started))
6985 ret = ath11k_mac_vdev_start(arvif, &arvif->chanctx);
6987 ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
6988 arvif->vdev_id, vif->addr,
6989 arvif->chanctx.def.chan->center_freq, ret);
6993 /* Reconfigure hardware rate code since it is cleared by firmware.
6995 if (ar->hw_rate_code > 0) {
6996 u32 vdev_param = WMI_VDEV_PARAM_MGMT_RATE;
6998 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
7001 ath11k_warn(ar->ab, "failed to set mgmt tx rate %d\n", ret);
7006 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
7007 ret = ath11k_wmi_vdev_up(ar, arvif->vdev_id, 0, ar->mac_addr);
7009 ath11k_warn(ab, "failed put monitor up: %d\n", ret);
7014 arvif->is_started = true;
7016 /* TODO: Setup ps and cts/rts protection */
7021 ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
7022 struct ieee80211_vif *vif,
7023 struct ieee80211_chanctx_conf *ctx)
7025 struct ath11k *ar = hw->priv;
7026 struct ath11k_base *ab = ar->ab;
7027 struct ath11k_vif *arvif = (void *)vif->drv_priv;
7029 struct peer_create_params param;
7031 mutex_lock(&ar->conf_mutex);
7033 ath11k_dbg(ab, ATH11K_DBG_MAC,
7034 "mac chanctx assign ptr %pK vdev_id %i\n",
7035 ctx, arvif->vdev_id);
7037 /* for QCA6390 bss peer must be created before vdev_start */
7038 if (ab->hw_params.vdev_start_delay &&
7039 arvif->vdev_type != WMI_VDEV_TYPE_AP &&
7040 arvif->vdev_type != WMI_VDEV_TYPE_MONITOR &&
7041 !ath11k_peer_find_by_vdev_id(ab, arvif->vdev_id)) {
7042 memcpy(&arvif->chanctx, ctx, sizeof(*ctx));
7047 if (WARN_ON(arvif->is_started)) {
7052 if (ab->hw_params.vdev_start_delay &&
7053 arvif->vdev_type != WMI_VDEV_TYPE_AP &&
7054 arvif->vdev_type != WMI_VDEV_TYPE_MONITOR) {
7055 param.vdev_id = arvif->vdev_id;
7056 param.peer_type = WMI_PEER_TYPE_DEFAULT;
7057 param.peer_addr = ar->mac_addr;
7059 ret = ath11k_peer_create(ar, arvif, NULL, ¶m);
7061 ath11k_warn(ab, "failed to create peer after vdev start delay: %d",
7067 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
7068 ret = ath11k_mac_monitor_start(ar);
7070 ath11k_warn(ar->ab, "failed to start monitor during vif channel context assignment: %d",
7075 arvif->is_started = true;
7079 ret = ath11k_mac_vdev_start(arvif, ctx);
7081 ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
7082 arvif->vdev_id, vif->addr,
7083 ctx->def.chan->center_freq, ret);
7087 arvif->is_started = true;
7089 if (arvif->vdev_type != WMI_VDEV_TYPE_MONITOR &&
7090 test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags)) {
7091 ret = ath11k_mac_monitor_start(ar);
7093 ath11k_warn(ar->ab, "failed to start monitor during vif channel context assignment: %d",
7099 /* TODO: Setup ps and cts/rts protection */
7104 mutex_unlock(&ar->conf_mutex);
7110 ath11k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
7111 struct ieee80211_vif *vif,
7112 struct ieee80211_chanctx_conf *ctx)
7114 struct ath11k *ar = hw->priv;
7115 struct ath11k_base *ab = ar->ab;
7116 struct ath11k_vif *arvif = (void *)vif->drv_priv;
7119 mutex_lock(&ar->conf_mutex);
7121 ath11k_dbg(ab, ATH11K_DBG_MAC,
7122 "mac chanctx unassign ptr %pK vdev_id %i\n",
7123 ctx, arvif->vdev_id);
7125 WARN_ON(!arvif->is_started);
7127 if (ab->hw_params.vdev_start_delay &&
7128 arvif->vdev_type == WMI_VDEV_TYPE_MONITOR &&
7129 ath11k_peer_find_by_addr(ab, ar->mac_addr))
7130 ath11k_peer_delete(ar, arvif->vdev_id, ar->mac_addr);
7132 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
7133 ret = ath11k_mac_monitor_stop(ar);
7135 ath11k_warn(ar->ab, "failed to stop monitor during vif channel context unassignment: %d",
7137 mutex_unlock(&ar->conf_mutex);
7141 arvif->is_started = false;
7142 mutex_unlock(&ar->conf_mutex);
7146 ret = ath11k_mac_vdev_stop(arvif);
7148 ath11k_warn(ab, "failed to stop vdev %i: %d\n",
7149 arvif->vdev_id, ret);
7151 arvif->is_started = false;
7153 if (ab->hw_params.vdev_start_delay &&
7154 arvif->vdev_type == WMI_VDEV_TYPE_STA) {
7155 ret = ath11k_peer_delete(ar, arvif->vdev_id, arvif->bssid);
7158 "failed to delete peer %pM for vdev %d: %d\n",
7159 arvif->bssid, arvif->vdev_id, ret);
7161 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
7162 "mac removed peer %pM vdev %d after vdev stop\n",
7163 arvif->bssid, arvif->vdev_id);
7166 if (ab->hw_params.vdev_start_delay &&
7167 arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
7168 ath11k_wmi_vdev_down(ar, arvif->vdev_id);
7170 if (arvif->vdev_type != WMI_VDEV_TYPE_MONITOR &&
7171 ar->num_started_vdevs == 1 &&
7172 test_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags)) {
7173 ret = ath11k_mac_monitor_stop(ar);
7175 /* continue even if there's an error */
7176 ath11k_warn(ar->ab, "failed to stop monitor during vif channel context unassignment: %d",
7180 if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
7181 ath11k_mac_11d_scan_start(ar, arvif->vdev_id);
7183 mutex_unlock(&ar->conf_mutex);
7187 ath11k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
7188 struct ieee80211_vif_chanctx_switch *vifs,
7190 enum ieee80211_chanctx_switch_mode mode)
7192 struct ath11k *ar = hw->priv;
7194 mutex_lock(&ar->conf_mutex);
7196 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
7197 "mac chanctx switch n_vifs %d mode %d\n",
7199 ath11k_mac_update_vif_chan(ar, vifs, n_vifs);
7201 mutex_unlock(&ar->conf_mutex);
7207 ath11k_set_vdev_param_to_all_vifs(struct ath11k *ar, int param, u32 value)
7209 struct ath11k_vif *arvif;
7212 mutex_lock(&ar->conf_mutex);
7213 list_for_each_entry(arvif, &ar->arvifs, list) {
7214 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "setting mac vdev %d param %d value %d\n",
7215 param, arvif->vdev_id, value);
7217 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7220 ath11k_warn(ar->ab, "failed to set param %d for vdev %d: %d\n",
7221 param, arvif->vdev_id, ret);
7225 mutex_unlock(&ar->conf_mutex);
7229 /* mac80211 stores device specific RTS/Fragmentation threshold value,
7230 * this is set interface specific to firmware from ath11k driver
7232 static int ath11k_mac_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
7234 struct ath11k *ar = hw->priv;
7235 int param_id = WMI_VDEV_PARAM_RTS_THRESHOLD;
7237 return ath11k_set_vdev_param_to_all_vifs(ar, param_id, value);
7240 static int ath11k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
7242 /* Even though there's a WMI vdev param for fragmentation threshold no
7243 * known firmware actually implements it. Moreover it is not possible to
7244 * rely frame fragmentation to mac80211 because firmware clears the
7245 * "more fragments" bit in frame control making it impossible for remote
7246 * devices to reassemble frames.
7248 * Hence implement a dummy callback just to say fragmentation isn't
7249 * supported. This effectively prevents mac80211 from doing frame
7250 * fragmentation in software.
7255 static void ath11k_mac_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
7256 u32 queues, bool drop)
7258 struct ath11k *ar = hw->priv;
7264 time_left = wait_event_timeout(ar->dp.tx_empty_waitq,
7265 (atomic_read(&ar->dp.num_tx_pending) == 0),
7266 ATH11K_FLUSH_TIMEOUT);
7268 ath11k_warn(ar->ab, "failed to flush transmit queue %ld\n", time_left);
7270 time_left = wait_event_timeout(ar->txmgmt_empty_waitq,
7271 (atomic_read(&ar->num_pending_mgmt_tx) == 0),
7272 ATH11K_FLUSH_TIMEOUT);
7274 ath11k_warn(ar->ab, "failed to flush mgmt transmit queue %ld\n",
7277 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
7278 "mac mgmt tx flush mgmt pending %d\n",
7279 atomic_read(&ar->num_pending_mgmt_tx));
7283 ath11k_mac_bitrate_mask_num_ht_rates(struct ath11k *ar,
7284 enum nl80211_band band,
7285 const struct cfg80211_bitrate_mask *mask)
7290 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
7291 num_rates += hweight16(mask->control[band].ht_mcs[i]);
7297 ath11k_mac_has_single_legacy_rate(struct ath11k *ar,
7298 enum nl80211_band band,
7299 const struct cfg80211_bitrate_mask *mask)
7303 num_rates = hweight32(mask->control[band].legacy);
7305 if (ath11k_mac_bitrate_mask_num_ht_rates(ar, band, mask))
7308 if (ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask))
7311 if (ath11k_mac_bitrate_mask_num_he_rates(ar, band, mask))
7314 return num_rates == 1;
7318 ath11k_mac_get_tx_mcs_map(const struct ieee80211_sta_he_cap *he_cap)
7320 if (he_cap->he_cap_elem.phy_cap_info[0] &
7321 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)
7322 return he_cap->he_mcs_nss_supp.tx_mcs_80p80;
7324 if (he_cap->he_cap_elem.phy_cap_info[0] &
7325 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
7326 return he_cap->he_mcs_nss_supp.tx_mcs_160;
7328 return he_cap->he_mcs_nss_supp.tx_mcs_80;
7332 ath11k_mac_bitrate_mask_get_single_nss(struct ath11k *ar,
7333 enum nl80211_band band,
7334 const struct cfg80211_bitrate_mask *mask,
7337 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
7338 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7341 u8 vht_nss_mask = 0;
7345 /* No need to consider legacy here. Basic rates are always present
7349 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
7350 if (mask->control[band].ht_mcs[i] == 0)
7352 else if (mask->control[band].ht_mcs[i] ==
7353 sband->ht_cap.mcs.rx_mask[i])
7354 ht_nss_mask |= BIT(i);
7359 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
7360 if (mask->control[band].vht_mcs[i] == 0)
7362 else if (mask->control[band].vht_mcs[i] ==
7363 ath11k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
7364 vht_nss_mask |= BIT(i);
7369 he_mcs_map = le16_to_cpu(ath11k_mac_get_tx_mcs_map(&sband->iftype_data->he_cap));
7371 for (i = 0; i < ARRAY_SIZE(mask->control[band].he_mcs); i++) {
7372 if (mask->control[band].he_mcs[i] == 0)
7375 if (mask->control[band].he_mcs[i] ==
7376 ath11k_mac_get_max_he_mcs_map(he_mcs_map, i))
7377 he_nss_mask |= BIT(i);
7382 if (ht_nss_mask != vht_nss_mask || ht_nss_mask != he_nss_mask)
7385 if (ht_nss_mask == 0)
7388 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
7391 *nss = fls(ht_nss_mask);
7397 ath11k_mac_get_single_legacy_rate(struct ath11k *ar,
7398 enum nl80211_band band,
7399 const struct cfg80211_bitrate_mask *mask,
7407 if (hweight32(mask->control[band].legacy) != 1)
7410 rate_idx = ffs(mask->control[band].legacy) - 1;
7412 if (band == NL80211_BAND_5GHZ || band == NL80211_BAND_6GHZ)
7413 rate_idx += ATH11K_MAC_FIRST_OFDM_RATE_IDX;
7415 hw_rate = ath11k_legacy_rates[rate_idx].hw_value;
7416 bitrate = ath11k_legacy_rates[rate_idx].bitrate;
7418 if (ath11k_mac_bitrate_is_cck(bitrate))
7419 preamble = WMI_RATE_PREAMBLE_CCK;
7421 preamble = WMI_RATE_PREAMBLE_OFDM;
7424 *rate = ATH11K_HW_RATE_CODE(hw_rate, 0, preamble);
7430 ath11k_mac_set_fixed_rate_gi_ltf(struct ath11k_vif *arvif, u8 he_gi, u8 he_ltf)
7432 struct ath11k *ar = arvif->ar;
7435 /* 0.8 = 0, 1.6 = 2 and 3.2 = 3. */
7436 if (he_gi && he_gi != 0xFF)
7439 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7440 WMI_VDEV_PARAM_SGI, he_gi);
7442 ath11k_warn(ar->ab, "failed to set he gi %d: %d\n",
7450 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7451 WMI_VDEV_PARAM_HE_LTF, he_ltf);
7453 ath11k_warn(ar->ab, "failed to set he ltf %d: %d\n",
7462 ath11k_mac_set_auto_rate_gi_ltf(struct ath11k_vif *arvif, u16 he_gi, u8 he_ltf)
7464 struct ath11k *ar = arvif->ar;
7468 if (he_gi != 0xFF) {
7470 case NL80211_RATE_INFO_HE_GI_0_8:
7471 he_gi = WMI_AUTORATE_800NS_GI;
7473 case NL80211_RATE_INFO_HE_GI_1_6:
7474 he_gi = WMI_AUTORATE_1600NS_GI;
7476 case NL80211_RATE_INFO_HE_GI_3_2:
7477 he_gi = WMI_AUTORATE_3200NS_GI;
7480 ath11k_warn(ar->ab, "invalid he gi: %d\n", he_gi);
7485 if (he_ltf != 0xFF) {
7487 case NL80211_RATE_INFO_HE_1XLTF:
7488 he_ltf = WMI_HE_AUTORATE_LTF_1X;
7490 case NL80211_RATE_INFO_HE_2XLTF:
7491 he_ltf = WMI_HE_AUTORATE_LTF_2X;
7493 case NL80211_RATE_INFO_HE_4XLTF:
7494 he_ltf = WMI_HE_AUTORATE_LTF_4X;
7497 ath11k_warn(ar->ab, "invalid he ltf: %d\n", he_ltf);
7502 he_ar_gi_ltf = he_gi | he_ltf;
7503 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7504 WMI_VDEV_PARAM_AUTORATE_MISC_CFG,
7508 "failed to set he autorate gi %u ltf %u: %d\n",
7509 he_gi, he_ltf, ret);
7516 static int ath11k_mac_set_rate_params(struct ath11k_vif *arvif,
7517 u32 rate, u8 nss, u8 sgi, u8 ldpc,
7518 u8 he_gi, u8 he_ltf, bool he_fixed_rate)
7520 struct ath11k *ar = arvif->ar;
7524 lockdep_assert_held(&ar->conf_mutex);
7526 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
7527 "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",
7528 arvif->vdev_id, rate, nss, sgi, ldpc, he_gi,
7529 he_ltf, he_fixed_rate);
7531 if (!arvif->vif->bss_conf.he_support) {
7532 vdev_param = WMI_VDEV_PARAM_FIXED_RATE;
7533 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7536 ath11k_warn(ar->ab, "failed to set fixed rate param 0x%02x: %d\n",
7542 vdev_param = WMI_VDEV_PARAM_NSS;
7543 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7546 ath11k_warn(ar->ab, "failed to set nss param %d: %d\n",
7551 vdev_param = WMI_VDEV_PARAM_LDPC;
7552 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7555 ath11k_warn(ar->ab, "failed to set ldpc param %d: %d\n",
7560 if (arvif->vif->bss_conf.he_support) {
7561 if (he_fixed_rate) {
7562 ret = ath11k_mac_set_fixed_rate_gi_ltf(arvif, he_gi,
7565 ath11k_warn(ar->ab, "failed to set fixed rate gi ltf: %d\n",
7570 ret = ath11k_mac_set_auto_rate_gi_ltf(arvif, he_gi,
7573 ath11k_warn(ar->ab, "failed to set auto rate gi ltf: %d\n",
7579 vdev_param = WMI_VDEV_PARAM_SGI;
7580 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
7583 ath11k_warn(ar->ab, "failed to set sgi param %d: %d\n",
7593 ath11k_mac_vht_mcs_range_present(struct ath11k *ar,
7594 enum nl80211_band band,
7595 const struct cfg80211_bitrate_mask *mask)
7600 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7601 vht_mcs = mask->control[band].vht_mcs[i];
7618 ath11k_mac_he_mcs_range_present(struct ath11k *ar,
7619 enum nl80211_band band,
7620 const struct cfg80211_bitrate_mask *mask)
7625 for (i = 0; i < NL80211_HE_NSS_MAX; i++) {
7626 he_mcs = mask->control[band].he_mcs[i];
7642 static void ath11k_mac_set_bitrate_mask_iter(void *data,
7643 struct ieee80211_sta *sta)
7645 struct ath11k_vif *arvif = data;
7646 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
7647 struct ath11k *ar = arvif->ar;
7649 spin_lock_bh(&ar->data_lock);
7650 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
7651 spin_unlock_bh(&ar->data_lock);
7653 ieee80211_queue_work(ar->hw, &arsta->update_wk);
7656 static void ath11k_mac_disable_peer_fixed_rate(void *data,
7657 struct ieee80211_sta *sta)
7659 struct ath11k_vif *arvif = data;
7660 struct ath11k *ar = arvif->ar;
7663 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
7665 WMI_PEER_PARAM_FIXED_RATE,
7666 WMI_FIXED_RATE_NONE);
7669 "failed to disable peer fixed rate for STA %pM ret %d\n",
7674 ath11k_mac_validate_vht_he_fixed_rate_settings(struct ath11k *ar, enum nl80211_band band,
7675 const struct cfg80211_bitrate_mask *mask)
7677 bool he_fixed_rate = false, vht_fixed_rate = false;
7678 struct ath11k_peer *peer, *tmp;
7679 const u16 *vht_mcs_mask, *he_mcs_mask;
7683 vht_mcs_mask = mask->control[band].vht_mcs;
7684 he_mcs_mask = mask->control[band].he_mcs;
7686 if (ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask) == 1)
7687 vht_fixed_rate = true;
7689 if (ath11k_mac_bitrate_mask_num_he_rates(ar, band, mask) == 1)
7690 he_fixed_rate = true;
7692 if (!vht_fixed_rate && !he_fixed_rate)
7695 vht_nss = ath11k_mac_max_vht_nss(vht_mcs_mask);
7696 he_nss = ath11k_mac_max_he_nss(he_mcs_mask);
7699 spin_lock_bh(&ar->ab->base_lock);
7700 list_for_each_entry_safe(peer, tmp, &ar->ab->peers, list) {
7702 if (vht_fixed_rate && (!peer->sta->vht_cap.vht_supported ||
7703 peer->sta->rx_nss < vht_nss)) {
7707 if (he_fixed_rate && (!peer->sta->he_cap.has_he ||
7708 peer->sta->rx_nss < he_nss)) {
7716 spin_unlock_bh(&ar->ab->base_lock);
7722 ath11k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
7723 struct ieee80211_vif *vif,
7724 const struct cfg80211_bitrate_mask *mask)
7726 struct ath11k_vif *arvif = (void *)vif->drv_priv;
7727 struct cfg80211_chan_def def;
7728 struct ath11k *ar = arvif->ar;
7729 enum nl80211_band band;
7730 const u8 *ht_mcs_mask;
7731 const u16 *vht_mcs_mask;
7732 const u16 *he_mcs_mask;
7742 bool he_fixed_rate = false;
7744 if (ath11k_mac_vif_chan(vif, &def))
7747 band = def.chan->band;
7748 ht_mcs_mask = mask->control[band].ht_mcs;
7749 vht_mcs_mask = mask->control[band].vht_mcs;
7750 he_mcs_mask = mask->control[band].he_mcs;
7751 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
7753 sgi = mask->control[band].gi;
7754 if (sgi == NL80211_TXRATE_FORCE_LGI)
7757 he_gi = mask->control[band].he_gi;
7758 he_ltf = mask->control[band].he_ltf;
7760 /* mac80211 doesn't support sending a fixed HT/VHT MCS alone, rather it
7761 * requires passing atleast one of used basic rates along with them.
7762 * Fixed rate setting across different preambles(legacy, HT, VHT) is
7763 * not supported by the FW. Hence use of FIXED_RATE vdev param is not
7764 * suitable for setting single HT/VHT rates.
7765 * But, there could be a single basic rate passed from userspace which
7766 * can be done through the FIXED_RATE param.
7768 if (ath11k_mac_has_single_legacy_rate(ar, band, mask)) {
7769 ret = ath11k_mac_get_single_legacy_rate(ar, band, mask, &rate,
7772 ath11k_warn(ar->ab, "failed to get single legacy rate for vdev %i: %d\n",
7773 arvif->vdev_id, ret);
7776 ieee80211_iterate_stations_atomic(ar->hw,
7777 ath11k_mac_disable_peer_fixed_rate,
7779 } else if (ath11k_mac_bitrate_mask_get_single_nss(ar, band, mask,
7781 rate = WMI_FIXED_RATE_NONE;
7783 mutex_lock(&ar->conf_mutex);
7784 arvif->bitrate_mask = *mask;
7785 ieee80211_iterate_stations_atomic(ar->hw,
7786 ath11k_mac_set_bitrate_mask_iter,
7788 mutex_unlock(&ar->conf_mutex);
7790 rate = WMI_FIXED_RATE_NONE;
7792 if (!ath11k_mac_validate_vht_he_fixed_rate_settings(ar, band, mask))
7794 "could not update fixed rate settings to all peers due to mcs/nss incompatibility\n");
7795 nss = min_t(u32, ar->num_tx_chains,
7796 max(max(ath11k_mac_max_ht_nss(ht_mcs_mask),
7797 ath11k_mac_max_vht_nss(vht_mcs_mask)),
7798 ath11k_mac_max_he_nss(he_mcs_mask)));
7800 /* If multiple rates across different preambles are given
7801 * we can reconfigure this info with all peers using PEER_ASSOC
7802 * command with the below exception cases.
7803 * - Single VHT Rate : peer_assoc command accommodates only MCS
7804 * range values i.e 0-7, 0-8, 0-9 for VHT. Though mac80211
7805 * mandates passing basic rates along with HT/VHT rates, FW
7806 * doesn't allow switching from VHT to Legacy. Hence instead of
7807 * setting legacy and VHT rates using RATEMASK_CMD vdev cmd,
7808 * we could set this VHT rate as peer fixed rate param, which
7809 * will override FIXED rate and FW rate control algorithm.
7810 * If single VHT rate is passed along with HT rates, we select
7811 * the VHT rate as fixed rate for vht peers.
7812 * - Multiple VHT Rates : When Multiple VHT rates are given,this
7813 * can be set using RATEMASK CMD which uses FW rate-ctl alg.
7814 * TODO: Setting multiple VHT MCS and replacing peer_assoc with
7815 * RATEMASK_CMDID can cover all use cases of setting rates
7816 * across multiple preambles and rates within same type.
7817 * But requires more validation of the command at this point.
7820 num_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band,
7823 if (!ath11k_mac_vht_mcs_range_present(ar, band, mask) &&
7825 /* TODO: Handle multiple VHT MCS values setting using
7829 "setting %d mcs values in bitrate mask not supported\n",
7834 num_rates = ath11k_mac_bitrate_mask_num_he_rates(ar, band,
7837 he_fixed_rate = true;
7839 if (!ath11k_mac_he_mcs_range_present(ar, band, mask) &&
7842 "Setting more than one HE MCS Value in bitrate mask not supported\n");
7846 mutex_lock(&ar->conf_mutex);
7847 ieee80211_iterate_stations_atomic(ar->hw,
7848 ath11k_mac_disable_peer_fixed_rate,
7851 arvif->bitrate_mask = *mask;
7852 ieee80211_iterate_stations_atomic(ar->hw,
7853 ath11k_mac_set_bitrate_mask_iter,
7856 mutex_unlock(&ar->conf_mutex);
7859 mutex_lock(&ar->conf_mutex);
7861 ret = ath11k_mac_set_rate_params(arvif, rate, nss, sgi, ldpc, he_gi,
7862 he_ltf, he_fixed_rate);
7864 ath11k_warn(ar->ab, "failed to set rate params on vdev %i: %d\n",
7865 arvif->vdev_id, ret);
7868 mutex_unlock(&ar->conf_mutex);
7874 ath11k_mac_op_reconfig_complete(struct ieee80211_hw *hw,
7875 enum ieee80211_reconfig_type reconfig_type)
7877 struct ath11k *ar = hw->priv;
7879 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
7882 mutex_lock(&ar->conf_mutex);
7884 if (ar->state == ATH11K_STATE_RESTARTED) {
7885 ath11k_warn(ar->ab, "pdev %d successfully recovered\n",
7887 ar->state = ATH11K_STATE_ON;
7888 ieee80211_wake_queues(ar->hw);
7891 mutex_unlock(&ar->conf_mutex);
7895 ath11k_mac_update_bss_chan_survey(struct ath11k *ar,
7896 struct ieee80211_channel *channel)
7899 enum wmi_bss_chan_info_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
7901 lockdep_assert_held(&ar->conf_mutex);
7903 if (!test_bit(WMI_TLV_SERVICE_BSS_CHANNEL_INFO_64, ar->ab->wmi_ab.svc_map) ||
7904 ar->rx_channel != channel)
7907 if (ar->scan.state != ATH11K_SCAN_IDLE) {
7908 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
7909 "ignoring bss chan info req while scanning..\n");
7913 reinit_completion(&ar->bss_survey_done);
7915 ret = ath11k_wmi_pdev_bss_chan_info_request(ar, type);
7917 ath11k_warn(ar->ab, "failed to send pdev bss chan info request\n");
7921 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
7923 ath11k_warn(ar->ab, "bss channel survey timed out\n");
7926 static int ath11k_mac_op_get_survey(struct ieee80211_hw *hw, int idx,
7927 struct survey_info *survey)
7929 struct ath11k *ar = hw->priv;
7930 struct ieee80211_supported_band *sband;
7931 struct survey_info *ar_survey;
7934 if (idx >= ATH11K_NUM_CHANS)
7937 ar_survey = &ar->survey[idx];
7939 mutex_lock(&ar->conf_mutex);
7941 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
7942 if (sband && idx >= sband->n_channels) {
7943 idx -= sband->n_channels;
7948 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
7949 if (sband && idx >= sband->n_channels) {
7950 idx -= sband->n_channels;
7955 sband = hw->wiphy->bands[NL80211_BAND_6GHZ];
7956 if (!sband || idx >= sband->n_channels) {
7961 ath11k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
7963 spin_lock_bh(&ar->data_lock);
7964 memcpy(survey, ar_survey, sizeof(*survey));
7965 spin_unlock_bh(&ar->data_lock);
7967 survey->channel = &sband->channels[idx];
7969 if (ar->rx_channel == survey->channel)
7970 survey->filled |= SURVEY_INFO_IN_USE;
7973 mutex_unlock(&ar->conf_mutex);
7977 static void ath11k_mac_put_chain_rssi(struct station_info *sinfo,
7978 struct ath11k_sta *arsta,
7982 struct ath11k *ar = arsta->arvif->ar;
7986 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
7987 sinfo->chains &= ~BIT(i);
7988 rssi = arsta->chain_signal[i];
7990 arsta->chain_signal[i] = ATH11K_INVALID_RSSI_FULL;
7992 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
7993 "mac sta statistics %s rssi[%d] %d\n", pre, i, rssi);
7995 if (rssi != ATH11K_DEFAULT_NOISE_FLOOR &&
7996 rssi != ATH11K_INVALID_RSSI_FULL &&
7997 rssi != ATH11K_INVALID_RSSI_EMPTY &&
7999 sinfo->chain_signal[i] = rssi;
8000 sinfo->chains |= BIT(i);
8001 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
8006 static void ath11k_mac_op_sta_statistics(struct ieee80211_hw *hw,
8007 struct ieee80211_vif *vif,
8008 struct ieee80211_sta *sta,
8009 struct station_info *sinfo)
8011 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
8012 struct ath11k *ar = arsta->arvif->ar;
8014 bool db2dbm = test_bit(WMI_TLV_SERVICE_HW_DB2DBM_CONVERSION_SUPPORT,
8015 ar->ab->wmi_ab.svc_map);
8017 sinfo->rx_duration = arsta->rx_duration;
8018 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
8020 sinfo->tx_duration = arsta->tx_duration;
8021 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION);
8023 if (arsta->txrate.legacy || arsta->txrate.nss) {
8024 if (arsta->txrate.legacy) {
8025 sinfo->txrate.legacy = arsta->txrate.legacy;
8027 sinfo->txrate.mcs = arsta->txrate.mcs;
8028 sinfo->txrate.nss = arsta->txrate.nss;
8029 sinfo->txrate.bw = arsta->txrate.bw;
8030 sinfo->txrate.he_gi = arsta->txrate.he_gi;
8031 sinfo->txrate.he_dcm = arsta->txrate.he_dcm;
8032 sinfo->txrate.he_ru_alloc = arsta->txrate.he_ru_alloc;
8034 sinfo->txrate.flags = arsta->txrate.flags;
8035 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
8038 ath11k_mac_put_chain_rssi(sinfo, arsta, "ppdu", false);
8040 if (!(sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) &&
8041 arsta->arvif->vdev_type == WMI_VDEV_TYPE_STA &&
8042 ar->ab->hw_params.supports_rssi_stats &&
8043 !ath11k_debugfs_get_fw_stats(ar, ar->pdev->pdev_id, 0,
8044 WMI_REQUEST_RSSI_PER_CHAIN_STAT)) {
8045 ath11k_mac_put_chain_rssi(sinfo, arsta, "fw stats", true);
8048 signal = arsta->rssi_comb;
8050 arsta->arvif->vdev_type == WMI_VDEV_TYPE_STA &&
8051 ar->ab->hw_params.supports_rssi_stats &&
8052 !(ath11k_debugfs_get_fw_stats(ar, ar->pdev->pdev_id, 0,
8053 WMI_REQUEST_VDEV_STAT)))
8054 signal = arsta->rssi_beacon;
8056 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
8057 "mac sta statistics db2dbm %u rssi comb %d rssi beacon %d\n",
8058 db2dbm, arsta->rssi_comb, arsta->rssi_beacon);
8061 sinfo->signal = db2dbm ? signal : signal + ATH11K_DEFAULT_NOISE_FLOOR;
8062 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
8066 static const struct ieee80211_ops ath11k_ops = {
8067 .tx = ath11k_mac_op_tx,
8068 .start = ath11k_mac_op_start,
8069 .stop = ath11k_mac_op_stop,
8070 .reconfig_complete = ath11k_mac_op_reconfig_complete,
8071 .add_interface = ath11k_mac_op_add_interface,
8072 .remove_interface = ath11k_mac_op_remove_interface,
8073 .update_vif_offload = ath11k_mac_op_update_vif_offload,
8074 .config = ath11k_mac_op_config,
8075 .bss_info_changed = ath11k_mac_op_bss_info_changed,
8076 .configure_filter = ath11k_mac_op_configure_filter,
8077 .hw_scan = ath11k_mac_op_hw_scan,
8078 .cancel_hw_scan = ath11k_mac_op_cancel_hw_scan,
8079 .set_key = ath11k_mac_op_set_key,
8080 .sta_state = ath11k_mac_op_sta_state,
8081 .sta_set_4addr = ath11k_mac_op_sta_set_4addr,
8082 .sta_set_txpwr = ath11k_mac_op_sta_set_txpwr,
8083 .sta_rc_update = ath11k_mac_op_sta_rc_update,
8084 .conf_tx = ath11k_mac_op_conf_tx,
8085 .set_antenna = ath11k_mac_op_set_antenna,
8086 .get_antenna = ath11k_mac_op_get_antenna,
8087 .ampdu_action = ath11k_mac_op_ampdu_action,
8088 .add_chanctx = ath11k_mac_op_add_chanctx,
8089 .remove_chanctx = ath11k_mac_op_remove_chanctx,
8090 .change_chanctx = ath11k_mac_op_change_chanctx,
8091 .assign_vif_chanctx = ath11k_mac_op_assign_vif_chanctx,
8092 .unassign_vif_chanctx = ath11k_mac_op_unassign_vif_chanctx,
8093 .switch_vif_chanctx = ath11k_mac_op_switch_vif_chanctx,
8094 .set_rts_threshold = ath11k_mac_op_set_rts_threshold,
8095 .set_frag_threshold = ath11k_mac_op_set_frag_threshold,
8096 .set_bitrate_mask = ath11k_mac_op_set_bitrate_mask,
8097 .get_survey = ath11k_mac_op_get_survey,
8098 .flush = ath11k_mac_op_flush,
8099 .sta_statistics = ath11k_mac_op_sta_statistics,
8100 CFG80211_TESTMODE_CMD(ath11k_tm_cmd)
8101 #ifdef CONFIG_ATH11K_DEBUGFS
8102 .sta_add_debugfs = ath11k_debugfs_sta_op_add,
8106 static void ath11k_mac_update_ch_list(struct ath11k *ar,
8107 struct ieee80211_supported_band *band,
8108 u32 freq_low, u32 freq_high)
8112 if (!(freq_low && freq_high))
8115 for (i = 0; i < band->n_channels; i++) {
8116 if (band->channels[i].center_freq < freq_low ||
8117 band->channels[i].center_freq > freq_high)
8118 band->channels[i].flags |= IEEE80211_CHAN_DISABLED;
8122 static u32 ath11k_get_phy_id(struct ath11k *ar, u32 band)
8124 struct ath11k_pdev *pdev = ar->pdev;
8125 struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
8127 if (band == WMI_HOST_WLAN_2G_CAP)
8128 return pdev_cap->band[NL80211_BAND_2GHZ].phy_id;
8130 if (band == WMI_HOST_WLAN_5G_CAP)
8131 return pdev_cap->band[NL80211_BAND_5GHZ].phy_id;
8133 ath11k_warn(ar->ab, "unsupported phy cap:%d\n", band);
8138 static int ath11k_mac_setup_channels_rates(struct ath11k *ar,
8139 u32 supported_bands)
8141 struct ieee80211_supported_band *band;
8142 struct ath11k_hal_reg_capabilities_ext *reg_cap, *temp_reg_cap;
8146 BUILD_BUG_ON((ARRAY_SIZE(ath11k_2ghz_channels) +
8147 ARRAY_SIZE(ath11k_5ghz_channels) +
8148 ARRAY_SIZE(ath11k_6ghz_channels)) !=
8151 reg_cap = &ar->ab->hal_reg_cap[ar->pdev_idx];
8152 temp_reg_cap = reg_cap;
8154 if (supported_bands & WMI_HOST_WLAN_2G_CAP) {
8155 channels = kmemdup(ath11k_2ghz_channels,
8156 sizeof(ath11k_2ghz_channels),
8161 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
8162 band->band = NL80211_BAND_2GHZ;
8163 band->n_channels = ARRAY_SIZE(ath11k_2ghz_channels);
8164 band->channels = channels;
8165 band->n_bitrates = ath11k_g_rates_size;
8166 band->bitrates = ath11k_g_rates;
8167 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
8169 if (ar->ab->hw_params.single_pdev_only) {
8170 phy_id = ath11k_get_phy_id(ar, WMI_HOST_WLAN_2G_CAP);
8171 temp_reg_cap = &ar->ab->hal_reg_cap[phy_id];
8173 ath11k_mac_update_ch_list(ar, band,
8174 temp_reg_cap->low_2ghz_chan,
8175 temp_reg_cap->high_2ghz_chan);
8178 if (supported_bands & WMI_HOST_WLAN_5G_CAP) {
8179 if (reg_cap->high_5ghz_chan >= ATH11K_MAX_6G_FREQ) {
8180 channels = kmemdup(ath11k_6ghz_channels,
8181 sizeof(ath11k_6ghz_channels), GFP_KERNEL);
8183 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8187 ar->supports_6ghz = true;
8188 band = &ar->mac.sbands[NL80211_BAND_6GHZ];
8189 band->band = NL80211_BAND_6GHZ;
8190 band->n_channels = ARRAY_SIZE(ath11k_6ghz_channels);
8191 band->channels = channels;
8192 band->n_bitrates = ath11k_a_rates_size;
8193 band->bitrates = ath11k_a_rates;
8194 ar->hw->wiphy->bands[NL80211_BAND_6GHZ] = band;
8196 if (ar->ab->hw_params.single_pdev_only) {
8197 phy_id = ath11k_get_phy_id(ar, WMI_HOST_WLAN_5G_CAP);
8198 temp_reg_cap = &ar->ab->hal_reg_cap[phy_id];
8201 ath11k_mac_update_ch_list(ar, band,
8202 temp_reg_cap->low_5ghz_chan,
8203 temp_reg_cap->high_5ghz_chan);
8206 if (reg_cap->low_5ghz_chan < ATH11K_MIN_6G_FREQ) {
8207 channels = kmemdup(ath11k_5ghz_channels,
8208 sizeof(ath11k_5ghz_channels),
8211 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8212 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
8216 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
8217 band->band = NL80211_BAND_5GHZ;
8218 band->n_channels = ARRAY_SIZE(ath11k_5ghz_channels);
8219 band->channels = channels;
8220 band->n_bitrates = ath11k_a_rates_size;
8221 band->bitrates = ath11k_a_rates;
8222 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
8224 if (ar->ab->hw_params.single_pdev_only) {
8225 phy_id = ath11k_get_phy_id(ar, WMI_HOST_WLAN_5G_CAP);
8226 temp_reg_cap = &ar->ab->hal_reg_cap[phy_id];
8229 ath11k_mac_update_ch_list(ar, band,
8230 temp_reg_cap->low_5ghz_chan,
8231 temp_reg_cap->high_5ghz_chan);
8238 static int ath11k_mac_setup_iface_combinations(struct ath11k *ar)
8240 struct ath11k_base *ab = ar->ab;
8241 struct ieee80211_iface_combination *combinations;
8242 struct ieee80211_iface_limit *limits;
8245 combinations = kzalloc(sizeof(*combinations), GFP_KERNEL);
8251 limits = kcalloc(n_limits, sizeof(*limits), GFP_KERNEL);
8253 kfree(combinations);
8258 limits[0].types |= BIT(NL80211_IFTYPE_STATION);
8261 limits[1].types |= BIT(NL80211_IFTYPE_AP);
8263 if (IS_ENABLED(CONFIG_MAC80211_MESH) &&
8264 ab->hw_params.interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
8265 limits[1].types |= BIT(NL80211_IFTYPE_MESH_POINT);
8267 combinations[0].limits = limits;
8268 combinations[0].n_limits = n_limits;
8269 combinations[0].max_interfaces = 16;
8270 combinations[0].num_different_channels = 1;
8271 combinations[0].beacon_int_infra_match = true;
8272 combinations[0].beacon_int_min_gcd = 100;
8273 combinations[0].radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
8274 BIT(NL80211_CHAN_WIDTH_20) |
8275 BIT(NL80211_CHAN_WIDTH_40) |
8276 BIT(NL80211_CHAN_WIDTH_80) |
8277 BIT(NL80211_CHAN_WIDTH_80P80) |
8278 BIT(NL80211_CHAN_WIDTH_160);
8280 ar->hw->wiphy->iface_combinations = combinations;
8281 ar->hw->wiphy->n_iface_combinations = 1;
8286 static const u8 ath11k_if_types_ext_capa[] = {
8287 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
8288 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
8291 static const u8 ath11k_if_types_ext_capa_sta[] = {
8292 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
8293 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
8294 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
8297 static const u8 ath11k_if_types_ext_capa_ap[] = {
8298 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
8299 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
8300 [9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT,
8303 static const struct wiphy_iftype_ext_capab ath11k_iftypes_ext_capa[] = {
8305 .extended_capabilities = ath11k_if_types_ext_capa,
8306 .extended_capabilities_mask = ath11k_if_types_ext_capa,
8307 .extended_capabilities_len = sizeof(ath11k_if_types_ext_capa),
8309 .iftype = NL80211_IFTYPE_STATION,
8310 .extended_capabilities = ath11k_if_types_ext_capa_sta,
8311 .extended_capabilities_mask = ath11k_if_types_ext_capa_sta,
8312 .extended_capabilities_len =
8313 sizeof(ath11k_if_types_ext_capa_sta),
8315 .iftype = NL80211_IFTYPE_AP,
8316 .extended_capabilities = ath11k_if_types_ext_capa_ap,
8317 .extended_capabilities_mask = ath11k_if_types_ext_capa_ap,
8318 .extended_capabilities_len =
8319 sizeof(ath11k_if_types_ext_capa_ap),
8323 static void __ath11k_mac_unregister(struct ath11k *ar)
8325 cancel_work_sync(&ar->regd_update_work);
8327 ieee80211_unregister_hw(ar->hw);
8329 idr_for_each(&ar->txmgmt_idr, ath11k_mac_tx_mgmt_pending_free, ar);
8330 idr_destroy(&ar->txmgmt_idr);
8332 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8333 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8334 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
8336 kfree(ar->hw->wiphy->iface_combinations[0].limits);
8337 kfree(ar->hw->wiphy->iface_combinations);
8339 SET_IEEE80211_DEV(ar->hw, NULL);
8342 void ath11k_mac_unregister(struct ath11k_base *ab)
8345 struct ath11k_pdev *pdev;
8348 for (i = 0; i < ab->num_radios; i++) {
8349 pdev = &ab->pdevs[i];
8354 __ath11k_mac_unregister(ar);
8358 static int __ath11k_mac_register(struct ath11k *ar)
8360 struct ath11k_base *ab = ar->ab;
8361 struct ath11k_pdev_cap *cap = &ar->pdev->cap;
8362 static const u32 cipher_suites[] = {
8363 WLAN_CIPHER_SUITE_TKIP,
8364 WLAN_CIPHER_SUITE_CCMP,
8365 WLAN_CIPHER_SUITE_AES_CMAC,
8366 WLAN_CIPHER_SUITE_BIP_CMAC_256,
8367 WLAN_CIPHER_SUITE_BIP_GMAC_128,
8368 WLAN_CIPHER_SUITE_BIP_GMAC_256,
8369 WLAN_CIPHER_SUITE_GCMP,
8370 WLAN_CIPHER_SUITE_GCMP_256,
8371 WLAN_CIPHER_SUITE_CCMP_256,
8376 ath11k_pdev_caps_update(ar);
8378 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
8380 SET_IEEE80211_DEV(ar->hw, ab->dev);
8382 ret = ath11k_mac_setup_channels_rates(ar,
8383 cap->supported_bands);
8387 ath11k_mac_setup_ht_vht_cap(ar, cap, &ht_cap);
8388 ath11k_mac_setup_he_cap(ar, cap);
8390 ret = ath11k_mac_setup_iface_combinations(ar);
8392 ath11k_err(ar->ab, "failed to setup interface combinations: %d\n", ret);
8393 goto err_free_channels;
8396 ar->hw->wiphy->available_antennas_rx = cap->rx_chain_mask;
8397 ar->hw->wiphy->available_antennas_tx = cap->tx_chain_mask;
8399 ar->hw->wiphy->interface_modes = ab->hw_params.interface_modes;
8401 if (ab->hw_params.single_pdev_only && ar->supports_6ghz)
8402 ieee80211_hw_set(ar->hw, SINGLE_SCAN_ON_ALL_BANDS);
8404 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
8405 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
8406 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
8407 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
8408 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
8409 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
8410 ieee80211_hw_set(ar->hw, AP_LINK_PS);
8411 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
8412 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
8413 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
8414 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
8415 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
8416 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
8417 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
8418 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
8420 if (ath11k_frame_mode == ATH11K_HW_TXRX_ETHERNET) {
8421 ieee80211_hw_set(ar->hw, SUPPORTS_TX_ENCAP_OFFLOAD);
8422 ieee80211_hw_set(ar->hw, SUPPORTS_RX_DECAP_OFFLOAD);
8425 if (cap->nss_ratio_enabled)
8426 ieee80211_hw_set(ar->hw, SUPPORTS_VHT_EXT_NSS_BW);
8428 if ((ht_cap & WMI_HT_CAP_ENABLED) || ar->supports_6ghz) {
8429 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
8430 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
8431 ieee80211_hw_set(ar->hw, SUPPORTS_REORDERING_BUFFER);
8432 ieee80211_hw_set(ar->hw, SUPPORTS_AMSDU_IN_AMPDU);
8433 ieee80211_hw_set(ar->hw, USES_RSS);
8436 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
8437 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
8439 /* TODO: Check if HT capability advertised from firmware is different
8440 * for each band for a dual band capable radio. It will be tricky to
8441 * handle it when the ht capability different for each band.
8443 if (ht_cap & WMI_HT_CAP_DYNAMIC_SMPS ||
8444 (ar->supports_6ghz && ab->hw_params.supports_dynamic_smps_6ghz))
8445 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
8447 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
8448 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
8450 ar->hw->max_listen_interval = ATH11K_MAX_HW_LISTEN_INTERVAL;
8452 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
8453 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
8454 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
8456 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
8457 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
8458 NL80211_FEATURE_AP_SCAN;
8460 ar->max_num_stations = TARGET_NUM_STATIONS(ab);
8461 ar->max_num_peers = TARGET_NUM_PEERS_PDEV(ab);
8463 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
8465 if (test_bit(WMI_TLV_SERVICE_SPOOF_MAC_SUPPORT, ar->wmi->wmi_ab->svc_map)) {
8466 ar->hw->wiphy->features |=
8467 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
8470 ar->hw->queues = ATH11K_HW_MAX_QUEUES;
8471 ar->hw->wiphy->tx_queue_len = ATH11K_QUEUE_LEN;
8472 ar->hw->offchannel_tx_hw_queue = ATH11K_HW_MAX_QUEUES - 1;
8473 ar->hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_HE;
8475 ar->hw->vif_data_size = sizeof(struct ath11k_vif);
8476 ar->hw->sta_data_size = sizeof(struct ath11k_sta);
8478 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
8479 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_STA_TX_PWR);
8480 if (test_bit(WMI_TLV_SERVICE_BSS_COLOR_OFFLOAD, ar->ab->wmi_ab.svc_map))
8481 wiphy_ext_feature_set(ar->hw->wiphy,
8482 NL80211_EXT_FEATURE_BSS_COLOR);
8484 ar->hw->wiphy->cipher_suites = cipher_suites;
8485 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
8487 ar->hw->wiphy->iftype_ext_capab = ath11k_iftypes_ext_capa;
8488 ar->hw->wiphy->num_iftype_ext_capab =
8489 ARRAY_SIZE(ath11k_iftypes_ext_capa);
8491 if (ar->supports_6ghz) {
8492 wiphy_ext_feature_set(ar->hw->wiphy,
8493 NL80211_EXT_FEATURE_FILS_DISCOVERY);
8494 wiphy_ext_feature_set(ar->hw->wiphy,
8495 NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP);
8498 ath11k_reg_init(ar);
8500 if (!test_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags)) {
8501 ar->hw->netdev_features = NETIF_F_HW_CSUM;
8502 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
8503 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
8506 ret = ieee80211_register_hw(ar->hw);
8508 ath11k_err(ar->ab, "ieee80211 registration failed: %d\n", ret);
8509 goto err_free_if_combs;
8512 if (!ab->hw_params.supports_monitor)
8513 /* There's a race between calling ieee80211_register_hw()
8514 * and here where the monitor mode is enabled for a little
8515 * while. But that time is so short and in practise it make
8516 * a difference in real life.
8518 ar->hw->wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MONITOR);
8520 /* Apply the regd received during initialization */
8521 ret = ath11k_regd_update(ar);
8523 ath11k_err(ar->ab, "ath11k regd update failed: %d\n", ret);
8524 goto err_unregister_hw;
8527 ret = ath11k_debugfs_register(ar);
8529 ath11k_err(ar->ab, "debugfs registration failed: %d\n", ret);
8530 goto err_unregister_hw;
8536 ieee80211_unregister_hw(ar->hw);
8539 kfree(ar->hw->wiphy->iface_combinations[0].limits);
8540 kfree(ar->hw->wiphy->iface_combinations);
8543 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
8544 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
8545 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
8548 SET_IEEE80211_DEV(ar->hw, NULL);
8552 int ath11k_mac_register(struct ath11k_base *ab)
8555 struct ath11k_pdev *pdev;
8559 if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags))
8562 /* Initialize channel counters frequency value in hertz */
8563 ab->cc_freq_hz = IPQ8074_CC_FREQ_HERTZ;
8564 ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS(ab))) - 1;
8566 for (i = 0; i < ab->num_radios; i++) {
8567 pdev = &ab->pdevs[i];
8569 if (ab->pdevs_macaddr_valid) {
8570 ether_addr_copy(ar->mac_addr, pdev->mac_addr);
8572 ether_addr_copy(ar->mac_addr, ab->mac_addr);
8573 ar->mac_addr[4] += i;
8576 idr_init(&ar->txmgmt_idr);
8577 spin_lock_init(&ar->txmgmt_idr_lock);
8579 ret = __ath11k_mac_register(ar);
8583 init_waitqueue_head(&ar->txmgmt_empty_waitq);
8589 for (i = i - 1; i >= 0; i--) {
8590 pdev = &ab->pdevs[i];
8592 __ath11k_mac_unregister(ar);
8598 int ath11k_mac_allocate(struct ath11k_base *ab)
8600 struct ieee80211_hw *hw;
8602 struct ath11k_pdev *pdev;
8606 if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags))
8609 for (i = 0; i < ab->num_radios; i++) {
8610 pdev = &ab->pdevs[i];
8611 hw = ieee80211_alloc_hw(sizeof(struct ath11k), &ath11k_ops);
8613 ath11k_warn(ab, "failed to allocate mac80211 hw device\n");
8623 ar->lmac_id = ath11k_hw_get_mac_from_pdev_id(&ab->hw_params, i);
8625 ar->wmi = &ab->wmi_ab.wmi[i];
8626 /* FIXME wmi[0] is already initialized during attach,
8627 * Should we do this again?
8629 ath11k_wmi_pdev_attach(ab, i);
8631 ar->cfg_tx_chainmask = pdev->cap.tx_chain_mask;
8632 ar->cfg_rx_chainmask = pdev->cap.rx_chain_mask;
8633 ar->num_tx_chains = get_num_chains(pdev->cap.tx_chain_mask);
8634 ar->num_rx_chains = get_num_chains(pdev->cap.rx_chain_mask);
8637 spin_lock_init(&ar->data_lock);
8638 INIT_LIST_HEAD(&ar->arvifs);
8639 INIT_LIST_HEAD(&ar->ppdu_stats_info);
8640 mutex_init(&ar->conf_mutex);
8641 init_completion(&ar->vdev_setup_done);
8642 init_completion(&ar->vdev_delete_done);
8643 init_completion(&ar->peer_assoc_done);
8644 init_completion(&ar->peer_delete_done);
8645 init_completion(&ar->install_key_done);
8646 init_completion(&ar->bss_survey_done);
8647 init_completion(&ar->scan.started);
8648 init_completion(&ar->scan.completed);
8649 init_completion(&ar->thermal.wmi_sync);
8651 INIT_DELAYED_WORK(&ar->scan.timeout, ath11k_scan_timeout_work);
8652 INIT_WORK(&ar->regd_update_work, ath11k_regd_update_work);
8654 INIT_WORK(&ar->wmi_mgmt_tx_work, ath11k_mgmt_over_wmi_tx_work);
8655 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
8657 clear_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags);
8659 ar->monitor_vdev_id = -1;
8660 clear_bit(ATH11K_FLAG_MONITOR_VDEV_CREATED, &ar->monitor_flags);
8661 ar->vdev_id_11d_scan = ATH11K_11D_INVALID_VDEV_ID;
8662 init_completion(&ar->completed_11d_scan);
8668 ath11k_mac_destroy(ab);
8673 void ath11k_mac_destroy(struct ath11k_base *ab)
8676 struct ath11k_pdev *pdev;
8679 for (i = 0; i < ab->num_radios; i++) {
8680 pdev = &ab->pdevs[i];
8685 ieee80211_free_hw(ar->hw);