1 // SPDX-License-Identifier: BSD-3-Clause-Clear
3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
6 #include <net/mac80211.h>
7 #include <linux/etherdevice.h>
17 #include "debugfs_sta.h"
19 #define CHAN2G(_channel, _freq, _flags) { \
20 .band = NL80211_BAND_2GHZ, \
21 .hw_value = (_channel), \
22 .center_freq = (_freq), \
24 .max_antenna_gain = 0, \
28 #define CHAN5G(_channel, _freq, _flags) { \
29 .band = NL80211_BAND_5GHZ, \
30 .hw_value = (_channel), \
31 .center_freq = (_freq), \
33 .max_antenna_gain = 0, \
37 #define CHAN6G(_channel, _freq, _flags) { \
38 .band = NL80211_BAND_6GHZ, \
39 .hw_value = (_channel), \
40 .center_freq = (_freq), \
42 .max_antenna_gain = 0, \
46 static const struct ieee80211_channel ath11k_2ghz_channels[] = {
63 static const struct ieee80211_channel ath11k_5ghz_channels[] = {
93 static const struct ieee80211_channel ath11k_6ghz_channels[] = {
119 CHAN6G(101, 6455, 0),
120 CHAN6G(105, 6475, 0),
121 CHAN6G(109, 6495, 0),
122 CHAN6G(113, 6515, 0),
123 CHAN6G(117, 6535, 0),
124 CHAN6G(121, 6555, 0),
125 CHAN6G(125, 6575, 0),
126 CHAN6G(129, 6595, 0),
127 CHAN6G(133, 6615, 0),
128 CHAN6G(137, 6635, 0),
129 CHAN6G(141, 6655, 0),
130 CHAN6G(145, 6675, 0),
131 CHAN6G(149, 6695, 0),
132 CHAN6G(153, 6715, 0),
133 CHAN6G(157, 6735, 0),
134 CHAN6G(161, 6755, 0),
135 CHAN6G(165, 6775, 0),
136 CHAN6G(169, 6795, 0),
137 CHAN6G(173, 6815, 0),
138 CHAN6G(177, 6835, 0),
139 CHAN6G(181, 6855, 0),
140 CHAN6G(185, 6875, 0),
141 CHAN6G(189, 6895, 0),
142 CHAN6G(193, 6915, 0),
143 CHAN6G(197, 6935, 0),
144 CHAN6G(201, 6955, 0),
145 CHAN6G(205, 6975, 0),
146 CHAN6G(209, 6995, 0),
147 CHAN6G(213, 7015, 0),
148 CHAN6G(217, 7035, 0),
149 CHAN6G(221, 7055, 0),
150 CHAN6G(225, 7075, 0),
151 CHAN6G(229, 7095, 0),
152 CHAN6G(233, 7115, 0),
155 static struct ieee80211_rate ath11k_legacy_rates[] = {
157 .hw_value = ATH11K_HW_RATE_CCK_LP_1M },
159 .hw_value = ATH11K_HW_RATE_CCK_LP_2M,
160 .hw_value_short = ATH11K_HW_RATE_CCK_SP_2M,
161 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
163 .hw_value = ATH11K_HW_RATE_CCK_LP_5_5M,
164 .hw_value_short = ATH11K_HW_RATE_CCK_SP_5_5M,
165 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
167 .hw_value = ATH11K_HW_RATE_CCK_LP_11M,
168 .hw_value_short = ATH11K_HW_RATE_CCK_SP_11M,
169 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
171 { .bitrate = 60, .hw_value = ATH11K_HW_RATE_OFDM_6M },
172 { .bitrate = 90, .hw_value = ATH11K_HW_RATE_OFDM_9M },
173 { .bitrate = 120, .hw_value = ATH11K_HW_RATE_OFDM_12M },
174 { .bitrate = 180, .hw_value = ATH11K_HW_RATE_OFDM_18M },
175 { .bitrate = 240, .hw_value = ATH11K_HW_RATE_OFDM_24M },
176 { .bitrate = 360, .hw_value = ATH11K_HW_RATE_OFDM_36M },
177 { .bitrate = 480, .hw_value = ATH11K_HW_RATE_OFDM_48M },
178 { .bitrate = 540, .hw_value = ATH11K_HW_RATE_OFDM_54M },
182 ath11k_phymodes[NUM_NL80211_BANDS][ATH11K_CHAN_WIDTH_NUM] = {
183 [NL80211_BAND_2GHZ] = {
184 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
185 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
186 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20_2G,
187 [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20_2G,
188 [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40_2G,
189 [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80_2G,
190 [NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN,
191 [NL80211_CHAN_WIDTH_160] = MODE_UNKNOWN,
193 [NL80211_BAND_5GHZ] = {
194 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
195 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
196 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20,
197 [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20,
198 [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40,
199 [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80,
200 [NL80211_CHAN_WIDTH_160] = MODE_11AX_HE160,
201 [NL80211_CHAN_WIDTH_80P80] = MODE_11AX_HE80_80,
203 [NL80211_BAND_6GHZ] = {
204 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
205 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
206 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20,
207 [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20,
208 [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40,
209 [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80,
210 [NL80211_CHAN_WIDTH_160] = MODE_11AX_HE160,
211 [NL80211_CHAN_WIDTH_80P80] = MODE_11AX_HE80_80,
216 const struct htt_rx_ring_tlv_filter ath11k_mac_mon_status_filter_default = {
217 .rx_filter = HTT_RX_FILTER_TLV_FLAGS_MPDU_START |
218 HTT_RX_FILTER_TLV_FLAGS_PPDU_END |
219 HTT_RX_FILTER_TLV_FLAGS_PPDU_END_STATUS_DONE,
220 .pkt_filter_flags0 = HTT_RX_FP_MGMT_FILTER_FLAGS0,
221 .pkt_filter_flags1 = HTT_RX_FP_MGMT_FILTER_FLAGS1,
222 .pkt_filter_flags2 = HTT_RX_FP_CTRL_FILTER_FLASG2,
223 .pkt_filter_flags3 = HTT_RX_FP_DATA_FILTER_FLASG3 |
224 HTT_RX_FP_CTRL_FILTER_FLASG3
227 #define ATH11K_MAC_FIRST_OFDM_RATE_IDX 4
228 #define ath11k_g_rates ath11k_legacy_rates
229 #define ath11k_g_rates_size (ARRAY_SIZE(ath11k_legacy_rates))
230 #define ath11k_a_rates (ath11k_legacy_rates + 4)
231 #define ath11k_a_rates_size (ARRAY_SIZE(ath11k_legacy_rates) - 4)
233 #define ATH11K_MAC_SCAN_TIMEOUT_MSECS 200 /* in msecs */
235 static const u32 ath11k_smps_map[] = {
236 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
237 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
238 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
239 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
242 static int ath11k_start_vdev_delay(struct ieee80211_hw *hw,
243 struct ieee80211_vif *vif);
245 u8 ath11k_mac_bw_to_mac80211_bw(u8 bw)
251 ret = RATE_INFO_BW_20;
254 ret = RATE_INFO_BW_40;
257 ret = RATE_INFO_BW_80;
260 ret = RATE_INFO_BW_160;
267 enum ath11k_supported_bw ath11k_mac_mac80211_bw_to_ath11k_bw(enum rate_info_bw bw)
270 case RATE_INFO_BW_20:
272 case RATE_INFO_BW_40:
274 case RATE_INFO_BW_80:
276 case RATE_INFO_BW_160:
277 return ATH11K_BW_160;
283 int ath11k_mac_hw_ratecode_to_legacy_rate(u8 hw_rc, u8 preamble, u8 *rateidx,
286 /* As default, it is OFDM rates */
287 int i = ATH11K_MAC_FIRST_OFDM_RATE_IDX;
288 int max_rates_idx = ath11k_g_rates_size;
290 if (preamble == WMI_RATE_PREAMBLE_CCK) {
291 hw_rc &= ~ATH11k_HW_RATECODE_CCK_SHORT_PREAM_MASK;
293 max_rates_idx = ATH11K_MAC_FIRST_OFDM_RATE_IDX;
296 while (i < max_rates_idx) {
297 if (hw_rc == ath11k_legacy_rates[i].hw_value) {
299 *rate = ath11k_legacy_rates[i].bitrate;
308 static int get_num_chains(u32 mask)
321 u8 ath11k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
326 for (i = 0; i < sband->n_bitrates; i++)
327 if (sband->bitrates[i].bitrate == bitrate)
334 ath11k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
338 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
339 if (ht_mcs_mask[nss])
346 ath11k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
350 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
351 if (vht_mcs_mask[nss])
357 static u8 ath11k_parse_mpdudensity(u8 mpdudensity)
359 /* 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
360 * 0 for no restriction
369 switch (mpdudensity) {
375 /* Our lower layer calculations limit our precision to
392 static int ath11k_mac_vif_chan(struct ieee80211_vif *vif,
393 struct cfg80211_chan_def *def)
395 struct ieee80211_chanctx_conf *conf;
398 conf = rcu_dereference(vif->chanctx_conf);
410 static bool ath11k_mac_bitrate_is_cck(int bitrate)
423 u8 ath11k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
424 u8 hw_rate, bool cck)
426 const struct ieee80211_rate *rate;
429 for (i = 0; i < sband->n_bitrates; i++) {
430 rate = &sband->bitrates[i];
432 if (ath11k_mac_bitrate_is_cck(rate->bitrate) != cck)
435 if (rate->hw_value == hw_rate)
437 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
438 rate->hw_value_short == hw_rate)
445 static u8 ath11k_mac_bitrate_to_rate(int bitrate)
447 return DIV_ROUND_UP(bitrate, 5) |
448 (ath11k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
451 static void ath11k_get_arvif_iter(void *data, u8 *mac,
452 struct ieee80211_vif *vif)
454 struct ath11k_vif_iter *arvif_iter = data;
455 struct ath11k_vif *arvif = (void *)vif->drv_priv;
457 if (arvif->vdev_id == arvif_iter->vdev_id)
458 arvif_iter->arvif = arvif;
461 struct ath11k_vif *ath11k_mac_get_arvif(struct ath11k *ar, u32 vdev_id)
463 struct ath11k_vif_iter arvif_iter;
466 memset(&arvif_iter, 0, sizeof(struct ath11k_vif_iter));
467 arvif_iter.vdev_id = vdev_id;
469 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
470 ieee80211_iterate_active_interfaces_atomic(ar->hw,
472 ath11k_get_arvif_iter,
474 if (!arvif_iter.arvif) {
475 ath11k_warn(ar->ab, "No VIF found for vdev %d\n", vdev_id);
479 return arvif_iter.arvif;
482 struct ath11k_vif *ath11k_mac_get_arvif_by_vdev_id(struct ath11k_base *ab,
486 struct ath11k_pdev *pdev;
487 struct ath11k_vif *arvif;
489 for (i = 0; i < ab->num_radios; i++) {
490 pdev = rcu_dereference(ab->pdevs_active[i]);
491 if (pdev && pdev->ar) {
492 arvif = ath11k_mac_get_arvif(pdev->ar, vdev_id);
501 struct ath11k *ath11k_mac_get_ar_by_vdev_id(struct ath11k_base *ab, u32 vdev_id)
504 struct ath11k_pdev *pdev;
506 for (i = 0; i < ab->num_radios; i++) {
507 pdev = rcu_dereference(ab->pdevs_active[i]);
508 if (pdev && pdev->ar) {
509 if (pdev->ar->allocated_vdev_map & (1LL << vdev_id))
517 struct ath11k *ath11k_mac_get_ar_by_pdev_id(struct ath11k_base *ab, u32 pdev_id)
520 struct ath11k_pdev *pdev;
522 if (ab->hw_params.single_pdev_only) {
523 pdev = rcu_dereference(ab->pdevs_active[0]);
524 return pdev ? pdev->ar : NULL;
527 if (WARN_ON(pdev_id > ab->num_radios))
530 for (i = 0; i < ab->num_radios; i++) {
531 pdev = rcu_dereference(ab->pdevs_active[i]);
533 if (pdev && pdev->pdev_id == pdev_id)
534 return (pdev->ar ? pdev->ar : NULL);
540 static void ath11k_pdev_caps_update(struct ath11k *ar)
542 struct ath11k_base *ab = ar->ab;
544 ar->max_tx_power = ab->target_caps.hw_max_tx_power;
546 /* FIXME Set min_tx_power to ab->target_caps.hw_min_tx_power.
547 * But since the received value in svcrdy is same as hw_max_tx_power,
548 * we can set ar->min_tx_power to 0 currently until
549 * this is fixed in firmware
551 ar->min_tx_power = 0;
553 ar->txpower_limit_2g = ar->max_tx_power;
554 ar->txpower_limit_5g = ar->max_tx_power;
555 ar->txpower_scale = WMI_HOST_TP_SCALE_MAX;
558 static int ath11k_mac_txpower_recalc(struct ath11k *ar)
560 struct ath11k_pdev *pdev = ar->pdev;
561 struct ath11k_vif *arvif;
562 int ret, txpower = -1;
565 lockdep_assert_held(&ar->conf_mutex);
567 list_for_each_entry(arvif, &ar->arvifs, list) {
568 if (arvif->txpower <= 0)
572 txpower = arvif->txpower;
574 txpower = min(txpower, arvif->txpower);
580 /* txpwr is set as 2 units per dBm in FW*/
581 txpower = min_t(u32, max_t(u32, ar->min_tx_power, txpower),
582 ar->max_tx_power) * 2;
584 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "txpower to set in hw %d\n",
587 if ((pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) &&
588 ar->txpower_limit_2g != txpower) {
589 param = WMI_PDEV_PARAM_TXPOWER_LIMIT2G;
590 ret = ath11k_wmi_pdev_set_param(ar, param,
591 txpower, ar->pdev->pdev_id);
594 ar->txpower_limit_2g = txpower;
597 if ((pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) &&
598 ar->txpower_limit_5g != txpower) {
599 param = WMI_PDEV_PARAM_TXPOWER_LIMIT5G;
600 ret = ath11k_wmi_pdev_set_param(ar, param,
601 txpower, ar->pdev->pdev_id);
604 ar->txpower_limit_5g = txpower;
610 ath11k_warn(ar->ab, "failed to recalc txpower limit %d using pdev param %d: %d\n",
611 txpower / 2, param, ret);
615 static int ath11k_recalc_rtscts_prot(struct ath11k_vif *arvif)
617 struct ath11k *ar = arvif->ar;
618 u32 vdev_param, rts_cts = 0;
621 lockdep_assert_held(&ar->conf_mutex);
623 vdev_param = WMI_VDEV_PARAM_ENABLE_RTSCTS;
625 /* Enable RTS/CTS protection for sw retries (when legacy stations
626 * are in BSS) or by default only for second rate series.
627 * TODO: Check if we need to enable CTS 2 Self in any case
629 rts_cts = WMI_USE_RTS_CTS;
631 if (arvif->num_legacy_stations > 0)
632 rts_cts |= WMI_RTSCTS_ACROSS_SW_RETRIES << 4;
634 rts_cts |= WMI_RTSCTS_FOR_SECOND_RATESERIES << 4;
636 /* Need not send duplicate param value to firmware */
637 if (arvif->rtscts_prot_mode == rts_cts)
640 arvif->rtscts_prot_mode = rts_cts;
642 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
643 arvif->vdev_id, rts_cts);
645 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
646 vdev_param, rts_cts);
648 ath11k_warn(ar->ab, "failed to recalculate rts/cts prot for vdev %d: %d\n",
649 arvif->vdev_id, ret);
654 static int ath11k_mac_set_kickout(struct ath11k_vif *arvif)
656 struct ath11k *ar = arvif->ar;
660 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_STA_KICKOUT_TH,
661 ATH11K_KICKOUT_THRESHOLD,
664 ath11k_warn(ar->ab, "failed to set kickout threshold on vdev %i: %d\n",
665 arvif->vdev_id, ret);
669 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS;
670 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
671 ATH11K_KEEPALIVE_MIN_IDLE);
673 ath11k_warn(ar->ab, "failed to set keepalive minimum idle time on vdev %i: %d\n",
674 arvif->vdev_id, ret);
678 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS;
679 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
680 ATH11K_KEEPALIVE_MAX_IDLE);
682 ath11k_warn(ar->ab, "failed to set keepalive maximum idle time on vdev %i: %d\n",
683 arvif->vdev_id, ret);
687 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS;
688 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
689 ATH11K_KEEPALIVE_MAX_UNRESPONSIVE);
691 ath11k_warn(ar->ab, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
692 arvif->vdev_id, ret);
699 void ath11k_mac_peer_cleanup_all(struct ath11k *ar)
701 struct ath11k_peer *peer, *tmp;
702 struct ath11k_base *ab = ar->ab;
704 lockdep_assert_held(&ar->conf_mutex);
706 spin_lock_bh(&ab->base_lock);
707 list_for_each_entry_safe(peer, tmp, &ab->peers, list) {
708 ath11k_peer_rx_tid_cleanup(ar, peer);
709 list_del(&peer->list);
712 spin_unlock_bh(&ab->base_lock);
715 ar->num_stations = 0;
718 static int ath11k_monitor_vdev_up(struct ath11k *ar, int vdev_id)
722 ret = ath11k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
724 ath11k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n",
729 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor vdev %i started\n",
734 static int ath11k_mac_op_config(struct ieee80211_hw *hw, u32 changed)
736 /* mac80211 requires this op to be present and that's why
737 * there's an empty function, this can be extended when
744 static int ath11k_mac_setup_bcn_tmpl(struct ath11k_vif *arvif)
746 struct ath11k *ar = arvif->ar;
747 struct ath11k_base *ab = ar->ab;
748 struct ieee80211_hw *hw = ar->hw;
749 struct ieee80211_vif *vif = arvif->vif;
750 struct ieee80211_mutable_offsets offs = {};
752 struct ieee80211_mgmt *mgmt;
756 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
759 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
761 ath11k_warn(ab, "failed to get beacon template from mac80211\n");
765 ies = bcn->data + ieee80211_get_hdrlen_from_skb(bcn);
766 ies += sizeof(mgmt->u.beacon);
768 if (cfg80211_find_ie(WLAN_EID_RSN, ies, (skb_tail_pointer(bcn) - ies)))
769 arvif->rsnie_present = true;
771 if (cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
772 WLAN_OUI_TYPE_MICROSOFT_WPA,
773 ies, (skb_tail_pointer(bcn) - ies)))
774 arvif->wpaie_present = true;
776 ret = ath11k_wmi_bcn_tmpl(ar, arvif->vdev_id, &offs, bcn);
781 ath11k_warn(ab, "failed to submit beacon template command: %d\n",
787 static void ath11k_control_beaconing(struct ath11k_vif *arvif,
788 struct ieee80211_bss_conf *info)
790 struct ath11k *ar = arvif->ar;
793 lockdep_assert_held(&arvif->ar->conf_mutex);
795 if (!info->enable_beacon) {
796 ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id);
798 ath11k_warn(ar->ab, "failed to down vdev_id %i: %d\n",
799 arvif->vdev_id, ret);
801 arvif->is_up = false;
805 /* Install the beacon template to the FW */
806 ret = ath11k_mac_setup_bcn_tmpl(arvif);
808 ath11k_warn(ar->ab, "failed to update bcn tmpl during vdev up: %d\n",
813 arvif->tx_seq_no = 0x1000;
817 ether_addr_copy(arvif->bssid, info->bssid);
819 ret = ath11k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
822 ath11k_warn(ar->ab, "failed to bring up vdev %d: %i\n",
823 arvif->vdev_id, ret);
829 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
832 static void ath11k_mac_handle_beacon_iter(void *data, u8 *mac,
833 struct ieee80211_vif *vif)
835 struct sk_buff *skb = data;
836 struct ieee80211_mgmt *mgmt = (void *)skb->data;
837 struct ath11k_vif *arvif = (void *)vif->drv_priv;
839 if (vif->type != NL80211_IFTYPE_STATION)
842 if (!ether_addr_equal(mgmt->bssid, vif->bss_conf.bssid))
845 cancel_delayed_work(&arvif->connection_loss_work);
848 void ath11k_mac_handle_beacon(struct ath11k *ar, struct sk_buff *skb)
850 ieee80211_iterate_active_interfaces_atomic(ar->hw,
851 IEEE80211_IFACE_ITER_NORMAL,
852 ath11k_mac_handle_beacon_iter,
856 static void ath11k_mac_handle_beacon_miss_iter(void *data, u8 *mac,
857 struct ieee80211_vif *vif)
860 struct ath11k_vif *arvif = (void *)vif->drv_priv;
861 struct ath11k *ar = arvif->ar;
862 struct ieee80211_hw *hw = ar->hw;
864 if (arvif->vdev_id != *vdev_id)
870 ieee80211_beacon_loss(vif);
872 /* Firmware doesn't report beacon loss events repeatedly. If AP probe
873 * (done by mac80211) succeeds but beacons do not resume then it
874 * doesn't make sense to continue operation. Queue connection loss work
875 * which can be cancelled when beacon is received.
877 ieee80211_queue_delayed_work(hw, &arvif->connection_loss_work,
878 ATH11K_CONNECTION_LOSS_HZ);
881 void ath11k_mac_handle_beacon_miss(struct ath11k *ar, u32 vdev_id)
883 ieee80211_iterate_active_interfaces_atomic(ar->hw,
884 IEEE80211_IFACE_ITER_NORMAL,
885 ath11k_mac_handle_beacon_miss_iter,
889 static void ath11k_mac_vif_sta_connection_loss_work(struct work_struct *work)
891 struct ath11k_vif *arvif = container_of(work, struct ath11k_vif,
892 connection_loss_work.work);
893 struct ieee80211_vif *vif = arvif->vif;
898 ieee80211_connection_loss(vif);
901 static void ath11k_peer_assoc_h_basic(struct ath11k *ar,
902 struct ieee80211_vif *vif,
903 struct ieee80211_sta *sta,
904 struct peer_assoc_params *arg)
906 struct ath11k_vif *arvif = (void *)vif->drv_priv;
909 lockdep_assert_held(&ar->conf_mutex);
911 if (vif->type == NL80211_IFTYPE_STATION)
912 aid = vif->bss_conf.aid;
916 ether_addr_copy(arg->peer_mac, sta->addr);
917 arg->vdev_id = arvif->vdev_id;
918 arg->peer_associd = aid;
919 arg->auth_flag = true;
920 /* TODO: STA WAR in ath10k for listen interval required? */
921 arg->peer_listen_intval = ar->hw->conf.listen_interval;
923 arg->peer_caps = vif->bss_conf.assoc_capability;
926 static void ath11k_peer_assoc_h_crypto(struct ath11k *ar,
927 struct ieee80211_vif *vif,
928 struct ieee80211_sta *sta,
929 struct peer_assoc_params *arg)
931 struct ieee80211_bss_conf *info = &vif->bss_conf;
932 struct cfg80211_chan_def def;
933 struct cfg80211_bss *bss;
934 struct ath11k_vif *arvif = (struct ath11k_vif *)vif->drv_priv;
935 const u8 *rsnie = NULL;
936 const u8 *wpaie = NULL;
938 lockdep_assert_held(&ar->conf_mutex);
940 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
943 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
944 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
946 if (arvif->rsnie_present || arvif->wpaie_present) {
947 arg->need_ptk_4_way = true;
948 if (arvif->wpaie_present)
949 arg->need_gtk_2_way = true;
951 const struct cfg80211_bss_ies *ies;
954 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
956 ies = rcu_dereference(bss->ies);
958 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
959 WLAN_OUI_TYPE_MICROSOFT_WPA,
963 cfg80211_put_bss(ar->hw->wiphy, bss);
966 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
967 if (rsnie || wpaie) {
968 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
969 "%s: rsn ie found\n", __func__);
970 arg->need_ptk_4_way = true;
974 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
975 "%s: wpa ie found\n", __func__);
976 arg->need_gtk_2_way = true;
980 /* TODO: Need to check if FW supports PMF? */
981 arg->is_pmf_enabled = true;
984 /* TODO: safe_mode_enabled (bypass 4-way handshake) flag req? */
987 static void ath11k_peer_assoc_h_rates(struct ath11k *ar,
988 struct ieee80211_vif *vif,
989 struct ieee80211_sta *sta,
990 struct peer_assoc_params *arg)
992 struct ath11k_vif *arvif = (void *)vif->drv_priv;
993 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
994 struct cfg80211_chan_def def;
995 const struct ieee80211_supported_band *sband;
996 const struct ieee80211_rate *rates;
997 enum nl80211_band band;
1002 lockdep_assert_held(&ar->conf_mutex);
1004 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1007 band = def.chan->band;
1008 sband = ar->hw->wiphy->bands[band];
1009 ratemask = sta->supp_rates[band];
1010 ratemask &= arvif->bitrate_mask.control[band].legacy;
1011 rates = sband->bitrates;
1013 rateset->num_rates = 0;
1015 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
1016 if (!(ratemask & 1))
1019 rate = ath11k_mac_bitrate_to_rate(rates->bitrate);
1020 rateset->rates[rateset->num_rates] = rate;
1021 rateset->num_rates++;
1026 ath11k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
1030 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
1031 if (ht_mcs_mask[nss])
1038 ath11k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
1042 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
1043 if (vht_mcs_mask[nss])
1049 static void ath11k_peer_assoc_h_ht(struct ath11k *ar,
1050 struct ieee80211_vif *vif,
1051 struct ieee80211_sta *sta,
1052 struct peer_assoc_params *arg)
1054 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1055 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1056 struct cfg80211_chan_def def;
1057 enum nl80211_band band;
1058 const u8 *ht_mcs_mask;
1063 lockdep_assert_held(&ar->conf_mutex);
1065 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1068 if (!ht_cap->ht_supported)
1071 band = def.chan->band;
1072 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
1074 if (ath11k_peer_assoc_h_ht_masked(ht_mcs_mask))
1077 arg->ht_flag = true;
1079 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1080 ht_cap->ampdu_factor)) - 1;
1082 arg->peer_mpdu_density =
1083 ath11k_parse_mpdudensity(ht_cap->ampdu_density);
1085 arg->peer_ht_caps = ht_cap->cap;
1086 arg->peer_rate_caps |= WMI_HOST_RC_HT_FLAG;
1088 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1089 arg->ldpc_flag = true;
1091 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1093 arg->peer_rate_caps |= WMI_HOST_RC_CW40_FLAG;
1096 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
1097 if (ht_cap->cap & (IEEE80211_HT_CAP_SGI_20 |
1098 IEEE80211_HT_CAP_SGI_40))
1099 arg->peer_rate_caps |= WMI_HOST_RC_SGI_FLAG;
1102 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1103 arg->peer_rate_caps |= WMI_HOST_RC_TX_STBC_FLAG;
1104 arg->stbc_flag = true;
1107 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1108 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1109 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1110 stbc = stbc << WMI_HOST_RC_RX_STBC_FLAG_S;
1111 arg->peer_rate_caps |= stbc;
1112 arg->stbc_flag = true;
1115 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1116 arg->peer_rate_caps |= WMI_HOST_RC_TS_FLAG;
1117 else if (ht_cap->mcs.rx_mask[1])
1118 arg->peer_rate_caps |= WMI_HOST_RC_DS_FLAG;
1120 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
1121 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
1122 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
1123 max_nss = (i / 8) + 1;
1124 arg->peer_ht_rates.rates[n++] = i;
1127 /* This is a workaround for HT-enabled STAs which break the spec
1128 * and have no HT capabilities RX mask (no HT RX MCS map).
1130 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1131 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1133 * Firmware asserts if such situation occurs.
1136 arg->peer_ht_rates.num_rates = 8;
1137 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1138 arg->peer_ht_rates.rates[i] = i;
1140 arg->peer_ht_rates.num_rates = n;
1141 arg->peer_nss = min(sta->rx_nss, max_nss);
1144 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1146 arg->peer_ht_rates.num_rates,
1150 static int ath11k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
1152 switch ((mcs_map >> (2 * nss)) & 0x3) {
1153 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
1154 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
1155 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
1161 ath11k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
1162 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
1169 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
1170 mcs_map = ath11k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
1174 idx_limit = fls(mcs_map) - 1;
1178 switch (idx_limit) {
1187 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
1190 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
1193 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
1199 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
1203 tx_mcs_set &= ~(0x3 << (nss * 2));
1204 tx_mcs_set |= mcs << (nss * 2);
1210 static void ath11k_peer_assoc_h_vht(struct ath11k *ar,
1211 struct ieee80211_vif *vif,
1212 struct ieee80211_sta *sta,
1213 struct peer_assoc_params *arg)
1215 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1216 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1217 struct cfg80211_chan_def def;
1218 enum nl80211_band band;
1219 const u16 *vht_mcs_mask;
1221 u8 max_nss, vht_mcs;
1224 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1227 if (!vht_cap->vht_supported)
1230 band = def.chan->band;
1231 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
1233 if (ath11k_peer_assoc_h_vht_masked(vht_mcs_mask))
1236 arg->vht_flag = true;
1238 /* TODO: similar flags required? */
1239 arg->vht_capable = true;
1241 if (def.chan->band == NL80211_BAND_2GHZ)
1242 arg->vht_ng_flag = true;
1244 arg->peer_vht_caps = vht_cap->cap;
1246 ampdu_factor = (vht_cap->cap &
1247 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1248 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1250 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1251 * zero in VHT IE. Using it would result in degraded throughput.
1252 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1253 * it if VHT max_mpdu is smaller.
1255 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1256 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1257 ampdu_factor)) - 1);
1259 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1262 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
1265 /* Calculate peer NSS capability from VHT capabilities if STA
1268 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
1269 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
1272 if (vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED &&
1276 arg->peer_nss = min(sta->rx_nss, max_nss);
1277 arg->rx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1278 arg->rx_mcs_set = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1279 arg->tx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1280 arg->tx_mcs_set = ath11k_peer_assoc_h_vht_limit(
1281 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
1283 /* In IPQ8074 platform, VHT mcs rate 10 and 11 is enabled by default.
1284 * VHT mcs rate 10 and 11 is not suppoerted in 11ac standard.
1285 * so explicitly disable the VHT MCS rate 10 and 11 in 11ac mode.
1287 arg->tx_mcs_set &= ~IEEE80211_VHT_MCS_SUPPORT_0_11_MASK;
1288 arg->tx_mcs_set |= IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11;
1290 if ((arg->tx_mcs_set & IEEE80211_VHT_MCS_NOT_SUPPORTED) ==
1291 IEEE80211_VHT_MCS_NOT_SUPPORTED)
1292 arg->peer_vht_caps &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1295 arg->tx_max_mcs_nss = 0xFF;
1297 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1298 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1300 /* TODO: rxnss_override */
1303 static void ath11k_peer_assoc_h_he(struct ath11k *ar,
1304 struct ieee80211_vif *vif,
1305 struct ieee80211_sta *sta,
1306 struct peer_assoc_params *arg)
1308 const struct ieee80211_sta_he_cap *he_cap = &sta->he_cap;
1312 if (!he_cap->has_he)
1315 arg->he_flag = true;
1317 memcpy(&arg->peer_he_cap_macinfo, he_cap->he_cap_elem.mac_cap_info,
1318 sizeof(arg->peer_he_cap_macinfo));
1319 memcpy(&arg->peer_he_cap_phyinfo, he_cap->he_cap_elem.phy_cap_info,
1320 sizeof(arg->peer_he_cap_phyinfo));
1321 arg->peer_he_ops = vif->bss_conf.he_oper.params;
1323 /* the top most byte is used to indicate BSS color info */
1324 arg->peer_he_ops &= 0xffffff;
1326 /* As per section 26.6.1 11ax Draft5.0, if the Max AMPDU Exponent Extension
1327 * in HE cap is zero, use the arg->peer_max_mpdu as calculated while parsing
1328 * VHT caps(if VHT caps is present) or HT caps (if VHT caps is not present).
1330 * For non-zero value of Max AMPDU Extponent Extension in HE MAC caps,
1331 * if a HE STA sends VHT cap and HE cap IE in assoc request then, use
1332 * MAX_AMPDU_LEN_FACTOR as 20 to calculate max_ampdu length.
1333 * If a HE STA that does not send VHT cap, but HE and HT cap in assoc
1334 * request, then use MAX_AMPDU_LEN_FACTOR as 16 to calculate max_ampdu
1337 ampdu_factor = u8_get_bits(he_cap->he_cap_elem.mac_cap_info[3],
1338 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK);
1341 if (sta->vht_cap.vht_supported)
1342 arg->peer_max_mpdu = (1 << (IEEE80211_HE_VHT_MAX_AMPDU_FACTOR +
1344 else if (sta->ht_cap.ht_supported)
1345 arg->peer_max_mpdu = (1 << (IEEE80211_HE_HT_MAX_AMPDU_FACTOR +
1349 if (he_cap->he_cap_elem.phy_cap_info[6] &
1350 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
1354 arg->peer_ppet.numss_m1 = he_cap->ppe_thres[0] &
1355 IEEE80211_PPE_THRES_NSS_MASK;
1356 arg->peer_ppet.ru_bit_mask =
1357 (he_cap->ppe_thres[0] &
1358 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
1359 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
1361 for (nss = 0; nss <= arg->peer_ppet.numss_m1; nss++) {
1362 for (ru = 0; ru < 4; ru++) {
1366 if ((arg->peer_ppet.ru_bit_mask & BIT(ru)) == 0)
1368 for (i = 0; i < 6; i++) {
1370 val |= ((he_cap->ppe_thres[bit / 8] >>
1371 (bit % 8)) & 0x1) << 5;
1374 arg->peer_ppet.ppet16_ppet8_ru3_ru0[nss] |=
1380 if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_RES)
1381 arg->twt_responder = true;
1382 if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_REQ)
1383 arg->twt_requester = true;
1385 switch (sta->bandwidth) {
1386 case IEEE80211_STA_RX_BW_160:
1387 if (he_cap->he_cap_elem.phy_cap_info[0] &
1388 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) {
1389 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80p80);
1390 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v;
1392 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80p80);
1393 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v;
1395 arg->peer_he_mcs_count++;
1397 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160);
1398 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v;
1400 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_160);
1401 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v;
1403 arg->peer_he_mcs_count++;
1407 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80);
1408 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v;
1410 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80);
1411 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v;
1413 arg->peer_he_mcs_count++;
1418 static void ath11k_peer_assoc_h_smps(struct ieee80211_sta *sta,
1419 struct peer_assoc_params *arg)
1421 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1424 if (!ht_cap->ht_supported)
1427 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1428 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1431 case WLAN_HT_CAP_SM_PS_STATIC:
1432 arg->static_mimops_flag = true;
1434 case WLAN_HT_CAP_SM_PS_DYNAMIC:
1435 arg->dynamic_mimops_flag = true;
1437 case WLAN_HT_CAP_SM_PS_DISABLED:
1438 arg->spatial_mux_flag = true;
1445 static void ath11k_peer_assoc_h_qos(struct ath11k *ar,
1446 struct ieee80211_vif *vif,
1447 struct ieee80211_sta *sta,
1448 struct peer_assoc_params *arg)
1450 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1452 switch (arvif->vdev_type) {
1453 case WMI_VDEV_TYPE_AP:
1455 /* TODO: Check WME vs QoS */
1456 arg->is_wme_set = true;
1457 arg->qos_flag = true;
1460 if (sta->wme && sta->uapsd_queues) {
1461 /* TODO: Check WME vs QoS */
1462 arg->is_wme_set = true;
1463 arg->apsd_flag = true;
1464 arg->peer_rate_caps |= WMI_HOST_RC_UAPSD_FLAG;
1467 case WMI_VDEV_TYPE_STA:
1469 arg->is_wme_set = true;
1470 arg->qos_flag = true;
1477 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac peer %pM qos %d\n",
1478 sta->addr, arg->qos_flag);
1481 static int ath11k_peer_assoc_qos_ap(struct ath11k *ar,
1482 struct ath11k_vif *arvif,
1483 struct ieee80211_sta *sta)
1485 struct ap_ps_params params;
1490 lockdep_assert_held(&ar->conf_mutex);
1492 params.vdev_id = arvif->vdev_id;
1494 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1495 sta->uapsd_queues, sta->max_sp);
1498 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1499 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1500 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1501 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1502 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1503 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1504 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1505 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1506 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1507 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1508 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1509 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1512 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1513 max_sp = sta->max_sp;
1515 params.param = WMI_AP_PS_PEER_PARAM_UAPSD;
1516 params.value = uapsd;
1517 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
1521 params.param = WMI_AP_PS_PEER_PARAM_MAX_SP;
1522 params.value = max_sp;
1523 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
1527 /* TODO revisit during testing */
1528 params.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_FRMTYPE;
1529 params.value = DISABLE_SIFS_RESPONSE_TRIGGER;
1530 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
1534 params.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_UAPSD;
1535 params.value = DISABLE_SIFS_RESPONSE_TRIGGER;
1536 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
1543 ath11k_warn(ar->ab, "failed to set ap ps peer param %d for vdev %i: %d\n",
1544 params.param, arvif->vdev_id, ret);
1548 static bool ath11k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
1550 return sta->supp_rates[NL80211_BAND_2GHZ] >>
1551 ATH11K_MAC_FIRST_OFDM_RATE_IDX;
1554 static enum wmi_phy_mode ath11k_mac_get_phymode_vht(struct ath11k *ar,
1555 struct ieee80211_sta *sta)
1557 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
1558 switch (sta->vht_cap.cap &
1559 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
1560 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
1561 return MODE_11AC_VHT160;
1562 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
1563 return MODE_11AC_VHT80_80;
1565 /* not sure if this is a valid case? */
1566 return MODE_11AC_VHT160;
1570 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1571 return MODE_11AC_VHT80;
1573 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1574 return MODE_11AC_VHT40;
1576 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1577 return MODE_11AC_VHT20;
1579 return MODE_UNKNOWN;
1582 static enum wmi_phy_mode ath11k_mac_get_phymode_he(struct ath11k *ar,
1583 struct ieee80211_sta *sta)
1585 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
1586 if (sta->he_cap.he_cap_elem.phy_cap_info[0] &
1587 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
1588 return MODE_11AX_HE160;
1589 else if (sta->he_cap.he_cap_elem.phy_cap_info[0] &
1590 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)
1591 return MODE_11AX_HE80_80;
1592 /* not sure if this is a valid case? */
1593 return MODE_11AX_HE160;
1596 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1597 return MODE_11AX_HE80;
1599 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1600 return MODE_11AX_HE40;
1602 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1603 return MODE_11AX_HE20;
1605 return MODE_UNKNOWN;
1608 static void ath11k_peer_assoc_h_phymode(struct ath11k *ar,
1609 struct ieee80211_vif *vif,
1610 struct ieee80211_sta *sta,
1611 struct peer_assoc_params *arg)
1613 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1614 struct cfg80211_chan_def def;
1615 enum nl80211_band band;
1616 const u8 *ht_mcs_mask;
1617 const u16 *vht_mcs_mask;
1618 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1620 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1623 band = def.chan->band;
1624 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
1625 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
1628 case NL80211_BAND_2GHZ:
1629 if (sta->he_cap.has_he) {
1630 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1631 phymode = MODE_11AX_HE80_2G;
1632 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1633 phymode = MODE_11AX_HE40_2G;
1635 phymode = MODE_11AX_HE20_2G;
1636 } else if (sta->vht_cap.vht_supported &&
1637 !ath11k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
1638 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1639 phymode = MODE_11AC_VHT40;
1641 phymode = MODE_11AC_VHT20;
1642 } else if (sta->ht_cap.ht_supported &&
1643 !ath11k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
1644 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1645 phymode = MODE_11NG_HT40;
1647 phymode = MODE_11NG_HT20;
1648 } else if (ath11k_mac_sta_has_ofdm_only(sta)) {
1654 case NL80211_BAND_5GHZ:
1655 case NL80211_BAND_6GHZ:
1656 /* Check HE first */
1657 if (sta->he_cap.has_he) {
1658 phymode = ath11k_mac_get_phymode_he(ar, sta);
1659 } else if (sta->vht_cap.vht_supported &&
1660 !ath11k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
1661 phymode = ath11k_mac_get_phymode_vht(ar, sta);
1662 } else if (sta->ht_cap.ht_supported &&
1663 !ath11k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
1664 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
1665 phymode = MODE_11NA_HT40;
1667 phymode = MODE_11NA_HT20;
1676 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac peer %pM phymode %s\n",
1677 sta->addr, ath11k_wmi_phymode_str(phymode));
1679 arg->peer_phymode = phymode;
1680 WARN_ON(phymode == MODE_UNKNOWN);
1683 static void ath11k_peer_assoc_prepare(struct ath11k *ar,
1684 struct ieee80211_vif *vif,
1685 struct ieee80211_sta *sta,
1686 struct peer_assoc_params *arg,
1689 lockdep_assert_held(&ar->conf_mutex);
1691 memset(arg, 0, sizeof(*arg));
1693 reinit_completion(&ar->peer_assoc_done);
1695 arg->peer_new_assoc = !reassoc;
1696 ath11k_peer_assoc_h_basic(ar, vif, sta, arg);
1697 ath11k_peer_assoc_h_crypto(ar, vif, sta, arg);
1698 ath11k_peer_assoc_h_rates(ar, vif, sta, arg);
1699 ath11k_peer_assoc_h_ht(ar, vif, sta, arg);
1700 ath11k_peer_assoc_h_vht(ar, vif, sta, arg);
1701 ath11k_peer_assoc_h_he(ar, vif, sta, arg);
1702 ath11k_peer_assoc_h_qos(ar, vif, sta, arg);
1703 ath11k_peer_assoc_h_phymode(ar, vif, sta, arg);
1704 ath11k_peer_assoc_h_smps(sta, arg);
1706 /* TODO: amsdu_disable req? */
1709 static int ath11k_setup_peer_smps(struct ath11k *ar, struct ath11k_vif *arvif,
1711 const struct ieee80211_sta_ht_cap *ht_cap)
1715 if (!ht_cap->ht_supported)
1718 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1719 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1721 if (smps >= ARRAY_SIZE(ath11k_smps_map))
1724 return ath11k_wmi_set_peer_param(ar, addr, arvif->vdev_id,
1725 WMI_PEER_MIMO_PS_STATE,
1726 ath11k_smps_map[smps]);
1729 static void ath11k_bss_assoc(struct ieee80211_hw *hw,
1730 struct ieee80211_vif *vif,
1731 struct ieee80211_bss_conf *bss_conf)
1733 struct ath11k *ar = hw->priv;
1734 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1735 struct peer_assoc_params peer_arg;
1736 struct ieee80211_sta *ap_sta;
1739 lockdep_assert_held(&ar->conf_mutex);
1741 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1742 arvif->vdev_id, arvif->bssid, arvif->aid);
1746 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1748 ath11k_warn(ar->ab, "failed to find station entry for bss %pM vdev %i\n",
1749 bss_conf->bssid, arvif->vdev_id);
1754 ath11k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg, false);
1758 ret = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
1760 ath11k_warn(ar->ab, "failed to run peer assoc for %pM vdev %i: %d\n",
1761 bss_conf->bssid, arvif->vdev_id, ret);
1765 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
1766 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
1767 bss_conf->bssid, arvif->vdev_id);
1771 ret = ath11k_setup_peer_smps(ar, arvif, bss_conf->bssid,
1774 ath11k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n",
1775 arvif->vdev_id, ret);
1779 WARN_ON(arvif->is_up);
1781 arvif->aid = bss_conf->aid;
1782 ether_addr_copy(arvif->bssid, bss_conf->bssid);
1784 ret = ath11k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1786 ath11k_warn(ar->ab, "failed to set vdev %d up: %d\n",
1787 arvif->vdev_id, ret);
1791 arvif->is_up = true;
1793 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1794 "mac vdev %d up (associated) bssid %pM aid %d\n",
1795 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1797 /* Authorize BSS Peer */
1798 ret = ath11k_wmi_set_peer_param(ar, arvif->bssid,
1803 ath11k_warn(ar->ab, "Unable to authorize BSS peer: %d\n", ret);
1805 ret = ath11k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id,
1806 &bss_conf->he_obss_pd);
1808 ath11k_warn(ar->ab, "failed to set vdev %i OBSS PD parameters: %d\n",
1809 arvif->vdev_id, ret);
1812 static void ath11k_bss_disassoc(struct ieee80211_hw *hw,
1813 struct ieee80211_vif *vif)
1815 struct ath11k *ar = hw->priv;
1816 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1819 lockdep_assert_held(&ar->conf_mutex);
1821 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1822 arvif->vdev_id, arvif->bssid);
1824 ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id);
1826 ath11k_warn(ar->ab, "failed to down vdev %i: %d\n",
1827 arvif->vdev_id, ret);
1829 arvif->is_up = false;
1831 cancel_delayed_work_sync(&arvif->connection_loss_work);
1834 static u32 ath11k_mac_get_rate_hw_value(int bitrate)
1841 if (ath11k_mac_bitrate_is_cck(bitrate))
1842 preamble = WMI_RATE_PREAMBLE_CCK;
1844 preamble = WMI_RATE_PREAMBLE_OFDM;
1846 for (i = 0; i < ARRAY_SIZE(ath11k_legacy_rates); i++) {
1847 if (ath11k_legacy_rates[i].bitrate != bitrate)
1850 hw_value = ath11k_legacy_rates[i].hw_value;
1851 rate = ATH11K_HW_RATE_CODE(hw_value, 0, preamble);
1859 static void ath11k_recalculate_mgmt_rate(struct ath11k *ar,
1860 struct ieee80211_vif *vif,
1861 struct cfg80211_chan_def *def)
1863 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1864 const struct ieee80211_supported_band *sband;
1871 lockdep_assert_held(&ar->conf_mutex);
1873 sband = ar->hw->wiphy->bands[def->chan->band];
1874 basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
1875 bitrate = sband->bitrates[basic_rate_idx].bitrate;
1877 hw_rate_code = ath11k_mac_get_rate_hw_value(bitrate);
1878 if (hw_rate_code < 0) {
1879 ath11k_warn(ar->ab, "bitrate not supported %d\n", bitrate);
1883 vdev_param = WMI_VDEV_PARAM_MGMT_RATE;
1884 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
1887 ath11k_warn(ar->ab, "failed to set mgmt tx rate %d\n", ret);
1889 vdev_param = WMI_VDEV_PARAM_BEACON_RATE;
1890 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
1893 ath11k_warn(ar->ab, "failed to set beacon tx rate %d\n", ret);
1896 static int ath11k_mac_fils_discovery(struct ath11k_vif *arvif,
1897 struct ieee80211_bss_conf *info)
1899 struct ath11k *ar = arvif->ar;
1900 struct sk_buff *tmpl;
1903 bool unsol_bcast_probe_resp_enabled = false;
1905 if (info->fils_discovery.max_interval) {
1906 interval = info->fils_discovery.max_interval;
1908 tmpl = ieee80211_get_fils_discovery_tmpl(ar->hw, arvif->vif);
1910 ret = ath11k_wmi_fils_discovery_tmpl(ar, arvif->vdev_id,
1912 } else if (info->unsol_bcast_probe_resp_interval) {
1913 unsol_bcast_probe_resp_enabled = 1;
1914 interval = info->unsol_bcast_probe_resp_interval;
1916 tmpl = ieee80211_get_unsol_bcast_probe_resp_tmpl(ar->hw,
1919 ret = ath11k_wmi_probe_resp_tmpl(ar, arvif->vdev_id,
1921 } else { /* Disable */
1922 return ath11k_wmi_fils_discovery(ar, arvif->vdev_id, 0, false);
1927 "mac vdev %i failed to retrieve %s template\n",
1928 arvif->vdev_id, (unsol_bcast_probe_resp_enabled ?
1929 "unsolicited broadcast probe response" :
1936 ret = ath11k_wmi_fils_discovery(ar, arvif->vdev_id, interval,
1937 unsol_bcast_probe_resp_enabled);
1942 static int ath11k_mac_config_obss_pd(struct ath11k *ar,
1943 struct ieee80211_he_obss_pd *he_obss_pd)
1945 u32 bitmap[2], param_id, param_val, pdev_id;
1947 s8 non_srg_th = 0, srg_th = 0;
1949 pdev_id = ar->pdev->pdev_id;
1951 /* Set and enable SRG/non-SRG OBSS PD Threshold */
1952 param_id = WMI_PDEV_PARAM_SET_CMD_OBSS_PD_THRESHOLD;
1953 if (test_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags)) {
1954 ret = ath11k_wmi_pdev_set_param(ar, param_id, 0, pdev_id);
1957 "failed to set obss_pd_threshold for pdev: %u\n",
1962 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1963 "mac obss pd sr_ctrl %x non_srg_thres %u srg_max %u\n",
1964 he_obss_pd->sr_ctrl, he_obss_pd->non_srg_max_offset,
1965 he_obss_pd->max_offset);
1969 if (he_obss_pd->sr_ctrl &
1970 IEEE80211_HE_SPR_NON_SRG_OBSS_PD_SR_DISALLOWED) {
1971 non_srg_th = ATH11K_OBSS_PD_MAX_THRESHOLD;
1973 if (he_obss_pd->sr_ctrl & IEEE80211_HE_SPR_NON_SRG_OFFSET_PRESENT)
1974 non_srg_th = (ATH11K_OBSS_PD_MAX_THRESHOLD +
1975 he_obss_pd->non_srg_max_offset);
1977 non_srg_th = ATH11K_OBSS_PD_NON_SRG_MAX_THRESHOLD;
1979 param_val |= ATH11K_OBSS_PD_NON_SRG_EN;
1982 if (he_obss_pd->sr_ctrl & IEEE80211_HE_SPR_SRG_INFORMATION_PRESENT) {
1983 srg_th = ATH11K_OBSS_PD_MAX_THRESHOLD + he_obss_pd->max_offset;
1984 param_val |= ATH11K_OBSS_PD_SRG_EN;
1987 if (test_bit(WMI_TLV_SERVICE_SRG_SRP_SPATIAL_REUSE_SUPPORT,
1988 ar->ab->wmi_ab.svc_map)) {
1989 param_val |= ATH11K_OBSS_PD_THRESHOLD_IN_DBM;
1990 param_val |= FIELD_PREP(GENMASK(15, 8), srg_th);
1992 non_srg_th -= ATH11K_DEFAULT_NOISE_FLOOR;
1993 /* SRG not supported and threshold in dB */
1994 param_val &= ~(ATH11K_OBSS_PD_SRG_EN |
1995 ATH11K_OBSS_PD_THRESHOLD_IN_DBM);
1998 param_val |= (non_srg_th & GENMASK(7, 0));
1999 ret = ath11k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id);
2002 "failed to set obss_pd_threshold for pdev: %u\n",
2007 /* Enable OBSS PD for all access category */
2008 param_id = WMI_PDEV_PARAM_SET_CMD_OBSS_PD_PER_AC;
2010 ret = ath11k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id);
2013 "failed to set obss_pd_per_ac for pdev: %u\n",
2018 /* Set SR Prohibit */
2019 param_id = WMI_PDEV_PARAM_ENABLE_SR_PROHIBIT;
2020 param_val = !!(he_obss_pd->sr_ctrl &
2021 IEEE80211_HE_SPR_HESIGA_SR_VAL15_ALLOWED);
2022 ret = ath11k_wmi_pdev_set_param(ar, param_id, param_val, pdev_id);
2024 ath11k_warn(ar->ab, "failed to set sr_prohibit for pdev: %u\n",
2029 if (!test_bit(WMI_TLV_SERVICE_SRG_SRP_SPATIAL_REUSE_SUPPORT,
2030 ar->ab->wmi_ab.svc_map))
2033 /* Set SRG BSS Color Bitmap */
2034 memcpy(bitmap, he_obss_pd->bss_color_bitmap, sizeof(bitmap));
2035 ret = ath11k_wmi_pdev_set_srg_bss_color_bitmap(ar, bitmap);
2038 "failed to set bss_color_bitmap for pdev: %u\n",
2043 /* Set SRG Partial BSSID Bitmap */
2044 memcpy(bitmap, he_obss_pd->partial_bssid_bitmap, sizeof(bitmap));
2045 ret = ath11k_wmi_pdev_set_srg_patial_bssid_bitmap(ar, bitmap);
2048 "failed to set partial_bssid_bitmap for pdev: %u\n",
2053 memset(bitmap, 0xff, sizeof(bitmap));
2055 /* Enable all BSS Colors for SRG */
2056 ret = ath11k_wmi_pdev_srg_obss_color_enable_bitmap(ar, bitmap);
2059 "failed to set srg_color_en_bitmap pdev: %u\n",
2064 /* Enable all patial BSSID mask for SRG */
2065 ret = ath11k_wmi_pdev_srg_obss_bssid_enable_bitmap(ar, bitmap);
2068 "failed to set srg_bssid_en_bitmap pdev: %u\n",
2073 /* Enable all BSS Colors for non-SRG */
2074 ret = ath11k_wmi_pdev_non_srg_obss_color_enable_bitmap(ar, bitmap);
2077 "failed to set non_srg_color_en_bitmap pdev: %u\n",
2082 /* Enable all patial BSSID mask for non-SRG */
2083 ret = ath11k_wmi_pdev_non_srg_obss_bssid_enable_bitmap(ar, bitmap);
2086 "failed to set non_srg_bssid_en_bitmap pdev: %u\n",
2094 static void ath11k_mac_op_bss_info_changed(struct ieee80211_hw *hw,
2095 struct ieee80211_vif *vif,
2096 struct ieee80211_bss_conf *info,
2099 struct ath11k *ar = hw->priv;
2100 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
2101 struct cfg80211_chan_def def;
2102 u32 param_id, param_value;
2103 enum nl80211_band band;
2113 mutex_lock(&ar->conf_mutex);
2115 if (changed & BSS_CHANGED_BEACON_INT) {
2116 arvif->beacon_interval = info->beacon_int;
2118 param_id = WMI_VDEV_PARAM_BEACON_INTERVAL;
2119 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2121 arvif->beacon_interval);
2123 ath11k_warn(ar->ab, "Failed to set beacon interval for VDEV: %d\n",
2126 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2127 "Beacon interval: %d set for VDEV: %d\n",
2128 arvif->beacon_interval, arvif->vdev_id);
2131 if (changed & BSS_CHANGED_BEACON) {
2132 param_id = WMI_PDEV_PARAM_BEACON_TX_MODE;
2133 param_value = WMI_BEACON_STAGGERED_MODE;
2134 ret = ath11k_wmi_pdev_set_param(ar, param_id,
2135 param_value, ar->pdev->pdev_id);
2137 ath11k_warn(ar->ab, "Failed to set beacon mode for VDEV: %d\n",
2140 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2141 "Set staggered beacon mode for VDEV: %d\n",
2144 ret = ath11k_mac_setup_bcn_tmpl(arvif);
2146 ath11k_warn(ar->ab, "failed to update bcn template: %d\n",
2150 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
2151 arvif->dtim_period = info->dtim_period;
2153 param_id = WMI_VDEV_PARAM_DTIM_PERIOD;
2154 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2156 arvif->dtim_period);
2159 ath11k_warn(ar->ab, "Failed to set dtim period for VDEV %d: %i\n",
2160 arvif->vdev_id, ret);
2162 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2163 "DTIM period: %d set for VDEV: %d\n",
2164 arvif->dtim_period, arvif->vdev_id);
2167 if (changed & BSS_CHANGED_SSID &&
2168 vif->type == NL80211_IFTYPE_AP) {
2169 arvif->u.ap.ssid_len = info->ssid_len;
2171 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
2172 arvif->u.ap.hidden_ssid = info->hidden_ssid;
2175 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
2176 ether_addr_copy(arvif->bssid, info->bssid);
2178 if (changed & BSS_CHANGED_BEACON_ENABLED) {
2179 ath11k_control_beaconing(arvif, info);
2181 if (arvif->is_up && vif->bss_conf.he_support &&
2182 vif->bss_conf.he_oper.params) {
2183 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2184 WMI_VDEV_PARAM_BA_MODE,
2185 WMI_BA_MODE_BUFFER_SIZE_256);
2188 "failed to set BA BUFFER SIZE 256 for vdev: %d\n",
2191 param_id = WMI_VDEV_PARAM_HEOPS_0_31;
2192 param_value = vif->bss_conf.he_oper.params;
2193 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2194 param_id, param_value);
2195 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2196 "he oper param: %x set for VDEV: %d\n",
2197 param_value, arvif->vdev_id);
2200 ath11k_warn(ar->ab, "Failed to set he oper params %x for VDEV %d: %i\n",
2201 param_value, arvif->vdev_id, ret);
2205 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2208 cts_prot = !!(info->use_cts_prot);
2209 param_id = WMI_VDEV_PARAM_PROTECTION_MODE;
2211 if (arvif->is_started) {
2212 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2213 param_id, cts_prot);
2215 ath11k_warn(ar->ab, "Failed to set CTS prot for VDEV: %d\n",
2218 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "Set CTS prot: %d for VDEV: %d\n",
2219 cts_prot, arvif->vdev_id);
2221 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "defer protection mode setup, vdev is not ready yet\n");
2225 if (changed & BSS_CHANGED_ERP_SLOT) {
2228 if (info->use_short_slot)
2229 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
2232 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
2234 param_id = WMI_VDEV_PARAM_SLOT_TIME;
2235 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2236 param_id, slottime);
2238 ath11k_warn(ar->ab, "Failed to set erp slot for VDEV: %d\n",
2241 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2242 "Set slottime: %d for VDEV: %d\n",
2243 slottime, arvif->vdev_id);
2246 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2249 if (info->use_short_preamble)
2250 preamble = WMI_VDEV_PREAMBLE_SHORT;
2252 preamble = WMI_VDEV_PREAMBLE_LONG;
2254 param_id = WMI_VDEV_PARAM_PREAMBLE;
2255 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2256 param_id, preamble);
2258 ath11k_warn(ar->ab, "Failed to set preamble for VDEV: %d\n",
2261 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2262 "Set preamble: %d for VDEV: %d\n",
2263 preamble, arvif->vdev_id);
2266 if (changed & BSS_CHANGED_ASSOC) {
2268 ath11k_bss_assoc(hw, vif, info);
2270 ath11k_bss_disassoc(hw, vif);
2273 if (changed & BSS_CHANGED_TXPOWER) {
2274 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev_id %i txpower %d\n",
2275 arvif->vdev_id, info->txpower);
2277 arvif->txpower = info->txpower;
2278 ath11k_mac_txpower_recalc(ar);
2281 if (changed & BSS_CHANGED_MCAST_RATE &&
2282 !ath11k_mac_vif_chan(arvif->vif, &def)) {
2283 band = def.chan->band;
2284 mcast_rate = vif->bss_conf.mcast_rate[band];
2287 rateidx = mcast_rate - 1;
2289 rateidx = ffs(vif->bss_conf.basic_rates) - 1;
2291 if (ar->pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP)
2292 rateidx += ATH11K_MAC_FIRST_OFDM_RATE_IDX;
2294 bitrate = ath11k_legacy_rates[rateidx].bitrate;
2295 hw_value = ath11k_legacy_rates[rateidx].hw_value;
2297 if (ath11k_mac_bitrate_is_cck(bitrate))
2298 preamble = WMI_RATE_PREAMBLE_CCK;
2300 preamble = WMI_RATE_PREAMBLE_OFDM;
2302 rate = ATH11K_HW_RATE_CODE(hw_value, 0, preamble);
2304 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2305 "mac vdev %d mcast_rate %x\n",
2306 arvif->vdev_id, rate);
2308 vdev_param = WMI_VDEV_PARAM_MCAST_DATA_RATE;
2309 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2313 "failed to set mcast rate on vdev %i: %d\n",
2314 arvif->vdev_id, ret);
2316 vdev_param = WMI_VDEV_PARAM_BCAST_DATA_RATE;
2317 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2321 "failed to set bcast rate on vdev %i: %d\n",
2322 arvif->vdev_id, ret);
2325 if (changed & BSS_CHANGED_BASIC_RATES &&
2326 !ath11k_mac_vif_chan(arvif->vif, &def))
2327 ath11k_recalculate_mgmt_rate(ar, vif, &def);
2329 if (changed & BSS_CHANGED_TWT) {
2330 if (info->twt_requester || info->twt_responder)
2331 ath11k_wmi_send_twt_enable_cmd(ar, ar->pdev->pdev_id);
2333 ath11k_wmi_send_twt_disable_cmd(ar, ar->pdev->pdev_id);
2336 if (changed & BSS_CHANGED_HE_OBSS_PD)
2337 ath11k_mac_config_obss_pd(ar, &info->he_obss_pd);
2339 if (changed & BSS_CHANGED_HE_BSS_COLOR) {
2340 if (vif->type == NL80211_IFTYPE_AP) {
2341 ret = ath11k_wmi_send_obss_color_collision_cfg_cmd(
2342 ar, arvif->vdev_id, info->he_bss_color.color,
2343 ATH11K_BSS_COLOR_COLLISION_DETECTION_AP_PERIOD_MS,
2344 info->he_bss_color.enabled);
2346 ath11k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n",
2347 arvif->vdev_id, ret);
2348 } else if (vif->type == NL80211_IFTYPE_STATION) {
2349 ret = ath11k_wmi_send_bss_color_change_enable_cmd(ar,
2353 ath11k_warn(ar->ab, "failed to enable bss color change on vdev %i: %d\n",
2354 arvif->vdev_id, ret);
2355 ret = ath11k_wmi_send_obss_color_collision_cfg_cmd(
2356 ar, arvif->vdev_id, 0,
2357 ATH11K_BSS_COLOR_COLLISION_DETECTION_STA_PERIOD_MS, 1);
2359 ath11k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n",
2360 arvif->vdev_id, ret);
2364 if (changed & BSS_CHANGED_FILS_DISCOVERY ||
2365 changed & BSS_CHANGED_UNSOL_BCAST_PROBE_RESP)
2366 ath11k_mac_fils_discovery(arvif, info);
2368 mutex_unlock(&ar->conf_mutex);
2371 void __ath11k_mac_scan_finish(struct ath11k *ar)
2373 lockdep_assert_held(&ar->data_lock);
2375 switch (ar->scan.state) {
2376 case ATH11K_SCAN_IDLE:
2378 case ATH11K_SCAN_RUNNING:
2379 case ATH11K_SCAN_ABORTING:
2380 if (!ar->scan.is_roc) {
2381 struct cfg80211_scan_info info = {
2382 .aborted = (ar->scan.state ==
2383 ATH11K_SCAN_ABORTING),
2386 ieee80211_scan_completed(ar->hw, &info);
2387 } else if (ar->scan.roc_notify) {
2388 ieee80211_remain_on_channel_expired(ar->hw);
2391 case ATH11K_SCAN_STARTING:
2392 ar->scan.state = ATH11K_SCAN_IDLE;
2393 ar->scan_channel = NULL;
2394 ar->scan.roc_freq = 0;
2395 cancel_delayed_work(&ar->scan.timeout);
2396 complete(&ar->scan.completed);
2401 void ath11k_mac_scan_finish(struct ath11k *ar)
2403 spin_lock_bh(&ar->data_lock);
2404 __ath11k_mac_scan_finish(ar);
2405 spin_unlock_bh(&ar->data_lock);
2408 static int ath11k_scan_stop(struct ath11k *ar)
2410 struct scan_cancel_param arg = {
2411 .req_type = WLAN_SCAN_CANCEL_SINGLE,
2412 .scan_id = ATH11K_SCAN_ID,
2416 lockdep_assert_held(&ar->conf_mutex);
2418 /* TODO: Fill other STOP Params */
2419 arg.pdev_id = ar->pdev->pdev_id;
2421 ret = ath11k_wmi_send_scan_stop_cmd(ar, &arg);
2423 ath11k_warn(ar->ab, "failed to stop wmi scan: %d\n", ret);
2427 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
2430 "failed to receive scan abort comple: timed out\n");
2432 } else if (ret > 0) {
2437 /* Scan state should be updated upon scan completion but in case
2438 * firmware fails to deliver the event (for whatever reason) it is
2439 * desired to clean up scan state anyway. Firmware may have just
2440 * dropped the scan completion event delivery due to transport pipe
2441 * being overflown with data and/or it can recover on its own before
2442 * next scan request is submitted.
2444 spin_lock_bh(&ar->data_lock);
2445 if (ar->scan.state != ATH11K_SCAN_IDLE)
2446 __ath11k_mac_scan_finish(ar);
2447 spin_unlock_bh(&ar->data_lock);
2452 static void ath11k_scan_abort(struct ath11k *ar)
2456 lockdep_assert_held(&ar->conf_mutex);
2458 spin_lock_bh(&ar->data_lock);
2460 switch (ar->scan.state) {
2461 case ATH11K_SCAN_IDLE:
2462 /* This can happen if timeout worker kicked in and called
2463 * abortion while scan completion was being processed.
2466 case ATH11K_SCAN_STARTING:
2467 case ATH11K_SCAN_ABORTING:
2468 ath11k_warn(ar->ab, "refusing scan abortion due to invalid scan state: %d\n",
2471 case ATH11K_SCAN_RUNNING:
2472 ar->scan.state = ATH11K_SCAN_ABORTING;
2473 spin_unlock_bh(&ar->data_lock);
2475 ret = ath11k_scan_stop(ar);
2477 ath11k_warn(ar->ab, "failed to abort scan: %d\n", ret);
2479 spin_lock_bh(&ar->data_lock);
2483 spin_unlock_bh(&ar->data_lock);
2486 static void ath11k_scan_timeout_work(struct work_struct *work)
2488 struct ath11k *ar = container_of(work, struct ath11k,
2491 mutex_lock(&ar->conf_mutex);
2492 ath11k_scan_abort(ar);
2493 mutex_unlock(&ar->conf_mutex);
2496 static int ath11k_start_scan(struct ath11k *ar,
2497 struct scan_req_params *arg)
2501 lockdep_assert_held(&ar->conf_mutex);
2503 if (ath11k_spectral_get_mode(ar) == ATH11K_SPECTRAL_BACKGROUND)
2504 ath11k_spectral_reset_buffer(ar);
2506 ret = ath11k_wmi_send_scan_start_cmd(ar, arg);
2510 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
2512 ret = ath11k_scan_stop(ar);
2514 ath11k_warn(ar->ab, "failed to stop scan: %d\n", ret);
2519 /* If we failed to start the scan, return error code at
2520 * this point. This is probably due to some issue in the
2521 * firmware, but no need to wedge the driver due to that...
2523 spin_lock_bh(&ar->data_lock);
2524 if (ar->scan.state == ATH11K_SCAN_IDLE) {
2525 spin_unlock_bh(&ar->data_lock);
2528 spin_unlock_bh(&ar->data_lock);
2533 static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
2534 struct ieee80211_vif *vif,
2535 struct ieee80211_scan_request *hw_req)
2537 struct ath11k *ar = hw->priv;
2538 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
2539 struct cfg80211_scan_request *req = &hw_req->req;
2540 struct scan_req_params arg;
2544 mutex_lock(&ar->conf_mutex);
2546 spin_lock_bh(&ar->data_lock);
2547 switch (ar->scan.state) {
2548 case ATH11K_SCAN_IDLE:
2549 reinit_completion(&ar->scan.started);
2550 reinit_completion(&ar->scan.completed);
2551 ar->scan.state = ATH11K_SCAN_STARTING;
2552 ar->scan.is_roc = false;
2553 ar->scan.vdev_id = arvif->vdev_id;
2556 case ATH11K_SCAN_STARTING:
2557 case ATH11K_SCAN_RUNNING:
2558 case ATH11K_SCAN_ABORTING:
2562 spin_unlock_bh(&ar->data_lock);
2567 memset(&arg, 0, sizeof(arg));
2568 ath11k_wmi_start_scan_init(ar, &arg);
2569 arg.vdev_id = arvif->vdev_id;
2570 arg.scan_id = ATH11K_SCAN_ID;
2573 arg.extraie.len = req->ie_len;
2574 arg.extraie.ptr = kzalloc(req->ie_len, GFP_KERNEL);
2575 memcpy(arg.extraie.ptr, req->ie, req->ie_len);
2579 arg.num_ssids = req->n_ssids;
2580 for (i = 0; i < arg.num_ssids; i++) {
2581 arg.ssid[i].length = req->ssids[i].ssid_len;
2582 memcpy(&arg.ssid[i].ssid, req->ssids[i].ssid,
2583 req->ssids[i].ssid_len);
2586 arg.scan_flags |= WMI_SCAN_FLAG_PASSIVE;
2589 if (req->n_channels) {
2590 arg.num_chan = req->n_channels;
2591 for (i = 0; i < arg.num_chan; i++)
2592 arg.chan_list[i] = req->channels[i]->center_freq;
2595 ret = ath11k_start_scan(ar, &arg);
2597 ath11k_warn(ar->ab, "failed to start hw scan: %d\n", ret);
2598 spin_lock_bh(&ar->data_lock);
2599 ar->scan.state = ATH11K_SCAN_IDLE;
2600 spin_unlock_bh(&ar->data_lock);
2603 /* Add a 200ms margin to account for event/command processing */
2604 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2605 msecs_to_jiffies(arg.max_scan_time +
2606 ATH11K_MAC_SCAN_TIMEOUT_MSECS));
2610 kfree(arg.extraie.ptr);
2612 mutex_unlock(&ar->conf_mutex);
2616 static void ath11k_mac_op_cancel_hw_scan(struct ieee80211_hw *hw,
2617 struct ieee80211_vif *vif)
2619 struct ath11k *ar = hw->priv;
2621 mutex_lock(&ar->conf_mutex);
2622 ath11k_scan_abort(ar);
2623 mutex_unlock(&ar->conf_mutex);
2625 cancel_delayed_work_sync(&ar->scan.timeout);
2628 static int ath11k_install_key(struct ath11k_vif *arvif,
2629 struct ieee80211_key_conf *key,
2630 enum set_key_cmd cmd,
2631 const u8 *macaddr, u32 flags)
2634 struct ath11k *ar = arvif->ar;
2635 struct wmi_vdev_install_key_arg arg = {
2636 .vdev_id = arvif->vdev_id,
2637 .key_idx = key->keyidx,
2638 .key_len = key->keylen,
2639 .key_data = key->key,
2644 lockdep_assert_held(&arvif->ar->conf_mutex);
2646 reinit_completion(&ar->install_key_done);
2648 if (test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags))
2651 if (cmd == DISABLE_KEY) {
2652 /* TODO: Check if FW expects value other than NONE for del */
2653 /* arg.key_cipher = WMI_CIPHER_NONE; */
2655 arg.key_data = NULL;
2659 switch (key->cipher) {
2660 case WLAN_CIPHER_SUITE_CCMP:
2661 arg.key_cipher = WMI_CIPHER_AES_CCM;
2662 /* TODO: Re-check if flag is valid */
2663 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
2665 case WLAN_CIPHER_SUITE_TKIP:
2666 arg.key_cipher = WMI_CIPHER_TKIP;
2667 arg.key_txmic_len = 8;
2668 arg.key_rxmic_len = 8;
2670 case WLAN_CIPHER_SUITE_CCMP_256:
2671 arg.key_cipher = WMI_CIPHER_AES_CCM;
2673 case WLAN_CIPHER_SUITE_GCMP:
2674 case WLAN_CIPHER_SUITE_GCMP_256:
2675 arg.key_cipher = WMI_CIPHER_AES_GCM;
2678 ath11k_warn(ar->ab, "cipher %d is not supported\n", key->cipher);
2682 if (test_bit(ATH11K_FLAG_RAW_MODE, &ar->ab->dev_flags))
2683 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV |
2684 IEEE80211_KEY_FLAG_RESERVE_TAILROOM;
2687 ret = ath11k_wmi_vdev_install_key(arvif->ar, &arg);
2692 if (!wait_for_completion_timeout(&ar->install_key_done, 1 * HZ))
2695 return ar->install_key_status ? -EINVAL : 0;
2698 static int ath11k_clear_peer_keys(struct ath11k_vif *arvif,
2701 struct ath11k *ar = arvif->ar;
2702 struct ath11k_base *ab = ar->ab;
2703 struct ath11k_peer *peer;
2704 int first_errno = 0;
2709 lockdep_assert_held(&ar->conf_mutex);
2711 spin_lock_bh(&ab->base_lock);
2712 peer = ath11k_peer_find(ab, arvif->vdev_id, addr);
2713 spin_unlock_bh(&ab->base_lock);
2718 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
2722 /* key flags are not required to delete the key */
2723 ret = ath11k_install_key(arvif, peer->keys[i],
2724 DISABLE_KEY, addr, flags);
2725 if (ret < 0 && first_errno == 0)
2729 ath11k_warn(ab, "failed to remove peer key %d: %d\n",
2732 spin_lock_bh(&ab->base_lock);
2733 peer->keys[i] = NULL;
2734 spin_unlock_bh(&ab->base_lock);
2740 static int ath11k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2741 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2742 struct ieee80211_key_conf *key)
2744 struct ath11k *ar = hw->priv;
2745 struct ath11k_base *ab = ar->ab;
2746 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
2747 struct ath11k_peer *peer;
2748 struct ath11k_sta *arsta;
2749 const u8 *peer_addr;
2753 /* BIP needs to be done in software */
2754 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2755 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2756 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 ||
2757 key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256)
2760 if (test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags))
2763 if (key->keyidx > WMI_MAX_KEY_INDEX)
2766 mutex_lock(&ar->conf_mutex);
2769 peer_addr = sta->addr;
2770 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2771 peer_addr = vif->bss_conf.bssid;
2773 peer_addr = vif->addr;
2775 key->hw_key_idx = key->keyidx;
2777 /* the peer should not disappear in mid-way (unless FW goes awry) since
2778 * we already hold conf_mutex. we just make sure its there now.
2780 spin_lock_bh(&ab->base_lock);
2781 peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr);
2783 /* flush the fragments cache during key (re)install to
2784 * ensure all frags in the new frag list belong to the same key.
2786 if (peer && cmd == SET_KEY)
2787 ath11k_peer_frags_flush(ar, peer);
2788 spin_unlock_bh(&ab->base_lock);
2791 if (cmd == SET_KEY) {
2792 ath11k_warn(ab, "cannot install key for non-existent peer %pM\n",
2797 /* if the peer doesn't exist there is no key to disable
2804 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
2805 flags |= WMI_KEY_PAIRWISE;
2807 flags |= WMI_KEY_GROUP;
2809 ret = ath11k_install_key(arvif, key, cmd, peer_addr, flags);
2811 ath11k_warn(ab, "ath11k_install_key failed (%d)\n", ret);
2815 ret = ath11k_dp_peer_rx_pn_replay_config(arvif, peer_addr, cmd, key);
2817 ath11k_warn(ab, "failed to offload PN replay detection %d\n", ret);
2821 spin_lock_bh(&ab->base_lock);
2822 peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr);
2823 if (peer && cmd == SET_KEY) {
2824 peer->keys[key->keyidx] = key;
2825 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
2826 peer->ucast_keyidx = key->keyidx;
2827 peer->sec_type = ath11k_dp_tx_get_encrypt_type(key->cipher);
2829 peer->mcast_keyidx = key->keyidx;
2830 peer->sec_type_grp = ath11k_dp_tx_get_encrypt_type(key->cipher);
2832 } else if (peer && cmd == DISABLE_KEY) {
2833 peer->keys[key->keyidx] = NULL;
2834 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
2835 peer->ucast_keyidx = 0;
2837 peer->mcast_keyidx = 0;
2839 /* impossible unless FW goes crazy */
2840 ath11k_warn(ab, "peer %pM disappeared!\n", peer_addr);
2843 arsta = (struct ath11k_sta *)sta->drv_priv;
2845 switch (key->cipher) {
2846 case WLAN_CIPHER_SUITE_TKIP:
2847 case WLAN_CIPHER_SUITE_CCMP:
2848 case WLAN_CIPHER_SUITE_CCMP_256:
2849 case WLAN_CIPHER_SUITE_GCMP:
2850 case WLAN_CIPHER_SUITE_GCMP_256:
2852 arsta->pn_type = HAL_PN_TYPE_WPA;
2854 arsta->pn_type = HAL_PN_TYPE_NONE;
2857 arsta->pn_type = HAL_PN_TYPE_NONE;
2862 spin_unlock_bh(&ab->base_lock);
2865 mutex_unlock(&ar->conf_mutex);
2870 ath11k_mac_bitrate_mask_num_vht_rates(struct ath11k *ar,
2871 enum nl80211_band band,
2872 const struct cfg80211_bitrate_mask *mask)
2877 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
2878 num_rates += hweight16(mask->control[band].vht_mcs[i]);
2884 ath11k_mac_set_peer_vht_fixed_rate(struct ath11k_vif *arvif,
2885 struct ieee80211_sta *sta,
2886 const struct cfg80211_bitrate_mask *mask,
2887 enum nl80211_band band)
2889 struct ath11k *ar = arvif->ar;
2894 lockdep_assert_held(&ar->conf_mutex);
2898 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
2899 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
2901 vht_rate = ffs(mask->control[band].vht_mcs[i]) - 1;
2906 ath11k_warn(ar->ab, "No single VHT Fixed rate found to set for %pM",
2911 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2912 "Setting Fixed VHT Rate for peer %pM. Device will not switch to any other selected rates",
2915 rate_code = ATH11K_HW_RATE_CODE(vht_rate, nss - 1,
2916 WMI_RATE_PREAMBLE_VHT);
2917 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
2919 WMI_PEER_PARAM_FIXED_RATE,
2923 "failed to update STA %pM Fixed Rate %d: %d\n",
2924 sta->addr, rate_code, ret);
2929 static int ath11k_station_assoc(struct ath11k *ar,
2930 struct ieee80211_vif *vif,
2931 struct ieee80211_sta *sta,
2934 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
2935 struct peer_assoc_params peer_arg;
2937 struct cfg80211_chan_def def;
2938 enum nl80211_band band;
2939 struct cfg80211_bitrate_mask *mask;
2942 lockdep_assert_held(&ar->conf_mutex);
2944 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
2947 band = def.chan->band;
2948 mask = &arvif->bitrate_mask;
2950 ath11k_peer_assoc_prepare(ar, vif, sta, &peer_arg, reassoc);
2952 ret = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
2954 ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2955 sta->addr, arvif->vdev_id, ret);
2959 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
2960 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
2961 sta->addr, arvif->vdev_id);
2965 num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask);
2967 /* If single VHT rate is configured (by set_bitrate_mask()),
2968 * peer_assoc will disable VHT. This is now enabled by a peer specific
2970 * Note that all other rates and NSS will be disabled for this peer.
2972 if (sta->vht_cap.vht_supported && num_vht_rates == 1) {
2973 ret = ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask,
2979 /* Re-assoc is run only to update supported rates for given station. It
2980 * doesn't make much sense to reconfigure the peer completely.
2985 ret = ath11k_setup_peer_smps(ar, arvif, sta->addr,
2988 ath11k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n",
2989 arvif->vdev_id, ret);
2994 arvif->num_legacy_stations++;
2995 ret = ath11k_recalc_rtscts_prot(arvif);
3000 if (sta->wme && sta->uapsd_queues) {
3001 ret = ath11k_peer_assoc_qos_ap(ar, arvif, sta);
3003 ath11k_warn(ar->ab, "failed to set qos params for STA %pM for vdev %i: %d\n",
3004 sta->addr, arvif->vdev_id, ret);
3012 static int ath11k_station_disassoc(struct ath11k *ar,
3013 struct ieee80211_vif *vif,
3014 struct ieee80211_sta *sta)
3016 struct ath11k_vif *arvif = (void *)vif->drv_priv;
3019 lockdep_assert_held(&ar->conf_mutex);
3022 arvif->num_legacy_stations--;
3023 ret = ath11k_recalc_rtscts_prot(arvif);
3028 ret = ath11k_clear_peer_keys(arvif, sta->addr);
3030 ath11k_warn(ar->ab, "failed to clear all peer keys for vdev %i: %d\n",
3031 arvif->vdev_id, ret);
3037 static void ath11k_sta_rc_update_wk(struct work_struct *wk)
3040 struct ath11k_vif *arvif;
3041 struct ath11k_sta *arsta;
3042 struct ieee80211_sta *sta;
3043 struct cfg80211_chan_def def;
3044 enum nl80211_band band;
3045 const u8 *ht_mcs_mask;
3046 const u16 *vht_mcs_mask;
3047 u32 changed, bw, nss, smps;
3048 int err, num_vht_rates;
3049 const struct cfg80211_bitrate_mask *mask;
3050 struct peer_assoc_params peer_arg;
3052 arsta = container_of(wk, struct ath11k_sta, update_wk);
3053 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
3054 arvif = arsta->arvif;
3057 if (WARN_ON(ath11k_mac_vif_chan(arvif->vif, &def)))
3060 band = def.chan->band;
3061 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
3062 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
3064 spin_lock_bh(&ar->data_lock);
3066 changed = arsta->changed;
3073 spin_unlock_bh(&ar->data_lock);
3075 mutex_lock(&ar->conf_mutex);
3077 nss = max_t(u32, 1, nss);
3078 nss = min(nss, max(ath11k_mac_max_ht_nss(ht_mcs_mask),
3079 ath11k_mac_max_vht_nss(vht_mcs_mask)));
3081 if (changed & IEEE80211_RC_BW_CHANGED) {
3082 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
3083 WMI_PEER_CHWIDTH, bw);
3085 ath11k_warn(ar->ab, "failed to update STA %pM peer bw %d: %d\n",
3086 sta->addr, bw, err);
3089 if (changed & IEEE80211_RC_NSS_CHANGED) {
3090 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM nss %d\n",
3093 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
3096 ath11k_warn(ar->ab, "failed to update STA %pM nss %d: %d\n",
3097 sta->addr, nss, err);
3100 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3101 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM smps %d\n",
3104 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
3105 WMI_PEER_MIMO_PS_STATE, smps);
3107 ath11k_warn(ar->ab, "failed to update STA %pM smps %d: %d\n",
3108 sta->addr, smps, err);
3111 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
3112 mask = &arvif->bitrate_mask;
3113 num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band,
3116 /* Peer_assoc_prepare will reject vht rates in
3117 * bitrate_mask if its not available in range format and
3118 * sets vht tx_rateset as unsupported. So multiple VHT MCS
3119 * setting(eg. MCS 4,5,6) per peer is not supported here.
3120 * But, Single rate in VHT mask can be set as per-peer
3121 * fixed rate. But even if any HT rates are configured in
3122 * the bitrate mask, device will not switch to those rates
3123 * when per-peer Fixed rate is set.
3124 * TODO: Check RATEMASK_CMDID to support auto rates selection
3125 * across HT/VHT and for multiple VHT MCS support.
3127 if (sta->vht_cap.vht_supported && num_vht_rates == 1) {
3128 ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask,
3131 /* If the peer is non-VHT or no fixed VHT rate
3132 * is provided in the new bitrate mask we set the
3133 * other rates using peer_assoc command.
3135 ath11k_peer_assoc_prepare(ar, arvif->vif, sta,
3138 err = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
3140 ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n",
3141 sta->addr, arvif->vdev_id, err);
3143 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ))
3144 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
3145 sta->addr, arvif->vdev_id);
3149 mutex_unlock(&ar->conf_mutex);
3152 static int ath11k_mac_inc_num_stations(struct ath11k_vif *arvif,
3153 struct ieee80211_sta *sta)
3155 struct ath11k *ar = arvif->ar;
3157 lockdep_assert_held(&ar->conf_mutex);
3159 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
3162 if (ar->num_stations >= ar->max_num_stations)
3170 static void ath11k_mac_dec_num_stations(struct ath11k_vif *arvif,
3171 struct ieee80211_sta *sta)
3173 struct ath11k *ar = arvif->ar;
3175 lockdep_assert_held(&ar->conf_mutex);
3177 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
3183 static int ath11k_mac_station_add(struct ath11k *ar,
3184 struct ieee80211_vif *vif,
3185 struct ieee80211_sta *sta)
3187 struct ath11k_base *ab = ar->ab;
3188 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
3189 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
3190 struct peer_create_params peer_param;
3193 lockdep_assert_held(&ar->conf_mutex);
3195 ret = ath11k_mac_inc_num_stations(arvif, sta);
3197 ath11k_warn(ab, "refusing to associate station: too many connected already (%d)\n",
3198 ar->max_num_stations);
3202 arsta->rx_stats = kzalloc(sizeof(*arsta->rx_stats), GFP_KERNEL);
3203 if (!arsta->rx_stats) {
3205 goto dec_num_station;
3208 peer_param.vdev_id = arvif->vdev_id;
3209 peer_param.peer_addr = sta->addr;
3210 peer_param.peer_type = WMI_PEER_TYPE_DEFAULT;
3212 ret = ath11k_peer_create(ar, arvif, sta, &peer_param);
3214 ath11k_warn(ab, "Failed to add peer: %pM for VDEV: %d\n",
3215 sta->addr, arvif->vdev_id);
3219 ath11k_dbg(ab, ATH11K_DBG_MAC, "Added peer: %pM for VDEV: %d\n",
3220 sta->addr, arvif->vdev_id);
3222 if (ath11k_debugfs_is_extd_tx_stats_enabled(ar)) {
3223 arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats), GFP_KERNEL);
3224 if (!arsta->tx_stats) {
3230 if (ieee80211_vif_is_mesh(vif)) {
3231 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
3233 WMI_PEER_USE_4ADDR, 1);
3235 ath11k_warn(ab, "failed to STA %pM 4addr capability: %d\n",
3241 ret = ath11k_dp_peer_setup(ar, arvif->vdev_id, sta->addr);
3243 ath11k_warn(ab, "failed to setup dp for peer %pM on vdev %i (%d)\n",
3244 sta->addr, arvif->vdev_id, ret);
3248 if (ab->hw_params.vdev_start_delay &&
3249 !arvif->is_started &&
3250 arvif->vdev_type != WMI_VDEV_TYPE_AP) {
3251 ret = ath11k_start_vdev_delay(ar->hw, vif);
3253 ath11k_warn(ab, "failed to delay vdev start: %d\n", ret);
3261 kfree(arsta->tx_stats);
3262 arsta->tx_stats = NULL;
3264 ath11k_peer_delete(ar, arvif->vdev_id, sta->addr);
3266 kfree(arsta->rx_stats);
3267 arsta->rx_stats = NULL;
3269 ath11k_mac_dec_num_stations(arvif, sta);
3274 static int ath11k_mac_op_sta_state(struct ieee80211_hw *hw,
3275 struct ieee80211_vif *vif,
3276 struct ieee80211_sta *sta,
3277 enum ieee80211_sta_state old_state,
3278 enum ieee80211_sta_state new_state)
3280 struct ath11k *ar = hw->priv;
3281 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
3282 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
3283 struct ath11k_peer *peer;
3286 /* cancel must be done outside the mutex to avoid deadlock */
3287 if ((old_state == IEEE80211_STA_NONE &&
3288 new_state == IEEE80211_STA_NOTEXIST))
3289 cancel_work_sync(&arsta->update_wk);
3291 mutex_lock(&ar->conf_mutex);
3293 if (old_state == IEEE80211_STA_NOTEXIST &&
3294 new_state == IEEE80211_STA_NONE) {
3295 memset(arsta, 0, sizeof(*arsta));
3296 arsta->arvif = arvif;
3297 INIT_WORK(&arsta->update_wk, ath11k_sta_rc_update_wk);
3299 ret = ath11k_mac_station_add(ar, vif, sta);
3301 ath11k_warn(ar->ab, "Failed to add station: %pM for VDEV: %d\n",
3302 sta->addr, arvif->vdev_id);
3303 } else if ((old_state == IEEE80211_STA_NONE &&
3304 new_state == IEEE80211_STA_NOTEXIST)) {
3305 ath11k_dp_peer_cleanup(ar, arvif->vdev_id, sta->addr);
3307 ret = ath11k_peer_delete(ar, arvif->vdev_id, sta->addr);
3309 ath11k_warn(ar->ab, "Failed to delete peer: %pM for VDEV: %d\n",
3310 sta->addr, arvif->vdev_id);
3312 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "Removed peer: %pM for VDEV: %d\n",
3313 sta->addr, arvif->vdev_id);
3315 ath11k_mac_dec_num_stations(arvif, sta);
3316 spin_lock_bh(&ar->ab->base_lock);
3317 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
3318 if (peer && peer->sta == sta) {
3319 ath11k_warn(ar->ab, "Found peer entry %pM n vdev %i after it was supposedly removed\n",
3320 vif->addr, arvif->vdev_id);
3322 list_del(&peer->list);
3326 spin_unlock_bh(&ar->ab->base_lock);
3328 kfree(arsta->tx_stats);
3329 arsta->tx_stats = NULL;
3331 kfree(arsta->rx_stats);
3332 arsta->rx_stats = NULL;
3333 } else if (old_state == IEEE80211_STA_AUTH &&
3334 new_state == IEEE80211_STA_ASSOC &&
3335 (vif->type == NL80211_IFTYPE_AP ||
3336 vif->type == NL80211_IFTYPE_MESH_POINT ||
3337 vif->type == NL80211_IFTYPE_ADHOC)) {
3338 ret = ath11k_station_assoc(ar, vif, sta, false);
3340 ath11k_warn(ar->ab, "Failed to associate station: %pM\n",
3342 } else if (old_state == IEEE80211_STA_ASSOC &&
3343 new_state == IEEE80211_STA_AUTH &&
3344 (vif->type == NL80211_IFTYPE_AP ||
3345 vif->type == NL80211_IFTYPE_MESH_POINT ||
3346 vif->type == NL80211_IFTYPE_ADHOC)) {
3347 ret = ath11k_station_disassoc(ar, vif, sta);
3349 ath11k_warn(ar->ab, "Failed to disassociate station: %pM\n",
3353 mutex_unlock(&ar->conf_mutex);
3357 static int ath11k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw,
3358 struct ieee80211_vif *vif,
3359 struct ieee80211_sta *sta)
3361 struct ath11k *ar = hw->priv;
3362 struct ath11k_vif *arvif = (void *)vif->drv_priv;
3366 if (sta->txpwr.type == NL80211_TX_POWER_AUTOMATIC) {
3369 txpwr = sta->txpwr.power;
3374 if (txpwr > ATH11K_TX_POWER_MAX_VAL || txpwr < ATH11K_TX_POWER_MIN_VAL)
3377 mutex_lock(&ar->conf_mutex);
3379 ret = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
3380 WMI_PEER_USE_FIXED_PWR, txpwr);
3382 ath11k_warn(ar->ab, "failed to set tx power for station ret: %d\n",
3388 mutex_unlock(&ar->conf_mutex);
3392 static void ath11k_mac_op_sta_rc_update(struct ieee80211_hw *hw,
3393 struct ieee80211_vif *vif,
3394 struct ieee80211_sta *sta,
3397 struct ath11k *ar = hw->priv;
3398 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
3399 struct ath11k_vif *arvif = (void *)vif->drv_priv;
3400 struct ath11k_peer *peer;
3403 spin_lock_bh(&ar->ab->base_lock);
3405 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
3407 spin_unlock_bh(&ar->ab->base_lock);
3408 ath11k_warn(ar->ab, "mac sta rc update failed to find peer %pM on vdev %i\n",
3409 sta->addr, arvif->vdev_id);
3413 spin_unlock_bh(&ar->ab->base_lock);
3415 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3416 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
3417 sta->addr, changed, sta->bandwidth, sta->rx_nss,
3420 spin_lock_bh(&ar->data_lock);
3422 if (changed & IEEE80211_RC_BW_CHANGED) {
3423 bw = WMI_PEER_CHWIDTH_20MHZ;
3425 switch (sta->bandwidth) {
3426 case IEEE80211_STA_RX_BW_20:
3427 bw = WMI_PEER_CHWIDTH_20MHZ;
3429 case IEEE80211_STA_RX_BW_40:
3430 bw = WMI_PEER_CHWIDTH_40MHZ;
3432 case IEEE80211_STA_RX_BW_80:
3433 bw = WMI_PEER_CHWIDTH_80MHZ;
3435 case IEEE80211_STA_RX_BW_160:
3436 bw = WMI_PEER_CHWIDTH_160MHZ;
3439 ath11k_warn(ar->ab, "Invalid bandwidth %d in rc update for %pM\n",
3440 sta->bandwidth, sta->addr);
3441 bw = WMI_PEER_CHWIDTH_20MHZ;
3448 if (changed & IEEE80211_RC_NSS_CHANGED)
3449 arsta->nss = sta->rx_nss;
3451 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3452 smps = WMI_PEER_SMPS_PS_NONE;
3454 switch (sta->smps_mode) {
3455 case IEEE80211_SMPS_AUTOMATIC:
3456 case IEEE80211_SMPS_OFF:
3457 smps = WMI_PEER_SMPS_PS_NONE;
3459 case IEEE80211_SMPS_STATIC:
3460 smps = WMI_PEER_SMPS_STATIC;
3462 case IEEE80211_SMPS_DYNAMIC:
3463 smps = WMI_PEER_SMPS_DYNAMIC;
3466 ath11k_warn(ar->ab, "Invalid smps %d in sta rc update for %pM\n",
3467 sta->smps_mode, sta->addr);
3468 smps = WMI_PEER_SMPS_PS_NONE;
3475 arsta->changed |= changed;
3477 spin_unlock_bh(&ar->data_lock);
3479 ieee80211_queue_work(hw, &arsta->update_wk);
3482 static int ath11k_conf_tx_uapsd(struct ath11k *ar, struct ieee80211_vif *vif,
3483 u16 ac, bool enable)
3485 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
3489 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3493 case IEEE80211_AC_VO:
3494 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3495 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3497 case IEEE80211_AC_VI:
3498 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3499 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3501 case IEEE80211_AC_BE:
3502 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3503 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3505 case IEEE80211_AC_BK:
3506 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3507 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3512 arvif->u.sta.uapsd |= value;
3514 arvif->u.sta.uapsd &= ~value;
3516 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3517 WMI_STA_PS_PARAM_UAPSD,
3518 arvif->u.sta.uapsd);
3520 ath11k_warn(ar->ab, "could not set uapsd params %d\n", ret);
3524 if (arvif->u.sta.uapsd)
3525 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3527 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3529 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3530 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3533 ath11k_warn(ar->ab, "could not set rx wake param %d\n", ret);
3539 static int ath11k_mac_op_conf_tx(struct ieee80211_hw *hw,
3540 struct ieee80211_vif *vif, u16 ac,
3541 const struct ieee80211_tx_queue_params *params)
3543 struct ath11k *ar = hw->priv;
3544 struct ath11k_vif *arvif = (void *)vif->drv_priv;
3545 struct wmi_wmm_params_arg *p = NULL;
3548 mutex_lock(&ar->conf_mutex);
3551 case IEEE80211_AC_VO:
3552 p = &arvif->wmm_params.ac_vo;
3554 case IEEE80211_AC_VI:
3555 p = &arvif->wmm_params.ac_vi;
3557 case IEEE80211_AC_BE:
3558 p = &arvif->wmm_params.ac_be;
3560 case IEEE80211_AC_BK:
3561 p = &arvif->wmm_params.ac_bk;
3570 p->cwmin = params->cw_min;
3571 p->cwmax = params->cw_max;
3572 p->aifs = params->aifs;
3573 p->txop = params->txop;
3575 ret = ath11k_wmi_send_wmm_update_cmd_tlv(ar, arvif->vdev_id,
3576 &arvif->wmm_params);
3578 ath11k_warn(ar->ab, "failed to set wmm params: %d\n", ret);
3582 ret = ath11k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3585 ath11k_warn(ar->ab, "failed to set sta uapsd: %d\n", ret);
3588 mutex_unlock(&ar->conf_mutex);
3592 static struct ieee80211_sta_ht_cap
3593 ath11k_create_ht_cap(struct ath11k *ar, u32 ar_ht_cap, u32 rate_cap_rx_chainmask)
3596 struct ieee80211_sta_ht_cap ht_cap = {0};
3597 u32 ar_vht_cap = ar->pdev->cap.vht_cap;
3599 if (!(ar_ht_cap & WMI_HT_CAP_ENABLED))
3602 ht_cap.ht_supported = 1;
3603 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3604 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
3605 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3606 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3607 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3609 if (ar_ht_cap & WMI_HT_CAP_HT20_SGI)
3610 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3612 if (ar_ht_cap & WMI_HT_CAP_HT40_SGI)
3613 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3615 if (ar_ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) {
3618 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3619 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3624 if (ar_ht_cap & WMI_HT_CAP_TX_STBC)
3625 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3627 if (ar_ht_cap & WMI_HT_CAP_RX_STBC) {
3631 stbc &= WMI_HT_CAP_RX_STBC;
3632 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3633 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3634 stbc &= IEEE80211_HT_CAP_RX_STBC;
3639 if (ar_ht_cap & WMI_HT_CAP_RX_LDPC)
3640 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3642 if (ar_ht_cap & WMI_HT_CAP_L_SIG_TXOP_PROT)
3643 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3645 if (ar_vht_cap & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3646 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3648 for (i = 0; i < ar->num_rx_chains; i++) {
3649 if (rate_cap_rx_chainmask & BIT(i))
3650 ht_cap.mcs.rx_mask[i] = 0xFF;
3653 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3658 static int ath11k_mac_set_txbf_conf(struct ath11k_vif *arvif)
3661 struct ath11k *ar = arvif->ar;
3664 u32 vht_cap = ar->pdev->cap.vht_cap;
3665 u32 vdev_param = WMI_VDEV_PARAM_TXBF;
3667 if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)) {
3668 nsts = vht_cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
3669 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
3670 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
3673 if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) {
3674 sound_dim = vht_cap &
3675 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
3676 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
3677 if (sound_dim > (ar->num_tx_chains - 1))
3678 sound_dim = ar->num_tx_chains - 1;
3679 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
3685 if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) {
3686 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
3688 if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) &&
3689 arvif->vdev_type == WMI_VDEV_TYPE_AP)
3690 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
3693 /* TODO: SUBFEE not validated in HK, disable here until validated? */
3695 if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) {
3696 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
3698 if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) &&
3699 arvif->vdev_type == WMI_VDEV_TYPE_STA)
3700 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
3703 return ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3707 static void ath11k_set_vht_txbf_cap(struct ath11k *ar, u32 *vht_cap)
3709 bool subfer, subfee;
3712 subfer = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE));
3713 subfee = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE));
3715 if (ar->num_tx_chains < 2) {
3716 *vht_cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
3720 /* If SU Beaformer is not set, then disable MU Beamformer Capability */
3722 *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE);
3724 /* If SU Beaformee is not set, then disable MU Beamformee Capability */
3726 *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
3728 sound_dim = (*vht_cap & IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK);
3729 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
3730 *vht_cap &= ~IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
3732 /* TODO: Need to check invalid STS and Sound_dim values set by FW? */
3734 /* Enable Sounding Dimension Field only if SU BF is enabled */
3736 if (sound_dim > (ar->num_tx_chains - 1))
3737 sound_dim = ar->num_tx_chains - 1;
3739 sound_dim <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
3740 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
3741 *vht_cap |= sound_dim;
3744 /* Use the STS advertised by FW unless SU Beamformee is not supported*/
3746 *vht_cap &= ~(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK);
3749 static struct ieee80211_sta_vht_cap
3750 ath11k_create_vht_cap(struct ath11k *ar, u32 rate_cap_tx_chainmask,
3751 u32 rate_cap_rx_chainmask)
3753 struct ieee80211_sta_vht_cap vht_cap = {0};
3754 u16 txmcs_map, rxmcs_map;
3757 vht_cap.vht_supported = 1;
3758 vht_cap.cap = ar->pdev->cap.vht_cap;
3760 ath11k_set_vht_txbf_cap(ar, &vht_cap.cap);
3762 /* TODO: Enable back VHT160 mode once association issues are fixed */
3763 /* Disabling VHT160 and VHT80+80 modes */
3764 vht_cap.cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
3765 vht_cap.cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
3769 for (i = 0; i < 8; i++) {
3770 if (i < ar->num_tx_chains && rate_cap_tx_chainmask & BIT(i))
3771 txmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
3773 txmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
3775 if (i < ar->num_rx_chains && rate_cap_rx_chainmask & BIT(i))
3776 rxmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
3778 rxmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
3781 if (rate_cap_tx_chainmask <= 1)
3782 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
3784 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_map);
3785 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_map);
3790 static void ath11k_mac_setup_ht_vht_cap(struct ath11k *ar,
3791 struct ath11k_pdev_cap *cap,
3794 struct ieee80211_supported_band *band;
3795 u32 rate_cap_tx_chainmask;
3796 u32 rate_cap_rx_chainmask;
3799 rate_cap_tx_chainmask = ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift;
3800 rate_cap_rx_chainmask = ar->cfg_rx_chainmask >> cap->rx_chain_mask_shift;
3802 if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) {
3803 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
3804 ht_cap = cap->band[NL80211_BAND_2GHZ].ht_cap_info;
3806 *ht_cap_info = ht_cap;
3807 band->ht_cap = ath11k_create_ht_cap(ar, ht_cap,
3808 rate_cap_rx_chainmask);
3811 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP && !ar->supports_6ghz) {
3812 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
3813 ht_cap = cap->band[NL80211_BAND_5GHZ].ht_cap_info;
3815 *ht_cap_info = ht_cap;
3816 band->ht_cap = ath11k_create_ht_cap(ar, ht_cap,
3817 rate_cap_rx_chainmask);
3818 band->vht_cap = ath11k_create_vht_cap(ar, rate_cap_tx_chainmask,
3819 rate_cap_rx_chainmask);
3823 static int ath11k_check_chain_mask(struct ath11k *ar, u32 ant, bool is_tx_ant)
3825 /* TODO: Check the request chainmask against the supported
3826 * chainmask table which is advertised in extented_service_ready event
3832 static void ath11k_gen_ppe_thresh(struct ath11k_ppe_threshold *fw_ppet,
3838 he_ppet[0] = fw_ppet->numss_m1 & IEEE80211_PPE_THRES_NSS_MASK;
3839 he_ppet[0] |= (fw_ppet->ru_bit_mask <<
3840 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS) &
3841 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK;
3842 for (nss = 0; nss <= fw_ppet->numss_m1; nss++) {
3843 for (ru = 0; ru < 4; ru++) {
3847 if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0)
3849 val = (fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> (ru * 6)) &
3851 val = ((val >> 3) & 0x7) | ((val & 0x7) << 3);
3852 for (i = 5; i >= 0; i--) {
3854 ((val >> i) & 0x1) << ((bit % 8));
3862 ath11k_mac_filter_he_cap_mesh(struct ieee80211_he_cap_elem *he_cap_elem)
3866 m = IEEE80211_HE_MAC_CAP0_TWT_RES |
3867 IEEE80211_HE_MAC_CAP0_TWT_REQ;
3868 he_cap_elem->mac_cap_info[0] &= ~m;
3870 m = IEEE80211_HE_MAC_CAP2_TRS |
3871 IEEE80211_HE_MAC_CAP2_BCAST_TWT |
3872 IEEE80211_HE_MAC_CAP2_MU_CASCADING;
3873 he_cap_elem->mac_cap_info[2] &= ~m;
3875 m = IEEE80211_HE_MAC_CAP3_FLEX_TWT_SCHED |
3876 IEEE80211_HE_MAC_CAP2_BCAST_TWT |
3877 IEEE80211_HE_MAC_CAP2_MU_CASCADING;
3878 he_cap_elem->mac_cap_info[3] &= ~m;
3880 m = IEEE80211_HE_MAC_CAP4_BSRP_BQRP_A_MPDU_AGG |
3881 IEEE80211_HE_MAC_CAP4_BQR;
3882 he_cap_elem->mac_cap_info[4] &= ~m;
3884 m = IEEE80211_HE_MAC_CAP5_SUBCHAN_SELECTIVE_TRANSMISSION |
3885 IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU |
3886 IEEE80211_HE_MAC_CAP5_PUNCTURED_SOUNDING |
3887 IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX;
3888 he_cap_elem->mac_cap_info[5] &= ~m;
3890 m = IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
3891 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO;
3892 he_cap_elem->phy_cap_info[2] &= ~m;
3894 m = IEEE80211_HE_PHY_CAP3_RX_PARTIAL_BW_SU_IN_20MHZ_MU |
3895 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK |
3896 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK;
3897 he_cap_elem->phy_cap_info[3] &= ~m;
3899 m = IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
3900 he_cap_elem->phy_cap_info[4] &= ~m;
3902 m = IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK;
3903 he_cap_elem->phy_cap_info[5] &= ~m;
3905 m = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU |
3906 IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB |
3907 IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB |
3908 IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO;
3909 he_cap_elem->phy_cap_info[6] &= ~m;
3911 m = IEEE80211_HE_PHY_CAP7_PSR_BASED_SR |
3912 IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_SUPP |
3913 IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ |
3914 IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ;
3915 he_cap_elem->phy_cap_info[7] &= ~m;
3917 m = IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI |
3918 IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
3919 IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
3920 IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU;
3921 he_cap_elem->phy_cap_info[8] &= ~m;
3923 m = IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM |
3924 IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK |
3925 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU |
3926 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
3927 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
3928 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB;
3929 he_cap_elem->phy_cap_info[9] &= ~m;
3932 static __le16 ath11k_mac_setup_he_6ghz_cap(struct ath11k_pdev_cap *pcap,
3933 struct ath11k_band_cap *bcap)
3937 bcap->he_6ghz_capa = IEEE80211_HT_MPDU_DENSITY_NONE;
3938 if (bcap->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3939 bcap->he_6ghz_capa |=
3940 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_SM_PS,
3941 WLAN_HT_CAP_SM_PS_DYNAMIC);
3943 bcap->he_6ghz_capa |=
3944 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_SM_PS,
3945 WLAN_HT_CAP_SM_PS_DISABLED);
3946 val = FIELD_GET(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK,
3948 bcap->he_6ghz_capa |=
3949 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP, val);
3950 val = FIELD_GET(IEEE80211_VHT_CAP_MAX_MPDU_MASK, pcap->vht_cap);
3951 bcap->he_6ghz_capa |=
3952 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN, val);
3953 if (pcap->vht_cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN)
3954 bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS;
3955 if (pcap->vht_cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN)
3956 bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS;
3958 return cpu_to_le16(bcap->he_6ghz_capa);
3961 static int ath11k_mac_copy_he_cap(struct ath11k *ar,
3962 struct ath11k_pdev_cap *cap,
3963 struct ieee80211_sband_iftype_data *data,
3968 for (i = 0; i < NUM_NL80211_IFTYPES; i++) {
3969 struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap;
3970 struct ath11k_band_cap *band_cap = &cap->band[band];
3971 struct ieee80211_he_cap_elem *he_cap_elem =
3972 &he_cap->he_cap_elem;
3975 case NL80211_IFTYPE_STATION:
3976 case NL80211_IFTYPE_AP:
3977 case NL80211_IFTYPE_MESH_POINT:
3984 data[idx].types_mask = BIT(i);
3985 he_cap->has_he = true;
3986 memcpy(he_cap_elem->mac_cap_info, band_cap->he_cap_info,
3987 sizeof(he_cap_elem->mac_cap_info));
3988 memcpy(he_cap_elem->phy_cap_info, band_cap->he_cap_phy_info,
3989 sizeof(he_cap_elem->phy_cap_info));
3991 he_cap_elem->mac_cap_info[1] &=
3992 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_MASK;
3994 he_cap_elem->phy_cap_info[5] &=
3995 ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK;
3996 he_cap_elem->phy_cap_info[5] |= ar->num_tx_chains - 1;
3999 case NL80211_IFTYPE_AP:
4000 he_cap_elem->phy_cap_info[3] &=
4001 ~IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK;
4002 he_cap_elem->phy_cap_info[9] |=
4003 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU;
4005 case NL80211_IFTYPE_STATION:
4006 he_cap_elem->mac_cap_info[0] &=
4007 ~IEEE80211_HE_MAC_CAP0_TWT_RES;
4008 he_cap_elem->mac_cap_info[0] |=
4009 IEEE80211_HE_MAC_CAP0_TWT_REQ;
4010 he_cap_elem->phy_cap_info[9] |=
4011 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU;
4013 case NL80211_IFTYPE_MESH_POINT:
4014 ath11k_mac_filter_he_cap_mesh(he_cap_elem);
4018 he_cap->he_mcs_nss_supp.rx_mcs_80 =
4019 cpu_to_le16(band_cap->he_mcs & 0xffff);
4020 he_cap->he_mcs_nss_supp.tx_mcs_80 =
4021 cpu_to_le16(band_cap->he_mcs & 0xffff);
4022 he_cap->he_mcs_nss_supp.rx_mcs_160 =
4023 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
4024 he_cap->he_mcs_nss_supp.tx_mcs_160 =
4025 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
4026 he_cap->he_mcs_nss_supp.rx_mcs_80p80 =
4027 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
4028 he_cap->he_mcs_nss_supp.tx_mcs_80p80 =
4029 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
4031 memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
4032 if (he_cap_elem->phy_cap_info[6] &
4033 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
4034 ath11k_gen_ppe_thresh(&band_cap->he_ppet,
4037 if (band == NL80211_BAND_6GHZ) {
4038 data[idx].he_6ghz_capa.capa =
4039 ath11k_mac_setup_he_6ghz_cap(cap, band_cap);
4047 static void ath11k_mac_setup_he_cap(struct ath11k *ar,
4048 struct ath11k_pdev_cap *cap)
4050 struct ieee80211_supported_band *band;
4053 if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) {
4054 count = ath11k_mac_copy_he_cap(ar, cap,
4055 ar->mac.iftype[NL80211_BAND_2GHZ],
4057 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
4058 band->iftype_data = ar->mac.iftype[NL80211_BAND_2GHZ];
4059 band->n_iftype_data = count;
4062 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP) {
4063 count = ath11k_mac_copy_he_cap(ar, cap,
4064 ar->mac.iftype[NL80211_BAND_5GHZ],
4066 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
4067 band->iftype_data = ar->mac.iftype[NL80211_BAND_5GHZ];
4068 band->n_iftype_data = count;
4071 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP &&
4072 ar->supports_6ghz) {
4073 count = ath11k_mac_copy_he_cap(ar, cap,
4074 ar->mac.iftype[NL80211_BAND_6GHZ],
4076 band = &ar->mac.sbands[NL80211_BAND_6GHZ];
4077 band->iftype_data = ar->mac.iftype[NL80211_BAND_6GHZ];
4078 band->n_iftype_data = count;
4082 static int __ath11k_set_antenna(struct ath11k *ar, u32 tx_ant, u32 rx_ant)
4086 lockdep_assert_held(&ar->conf_mutex);
4088 if (ath11k_check_chain_mask(ar, tx_ant, true))
4091 if (ath11k_check_chain_mask(ar, rx_ant, false))
4094 ar->cfg_tx_chainmask = tx_ant;
4095 ar->cfg_rx_chainmask = rx_ant;
4097 if (ar->state != ATH11K_STATE_ON &&
4098 ar->state != ATH11K_STATE_RESTARTED)
4101 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_TX_CHAIN_MASK,
4102 tx_ant, ar->pdev->pdev_id);
4104 ath11k_warn(ar->ab, "failed to set tx-chainmask: %d, req 0x%x\n",
4109 ar->num_tx_chains = get_num_chains(tx_ant);
4111 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RX_CHAIN_MASK,
4112 rx_ant, ar->pdev->pdev_id);
4114 ath11k_warn(ar->ab, "failed to set rx-chainmask: %d, req 0x%x\n",
4119 ar->num_rx_chains = get_num_chains(rx_ant);
4121 /* Reload HT/VHT/HE capability */
4122 ath11k_mac_setup_ht_vht_cap(ar, &ar->pdev->cap, NULL);
4123 ath11k_mac_setup_he_cap(ar, &ar->pdev->cap);
4128 int ath11k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx)
4130 struct sk_buff *msdu = skb;
4131 struct ieee80211_tx_info *info;
4132 struct ath11k *ar = ctx;
4133 struct ath11k_base *ab = ar->ab;
4135 spin_lock_bh(&ar->txmgmt_idr_lock);
4136 idr_remove(&ar->txmgmt_idr, buf_id);
4137 spin_unlock_bh(&ar->txmgmt_idr_lock);
4138 dma_unmap_single(ab->dev, ATH11K_SKB_CB(msdu)->paddr, msdu->len,
4141 info = IEEE80211_SKB_CB(msdu);
4142 memset(&info->status, 0, sizeof(info->status));
4144 ieee80211_free_txskb(ar->hw, msdu);
4149 static int ath11k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx)
4151 struct ieee80211_vif *vif = ctx;
4152 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb);
4153 struct sk_buff *msdu = skb;
4154 struct ath11k *ar = skb_cb->ar;
4155 struct ath11k_base *ab = ar->ab;
4157 if (skb_cb->vif == vif) {
4158 spin_lock_bh(&ar->txmgmt_idr_lock);
4159 idr_remove(&ar->txmgmt_idr, buf_id);
4160 spin_unlock_bh(&ar->txmgmt_idr_lock);
4161 dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len,
4168 static int ath11k_mac_mgmt_tx_wmi(struct ath11k *ar, struct ath11k_vif *arvif,
4169 struct sk_buff *skb)
4171 struct ath11k_base *ab = ar->ab;
4172 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
4173 struct ieee80211_tx_info *info;
4178 spin_lock_bh(&ar->txmgmt_idr_lock);
4179 buf_id = idr_alloc(&ar->txmgmt_idr, skb, 0,
4180 ATH11K_TX_MGMT_NUM_PENDING_MAX, GFP_ATOMIC);
4181 spin_unlock_bh(&ar->txmgmt_idr_lock);
4185 info = IEEE80211_SKB_CB(skb);
4186 if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) {
4187 if ((ieee80211_is_action(hdr->frame_control) ||
4188 ieee80211_is_deauth(hdr->frame_control) ||
4189 ieee80211_is_disassoc(hdr->frame_control)) &&
4190 ieee80211_has_protected(hdr->frame_control)) {
4191 skb_put(skb, IEEE80211_CCMP_MIC_LEN);
4195 paddr = dma_map_single(ab->dev, skb->data, skb->len, DMA_TO_DEVICE);
4196 if (dma_mapping_error(ab->dev, paddr)) {
4197 ath11k_warn(ab, "failed to DMA map mgmt Tx buffer\n");
4202 ATH11K_SKB_CB(skb)->paddr = paddr;
4204 ret = ath11k_wmi_mgmt_send(ar, arvif->vdev_id, buf_id, skb);
4206 ath11k_warn(ar->ab, "failed to send mgmt frame: %d\n", ret);
4213 dma_unmap_single(ab->dev, ATH11K_SKB_CB(skb)->paddr,
4214 skb->len, DMA_TO_DEVICE);
4216 spin_lock_bh(&ar->txmgmt_idr_lock);
4217 idr_remove(&ar->txmgmt_idr, buf_id);
4218 spin_unlock_bh(&ar->txmgmt_idr_lock);
4223 static void ath11k_mgmt_over_wmi_tx_purge(struct ath11k *ar)
4225 struct sk_buff *skb;
4227 while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL)
4228 ieee80211_free_txskb(ar->hw, skb);
4231 static void ath11k_mgmt_over_wmi_tx_work(struct work_struct *work)
4233 struct ath11k *ar = container_of(work, struct ath11k, wmi_mgmt_tx_work);
4234 struct ath11k_skb_cb *skb_cb;
4235 struct ath11k_vif *arvif;
4236 struct sk_buff *skb;
4239 while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) {
4240 skb_cb = ATH11K_SKB_CB(skb);
4242 ath11k_warn(ar->ab, "no vif found for mgmt frame\n");
4243 ieee80211_free_txskb(ar->hw, skb);
4247 arvif = ath11k_vif_to_arvif(skb_cb->vif);
4248 if (ar->allocated_vdev_map & (1LL << arvif->vdev_id) &&
4249 arvif->is_started) {
4250 ret = ath11k_mac_mgmt_tx_wmi(ar, arvif, skb);
4252 ath11k_warn(ar->ab, "failed to tx mgmt frame, vdev_id %d :%d\n",
4253 arvif->vdev_id, ret);
4254 ieee80211_free_txskb(ar->hw, skb);
4256 atomic_inc(&ar->num_pending_mgmt_tx);
4260 "dropping mgmt frame for vdev %d, is_started %d\n",
4263 ieee80211_free_txskb(ar->hw, skb);
4268 static int ath11k_mac_mgmt_tx(struct ath11k *ar, struct sk_buff *skb,
4271 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
4273 if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))
4276 /* Drop probe response packets when the pending management tx
4277 * count has reached a certain threshold, so as to prioritize
4278 * other mgmt packets like auth and assoc to be sent on time
4279 * for establishing successful connections.
4282 atomic_read(&ar->num_pending_mgmt_tx) > ATH11K_PRB_RSP_DROP_THRESHOLD) {
4284 "dropping probe response as pending queue is almost full\n");
4288 if (skb_queue_len_lockless(q) >= ATH11K_TX_MGMT_NUM_PENDING_MAX) {
4289 ath11k_warn(ar->ab, "mgmt tx queue is full\n");
4293 skb_queue_tail(q, skb);
4294 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
4299 static void ath11k_mac_op_tx(struct ieee80211_hw *hw,
4300 struct ieee80211_tx_control *control,
4301 struct sk_buff *skb)
4303 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb);
4304 struct ath11k *ar = hw->priv;
4305 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4306 struct ieee80211_vif *vif = info->control.vif;
4307 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4308 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
4309 struct ieee80211_key_conf *key = info->control.hw_key;
4310 u32 info_flags = info->flags;
4314 memset(skb_cb, 0, sizeof(*skb_cb));
4318 skb_cb->cipher = key->cipher;
4319 skb_cb->flags |= ATH11K_SKB_CIPHER_SET;
4322 if (info_flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
4323 skb_cb->flags |= ATH11K_SKB_HW_80211_ENCAP;
4324 } else if (ieee80211_is_mgmt(hdr->frame_control)) {
4325 is_prb_rsp = ieee80211_is_probe_resp(hdr->frame_control);
4326 ret = ath11k_mac_mgmt_tx(ar, skb, is_prb_rsp);
4328 ath11k_warn(ar->ab, "failed to queue management frame %d\n",
4330 ieee80211_free_txskb(ar->hw, skb);
4335 ret = ath11k_dp_tx(ar, arvif, skb);
4337 ath11k_warn(ar->ab, "failed to transmit frame %d\n", ret);
4338 ieee80211_free_txskb(ar->hw, skb);
4342 void ath11k_mac_drain_tx(struct ath11k *ar)
4344 /* make sure rcu-protected mac80211 tx path itself is drained */
4347 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4348 ath11k_mgmt_over_wmi_tx_purge(ar);
4351 static int ath11k_mac_config_mon_status_default(struct ath11k *ar, bool enable)
4353 struct htt_rx_ring_tlv_filter tlv_filter = {0};
4354 struct ath11k_base *ab = ar->ab;
4359 tlv_filter = ath11k_mac_mon_status_filter_default;
4360 if (ath11k_debugfs_rx_filter(ar))
4361 tlv_filter.rx_filter = ath11k_debugfs_rx_filter(ar);
4364 for (i = 0; i < ab->hw_params.num_rxmda_per_pdev; i++) {
4365 ring_id = ar->dp.rx_mon_status_refill_ring[i].refill_buf_ring.ring_id;
4366 ret = ath11k_dp_tx_htt_rx_filter_setup(ar->ab, ring_id,
4368 HAL_RXDMA_MONITOR_STATUS,
4373 if (enable && !ar->ab->hw_params.rxdma1_enable)
4374 mod_timer(&ar->ab->mon_reap_timer, jiffies +
4375 msecs_to_jiffies(ATH11K_MON_TIMER_INTERVAL));
4380 static int ath11k_mac_op_start(struct ieee80211_hw *hw)
4382 struct ath11k *ar = hw->priv;
4383 struct ath11k_base *ab = ar->ab;
4384 struct ath11k_pdev *pdev = ar->pdev;
4387 ath11k_mac_drain_tx(ar);
4388 mutex_lock(&ar->conf_mutex);
4390 switch (ar->state) {
4391 case ATH11K_STATE_OFF:
4392 ar->state = ATH11K_STATE_ON;
4394 case ATH11K_STATE_RESTARTING:
4395 ar->state = ATH11K_STATE_RESTARTED;
4397 case ATH11K_STATE_RESTARTED:
4398 case ATH11K_STATE_WEDGED:
4399 case ATH11K_STATE_ON:
4405 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS,
4409 ath11k_err(ar->ab, "failed to enable PMF QOS: (%d\n", ret);
4413 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 1,
4416 ath11k_err(ar->ab, "failed to enable dynamic bw: %d\n", ret);
4420 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
4423 ath11k_err(ab, "failed to set ac override for ARP: %d\n",
4428 ret = ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(ar, pdev->pdev_id);
4430 ath11k_err(ab, "failed to offload radar detection: %d\n",
4435 ret = ath11k_dp_tx_htt_h2t_ppdu_stats_req(ar,
4436 HTT_PPDU_STATS_TAG_DEFAULT);
4438 ath11k_err(ab, "failed to req ppdu stats: %d\n", ret);
4442 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_MESH_MCAST_ENABLE,
4446 ath11k_err(ar->ab, "failed to enable MESH MCAST ENABLE: (%d\n", ret);
4450 __ath11k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4452 /* TODO: Do we need to enable ANI? */
4454 ath11k_reg_update_chan_list(ar);
4456 ar->num_started_vdevs = 0;
4457 ar->num_created_vdevs = 0;
4459 ar->allocated_vdev_map = 0;
4461 /* Configure monitor status ring with default rx_filter to get rx status
4462 * such as rssi, rx_duration.
4464 ret = ath11k_mac_config_mon_status_default(ar, true);
4466 ath11k_err(ab, "failed to configure monitor status ring with default rx_filter: (%d)\n",
4471 /* Configure the hash seed for hash based reo dest ring selection */
4472 ath11k_wmi_pdev_lro_cfg(ar, ar->pdev->pdev_id);
4474 /* allow device to enter IMPS */
4475 if (ab->hw_params.idle_ps) {
4476 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_IDLE_PS_CONFIG,
4479 ath11k_err(ab, "failed to enable idle ps: %d\n", ret);
4484 mutex_unlock(&ar->conf_mutex);
4486 rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx],
4487 &ab->pdevs[ar->pdev_idx]);
4492 ar->state = ATH11K_STATE_OFF;
4493 mutex_unlock(&ar->conf_mutex);
4498 static void ath11k_mac_op_stop(struct ieee80211_hw *hw)
4500 struct ath11k *ar = hw->priv;
4501 struct htt_ppdu_stats_info *ppdu_stats, *tmp;
4504 ath11k_mac_drain_tx(ar);
4506 mutex_lock(&ar->conf_mutex);
4507 ret = ath11k_mac_config_mon_status_default(ar, false);
4509 ath11k_err(ar->ab, "failed to clear rx_filter for monitor status ring: (%d)\n",
4512 clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
4513 ar->state = ATH11K_STATE_OFF;
4514 mutex_unlock(&ar->conf_mutex);
4516 cancel_delayed_work_sync(&ar->scan.timeout);
4517 cancel_work_sync(&ar->regd_update_work);
4519 spin_lock_bh(&ar->data_lock);
4520 list_for_each_entry_safe(ppdu_stats, tmp, &ar->ppdu_stats_info, list) {
4521 list_del(&ppdu_stats->list);
4524 spin_unlock_bh(&ar->data_lock);
4526 rcu_assign_pointer(ar->ab->pdevs_active[ar->pdev_idx], NULL);
4530 atomic_set(&ar->num_pending_mgmt_tx, 0);
4534 ath11k_mac_setup_vdev_create_params(struct ath11k_vif *arvif,
4535 struct vdev_create_params *params)
4537 struct ath11k *ar = arvif->ar;
4538 struct ath11k_pdev *pdev = ar->pdev;
4540 params->if_id = arvif->vdev_id;
4541 params->type = arvif->vdev_type;
4542 params->subtype = arvif->vdev_subtype;
4543 params->pdev_id = pdev->pdev_id;
4545 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) {
4546 params->chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains;
4547 params->chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains;
4549 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) {
4550 params->chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains;
4551 params->chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains;
4553 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP &&
4554 ar->supports_6ghz) {
4555 params->chains[NL80211_BAND_6GHZ].tx = ar->num_tx_chains;
4556 params->chains[NL80211_BAND_6GHZ].rx = ar->num_rx_chains;
4561 ath11k_mac_prepare_he_mode(struct ath11k_pdev *pdev, u32 viftype)
4563 struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
4564 struct ath11k_band_cap *cap_band = NULL;
4565 u32 *hecap_phy_ptr = NULL;
4568 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP)
4569 cap_band = &pdev_cap->band[NL80211_BAND_2GHZ];
4571 cap_band = &pdev_cap->band[NL80211_BAND_5GHZ];
4573 hecap_phy_ptr = &cap_band->he_cap_phy_info[0];
4575 hemode = FIELD_PREP(HE_MODE_SU_TX_BFEE, HE_SU_BFEE_ENABLE) |
4576 FIELD_PREP(HE_MODE_SU_TX_BFER, HECAP_PHY_SUBFMR_GET(hecap_phy_ptr)) |
4577 FIELD_PREP(HE_MODE_UL_MUMIMO, HECAP_PHY_ULMUMIMO_GET(hecap_phy_ptr));
4579 /* TODO WDS and other modes */
4580 if (viftype == NL80211_IFTYPE_AP) {
4581 hemode |= FIELD_PREP(HE_MODE_MU_TX_BFER,
4582 HECAP_PHY_MUBFMR_GET(hecap_phy_ptr)) |
4583 FIELD_PREP(HE_MODE_DL_OFDMA, HE_DL_MUOFDMA_ENABLE) |
4584 FIELD_PREP(HE_MODE_UL_OFDMA, HE_UL_MUOFDMA_ENABLE);
4586 hemode |= FIELD_PREP(HE_MODE_MU_TX_BFEE, HE_MU_BFEE_ENABLE);
4592 static int ath11k_set_he_mu_sounding_mode(struct ath11k *ar,
4593 struct ath11k_vif *arvif)
4595 u32 param_id, param_value;
4596 struct ath11k_base *ab = ar->ab;
4599 param_id = WMI_VDEV_PARAM_SET_HEMU_MODE;
4600 param_value = ath11k_mac_prepare_he_mode(ar->pdev, arvif->vif->type);
4601 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4602 param_id, param_value);
4604 ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d param_value %x\n",
4605 arvif->vdev_id, ret, param_value);
4608 param_id = WMI_VDEV_PARAM_SET_HE_SOUNDING_MODE;
4610 FIELD_PREP(HE_VHT_SOUNDING_MODE, HE_VHT_SOUNDING_MODE_ENABLE) |
4611 FIELD_PREP(HE_TRIG_NONTRIG_SOUNDING_MODE,
4612 HE_TRIG_NONTRIG_SOUNDING_MODE_ENABLE);
4613 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4614 param_id, param_value);
4616 ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d\n",
4617 arvif->vdev_id, ret);
4623 static void ath11k_mac_op_update_vif_offload(struct ieee80211_hw *hw,
4624 struct ieee80211_vif *vif)
4626 struct ath11k *ar = hw->priv;
4627 struct ath11k_base *ab = ar->ab;
4628 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4629 u32 param_id, param_value;
4632 param_id = WMI_VDEV_PARAM_TX_ENCAP_TYPE;
4633 if (ath11k_frame_mode != ATH11K_HW_TXRX_ETHERNET ||
4634 (vif->type != NL80211_IFTYPE_STATION &&
4635 vif->type != NL80211_IFTYPE_AP))
4636 vif->offload_flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
4638 if (vif->offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED)
4639 param_value = ATH11K_HW_TXRX_ETHERNET;
4640 else if (test_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags))
4641 param_value = ATH11K_HW_TXRX_RAW;
4643 param_value = ATH11K_HW_TXRX_NATIVE_WIFI;
4645 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4646 param_id, param_value);
4648 ath11k_warn(ab, "failed to set vdev %d tx encap mode: %d\n",
4649 arvif->vdev_id, ret);
4650 vif->offload_flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
4654 static int ath11k_mac_op_add_interface(struct ieee80211_hw *hw,
4655 struct ieee80211_vif *vif)
4657 struct ath11k *ar = hw->priv;
4658 struct ath11k_base *ab = ar->ab;
4659 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4660 struct vdev_create_params vdev_param = {0};
4661 struct peer_create_params peer_param;
4662 u32 param_id, param_value;
4668 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4670 mutex_lock(&ar->conf_mutex);
4672 if (vif->type == NL80211_IFTYPE_AP &&
4673 ar->num_peers > (ar->max_num_peers - 1)) {
4674 ath11k_warn(ab, "failed to create vdev due to insufficient peer entry resource in firmware\n");
4679 if (ar->num_created_vdevs > (TARGET_NUM_VDEVS - 1)) {
4680 ath11k_warn(ab, "failed to create vdev, reached max vdev limit %d\n",
4686 memset(arvif, 0, sizeof(*arvif));
4691 INIT_LIST_HEAD(&arvif->list);
4692 INIT_DELAYED_WORK(&arvif->connection_loss_work,
4693 ath11k_mac_vif_sta_connection_loss_work);
4695 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4696 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4697 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4698 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4699 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4700 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4703 bit = __ffs64(ab->free_vdev_map);
4705 arvif->vdev_id = bit;
4706 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
4708 switch (vif->type) {
4709 case NL80211_IFTYPE_UNSPECIFIED:
4710 case NL80211_IFTYPE_STATION:
4711 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4713 case NL80211_IFTYPE_MESH_POINT:
4714 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_MESH_11S;
4716 case NL80211_IFTYPE_AP:
4717 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4719 case NL80211_IFTYPE_MONITOR:
4720 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4727 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac add interface id %d type %d subtype %d map %llx\n",
4728 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4731 vif->cab_queue = arvif->vdev_id % (ATH11K_HW_MAX_QUEUES - 1);
4732 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4733 vif->hw_queue[i] = i % (ATH11K_HW_MAX_QUEUES - 1);
4735 ath11k_mac_setup_vdev_create_params(arvif, &vdev_param);
4737 ret = ath11k_wmi_vdev_create(ar, vif->addr, &vdev_param);
4739 ath11k_warn(ab, "failed to create WMI vdev %d: %d\n",
4740 arvif->vdev_id, ret);
4744 ar->num_created_vdevs++;
4745 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM created, vdev_id %d\n",
4746 vif->addr, arvif->vdev_id);
4747 ar->allocated_vdev_map |= 1LL << arvif->vdev_id;
4748 ab->free_vdev_map &= ~(1LL << arvif->vdev_id);
4750 spin_lock_bh(&ar->data_lock);
4751 list_add(&arvif->list, &ar->arvifs);
4752 spin_unlock_bh(&ar->data_lock);
4754 ath11k_mac_op_update_vif_offload(hw, vif);
4756 nss = get_num_chains(ar->cfg_tx_chainmask) ? : 1;
4757 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4758 WMI_VDEV_PARAM_NSS, nss);
4760 ath11k_warn(ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n",
4761 arvif->vdev_id, ar->cfg_tx_chainmask, nss, ret);
4765 switch (arvif->vdev_type) {
4766 case WMI_VDEV_TYPE_AP:
4767 peer_param.vdev_id = arvif->vdev_id;
4768 peer_param.peer_addr = vif->addr;
4769 peer_param.peer_type = WMI_PEER_TYPE_DEFAULT;
4770 ret = ath11k_peer_create(ar, arvif, NULL, &peer_param);
4772 ath11k_warn(ab, "failed to vdev %d create peer for AP: %d\n",
4773 arvif->vdev_id, ret);
4777 ret = ath11k_mac_set_kickout(arvif);
4779 ath11k_warn(ar->ab, "failed to set vdev %i kickout parameters: %d\n",
4780 arvif->vdev_id, ret);
4784 case WMI_VDEV_TYPE_STA:
4785 param_id = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4786 param_value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4787 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4788 param_id, param_value);
4790 ath11k_warn(ar->ab, "failed to set vdev %d RX wake policy: %d\n",
4791 arvif->vdev_id, ret);
4795 param_id = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
4796 param_value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
4797 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4798 param_id, param_value);
4800 ath11k_warn(ar->ab, "failed to set vdev %d TX wake threshold: %d\n",
4801 arvif->vdev_id, ret);
4805 param_id = WMI_STA_PS_PARAM_PSPOLL_COUNT;
4806 param_value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
4807 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4808 param_id, param_value);
4810 ath11k_warn(ar->ab, "failed to set vdev %d pspoll count: %d\n",
4811 arvif->vdev_id, ret);
4815 ret = ath11k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, false);
4817 ath11k_warn(ar->ab, "failed to disable vdev %d ps mode: %d\n",
4818 arvif->vdev_id, ret);
4826 arvif->txpower = vif->bss_conf.txpower;
4827 ret = ath11k_mac_txpower_recalc(ar);
4831 param_id = WMI_VDEV_PARAM_RTS_THRESHOLD;
4832 param_value = ar->hw->wiphy->rts_threshold;
4833 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4834 param_id, param_value);
4836 ath11k_warn(ar->ab, "failed to set rts threshold for vdev %d: %d\n",
4837 arvif->vdev_id, ret);
4840 ath11k_dp_vdev_tx_attach(ar, arvif);
4842 mutex_unlock(&ar->conf_mutex);
4847 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4848 reinit_completion(&ar->peer_delete_done);
4850 ret = ath11k_wmi_send_peer_delete_cmd(ar, vif->addr,
4853 ath11k_warn(ar->ab, "failed to delete peer vdev_id %d addr %pM\n",
4854 arvif->vdev_id, vif->addr);
4858 ret = ath11k_wait_for_peer_delete_done(ar, arvif->vdev_id,
4867 ath11k_wmi_vdev_delete(ar, arvif->vdev_id);
4868 ar->num_created_vdevs--;
4869 ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id);
4870 ab->free_vdev_map |= 1LL << arvif->vdev_id;
4871 spin_lock_bh(&ar->data_lock);
4872 list_del(&arvif->list);
4873 spin_unlock_bh(&ar->data_lock);
4876 mutex_unlock(&ar->conf_mutex);
4881 static int ath11k_mac_vif_unref(int buf_id, void *skb, void *ctx)
4883 struct ieee80211_vif *vif = (struct ieee80211_vif *)ctx;
4884 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb);
4886 if (skb_cb->vif == vif)
4892 static void ath11k_mac_op_remove_interface(struct ieee80211_hw *hw,
4893 struct ieee80211_vif *vif)
4895 struct ath11k *ar = hw->priv;
4896 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4897 struct ath11k_base *ab = ar->ab;
4898 unsigned long time_left;
4902 cancel_delayed_work_sync(&arvif->connection_loss_work);
4904 mutex_lock(&ar->conf_mutex);
4906 ath11k_dbg(ab, ATH11K_DBG_MAC, "mac remove interface (vdev %d)\n",
4909 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4910 ret = ath11k_peer_delete(ar, arvif->vdev_id, vif->addr);
4912 ath11k_warn(ab, "failed to submit AP self-peer removal on vdev %d: %d\n",
4913 arvif->vdev_id, ret);
4916 reinit_completion(&ar->vdev_delete_done);
4918 ret = ath11k_wmi_vdev_delete(ar, arvif->vdev_id);
4920 ath11k_warn(ab, "failed to delete WMI vdev %d: %d\n",
4921 arvif->vdev_id, ret);
4925 time_left = wait_for_completion_timeout(&ar->vdev_delete_done,
4926 ATH11K_VDEV_DELETE_TIMEOUT_HZ);
4927 if (time_left == 0) {
4928 ath11k_warn(ab, "Timeout in receiving vdev delete response\n");
4932 ab->free_vdev_map |= 1LL << (arvif->vdev_id);
4933 ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id);
4934 ar->num_created_vdevs--;
4936 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM deleted, vdev_id %d\n",
4937 vif->addr, arvif->vdev_id);
4940 spin_lock_bh(&ar->data_lock);
4941 list_del(&arvif->list);
4942 spin_unlock_bh(&ar->data_lock);
4944 ath11k_peer_cleanup(ar, arvif->vdev_id);
4946 idr_for_each(&ar->txmgmt_idr,
4947 ath11k_mac_vif_txmgmt_idr_remove, vif);
4949 for (i = 0; i < DP_TCL_NUM_RING_MAX; i++) {
4950 spin_lock_bh(&ab->dp.tx_ring[i].tx_idr_lock);
4951 idr_for_each(&ab->dp.tx_ring[i].txbuf_idr,
4952 ath11k_mac_vif_unref, vif);
4953 spin_unlock_bh(&ab->dp.tx_ring[i].tx_idr_lock);
4956 /* Recalc txpower for remaining vdev */
4957 ath11k_mac_txpower_recalc(ar);
4958 clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags);
4960 /* TODO: recal traffic pause state based on the available vdevs */
4962 mutex_unlock(&ar->conf_mutex);
4965 /* FIXME: Has to be verified. */
4966 #define SUPPORTED_FILTERS \
4971 FIF_BCN_PRBRESP_PROMISC | \
4975 static void ath11k_mac_op_configure_filter(struct ieee80211_hw *hw,
4976 unsigned int changed_flags,
4977 unsigned int *total_flags,
4980 struct ath11k *ar = hw->priv;
4981 bool reset_flag = false;
4984 mutex_lock(&ar->conf_mutex);
4986 changed_flags &= SUPPORTED_FILTERS;
4987 *total_flags &= SUPPORTED_FILTERS;
4988 ar->filter_flags = *total_flags;
4990 /* For monitor mode */
4991 reset_flag = !(ar->filter_flags & FIF_BCN_PRBRESP_PROMISC);
4993 ret = ath11k_dp_tx_htt_monitor_mode_ring_config(ar, reset_flag);
4996 set_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags);
4998 clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags);
5001 "fail to set monitor filter: %d\n", ret);
5003 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
5004 "changed_flags:0x%x, total_flags:0x%x, reset_flag:%d\n",
5005 changed_flags, *total_flags, reset_flag);
5007 mutex_unlock(&ar->conf_mutex);
5010 static int ath11k_mac_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
5012 struct ath11k *ar = hw->priv;
5014 mutex_lock(&ar->conf_mutex);
5016 *tx_ant = ar->cfg_tx_chainmask;
5017 *rx_ant = ar->cfg_rx_chainmask;
5019 mutex_unlock(&ar->conf_mutex);
5024 static int ath11k_mac_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
5026 struct ath11k *ar = hw->priv;
5029 mutex_lock(&ar->conf_mutex);
5030 ret = __ath11k_set_antenna(ar, tx_ant, rx_ant);
5031 mutex_unlock(&ar->conf_mutex);
5036 static int ath11k_mac_op_ampdu_action(struct ieee80211_hw *hw,
5037 struct ieee80211_vif *vif,
5038 struct ieee80211_ampdu_params *params)
5040 struct ath11k *ar = hw->priv;
5043 mutex_lock(&ar->conf_mutex);
5045 switch (params->action) {
5046 case IEEE80211_AMPDU_RX_START:
5047 ret = ath11k_dp_rx_ampdu_start(ar, params);
5049 case IEEE80211_AMPDU_RX_STOP:
5050 ret = ath11k_dp_rx_ampdu_stop(ar, params);
5052 case IEEE80211_AMPDU_TX_START:
5053 case IEEE80211_AMPDU_TX_STOP_CONT:
5054 case IEEE80211_AMPDU_TX_STOP_FLUSH:
5055 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
5056 case IEEE80211_AMPDU_TX_OPERATIONAL:
5057 /* Tx A-MPDU aggregation offloaded to hw/fw so deny mac80211
5058 * Tx aggregation requests.
5064 mutex_unlock(&ar->conf_mutex);
5069 static int ath11k_mac_op_add_chanctx(struct ieee80211_hw *hw,
5070 struct ieee80211_chanctx_conf *ctx)
5072 struct ath11k *ar = hw->priv;
5073 struct ath11k_base *ab = ar->ab;
5075 ath11k_dbg(ab, ATH11K_DBG_MAC,
5076 "mac chanctx add freq %u width %d ptr %pK\n",
5077 ctx->def.chan->center_freq, ctx->def.width, ctx);
5079 mutex_lock(&ar->conf_mutex);
5081 spin_lock_bh(&ar->data_lock);
5082 /* TODO: In case of multiple channel context, populate rx_channel from
5083 * Rx PPDU desc information.
5085 ar->rx_channel = ctx->def.chan;
5086 spin_unlock_bh(&ar->data_lock);
5088 mutex_unlock(&ar->conf_mutex);
5093 static void ath11k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
5094 struct ieee80211_chanctx_conf *ctx)
5096 struct ath11k *ar = hw->priv;
5097 struct ath11k_base *ab = ar->ab;
5099 ath11k_dbg(ab, ATH11K_DBG_MAC,
5100 "mac chanctx remove freq %u width %d ptr %pK\n",
5101 ctx->def.chan->center_freq, ctx->def.width, ctx);
5103 mutex_lock(&ar->conf_mutex);
5105 spin_lock_bh(&ar->data_lock);
5106 /* TODO: In case of there is one more channel context left, populate
5107 * rx_channel with the channel of that remaining channel context.
5109 ar->rx_channel = NULL;
5110 spin_unlock_bh(&ar->data_lock);
5112 mutex_unlock(&ar->conf_mutex);
5115 static inline int ath11k_mac_vdev_setup_sync(struct ath11k *ar)
5117 lockdep_assert_held(&ar->conf_mutex);
5119 if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))
5122 if (!wait_for_completion_timeout(&ar->vdev_setup_done,
5123 ATH11K_VDEV_SETUP_TIMEOUT_HZ))
5126 return ar->last_wmi_vdev_start_status ? -EINVAL : 0;
5130 ath11k_mac_vdev_start_restart(struct ath11k_vif *arvif,
5131 const struct cfg80211_chan_def *chandef,
5134 struct ath11k *ar = arvif->ar;
5135 struct ath11k_base *ab = ar->ab;
5136 struct wmi_vdev_start_req_arg arg = {};
5137 int he_support = arvif->vif->bss_conf.he_support;
5140 lockdep_assert_held(&ar->conf_mutex);
5142 reinit_completion(&ar->vdev_setup_done);
5144 arg.vdev_id = arvif->vdev_id;
5145 arg.dtim_period = arvif->dtim_period;
5146 arg.bcn_intval = arvif->beacon_interval;
5148 arg.channel.freq = chandef->chan->center_freq;
5149 arg.channel.band_center_freq1 = chandef->center_freq1;
5150 arg.channel.band_center_freq2 = chandef->center_freq2;
5152 ath11k_phymodes[chandef->chan->band][chandef->width];
5154 arg.channel.min_power = 0;
5155 arg.channel.max_power = chandef->chan->max_power * 2;
5156 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
5157 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
5159 arg.pref_tx_streams = ar->num_tx_chains;
5160 arg.pref_rx_streams = ar->num_rx_chains;
5162 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
5163 arg.ssid = arvif->u.ap.ssid;
5164 arg.ssid_len = arvif->u.ap.ssid_len;
5165 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
5167 /* For now allow DFS for AP mode */
5168 arg.channel.chan_radar =
5169 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
5171 arg.channel.freq2_radar =
5172 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
5174 arg.channel.passive = arg.channel.chan_radar;
5176 spin_lock_bh(&ab->base_lock);
5177 arg.regdomain = ar->ab->dfs_region;
5178 spin_unlock_bh(&ab->base_lock);
5181 ret = ath11k_set_he_mu_sounding_mode(ar, arvif);
5183 ath11k_warn(ar->ab, "failed to set he mode vdev %i\n",
5190 arg.channel.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR);
5192 ath11k_dbg(ab, ATH11K_DBG_MAC,
5193 "mac vdev %d start center_freq %d phymode %s\n",
5194 arg.vdev_id, arg.channel.freq,
5195 ath11k_wmi_phymode_str(arg.channel.mode));
5197 ret = ath11k_wmi_vdev_start(ar, &arg, restart);
5199 ath11k_warn(ar->ab, "failed to %s WMI vdev %i\n",
5200 restart ? "restart" : "start", arg.vdev_id);
5204 ret = ath11k_mac_vdev_setup_sync(ar);
5206 ath11k_warn(ab, "failed to synchronize setup for vdev %i %s: %d\n",
5207 arg.vdev_id, restart ? "restart" : "start", ret);
5211 ar->num_started_vdevs++;
5212 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM started, vdev_id %d\n",
5213 arvif->vif->addr, arvif->vdev_id);
5215 /* Enable CAC Flag in the driver by checking the channel DFS cac time,
5216 * i.e dfs_cac_ms value which will be valid only for radar channels
5217 * and state as NL80211_DFS_USABLE which indicates CAC needs to be
5218 * done before channel usage. This flags is used to drop rx packets.
5221 /* TODO Set the flag for other interface types as required */
5222 if (arvif->vdev_type == WMI_VDEV_TYPE_AP &&
5223 chandef->chan->dfs_cac_ms &&
5224 chandef->chan->dfs_state == NL80211_DFS_USABLE) {
5225 set_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
5226 ath11k_dbg(ab, ATH11K_DBG_MAC,
5227 "CAC Started in chan_freq %d for vdev %d\n",
5228 arg.channel.freq, arg.vdev_id);
5231 ret = ath11k_mac_set_txbf_conf(arvif);
5233 ath11k_warn(ab, "failed to set txbf conf for vdev %d: %d\n",
5234 arvif->vdev_id, ret);
5239 static int ath11k_mac_vdev_stop(struct ath11k_vif *arvif)
5241 struct ath11k *ar = arvif->ar;
5244 lockdep_assert_held(&ar->conf_mutex);
5246 reinit_completion(&ar->vdev_setup_done);
5248 ret = ath11k_wmi_vdev_stop(ar, arvif->vdev_id);
5250 ath11k_warn(ar->ab, "failed to stop WMI vdev %i: %d\n",
5251 arvif->vdev_id, ret);
5255 ret = ath11k_mac_vdev_setup_sync(ar);
5257 ath11k_warn(ar->ab, "failed to synchronize setup for vdev %i: %d\n",
5258 arvif->vdev_id, ret);
5262 WARN_ON(ar->num_started_vdevs == 0);
5264 ar->num_started_vdevs--;
5265 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "vdev %pM stopped, vdev_id %d\n",
5266 arvif->vif->addr, arvif->vdev_id);
5268 if (test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) {
5269 clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
5270 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "CAC Stopped for vdev %d\n",
5279 static int ath11k_mac_vdev_start(struct ath11k_vif *arvif,
5280 const struct cfg80211_chan_def *chandef)
5282 return ath11k_mac_vdev_start_restart(arvif, chandef, false);
5285 static int ath11k_mac_vdev_restart(struct ath11k_vif *arvif,
5286 const struct cfg80211_chan_def *chandef)
5288 return ath11k_mac_vdev_start_restart(arvif, chandef, true);
5291 struct ath11k_mac_change_chanctx_arg {
5292 struct ieee80211_chanctx_conf *ctx;
5293 struct ieee80211_vif_chanctx_switch *vifs;
5299 ath11k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
5300 struct ieee80211_vif *vif)
5302 struct ath11k_mac_change_chanctx_arg *arg = data;
5304 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
5311 ath11k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
5312 struct ieee80211_vif *vif)
5314 struct ath11k_mac_change_chanctx_arg *arg = data;
5315 struct ieee80211_chanctx_conf *ctx;
5317 ctx = rcu_access_pointer(vif->chanctx_conf);
5318 if (ctx != arg->ctx)
5321 if (WARN_ON(arg->next_vif == arg->n_vifs))
5324 arg->vifs[arg->next_vif].vif = vif;
5325 arg->vifs[arg->next_vif].old_ctx = ctx;
5326 arg->vifs[arg->next_vif].new_ctx = ctx;
5331 ath11k_mac_update_vif_chan(struct ath11k *ar,
5332 struct ieee80211_vif_chanctx_switch *vifs,
5335 struct ath11k_base *ab = ar->ab;
5336 struct ath11k_vif *arvif;
5340 lockdep_assert_held(&ar->conf_mutex);
5342 for (i = 0; i < n_vifs; i++) {
5343 arvif = (void *)vifs[i].vif->drv_priv;
5345 ath11k_dbg(ab, ATH11K_DBG_MAC,
5346 "mac chanctx switch vdev_id %i freq %u->%u width %d->%d\n",
5348 vifs[i].old_ctx->def.chan->center_freq,
5349 vifs[i].new_ctx->def.chan->center_freq,
5350 vifs[i].old_ctx->def.width,
5351 vifs[i].new_ctx->def.width);
5353 if (WARN_ON(!arvif->is_started))
5356 if (WARN_ON(!arvif->is_up))
5359 ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id);
5361 ath11k_warn(ab, "failed to down vdev %d: %d\n",
5362 arvif->vdev_id, ret);
5367 /* All relevant vdevs are downed and associated channel resources
5368 * should be available for the channel switch now.
5371 /* TODO: Update ar->rx_channel */
5373 for (i = 0; i < n_vifs; i++) {
5374 arvif = (void *)vifs[i].vif->drv_priv;
5376 if (WARN_ON(!arvif->is_started))
5379 if (WARN_ON(!arvif->is_up))
5382 ret = ath11k_mac_setup_bcn_tmpl(arvif);
5384 ath11k_warn(ab, "failed to update bcn tmpl during csa: %d\n",
5387 ret = ath11k_mac_vdev_restart(arvif, &vifs[i].new_ctx->def);
5389 ath11k_warn(ab, "failed to restart vdev %d: %d\n",
5390 arvif->vdev_id, ret);
5394 ret = ath11k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
5397 ath11k_warn(ab, "failed to bring vdev up %d: %d\n",
5398 arvif->vdev_id, ret);
5405 ath11k_mac_update_active_vif_chan(struct ath11k *ar,
5406 struct ieee80211_chanctx_conf *ctx)
5408 struct ath11k_mac_change_chanctx_arg arg = { .ctx = ctx };
5410 lockdep_assert_held(&ar->conf_mutex);
5412 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5413 IEEE80211_IFACE_ITER_NORMAL,
5414 ath11k_mac_change_chanctx_cnt_iter,
5416 if (arg.n_vifs == 0)
5419 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]), GFP_KERNEL);
5423 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5424 IEEE80211_IFACE_ITER_NORMAL,
5425 ath11k_mac_change_chanctx_fill_iter,
5428 ath11k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
5433 static void ath11k_mac_op_change_chanctx(struct ieee80211_hw *hw,
5434 struct ieee80211_chanctx_conf *ctx,
5437 struct ath11k *ar = hw->priv;
5438 struct ath11k_base *ab = ar->ab;
5440 mutex_lock(&ar->conf_mutex);
5442 ath11k_dbg(ab, ATH11K_DBG_MAC,
5443 "mac chanctx change freq %u width %d ptr %pK changed %x\n",
5444 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
5446 /* This shouldn't really happen because channel switching should use
5447 * switch_vif_chanctx().
5449 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
5452 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH)
5453 ath11k_mac_update_active_vif_chan(ar, ctx);
5455 /* TODO: Recalc radar detection */
5458 mutex_unlock(&ar->conf_mutex);
5461 static int ath11k_start_vdev_delay(struct ieee80211_hw *hw,
5462 struct ieee80211_vif *vif)
5464 struct ath11k *ar = hw->priv;
5465 struct ath11k_base *ab = ar->ab;
5466 struct ath11k_vif *arvif = (void *)vif->drv_priv;
5469 if (WARN_ON(arvif->is_started))
5472 ret = ath11k_mac_vdev_start(arvif, &arvif->chanctx.def);
5474 ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
5475 arvif->vdev_id, vif->addr,
5476 arvif->chanctx.def.chan->center_freq, ret);
5480 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
5481 ret = ath11k_monitor_vdev_up(ar, arvif->vdev_id);
5483 ath11k_warn(ab, "failed put monitor up: %d\n", ret);
5488 arvif->is_started = true;
5490 /* TODO: Setup ps and cts/rts protection */
5495 ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
5496 struct ieee80211_vif *vif,
5497 struct ieee80211_chanctx_conf *ctx)
5499 struct ath11k *ar = hw->priv;
5500 struct ath11k_base *ab = ar->ab;
5501 struct ath11k_vif *arvif = (void *)vif->drv_priv;
5503 struct peer_create_params param;
5505 mutex_lock(&ar->conf_mutex);
5507 ath11k_dbg(ab, ATH11K_DBG_MAC,
5508 "mac chanctx assign ptr %pK vdev_id %i\n",
5509 ctx, arvif->vdev_id);
5511 /* for QCA6390 bss peer must be created before vdev_start */
5512 if (ab->hw_params.vdev_start_delay &&
5513 arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5514 arvif->vdev_type != WMI_VDEV_TYPE_MONITOR &&
5515 !ath11k_peer_find_by_vdev_id(ab, arvif->vdev_id)) {
5516 memcpy(&arvif->chanctx, ctx, sizeof(*ctx));
5521 if (WARN_ON(arvif->is_started)) {
5526 if (ab->hw_params.vdev_start_delay &&
5527 arvif->vdev_type != WMI_VDEV_TYPE_AP &&
5528 arvif->vdev_type != WMI_VDEV_TYPE_MONITOR) {
5529 param.vdev_id = arvif->vdev_id;
5530 param.peer_type = WMI_PEER_TYPE_DEFAULT;
5531 param.peer_addr = ar->mac_addr;
5533 ret = ath11k_peer_create(ar, arvif, NULL, ¶m);
5535 ath11k_warn(ab, "failed to create peer after vdev start delay: %d",
5541 ret = ath11k_mac_vdev_start(arvif, &ctx->def);
5543 ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
5544 arvif->vdev_id, vif->addr,
5545 ctx->def.chan->center_freq, ret);
5548 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
5549 ret = ath11k_monitor_vdev_up(ar, arvif->vdev_id);
5554 arvif->is_started = true;
5556 /* TODO: Setup ps and cts/rts protection */
5561 mutex_unlock(&ar->conf_mutex);
5567 ath11k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
5568 struct ieee80211_vif *vif,
5569 struct ieee80211_chanctx_conf *ctx)
5571 struct ath11k *ar = hw->priv;
5572 struct ath11k_base *ab = ar->ab;
5573 struct ath11k_vif *arvif = (void *)vif->drv_priv;
5576 mutex_lock(&ar->conf_mutex);
5578 ath11k_dbg(ab, ATH11K_DBG_MAC,
5579 "mac chanctx unassign ptr %pK vdev_id %i\n",
5580 ctx, arvif->vdev_id);
5582 WARN_ON(!arvif->is_started);
5584 if (ab->hw_params.vdev_start_delay &&
5585 arvif->vdev_type == WMI_VDEV_TYPE_MONITOR &&
5586 ath11k_peer_find_by_addr(ab, ar->mac_addr))
5587 ath11k_peer_delete(ar, arvif->vdev_id, ar->mac_addr);
5589 ret = ath11k_mac_vdev_stop(arvif);
5591 ath11k_warn(ab, "failed to stop vdev %i: %d\n",
5592 arvif->vdev_id, ret);
5594 arvif->is_started = false;
5596 if (ab->hw_params.vdev_start_delay &&
5597 arvif->vdev_type == WMI_VDEV_TYPE_MONITOR)
5598 ath11k_wmi_vdev_down(ar, arvif->vdev_id);
5600 mutex_unlock(&ar->conf_mutex);
5604 ath11k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
5605 struct ieee80211_vif_chanctx_switch *vifs,
5607 enum ieee80211_chanctx_switch_mode mode)
5609 struct ath11k *ar = hw->priv;
5611 mutex_lock(&ar->conf_mutex);
5613 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
5614 "mac chanctx switch n_vifs %d mode %d\n",
5616 ath11k_mac_update_vif_chan(ar, vifs, n_vifs);
5618 mutex_unlock(&ar->conf_mutex);
5624 ath11k_set_vdev_param_to_all_vifs(struct ath11k *ar, int param, u32 value)
5626 struct ath11k_vif *arvif;
5629 mutex_lock(&ar->conf_mutex);
5630 list_for_each_entry(arvif, &ar->arvifs, list) {
5631 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "setting mac vdev %d param %d value %d\n",
5632 param, arvif->vdev_id, value);
5634 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5637 ath11k_warn(ar->ab, "failed to set param %d for vdev %d: %d\n",
5638 param, arvif->vdev_id, ret);
5642 mutex_unlock(&ar->conf_mutex);
5646 /* mac80211 stores device specific RTS/Fragmentation threshold value,
5647 * this is set interface specific to firmware from ath11k driver
5649 static int ath11k_mac_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5651 struct ath11k *ar = hw->priv;
5652 int param_id = WMI_VDEV_PARAM_RTS_THRESHOLD;
5654 return ath11k_set_vdev_param_to_all_vifs(ar, param_id, value);
5657 static int ath11k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
5659 /* Even though there's a WMI vdev param for fragmentation threshold no
5660 * known firmware actually implements it. Moreover it is not possible to
5661 * rely frame fragmentation to mac80211 because firmware clears the
5662 * "more fragments" bit in frame control making it impossible for remote
5663 * devices to reassemble frames.
5665 * Hence implement a dummy callback just to say fragmentation isn't
5666 * supported. This effectively prevents mac80211 from doing frame
5667 * fragmentation in software.
5672 static void ath11k_mac_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5673 u32 queues, bool drop)
5675 struct ath11k *ar = hw->priv;
5681 time_left = wait_event_timeout(ar->dp.tx_empty_waitq,
5682 (atomic_read(&ar->dp.num_tx_pending) == 0),
5683 ATH11K_FLUSH_TIMEOUT);
5685 ath11k_warn(ar->ab, "failed to flush transmit queue %ld\n", time_left);
5689 ath11k_mac_bitrate_mask_num_ht_rates(struct ath11k *ar,
5690 enum nl80211_band band,
5691 const struct cfg80211_bitrate_mask *mask)
5696 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5697 num_rates += hweight16(mask->control[band].ht_mcs[i]);
5703 ath11k_mac_has_single_legacy_rate(struct ath11k *ar,
5704 enum nl80211_band band,
5705 const struct cfg80211_bitrate_mask *mask)
5709 num_rates = hweight32(mask->control[band].legacy);
5711 if (ath11k_mac_bitrate_mask_num_ht_rates(ar, band, mask))
5714 if (ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask))
5717 return num_rates == 1;
5721 ath11k_mac_bitrate_mask_get_single_nss(struct ath11k *ar,
5722 enum nl80211_band band,
5723 const struct cfg80211_bitrate_mask *mask,
5726 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5727 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5729 u8 vht_nss_mask = 0;
5732 /* No need to consider legacy here. Basic rates are always present
5736 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5737 if (mask->control[band].ht_mcs[i] == 0)
5739 else if (mask->control[band].ht_mcs[i] ==
5740 sband->ht_cap.mcs.rx_mask[i])
5741 ht_nss_mask |= BIT(i);
5746 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5747 if (mask->control[band].vht_mcs[i] == 0)
5749 else if (mask->control[band].vht_mcs[i] ==
5750 ath11k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5751 vht_nss_mask |= BIT(i);
5756 if (ht_nss_mask != vht_nss_mask)
5759 if (ht_nss_mask == 0)
5762 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5765 *nss = fls(ht_nss_mask);
5771 ath11k_mac_get_single_legacy_rate(struct ath11k *ar,
5772 enum nl80211_band band,
5773 const struct cfg80211_bitrate_mask *mask,
5781 if (hweight32(mask->control[band].legacy) != 1)
5784 rate_idx = ffs(mask->control[band].legacy) - 1;
5786 if (band == NL80211_BAND_5GHZ || band == NL80211_BAND_6GHZ)
5787 rate_idx += ATH11K_MAC_FIRST_OFDM_RATE_IDX;
5789 hw_rate = ath11k_legacy_rates[rate_idx].hw_value;
5790 bitrate = ath11k_legacy_rates[rate_idx].bitrate;
5792 if (ath11k_mac_bitrate_is_cck(bitrate))
5793 preamble = WMI_RATE_PREAMBLE_CCK;
5795 preamble = WMI_RATE_PREAMBLE_OFDM;
5798 *rate = ATH11K_HW_RATE_CODE(hw_rate, 0, preamble);
5803 static int ath11k_mac_set_fixed_rate_params(struct ath11k_vif *arvif,
5804 u32 rate, u8 nss, u8 sgi, u8 ldpc)
5806 struct ath11k *ar = arvif->ar;
5810 lockdep_assert_held(&ar->conf_mutex);
5812 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02x nss %u sgi %u\n",
5813 arvif->vdev_id, rate, nss, sgi);
5815 vdev_param = WMI_VDEV_PARAM_FIXED_RATE;
5816 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5819 ath11k_warn(ar->ab, "failed to set fixed rate param 0x%02x: %d\n",
5824 vdev_param = WMI_VDEV_PARAM_NSS;
5825 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5828 ath11k_warn(ar->ab, "failed to set nss param %d: %d\n",
5833 vdev_param = WMI_VDEV_PARAM_SGI;
5834 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5837 ath11k_warn(ar->ab, "failed to set sgi param %d: %d\n",
5842 vdev_param = WMI_VDEV_PARAM_LDPC;
5843 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5846 ath11k_warn(ar->ab, "failed to set ldpc param %d: %d\n",
5855 ath11k_mac_vht_mcs_range_present(struct ath11k *ar,
5856 enum nl80211_band band,
5857 const struct cfg80211_bitrate_mask *mask)
5862 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5863 vht_mcs = mask->control[band].vht_mcs[i];
5879 static void ath11k_mac_set_bitrate_mask_iter(void *data,
5880 struct ieee80211_sta *sta)
5882 struct ath11k_vif *arvif = data;
5883 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
5884 struct ath11k *ar = arvif->ar;
5886 spin_lock_bh(&ar->data_lock);
5887 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
5888 spin_unlock_bh(&ar->data_lock);
5890 ieee80211_queue_work(ar->hw, &arsta->update_wk);
5893 static void ath11k_mac_disable_peer_fixed_rate(void *data,
5894 struct ieee80211_sta *sta)
5896 struct ath11k_vif *arvif = data;
5897 struct ath11k *ar = arvif->ar;
5900 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
5902 WMI_PEER_PARAM_FIXED_RATE,
5903 WMI_FIXED_RATE_NONE);
5906 "failed to disable peer fixed rate for STA %pM ret %d\n",
5911 ath11k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5912 struct ieee80211_vif *vif,
5913 const struct cfg80211_bitrate_mask *mask)
5915 struct ath11k_vif *arvif = (void *)vif->drv_priv;
5916 struct cfg80211_chan_def def;
5917 struct ath11k *ar = arvif->ar;
5918 enum nl80211_band band;
5919 const u8 *ht_mcs_mask;
5920 const u16 *vht_mcs_mask;
5929 if (ath11k_mac_vif_chan(vif, &def))
5932 band = def.chan->band;
5933 ht_mcs_mask = mask->control[band].ht_mcs;
5934 vht_mcs_mask = mask->control[band].vht_mcs;
5935 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
5937 sgi = mask->control[band].gi;
5938 if (sgi == NL80211_TXRATE_FORCE_LGI)
5941 /* mac80211 doesn't support sending a fixed HT/VHT MCS alone, rather it
5942 * requires passing atleast one of used basic rates along with them.
5943 * Fixed rate setting across different preambles(legacy, HT, VHT) is
5944 * not supported by the FW. Hence use of FIXED_RATE vdev param is not
5945 * suitable for setting single HT/VHT rates.
5946 * But, there could be a single basic rate passed from userspace which
5947 * can be done through the FIXED_RATE param.
5949 if (ath11k_mac_has_single_legacy_rate(ar, band, mask)) {
5950 ret = ath11k_mac_get_single_legacy_rate(ar, band, mask, &rate,
5953 ath11k_warn(ar->ab, "failed to get single legacy rate for vdev %i: %d\n",
5954 arvif->vdev_id, ret);
5957 ieee80211_iterate_stations_atomic(ar->hw,
5958 ath11k_mac_disable_peer_fixed_rate,
5960 } else if (ath11k_mac_bitrate_mask_get_single_nss(ar, band, mask,
5962 rate = WMI_FIXED_RATE_NONE;
5965 rate = WMI_FIXED_RATE_NONE;
5966 nss = min_t(u32, ar->num_tx_chains,
5967 max(ath11k_mac_max_ht_nss(ht_mcs_mask),
5968 ath11k_mac_max_vht_nss(vht_mcs_mask)));
5970 /* If multiple rates across different preambles are given
5971 * we can reconfigure this info with all peers using PEER_ASSOC
5972 * command with the below exception cases.
5973 * - Single VHT Rate : peer_assoc command accommodates only MCS
5974 * range values i.e 0-7, 0-8, 0-9 for VHT. Though mac80211
5975 * mandates passing basic rates along with HT/VHT rates, FW
5976 * doesn't allow switching from VHT to Legacy. Hence instead of
5977 * setting legacy and VHT rates using RATEMASK_CMD vdev cmd,
5978 * we could set this VHT rate as peer fixed rate param, which
5979 * will override FIXED rate and FW rate control algorithm.
5980 * If single VHT rate is passed along with HT rates, we select
5981 * the VHT rate as fixed rate for vht peers.
5982 * - Multiple VHT Rates : When Multiple VHT rates are given,this
5983 * can be set using RATEMASK CMD which uses FW rate-ctl alg.
5984 * TODO: Setting multiple VHT MCS and replacing peer_assoc with
5985 * RATEMASK_CMDID can cover all use cases of setting rates
5986 * across multiple preambles and rates within same type.
5987 * But requires more validation of the command at this point.
5990 num_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band,
5993 if (!ath11k_mac_vht_mcs_range_present(ar, band, mask) &&
5995 /* TODO: Handle multiple VHT MCS values setting using
5999 "Setting more than one MCS Value in bitrate mask not supported\n");
6003 ieee80211_iterate_stations_atomic(ar->hw,
6004 ath11k_mac_disable_peer_fixed_rate,
6007 mutex_lock(&ar->conf_mutex);
6009 arvif->bitrate_mask = *mask;
6010 ieee80211_iterate_stations_atomic(ar->hw,
6011 ath11k_mac_set_bitrate_mask_iter,
6014 mutex_unlock(&ar->conf_mutex);
6017 mutex_lock(&ar->conf_mutex);
6019 ret = ath11k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
6021 ath11k_warn(ar->ab, "failed to set fixed rate params on vdev %i: %d\n",
6022 arvif->vdev_id, ret);
6025 mutex_unlock(&ar->conf_mutex);
6031 ath11k_mac_op_reconfig_complete(struct ieee80211_hw *hw,
6032 enum ieee80211_reconfig_type reconfig_type)
6034 struct ath11k *ar = hw->priv;
6036 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
6039 mutex_lock(&ar->conf_mutex);
6041 if (ar->state == ATH11K_STATE_RESTARTED) {
6042 ath11k_warn(ar->ab, "pdev %d successfully recovered\n",
6044 ar->state = ATH11K_STATE_ON;
6045 ieee80211_wake_queues(ar->hw);
6048 mutex_unlock(&ar->conf_mutex);
6052 ath11k_mac_update_bss_chan_survey(struct ath11k *ar,
6053 struct ieee80211_channel *channel)
6056 enum wmi_bss_chan_info_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
6058 lockdep_assert_held(&ar->conf_mutex);
6060 if (!test_bit(WMI_TLV_SERVICE_BSS_CHANNEL_INFO_64, ar->ab->wmi_ab.svc_map) ||
6061 ar->rx_channel != channel)
6064 if (ar->scan.state != ATH11K_SCAN_IDLE) {
6065 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
6066 "ignoring bss chan info req while scanning..\n");
6070 reinit_completion(&ar->bss_survey_done);
6072 ret = ath11k_wmi_pdev_bss_chan_info_request(ar, type);
6074 ath11k_warn(ar->ab, "failed to send pdev bss chan info request\n");
6078 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
6080 ath11k_warn(ar->ab, "bss channel survey timed out\n");
6083 static int ath11k_mac_op_get_survey(struct ieee80211_hw *hw, int idx,
6084 struct survey_info *survey)
6086 struct ath11k *ar = hw->priv;
6087 struct ieee80211_supported_band *sband;
6088 struct survey_info *ar_survey;
6091 if (idx >= ATH11K_NUM_CHANS)
6094 ar_survey = &ar->survey[idx];
6096 mutex_lock(&ar->conf_mutex);
6098 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
6099 if (sband && idx >= sband->n_channels) {
6100 idx -= sband->n_channels;
6105 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
6107 if (!sband || idx >= sband->n_channels) {
6112 ath11k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
6114 spin_lock_bh(&ar->data_lock);
6115 memcpy(survey, ar_survey, sizeof(*survey));
6116 spin_unlock_bh(&ar->data_lock);
6118 survey->channel = &sband->channels[idx];
6120 if (ar->rx_channel == survey->channel)
6121 survey->filled |= SURVEY_INFO_IN_USE;
6124 mutex_unlock(&ar->conf_mutex);
6128 static void ath11k_mac_op_sta_statistics(struct ieee80211_hw *hw,
6129 struct ieee80211_vif *vif,
6130 struct ieee80211_sta *sta,
6131 struct station_info *sinfo)
6133 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
6135 sinfo->rx_duration = arsta->rx_duration;
6136 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
6138 sinfo->tx_duration = arsta->tx_duration;
6139 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION);
6141 if (!arsta->txrate.legacy && !arsta->txrate.nss)
6144 if (arsta->txrate.legacy) {
6145 sinfo->txrate.legacy = arsta->txrate.legacy;
6147 sinfo->txrate.mcs = arsta->txrate.mcs;
6148 sinfo->txrate.nss = arsta->txrate.nss;
6149 sinfo->txrate.bw = arsta->txrate.bw;
6150 sinfo->txrate.he_gi = arsta->txrate.he_gi;
6151 sinfo->txrate.he_dcm = arsta->txrate.he_dcm;
6152 sinfo->txrate.he_ru_alloc = arsta->txrate.he_ru_alloc;
6154 sinfo->txrate.flags = arsta->txrate.flags;
6155 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
6157 /* TODO: Use real NF instead of default one. */
6158 sinfo->signal = arsta->rssi_comb + ATH11K_DEFAULT_NOISE_FLOOR;
6159 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
6162 static const struct ieee80211_ops ath11k_ops = {
6163 .tx = ath11k_mac_op_tx,
6164 .start = ath11k_mac_op_start,
6165 .stop = ath11k_mac_op_stop,
6166 .reconfig_complete = ath11k_mac_op_reconfig_complete,
6167 .add_interface = ath11k_mac_op_add_interface,
6168 .remove_interface = ath11k_mac_op_remove_interface,
6169 .update_vif_offload = ath11k_mac_op_update_vif_offload,
6170 .config = ath11k_mac_op_config,
6171 .bss_info_changed = ath11k_mac_op_bss_info_changed,
6172 .configure_filter = ath11k_mac_op_configure_filter,
6173 .hw_scan = ath11k_mac_op_hw_scan,
6174 .cancel_hw_scan = ath11k_mac_op_cancel_hw_scan,
6175 .set_key = ath11k_mac_op_set_key,
6176 .sta_state = ath11k_mac_op_sta_state,
6177 .sta_set_txpwr = ath11k_mac_op_sta_set_txpwr,
6178 .sta_rc_update = ath11k_mac_op_sta_rc_update,
6179 .conf_tx = ath11k_mac_op_conf_tx,
6180 .set_antenna = ath11k_mac_op_set_antenna,
6181 .get_antenna = ath11k_mac_op_get_antenna,
6182 .ampdu_action = ath11k_mac_op_ampdu_action,
6183 .add_chanctx = ath11k_mac_op_add_chanctx,
6184 .remove_chanctx = ath11k_mac_op_remove_chanctx,
6185 .change_chanctx = ath11k_mac_op_change_chanctx,
6186 .assign_vif_chanctx = ath11k_mac_op_assign_vif_chanctx,
6187 .unassign_vif_chanctx = ath11k_mac_op_unassign_vif_chanctx,
6188 .switch_vif_chanctx = ath11k_mac_op_switch_vif_chanctx,
6189 .set_rts_threshold = ath11k_mac_op_set_rts_threshold,
6190 .set_frag_threshold = ath11k_mac_op_set_frag_threshold,
6191 .set_bitrate_mask = ath11k_mac_op_set_bitrate_mask,
6192 .get_survey = ath11k_mac_op_get_survey,
6193 .flush = ath11k_mac_op_flush,
6194 .sta_statistics = ath11k_mac_op_sta_statistics,
6195 CFG80211_TESTMODE_CMD(ath11k_tm_cmd)
6196 #ifdef CONFIG_ATH11K_DEBUGFS
6197 .sta_add_debugfs = ath11k_debugfs_sta_op_add,
6201 static void ath11k_mac_update_ch_list(struct ath11k *ar,
6202 struct ieee80211_supported_band *band,
6203 u32 freq_low, u32 freq_high)
6207 if (!(freq_low && freq_high))
6210 for (i = 0; i < band->n_channels; i++) {
6211 if (band->channels[i].center_freq < freq_low ||
6212 band->channels[i].center_freq > freq_high)
6213 band->channels[i].flags |= IEEE80211_CHAN_DISABLED;
6217 static u32 ath11k_get_phy_id(struct ath11k *ar, u32 band)
6219 struct ath11k_pdev *pdev = ar->pdev;
6220 struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
6222 if (band == WMI_HOST_WLAN_2G_CAP)
6223 return pdev_cap->band[NL80211_BAND_2GHZ].phy_id;
6225 if (band == WMI_HOST_WLAN_5G_CAP)
6226 return pdev_cap->band[NL80211_BAND_5GHZ].phy_id;
6228 ath11k_warn(ar->ab, "unsupported phy cap:%d\n", band);
6233 static int ath11k_mac_setup_channels_rates(struct ath11k *ar,
6234 u32 supported_bands)
6236 struct ieee80211_supported_band *band;
6237 struct ath11k_hal_reg_capabilities_ext *reg_cap;
6241 BUILD_BUG_ON((ARRAY_SIZE(ath11k_2ghz_channels) +
6242 ARRAY_SIZE(ath11k_5ghz_channels) +
6243 ARRAY_SIZE(ath11k_6ghz_channels)) !=
6246 reg_cap = &ar->ab->hal_reg_cap[ar->pdev_idx];
6248 if (supported_bands & WMI_HOST_WLAN_2G_CAP) {
6249 channels = kmemdup(ath11k_2ghz_channels,
6250 sizeof(ath11k_2ghz_channels),
6255 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
6256 band->band = NL80211_BAND_2GHZ;
6257 band->n_channels = ARRAY_SIZE(ath11k_2ghz_channels);
6258 band->channels = channels;
6259 band->n_bitrates = ath11k_g_rates_size;
6260 band->bitrates = ath11k_g_rates;
6261 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
6263 if (ar->ab->hw_params.single_pdev_only) {
6264 phy_id = ath11k_get_phy_id(ar, WMI_HOST_WLAN_2G_CAP);
6265 reg_cap = &ar->ab->hal_reg_cap[phy_id];
6267 ath11k_mac_update_ch_list(ar, band,
6268 reg_cap->low_2ghz_chan,
6269 reg_cap->high_2ghz_chan);
6272 if (supported_bands & WMI_HOST_WLAN_5G_CAP) {
6273 if (reg_cap->high_5ghz_chan >= ATH11K_MAX_6G_FREQ) {
6274 channels = kmemdup(ath11k_6ghz_channels,
6275 sizeof(ath11k_6ghz_channels), GFP_KERNEL);
6277 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
6281 ar->supports_6ghz = true;
6282 band = &ar->mac.sbands[NL80211_BAND_6GHZ];
6283 band->band = NL80211_BAND_6GHZ;
6284 band->n_channels = ARRAY_SIZE(ath11k_6ghz_channels);
6285 band->channels = channels;
6286 band->n_bitrates = ath11k_a_rates_size;
6287 band->bitrates = ath11k_a_rates;
6288 ar->hw->wiphy->bands[NL80211_BAND_6GHZ] = band;
6289 ath11k_mac_update_ch_list(ar, band,
6290 reg_cap->low_5ghz_chan,
6291 reg_cap->high_5ghz_chan);
6294 if (reg_cap->low_5ghz_chan < ATH11K_MIN_6G_FREQ) {
6295 channels = kmemdup(ath11k_5ghz_channels,
6296 sizeof(ath11k_5ghz_channels),
6299 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
6300 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
6304 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
6305 band->band = NL80211_BAND_5GHZ;
6306 band->n_channels = ARRAY_SIZE(ath11k_5ghz_channels);
6307 band->channels = channels;
6308 band->n_bitrates = ath11k_a_rates_size;
6309 band->bitrates = ath11k_a_rates;
6310 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
6312 if (ar->ab->hw_params.single_pdev_only) {
6313 phy_id = ath11k_get_phy_id(ar, WMI_HOST_WLAN_5G_CAP);
6314 reg_cap = &ar->ab->hal_reg_cap[phy_id];
6317 ath11k_mac_update_ch_list(ar, band,
6318 reg_cap->low_5ghz_chan,
6319 reg_cap->high_5ghz_chan);
6326 static int ath11k_mac_setup_iface_combinations(struct ath11k *ar)
6328 struct ath11k_base *ab = ar->ab;
6329 struct ieee80211_iface_combination *combinations;
6330 struct ieee80211_iface_limit *limits;
6333 combinations = kzalloc(sizeof(*combinations), GFP_KERNEL);
6339 limits = kcalloc(n_limits, sizeof(*limits), GFP_KERNEL);
6341 kfree(combinations);
6346 limits[0].types |= BIT(NL80211_IFTYPE_STATION);
6349 limits[1].types |= BIT(NL80211_IFTYPE_AP);
6351 if (IS_ENABLED(CONFIG_MAC80211_MESH) &&
6352 ab->hw_params.interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
6353 limits[1].types |= BIT(NL80211_IFTYPE_MESH_POINT);
6355 combinations[0].limits = limits;
6356 combinations[0].n_limits = n_limits;
6357 combinations[0].max_interfaces = 16;
6358 combinations[0].num_different_channels = 1;
6359 combinations[0].beacon_int_infra_match = true;
6360 combinations[0].beacon_int_min_gcd = 100;
6361 combinations[0].radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6362 BIT(NL80211_CHAN_WIDTH_20) |
6363 BIT(NL80211_CHAN_WIDTH_40) |
6364 BIT(NL80211_CHAN_WIDTH_80);
6366 ar->hw->wiphy->iface_combinations = combinations;
6367 ar->hw->wiphy->n_iface_combinations = 1;
6372 static const u8 ath11k_if_types_ext_capa[] = {
6373 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
6374 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
6377 static const u8 ath11k_if_types_ext_capa_sta[] = {
6378 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
6379 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
6380 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
6383 static const u8 ath11k_if_types_ext_capa_ap[] = {
6384 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
6385 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
6386 [9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT,
6389 static const struct wiphy_iftype_ext_capab ath11k_iftypes_ext_capa[] = {
6391 .extended_capabilities = ath11k_if_types_ext_capa,
6392 .extended_capabilities_mask = ath11k_if_types_ext_capa,
6393 .extended_capabilities_len = sizeof(ath11k_if_types_ext_capa),
6395 .iftype = NL80211_IFTYPE_STATION,
6396 .extended_capabilities = ath11k_if_types_ext_capa_sta,
6397 .extended_capabilities_mask = ath11k_if_types_ext_capa_sta,
6398 .extended_capabilities_len =
6399 sizeof(ath11k_if_types_ext_capa_sta),
6401 .iftype = NL80211_IFTYPE_AP,
6402 .extended_capabilities = ath11k_if_types_ext_capa_ap,
6403 .extended_capabilities_mask = ath11k_if_types_ext_capa_ap,
6404 .extended_capabilities_len =
6405 sizeof(ath11k_if_types_ext_capa_ap),
6409 static void __ath11k_mac_unregister(struct ath11k *ar)
6411 cancel_work_sync(&ar->regd_update_work);
6413 ieee80211_unregister_hw(ar->hw);
6415 idr_for_each(&ar->txmgmt_idr, ath11k_mac_tx_mgmt_pending_free, ar);
6416 idr_destroy(&ar->txmgmt_idr);
6418 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
6419 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
6420 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
6422 kfree(ar->hw->wiphy->iface_combinations[0].limits);
6423 kfree(ar->hw->wiphy->iface_combinations);
6425 SET_IEEE80211_DEV(ar->hw, NULL);
6428 void ath11k_mac_unregister(struct ath11k_base *ab)
6431 struct ath11k_pdev *pdev;
6434 for (i = 0; i < ab->num_radios; i++) {
6435 pdev = &ab->pdevs[i];
6440 __ath11k_mac_unregister(ar);
6444 static int __ath11k_mac_register(struct ath11k *ar)
6446 struct ath11k_base *ab = ar->ab;
6447 struct ath11k_pdev_cap *cap = &ar->pdev->cap;
6448 static const u32 cipher_suites[] = {
6449 WLAN_CIPHER_SUITE_TKIP,
6450 WLAN_CIPHER_SUITE_CCMP,
6451 WLAN_CIPHER_SUITE_AES_CMAC,
6452 WLAN_CIPHER_SUITE_BIP_CMAC_256,
6453 WLAN_CIPHER_SUITE_BIP_GMAC_128,
6454 WLAN_CIPHER_SUITE_BIP_GMAC_256,
6455 WLAN_CIPHER_SUITE_GCMP,
6456 WLAN_CIPHER_SUITE_GCMP_256,
6457 WLAN_CIPHER_SUITE_CCMP_256,
6462 ath11k_pdev_caps_update(ar);
6464 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6466 SET_IEEE80211_DEV(ar->hw, ab->dev);
6468 ret = ath11k_mac_setup_channels_rates(ar,
6469 cap->supported_bands);
6473 ath11k_mac_setup_ht_vht_cap(ar, cap, &ht_cap);
6474 ath11k_mac_setup_he_cap(ar, cap);
6476 ret = ath11k_mac_setup_iface_combinations(ar);
6478 ath11k_err(ar->ab, "failed to setup interface combinations: %d\n", ret);
6479 goto err_free_channels;
6482 ar->hw->wiphy->available_antennas_rx = cap->rx_chain_mask;
6483 ar->hw->wiphy->available_antennas_tx = cap->tx_chain_mask;
6485 ar->hw->wiphy->interface_modes = ab->hw_params.interface_modes;
6487 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
6488 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
6489 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
6490 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
6491 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
6492 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
6493 ieee80211_hw_set(ar->hw, AP_LINK_PS);
6494 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
6495 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
6496 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
6497 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
6498 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
6499 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
6500 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
6501 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
6502 ieee80211_hw_set(ar->hw, SUPPORTS_TX_ENCAP_OFFLOAD);
6503 if (ht_cap & WMI_HT_CAP_ENABLED) {
6504 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
6505 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
6506 ieee80211_hw_set(ar->hw, SUPPORTS_REORDERING_BUFFER);
6507 ieee80211_hw_set(ar->hw, SUPPORTS_AMSDU_IN_AMPDU);
6508 ieee80211_hw_set(ar->hw, USES_RSS);
6511 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6512 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
6514 /* TODO: Check if HT capability advertised from firmware is different
6515 * for each band for a dual band capable radio. It will be tricky to
6516 * handle it when the ht capability different for each band.
6518 if (ht_cap & WMI_HT_CAP_DYNAMIC_SMPS)
6519 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
6521 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6522 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6524 ar->hw->max_listen_interval = ATH11K_MAX_HW_LISTEN_INTERVAL;
6526 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
6527 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
6528 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6530 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
6531 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
6532 NL80211_FEATURE_AP_SCAN;
6534 ar->max_num_stations = TARGET_NUM_STATIONS;
6535 ar->max_num_peers = TARGET_NUM_PEERS_PDEV;
6537 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6539 ar->hw->queues = ATH11K_HW_MAX_QUEUES;
6540 ar->hw->wiphy->tx_queue_len = ATH11K_QUEUE_LEN;
6541 ar->hw->offchannel_tx_hw_queue = ATH11K_HW_MAX_QUEUES - 1;
6542 ar->hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
6544 ar->hw->vif_data_size = sizeof(struct ath11k_vif);
6545 ar->hw->sta_data_size = sizeof(struct ath11k_sta);
6547 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
6548 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_STA_TX_PWR);
6550 ar->hw->wiphy->cipher_suites = cipher_suites;
6551 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6553 ar->hw->wiphy->iftype_ext_capab = ath11k_iftypes_ext_capa;
6554 ar->hw->wiphy->num_iftype_ext_capab =
6555 ARRAY_SIZE(ath11k_iftypes_ext_capa);
6557 if (ar->supports_6ghz) {
6558 wiphy_ext_feature_set(ar->hw->wiphy,
6559 NL80211_EXT_FEATURE_FILS_DISCOVERY);
6560 wiphy_ext_feature_set(ar->hw->wiphy,
6561 NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP);
6564 ath11k_reg_init(ar);
6566 if (!test_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags)) {
6567 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6568 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
6569 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
6572 ret = ieee80211_register_hw(ar->hw);
6574 ath11k_err(ar->ab, "ieee80211 registration failed: %d\n", ret);
6575 goto err_free_if_combs;
6578 if (!ab->hw_params.supports_monitor)
6579 /* There's a race between calling ieee80211_register_hw()
6580 * and here where the monitor mode is enabled for a little
6581 * while. But that time is so short and in practise it make
6582 * a difference in real life.
6584 ar->hw->wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MONITOR);
6586 /* Apply the regd received during initialization */
6587 ret = ath11k_regd_update(ar, true);
6589 ath11k_err(ar->ab, "ath11k regd update failed: %d\n", ret);
6590 goto err_unregister_hw;
6593 ret = ath11k_debugfs_register(ar);
6595 ath11k_err(ar->ab, "debugfs registration failed: %d\n", ret);
6596 goto err_unregister_hw;
6602 ieee80211_unregister_hw(ar->hw);
6605 kfree(ar->hw->wiphy->iface_combinations[0].limits);
6606 kfree(ar->hw->wiphy->iface_combinations);
6609 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
6610 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
6611 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
6614 SET_IEEE80211_DEV(ar->hw, NULL);
6618 int ath11k_mac_register(struct ath11k_base *ab)
6621 struct ath11k_pdev *pdev;
6625 if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags))
6628 for (i = 0; i < ab->num_radios; i++) {
6629 pdev = &ab->pdevs[i];
6631 if (ab->pdevs_macaddr_valid) {
6632 ether_addr_copy(ar->mac_addr, pdev->mac_addr);
6634 ether_addr_copy(ar->mac_addr, ab->mac_addr);
6635 ar->mac_addr[4] += i;
6638 ret = __ath11k_mac_register(ar);
6642 idr_init(&ar->txmgmt_idr);
6643 spin_lock_init(&ar->txmgmt_idr_lock);
6646 /* Initialize channel counters frequency value in hertz */
6647 ab->cc_freq_hz = IPQ8074_CC_FREQ_HERTZ;
6648 ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS)) - 1;
6653 for (i = i - 1; i >= 0; i--) {
6654 pdev = &ab->pdevs[i];
6656 __ath11k_mac_unregister(ar);
6662 int ath11k_mac_allocate(struct ath11k_base *ab)
6664 struct ieee80211_hw *hw;
6666 struct ath11k_pdev *pdev;
6670 if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags))
6673 for (i = 0; i < ab->num_radios; i++) {
6674 pdev = &ab->pdevs[i];
6675 hw = ieee80211_alloc_hw(sizeof(struct ath11k), &ath11k_ops);
6677 ath11k_warn(ab, "failed to allocate mac80211 hw device\n");
6687 ar->lmac_id = ath11k_hw_get_mac_from_pdev_id(&ab->hw_params, i);
6689 ar->wmi = &ab->wmi_ab.wmi[i];
6690 /* FIXME wmi[0] is already initialized during attach,
6691 * Should we do this again?
6693 ath11k_wmi_pdev_attach(ab, i);
6695 ar->cfg_tx_chainmask = pdev->cap.tx_chain_mask;
6696 ar->cfg_rx_chainmask = pdev->cap.rx_chain_mask;
6697 ar->num_tx_chains = get_num_chains(pdev->cap.tx_chain_mask);
6698 ar->num_rx_chains = get_num_chains(pdev->cap.rx_chain_mask);
6701 spin_lock_init(&ar->data_lock);
6702 INIT_LIST_HEAD(&ar->arvifs);
6703 INIT_LIST_HEAD(&ar->ppdu_stats_info);
6704 mutex_init(&ar->conf_mutex);
6705 init_completion(&ar->vdev_setup_done);
6706 init_completion(&ar->vdev_delete_done);
6707 init_completion(&ar->peer_assoc_done);
6708 init_completion(&ar->peer_delete_done);
6709 init_completion(&ar->install_key_done);
6710 init_completion(&ar->bss_survey_done);
6711 init_completion(&ar->scan.started);
6712 init_completion(&ar->scan.completed);
6713 init_completion(&ar->thermal.wmi_sync);
6715 INIT_DELAYED_WORK(&ar->scan.timeout, ath11k_scan_timeout_work);
6716 INIT_WORK(&ar->regd_update_work, ath11k_regd_update_work);
6718 INIT_WORK(&ar->wmi_mgmt_tx_work, ath11k_mgmt_over_wmi_tx_work);
6719 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
6720 clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags);
6726 ath11k_mac_destroy(ab);
6731 void ath11k_mac_destroy(struct ath11k_base *ab)
6734 struct ath11k_pdev *pdev;
6737 for (i = 0; i < ab->num_radios; i++) {
6738 pdev = &ab->pdevs[i];
6743 ieee80211_free_hw(ar->hw);