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 struct ath11k *ath11k_mac_get_ar_vdev_stop_status(struct ath11k_base *ab,
544 struct ath11k_pdev *pdev;
547 for (i = 0; i < ab->num_radios; i++) {
548 pdev = rcu_dereference(ab->pdevs_active[i]);
549 if (pdev && pdev->ar) {
552 spin_lock_bh(&ar->data_lock);
553 if (ar->vdev_stop_status.stop_in_progress &&
554 ar->vdev_stop_status.vdev_id == vdev_id) {
555 ar->vdev_stop_status.stop_in_progress = false;
556 spin_unlock_bh(&ar->data_lock);
559 spin_unlock_bh(&ar->data_lock);
565 static void ath11k_pdev_caps_update(struct ath11k *ar)
567 struct ath11k_base *ab = ar->ab;
569 ar->max_tx_power = ab->target_caps.hw_max_tx_power;
571 /* FIXME Set min_tx_power to ab->target_caps.hw_min_tx_power.
572 * But since the received value in svcrdy is same as hw_max_tx_power,
573 * we can set ar->min_tx_power to 0 currently until
574 * this is fixed in firmware
576 ar->min_tx_power = 0;
578 ar->txpower_limit_2g = ar->max_tx_power;
579 ar->txpower_limit_5g = ar->max_tx_power;
580 ar->txpower_scale = WMI_HOST_TP_SCALE_MAX;
583 static int ath11k_mac_txpower_recalc(struct ath11k *ar)
585 struct ath11k_pdev *pdev = ar->pdev;
586 struct ath11k_vif *arvif;
587 int ret, txpower = -1;
590 lockdep_assert_held(&ar->conf_mutex);
592 list_for_each_entry(arvif, &ar->arvifs, list) {
593 if (arvif->txpower <= 0)
597 txpower = arvif->txpower;
599 txpower = min(txpower, arvif->txpower);
605 /* txpwr is set as 2 units per dBm in FW*/
606 txpower = min_t(u32, max_t(u32, ar->min_tx_power, txpower),
607 ar->max_tx_power) * 2;
609 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "txpower to set in hw %d\n",
612 if ((pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) &&
613 ar->txpower_limit_2g != txpower) {
614 param = WMI_PDEV_PARAM_TXPOWER_LIMIT2G;
615 ret = ath11k_wmi_pdev_set_param(ar, param,
616 txpower, ar->pdev->pdev_id);
619 ar->txpower_limit_2g = txpower;
622 if ((pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) &&
623 ar->txpower_limit_5g != txpower) {
624 param = WMI_PDEV_PARAM_TXPOWER_LIMIT5G;
625 ret = ath11k_wmi_pdev_set_param(ar, param,
626 txpower, ar->pdev->pdev_id);
629 ar->txpower_limit_5g = txpower;
635 ath11k_warn(ar->ab, "failed to recalc txpower limit %d using pdev param %d: %d\n",
636 txpower / 2, param, ret);
640 static int ath11k_recalc_rtscts_prot(struct ath11k_vif *arvif)
642 struct ath11k *ar = arvif->ar;
643 u32 vdev_param, rts_cts = 0;
646 lockdep_assert_held(&ar->conf_mutex);
648 vdev_param = WMI_VDEV_PARAM_ENABLE_RTSCTS;
650 /* Enable RTS/CTS protection for sw retries (when legacy stations
651 * are in BSS) or by default only for second rate series.
652 * TODO: Check if we need to enable CTS 2 Self in any case
654 rts_cts = WMI_USE_RTS_CTS;
656 if (arvif->num_legacy_stations > 0)
657 rts_cts |= WMI_RTSCTS_ACROSS_SW_RETRIES << 4;
659 rts_cts |= WMI_RTSCTS_FOR_SECOND_RATESERIES << 4;
661 /* Need not send duplicate param value to firmware */
662 if (arvif->rtscts_prot_mode == rts_cts)
665 arvif->rtscts_prot_mode = rts_cts;
667 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
668 arvif->vdev_id, rts_cts);
670 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
671 vdev_param, rts_cts);
673 ath11k_warn(ar->ab, "failed to recalculate rts/cts prot for vdev %d: %d\n",
674 arvif->vdev_id, ret);
679 static int ath11k_mac_set_kickout(struct ath11k_vif *arvif)
681 struct ath11k *ar = arvif->ar;
685 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_STA_KICKOUT_TH,
686 ATH11K_KICKOUT_THRESHOLD,
689 ath11k_warn(ar->ab, "failed to set kickout threshold on vdev %i: %d\n",
690 arvif->vdev_id, ret);
694 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS;
695 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
696 ATH11K_KEEPALIVE_MIN_IDLE);
698 ath11k_warn(ar->ab, "failed to set keepalive minimum idle time on vdev %i: %d\n",
699 arvif->vdev_id, ret);
703 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS;
704 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
705 ATH11K_KEEPALIVE_MAX_IDLE);
707 ath11k_warn(ar->ab, "failed to set keepalive maximum idle time on vdev %i: %d\n",
708 arvif->vdev_id, ret);
712 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS;
713 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
714 ATH11K_KEEPALIVE_MAX_UNRESPONSIVE);
716 ath11k_warn(ar->ab, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
717 arvif->vdev_id, ret);
724 void ath11k_mac_peer_cleanup_all(struct ath11k *ar)
726 struct ath11k_peer *peer, *tmp;
727 struct ath11k_base *ab = ar->ab;
729 lockdep_assert_held(&ar->conf_mutex);
731 spin_lock_bh(&ab->base_lock);
732 list_for_each_entry_safe(peer, tmp, &ab->peers, list) {
733 ath11k_peer_rx_tid_cleanup(ar, peer);
734 list_del(&peer->list);
737 spin_unlock_bh(&ab->base_lock);
740 ar->num_stations = 0;
743 static int ath11k_monitor_vdev_up(struct ath11k *ar, int vdev_id)
747 ret = ath11k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
749 ath11k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n",
754 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor vdev %i started\n",
759 static int ath11k_mac_op_config(struct ieee80211_hw *hw, u32 changed)
761 struct ath11k *ar = hw->priv;
764 /* mac80211 requires this op to be present and that's why
765 * there's an empty function, this can be extended when
769 mutex_lock(&ar->conf_mutex);
771 /* TODO: Handle configuration changes as appropriate */
773 mutex_unlock(&ar->conf_mutex);
778 static int ath11k_mac_setup_bcn_tmpl(struct ath11k_vif *arvif)
780 struct ath11k *ar = arvif->ar;
781 struct ath11k_base *ab = ar->ab;
782 struct ieee80211_hw *hw = ar->hw;
783 struct ieee80211_vif *vif = arvif->vif;
784 struct ieee80211_mutable_offsets offs = {};
786 struct ieee80211_mgmt *mgmt;
790 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
793 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
795 ath11k_warn(ab, "failed to get beacon template from mac80211\n");
799 ies = bcn->data + ieee80211_get_hdrlen_from_skb(bcn);
800 ies += sizeof(mgmt->u.beacon);
802 if (cfg80211_find_ie(WLAN_EID_RSN, ies, (skb_tail_pointer(bcn) - ies)))
803 arvif->rsnie_present = true;
805 if (cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
806 WLAN_OUI_TYPE_MICROSOFT_WPA,
807 ies, (skb_tail_pointer(bcn) - ies)))
808 arvif->wpaie_present = true;
810 ret = ath11k_wmi_bcn_tmpl(ar, arvif->vdev_id, &offs, bcn);
815 ath11k_warn(ab, "failed to submit beacon template command: %d\n",
821 static void ath11k_control_beaconing(struct ath11k_vif *arvif,
822 struct ieee80211_bss_conf *info)
824 struct ath11k *ar = arvif->ar;
827 lockdep_assert_held(&arvif->ar->conf_mutex);
829 if (!info->enable_beacon) {
830 ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id);
832 ath11k_warn(ar->ab, "failed to down vdev_id %i: %d\n",
833 arvif->vdev_id, ret);
835 arvif->is_up = false;
839 /* Install the beacon template to the FW */
840 ret = ath11k_mac_setup_bcn_tmpl(arvif);
842 ath11k_warn(ar->ab, "failed to update bcn tmpl during vdev up: %d\n",
847 arvif->tx_seq_no = 0x1000;
851 ether_addr_copy(arvif->bssid, info->bssid);
853 ret = ath11k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
856 ath11k_warn(ar->ab, "failed to bring up vdev %d: %i\n",
857 arvif->vdev_id, ret);
863 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
866 static void ath11k_peer_assoc_h_basic(struct ath11k *ar,
867 struct ieee80211_vif *vif,
868 struct ieee80211_sta *sta,
869 struct peer_assoc_params *arg)
871 struct ath11k_vif *arvif = (void *)vif->drv_priv;
874 lockdep_assert_held(&ar->conf_mutex);
876 if (vif->type == NL80211_IFTYPE_STATION)
877 aid = vif->bss_conf.aid;
881 ether_addr_copy(arg->peer_mac, sta->addr);
882 arg->vdev_id = arvif->vdev_id;
883 arg->peer_associd = aid;
884 arg->auth_flag = true;
885 /* TODO: STA WAR in ath10k for listen interval required? */
886 arg->peer_listen_intval = ar->hw->conf.listen_interval;
888 arg->peer_caps = vif->bss_conf.assoc_capability;
891 static void ath11k_peer_assoc_h_crypto(struct ath11k *ar,
892 struct ieee80211_vif *vif,
893 struct ieee80211_sta *sta,
894 struct peer_assoc_params *arg)
896 struct ieee80211_bss_conf *info = &vif->bss_conf;
897 struct cfg80211_chan_def def;
898 struct cfg80211_bss *bss;
899 struct ath11k_vif *arvif = (struct ath11k_vif *)vif->drv_priv;
900 const u8 *rsnie = NULL;
901 const u8 *wpaie = NULL;
903 lockdep_assert_held(&ar->conf_mutex);
905 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
908 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
909 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
911 if (arvif->rsnie_present || arvif->wpaie_present) {
912 arg->need_ptk_4_way = true;
913 if (arvif->wpaie_present)
914 arg->need_gtk_2_way = true;
916 const struct cfg80211_bss_ies *ies;
919 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
921 ies = rcu_dereference(bss->ies);
923 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
924 WLAN_OUI_TYPE_MICROSOFT_WPA,
928 cfg80211_put_bss(ar->hw->wiphy, bss);
931 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
932 if (rsnie || wpaie) {
933 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
934 "%s: rsn ie found\n", __func__);
935 arg->need_ptk_4_way = true;
939 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
940 "%s: wpa ie found\n", __func__);
941 arg->need_gtk_2_way = true;
945 /* TODO: Need to check if FW supports PMF? */
946 arg->is_pmf_enabled = true;
949 /* TODO: safe_mode_enabled (bypass 4-way handshake) flag req? */
952 static void ath11k_peer_assoc_h_rates(struct ath11k *ar,
953 struct ieee80211_vif *vif,
954 struct ieee80211_sta *sta,
955 struct peer_assoc_params *arg)
957 struct ath11k_vif *arvif = (void *)vif->drv_priv;
958 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
959 struct cfg80211_chan_def def;
960 const struct ieee80211_supported_band *sband;
961 const struct ieee80211_rate *rates;
962 enum nl80211_band band;
967 lockdep_assert_held(&ar->conf_mutex);
969 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
972 band = def.chan->band;
973 sband = ar->hw->wiphy->bands[band];
974 ratemask = sta->supp_rates[band];
975 ratemask &= arvif->bitrate_mask.control[band].legacy;
976 rates = sband->bitrates;
978 rateset->num_rates = 0;
980 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
984 rate = ath11k_mac_bitrate_to_rate(rates->bitrate);
985 rateset->rates[rateset->num_rates] = rate;
986 rateset->num_rates++;
991 ath11k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
995 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
996 if (ht_mcs_mask[nss])
1003 ath11k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
1007 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
1008 if (vht_mcs_mask[nss])
1014 static void ath11k_peer_assoc_h_ht(struct ath11k *ar,
1015 struct ieee80211_vif *vif,
1016 struct ieee80211_sta *sta,
1017 struct peer_assoc_params *arg)
1019 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1020 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1021 struct cfg80211_chan_def def;
1022 enum nl80211_band band;
1023 const u8 *ht_mcs_mask;
1028 lockdep_assert_held(&ar->conf_mutex);
1030 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1033 if (!ht_cap->ht_supported)
1036 band = def.chan->band;
1037 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
1039 if (ath11k_peer_assoc_h_ht_masked(ht_mcs_mask))
1042 arg->ht_flag = true;
1044 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1045 ht_cap->ampdu_factor)) - 1;
1047 arg->peer_mpdu_density =
1048 ath11k_parse_mpdudensity(ht_cap->ampdu_density);
1050 arg->peer_ht_caps = ht_cap->cap;
1051 arg->peer_rate_caps |= WMI_HOST_RC_HT_FLAG;
1053 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1054 arg->ldpc_flag = true;
1056 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1058 arg->peer_rate_caps |= WMI_HOST_RC_CW40_FLAG;
1061 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
1062 if (ht_cap->cap & (IEEE80211_HT_CAP_SGI_20 |
1063 IEEE80211_HT_CAP_SGI_40))
1064 arg->peer_rate_caps |= WMI_HOST_RC_SGI_FLAG;
1067 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1068 arg->peer_rate_caps |= WMI_HOST_RC_TX_STBC_FLAG;
1069 arg->stbc_flag = true;
1072 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1073 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1074 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1075 stbc = stbc << WMI_HOST_RC_RX_STBC_FLAG_S;
1076 arg->peer_rate_caps |= stbc;
1077 arg->stbc_flag = true;
1080 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1081 arg->peer_rate_caps |= WMI_HOST_RC_TS_FLAG;
1082 else if (ht_cap->mcs.rx_mask[1])
1083 arg->peer_rate_caps |= WMI_HOST_RC_DS_FLAG;
1085 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
1086 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
1087 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
1088 max_nss = (i / 8) + 1;
1089 arg->peer_ht_rates.rates[n++] = i;
1092 /* This is a workaround for HT-enabled STAs which break the spec
1093 * and have no HT capabilities RX mask (no HT RX MCS map).
1095 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1096 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1098 * Firmware asserts if such situation occurs.
1101 arg->peer_ht_rates.num_rates = 8;
1102 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1103 arg->peer_ht_rates.rates[i] = i;
1105 arg->peer_ht_rates.num_rates = n;
1106 arg->peer_nss = min(sta->rx_nss, max_nss);
1109 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1111 arg->peer_ht_rates.num_rates,
1115 static int ath11k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
1117 switch ((mcs_map >> (2 * nss)) & 0x3) {
1118 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
1119 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
1120 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
1126 ath11k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
1127 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
1134 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
1135 mcs_map = ath11k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
1139 idx_limit = fls(mcs_map) - 1;
1143 switch (idx_limit) {
1152 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
1155 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
1158 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
1164 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
1168 tx_mcs_set &= ~(0x3 << (nss * 2));
1169 tx_mcs_set |= mcs << (nss * 2);
1175 static void ath11k_peer_assoc_h_vht(struct ath11k *ar,
1176 struct ieee80211_vif *vif,
1177 struct ieee80211_sta *sta,
1178 struct peer_assoc_params *arg)
1180 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1181 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1182 struct cfg80211_chan_def def;
1183 enum nl80211_band band;
1184 const u16 *vht_mcs_mask;
1186 u8 max_nss, vht_mcs;
1189 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1192 if (!vht_cap->vht_supported)
1195 band = def.chan->band;
1196 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
1198 if (ath11k_peer_assoc_h_vht_masked(vht_mcs_mask))
1201 arg->vht_flag = true;
1203 /* TODO: similar flags required? */
1204 arg->vht_capable = true;
1206 if (def.chan->band == NL80211_BAND_2GHZ)
1207 arg->vht_ng_flag = true;
1209 arg->peer_vht_caps = vht_cap->cap;
1211 ampdu_factor = (vht_cap->cap &
1212 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1213 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1215 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1216 * zero in VHT IE. Using it would result in degraded throughput.
1217 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1218 * it if VHT max_mpdu is smaller.
1220 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1221 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1222 ampdu_factor)) - 1);
1224 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1227 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
1230 /* Calculate peer NSS capability from VHT capabilities if STA
1233 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
1234 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
1237 if (vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED &&
1241 arg->peer_nss = min(sta->rx_nss, max_nss);
1242 arg->rx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1243 arg->rx_mcs_set = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1244 arg->tx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1245 arg->tx_mcs_set = ath11k_peer_assoc_h_vht_limit(
1246 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
1248 /* In IPQ8074 platform, VHT mcs rate 10 and 11 is enabled by default.
1249 * VHT mcs rate 10 and 11 is not suppoerted in 11ac standard.
1250 * so explicitly disable the VHT MCS rate 10 and 11 in 11ac mode.
1252 arg->tx_mcs_set &= ~IEEE80211_VHT_MCS_SUPPORT_0_11_MASK;
1253 arg->tx_mcs_set |= IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11;
1255 if ((arg->tx_mcs_set & IEEE80211_VHT_MCS_NOT_SUPPORTED) ==
1256 IEEE80211_VHT_MCS_NOT_SUPPORTED)
1257 arg->peer_vht_caps &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1260 arg->tx_max_mcs_nss = 0xFF;
1262 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1263 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1265 /* TODO: rxnss_override */
1268 static void ath11k_peer_assoc_h_he(struct ath11k *ar,
1269 struct ieee80211_vif *vif,
1270 struct ieee80211_sta *sta,
1271 struct peer_assoc_params *arg)
1273 const struct ieee80211_sta_he_cap *he_cap = &sta->he_cap;
1277 if (!he_cap->has_he)
1280 arg->he_flag = true;
1282 memcpy(&arg->peer_he_cap_macinfo, he_cap->he_cap_elem.mac_cap_info,
1283 sizeof(arg->peer_he_cap_macinfo));
1284 memcpy(&arg->peer_he_cap_phyinfo, he_cap->he_cap_elem.phy_cap_info,
1285 sizeof(arg->peer_he_cap_phyinfo));
1286 arg->peer_he_ops = vif->bss_conf.he_oper.params;
1288 /* the top most byte is used to indicate BSS color info */
1289 arg->peer_he_ops &= 0xffffff;
1291 /* As per section 26.6.1 11ax Draft5.0, if the Max AMPDU Exponent Extension
1292 * in HE cap is zero, use the arg->peer_max_mpdu as calculated while parsing
1293 * VHT caps(if VHT caps is present) or HT caps (if VHT caps is not present).
1295 * For non-zero value of Max AMPDU Extponent Extension in HE MAC caps,
1296 * if a HE STA sends VHT cap and HE cap IE in assoc request then, use
1297 * MAX_AMPDU_LEN_FACTOR as 20 to calculate max_ampdu length.
1298 * If a HE STA that does not send VHT cap, but HE and HT cap in assoc
1299 * request, then use MAX_AMPDU_LEN_FACTOR as 16 to calculate max_ampdu
1302 ampdu_factor = (he_cap->he_cap_elem.mac_cap_info[3] &
1303 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_MASK) >>
1304 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_SHIFT;
1307 if (sta->vht_cap.vht_supported)
1308 arg->peer_max_mpdu = (1 << (IEEE80211_HE_VHT_MAX_AMPDU_FACTOR +
1310 else if (sta->ht_cap.ht_supported)
1311 arg->peer_max_mpdu = (1 << (IEEE80211_HE_HT_MAX_AMPDU_FACTOR +
1315 if (he_cap->he_cap_elem.phy_cap_info[6] &
1316 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
1320 arg->peer_ppet.numss_m1 = he_cap->ppe_thres[0] &
1321 IEEE80211_PPE_THRES_NSS_MASK;
1322 arg->peer_ppet.ru_bit_mask =
1323 (he_cap->ppe_thres[0] &
1324 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
1325 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
1327 for (nss = 0; nss <= arg->peer_ppet.numss_m1; nss++) {
1328 for (ru = 0; ru < 4; ru++) {
1332 if ((arg->peer_ppet.ru_bit_mask & BIT(ru)) == 0)
1334 for (i = 0; i < 6; i++) {
1336 val |= ((he_cap->ppe_thres[bit / 8] >>
1337 (bit % 8)) & 0x1) << 5;
1340 arg->peer_ppet.ppet16_ppet8_ru3_ru0[nss] |=
1346 if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_RES)
1347 arg->twt_responder = true;
1348 if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_REQ)
1349 arg->twt_requester = true;
1351 switch (sta->bandwidth) {
1352 case IEEE80211_STA_RX_BW_160:
1353 if (he_cap->he_cap_elem.phy_cap_info[0] &
1354 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) {
1355 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80p80);
1356 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v;
1358 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80p80);
1359 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v;
1361 arg->peer_he_mcs_count++;
1363 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160);
1364 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v;
1366 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_160);
1367 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v;
1369 arg->peer_he_mcs_count++;
1373 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80);
1374 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v;
1376 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80);
1377 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v;
1379 arg->peer_he_mcs_count++;
1384 static void ath11k_peer_assoc_h_smps(struct ieee80211_sta *sta,
1385 struct peer_assoc_params *arg)
1387 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1390 if (!ht_cap->ht_supported)
1393 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1394 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1397 case WLAN_HT_CAP_SM_PS_STATIC:
1398 arg->static_mimops_flag = true;
1400 case WLAN_HT_CAP_SM_PS_DYNAMIC:
1401 arg->dynamic_mimops_flag = true;
1403 case WLAN_HT_CAP_SM_PS_DISABLED:
1404 arg->spatial_mux_flag = true;
1411 static void ath11k_peer_assoc_h_qos(struct ath11k *ar,
1412 struct ieee80211_vif *vif,
1413 struct ieee80211_sta *sta,
1414 struct peer_assoc_params *arg)
1416 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1418 switch (arvif->vdev_type) {
1419 case WMI_VDEV_TYPE_AP:
1421 /* TODO: Check WME vs QoS */
1422 arg->is_wme_set = true;
1423 arg->qos_flag = true;
1426 if (sta->wme && sta->uapsd_queues) {
1427 /* TODO: Check WME vs QoS */
1428 arg->is_wme_set = true;
1429 arg->apsd_flag = true;
1430 arg->peer_rate_caps |= WMI_HOST_RC_UAPSD_FLAG;
1433 case WMI_VDEV_TYPE_STA:
1435 arg->is_wme_set = true;
1436 arg->qos_flag = true;
1443 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac peer %pM qos %d\n",
1444 sta->addr, arg->qos_flag);
1447 static int ath11k_peer_assoc_qos_ap(struct ath11k *ar,
1448 struct ath11k_vif *arvif,
1449 struct ieee80211_sta *sta)
1451 struct ap_ps_params params;
1456 lockdep_assert_held(&ar->conf_mutex);
1458 params.vdev_id = arvif->vdev_id;
1460 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1461 sta->uapsd_queues, sta->max_sp);
1464 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1465 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1466 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1467 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1468 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1469 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1470 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1471 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1472 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1473 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1474 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1475 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1478 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1479 max_sp = sta->max_sp;
1481 params.param = WMI_AP_PS_PEER_PARAM_UAPSD;
1482 params.value = uapsd;
1483 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
1487 params.param = WMI_AP_PS_PEER_PARAM_MAX_SP;
1488 params.value = max_sp;
1489 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
1493 /* TODO revisit during testing */
1494 params.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_FRMTYPE;
1495 params.value = DISABLE_SIFS_RESPONSE_TRIGGER;
1496 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
1500 params.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_UAPSD;
1501 params.value = DISABLE_SIFS_RESPONSE_TRIGGER;
1502 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
1509 ath11k_warn(ar->ab, "failed to set ap ps peer param %d for vdev %i: %d\n",
1510 params.param, arvif->vdev_id, ret);
1514 static bool ath11k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
1516 return sta->supp_rates[NL80211_BAND_2GHZ] >>
1517 ATH11K_MAC_FIRST_OFDM_RATE_IDX;
1520 static enum wmi_phy_mode ath11k_mac_get_phymode_vht(struct ath11k *ar,
1521 struct ieee80211_sta *sta)
1523 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
1524 switch (sta->vht_cap.cap &
1525 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
1526 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
1527 return MODE_11AC_VHT160;
1528 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
1529 return MODE_11AC_VHT80_80;
1531 /* not sure if this is a valid case? */
1532 return MODE_11AC_VHT160;
1536 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1537 return MODE_11AC_VHT80;
1539 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1540 return MODE_11AC_VHT40;
1542 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1543 return MODE_11AC_VHT20;
1545 return MODE_UNKNOWN;
1548 static enum wmi_phy_mode ath11k_mac_get_phymode_he(struct ath11k *ar,
1549 struct ieee80211_sta *sta)
1551 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
1552 if (sta->he_cap.he_cap_elem.phy_cap_info[0] &
1553 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
1554 return MODE_11AX_HE160;
1555 else if (sta->he_cap.he_cap_elem.phy_cap_info[0] &
1556 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)
1557 return MODE_11AX_HE80_80;
1558 /* not sure if this is a valid case? */
1559 return MODE_11AX_HE160;
1562 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1563 return MODE_11AX_HE80;
1565 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1566 return MODE_11AX_HE40;
1568 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1569 return MODE_11AX_HE20;
1571 return MODE_UNKNOWN;
1574 static void ath11k_peer_assoc_h_phymode(struct ath11k *ar,
1575 struct ieee80211_vif *vif,
1576 struct ieee80211_sta *sta,
1577 struct peer_assoc_params *arg)
1579 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1580 struct cfg80211_chan_def def;
1581 enum nl80211_band band;
1582 const u8 *ht_mcs_mask;
1583 const u16 *vht_mcs_mask;
1584 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1586 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1589 band = def.chan->band;
1590 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
1591 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
1594 case NL80211_BAND_2GHZ:
1595 if (sta->he_cap.has_he) {
1596 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1597 phymode = MODE_11AX_HE80_2G;
1598 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1599 phymode = MODE_11AX_HE40_2G;
1601 phymode = MODE_11AX_HE20_2G;
1602 } else if (sta->vht_cap.vht_supported &&
1603 !ath11k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
1604 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1605 phymode = MODE_11AC_VHT40;
1607 phymode = MODE_11AC_VHT20;
1608 } else if (sta->ht_cap.ht_supported &&
1609 !ath11k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
1610 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1611 phymode = MODE_11NG_HT40;
1613 phymode = MODE_11NG_HT20;
1614 } else if (ath11k_mac_sta_has_ofdm_only(sta)) {
1620 case NL80211_BAND_5GHZ:
1621 case NL80211_BAND_6GHZ:
1622 /* Check HE first */
1623 if (sta->he_cap.has_he) {
1624 phymode = ath11k_mac_get_phymode_he(ar, sta);
1625 } else if (sta->vht_cap.vht_supported &&
1626 !ath11k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
1627 phymode = ath11k_mac_get_phymode_vht(ar, sta);
1628 } else if (sta->ht_cap.ht_supported &&
1629 !ath11k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
1630 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
1631 phymode = MODE_11NA_HT40;
1633 phymode = MODE_11NA_HT20;
1642 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac peer %pM phymode %s\n",
1643 sta->addr, ath11k_wmi_phymode_str(phymode));
1645 arg->peer_phymode = phymode;
1646 WARN_ON(phymode == MODE_UNKNOWN);
1649 static void ath11k_peer_assoc_prepare(struct ath11k *ar,
1650 struct ieee80211_vif *vif,
1651 struct ieee80211_sta *sta,
1652 struct peer_assoc_params *arg,
1655 lockdep_assert_held(&ar->conf_mutex);
1657 memset(arg, 0, sizeof(*arg));
1659 reinit_completion(&ar->peer_assoc_done);
1661 arg->peer_new_assoc = !reassoc;
1662 ath11k_peer_assoc_h_basic(ar, vif, sta, arg);
1663 ath11k_peer_assoc_h_crypto(ar, vif, sta, arg);
1664 ath11k_peer_assoc_h_rates(ar, vif, sta, arg);
1665 ath11k_peer_assoc_h_ht(ar, vif, sta, arg);
1666 ath11k_peer_assoc_h_vht(ar, vif, sta, arg);
1667 ath11k_peer_assoc_h_he(ar, vif, sta, arg);
1668 ath11k_peer_assoc_h_qos(ar, vif, sta, arg);
1669 ath11k_peer_assoc_h_phymode(ar, vif, sta, arg);
1670 ath11k_peer_assoc_h_smps(sta, arg);
1672 /* TODO: amsdu_disable req? */
1675 static int ath11k_setup_peer_smps(struct ath11k *ar, struct ath11k_vif *arvif,
1677 const struct ieee80211_sta_ht_cap *ht_cap)
1681 if (!ht_cap->ht_supported)
1684 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1685 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1687 if (smps >= ARRAY_SIZE(ath11k_smps_map))
1690 return ath11k_wmi_set_peer_param(ar, addr, arvif->vdev_id,
1691 WMI_PEER_MIMO_PS_STATE,
1692 ath11k_smps_map[smps]);
1695 static void ath11k_bss_assoc(struct ieee80211_hw *hw,
1696 struct ieee80211_vif *vif,
1697 struct ieee80211_bss_conf *bss_conf)
1699 struct ath11k *ar = hw->priv;
1700 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1701 struct peer_assoc_params peer_arg;
1702 struct ieee80211_sta *ap_sta;
1705 lockdep_assert_held(&ar->conf_mutex);
1707 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1708 arvif->vdev_id, arvif->bssid, arvif->aid);
1712 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1714 ath11k_warn(ar->ab, "failed to find station entry for bss %pM vdev %i\n",
1715 bss_conf->bssid, arvif->vdev_id);
1720 ath11k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg, false);
1724 ret = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
1726 ath11k_warn(ar->ab, "failed to run peer assoc for %pM vdev %i: %d\n",
1727 bss_conf->bssid, arvif->vdev_id, ret);
1731 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
1732 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
1733 bss_conf->bssid, arvif->vdev_id);
1737 ret = ath11k_setup_peer_smps(ar, arvif, bss_conf->bssid,
1740 ath11k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n",
1741 arvif->vdev_id, ret);
1745 WARN_ON(arvif->is_up);
1747 arvif->aid = bss_conf->aid;
1748 ether_addr_copy(arvif->bssid, bss_conf->bssid);
1750 ret = ath11k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1752 ath11k_warn(ar->ab, "failed to set vdev %d up: %d\n",
1753 arvif->vdev_id, ret);
1757 arvif->is_up = true;
1759 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1760 "mac vdev %d up (associated) bssid %pM aid %d\n",
1761 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1763 /* Authorize BSS Peer */
1764 ret = ath11k_wmi_set_peer_param(ar, arvif->bssid,
1769 ath11k_warn(ar->ab, "Unable to authorize BSS peer: %d\n", ret);
1771 ret = ath11k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id,
1772 &bss_conf->he_obss_pd);
1774 ath11k_warn(ar->ab, "failed to set vdev %i OBSS PD parameters: %d\n",
1775 arvif->vdev_id, ret);
1778 static void ath11k_bss_disassoc(struct ieee80211_hw *hw,
1779 struct ieee80211_vif *vif)
1781 struct ath11k *ar = hw->priv;
1782 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1785 lockdep_assert_held(&ar->conf_mutex);
1787 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1788 arvif->vdev_id, arvif->bssid);
1790 ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id);
1792 ath11k_warn(ar->ab, "failed to down vdev %i: %d\n",
1793 arvif->vdev_id, ret);
1795 arvif->is_up = false;
1797 /* TODO: cancel connection_loss_work */
1800 static u32 ath11k_mac_get_rate_hw_value(int bitrate)
1807 if (ath11k_mac_bitrate_is_cck(bitrate))
1808 preamble = WMI_RATE_PREAMBLE_CCK;
1810 preamble = WMI_RATE_PREAMBLE_OFDM;
1812 for (i = 0; i < ARRAY_SIZE(ath11k_legacy_rates); i++) {
1813 if (ath11k_legacy_rates[i].bitrate != bitrate)
1816 hw_value = ath11k_legacy_rates[i].hw_value;
1817 rate = ATH11K_HW_RATE_CODE(hw_value, 0, preamble);
1825 static void ath11k_recalculate_mgmt_rate(struct ath11k *ar,
1826 struct ieee80211_vif *vif,
1827 struct cfg80211_chan_def *def)
1829 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1830 const struct ieee80211_supported_band *sband;
1837 lockdep_assert_held(&ar->conf_mutex);
1839 sband = ar->hw->wiphy->bands[def->chan->band];
1840 basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
1841 bitrate = sband->bitrates[basic_rate_idx].bitrate;
1843 hw_rate_code = ath11k_mac_get_rate_hw_value(bitrate);
1844 if (hw_rate_code < 0) {
1845 ath11k_warn(ar->ab, "bitrate not supported %d\n", bitrate);
1849 vdev_param = WMI_VDEV_PARAM_MGMT_RATE;
1850 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
1853 ath11k_warn(ar->ab, "failed to set mgmt tx rate %d\n", ret);
1855 vdev_param = WMI_VDEV_PARAM_BEACON_RATE;
1856 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
1859 ath11k_warn(ar->ab, "failed to set beacon tx rate %d\n", ret);
1862 static void ath11k_mac_op_bss_info_changed(struct ieee80211_hw *hw,
1863 struct ieee80211_vif *vif,
1864 struct ieee80211_bss_conf *info,
1867 struct ath11k *ar = hw->priv;
1868 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
1869 struct cfg80211_chan_def def;
1870 u32 param_id, param_value;
1871 enum nl80211_band band;
1881 mutex_lock(&ar->conf_mutex);
1883 if (changed & BSS_CHANGED_BEACON_INT) {
1884 arvif->beacon_interval = info->beacon_int;
1886 param_id = WMI_VDEV_PARAM_BEACON_INTERVAL;
1887 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
1889 arvif->beacon_interval);
1891 ath11k_warn(ar->ab, "Failed to set beacon interval for VDEV: %d\n",
1894 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1895 "Beacon interval: %d set for VDEV: %d\n",
1896 arvif->beacon_interval, arvif->vdev_id);
1899 if (changed & BSS_CHANGED_BEACON) {
1900 param_id = WMI_PDEV_PARAM_BEACON_TX_MODE;
1901 param_value = WMI_BEACON_STAGGERED_MODE;
1902 ret = ath11k_wmi_pdev_set_param(ar, param_id,
1903 param_value, ar->pdev->pdev_id);
1905 ath11k_warn(ar->ab, "Failed to set beacon mode for VDEV: %d\n",
1908 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1909 "Set staggered beacon mode for VDEV: %d\n",
1912 ret = ath11k_mac_setup_bcn_tmpl(arvif);
1914 ath11k_warn(ar->ab, "failed to update bcn template: %d\n",
1917 if (vif->bss_conf.he_support) {
1918 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
1919 WMI_VDEV_PARAM_BA_MODE,
1920 WMI_BA_MODE_BUFFER_SIZE_256);
1923 "failed to set BA BUFFER SIZE 256 for vdev: %d\n",
1926 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1927 "Set BA BUFFER SIZE 256 for VDEV: %d\n",
1932 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
1933 arvif->dtim_period = info->dtim_period;
1935 param_id = WMI_VDEV_PARAM_DTIM_PERIOD;
1936 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
1938 arvif->dtim_period);
1941 ath11k_warn(ar->ab, "Failed to set dtim period for VDEV %d: %i\n",
1942 arvif->vdev_id, ret);
1944 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1945 "DTIM period: %d set for VDEV: %d\n",
1946 arvif->dtim_period, arvif->vdev_id);
1949 if (changed & BSS_CHANGED_SSID &&
1950 vif->type == NL80211_IFTYPE_AP) {
1951 arvif->u.ap.ssid_len = info->ssid_len;
1953 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
1954 arvif->u.ap.hidden_ssid = info->hidden_ssid;
1957 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
1958 ether_addr_copy(arvif->bssid, info->bssid);
1960 if (changed & BSS_CHANGED_BEACON_ENABLED)
1961 ath11k_control_beaconing(arvif, info);
1963 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1966 cts_prot = !!(info->use_cts_prot);
1967 param_id = WMI_VDEV_PARAM_PROTECTION_MODE;
1969 if (arvif->is_started) {
1970 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
1971 param_id, cts_prot);
1973 ath11k_warn(ar->ab, "Failed to set CTS prot for VDEV: %d\n",
1976 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "Set CTS prot: %d for VDEV: %d\n",
1977 cts_prot, arvif->vdev_id);
1979 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "defer protection mode setup, vdev is not ready yet\n");
1983 if (changed & BSS_CHANGED_ERP_SLOT) {
1986 if (info->use_short_slot)
1987 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
1990 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
1992 param_id = WMI_VDEV_PARAM_SLOT_TIME;
1993 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
1994 param_id, slottime);
1996 ath11k_warn(ar->ab, "Failed to set erp slot for VDEV: %d\n",
1999 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2000 "Set slottime: %d for VDEV: %d\n",
2001 slottime, arvif->vdev_id);
2004 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2007 if (info->use_short_preamble)
2008 preamble = WMI_VDEV_PREAMBLE_SHORT;
2010 preamble = WMI_VDEV_PREAMBLE_LONG;
2012 param_id = WMI_VDEV_PARAM_PREAMBLE;
2013 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2014 param_id, preamble);
2016 ath11k_warn(ar->ab, "Failed to set preamble for VDEV: %d\n",
2019 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2020 "Set preamble: %d for VDEV: %d\n",
2021 preamble, arvif->vdev_id);
2024 if (changed & BSS_CHANGED_ASSOC) {
2026 ath11k_bss_assoc(hw, vif, info);
2028 ath11k_bss_disassoc(hw, vif);
2031 if (changed & BSS_CHANGED_TXPOWER) {
2032 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev_id %i txpower %d\n",
2033 arvif->vdev_id, info->txpower);
2035 arvif->txpower = info->txpower;
2036 ath11k_mac_txpower_recalc(ar);
2039 if (changed & BSS_CHANGED_MCAST_RATE &&
2040 !ath11k_mac_vif_chan(arvif->vif, &def)) {
2041 band = def.chan->band;
2042 mcast_rate = vif->bss_conf.mcast_rate[band];
2045 rateidx = mcast_rate - 1;
2047 rateidx = ffs(vif->bss_conf.basic_rates) - 1;
2049 if (ar->pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP)
2050 rateidx += ATH11K_MAC_FIRST_OFDM_RATE_IDX;
2052 bitrate = ath11k_legacy_rates[rateidx].bitrate;
2053 hw_value = ath11k_legacy_rates[rateidx].hw_value;
2055 if (ath11k_mac_bitrate_is_cck(bitrate))
2056 preamble = WMI_RATE_PREAMBLE_CCK;
2058 preamble = WMI_RATE_PREAMBLE_OFDM;
2060 rate = ATH11K_HW_RATE_CODE(hw_value, 0, preamble);
2062 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2063 "mac vdev %d mcast_rate %x\n",
2064 arvif->vdev_id, rate);
2066 vdev_param = WMI_VDEV_PARAM_MCAST_DATA_RATE;
2067 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2071 "failed to set mcast rate on vdev %i: %d\n",
2072 arvif->vdev_id, ret);
2074 vdev_param = WMI_VDEV_PARAM_BCAST_DATA_RATE;
2075 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2079 "failed to set bcast rate on vdev %i: %d\n",
2080 arvif->vdev_id, ret);
2083 if (changed & BSS_CHANGED_BASIC_RATES &&
2084 !ath11k_mac_vif_chan(arvif->vif, &def))
2085 ath11k_recalculate_mgmt_rate(ar, vif, &def);
2087 if (changed & BSS_CHANGED_TWT) {
2088 if (info->twt_requester || info->twt_responder)
2089 ath11k_wmi_send_twt_enable_cmd(ar, ar->pdev->pdev_id);
2091 ath11k_wmi_send_twt_disable_cmd(ar, ar->pdev->pdev_id);
2094 if (changed & BSS_CHANGED_HE_OBSS_PD)
2095 ath11k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id,
2098 if (changed & BSS_CHANGED_HE_BSS_COLOR) {
2099 if (vif->type == NL80211_IFTYPE_AP) {
2100 ret = ath11k_wmi_send_obss_color_collision_cfg_cmd(
2101 ar, arvif->vdev_id, info->he_bss_color.color,
2102 ATH11K_BSS_COLOR_COLLISION_DETECTION_AP_PERIOD_MS,
2103 info->he_bss_color.enabled);
2105 ath11k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n",
2106 arvif->vdev_id, ret);
2107 } else if (vif->type == NL80211_IFTYPE_STATION) {
2108 ret = ath11k_wmi_send_bss_color_change_enable_cmd(ar,
2112 ath11k_warn(ar->ab, "failed to enable bss color change on vdev %i: %d\n",
2113 arvif->vdev_id, ret);
2114 ret = ath11k_wmi_send_obss_color_collision_cfg_cmd(
2115 ar, arvif->vdev_id, 0,
2116 ATH11K_BSS_COLOR_COLLISION_DETECTION_STA_PERIOD_MS, 1);
2118 ath11k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n",
2119 arvif->vdev_id, ret);
2123 mutex_unlock(&ar->conf_mutex);
2126 void __ath11k_mac_scan_finish(struct ath11k *ar)
2128 lockdep_assert_held(&ar->data_lock);
2130 switch (ar->scan.state) {
2131 case ATH11K_SCAN_IDLE:
2133 case ATH11K_SCAN_RUNNING:
2134 case ATH11K_SCAN_ABORTING:
2135 if (!ar->scan.is_roc) {
2136 struct cfg80211_scan_info info = {
2137 .aborted = (ar->scan.state ==
2138 ATH11K_SCAN_ABORTING),
2141 ieee80211_scan_completed(ar->hw, &info);
2142 } else if (ar->scan.roc_notify) {
2143 ieee80211_remain_on_channel_expired(ar->hw);
2146 case ATH11K_SCAN_STARTING:
2147 ar->scan.state = ATH11K_SCAN_IDLE;
2148 ar->scan_channel = NULL;
2149 ar->scan.roc_freq = 0;
2150 cancel_delayed_work(&ar->scan.timeout);
2151 complete(&ar->scan.completed);
2156 void ath11k_mac_scan_finish(struct ath11k *ar)
2158 spin_lock_bh(&ar->data_lock);
2159 __ath11k_mac_scan_finish(ar);
2160 spin_unlock_bh(&ar->data_lock);
2163 static int ath11k_scan_stop(struct ath11k *ar)
2165 struct scan_cancel_param arg = {
2166 .req_type = WLAN_SCAN_CANCEL_SINGLE,
2167 .scan_id = ATH11K_SCAN_ID,
2171 lockdep_assert_held(&ar->conf_mutex);
2173 /* TODO: Fill other STOP Params */
2174 arg.pdev_id = ar->pdev->pdev_id;
2176 ret = ath11k_wmi_send_scan_stop_cmd(ar, &arg);
2178 ath11k_warn(ar->ab, "failed to stop wmi scan: %d\n", ret);
2182 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
2185 "failed to receive scan abort comple: timed out\n");
2187 } else if (ret > 0) {
2192 /* Scan state should be updated upon scan completion but in case
2193 * firmware fails to deliver the event (for whatever reason) it is
2194 * desired to clean up scan state anyway. Firmware may have just
2195 * dropped the scan completion event delivery due to transport pipe
2196 * being overflown with data and/or it can recover on its own before
2197 * next scan request is submitted.
2199 spin_lock_bh(&ar->data_lock);
2200 if (ar->scan.state != ATH11K_SCAN_IDLE)
2201 __ath11k_mac_scan_finish(ar);
2202 spin_unlock_bh(&ar->data_lock);
2207 static void ath11k_scan_abort(struct ath11k *ar)
2211 lockdep_assert_held(&ar->conf_mutex);
2213 spin_lock_bh(&ar->data_lock);
2215 switch (ar->scan.state) {
2216 case ATH11K_SCAN_IDLE:
2217 /* This can happen if timeout worker kicked in and called
2218 * abortion while scan completion was being processed.
2221 case ATH11K_SCAN_STARTING:
2222 case ATH11K_SCAN_ABORTING:
2223 ath11k_warn(ar->ab, "refusing scan abortion due to invalid scan state: %d\n",
2226 case ATH11K_SCAN_RUNNING:
2227 ar->scan.state = ATH11K_SCAN_ABORTING;
2228 spin_unlock_bh(&ar->data_lock);
2230 ret = ath11k_scan_stop(ar);
2232 ath11k_warn(ar->ab, "failed to abort scan: %d\n", ret);
2234 spin_lock_bh(&ar->data_lock);
2238 spin_unlock_bh(&ar->data_lock);
2241 static void ath11k_scan_timeout_work(struct work_struct *work)
2243 struct ath11k *ar = container_of(work, struct ath11k,
2246 mutex_lock(&ar->conf_mutex);
2247 ath11k_scan_abort(ar);
2248 mutex_unlock(&ar->conf_mutex);
2251 static int ath11k_start_scan(struct ath11k *ar,
2252 struct scan_req_params *arg)
2256 lockdep_assert_held(&ar->conf_mutex);
2258 if (ath11k_spectral_get_mode(ar) == ATH11K_SPECTRAL_BACKGROUND)
2259 ath11k_spectral_reset_buffer(ar);
2261 ret = ath11k_wmi_send_scan_start_cmd(ar, arg);
2265 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
2267 ret = ath11k_scan_stop(ar);
2269 ath11k_warn(ar->ab, "failed to stop scan: %d\n", ret);
2274 /* If we failed to start the scan, return error code at
2275 * this point. This is probably due to some issue in the
2276 * firmware, but no need to wedge the driver due to that...
2278 spin_lock_bh(&ar->data_lock);
2279 if (ar->scan.state == ATH11K_SCAN_IDLE) {
2280 spin_unlock_bh(&ar->data_lock);
2283 spin_unlock_bh(&ar->data_lock);
2288 static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
2289 struct ieee80211_vif *vif,
2290 struct ieee80211_scan_request *hw_req)
2292 struct ath11k *ar = hw->priv;
2293 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
2294 struct cfg80211_scan_request *req = &hw_req->req;
2295 struct scan_req_params arg;
2299 mutex_lock(&ar->conf_mutex);
2301 spin_lock_bh(&ar->data_lock);
2302 switch (ar->scan.state) {
2303 case ATH11K_SCAN_IDLE:
2304 reinit_completion(&ar->scan.started);
2305 reinit_completion(&ar->scan.completed);
2306 ar->scan.state = ATH11K_SCAN_STARTING;
2307 ar->scan.is_roc = false;
2308 ar->scan.vdev_id = arvif->vdev_id;
2311 case ATH11K_SCAN_STARTING:
2312 case ATH11K_SCAN_RUNNING:
2313 case ATH11K_SCAN_ABORTING:
2317 spin_unlock_bh(&ar->data_lock);
2322 memset(&arg, 0, sizeof(arg));
2323 ath11k_wmi_start_scan_init(ar, &arg);
2324 arg.vdev_id = arvif->vdev_id;
2325 arg.scan_id = ATH11K_SCAN_ID;
2328 arg.extraie.len = req->ie_len;
2329 arg.extraie.ptr = kzalloc(req->ie_len, GFP_KERNEL);
2330 memcpy(arg.extraie.ptr, req->ie, req->ie_len);
2334 arg.num_ssids = req->n_ssids;
2335 for (i = 0; i < arg.num_ssids; i++) {
2336 arg.ssid[i].length = req->ssids[i].ssid_len;
2337 memcpy(&arg.ssid[i].ssid, req->ssids[i].ssid,
2338 req->ssids[i].ssid_len);
2341 arg.scan_flags |= WMI_SCAN_FLAG_PASSIVE;
2344 if (req->n_channels) {
2345 arg.num_chan = req->n_channels;
2346 for (i = 0; i < arg.num_chan; i++)
2347 arg.chan_list[i] = req->channels[i]->center_freq;
2350 ret = ath11k_start_scan(ar, &arg);
2352 ath11k_warn(ar->ab, "failed to start hw scan: %d\n", ret);
2353 spin_lock_bh(&ar->data_lock);
2354 ar->scan.state = ATH11K_SCAN_IDLE;
2355 spin_unlock_bh(&ar->data_lock);
2358 /* Add a 200ms margin to account for event/command processing */
2359 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2360 msecs_to_jiffies(arg.max_scan_time +
2361 ATH11K_MAC_SCAN_TIMEOUT_MSECS));
2365 kfree(arg.extraie.ptr);
2367 mutex_unlock(&ar->conf_mutex);
2371 static void ath11k_mac_op_cancel_hw_scan(struct ieee80211_hw *hw,
2372 struct ieee80211_vif *vif)
2374 struct ath11k *ar = hw->priv;
2376 mutex_lock(&ar->conf_mutex);
2377 ath11k_scan_abort(ar);
2378 mutex_unlock(&ar->conf_mutex);
2380 cancel_delayed_work_sync(&ar->scan.timeout);
2383 static int ath11k_install_key(struct ath11k_vif *arvif,
2384 struct ieee80211_key_conf *key,
2385 enum set_key_cmd cmd,
2386 const u8 *macaddr, u32 flags)
2389 struct ath11k *ar = arvif->ar;
2390 struct wmi_vdev_install_key_arg arg = {
2391 .vdev_id = arvif->vdev_id,
2392 .key_idx = key->keyidx,
2393 .key_len = key->keylen,
2394 .key_data = key->key,
2399 lockdep_assert_held(&arvif->ar->conf_mutex);
2401 reinit_completion(&ar->install_key_done);
2403 if (test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags))
2406 if (cmd == DISABLE_KEY) {
2407 /* TODO: Check if FW expects value other than NONE for del */
2408 /* arg.key_cipher = WMI_CIPHER_NONE; */
2410 arg.key_data = NULL;
2414 switch (key->cipher) {
2415 case WLAN_CIPHER_SUITE_CCMP:
2416 arg.key_cipher = WMI_CIPHER_AES_CCM;
2417 /* TODO: Re-check if flag is valid */
2418 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
2420 case WLAN_CIPHER_SUITE_TKIP:
2421 arg.key_cipher = WMI_CIPHER_TKIP;
2422 arg.key_txmic_len = 8;
2423 arg.key_rxmic_len = 8;
2425 case WLAN_CIPHER_SUITE_CCMP_256:
2426 arg.key_cipher = WMI_CIPHER_AES_CCM;
2428 case WLAN_CIPHER_SUITE_GCMP:
2429 case WLAN_CIPHER_SUITE_GCMP_256:
2430 arg.key_cipher = WMI_CIPHER_AES_GCM;
2433 ath11k_warn(ar->ab, "cipher %d is not supported\n", key->cipher);
2437 if (test_bit(ATH11K_FLAG_RAW_MODE, &ar->ab->dev_flags))
2438 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV |
2439 IEEE80211_KEY_FLAG_RESERVE_TAILROOM;
2442 ret = ath11k_wmi_vdev_install_key(arvif->ar, &arg);
2447 if (!wait_for_completion_timeout(&ar->install_key_done, 1 * HZ))
2450 return ar->install_key_status ? -EINVAL : 0;
2453 static int ath11k_clear_peer_keys(struct ath11k_vif *arvif,
2456 struct ath11k *ar = arvif->ar;
2457 struct ath11k_base *ab = ar->ab;
2458 struct ath11k_peer *peer;
2459 int first_errno = 0;
2464 lockdep_assert_held(&ar->conf_mutex);
2466 spin_lock_bh(&ab->base_lock);
2467 peer = ath11k_peer_find(ab, arvif->vdev_id, addr);
2468 spin_unlock_bh(&ab->base_lock);
2473 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
2477 /* key flags are not required to delete the key */
2478 ret = ath11k_install_key(arvif, peer->keys[i],
2479 DISABLE_KEY, addr, flags);
2480 if (ret < 0 && first_errno == 0)
2484 ath11k_warn(ab, "failed to remove peer key %d: %d\n",
2487 spin_lock_bh(&ab->base_lock);
2488 peer->keys[i] = NULL;
2489 spin_unlock_bh(&ab->base_lock);
2495 static int ath11k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2496 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2497 struct ieee80211_key_conf *key)
2499 struct ath11k *ar = hw->priv;
2500 struct ath11k_base *ab = ar->ab;
2501 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
2502 struct ath11k_peer *peer;
2503 struct ath11k_sta *arsta;
2504 const u8 *peer_addr;
2508 /* BIP needs to be done in software */
2509 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2510 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2511 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 ||
2512 key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256)
2515 if (test_bit(ATH11K_FLAG_HW_CRYPTO_DISABLED, &ar->ab->dev_flags))
2518 if (key->keyidx > WMI_MAX_KEY_INDEX)
2521 mutex_lock(&ar->conf_mutex);
2524 peer_addr = sta->addr;
2525 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2526 peer_addr = vif->bss_conf.bssid;
2528 peer_addr = vif->addr;
2530 key->hw_key_idx = key->keyidx;
2532 /* the peer should not disappear in mid-way (unless FW goes awry) since
2533 * we already hold conf_mutex. we just make sure its there now.
2535 spin_lock_bh(&ab->base_lock);
2536 peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr);
2537 spin_unlock_bh(&ab->base_lock);
2540 if (cmd == SET_KEY) {
2541 ath11k_warn(ab, "cannot install key for non-existent peer %pM\n",
2546 /* if the peer doesn't exist there is no key to disable
2553 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
2554 flags |= WMI_KEY_PAIRWISE;
2556 flags |= WMI_KEY_GROUP;
2558 ret = ath11k_install_key(arvif, key, cmd, peer_addr, flags);
2560 ath11k_warn(ab, "ath11k_install_key failed (%d)\n", ret);
2564 ret = ath11k_dp_peer_rx_pn_replay_config(arvif, peer_addr, cmd, key);
2566 ath11k_warn(ab, "failed to offload PN replay detection %d\n", ret);
2570 spin_lock_bh(&ab->base_lock);
2571 peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr);
2572 if (peer && cmd == SET_KEY) {
2573 peer->keys[key->keyidx] = key;
2574 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
2575 peer->ucast_keyidx = key->keyidx;
2576 peer->sec_type = ath11k_dp_tx_get_encrypt_type(key->cipher);
2578 peer->mcast_keyidx = key->keyidx;
2579 peer->sec_type_grp = ath11k_dp_tx_get_encrypt_type(key->cipher);
2581 } else if (peer && cmd == DISABLE_KEY) {
2582 peer->keys[key->keyidx] = NULL;
2583 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
2584 peer->ucast_keyidx = 0;
2586 peer->mcast_keyidx = 0;
2588 /* impossible unless FW goes crazy */
2589 ath11k_warn(ab, "peer %pM disappeared!\n", peer_addr);
2592 arsta = (struct ath11k_sta *)sta->drv_priv;
2594 switch (key->cipher) {
2595 case WLAN_CIPHER_SUITE_TKIP:
2596 case WLAN_CIPHER_SUITE_CCMP:
2597 case WLAN_CIPHER_SUITE_CCMP_256:
2598 case WLAN_CIPHER_SUITE_GCMP:
2599 case WLAN_CIPHER_SUITE_GCMP_256:
2601 arsta->pn_type = HAL_PN_TYPE_WPA;
2603 arsta->pn_type = HAL_PN_TYPE_NONE;
2606 arsta->pn_type = HAL_PN_TYPE_NONE;
2611 spin_unlock_bh(&ab->base_lock);
2614 mutex_unlock(&ar->conf_mutex);
2619 ath11k_mac_bitrate_mask_num_vht_rates(struct ath11k *ar,
2620 enum nl80211_band band,
2621 const struct cfg80211_bitrate_mask *mask)
2626 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
2627 num_rates += hweight16(mask->control[band].vht_mcs[i]);
2633 ath11k_mac_set_peer_vht_fixed_rate(struct ath11k_vif *arvif,
2634 struct ieee80211_sta *sta,
2635 const struct cfg80211_bitrate_mask *mask,
2636 enum nl80211_band band)
2638 struct ath11k *ar = arvif->ar;
2643 lockdep_assert_held(&ar->conf_mutex);
2647 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
2648 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
2650 vht_rate = ffs(mask->control[band].vht_mcs[i]) - 1;
2655 ath11k_warn(ar->ab, "No single VHT Fixed rate found to set for %pM",
2660 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2661 "Setting Fixed VHT Rate for peer %pM. Device will not switch to any other selected rates",
2664 rate_code = ATH11K_HW_RATE_CODE(vht_rate, nss - 1,
2665 WMI_RATE_PREAMBLE_VHT);
2666 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
2668 WMI_PEER_PARAM_FIXED_RATE,
2672 "failed to update STA %pM Fixed Rate %d: %d\n",
2673 sta->addr, rate_code, ret);
2678 static int ath11k_station_assoc(struct ath11k *ar,
2679 struct ieee80211_vif *vif,
2680 struct ieee80211_sta *sta,
2683 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
2684 struct peer_assoc_params peer_arg;
2686 struct cfg80211_chan_def def;
2687 enum nl80211_band band;
2688 struct cfg80211_bitrate_mask *mask;
2691 lockdep_assert_held(&ar->conf_mutex);
2693 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
2696 band = def.chan->band;
2697 mask = &arvif->bitrate_mask;
2699 ath11k_peer_assoc_prepare(ar, vif, sta, &peer_arg, reassoc);
2701 ret = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
2703 ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2704 sta->addr, arvif->vdev_id, ret);
2708 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
2709 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
2710 sta->addr, arvif->vdev_id);
2714 num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask);
2716 /* If single VHT rate is configured (by set_bitrate_mask()),
2717 * peer_assoc will disable VHT. This is now enabled by a peer specific
2719 * Note that all other rates and NSS will be disabled for this peer.
2721 if (sta->vht_cap.vht_supported && num_vht_rates == 1) {
2722 ret = ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask,
2728 /* Re-assoc is run only to update supported rates for given station. It
2729 * doesn't make much sense to reconfigure the peer completely.
2734 ret = ath11k_setup_peer_smps(ar, arvif, sta->addr,
2737 ath11k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n",
2738 arvif->vdev_id, ret);
2743 arvif->num_legacy_stations++;
2744 ret = ath11k_recalc_rtscts_prot(arvif);
2749 if (sta->wme && sta->uapsd_queues) {
2750 ret = ath11k_peer_assoc_qos_ap(ar, arvif, sta);
2752 ath11k_warn(ar->ab, "failed to set qos params for STA %pM for vdev %i: %d\n",
2753 sta->addr, arvif->vdev_id, ret);
2761 static int ath11k_station_disassoc(struct ath11k *ar,
2762 struct ieee80211_vif *vif,
2763 struct ieee80211_sta *sta)
2765 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2768 lockdep_assert_held(&ar->conf_mutex);
2771 arvif->num_legacy_stations--;
2772 ret = ath11k_recalc_rtscts_prot(arvif);
2777 ret = ath11k_clear_peer_keys(arvif, sta->addr);
2779 ath11k_warn(ar->ab, "failed to clear all peer keys for vdev %i: %d\n",
2780 arvif->vdev_id, ret);
2786 static void ath11k_sta_rc_update_wk(struct work_struct *wk)
2789 struct ath11k_vif *arvif;
2790 struct ath11k_sta *arsta;
2791 struct ieee80211_sta *sta;
2792 struct cfg80211_chan_def def;
2793 enum nl80211_band band;
2794 const u8 *ht_mcs_mask;
2795 const u16 *vht_mcs_mask;
2796 u32 changed, bw, nss, smps;
2797 int err, num_vht_rates;
2798 const struct cfg80211_bitrate_mask *mask;
2799 struct peer_assoc_params peer_arg;
2801 arsta = container_of(wk, struct ath11k_sta, update_wk);
2802 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
2803 arvif = arsta->arvif;
2806 if (WARN_ON(ath11k_mac_vif_chan(arvif->vif, &def)))
2809 band = def.chan->band;
2810 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2811 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2813 spin_lock_bh(&ar->data_lock);
2815 changed = arsta->changed;
2822 spin_unlock_bh(&ar->data_lock);
2824 mutex_lock(&ar->conf_mutex);
2826 nss = max_t(u32, 1, nss);
2827 nss = min(nss, max(ath11k_mac_max_ht_nss(ht_mcs_mask),
2828 ath11k_mac_max_vht_nss(vht_mcs_mask)));
2830 if (changed & IEEE80211_RC_BW_CHANGED) {
2831 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
2832 WMI_PEER_CHWIDTH, bw);
2834 ath11k_warn(ar->ab, "failed to update STA %pM peer bw %d: %d\n",
2835 sta->addr, bw, err);
2838 if (changed & IEEE80211_RC_NSS_CHANGED) {
2839 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM nss %d\n",
2842 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
2845 ath11k_warn(ar->ab, "failed to update STA %pM nss %d: %d\n",
2846 sta->addr, nss, err);
2849 if (changed & IEEE80211_RC_SMPS_CHANGED) {
2850 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM smps %d\n",
2853 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
2854 WMI_PEER_MIMO_PS_STATE, smps);
2856 ath11k_warn(ar->ab, "failed to update STA %pM smps %d: %d\n",
2857 sta->addr, smps, err);
2860 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
2861 mask = &arvif->bitrate_mask;
2862 num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band,
2865 /* Peer_assoc_prepare will reject vht rates in
2866 * bitrate_mask if its not available in range format and
2867 * sets vht tx_rateset as unsupported. So multiple VHT MCS
2868 * setting(eg. MCS 4,5,6) per peer is not supported here.
2869 * But, Single rate in VHT mask can be set as per-peer
2870 * fixed rate. But even if any HT rates are configured in
2871 * the bitrate mask, device will not switch to those rates
2872 * when per-peer Fixed rate is set.
2873 * TODO: Check RATEMASK_CMDID to support auto rates selection
2874 * across HT/VHT and for multiple VHT MCS support.
2876 if (sta->vht_cap.vht_supported && num_vht_rates == 1) {
2877 ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask,
2880 /* If the peer is non-VHT or no fixed VHT rate
2881 * is provided in the new bitrate mask we set the
2882 * other rates using peer_assoc command.
2884 ath11k_peer_assoc_prepare(ar, arvif->vif, sta,
2887 err = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
2889 ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2890 sta->addr, arvif->vdev_id, err);
2892 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ))
2893 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
2894 sta->addr, arvif->vdev_id);
2898 mutex_unlock(&ar->conf_mutex);
2901 static int ath11k_mac_inc_num_stations(struct ath11k_vif *arvif,
2902 struct ieee80211_sta *sta)
2904 struct ath11k *ar = arvif->ar;
2906 lockdep_assert_held(&ar->conf_mutex);
2908 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
2911 if (ar->num_stations >= ar->max_num_stations)
2919 static void ath11k_mac_dec_num_stations(struct ath11k_vif *arvif,
2920 struct ieee80211_sta *sta)
2922 struct ath11k *ar = arvif->ar;
2924 lockdep_assert_held(&ar->conf_mutex);
2926 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
2932 static int ath11k_mac_station_add(struct ath11k *ar,
2933 struct ieee80211_vif *vif,
2934 struct ieee80211_sta *sta)
2936 struct ath11k_base *ab = ar->ab;
2937 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
2938 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
2939 struct peer_create_params peer_param;
2942 lockdep_assert_held(&ar->conf_mutex);
2944 ret = ath11k_mac_inc_num_stations(arvif, sta);
2946 ath11k_warn(ab, "refusing to associate station: too many connected already (%d)\n",
2947 ar->max_num_stations);
2951 arsta->rx_stats = kzalloc(sizeof(*arsta->rx_stats), GFP_KERNEL);
2952 if (!arsta->rx_stats) {
2954 goto dec_num_station;
2957 peer_param.vdev_id = arvif->vdev_id;
2958 peer_param.peer_addr = sta->addr;
2959 peer_param.peer_type = WMI_PEER_TYPE_DEFAULT;
2961 ret = ath11k_peer_create(ar, arvif, sta, &peer_param);
2963 ath11k_warn(ab, "Failed to add peer: %pM for VDEV: %d\n",
2964 sta->addr, arvif->vdev_id);
2968 ath11k_dbg(ab, ATH11K_DBG_MAC, "Added peer: %pM for VDEV: %d\n",
2969 sta->addr, arvif->vdev_id);
2971 if (ath11k_debugfs_is_extd_tx_stats_enabled(ar)) {
2972 arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats), GFP_KERNEL);
2973 if (!arsta->tx_stats) {
2979 if (ieee80211_vif_is_mesh(vif)) {
2980 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
2982 WMI_PEER_USE_4ADDR, 1);
2984 ath11k_warn(ab, "failed to STA %pM 4addr capability: %d\n",
2990 ret = ath11k_dp_peer_setup(ar, arvif->vdev_id, sta->addr);
2992 ath11k_warn(ab, "failed to setup dp for peer %pM on vdev %i (%d)\n",
2993 sta->addr, arvif->vdev_id, ret);
2997 if (ab->hw_params.vdev_start_delay &&
2998 arvif->vdev_type != WMI_VDEV_TYPE_AP) {
2999 ret = ath11k_start_vdev_delay(ar->hw, vif);
3001 ath11k_warn(ab, "failed to delay vdev start: %d\n", ret);
3009 kfree(arsta->tx_stats);
3010 arsta->tx_stats = NULL;
3012 ath11k_peer_delete(ar, arvif->vdev_id, sta->addr);
3014 kfree(arsta->rx_stats);
3015 arsta->rx_stats = NULL;
3017 ath11k_mac_dec_num_stations(arvif, sta);
3022 static int ath11k_mac_op_sta_state(struct ieee80211_hw *hw,
3023 struct ieee80211_vif *vif,
3024 struct ieee80211_sta *sta,
3025 enum ieee80211_sta_state old_state,
3026 enum ieee80211_sta_state new_state)
3028 struct ath11k *ar = hw->priv;
3029 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
3030 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
3031 struct ath11k_peer *peer;
3034 /* cancel must be done outside the mutex to avoid deadlock */
3035 if ((old_state == IEEE80211_STA_NONE &&
3036 new_state == IEEE80211_STA_NOTEXIST))
3037 cancel_work_sync(&arsta->update_wk);
3039 mutex_lock(&ar->conf_mutex);
3041 if (old_state == IEEE80211_STA_NOTEXIST &&
3042 new_state == IEEE80211_STA_NONE) {
3043 memset(arsta, 0, sizeof(*arsta));
3044 arsta->arvif = arvif;
3045 INIT_WORK(&arsta->update_wk, ath11k_sta_rc_update_wk);
3047 ret = ath11k_mac_station_add(ar, vif, sta);
3049 ath11k_warn(ar->ab, "Failed to add station: %pM for VDEV: %d\n",
3050 sta->addr, arvif->vdev_id);
3051 } else if ((old_state == IEEE80211_STA_NONE &&
3052 new_state == IEEE80211_STA_NOTEXIST)) {
3053 ath11k_dp_peer_cleanup(ar, arvif->vdev_id, sta->addr);
3055 ret = ath11k_peer_delete(ar, arvif->vdev_id, sta->addr);
3057 ath11k_warn(ar->ab, "Failed to delete peer: %pM for VDEV: %d\n",
3058 sta->addr, arvif->vdev_id);
3060 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "Removed peer: %pM for VDEV: %d\n",
3061 sta->addr, arvif->vdev_id);
3063 ath11k_mac_dec_num_stations(arvif, sta);
3064 spin_lock_bh(&ar->ab->base_lock);
3065 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
3066 if (peer && peer->sta == sta) {
3067 ath11k_warn(ar->ab, "Found peer entry %pM n vdev %i after it was supposedly removed\n",
3068 vif->addr, arvif->vdev_id);
3070 list_del(&peer->list);
3074 spin_unlock_bh(&ar->ab->base_lock);
3076 kfree(arsta->tx_stats);
3077 arsta->tx_stats = NULL;
3079 kfree(arsta->rx_stats);
3080 arsta->rx_stats = NULL;
3081 } else if (old_state == IEEE80211_STA_AUTH &&
3082 new_state == IEEE80211_STA_ASSOC &&
3083 (vif->type == NL80211_IFTYPE_AP ||
3084 vif->type == NL80211_IFTYPE_MESH_POINT ||
3085 vif->type == NL80211_IFTYPE_ADHOC)) {
3086 ret = ath11k_station_assoc(ar, vif, sta, false);
3088 ath11k_warn(ar->ab, "Failed to associate station: %pM\n",
3090 } else if (old_state == IEEE80211_STA_ASSOC &&
3091 new_state == IEEE80211_STA_AUTH &&
3092 (vif->type == NL80211_IFTYPE_AP ||
3093 vif->type == NL80211_IFTYPE_MESH_POINT ||
3094 vif->type == NL80211_IFTYPE_ADHOC)) {
3095 ret = ath11k_station_disassoc(ar, vif, sta);
3097 ath11k_warn(ar->ab, "Failed to disassociate station: %pM\n",
3101 mutex_unlock(&ar->conf_mutex);
3105 static int ath11k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw,
3106 struct ieee80211_vif *vif,
3107 struct ieee80211_sta *sta)
3109 struct ath11k *ar = hw->priv;
3110 struct ath11k_vif *arvif = (void *)vif->drv_priv;
3114 if (sta->txpwr.type == NL80211_TX_POWER_AUTOMATIC) {
3117 txpwr = sta->txpwr.power;
3122 if (txpwr > ATH11K_TX_POWER_MAX_VAL || txpwr < ATH11K_TX_POWER_MIN_VAL)
3125 mutex_lock(&ar->conf_mutex);
3127 ret = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
3128 WMI_PEER_USE_FIXED_PWR, txpwr);
3130 ath11k_warn(ar->ab, "failed to set tx power for station ret: %d\n",
3136 mutex_unlock(&ar->conf_mutex);
3140 static void ath11k_mac_op_sta_rc_update(struct ieee80211_hw *hw,
3141 struct ieee80211_vif *vif,
3142 struct ieee80211_sta *sta,
3145 struct ath11k *ar = hw->priv;
3146 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
3147 struct ath11k_vif *arvif = (void *)vif->drv_priv;
3148 struct ath11k_peer *peer;
3151 spin_lock_bh(&ar->ab->base_lock);
3153 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
3155 spin_unlock_bh(&ar->ab->base_lock);
3156 ath11k_warn(ar->ab, "mac sta rc update failed to find peer %pM on vdev %i\n",
3157 sta->addr, arvif->vdev_id);
3161 spin_unlock_bh(&ar->ab->base_lock);
3163 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3164 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
3165 sta->addr, changed, sta->bandwidth, sta->rx_nss,
3168 spin_lock_bh(&ar->data_lock);
3170 if (changed & IEEE80211_RC_BW_CHANGED) {
3171 bw = WMI_PEER_CHWIDTH_20MHZ;
3173 switch (sta->bandwidth) {
3174 case IEEE80211_STA_RX_BW_20:
3175 bw = WMI_PEER_CHWIDTH_20MHZ;
3177 case IEEE80211_STA_RX_BW_40:
3178 bw = WMI_PEER_CHWIDTH_40MHZ;
3180 case IEEE80211_STA_RX_BW_80:
3181 bw = WMI_PEER_CHWIDTH_80MHZ;
3183 case IEEE80211_STA_RX_BW_160:
3184 bw = WMI_PEER_CHWIDTH_160MHZ;
3187 ath11k_warn(ar->ab, "Invalid bandwidth %d in rc update for %pM\n",
3188 sta->bandwidth, sta->addr);
3189 bw = WMI_PEER_CHWIDTH_20MHZ;
3196 if (changed & IEEE80211_RC_NSS_CHANGED)
3197 arsta->nss = sta->rx_nss;
3199 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3200 smps = WMI_PEER_SMPS_PS_NONE;
3202 switch (sta->smps_mode) {
3203 case IEEE80211_SMPS_AUTOMATIC:
3204 case IEEE80211_SMPS_OFF:
3205 smps = WMI_PEER_SMPS_PS_NONE;
3207 case IEEE80211_SMPS_STATIC:
3208 smps = WMI_PEER_SMPS_STATIC;
3210 case IEEE80211_SMPS_DYNAMIC:
3211 smps = WMI_PEER_SMPS_DYNAMIC;
3214 ath11k_warn(ar->ab, "Invalid smps %d in sta rc update for %pM\n",
3215 sta->smps_mode, sta->addr);
3216 smps = WMI_PEER_SMPS_PS_NONE;
3223 arsta->changed |= changed;
3225 spin_unlock_bh(&ar->data_lock);
3227 ieee80211_queue_work(hw, &arsta->update_wk);
3230 static int ath11k_conf_tx_uapsd(struct ath11k *ar, struct ieee80211_vif *vif,
3231 u16 ac, bool enable)
3233 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
3237 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3241 case IEEE80211_AC_VO:
3242 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3243 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3245 case IEEE80211_AC_VI:
3246 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3247 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3249 case IEEE80211_AC_BE:
3250 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3251 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3253 case IEEE80211_AC_BK:
3254 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3255 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3260 arvif->u.sta.uapsd |= value;
3262 arvif->u.sta.uapsd &= ~value;
3264 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3265 WMI_STA_PS_PARAM_UAPSD,
3266 arvif->u.sta.uapsd);
3268 ath11k_warn(ar->ab, "could not set uapsd params %d\n", ret);
3272 if (arvif->u.sta.uapsd)
3273 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3275 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3277 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3278 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3281 ath11k_warn(ar->ab, "could not set rx wake param %d\n", ret);
3287 static int ath11k_mac_op_conf_tx(struct ieee80211_hw *hw,
3288 struct ieee80211_vif *vif, u16 ac,
3289 const struct ieee80211_tx_queue_params *params)
3291 struct ath11k *ar = hw->priv;
3292 struct ath11k_vif *arvif = (void *)vif->drv_priv;
3293 struct wmi_wmm_params_arg *p = NULL;
3296 mutex_lock(&ar->conf_mutex);
3299 case IEEE80211_AC_VO:
3300 p = &arvif->wmm_params.ac_vo;
3302 case IEEE80211_AC_VI:
3303 p = &arvif->wmm_params.ac_vi;
3305 case IEEE80211_AC_BE:
3306 p = &arvif->wmm_params.ac_be;
3308 case IEEE80211_AC_BK:
3309 p = &arvif->wmm_params.ac_bk;
3318 p->cwmin = params->cw_min;
3319 p->cwmax = params->cw_max;
3320 p->aifs = params->aifs;
3321 p->txop = params->txop;
3323 ret = ath11k_wmi_send_wmm_update_cmd_tlv(ar, arvif->vdev_id,
3324 &arvif->wmm_params);
3326 ath11k_warn(ar->ab, "failed to set wmm params: %d\n", ret);
3330 ret = ath11k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3333 ath11k_warn(ar->ab, "failed to set sta uapsd: %d\n", ret);
3336 mutex_unlock(&ar->conf_mutex);
3340 static struct ieee80211_sta_ht_cap
3341 ath11k_create_ht_cap(struct ath11k *ar, u32 ar_ht_cap, u32 rate_cap_rx_chainmask)
3344 struct ieee80211_sta_ht_cap ht_cap = {0};
3345 u32 ar_vht_cap = ar->pdev->cap.vht_cap;
3347 if (!(ar_ht_cap & WMI_HT_CAP_ENABLED))
3350 ht_cap.ht_supported = 1;
3351 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3352 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
3353 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3354 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3355 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3357 if (ar_ht_cap & WMI_HT_CAP_HT20_SGI)
3358 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3360 if (ar_ht_cap & WMI_HT_CAP_HT40_SGI)
3361 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3363 if (ar_ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) {
3366 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3367 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3372 if (ar_ht_cap & WMI_HT_CAP_TX_STBC)
3373 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3375 if (ar_ht_cap & WMI_HT_CAP_RX_STBC) {
3379 stbc &= WMI_HT_CAP_RX_STBC;
3380 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3381 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3382 stbc &= IEEE80211_HT_CAP_RX_STBC;
3387 if (ar_ht_cap & WMI_HT_CAP_RX_LDPC)
3388 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3390 if (ar_ht_cap & WMI_HT_CAP_L_SIG_TXOP_PROT)
3391 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3393 if (ar_vht_cap & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3394 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3396 for (i = 0; i < ar->num_rx_chains; i++) {
3397 if (rate_cap_rx_chainmask & BIT(i))
3398 ht_cap.mcs.rx_mask[i] = 0xFF;
3401 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3406 static int ath11k_mac_set_txbf_conf(struct ath11k_vif *arvif)
3409 struct ath11k *ar = arvif->ar;
3412 u32 vht_cap = ar->pdev->cap.vht_cap;
3413 u32 vdev_param = WMI_VDEV_PARAM_TXBF;
3415 if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)) {
3416 nsts = vht_cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
3417 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
3418 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
3421 if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) {
3422 sound_dim = vht_cap &
3423 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
3424 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
3425 if (sound_dim > (ar->num_tx_chains - 1))
3426 sound_dim = ar->num_tx_chains - 1;
3427 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
3433 if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) {
3434 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
3436 if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) &&
3437 arvif->vdev_type == WMI_VDEV_TYPE_AP)
3438 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
3441 /* TODO: SUBFEE not validated in HK, disable here until validated? */
3443 if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) {
3444 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
3446 if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) &&
3447 arvif->vdev_type == WMI_VDEV_TYPE_STA)
3448 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
3451 return ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3455 static void ath11k_set_vht_txbf_cap(struct ath11k *ar, u32 *vht_cap)
3457 bool subfer, subfee;
3460 subfer = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE));
3461 subfee = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE));
3463 if (ar->num_tx_chains < 2) {
3464 *vht_cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
3468 /* If SU Beaformer is not set, then disable MU Beamformer Capability */
3470 *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE);
3472 /* If SU Beaformee is not set, then disable MU Beamformee Capability */
3474 *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
3476 sound_dim = (*vht_cap & IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK);
3477 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
3478 *vht_cap &= ~IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
3480 /* TODO: Need to check invalid STS and Sound_dim values set by FW? */
3482 /* Enable Sounding Dimension Field only if SU BF is enabled */
3484 if (sound_dim > (ar->num_tx_chains - 1))
3485 sound_dim = ar->num_tx_chains - 1;
3487 sound_dim <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
3488 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
3489 *vht_cap |= sound_dim;
3492 /* Use the STS advertised by FW unless SU Beamformee is not supported*/
3494 *vht_cap &= ~(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK);
3497 static struct ieee80211_sta_vht_cap
3498 ath11k_create_vht_cap(struct ath11k *ar, u32 rate_cap_tx_chainmask,
3499 u32 rate_cap_rx_chainmask)
3501 struct ieee80211_sta_vht_cap vht_cap = {0};
3502 u16 txmcs_map, rxmcs_map;
3505 vht_cap.vht_supported = 1;
3506 vht_cap.cap = ar->pdev->cap.vht_cap;
3508 ath11k_set_vht_txbf_cap(ar, &vht_cap.cap);
3510 /* TODO: Enable back VHT160 mode once association issues are fixed */
3511 /* Disabling VHT160 and VHT80+80 modes */
3512 vht_cap.cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
3513 vht_cap.cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
3517 for (i = 0; i < 8; i++) {
3518 if (i < ar->num_tx_chains && rate_cap_tx_chainmask & BIT(i))
3519 txmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
3521 txmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
3523 if (i < ar->num_rx_chains && rate_cap_rx_chainmask & BIT(i))
3524 rxmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
3526 rxmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
3529 if (rate_cap_tx_chainmask <= 1)
3530 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
3532 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_map);
3533 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_map);
3538 static void ath11k_mac_setup_ht_vht_cap(struct ath11k *ar,
3539 struct ath11k_pdev_cap *cap,
3542 struct ieee80211_supported_band *band;
3543 u32 rate_cap_tx_chainmask;
3544 u32 rate_cap_rx_chainmask;
3547 rate_cap_tx_chainmask = ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift;
3548 rate_cap_rx_chainmask = ar->cfg_rx_chainmask >> cap->rx_chain_mask_shift;
3550 if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) {
3551 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
3552 ht_cap = cap->band[NL80211_BAND_2GHZ].ht_cap_info;
3554 *ht_cap_info = ht_cap;
3555 band->ht_cap = ath11k_create_ht_cap(ar, ht_cap,
3556 rate_cap_rx_chainmask);
3559 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP && !ar->supports_6ghz) {
3560 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
3561 ht_cap = cap->band[NL80211_BAND_5GHZ].ht_cap_info;
3563 *ht_cap_info = ht_cap;
3564 band->ht_cap = ath11k_create_ht_cap(ar, ht_cap,
3565 rate_cap_rx_chainmask);
3566 band->vht_cap = ath11k_create_vht_cap(ar, rate_cap_tx_chainmask,
3567 rate_cap_rx_chainmask);
3571 static int ath11k_check_chain_mask(struct ath11k *ar, u32 ant, bool is_tx_ant)
3573 /* TODO: Check the request chainmask against the supported
3574 * chainmask table which is advertised in extented_service_ready event
3580 static void ath11k_gen_ppe_thresh(struct ath11k_ppe_threshold *fw_ppet,
3586 he_ppet[0] = fw_ppet->numss_m1 & IEEE80211_PPE_THRES_NSS_MASK;
3587 he_ppet[0] |= (fw_ppet->ru_bit_mask <<
3588 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS) &
3589 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK;
3590 for (nss = 0; nss <= fw_ppet->numss_m1; nss++) {
3591 for (ru = 0; ru < 4; ru++) {
3595 if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0)
3597 val = (fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> (ru * 6)) &
3599 val = ((val >> 3) & 0x7) | ((val & 0x7) << 3);
3600 for (i = 5; i >= 0; i--) {
3602 ((val >> i) & 0x1) << ((bit % 8));
3610 ath11k_mac_filter_he_cap_mesh(struct ieee80211_he_cap_elem *he_cap_elem)
3614 m = IEEE80211_HE_MAC_CAP0_TWT_RES |
3615 IEEE80211_HE_MAC_CAP0_TWT_REQ;
3616 he_cap_elem->mac_cap_info[0] &= ~m;
3618 m = IEEE80211_HE_MAC_CAP2_TRS |
3619 IEEE80211_HE_MAC_CAP2_BCAST_TWT |
3620 IEEE80211_HE_MAC_CAP2_MU_CASCADING;
3621 he_cap_elem->mac_cap_info[2] &= ~m;
3623 m = IEEE80211_HE_MAC_CAP3_FLEX_TWT_SCHED |
3624 IEEE80211_HE_MAC_CAP2_BCAST_TWT |
3625 IEEE80211_HE_MAC_CAP2_MU_CASCADING;
3626 he_cap_elem->mac_cap_info[3] &= ~m;
3628 m = IEEE80211_HE_MAC_CAP4_BSRP_BQRP_A_MPDU_AGG |
3629 IEEE80211_HE_MAC_CAP4_BQR;
3630 he_cap_elem->mac_cap_info[4] &= ~m;
3632 m = IEEE80211_HE_MAC_CAP5_SUBCHAN_SELECVITE_TRANSMISSION |
3633 IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU |
3634 IEEE80211_HE_MAC_CAP5_PUNCTURED_SOUNDING |
3635 IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX;
3636 he_cap_elem->mac_cap_info[5] &= ~m;
3638 m = IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
3639 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO;
3640 he_cap_elem->phy_cap_info[2] &= ~m;
3642 m = IEEE80211_HE_PHY_CAP3_RX_HE_MU_PPDU_FROM_NON_AP_STA |
3643 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK |
3644 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK;
3645 he_cap_elem->phy_cap_info[3] &= ~m;
3647 m = IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
3648 he_cap_elem->phy_cap_info[4] &= ~m;
3650 m = IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK;
3651 he_cap_elem->phy_cap_info[5] &= ~m;
3653 m = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU |
3654 IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMER_FB |
3655 IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB |
3656 IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO;
3657 he_cap_elem->phy_cap_info[6] &= ~m;
3659 m = IEEE80211_HE_PHY_CAP7_SRP_BASED_SR |
3660 IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_AR |
3661 IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ |
3662 IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ;
3663 he_cap_elem->phy_cap_info[7] &= ~m;
3665 m = IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI |
3666 IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
3667 IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
3668 IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU;
3669 he_cap_elem->phy_cap_info[8] &= ~m;
3671 m = IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM |
3672 IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK |
3673 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU |
3674 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
3675 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
3676 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB;
3677 he_cap_elem->phy_cap_info[9] &= ~m;
3680 static __le16 ath11k_mac_setup_he_6ghz_cap(struct ath11k_pdev_cap *pcap,
3681 struct ath11k_band_cap *bcap)
3685 bcap->he_6ghz_capa = IEEE80211_HT_MPDU_DENSITY_NONE;
3686 if (bcap->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3687 bcap->he_6ghz_capa |=
3688 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_SM_PS,
3689 WLAN_HT_CAP_SM_PS_DYNAMIC);
3691 bcap->he_6ghz_capa |=
3692 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_SM_PS,
3693 WLAN_HT_CAP_SM_PS_DISABLED);
3694 val = FIELD_GET(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK,
3696 bcap->he_6ghz_capa |=
3697 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP, val);
3698 val = FIELD_GET(IEEE80211_VHT_CAP_MAX_MPDU_MASK, pcap->vht_cap);
3699 bcap->he_6ghz_capa |=
3700 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN, val);
3701 if (pcap->vht_cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN)
3702 bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS;
3703 if (pcap->vht_cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN)
3704 bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS;
3706 return cpu_to_le16(bcap->he_6ghz_capa);
3709 static int ath11k_mac_copy_he_cap(struct ath11k *ar,
3710 struct ath11k_pdev_cap *cap,
3711 struct ieee80211_sband_iftype_data *data,
3716 for (i = 0; i < NUM_NL80211_IFTYPES; i++) {
3717 struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap;
3718 struct ath11k_band_cap *band_cap = &cap->band[band];
3719 struct ieee80211_he_cap_elem *he_cap_elem =
3720 &he_cap->he_cap_elem;
3723 case NL80211_IFTYPE_STATION:
3724 case NL80211_IFTYPE_AP:
3725 case NL80211_IFTYPE_MESH_POINT:
3732 data[idx].types_mask = BIT(i);
3733 he_cap->has_he = true;
3734 memcpy(he_cap_elem->mac_cap_info, band_cap->he_cap_info,
3735 sizeof(he_cap_elem->mac_cap_info));
3736 memcpy(he_cap_elem->phy_cap_info, band_cap->he_cap_phy_info,
3737 sizeof(he_cap_elem->phy_cap_info));
3739 he_cap_elem->mac_cap_info[1] &=
3740 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_MASK;
3741 he_cap_elem->phy_cap_info[4] &=
3742 ~IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_MASK;
3743 he_cap_elem->phy_cap_info[4] &=
3744 ~IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_MASK;
3745 he_cap_elem->phy_cap_info[4] |= (ar->num_tx_chains - 1) << 2;
3747 he_cap_elem->phy_cap_info[5] &=
3748 ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK;
3749 he_cap_elem->phy_cap_info[5] &=
3750 ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK;
3751 he_cap_elem->phy_cap_info[5] |= ar->num_tx_chains - 1;
3754 case NL80211_IFTYPE_AP:
3755 he_cap_elem->phy_cap_info[3] &=
3756 ~IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK;
3757 he_cap_elem->phy_cap_info[9] |=
3758 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU;
3760 case NL80211_IFTYPE_STATION:
3761 he_cap_elem->mac_cap_info[0] &=
3762 ~IEEE80211_HE_MAC_CAP0_TWT_RES;
3763 he_cap_elem->mac_cap_info[0] |=
3764 IEEE80211_HE_MAC_CAP0_TWT_REQ;
3765 he_cap_elem->phy_cap_info[9] |=
3766 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU;
3768 case NL80211_IFTYPE_MESH_POINT:
3769 ath11k_mac_filter_he_cap_mesh(he_cap_elem);
3773 he_cap->he_mcs_nss_supp.rx_mcs_80 =
3774 cpu_to_le16(band_cap->he_mcs & 0xffff);
3775 he_cap->he_mcs_nss_supp.tx_mcs_80 =
3776 cpu_to_le16(band_cap->he_mcs & 0xffff);
3777 he_cap->he_mcs_nss_supp.rx_mcs_160 =
3778 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
3779 he_cap->he_mcs_nss_supp.tx_mcs_160 =
3780 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
3781 he_cap->he_mcs_nss_supp.rx_mcs_80p80 =
3782 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
3783 he_cap->he_mcs_nss_supp.tx_mcs_80p80 =
3784 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
3786 memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
3787 if (he_cap_elem->phy_cap_info[6] &
3788 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
3789 ath11k_gen_ppe_thresh(&band_cap->he_ppet,
3792 if (band == NL80211_BAND_6GHZ) {
3793 data[idx].he_6ghz_capa.capa =
3794 ath11k_mac_setup_he_6ghz_cap(cap, band_cap);
3802 static void ath11k_mac_setup_he_cap(struct ath11k *ar,
3803 struct ath11k_pdev_cap *cap)
3805 struct ieee80211_supported_band *band;
3808 if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) {
3809 count = ath11k_mac_copy_he_cap(ar, cap,
3810 ar->mac.iftype[NL80211_BAND_2GHZ],
3812 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
3813 band->iftype_data = ar->mac.iftype[NL80211_BAND_2GHZ];
3814 band->n_iftype_data = count;
3817 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP) {
3818 count = ath11k_mac_copy_he_cap(ar, cap,
3819 ar->mac.iftype[NL80211_BAND_5GHZ],
3821 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
3822 band->iftype_data = ar->mac.iftype[NL80211_BAND_5GHZ];
3823 band->n_iftype_data = count;
3826 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP &&
3827 ar->supports_6ghz) {
3828 count = ath11k_mac_copy_he_cap(ar, cap,
3829 ar->mac.iftype[NL80211_BAND_6GHZ],
3831 band = &ar->mac.sbands[NL80211_BAND_6GHZ];
3832 band->iftype_data = ar->mac.iftype[NL80211_BAND_6GHZ];
3833 band->n_iftype_data = count;
3837 static int __ath11k_set_antenna(struct ath11k *ar, u32 tx_ant, u32 rx_ant)
3841 lockdep_assert_held(&ar->conf_mutex);
3843 if (ath11k_check_chain_mask(ar, tx_ant, true))
3846 if (ath11k_check_chain_mask(ar, rx_ant, false))
3849 ar->cfg_tx_chainmask = tx_ant;
3850 ar->cfg_rx_chainmask = rx_ant;
3852 if (ar->state != ATH11K_STATE_ON &&
3853 ar->state != ATH11K_STATE_RESTARTED)
3856 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_TX_CHAIN_MASK,
3857 tx_ant, ar->pdev->pdev_id);
3859 ath11k_warn(ar->ab, "failed to set tx-chainmask: %d, req 0x%x\n",
3864 ar->num_tx_chains = get_num_chains(tx_ant);
3866 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RX_CHAIN_MASK,
3867 rx_ant, ar->pdev->pdev_id);
3869 ath11k_warn(ar->ab, "failed to set rx-chainmask: %d, req 0x%x\n",
3874 ar->num_rx_chains = get_num_chains(rx_ant);
3876 /* Reload HT/VHT/HE capability */
3877 ath11k_mac_setup_ht_vht_cap(ar, &ar->pdev->cap, NULL);
3878 ath11k_mac_setup_he_cap(ar, &ar->pdev->cap);
3883 int ath11k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx)
3885 struct sk_buff *msdu = skb;
3886 struct ieee80211_tx_info *info;
3887 struct ath11k *ar = ctx;
3888 struct ath11k_base *ab = ar->ab;
3890 spin_lock_bh(&ar->txmgmt_idr_lock);
3891 idr_remove(&ar->txmgmt_idr, buf_id);
3892 spin_unlock_bh(&ar->txmgmt_idr_lock);
3893 dma_unmap_single(ab->dev, ATH11K_SKB_CB(msdu)->paddr, msdu->len,
3896 info = IEEE80211_SKB_CB(msdu);
3897 memset(&info->status, 0, sizeof(info->status));
3899 ieee80211_free_txskb(ar->hw, msdu);
3904 static int ath11k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx)
3906 struct ieee80211_vif *vif = ctx;
3907 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb);
3908 struct sk_buff *msdu = skb;
3909 struct ath11k *ar = skb_cb->ar;
3910 struct ath11k_base *ab = ar->ab;
3912 if (skb_cb->vif == vif) {
3913 spin_lock_bh(&ar->txmgmt_idr_lock);
3914 idr_remove(&ar->txmgmt_idr, buf_id);
3915 spin_unlock_bh(&ar->txmgmt_idr_lock);
3916 dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len,
3923 static int ath11k_mac_mgmt_tx_wmi(struct ath11k *ar, struct ath11k_vif *arvif,
3924 struct sk_buff *skb)
3926 struct ath11k_base *ab = ar->ab;
3927 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3928 struct ieee80211_tx_info *info;
3933 spin_lock_bh(&ar->txmgmt_idr_lock);
3934 buf_id = idr_alloc(&ar->txmgmt_idr, skb, 0,
3935 ATH11K_TX_MGMT_NUM_PENDING_MAX, GFP_ATOMIC);
3936 spin_unlock_bh(&ar->txmgmt_idr_lock);
3940 info = IEEE80211_SKB_CB(skb);
3941 if (!(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) {
3942 if ((ieee80211_is_action(hdr->frame_control) ||
3943 ieee80211_is_deauth(hdr->frame_control) ||
3944 ieee80211_is_disassoc(hdr->frame_control)) &&
3945 ieee80211_has_protected(hdr->frame_control)) {
3946 skb_put(skb, IEEE80211_CCMP_MIC_LEN);
3950 paddr = dma_map_single(ab->dev, skb->data, skb->len, DMA_TO_DEVICE);
3951 if (dma_mapping_error(ab->dev, paddr)) {
3952 ath11k_warn(ab, "failed to DMA map mgmt Tx buffer\n");
3957 ATH11K_SKB_CB(skb)->paddr = paddr;
3959 ret = ath11k_wmi_mgmt_send(ar, arvif->vdev_id, buf_id, skb);
3961 ath11k_warn(ar->ab, "failed to send mgmt frame: %d\n", ret);
3968 dma_unmap_single(ab->dev, ATH11K_SKB_CB(skb)->paddr,
3969 skb->len, DMA_TO_DEVICE);
3971 spin_lock_bh(&ar->txmgmt_idr_lock);
3972 idr_remove(&ar->txmgmt_idr, buf_id);
3973 spin_unlock_bh(&ar->txmgmt_idr_lock);
3978 static void ath11k_mgmt_over_wmi_tx_purge(struct ath11k *ar)
3980 struct sk_buff *skb;
3982 while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL)
3983 ieee80211_free_txskb(ar->hw, skb);
3986 static void ath11k_mgmt_over_wmi_tx_work(struct work_struct *work)
3988 struct ath11k *ar = container_of(work, struct ath11k, wmi_mgmt_tx_work);
3989 struct ieee80211_tx_info *info;
3990 struct ath11k_vif *arvif;
3991 struct sk_buff *skb;
3994 while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) {
3995 info = IEEE80211_SKB_CB(skb);
3996 if (!info->control.vif) {
3997 ath11k_warn(ar->ab, "no vif found for mgmt frame, flags 0x%x\n",
3998 info->control.flags);
3999 ieee80211_free_txskb(ar->hw, skb);
4003 arvif = ath11k_vif_to_arvif(info->control.vif);
4004 if (ar->allocated_vdev_map & (1LL << arvif->vdev_id) &&
4005 arvif->is_started) {
4006 ret = ath11k_mac_mgmt_tx_wmi(ar, arvif, skb);
4008 ath11k_warn(ar->ab, "failed to tx mgmt frame, vdev_id %d :%d\n",
4009 arvif->vdev_id, ret);
4010 ieee80211_free_txskb(ar->hw, skb);
4012 atomic_inc(&ar->num_pending_mgmt_tx);
4016 "dropping mgmt frame for vdev %d, flags 0x%x is_started %d\n",
4017 arvif->vdev_id, info->control.flags,
4019 ieee80211_free_txskb(ar->hw, skb);
4024 static int ath11k_mac_mgmt_tx(struct ath11k *ar, struct sk_buff *skb,
4027 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
4029 if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))
4032 /* Drop probe response packets when the pending management tx
4033 * count has reached a certain threshold, so as to prioritize
4034 * other mgmt packets like auth and assoc to be sent on time
4035 * for establishing successful connections.
4038 atomic_read(&ar->num_pending_mgmt_tx) > ATH11K_PRB_RSP_DROP_THRESHOLD) {
4040 "dropping probe response as pending queue is almost full\n");
4044 if (skb_queue_len(q) == ATH11K_TX_MGMT_NUM_PENDING_MAX) {
4045 ath11k_warn(ar->ab, "mgmt tx queue is full\n");
4049 skb_queue_tail(q, skb);
4050 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
4055 static void ath11k_mac_op_tx(struct ieee80211_hw *hw,
4056 struct ieee80211_tx_control *control,
4057 struct sk_buff *skb)
4059 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb);
4060 struct ath11k *ar = hw->priv;
4061 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4062 struct ieee80211_vif *vif = info->control.vif;
4063 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4064 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
4068 if (info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) {
4069 skb_cb->flags |= ATH11K_SKB_HW_80211_ENCAP;
4070 } else if (ieee80211_is_mgmt(hdr->frame_control)) {
4071 is_prb_rsp = ieee80211_is_probe_resp(hdr->frame_control);
4072 ret = ath11k_mac_mgmt_tx(ar, skb, is_prb_rsp);
4074 ath11k_warn(ar->ab, "failed to queue management frame %d\n",
4076 ieee80211_free_txskb(ar->hw, skb);
4081 ret = ath11k_dp_tx(ar, arvif, skb);
4083 ath11k_warn(ar->ab, "failed to transmit frame %d\n", ret);
4084 ieee80211_free_txskb(ar->hw, skb);
4088 void ath11k_mac_drain_tx(struct ath11k *ar)
4090 /* make sure rcu-protected mac80211 tx path itself is drained */
4093 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4094 ath11k_mgmt_over_wmi_tx_purge(ar);
4097 static int ath11k_mac_config_mon_status_default(struct ath11k *ar, bool enable)
4099 struct htt_rx_ring_tlv_filter tlv_filter = {0};
4100 struct ath11k_base *ab = ar->ab;
4105 tlv_filter = ath11k_mac_mon_status_filter_default;
4106 tlv_filter.rx_filter = ath11k_debugfs_rx_filter(ar);
4109 for (i = 0; i < ab->hw_params.num_rxmda_per_pdev; i++) {
4110 ring_id = ar->dp.rx_mon_status_refill_ring[i].refill_buf_ring.ring_id;
4111 ret = ath11k_dp_tx_htt_rx_filter_setup(ar->ab, ring_id,
4113 HAL_RXDMA_MONITOR_STATUS,
4121 static int ath11k_mac_op_start(struct ieee80211_hw *hw)
4123 struct ath11k *ar = hw->priv;
4124 struct ath11k_base *ab = ar->ab;
4125 struct ath11k_pdev *pdev = ar->pdev;
4128 ath11k_mac_drain_tx(ar);
4129 mutex_lock(&ar->conf_mutex);
4131 switch (ar->state) {
4132 case ATH11K_STATE_OFF:
4133 ar->state = ATH11K_STATE_ON;
4135 case ATH11K_STATE_RESTARTING:
4136 ar->state = ATH11K_STATE_RESTARTED;
4138 case ATH11K_STATE_RESTARTED:
4139 case ATH11K_STATE_WEDGED:
4140 case ATH11K_STATE_ON:
4146 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS,
4150 ath11k_err(ar->ab, "failed to enable PMF QOS: (%d\n", ret);
4154 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 1,
4157 ath11k_err(ar->ab, "failed to enable dynamic bw: %d\n", ret);
4161 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
4164 ath11k_err(ab, "failed to set ac override for ARP: %d\n",
4169 ret = ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(ar, pdev->pdev_id);
4171 ath11k_err(ab, "failed to offload radar detection: %d\n",
4176 ret = ath11k_dp_tx_htt_h2t_ppdu_stats_req(ar,
4177 HTT_PPDU_STATS_TAG_DEFAULT);
4179 ath11k_err(ab, "failed to req ppdu stats: %d\n", ret);
4183 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_MESH_MCAST_ENABLE,
4187 ath11k_err(ar->ab, "failed to enable MESH MCAST ENABLE: (%d\n", ret);
4191 __ath11k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4193 /* TODO: Do we need to enable ANI? */
4195 ath11k_reg_update_chan_list(ar);
4197 ar->num_started_vdevs = 0;
4198 ar->num_created_vdevs = 0;
4200 ar->allocated_vdev_map = 0;
4202 /* Configure monitor status ring with default rx_filter to get rx status
4203 * such as rssi, rx_duration.
4205 ret = ath11k_mac_config_mon_status_default(ar, true);
4207 ath11k_err(ab, "failed to configure monitor status ring with default rx_filter: (%d)\n",
4212 /* Configure the hash seed for hash based reo dest ring selection */
4213 ath11k_wmi_pdev_lro_cfg(ar, ar->pdev->pdev_id);
4215 mutex_unlock(&ar->conf_mutex);
4217 rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx],
4218 &ab->pdevs[ar->pdev_idx]);
4223 ar->state = ATH11K_STATE_OFF;
4224 mutex_unlock(&ar->conf_mutex);
4229 static void ath11k_mac_op_stop(struct ieee80211_hw *hw)
4231 struct ath11k *ar = hw->priv;
4232 struct htt_ppdu_stats_info *ppdu_stats, *tmp;
4235 ath11k_mac_drain_tx(ar);
4237 mutex_lock(&ar->conf_mutex);
4238 ret = ath11k_mac_config_mon_status_default(ar, false);
4240 ath11k_err(ar->ab, "failed to clear rx_filter for monitor status ring: (%d)\n",
4243 clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
4244 ar->state = ATH11K_STATE_OFF;
4245 mutex_unlock(&ar->conf_mutex);
4247 cancel_delayed_work_sync(&ar->scan.timeout);
4248 cancel_work_sync(&ar->regd_update_work);
4250 spin_lock_bh(&ar->data_lock);
4251 list_for_each_entry_safe(ppdu_stats, tmp, &ar->ppdu_stats_info, list) {
4252 list_del(&ppdu_stats->list);
4255 spin_unlock_bh(&ar->data_lock);
4257 rcu_assign_pointer(ar->ab->pdevs_active[ar->pdev_idx], NULL);
4261 atomic_set(&ar->num_pending_mgmt_tx, 0);
4265 ath11k_mac_setup_vdev_create_params(struct ath11k_vif *arvif,
4266 struct vdev_create_params *params)
4268 struct ath11k *ar = arvif->ar;
4269 struct ath11k_pdev *pdev = ar->pdev;
4271 params->if_id = arvif->vdev_id;
4272 params->type = arvif->vdev_type;
4273 params->subtype = arvif->vdev_subtype;
4274 params->pdev_id = pdev->pdev_id;
4276 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) {
4277 params->chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains;
4278 params->chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains;
4280 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) {
4281 params->chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains;
4282 params->chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains;
4284 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP &&
4285 ar->supports_6ghz) {
4286 params->chains[NL80211_BAND_6GHZ].tx = ar->num_tx_chains;
4287 params->chains[NL80211_BAND_6GHZ].rx = ar->num_rx_chains;
4292 ath11k_mac_prepare_he_mode(struct ath11k_pdev *pdev, u32 viftype)
4294 struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
4295 struct ath11k_band_cap *cap_band = NULL;
4296 u32 *hecap_phy_ptr = NULL;
4299 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP)
4300 cap_band = &pdev_cap->band[NL80211_BAND_2GHZ];
4302 cap_band = &pdev_cap->band[NL80211_BAND_5GHZ];
4304 hecap_phy_ptr = &cap_band->he_cap_phy_info[0];
4306 hemode = FIELD_PREP(HE_MODE_SU_TX_BFEE, HE_SU_BFEE_ENABLE) |
4307 FIELD_PREP(HE_MODE_SU_TX_BFER, HECAP_PHY_SUBFMR_GET(hecap_phy_ptr)) |
4308 FIELD_PREP(HE_MODE_UL_MUMIMO, HECAP_PHY_ULMUMIMO_GET(hecap_phy_ptr));
4310 /* TODO WDS and other modes */
4311 if (viftype == NL80211_IFTYPE_AP) {
4312 hemode |= FIELD_PREP(HE_MODE_MU_TX_BFER,
4313 HECAP_PHY_MUBFMR_GET(hecap_phy_ptr)) |
4314 FIELD_PREP(HE_MODE_DL_OFDMA, HE_DL_MUOFDMA_ENABLE) |
4315 FIELD_PREP(HE_MODE_UL_OFDMA, HE_UL_MUOFDMA_ENABLE);
4317 hemode |= FIELD_PREP(HE_MODE_MU_TX_BFEE, HE_MU_BFEE_ENABLE);
4323 static int ath11k_set_he_mu_sounding_mode(struct ath11k *ar,
4324 struct ath11k_vif *arvif)
4326 u32 param_id, param_value;
4327 struct ath11k_base *ab = ar->ab;
4330 param_id = WMI_VDEV_PARAM_SET_HEMU_MODE;
4331 param_value = ath11k_mac_prepare_he_mode(ar->pdev, arvif->vif->type);
4332 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4333 param_id, param_value);
4335 ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d param_value %x\n",
4336 arvif->vdev_id, ret, param_value);
4339 param_id = WMI_VDEV_PARAM_SET_HE_SOUNDING_MODE;
4341 FIELD_PREP(HE_VHT_SOUNDING_MODE, HE_VHT_SOUNDING_MODE_ENABLE) |
4342 FIELD_PREP(HE_TRIG_NONTRIG_SOUNDING_MODE,
4343 HE_TRIG_NONTRIG_SOUNDING_MODE_ENABLE);
4344 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4345 param_id, param_value);
4347 ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d\n",
4348 arvif->vdev_id, ret);
4354 static void ath11k_mac_op_update_vif_offload(struct ieee80211_hw *hw,
4355 struct ieee80211_vif *vif)
4357 struct ath11k *ar = hw->priv;
4358 struct ath11k_base *ab = ar->ab;
4359 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4360 u32 param_id, param_value;
4363 param_id = WMI_VDEV_PARAM_TX_ENCAP_TYPE;
4364 if (ath11k_frame_mode != ATH11K_HW_TXRX_ETHERNET ||
4365 (vif->type != NL80211_IFTYPE_STATION &&
4366 vif->type != NL80211_IFTYPE_AP))
4367 vif->offload_flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
4369 if (vif->offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED)
4370 param_value = ATH11K_HW_TXRX_ETHERNET;
4371 else if (test_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags))
4372 param_value = ATH11K_HW_TXRX_RAW;
4374 param_value = ATH11K_HW_TXRX_NATIVE_WIFI;
4376 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4377 param_id, param_value);
4379 ath11k_warn(ab, "failed to set vdev %d tx encap mode: %d\n",
4380 arvif->vdev_id, ret);
4381 vif->offload_flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED;
4385 static int ath11k_mac_op_add_interface(struct ieee80211_hw *hw,
4386 struct ieee80211_vif *vif)
4388 struct ath11k *ar = hw->priv;
4389 struct ath11k_base *ab = ar->ab;
4390 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4391 struct vdev_create_params vdev_param = {0};
4392 struct peer_create_params peer_param;
4393 u32 param_id, param_value;
4399 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4401 mutex_lock(&ar->conf_mutex);
4403 if (vif->type == NL80211_IFTYPE_AP &&
4404 ar->num_peers > (ar->max_num_peers - 1)) {
4405 ath11k_warn(ab, "failed to create vdev due to insufficient peer entry resource in firmware\n");
4410 if (ar->num_created_vdevs > (TARGET_NUM_VDEVS - 1)) {
4411 ath11k_warn(ab, "failed to create vdev, reached max vdev limit %d\n",
4417 memset(arvif, 0, sizeof(*arvif));
4422 INIT_LIST_HEAD(&arvif->list);
4424 /* Should we initialize any worker to handle connection loss indication
4425 * from firmware in sta mode?
4428 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4429 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4430 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4431 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4432 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4433 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4436 bit = __ffs64(ab->free_vdev_map);
4438 arvif->vdev_id = bit;
4439 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
4441 switch (vif->type) {
4442 case NL80211_IFTYPE_UNSPECIFIED:
4443 case NL80211_IFTYPE_STATION:
4444 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4446 case NL80211_IFTYPE_MESH_POINT:
4447 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_MESH_11S;
4449 case NL80211_IFTYPE_AP:
4450 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4452 case NL80211_IFTYPE_MONITOR:
4453 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4460 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac add interface id %d type %d subtype %d map %llx\n",
4461 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4464 vif->cab_queue = arvif->vdev_id % (ATH11K_HW_MAX_QUEUES - 1);
4465 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4466 vif->hw_queue[i] = i % (ATH11K_HW_MAX_QUEUES - 1);
4468 ath11k_mac_setup_vdev_create_params(arvif, &vdev_param);
4470 ret = ath11k_wmi_vdev_create(ar, vif->addr, &vdev_param);
4472 ath11k_warn(ab, "failed to create WMI vdev %d: %d\n",
4473 arvif->vdev_id, ret);
4477 ar->num_created_vdevs++;
4478 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM created, vdev_id %d\n",
4479 vif->addr, arvif->vdev_id);
4480 ar->allocated_vdev_map |= 1LL << arvif->vdev_id;
4481 ab->free_vdev_map &= ~(1LL << arvif->vdev_id);
4483 spin_lock_bh(&ar->data_lock);
4484 list_add(&arvif->list, &ar->arvifs);
4485 spin_unlock_bh(&ar->data_lock);
4487 ath11k_mac_op_update_vif_offload(hw, vif);
4489 nss = get_num_chains(ar->cfg_tx_chainmask) ? : 1;
4490 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4491 WMI_VDEV_PARAM_NSS, nss);
4493 ath11k_warn(ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n",
4494 arvif->vdev_id, ar->cfg_tx_chainmask, nss, ret);
4498 switch (arvif->vdev_type) {
4499 case WMI_VDEV_TYPE_AP:
4500 peer_param.vdev_id = arvif->vdev_id;
4501 peer_param.peer_addr = vif->addr;
4502 peer_param.peer_type = WMI_PEER_TYPE_DEFAULT;
4503 ret = ath11k_peer_create(ar, arvif, NULL, &peer_param);
4505 ath11k_warn(ab, "failed to vdev %d create peer for AP: %d\n",
4506 arvif->vdev_id, ret);
4510 ret = ath11k_mac_set_kickout(arvif);
4512 ath11k_warn(ar->ab, "failed to set vdev %i kickout parameters: %d\n",
4513 arvif->vdev_id, ret);
4517 case WMI_VDEV_TYPE_STA:
4518 param_id = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4519 param_value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4520 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4521 param_id, param_value);
4523 ath11k_warn(ar->ab, "failed to set vdev %d RX wake policy: %d\n",
4524 arvif->vdev_id, ret);
4528 param_id = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
4529 param_value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
4530 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4531 param_id, param_value);
4533 ath11k_warn(ar->ab, "failed to set vdev %d TX wake threshold: %d\n",
4534 arvif->vdev_id, ret);
4538 param_id = WMI_STA_PS_PARAM_PSPOLL_COUNT;
4539 param_value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
4540 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4541 param_id, param_value);
4543 ath11k_warn(ar->ab, "failed to set vdev %d pspoll count: %d\n",
4544 arvif->vdev_id, ret);
4548 ret = ath11k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, false);
4550 ath11k_warn(ar->ab, "failed to disable vdev %d ps mode: %d\n",
4551 arvif->vdev_id, ret);
4559 arvif->txpower = vif->bss_conf.txpower;
4560 ret = ath11k_mac_txpower_recalc(ar);
4564 param_id = WMI_VDEV_PARAM_RTS_THRESHOLD;
4565 param_value = ar->hw->wiphy->rts_threshold;
4566 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4567 param_id, param_value);
4569 ath11k_warn(ar->ab, "failed to set rts threshold for vdev %d: %d\n",
4570 arvif->vdev_id, ret);
4573 ath11k_dp_vdev_tx_attach(ar, arvif);
4575 mutex_unlock(&ar->conf_mutex);
4580 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4582 ath11k_wmi_send_peer_delete_cmd(ar, vif->addr, arvif->vdev_id);
4586 ath11k_wmi_vdev_delete(ar, arvif->vdev_id);
4587 ar->num_created_vdevs--;
4588 ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id);
4589 ab->free_vdev_map |= 1LL << arvif->vdev_id;
4590 spin_lock_bh(&ar->data_lock);
4591 list_del(&arvif->list);
4592 spin_unlock_bh(&ar->data_lock);
4595 mutex_unlock(&ar->conf_mutex);
4600 static int ath11k_mac_vif_unref(int buf_id, void *skb, void *ctx)
4602 struct ieee80211_vif *vif = (struct ieee80211_vif *)ctx;
4603 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb);
4605 if (skb_cb->vif == vif)
4611 static void ath11k_mac_op_remove_interface(struct ieee80211_hw *hw,
4612 struct ieee80211_vif *vif)
4614 struct ath11k *ar = hw->priv;
4615 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4616 struct ath11k_base *ab = ar->ab;
4620 mutex_lock(&ar->conf_mutex);
4622 ath11k_dbg(ab, ATH11K_DBG_MAC, "mac remove interface (vdev %d)\n",
4625 spin_lock_bh(&ar->data_lock);
4626 list_del(&arvif->list);
4627 spin_unlock_bh(&ar->data_lock);
4629 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4630 ret = ath11k_peer_delete(ar, arvif->vdev_id, vif->addr);
4632 ath11k_warn(ab, "failed to submit AP self-peer removal on vdev %d: %d\n",
4633 arvif->vdev_id, ret);
4636 ret = ath11k_wmi_vdev_delete(ar, arvif->vdev_id);
4638 ath11k_warn(ab, "failed to delete WMI vdev %d: %d\n",
4639 arvif->vdev_id, ret);
4641 ar->num_created_vdevs--;
4642 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM deleted, vdev_id %d\n",
4643 vif->addr, arvif->vdev_id);
4644 ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id);
4645 ab->free_vdev_map |= 1LL << (arvif->vdev_id);
4647 ath11k_peer_cleanup(ar, arvif->vdev_id);
4649 idr_for_each(&ar->txmgmt_idr,
4650 ath11k_mac_vif_txmgmt_idr_remove, vif);
4652 for (i = 0; i < DP_TCL_NUM_RING_MAX; i++) {
4653 spin_lock_bh(&ab->dp.tx_ring[i].tx_idr_lock);
4654 idr_for_each(&ab->dp.tx_ring[i].txbuf_idr,
4655 ath11k_mac_vif_unref, vif);
4656 spin_unlock_bh(&ab->dp.tx_ring[i].tx_idr_lock);
4659 /* Recalc txpower for remaining vdev */
4660 ath11k_mac_txpower_recalc(ar);
4661 clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags);
4663 /* TODO: recal traffic pause state based on the available vdevs */
4665 mutex_unlock(&ar->conf_mutex);
4668 /* FIXME: Has to be verified. */
4669 #define SUPPORTED_FILTERS \
4674 FIF_BCN_PRBRESP_PROMISC | \
4678 static void ath11k_mac_op_configure_filter(struct ieee80211_hw *hw,
4679 unsigned int changed_flags,
4680 unsigned int *total_flags,
4683 struct ath11k *ar = hw->priv;
4684 bool reset_flag = false;
4687 mutex_lock(&ar->conf_mutex);
4689 changed_flags &= SUPPORTED_FILTERS;
4690 *total_flags &= SUPPORTED_FILTERS;
4691 ar->filter_flags = *total_flags;
4693 /* For monitor mode */
4694 reset_flag = !(ar->filter_flags & FIF_BCN_PRBRESP_PROMISC);
4696 ret = ath11k_dp_tx_htt_monitor_mode_ring_config(ar, reset_flag);
4699 set_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags);
4701 clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags);
4704 "fail to set monitor filter: %d\n", ret);
4706 mutex_unlock(&ar->conf_mutex);
4709 static int ath11k_mac_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4711 struct ath11k *ar = hw->priv;
4713 mutex_lock(&ar->conf_mutex);
4715 *tx_ant = ar->cfg_tx_chainmask;
4716 *rx_ant = ar->cfg_rx_chainmask;
4718 mutex_unlock(&ar->conf_mutex);
4723 static int ath11k_mac_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4725 struct ath11k *ar = hw->priv;
4728 mutex_lock(&ar->conf_mutex);
4729 ret = __ath11k_set_antenna(ar, tx_ant, rx_ant);
4730 mutex_unlock(&ar->conf_mutex);
4735 static int ath11k_mac_op_ampdu_action(struct ieee80211_hw *hw,
4736 struct ieee80211_vif *vif,
4737 struct ieee80211_ampdu_params *params)
4739 struct ath11k *ar = hw->priv;
4742 mutex_lock(&ar->conf_mutex);
4744 switch (params->action) {
4745 case IEEE80211_AMPDU_RX_START:
4746 ret = ath11k_dp_rx_ampdu_start(ar, params);
4748 case IEEE80211_AMPDU_RX_STOP:
4749 ret = ath11k_dp_rx_ampdu_stop(ar, params);
4751 case IEEE80211_AMPDU_TX_START:
4752 case IEEE80211_AMPDU_TX_STOP_CONT:
4753 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4754 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4755 case IEEE80211_AMPDU_TX_OPERATIONAL:
4756 /* Tx A-MPDU aggregation offloaded to hw/fw so deny mac80211
4757 * Tx aggregation requests.
4763 mutex_unlock(&ar->conf_mutex);
4768 static int ath11k_mac_op_add_chanctx(struct ieee80211_hw *hw,
4769 struct ieee80211_chanctx_conf *ctx)
4771 struct ath11k *ar = hw->priv;
4772 struct ath11k_base *ab = ar->ab;
4774 ath11k_dbg(ab, ATH11K_DBG_MAC,
4775 "mac chanctx add freq %hu width %d ptr %pK\n",
4776 ctx->def.chan->center_freq, ctx->def.width, ctx);
4778 mutex_lock(&ar->conf_mutex);
4780 spin_lock_bh(&ar->data_lock);
4781 /* TODO: In case of multiple channel context, populate rx_channel from
4782 * Rx PPDU desc information.
4784 ar->rx_channel = ctx->def.chan;
4785 spin_unlock_bh(&ar->data_lock);
4787 mutex_unlock(&ar->conf_mutex);
4792 static void ath11k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
4793 struct ieee80211_chanctx_conf *ctx)
4795 struct ath11k *ar = hw->priv;
4796 struct ath11k_base *ab = ar->ab;
4798 ath11k_dbg(ab, ATH11K_DBG_MAC,
4799 "mac chanctx remove freq %hu width %d ptr %pK\n",
4800 ctx->def.chan->center_freq, ctx->def.width, ctx);
4802 mutex_lock(&ar->conf_mutex);
4804 spin_lock_bh(&ar->data_lock);
4805 /* TODO: In case of there is one more channel context left, populate
4806 * rx_channel with the channel of that remaining channel context.
4808 ar->rx_channel = NULL;
4809 spin_unlock_bh(&ar->data_lock);
4811 mutex_unlock(&ar->conf_mutex);
4814 static inline int ath11k_mac_vdev_setup_sync(struct ath11k *ar)
4816 lockdep_assert_held(&ar->conf_mutex);
4818 if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))
4821 if (!wait_for_completion_timeout(&ar->vdev_setup_done,
4822 ATH11K_VDEV_SETUP_TIMEOUT_HZ))
4825 return ar->last_wmi_vdev_start_status ? -EINVAL : 0;
4829 ath11k_mac_vdev_start_restart(struct ath11k_vif *arvif,
4830 const struct cfg80211_chan_def *chandef,
4833 struct ath11k *ar = arvif->ar;
4834 struct ath11k_base *ab = ar->ab;
4835 struct wmi_vdev_start_req_arg arg = {};
4836 int he_support = arvif->vif->bss_conf.he_support;
4839 lockdep_assert_held(&ar->conf_mutex);
4841 reinit_completion(&ar->vdev_setup_done);
4843 arg.vdev_id = arvif->vdev_id;
4844 arg.dtim_period = arvif->dtim_period;
4845 arg.bcn_intval = arvif->beacon_interval;
4847 arg.channel.freq = chandef->chan->center_freq;
4848 arg.channel.band_center_freq1 = chandef->center_freq1;
4849 arg.channel.band_center_freq2 = chandef->center_freq2;
4851 ath11k_phymodes[chandef->chan->band][chandef->width];
4853 arg.channel.min_power = 0;
4854 arg.channel.max_power = chandef->chan->max_power * 2;
4855 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
4856 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
4858 arg.pref_tx_streams = ar->num_tx_chains;
4859 arg.pref_rx_streams = ar->num_rx_chains;
4861 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4862 arg.ssid = arvif->u.ap.ssid;
4863 arg.ssid_len = arvif->u.ap.ssid_len;
4864 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
4866 /* For now allow DFS for AP mode */
4867 arg.channel.chan_radar =
4868 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
4870 arg.channel.passive = arg.channel.chan_radar;
4872 spin_lock_bh(&ab->base_lock);
4873 arg.regdomain = ar->ab->dfs_region;
4874 spin_unlock_bh(&ab->base_lock);
4876 /* TODO: Notify if secondary 80Mhz also needs radar detection */
4878 ret = ath11k_set_he_mu_sounding_mode(ar, arvif);
4880 ath11k_warn(ar->ab, "failed to set he mode vdev %i\n",
4887 arg.channel.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR);
4889 ath11k_dbg(ab, ATH11K_DBG_MAC,
4890 "mac vdev %d start center_freq %d phymode %s\n",
4891 arg.vdev_id, arg.channel.freq,
4892 ath11k_wmi_phymode_str(arg.channel.mode));
4894 ret = ath11k_wmi_vdev_start(ar, &arg, restart);
4896 ath11k_warn(ar->ab, "failed to %s WMI vdev %i\n",
4897 restart ? "restart" : "start", arg.vdev_id);
4901 ret = ath11k_mac_vdev_setup_sync(ar);
4903 ath11k_warn(ab, "failed to synchronize setup for vdev %i %s: %d\n",
4904 arg.vdev_id, restart ? "restart" : "start", ret);
4908 ar->num_started_vdevs++;
4909 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM started, vdev_id %d\n",
4910 arvif->vif->addr, arvif->vdev_id);
4912 /* Enable CAC Flag in the driver by checking the channel DFS cac time,
4913 * i.e dfs_cac_ms value which will be valid only for radar channels
4914 * and state as NL80211_DFS_USABLE which indicates CAC needs to be
4915 * done before channel usage. This flags is used to drop rx packets.
4918 /* TODO Set the flag for other interface types as required */
4919 if (arvif->vdev_type == WMI_VDEV_TYPE_AP &&
4920 chandef->chan->dfs_cac_ms &&
4921 chandef->chan->dfs_state == NL80211_DFS_USABLE) {
4922 set_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
4923 ath11k_dbg(ab, ATH11K_DBG_MAC,
4924 "CAC Started in chan_freq %d for vdev %d\n",
4925 arg.channel.freq, arg.vdev_id);
4928 ret = ath11k_mac_set_txbf_conf(arvif);
4930 ath11k_warn(ab, "failed to set txbf conf for vdev %d: %d\n",
4931 arvif->vdev_id, ret);
4936 static int ath11k_mac_vdev_stop(struct ath11k_vif *arvif)
4938 struct ath11k *ar = arvif->ar;
4941 lockdep_assert_held(&ar->conf_mutex);
4943 reinit_completion(&ar->vdev_setup_done);
4945 spin_lock_bh(&ar->data_lock);
4947 ar->vdev_stop_status.stop_in_progress = true;
4948 ar->vdev_stop_status.vdev_id = arvif->vdev_id;
4950 spin_unlock_bh(&ar->data_lock);
4952 ret = ath11k_wmi_vdev_stop(ar, arvif->vdev_id);
4954 ath11k_warn(ar->ab, "failed to stop WMI vdev %i: %d\n",
4955 arvif->vdev_id, ret);
4959 ret = ath11k_mac_vdev_setup_sync(ar);
4961 ath11k_warn(ar->ab, "failed to synchronize setup for vdev %i: %d\n",
4962 arvif->vdev_id, ret);
4966 WARN_ON(ar->num_started_vdevs == 0);
4968 ar->num_started_vdevs--;
4969 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "vdev %pM stopped, vdev_id %d\n",
4970 arvif->vif->addr, arvif->vdev_id);
4972 if (test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) {
4973 clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
4974 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "CAC Stopped for vdev %d\n",
4980 spin_lock_bh(&ar->data_lock);
4981 ar->vdev_stop_status.stop_in_progress = false;
4982 spin_unlock_bh(&ar->data_lock);
4987 static int ath11k_mac_vdev_start(struct ath11k_vif *arvif,
4988 const struct cfg80211_chan_def *chandef)
4990 return ath11k_mac_vdev_start_restart(arvif, chandef, false);
4993 static int ath11k_mac_vdev_restart(struct ath11k_vif *arvif,
4994 const struct cfg80211_chan_def *chandef)
4996 return ath11k_mac_vdev_start_restart(arvif, chandef, true);
4999 struct ath11k_mac_change_chanctx_arg {
5000 struct ieee80211_chanctx_conf *ctx;
5001 struct ieee80211_vif_chanctx_switch *vifs;
5007 ath11k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
5008 struct ieee80211_vif *vif)
5010 struct ath11k_mac_change_chanctx_arg *arg = data;
5012 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
5019 ath11k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
5020 struct ieee80211_vif *vif)
5022 struct ath11k_mac_change_chanctx_arg *arg = data;
5023 struct ieee80211_chanctx_conf *ctx;
5025 ctx = rcu_access_pointer(vif->chanctx_conf);
5026 if (ctx != arg->ctx)
5029 if (WARN_ON(arg->next_vif == arg->n_vifs))
5032 arg->vifs[arg->next_vif].vif = vif;
5033 arg->vifs[arg->next_vif].old_ctx = ctx;
5034 arg->vifs[arg->next_vif].new_ctx = ctx;
5039 ath11k_mac_update_vif_chan(struct ath11k *ar,
5040 struct ieee80211_vif_chanctx_switch *vifs,
5043 struct ath11k_base *ab = ar->ab;
5044 struct ath11k_vif *arvif;
5048 lockdep_assert_held(&ar->conf_mutex);
5050 for (i = 0; i < n_vifs; i++) {
5051 arvif = (void *)vifs[i].vif->drv_priv;
5053 ath11k_dbg(ab, ATH11K_DBG_MAC,
5054 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
5056 vifs[i].old_ctx->def.chan->center_freq,
5057 vifs[i].new_ctx->def.chan->center_freq,
5058 vifs[i].old_ctx->def.width,
5059 vifs[i].new_ctx->def.width);
5061 if (WARN_ON(!arvif->is_started))
5064 if (WARN_ON(!arvif->is_up))
5067 ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id);
5069 ath11k_warn(ab, "failed to down vdev %d: %d\n",
5070 arvif->vdev_id, ret);
5075 /* All relevant vdevs are downed and associated channel resources
5076 * should be available for the channel switch now.
5079 /* TODO: Update ar->rx_channel */
5081 for (i = 0; i < n_vifs; i++) {
5082 arvif = (void *)vifs[i].vif->drv_priv;
5084 if (WARN_ON(!arvif->is_started))
5087 if (WARN_ON(!arvif->is_up))
5090 ret = ath11k_mac_setup_bcn_tmpl(arvif);
5092 ath11k_warn(ab, "failed to update bcn tmpl during csa: %d\n",
5095 ret = ath11k_mac_vdev_restart(arvif, &vifs[i].new_ctx->def);
5097 ath11k_warn(ab, "failed to restart vdev %d: %d\n",
5098 arvif->vdev_id, ret);
5102 ret = ath11k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
5105 ath11k_warn(ab, "failed to bring vdev up %d: %d\n",
5106 arvif->vdev_id, ret);
5113 ath11k_mac_update_active_vif_chan(struct ath11k *ar,
5114 struct ieee80211_chanctx_conf *ctx)
5116 struct ath11k_mac_change_chanctx_arg arg = { .ctx = ctx };
5118 lockdep_assert_held(&ar->conf_mutex);
5120 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5121 IEEE80211_IFACE_ITER_NORMAL,
5122 ath11k_mac_change_chanctx_cnt_iter,
5124 if (arg.n_vifs == 0)
5127 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]), GFP_KERNEL);
5131 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5132 IEEE80211_IFACE_ITER_NORMAL,
5133 ath11k_mac_change_chanctx_fill_iter,
5136 ath11k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
5141 static void ath11k_mac_op_change_chanctx(struct ieee80211_hw *hw,
5142 struct ieee80211_chanctx_conf *ctx,
5145 struct ath11k *ar = hw->priv;
5146 struct ath11k_base *ab = ar->ab;
5148 mutex_lock(&ar->conf_mutex);
5150 ath11k_dbg(ab, ATH11K_DBG_MAC,
5151 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
5152 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
5154 /* This shouldn't really happen because channel switching should use
5155 * switch_vif_chanctx().
5157 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
5160 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH)
5161 ath11k_mac_update_active_vif_chan(ar, ctx);
5163 /* TODO: Recalc radar detection */
5166 mutex_unlock(&ar->conf_mutex);
5169 static int ath11k_start_vdev_delay(struct ieee80211_hw *hw,
5170 struct ieee80211_vif *vif)
5172 struct ath11k *ar = hw->priv;
5173 struct ath11k_base *ab = ar->ab;
5174 struct ath11k_vif *arvif = (void *)vif->drv_priv;
5177 if (WARN_ON(arvif->is_started))
5180 ret = ath11k_mac_vdev_start(arvif, &arvif->chanctx.def);
5182 ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
5183 arvif->vdev_id, vif->addr,
5184 arvif->chanctx.def.chan->center_freq, ret);
5188 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
5189 ret = ath11k_monitor_vdev_up(ar, arvif->vdev_id);
5191 ath11k_warn(ab, "failed put monitor up: %d\n", ret);
5196 arvif->is_started = true;
5198 /* TODO: Setup ps and cts/rts protection */
5203 ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
5204 struct ieee80211_vif *vif,
5205 struct ieee80211_chanctx_conf *ctx)
5207 struct ath11k *ar = hw->priv;
5208 struct ath11k_base *ab = ar->ab;
5209 struct ath11k_vif *arvif = (void *)vif->drv_priv;
5212 mutex_lock(&ar->conf_mutex);
5214 ath11k_dbg(ab, ATH11K_DBG_MAC,
5215 "mac chanctx assign ptr %pK vdev_id %i\n",
5216 ctx, arvif->vdev_id);
5218 /* for QCA6390 bss peer must be created before vdev_start */
5219 if (ab->hw_params.vdev_start_delay &&
5220 arvif->vdev_type != WMI_VDEV_TYPE_AP) {
5221 memcpy(&arvif->chanctx, ctx, sizeof(*ctx));
5222 mutex_unlock(&ar->conf_mutex);
5226 if (WARN_ON(arvif->is_started)) {
5227 mutex_unlock(&ar->conf_mutex);
5231 ret = ath11k_mac_vdev_start(arvif, &ctx->def);
5233 ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
5234 arvif->vdev_id, vif->addr,
5235 ctx->def.chan->center_freq, ret);
5238 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
5239 ret = ath11k_monitor_vdev_up(ar, arvif->vdev_id);
5244 arvif->is_started = true;
5246 /* TODO: Setup ps and cts/rts protection */
5248 mutex_unlock(&ar->conf_mutex);
5253 mutex_unlock(&ar->conf_mutex);
5259 ath11k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
5260 struct ieee80211_vif *vif,
5261 struct ieee80211_chanctx_conf *ctx)
5263 struct ath11k *ar = hw->priv;
5264 struct ath11k_base *ab = ar->ab;
5265 struct ath11k_vif *arvif = (void *)vif->drv_priv;
5268 mutex_lock(&ar->conf_mutex);
5270 ath11k_dbg(ab, ATH11K_DBG_MAC,
5271 "mac chanctx unassign ptr %pK vdev_id %i\n",
5272 ctx, arvif->vdev_id);
5274 WARN_ON(!arvif->is_started);
5276 ret = ath11k_mac_vdev_stop(arvif);
5278 ath11k_warn(ab, "failed to stop vdev %i: %d\n",
5279 arvif->vdev_id, ret);
5281 arvif->is_started = false;
5283 mutex_unlock(&ar->conf_mutex);
5287 ath11k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
5288 struct ieee80211_vif_chanctx_switch *vifs,
5290 enum ieee80211_chanctx_switch_mode mode)
5292 struct ath11k *ar = hw->priv;
5294 mutex_lock(&ar->conf_mutex);
5296 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
5297 "mac chanctx switch n_vifs %d mode %d\n",
5299 ath11k_mac_update_vif_chan(ar, vifs, n_vifs);
5301 mutex_unlock(&ar->conf_mutex);
5307 ath11k_set_vdev_param_to_all_vifs(struct ath11k *ar, int param, u32 value)
5309 struct ath11k_vif *arvif;
5312 mutex_lock(&ar->conf_mutex);
5313 list_for_each_entry(arvif, &ar->arvifs, list) {
5314 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "setting mac vdev %d param %d value %d\n",
5315 param, arvif->vdev_id, value);
5317 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5320 ath11k_warn(ar->ab, "failed to set param %d for vdev %d: %d\n",
5321 param, arvif->vdev_id, ret);
5325 mutex_unlock(&ar->conf_mutex);
5329 /* mac80211 stores device specific RTS/Fragmentation threshold value,
5330 * this is set interface specific to firmware from ath11k driver
5332 static int ath11k_mac_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5334 struct ath11k *ar = hw->priv;
5335 int param_id = WMI_VDEV_PARAM_RTS_THRESHOLD;
5337 return ath11k_set_vdev_param_to_all_vifs(ar, param_id, value);
5340 static int ath11k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
5342 /* Even though there's a WMI vdev param for fragmentation threshold no
5343 * known firmware actually implements it. Moreover it is not possible to
5344 * rely frame fragmentation to mac80211 because firmware clears the
5345 * "more fragments" bit in frame control making it impossible for remote
5346 * devices to reassemble frames.
5348 * Hence implement a dummy callback just to say fragmentation isn't
5349 * supported. This effectively prevents mac80211 from doing frame
5350 * fragmentation in software.
5355 static void ath11k_mac_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5356 u32 queues, bool drop)
5358 struct ath11k *ar = hw->priv;
5364 time_left = wait_event_timeout(ar->dp.tx_empty_waitq,
5365 (atomic_read(&ar->dp.num_tx_pending) == 0),
5366 ATH11K_FLUSH_TIMEOUT);
5368 ath11k_warn(ar->ab, "failed to flush transmit queue %ld\n", time_left);
5372 ath11k_mac_bitrate_mask_num_ht_rates(struct ath11k *ar,
5373 enum nl80211_band band,
5374 const struct cfg80211_bitrate_mask *mask)
5379 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5380 num_rates += hweight16(mask->control[band].ht_mcs[i]);
5386 ath11k_mac_has_single_legacy_rate(struct ath11k *ar,
5387 enum nl80211_band band,
5388 const struct cfg80211_bitrate_mask *mask)
5392 num_rates = hweight32(mask->control[band].legacy);
5394 if (ath11k_mac_bitrate_mask_num_ht_rates(ar, band, mask))
5397 if (ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask))
5400 return num_rates == 1;
5404 ath11k_mac_bitrate_mask_get_single_nss(struct ath11k *ar,
5405 enum nl80211_band band,
5406 const struct cfg80211_bitrate_mask *mask,
5409 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5410 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5412 u8 vht_nss_mask = 0;
5415 /* No need to consider legacy here. Basic rates are always present
5419 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5420 if (mask->control[band].ht_mcs[i] == 0)
5422 else if (mask->control[band].ht_mcs[i] ==
5423 sband->ht_cap.mcs.rx_mask[i])
5424 ht_nss_mask |= BIT(i);
5429 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5430 if (mask->control[band].vht_mcs[i] == 0)
5432 else if (mask->control[band].vht_mcs[i] ==
5433 ath11k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5434 vht_nss_mask |= BIT(i);
5439 if (ht_nss_mask != vht_nss_mask)
5442 if (ht_nss_mask == 0)
5445 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5448 *nss = fls(ht_nss_mask);
5454 ath11k_mac_get_single_legacy_rate(struct ath11k *ar,
5455 enum nl80211_band band,
5456 const struct cfg80211_bitrate_mask *mask,
5464 if (hweight32(mask->control[band].legacy) != 1)
5467 rate_idx = ffs(mask->control[band].legacy) - 1;
5469 if (band == NL80211_BAND_5GHZ || band == NL80211_BAND_6GHZ)
5470 rate_idx += ATH11K_MAC_FIRST_OFDM_RATE_IDX;
5472 hw_rate = ath11k_legacy_rates[rate_idx].hw_value;
5473 bitrate = ath11k_legacy_rates[rate_idx].bitrate;
5475 if (ath11k_mac_bitrate_is_cck(bitrate))
5476 preamble = WMI_RATE_PREAMBLE_CCK;
5478 preamble = WMI_RATE_PREAMBLE_OFDM;
5481 *rate = ATH11K_HW_RATE_CODE(hw_rate, 0, preamble);
5486 static int ath11k_mac_set_fixed_rate_params(struct ath11k_vif *arvif,
5487 u32 rate, u8 nss, u8 sgi, u8 ldpc)
5489 struct ath11k *ar = arvif->ar;
5493 lockdep_assert_held(&ar->conf_mutex);
5495 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5496 arvif->vdev_id, rate, nss, sgi);
5498 vdev_param = WMI_VDEV_PARAM_FIXED_RATE;
5499 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5502 ath11k_warn(ar->ab, "failed to set fixed rate param 0x%02x: %d\n",
5507 vdev_param = WMI_VDEV_PARAM_NSS;
5508 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5511 ath11k_warn(ar->ab, "failed to set nss param %d: %d\n",
5516 vdev_param = WMI_VDEV_PARAM_SGI;
5517 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5520 ath11k_warn(ar->ab, "failed to set sgi param %d: %d\n",
5525 vdev_param = WMI_VDEV_PARAM_LDPC;
5526 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5529 ath11k_warn(ar->ab, "failed to set ldpc param %d: %d\n",
5538 ath11k_mac_vht_mcs_range_present(struct ath11k *ar,
5539 enum nl80211_band band,
5540 const struct cfg80211_bitrate_mask *mask)
5545 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5546 vht_mcs = mask->control[band].vht_mcs[i];
5562 static void ath11k_mac_set_bitrate_mask_iter(void *data,
5563 struct ieee80211_sta *sta)
5565 struct ath11k_vif *arvif = data;
5566 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
5567 struct ath11k *ar = arvif->ar;
5569 spin_lock_bh(&ar->data_lock);
5570 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
5571 spin_unlock_bh(&ar->data_lock);
5573 ieee80211_queue_work(ar->hw, &arsta->update_wk);
5576 static void ath11k_mac_disable_peer_fixed_rate(void *data,
5577 struct ieee80211_sta *sta)
5579 struct ath11k_vif *arvif = data;
5580 struct ath11k *ar = arvif->ar;
5583 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
5585 WMI_PEER_PARAM_FIXED_RATE,
5586 WMI_FIXED_RATE_NONE);
5589 "failed to disable peer fixed rate for STA %pM ret %d\n",
5594 ath11k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5595 struct ieee80211_vif *vif,
5596 const struct cfg80211_bitrate_mask *mask)
5598 struct ath11k_vif *arvif = (void *)vif->drv_priv;
5599 struct cfg80211_chan_def def;
5600 struct ath11k *ar = arvif->ar;
5601 enum nl80211_band band;
5602 const u8 *ht_mcs_mask;
5603 const u16 *vht_mcs_mask;
5612 if (ath11k_mac_vif_chan(vif, &def))
5615 band = def.chan->band;
5616 ht_mcs_mask = mask->control[band].ht_mcs;
5617 vht_mcs_mask = mask->control[band].vht_mcs;
5618 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
5620 sgi = mask->control[band].gi;
5621 if (sgi == NL80211_TXRATE_FORCE_LGI)
5624 /* mac80211 doesn't support sending a fixed HT/VHT MCS alone, rather it
5625 * requires passing atleast one of used basic rates along with them.
5626 * Fixed rate setting across different preambles(legacy, HT, VHT) is
5627 * not supported by the FW. Hence use of FIXED_RATE vdev param is not
5628 * suitable for setting single HT/VHT rates.
5629 * But, there could be a single basic rate passed from userspace which
5630 * can be done through the FIXED_RATE param.
5632 if (ath11k_mac_has_single_legacy_rate(ar, band, mask)) {
5633 ret = ath11k_mac_get_single_legacy_rate(ar, band, mask, &rate,
5636 ath11k_warn(ar->ab, "failed to get single legacy rate for vdev %i: %d\n",
5637 arvif->vdev_id, ret);
5640 ieee80211_iterate_stations_atomic(ar->hw,
5641 ath11k_mac_disable_peer_fixed_rate,
5643 } else if (ath11k_mac_bitrate_mask_get_single_nss(ar, band, mask,
5645 rate = WMI_FIXED_RATE_NONE;
5648 rate = WMI_FIXED_RATE_NONE;
5649 nss = min_t(u32, ar->num_tx_chains,
5650 max(ath11k_mac_max_ht_nss(ht_mcs_mask),
5651 ath11k_mac_max_vht_nss(vht_mcs_mask)));
5653 /* If multiple rates across different preambles are given
5654 * we can reconfigure this info with all peers using PEER_ASSOC
5655 * command with the below exception cases.
5656 * - Single VHT Rate : peer_assoc command accommodates only MCS
5657 * range values i.e 0-7, 0-8, 0-9 for VHT. Though mac80211
5658 * mandates passing basic rates along with HT/VHT rates, FW
5659 * doesn't allow switching from VHT to Legacy. Hence instead of
5660 * setting legacy and VHT rates using RATEMASK_CMD vdev cmd,
5661 * we could set this VHT rate as peer fixed rate param, which
5662 * will override FIXED rate and FW rate control algorithm.
5663 * If single VHT rate is passed along with HT rates, we select
5664 * the VHT rate as fixed rate for vht peers.
5665 * - Multiple VHT Rates : When Multiple VHT rates are given,this
5666 * can be set using RATEMASK CMD which uses FW rate-ctl alg.
5667 * TODO: Setting multiple VHT MCS and replacing peer_assoc with
5668 * RATEMASK_CMDID can cover all use cases of setting rates
5669 * across multiple preambles and rates within same type.
5670 * But requires more validation of the command at this point.
5673 num_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band,
5676 if (!ath11k_mac_vht_mcs_range_present(ar, band, mask) &&
5678 /* TODO: Handle multiple VHT MCS values setting using
5682 "Setting more than one MCS Value in bitrate mask not supported\n");
5686 ieee80211_iterate_stations_atomic(ar->hw,
5687 ath11k_mac_disable_peer_fixed_rate,
5690 mutex_lock(&ar->conf_mutex);
5692 arvif->bitrate_mask = *mask;
5693 ieee80211_iterate_stations_atomic(ar->hw,
5694 ath11k_mac_set_bitrate_mask_iter,
5697 mutex_unlock(&ar->conf_mutex);
5700 mutex_lock(&ar->conf_mutex);
5702 ret = ath11k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
5704 ath11k_warn(ar->ab, "failed to set fixed rate params on vdev %i: %d\n",
5705 arvif->vdev_id, ret);
5708 mutex_unlock(&ar->conf_mutex);
5714 ath11k_mac_op_reconfig_complete(struct ieee80211_hw *hw,
5715 enum ieee80211_reconfig_type reconfig_type)
5717 struct ath11k *ar = hw->priv;
5719 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5722 mutex_lock(&ar->conf_mutex);
5724 if (ar->state == ATH11K_STATE_RESTARTED) {
5725 ath11k_warn(ar->ab, "pdev %d successfully recovered\n",
5727 ar->state = ATH11K_STATE_ON;
5728 ieee80211_wake_queues(ar->hw);
5731 mutex_unlock(&ar->conf_mutex);
5735 ath11k_mac_update_bss_chan_survey(struct ath11k *ar,
5736 struct ieee80211_channel *channel)
5739 enum wmi_bss_chan_info_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
5741 lockdep_assert_held(&ar->conf_mutex);
5743 if (!test_bit(WMI_TLV_SERVICE_BSS_CHANNEL_INFO_64, ar->ab->wmi_ab.svc_map) ||
5744 ar->rx_channel != channel)
5747 if (ar->scan.state != ATH11K_SCAN_IDLE) {
5748 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
5749 "ignoring bss chan info req while scanning..\n");
5753 reinit_completion(&ar->bss_survey_done);
5755 ret = ath11k_wmi_pdev_bss_chan_info_request(ar, type);
5757 ath11k_warn(ar->ab, "failed to send pdev bss chan info request\n");
5761 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
5763 ath11k_warn(ar->ab, "bss channel survey timed out\n");
5766 static int ath11k_mac_op_get_survey(struct ieee80211_hw *hw, int idx,
5767 struct survey_info *survey)
5769 struct ath11k *ar = hw->priv;
5770 struct ieee80211_supported_band *sband;
5771 struct survey_info *ar_survey;
5774 if (idx >= ATH11K_NUM_CHANS)
5777 ar_survey = &ar->survey[idx];
5779 mutex_lock(&ar->conf_mutex);
5781 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
5782 if (sband && idx >= sband->n_channels) {
5783 idx -= sband->n_channels;
5788 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
5790 if (!sband || idx >= sband->n_channels) {
5795 ath11k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
5797 spin_lock_bh(&ar->data_lock);
5798 memcpy(survey, ar_survey, sizeof(*survey));
5799 spin_unlock_bh(&ar->data_lock);
5801 survey->channel = &sband->channels[idx];
5803 if (ar->rx_channel == survey->channel)
5804 survey->filled |= SURVEY_INFO_IN_USE;
5807 mutex_unlock(&ar->conf_mutex);
5811 static void ath11k_mac_op_sta_statistics(struct ieee80211_hw *hw,
5812 struct ieee80211_vif *vif,
5813 struct ieee80211_sta *sta,
5814 struct station_info *sinfo)
5816 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
5818 sinfo->rx_duration = arsta->rx_duration;
5819 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
5821 sinfo->tx_duration = arsta->tx_duration;
5822 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION);
5824 if (!arsta->txrate.legacy && !arsta->txrate.nss)
5827 if (arsta->txrate.legacy) {
5828 sinfo->txrate.legacy = arsta->txrate.legacy;
5830 sinfo->txrate.mcs = arsta->txrate.mcs;
5831 sinfo->txrate.nss = arsta->txrate.nss;
5832 sinfo->txrate.bw = arsta->txrate.bw;
5833 sinfo->txrate.he_gi = arsta->txrate.he_gi;
5834 sinfo->txrate.he_dcm = arsta->txrate.he_dcm;
5835 sinfo->txrate.he_ru_alloc = arsta->txrate.he_ru_alloc;
5837 sinfo->txrate.flags = arsta->txrate.flags;
5838 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
5840 /* TODO: Use real NF instead of default one. */
5841 sinfo->signal = arsta->rssi_comb + ATH11K_DEFAULT_NOISE_FLOOR;
5844 static const struct ieee80211_ops ath11k_ops = {
5845 .tx = ath11k_mac_op_tx,
5846 .start = ath11k_mac_op_start,
5847 .stop = ath11k_mac_op_stop,
5848 .reconfig_complete = ath11k_mac_op_reconfig_complete,
5849 .add_interface = ath11k_mac_op_add_interface,
5850 .remove_interface = ath11k_mac_op_remove_interface,
5851 .update_vif_offload = ath11k_mac_op_update_vif_offload,
5852 .config = ath11k_mac_op_config,
5853 .bss_info_changed = ath11k_mac_op_bss_info_changed,
5854 .configure_filter = ath11k_mac_op_configure_filter,
5855 .hw_scan = ath11k_mac_op_hw_scan,
5856 .cancel_hw_scan = ath11k_mac_op_cancel_hw_scan,
5857 .set_key = ath11k_mac_op_set_key,
5858 .sta_state = ath11k_mac_op_sta_state,
5859 .sta_set_txpwr = ath11k_mac_op_sta_set_txpwr,
5860 .sta_rc_update = ath11k_mac_op_sta_rc_update,
5861 .conf_tx = ath11k_mac_op_conf_tx,
5862 .set_antenna = ath11k_mac_op_set_antenna,
5863 .get_antenna = ath11k_mac_op_get_antenna,
5864 .ampdu_action = ath11k_mac_op_ampdu_action,
5865 .add_chanctx = ath11k_mac_op_add_chanctx,
5866 .remove_chanctx = ath11k_mac_op_remove_chanctx,
5867 .change_chanctx = ath11k_mac_op_change_chanctx,
5868 .assign_vif_chanctx = ath11k_mac_op_assign_vif_chanctx,
5869 .unassign_vif_chanctx = ath11k_mac_op_unassign_vif_chanctx,
5870 .switch_vif_chanctx = ath11k_mac_op_switch_vif_chanctx,
5871 .set_rts_threshold = ath11k_mac_op_set_rts_threshold,
5872 .set_frag_threshold = ath11k_mac_op_set_frag_threshold,
5873 .set_bitrate_mask = ath11k_mac_op_set_bitrate_mask,
5874 .get_survey = ath11k_mac_op_get_survey,
5875 .flush = ath11k_mac_op_flush,
5876 .sta_statistics = ath11k_mac_op_sta_statistics,
5877 CFG80211_TESTMODE_CMD(ath11k_tm_cmd)
5878 #ifdef CONFIG_ATH11K_DEBUGFS
5879 .sta_add_debugfs = ath11k_debugfs_sta_op_add,
5883 static void ath11k_mac_update_ch_list(struct ath11k *ar,
5884 struct ieee80211_supported_band *band,
5885 u32 freq_low, u32 freq_high)
5889 if (!(freq_low && freq_high))
5892 for (i = 0; i < band->n_channels; i++) {
5893 if (band->channels[i].center_freq < freq_low ||
5894 band->channels[i].center_freq > freq_high)
5895 band->channels[i].flags |= IEEE80211_CHAN_DISABLED;
5899 static u32 ath11k_get_phy_id(struct ath11k *ar, u32 band)
5901 struct ath11k_pdev *pdev = ar->pdev;
5902 struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
5904 if (band == WMI_HOST_WLAN_2G_CAP)
5905 return pdev_cap->band[NL80211_BAND_2GHZ].phy_id;
5907 if (band == WMI_HOST_WLAN_5G_CAP)
5908 return pdev_cap->band[NL80211_BAND_5GHZ].phy_id;
5910 ath11k_warn(ar->ab, "unsupported phy cap:%d\n", band);
5915 static int ath11k_mac_setup_channels_rates(struct ath11k *ar,
5916 u32 supported_bands)
5918 struct ieee80211_supported_band *band;
5919 struct ath11k_hal_reg_capabilities_ext *reg_cap;
5923 BUILD_BUG_ON((ARRAY_SIZE(ath11k_2ghz_channels) +
5924 ARRAY_SIZE(ath11k_5ghz_channels) +
5925 ARRAY_SIZE(ath11k_6ghz_channels)) !=
5928 reg_cap = &ar->ab->hal_reg_cap[ar->pdev_idx];
5930 if (supported_bands & WMI_HOST_WLAN_2G_CAP) {
5931 channels = kmemdup(ath11k_2ghz_channels,
5932 sizeof(ath11k_2ghz_channels),
5937 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
5938 band->band = NL80211_BAND_2GHZ;
5939 band->n_channels = ARRAY_SIZE(ath11k_2ghz_channels);
5940 band->channels = channels;
5941 band->n_bitrates = ath11k_g_rates_size;
5942 band->bitrates = ath11k_g_rates;
5943 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
5945 if (ar->ab->hw_params.single_pdev_only) {
5946 phy_id = ath11k_get_phy_id(ar, WMI_HOST_WLAN_2G_CAP);
5947 reg_cap = &ar->ab->hal_reg_cap[phy_id];
5949 ath11k_mac_update_ch_list(ar, band,
5950 reg_cap->low_2ghz_chan,
5951 reg_cap->high_2ghz_chan);
5954 if (supported_bands & WMI_HOST_WLAN_5G_CAP) {
5955 if (reg_cap->high_5ghz_chan >= ATH11K_MAX_6G_FREQ) {
5956 channels = kmemdup(ath11k_6ghz_channels,
5957 sizeof(ath11k_6ghz_channels), GFP_KERNEL);
5959 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
5963 ar->supports_6ghz = true;
5964 band = &ar->mac.sbands[NL80211_BAND_6GHZ];
5965 band->band = NL80211_BAND_6GHZ;
5966 band->n_channels = ARRAY_SIZE(ath11k_6ghz_channels);
5967 band->channels = channels;
5968 band->n_bitrates = ath11k_a_rates_size;
5969 band->bitrates = ath11k_a_rates;
5970 ar->hw->wiphy->bands[NL80211_BAND_6GHZ] = band;
5971 ath11k_mac_update_ch_list(ar, band,
5972 reg_cap->low_5ghz_chan,
5973 reg_cap->high_5ghz_chan);
5976 if (reg_cap->low_5ghz_chan < ATH11K_MIN_6G_FREQ) {
5977 channels = kmemdup(ath11k_5ghz_channels,
5978 sizeof(ath11k_5ghz_channels),
5981 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
5982 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
5986 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
5987 band->band = NL80211_BAND_5GHZ;
5988 band->n_channels = ARRAY_SIZE(ath11k_5ghz_channels);
5989 band->channels = channels;
5990 band->n_bitrates = ath11k_a_rates_size;
5991 band->bitrates = ath11k_a_rates;
5992 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
5994 if (ar->ab->hw_params.single_pdev_only) {
5995 phy_id = ath11k_get_phy_id(ar, WMI_HOST_WLAN_5G_CAP);
5996 reg_cap = &ar->ab->hal_reg_cap[phy_id];
5999 ath11k_mac_update_ch_list(ar, band,
6000 reg_cap->low_5ghz_chan,
6001 reg_cap->high_5ghz_chan);
6008 static int ath11k_mac_setup_iface_combinations(struct ath11k *ar)
6010 struct ath11k_base *ab = ar->ab;
6011 struct ieee80211_iface_combination *combinations;
6012 struct ieee80211_iface_limit *limits;
6015 combinations = kzalloc(sizeof(*combinations), GFP_KERNEL);
6021 limits = kcalloc(n_limits, sizeof(*limits), GFP_KERNEL);
6026 limits[0].types |= BIT(NL80211_IFTYPE_STATION);
6029 limits[1].types |= BIT(NL80211_IFTYPE_AP);
6031 if (IS_ENABLED(CONFIG_MAC80211_MESH) &&
6032 ab->hw_params.interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
6033 limits[1].types |= BIT(NL80211_IFTYPE_MESH_POINT);
6035 combinations[0].limits = limits;
6036 combinations[0].n_limits = n_limits;
6037 combinations[0].max_interfaces = 16;
6038 combinations[0].num_different_channels = 1;
6039 combinations[0].beacon_int_infra_match = true;
6040 combinations[0].beacon_int_min_gcd = 100;
6041 combinations[0].radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
6042 BIT(NL80211_CHAN_WIDTH_20) |
6043 BIT(NL80211_CHAN_WIDTH_40) |
6044 BIT(NL80211_CHAN_WIDTH_80);
6046 ar->hw->wiphy->iface_combinations = combinations;
6047 ar->hw->wiphy->n_iface_combinations = 1;
6052 static const u8 ath11k_if_types_ext_capa[] = {
6053 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
6054 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
6057 static const u8 ath11k_if_types_ext_capa_sta[] = {
6058 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
6059 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
6060 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
6063 static const u8 ath11k_if_types_ext_capa_ap[] = {
6064 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
6065 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
6066 [9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT,
6069 static const struct wiphy_iftype_ext_capab ath11k_iftypes_ext_capa[] = {
6071 .extended_capabilities = ath11k_if_types_ext_capa,
6072 .extended_capabilities_mask = ath11k_if_types_ext_capa,
6073 .extended_capabilities_len = sizeof(ath11k_if_types_ext_capa),
6075 .iftype = NL80211_IFTYPE_STATION,
6076 .extended_capabilities = ath11k_if_types_ext_capa_sta,
6077 .extended_capabilities_mask = ath11k_if_types_ext_capa_sta,
6078 .extended_capabilities_len =
6079 sizeof(ath11k_if_types_ext_capa_sta),
6081 .iftype = NL80211_IFTYPE_AP,
6082 .extended_capabilities = ath11k_if_types_ext_capa_ap,
6083 .extended_capabilities_mask = ath11k_if_types_ext_capa_ap,
6084 .extended_capabilities_len =
6085 sizeof(ath11k_if_types_ext_capa_ap),
6089 static void __ath11k_mac_unregister(struct ath11k *ar)
6091 cancel_work_sync(&ar->regd_update_work);
6093 ieee80211_unregister_hw(ar->hw);
6095 idr_for_each(&ar->txmgmt_idr, ath11k_mac_tx_mgmt_pending_free, ar);
6096 idr_destroy(&ar->txmgmt_idr);
6098 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
6099 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
6100 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
6102 kfree(ar->hw->wiphy->iface_combinations[0].limits);
6103 kfree(ar->hw->wiphy->iface_combinations);
6105 SET_IEEE80211_DEV(ar->hw, NULL);
6108 void ath11k_mac_unregister(struct ath11k_base *ab)
6111 struct ath11k_pdev *pdev;
6114 for (i = 0; i < ab->num_radios; i++) {
6115 pdev = &ab->pdevs[i];
6120 __ath11k_mac_unregister(ar);
6124 static int __ath11k_mac_register(struct ath11k *ar)
6126 struct ath11k_base *ab = ar->ab;
6127 struct ath11k_pdev_cap *cap = &ar->pdev->cap;
6128 static const u32 cipher_suites[] = {
6129 WLAN_CIPHER_SUITE_TKIP,
6130 WLAN_CIPHER_SUITE_CCMP,
6131 WLAN_CIPHER_SUITE_AES_CMAC,
6132 WLAN_CIPHER_SUITE_BIP_CMAC_256,
6133 WLAN_CIPHER_SUITE_BIP_GMAC_128,
6134 WLAN_CIPHER_SUITE_BIP_GMAC_256,
6135 WLAN_CIPHER_SUITE_GCMP,
6136 WLAN_CIPHER_SUITE_GCMP_256,
6137 WLAN_CIPHER_SUITE_CCMP_256,
6142 ath11k_pdev_caps_update(ar);
6144 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
6146 SET_IEEE80211_DEV(ar->hw, ab->dev);
6148 ret = ath11k_mac_setup_channels_rates(ar,
6149 cap->supported_bands);
6153 ath11k_mac_setup_ht_vht_cap(ar, cap, &ht_cap);
6154 ath11k_mac_setup_he_cap(ar, cap);
6156 ret = ath11k_mac_setup_iface_combinations(ar);
6158 ath11k_err(ar->ab, "failed to setup interface combinations: %d\n", ret);
6159 goto err_free_channels;
6162 ar->hw->wiphy->available_antennas_rx = cap->rx_chain_mask;
6163 ar->hw->wiphy->available_antennas_tx = cap->tx_chain_mask;
6165 ar->hw->wiphy->interface_modes = ab->hw_params.interface_modes;
6167 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
6168 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
6169 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
6170 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
6171 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
6172 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
6173 ieee80211_hw_set(ar->hw, AP_LINK_PS);
6174 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
6175 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
6176 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
6177 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
6178 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
6179 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
6180 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
6181 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
6182 ieee80211_hw_set(ar->hw, SUPPORTS_TX_ENCAP_OFFLOAD);
6183 if (ht_cap & WMI_HT_CAP_ENABLED) {
6184 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
6185 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
6186 ieee80211_hw_set(ar->hw, SUPPORTS_REORDERING_BUFFER);
6187 ieee80211_hw_set(ar->hw, SUPPORTS_AMSDU_IN_AMPDU);
6188 ieee80211_hw_set(ar->hw, USES_RSS);
6191 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6192 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
6194 /* TODO: Check if HT capability advertised from firmware is different
6195 * for each band for a dual band capable radio. It will be tricky to
6196 * handle it when the ht capability different for each band.
6198 if (ht_cap & WMI_HT_CAP_DYNAMIC_SMPS)
6199 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
6201 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6202 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6204 ar->hw->max_listen_interval = ATH11K_MAX_HW_LISTEN_INTERVAL;
6206 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
6207 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
6208 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6210 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
6211 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
6212 NL80211_FEATURE_AP_SCAN;
6214 ar->max_num_stations = TARGET_NUM_STATIONS;
6215 ar->max_num_peers = TARGET_NUM_PEERS_PDEV;
6217 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6219 ar->hw->queues = ATH11K_HW_MAX_QUEUES;
6220 ar->hw->wiphy->tx_queue_len = ATH11K_QUEUE_LEN;
6221 ar->hw->offchannel_tx_hw_queue = ATH11K_HW_MAX_QUEUES - 1;
6222 ar->hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
6224 ar->hw->vif_data_size = sizeof(struct ath11k_vif);
6225 ar->hw->sta_data_size = sizeof(struct ath11k_sta);
6227 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
6228 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_STA_TX_PWR);
6230 ar->hw->wiphy->cipher_suites = cipher_suites;
6231 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6233 ar->hw->wiphy->iftype_ext_capab = ath11k_iftypes_ext_capa;
6234 ar->hw->wiphy->num_iftype_ext_capab =
6235 ARRAY_SIZE(ath11k_iftypes_ext_capa);
6237 ath11k_reg_init(ar);
6239 if (!test_bit(ATH11K_FLAG_RAW_MODE, &ab->dev_flags)) {
6240 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6241 ieee80211_hw_set(ar->hw, SW_CRYPTO_CONTROL);
6242 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
6245 ret = ieee80211_register_hw(ar->hw);
6247 ath11k_err(ar->ab, "ieee80211 registration failed: %d\n", ret);
6248 goto err_free_if_combs;
6251 /* Apply the regd received during initialization */
6252 ret = ath11k_regd_update(ar, true);
6254 ath11k_err(ar->ab, "ath11k regd update failed: %d\n", ret);
6255 goto err_free_if_combs;
6258 ret = ath11k_debugfs_register(ar);
6260 ath11k_err(ar->ab, "debugfs registration failed: %d\n", ret);
6261 goto err_free_if_combs;
6267 kfree(ar->hw->wiphy->iface_combinations[0].limits);
6268 kfree(ar->hw->wiphy->iface_combinations);
6271 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
6272 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
6273 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
6276 SET_IEEE80211_DEV(ar->hw, NULL);
6280 int ath11k_mac_register(struct ath11k_base *ab)
6283 struct ath11k_pdev *pdev;
6287 if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags))
6290 for (i = 0; i < ab->num_radios; i++) {
6291 pdev = &ab->pdevs[i];
6293 if (ab->pdevs_macaddr_valid) {
6294 ether_addr_copy(ar->mac_addr, pdev->mac_addr);
6296 ether_addr_copy(ar->mac_addr, ab->mac_addr);
6297 ar->mac_addr[4] += i;
6300 ret = __ath11k_mac_register(ar);
6304 idr_init(&ar->txmgmt_idr);
6305 spin_lock_init(&ar->txmgmt_idr_lock);
6308 /* Initialize channel counters frequency value in hertz */
6309 ab->cc_freq_hz = IPQ8074_CC_FREQ_HERTZ;
6310 ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS)) - 1;
6315 for (i = i - 1; i >= 0; i--) {
6316 pdev = &ab->pdevs[i];
6318 __ath11k_mac_unregister(ar);
6324 int ath11k_mac_allocate(struct ath11k_base *ab)
6326 struct ieee80211_hw *hw;
6328 struct ath11k_pdev *pdev;
6332 if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags))
6335 for (i = 0; i < ab->num_radios; i++) {
6336 pdev = &ab->pdevs[i];
6337 hw = ieee80211_alloc_hw(sizeof(struct ath11k), &ath11k_ops);
6339 ath11k_warn(ab, "failed to allocate mac80211 hw device\n");
6349 ar->lmac_id = ath11k_hw_get_mac_from_pdev_id(&ab->hw_params, i);
6351 ar->wmi = &ab->wmi_ab.wmi[i];
6352 /* FIXME wmi[0] is already initialized during attach,
6353 * Should we do this again?
6355 ath11k_wmi_pdev_attach(ab, i);
6357 ar->cfg_tx_chainmask = pdev->cap.tx_chain_mask;
6358 ar->cfg_rx_chainmask = pdev->cap.rx_chain_mask;
6359 ar->num_tx_chains = get_num_chains(pdev->cap.tx_chain_mask);
6360 ar->num_rx_chains = get_num_chains(pdev->cap.rx_chain_mask);
6363 spin_lock_init(&ar->data_lock);
6364 INIT_LIST_HEAD(&ar->arvifs);
6365 INIT_LIST_HEAD(&ar->ppdu_stats_info);
6366 mutex_init(&ar->conf_mutex);
6367 init_completion(&ar->vdev_setup_done);
6368 init_completion(&ar->peer_assoc_done);
6369 init_completion(&ar->install_key_done);
6370 init_completion(&ar->bss_survey_done);
6371 init_completion(&ar->scan.started);
6372 init_completion(&ar->scan.completed);
6373 init_completion(&ar->thermal.wmi_sync);
6375 INIT_DELAYED_WORK(&ar->scan.timeout, ath11k_scan_timeout_work);
6376 INIT_WORK(&ar->regd_update_work, ath11k_regd_update_work);
6378 INIT_WORK(&ar->wmi_mgmt_tx_work, ath11k_mgmt_over_wmi_tx_work);
6379 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
6380 clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags);
6386 ath11k_mac_destroy(ab);
6391 void ath11k_mac_destroy(struct ath11k_base *ab)
6394 struct ath11k_pdev *pdev;
6397 for (i = 0; i < ab->num_radios; i++) {
6398 pdev = &ab->pdevs[i];
6403 ieee80211_free_hw(ar->hw);