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>
18 #define CHAN2G(_channel, _freq, _flags) { \
19 .band = NL80211_BAND_2GHZ, \
20 .hw_value = (_channel), \
21 .center_freq = (_freq), \
23 .max_antenna_gain = 0, \
27 #define CHAN5G(_channel, _freq, _flags) { \
28 .band = NL80211_BAND_5GHZ, \
29 .hw_value = (_channel), \
30 .center_freq = (_freq), \
32 .max_antenna_gain = 0, \
36 #define CHAN6G(_channel, _freq, _flags) { \
37 .band = NL80211_BAND_6GHZ, \
38 .hw_value = (_channel), \
39 .center_freq = (_freq), \
41 .max_antenna_gain = 0, \
45 /* frame mode values are mapped as per enum ath11k_hw_txrx_mode */
46 static unsigned int ath11k_frame_mode = ATH11K_HW_TXRX_NATIVE_WIFI;
47 module_param_named(frame_mode, ath11k_frame_mode, uint, 0644);
48 MODULE_PARM_DESC(frame_mode,
49 "Datapath frame mode (0: raw, 1: native wifi (default), 2: ethernet)");
51 static const struct ieee80211_channel ath11k_2ghz_channels[] = {
68 static const struct ieee80211_channel ath11k_5ghz_channels[] = {
98 static const struct ieee80211_channel ath11k_6ghz_channels[] = {
124 CHAN6G(101, 6455, 0),
125 CHAN6G(105, 6475, 0),
126 CHAN6G(109, 6495, 0),
127 CHAN6G(113, 6515, 0),
128 CHAN6G(117, 6535, 0),
129 CHAN6G(121, 6555, 0),
130 CHAN6G(125, 6575, 0),
131 CHAN6G(129, 6595, 0),
132 CHAN6G(133, 6615, 0),
133 CHAN6G(137, 6635, 0),
134 CHAN6G(141, 6655, 0),
135 CHAN6G(145, 6675, 0),
136 CHAN6G(149, 6695, 0),
137 CHAN6G(153, 6715, 0),
138 CHAN6G(157, 6735, 0),
139 CHAN6G(161, 6755, 0),
140 CHAN6G(165, 6775, 0),
141 CHAN6G(169, 6795, 0),
142 CHAN6G(173, 6815, 0),
143 CHAN6G(177, 6835, 0),
144 CHAN6G(181, 6855, 0),
145 CHAN6G(185, 6875, 0),
146 CHAN6G(189, 6895, 0),
147 CHAN6G(193, 6915, 0),
148 CHAN6G(197, 6935, 0),
149 CHAN6G(201, 6955, 0),
150 CHAN6G(205, 6975, 0),
151 CHAN6G(209, 6995, 0),
152 CHAN6G(213, 7015, 0),
153 CHAN6G(217, 7035, 0),
154 CHAN6G(221, 7055, 0),
155 CHAN6G(225, 7075, 0),
156 CHAN6G(229, 7095, 0),
157 CHAN6G(233, 7115, 0),
160 static struct ieee80211_rate ath11k_legacy_rates[] = {
162 .hw_value = ATH11K_HW_RATE_CCK_LP_1M },
164 .hw_value = ATH11K_HW_RATE_CCK_LP_2M,
165 .hw_value_short = ATH11K_HW_RATE_CCK_SP_2M,
166 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
168 .hw_value = ATH11K_HW_RATE_CCK_LP_5_5M,
169 .hw_value_short = ATH11K_HW_RATE_CCK_SP_5_5M,
170 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
172 .hw_value = ATH11K_HW_RATE_CCK_LP_11M,
173 .hw_value_short = ATH11K_HW_RATE_CCK_SP_11M,
174 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
176 { .bitrate = 60, .hw_value = ATH11K_HW_RATE_OFDM_6M },
177 { .bitrate = 90, .hw_value = ATH11K_HW_RATE_OFDM_9M },
178 { .bitrate = 120, .hw_value = ATH11K_HW_RATE_OFDM_12M },
179 { .bitrate = 180, .hw_value = ATH11K_HW_RATE_OFDM_18M },
180 { .bitrate = 240, .hw_value = ATH11K_HW_RATE_OFDM_24M },
181 { .bitrate = 360, .hw_value = ATH11K_HW_RATE_OFDM_36M },
182 { .bitrate = 480, .hw_value = ATH11K_HW_RATE_OFDM_48M },
183 { .bitrate = 540, .hw_value = ATH11K_HW_RATE_OFDM_54M },
187 ath11k_phymodes[NUM_NL80211_BANDS][ATH11K_CHAN_WIDTH_NUM] = {
188 [NL80211_BAND_2GHZ] = {
189 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
190 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
191 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20_2G,
192 [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20_2G,
193 [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40_2G,
194 [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80_2G,
195 [NL80211_CHAN_WIDTH_80P80] = MODE_UNKNOWN,
196 [NL80211_CHAN_WIDTH_160] = MODE_UNKNOWN,
198 [NL80211_BAND_5GHZ] = {
199 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
200 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
201 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20,
202 [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20,
203 [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40,
204 [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80,
205 [NL80211_CHAN_WIDTH_160] = MODE_11AX_HE160,
206 [NL80211_CHAN_WIDTH_80P80] = MODE_11AX_HE80_80,
208 [NL80211_BAND_6GHZ] = {
209 [NL80211_CHAN_WIDTH_5] = MODE_UNKNOWN,
210 [NL80211_CHAN_WIDTH_10] = MODE_UNKNOWN,
211 [NL80211_CHAN_WIDTH_20_NOHT] = MODE_11AX_HE20,
212 [NL80211_CHAN_WIDTH_20] = MODE_11AX_HE20,
213 [NL80211_CHAN_WIDTH_40] = MODE_11AX_HE40,
214 [NL80211_CHAN_WIDTH_80] = MODE_11AX_HE80,
215 [NL80211_CHAN_WIDTH_160] = MODE_11AX_HE160,
216 [NL80211_CHAN_WIDTH_80P80] = MODE_11AX_HE80_80,
221 const struct htt_rx_ring_tlv_filter ath11k_mac_mon_status_filter_default = {
222 .rx_filter = HTT_RX_FILTER_TLV_FLAGS_MPDU_START |
223 HTT_RX_FILTER_TLV_FLAGS_PPDU_END |
224 HTT_RX_FILTER_TLV_FLAGS_PPDU_END_STATUS_DONE,
225 .pkt_filter_flags0 = HTT_RX_FP_MGMT_FILTER_FLAGS0,
226 .pkt_filter_flags1 = HTT_RX_FP_MGMT_FILTER_FLAGS1,
227 .pkt_filter_flags2 = HTT_RX_FP_CTRL_FILTER_FLASG2,
228 .pkt_filter_flags3 = HTT_RX_FP_DATA_FILTER_FLASG3 |
229 HTT_RX_FP_CTRL_FILTER_FLASG3
232 #define ATH11K_MAC_FIRST_OFDM_RATE_IDX 4
233 #define ath11k_g_rates ath11k_legacy_rates
234 #define ath11k_g_rates_size (ARRAY_SIZE(ath11k_legacy_rates))
235 #define ath11k_a_rates (ath11k_legacy_rates + 4)
236 #define ath11k_a_rates_size (ARRAY_SIZE(ath11k_legacy_rates) - 4)
238 #define ATH11K_MAC_SCAN_TIMEOUT_MSECS 200 /* in msecs */
240 static const u32 ath11k_smps_map[] = {
241 [WLAN_HT_CAP_SM_PS_STATIC] = WMI_PEER_SMPS_STATIC,
242 [WLAN_HT_CAP_SM_PS_DYNAMIC] = WMI_PEER_SMPS_DYNAMIC,
243 [WLAN_HT_CAP_SM_PS_INVALID] = WMI_PEER_SMPS_PS_NONE,
244 [WLAN_HT_CAP_SM_PS_DISABLED] = WMI_PEER_SMPS_PS_NONE,
247 u8 ath11k_mac_bw_to_mac80211_bw(u8 bw)
253 ret = RATE_INFO_BW_20;
256 ret = RATE_INFO_BW_40;
259 ret = RATE_INFO_BW_80;
262 ret = RATE_INFO_BW_160;
269 enum ath11k_supported_bw ath11k_mac_mac80211_bw_to_ath11k_bw(enum rate_info_bw bw)
272 case RATE_INFO_BW_20:
274 case RATE_INFO_BW_40:
276 case RATE_INFO_BW_80:
278 case RATE_INFO_BW_160:
279 return ATH11K_BW_160;
285 int ath11k_mac_hw_ratecode_to_legacy_rate(u8 hw_rc, u8 preamble, u8 *rateidx,
288 /* As default, it is OFDM rates */
289 int i = ATH11K_MAC_FIRST_OFDM_RATE_IDX;
290 int max_rates_idx = ath11k_g_rates_size;
292 if (preamble == WMI_RATE_PREAMBLE_CCK) {
293 hw_rc &= ~ATH11k_HW_RATECODE_CCK_SHORT_PREAM_MASK;
295 max_rates_idx = ATH11K_MAC_FIRST_OFDM_RATE_IDX;
298 while (i < max_rates_idx) {
299 if (hw_rc == ath11k_legacy_rates[i].hw_value) {
301 *rate = ath11k_legacy_rates[i].bitrate;
310 static int get_num_chains(u32 mask)
323 u8 ath11k_mac_bitrate_to_idx(const struct ieee80211_supported_band *sband,
328 for (i = 0; i < sband->n_bitrates; i++)
329 if (sband->bitrates[i].bitrate == bitrate)
336 ath11k_mac_max_ht_nss(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
340 for (nss = IEEE80211_HT_MCS_MASK_LEN - 1; nss >= 0; nss--)
341 if (ht_mcs_mask[nss])
348 ath11k_mac_max_vht_nss(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
352 for (nss = NL80211_VHT_NSS_MAX - 1; nss >= 0; nss--)
353 if (vht_mcs_mask[nss])
359 static u8 ath11k_parse_mpdudensity(u8 mpdudensity)
361 /* 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
362 * 0 for no restriction
371 switch (mpdudensity) {
377 /* Our lower layer calculations limit our precision to
394 static int ath11k_mac_vif_chan(struct ieee80211_vif *vif,
395 struct cfg80211_chan_def *def)
397 struct ieee80211_chanctx_conf *conf;
400 conf = rcu_dereference(vif->chanctx_conf);
412 static bool ath11k_mac_bitrate_is_cck(int bitrate)
425 u8 ath11k_mac_hw_rate_to_idx(const struct ieee80211_supported_band *sband,
426 u8 hw_rate, bool cck)
428 const struct ieee80211_rate *rate;
431 for (i = 0; i < sband->n_bitrates; i++) {
432 rate = &sband->bitrates[i];
434 if (ath11k_mac_bitrate_is_cck(rate->bitrate) != cck)
437 if (rate->hw_value == hw_rate)
439 else if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE &&
440 rate->hw_value_short == hw_rate)
447 static u8 ath11k_mac_bitrate_to_rate(int bitrate)
449 return DIV_ROUND_UP(bitrate, 5) |
450 (ath11k_mac_bitrate_is_cck(bitrate) ? BIT(7) : 0);
453 static void ath11k_get_arvif_iter(void *data, u8 *mac,
454 struct ieee80211_vif *vif)
456 struct ath11k_vif_iter *arvif_iter = data;
457 struct ath11k_vif *arvif = (void *)vif->drv_priv;
459 if (arvif->vdev_id == arvif_iter->vdev_id)
460 arvif_iter->arvif = arvif;
463 struct ath11k_vif *ath11k_mac_get_arvif(struct ath11k *ar, u32 vdev_id)
465 struct ath11k_vif_iter arvif_iter;
468 memset(&arvif_iter, 0, sizeof(struct ath11k_vif_iter));
469 arvif_iter.vdev_id = vdev_id;
471 flags = IEEE80211_IFACE_ITER_RESUME_ALL;
472 ieee80211_iterate_active_interfaces_atomic(ar->hw,
474 ath11k_get_arvif_iter,
476 if (!arvif_iter.arvif) {
477 ath11k_warn(ar->ab, "No VIF found for vdev %d\n", vdev_id);
481 return arvif_iter.arvif;
484 struct ath11k_vif *ath11k_mac_get_arvif_by_vdev_id(struct ath11k_base *ab,
488 struct ath11k_pdev *pdev;
489 struct ath11k_vif *arvif;
491 for (i = 0; i < ab->num_radios; i++) {
492 pdev = rcu_dereference(ab->pdevs_active[i]);
493 if (pdev && pdev->ar) {
494 arvif = ath11k_mac_get_arvif(pdev->ar, vdev_id);
503 struct ath11k *ath11k_mac_get_ar_by_vdev_id(struct ath11k_base *ab, u32 vdev_id)
506 struct ath11k_pdev *pdev;
508 for (i = 0; i < ab->num_radios; i++) {
509 pdev = rcu_dereference(ab->pdevs_active[i]);
510 if (pdev && pdev->ar) {
511 if (pdev->ar->allocated_vdev_map & (1LL << vdev_id))
519 struct ath11k *ath11k_mac_get_ar_by_pdev_id(struct ath11k_base *ab, u32 pdev_id)
522 struct ath11k_pdev *pdev;
524 if (WARN_ON(pdev_id > ab->num_radios))
527 for (i = 0; i < ab->num_radios; i++) {
528 pdev = rcu_dereference(ab->pdevs_active[i]);
530 if (pdev && pdev->pdev_id == pdev_id)
531 return (pdev->ar ? pdev->ar : NULL);
537 struct ath11k *ath11k_mac_get_ar_vdev_stop_status(struct ath11k_base *ab,
541 struct ath11k_pdev *pdev;
544 for (i = 0; i < ab->num_radios; i++) {
545 pdev = rcu_dereference(ab->pdevs_active[i]);
546 if (pdev && pdev->ar) {
549 spin_lock_bh(&ar->data_lock);
550 if (ar->vdev_stop_status.stop_in_progress &&
551 ar->vdev_stop_status.vdev_id == vdev_id) {
552 ar->vdev_stop_status.stop_in_progress = false;
553 spin_unlock_bh(&ar->data_lock);
556 spin_unlock_bh(&ar->data_lock);
562 static void ath11k_pdev_caps_update(struct ath11k *ar)
564 struct ath11k_base *ab = ar->ab;
566 ar->max_tx_power = ab->target_caps.hw_max_tx_power;
568 /* FIXME Set min_tx_power to ab->target_caps.hw_min_tx_power.
569 * But since the received value in svcrdy is same as hw_max_tx_power,
570 * we can set ar->min_tx_power to 0 currently until
571 * this is fixed in firmware
573 ar->min_tx_power = 0;
575 ar->txpower_limit_2g = ar->max_tx_power;
576 ar->txpower_limit_5g = ar->max_tx_power;
577 ar->txpower_scale = WMI_HOST_TP_SCALE_MAX;
580 static int ath11k_mac_txpower_recalc(struct ath11k *ar)
582 struct ath11k_pdev *pdev = ar->pdev;
583 struct ath11k_vif *arvif;
584 int ret, txpower = -1;
587 lockdep_assert_held(&ar->conf_mutex);
589 list_for_each_entry(arvif, &ar->arvifs, list) {
590 if (arvif->txpower <= 0)
594 txpower = arvif->txpower;
596 txpower = min(txpower, arvif->txpower);
602 /* txpwr is set as 2 units per dBm in FW*/
603 txpower = min_t(u32, max_t(u32, ar->min_tx_power, txpower),
604 ar->max_tx_power) * 2;
606 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "txpower to set in hw %d\n",
609 if ((pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) &&
610 ar->txpower_limit_2g != txpower) {
611 param = WMI_PDEV_PARAM_TXPOWER_LIMIT2G;
612 ret = ath11k_wmi_pdev_set_param(ar, param,
613 txpower, ar->pdev->pdev_id);
616 ar->txpower_limit_2g = txpower;
619 if ((pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) &&
620 ar->txpower_limit_5g != txpower) {
621 param = WMI_PDEV_PARAM_TXPOWER_LIMIT5G;
622 ret = ath11k_wmi_pdev_set_param(ar, param,
623 txpower, ar->pdev->pdev_id);
626 ar->txpower_limit_5g = txpower;
632 ath11k_warn(ar->ab, "failed to recalc txpower limit %d using pdev param %d: %d\n",
633 txpower / 2, param, ret);
637 static int ath11k_recalc_rtscts_prot(struct ath11k_vif *arvif)
639 struct ath11k *ar = arvif->ar;
640 u32 vdev_param, rts_cts = 0;
643 lockdep_assert_held(&ar->conf_mutex);
645 vdev_param = WMI_VDEV_PARAM_ENABLE_RTSCTS;
647 /* Enable RTS/CTS protection for sw retries (when legacy stations
648 * are in BSS) or by default only for second rate series.
649 * TODO: Check if we need to enable CTS 2 Self in any case
651 rts_cts = WMI_USE_RTS_CTS;
653 if (arvif->num_legacy_stations > 0)
654 rts_cts |= WMI_RTSCTS_ACROSS_SW_RETRIES << 4;
656 rts_cts |= WMI_RTSCTS_FOR_SECOND_RATESERIES << 4;
658 /* Need not send duplicate param value to firmware */
659 if (arvif->rtscts_prot_mode == rts_cts)
662 arvif->rtscts_prot_mode = rts_cts;
664 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d recalc rts/cts prot %d\n",
665 arvif->vdev_id, rts_cts);
667 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
668 vdev_param, rts_cts);
670 ath11k_warn(ar->ab, "failed to recalculate rts/cts prot for vdev %d: %d\n",
671 arvif->vdev_id, ret);
676 static int ath11k_mac_set_kickout(struct ath11k_vif *arvif)
678 struct ath11k *ar = arvif->ar;
682 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_STA_KICKOUT_TH,
683 ATH11K_KICKOUT_THRESHOLD,
686 ath11k_warn(ar->ab, "failed to set kickout threshold on vdev %i: %d\n",
687 arvif->vdev_id, ret);
691 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MIN_IDLE_INACTIVE_TIME_SECS;
692 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
693 ATH11K_KEEPALIVE_MIN_IDLE);
695 ath11k_warn(ar->ab, "failed to set keepalive minimum idle time on vdev %i: %d\n",
696 arvif->vdev_id, ret);
700 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_IDLE_INACTIVE_TIME_SECS;
701 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
702 ATH11K_KEEPALIVE_MAX_IDLE);
704 ath11k_warn(ar->ab, "failed to set keepalive maximum idle time on vdev %i: %d\n",
705 arvif->vdev_id, ret);
709 param = WMI_VDEV_PARAM_AP_KEEPALIVE_MAX_UNRESPONSIVE_TIME_SECS;
710 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, param,
711 ATH11K_KEEPALIVE_MAX_UNRESPONSIVE);
713 ath11k_warn(ar->ab, "failed to set keepalive maximum unresponsive time on vdev %i: %d\n",
714 arvif->vdev_id, ret);
721 void ath11k_mac_peer_cleanup_all(struct ath11k *ar)
723 struct ath11k_peer *peer, *tmp;
724 struct ath11k_base *ab = ar->ab;
726 lockdep_assert_held(&ar->conf_mutex);
728 spin_lock_bh(&ab->base_lock);
729 list_for_each_entry_safe(peer, tmp, &ab->peers, list) {
730 ath11k_peer_rx_tid_cleanup(ar, peer);
731 list_del(&peer->list);
734 spin_unlock_bh(&ab->base_lock);
737 ar->num_stations = 0;
740 static int ath11k_monitor_vdev_up(struct ath11k *ar, int vdev_id)
744 ret = ath11k_wmi_vdev_up(ar, vdev_id, 0, ar->mac_addr);
746 ath11k_warn(ar->ab, "failed to put up monitor vdev %i: %d\n",
751 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac monitor vdev %i started\n",
756 static int ath11k_mac_op_config(struct ieee80211_hw *hw, u32 changed)
758 struct ath11k *ar = hw->priv;
761 /* mac80211 requires this op to be present and that's why
762 * there's an empty function, this can be extended when
766 mutex_lock(&ar->conf_mutex);
768 /* TODO: Handle configuration changes as appropriate */
770 mutex_unlock(&ar->conf_mutex);
775 static int ath11k_mac_setup_bcn_tmpl(struct ath11k_vif *arvif)
777 struct ath11k *ar = arvif->ar;
778 struct ath11k_base *ab = ar->ab;
779 struct ieee80211_hw *hw = ar->hw;
780 struct ieee80211_vif *vif = arvif->vif;
781 struct ieee80211_mutable_offsets offs = {};
783 struct ieee80211_mgmt *mgmt;
787 if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
790 bcn = ieee80211_beacon_get_template(hw, vif, &offs);
792 ath11k_warn(ab, "failed to get beacon template from mac80211\n");
796 ies = bcn->data + ieee80211_get_hdrlen_from_skb(bcn);
797 ies += sizeof(mgmt->u.beacon);
799 if (cfg80211_find_ie(WLAN_EID_RSN, ies, (skb_tail_pointer(bcn) - ies)))
800 arvif->rsnie_present = true;
802 if (cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
803 WLAN_OUI_TYPE_MICROSOFT_WPA,
804 ies, (skb_tail_pointer(bcn) - ies)))
805 arvif->wpaie_present = true;
807 ret = ath11k_wmi_bcn_tmpl(ar, arvif->vdev_id, &offs, bcn);
812 ath11k_warn(ab, "failed to submit beacon template command: %d\n",
818 static void ath11k_control_beaconing(struct ath11k_vif *arvif,
819 struct ieee80211_bss_conf *info)
821 struct ath11k *ar = arvif->ar;
824 lockdep_assert_held(&arvif->ar->conf_mutex);
826 if (!info->enable_beacon) {
827 ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id);
829 ath11k_warn(ar->ab, "failed to down vdev_id %i: %d\n",
830 arvif->vdev_id, ret);
832 arvif->is_up = false;
836 /* Install the beacon template to the FW */
837 ret = ath11k_mac_setup_bcn_tmpl(arvif);
839 ath11k_warn(ar->ab, "failed to update bcn tmpl during vdev up: %d\n",
844 arvif->tx_seq_no = 0x1000;
848 ether_addr_copy(arvif->bssid, info->bssid);
850 ret = ath11k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
853 ath11k_warn(ar->ab, "failed to bring up vdev %d: %i\n",
854 arvif->vdev_id, ret);
860 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %d up\n", arvif->vdev_id);
863 static void ath11k_peer_assoc_h_basic(struct ath11k *ar,
864 struct ieee80211_vif *vif,
865 struct ieee80211_sta *sta,
866 struct peer_assoc_params *arg)
868 struct ath11k_vif *arvif = (void *)vif->drv_priv;
871 lockdep_assert_held(&ar->conf_mutex);
873 if (vif->type == NL80211_IFTYPE_STATION)
874 aid = vif->bss_conf.aid;
878 ether_addr_copy(arg->peer_mac, sta->addr);
879 arg->vdev_id = arvif->vdev_id;
880 arg->peer_associd = aid;
881 arg->auth_flag = true;
882 /* TODO: STA WAR in ath10k for listen interval required? */
883 arg->peer_listen_intval = ar->hw->conf.listen_interval;
885 arg->peer_caps = vif->bss_conf.assoc_capability;
888 static void ath11k_peer_assoc_h_crypto(struct ath11k *ar,
889 struct ieee80211_vif *vif,
890 struct ieee80211_sta *sta,
891 struct peer_assoc_params *arg)
893 struct ieee80211_bss_conf *info = &vif->bss_conf;
894 struct cfg80211_chan_def def;
895 struct cfg80211_bss *bss;
896 struct ath11k_vif *arvif = (struct ath11k_vif *)vif->drv_priv;
897 const u8 *rsnie = NULL;
898 const u8 *wpaie = NULL;
900 lockdep_assert_held(&ar->conf_mutex);
902 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
905 bss = cfg80211_get_bss(ar->hw->wiphy, def.chan, info->bssid, NULL, 0,
906 IEEE80211_BSS_TYPE_ANY, IEEE80211_PRIVACY_ANY);
908 if (arvif->rsnie_present || arvif->wpaie_present) {
909 arg->need_ptk_4_way = true;
910 if (arvif->wpaie_present)
911 arg->need_gtk_2_way = true;
913 const struct cfg80211_bss_ies *ies;
916 rsnie = ieee80211_bss_get_ie(bss, WLAN_EID_RSN);
918 ies = rcu_dereference(bss->ies);
920 wpaie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
921 WLAN_OUI_TYPE_MICROSOFT_WPA,
925 cfg80211_put_bss(ar->hw->wiphy, bss);
928 /* FIXME: base on RSN IE/WPA IE is a correct idea? */
929 if (rsnie || wpaie) {
930 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
931 "%s: rsn ie found\n", __func__);
932 arg->need_ptk_4_way = true;
936 ath11k_dbg(ar->ab, ATH11K_DBG_WMI,
937 "%s: wpa ie found\n", __func__);
938 arg->need_gtk_2_way = true;
942 /* TODO: Need to check if FW supports PMF? */
943 arg->is_pmf_enabled = true;
946 /* TODO: safe_mode_enabled (bypass 4-way handshake) flag req? */
949 static void ath11k_peer_assoc_h_rates(struct ath11k *ar,
950 struct ieee80211_vif *vif,
951 struct ieee80211_sta *sta,
952 struct peer_assoc_params *arg)
954 struct ath11k_vif *arvif = (void *)vif->drv_priv;
955 struct wmi_rate_set_arg *rateset = &arg->peer_legacy_rates;
956 struct cfg80211_chan_def def;
957 const struct ieee80211_supported_band *sband;
958 const struct ieee80211_rate *rates;
959 enum nl80211_band band;
964 lockdep_assert_held(&ar->conf_mutex);
966 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
969 band = def.chan->band;
970 sband = ar->hw->wiphy->bands[band];
971 ratemask = sta->supp_rates[band];
972 ratemask &= arvif->bitrate_mask.control[band].legacy;
973 rates = sband->bitrates;
975 rateset->num_rates = 0;
977 for (i = 0; i < 32; i++, ratemask >>= 1, rates++) {
981 rate = ath11k_mac_bitrate_to_rate(rates->bitrate);
982 rateset->rates[rateset->num_rates] = rate;
983 rateset->num_rates++;
988 ath11k_peer_assoc_h_ht_masked(const u8 ht_mcs_mask[IEEE80211_HT_MCS_MASK_LEN])
992 for (nss = 0; nss < IEEE80211_HT_MCS_MASK_LEN; nss++)
993 if (ht_mcs_mask[nss])
1000 ath11k_peer_assoc_h_vht_masked(const u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
1004 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++)
1005 if (vht_mcs_mask[nss])
1011 static void ath11k_peer_assoc_h_ht(struct ath11k *ar,
1012 struct ieee80211_vif *vif,
1013 struct ieee80211_sta *sta,
1014 struct peer_assoc_params *arg)
1016 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1017 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1018 struct cfg80211_chan_def def;
1019 enum nl80211_band band;
1020 const u8 *ht_mcs_mask;
1025 lockdep_assert_held(&ar->conf_mutex);
1027 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1030 if (!ht_cap->ht_supported)
1033 band = def.chan->band;
1034 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
1036 if (ath11k_peer_assoc_h_ht_masked(ht_mcs_mask))
1039 arg->ht_flag = true;
1041 arg->peer_max_mpdu = (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1042 ht_cap->ampdu_factor)) - 1;
1044 arg->peer_mpdu_density =
1045 ath11k_parse_mpdudensity(ht_cap->ampdu_density);
1047 arg->peer_ht_caps = ht_cap->cap;
1048 arg->peer_rate_caps |= WMI_HOST_RC_HT_FLAG;
1050 if (ht_cap->cap & IEEE80211_HT_CAP_LDPC_CODING)
1051 arg->ldpc_flag = true;
1053 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40) {
1055 arg->peer_rate_caps |= WMI_HOST_RC_CW40_FLAG;
1058 if (arvif->bitrate_mask.control[band].gi != NL80211_TXRATE_FORCE_LGI) {
1059 if (ht_cap->cap & (IEEE80211_HT_CAP_SGI_20 |
1060 IEEE80211_HT_CAP_SGI_40))
1061 arg->peer_rate_caps |= WMI_HOST_RC_SGI_FLAG;
1064 if (ht_cap->cap & IEEE80211_HT_CAP_TX_STBC) {
1065 arg->peer_rate_caps |= WMI_HOST_RC_TX_STBC_FLAG;
1066 arg->stbc_flag = true;
1069 if (ht_cap->cap & IEEE80211_HT_CAP_RX_STBC) {
1070 stbc = ht_cap->cap & IEEE80211_HT_CAP_RX_STBC;
1071 stbc = stbc >> IEEE80211_HT_CAP_RX_STBC_SHIFT;
1072 stbc = stbc << WMI_HOST_RC_RX_STBC_FLAG_S;
1073 arg->peer_rate_caps |= stbc;
1074 arg->stbc_flag = true;
1077 if (ht_cap->mcs.rx_mask[1] && ht_cap->mcs.rx_mask[2])
1078 arg->peer_rate_caps |= WMI_HOST_RC_TS_FLAG;
1079 else if (ht_cap->mcs.rx_mask[1])
1080 arg->peer_rate_caps |= WMI_HOST_RC_DS_FLAG;
1082 for (i = 0, n = 0, max_nss = 0; i < IEEE80211_HT_MCS_MASK_LEN * 8; i++)
1083 if ((ht_cap->mcs.rx_mask[i / 8] & BIT(i % 8)) &&
1084 (ht_mcs_mask[i / 8] & BIT(i % 8))) {
1085 max_nss = (i / 8) + 1;
1086 arg->peer_ht_rates.rates[n++] = i;
1089 /* This is a workaround for HT-enabled STAs which break the spec
1090 * and have no HT capabilities RX mask (no HT RX MCS map).
1092 * As per spec, in section 20.3.5 Modulation and coding scheme (MCS),
1093 * MCS 0 through 7 are mandatory in 20MHz with 800 ns GI at all STAs.
1095 * Firmware asserts if such situation occurs.
1098 arg->peer_ht_rates.num_rates = 8;
1099 for (i = 0; i < arg->peer_ht_rates.num_rates; i++)
1100 arg->peer_ht_rates.rates[i] = i;
1102 arg->peer_ht_rates.num_rates = n;
1103 arg->peer_nss = min(sta->rx_nss, max_nss);
1106 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac ht peer %pM mcs cnt %d nss %d\n",
1108 arg->peer_ht_rates.num_rates,
1112 static int ath11k_mac_get_max_vht_mcs_map(u16 mcs_map, int nss)
1114 switch ((mcs_map >> (2 * nss)) & 0x3) {
1115 case IEEE80211_VHT_MCS_SUPPORT_0_7: return BIT(8) - 1;
1116 case IEEE80211_VHT_MCS_SUPPORT_0_8: return BIT(9) - 1;
1117 case IEEE80211_VHT_MCS_SUPPORT_0_9: return BIT(10) - 1;
1123 ath11k_peer_assoc_h_vht_limit(u16 tx_mcs_set,
1124 const u16 vht_mcs_limit[NL80211_VHT_NSS_MAX])
1131 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
1132 mcs_map = ath11k_mac_get_max_vht_mcs_map(tx_mcs_set, nss) &
1136 idx_limit = fls(mcs_map) - 1;
1140 switch (idx_limit) {
1141 case 0: /* fall through */
1142 case 1: /* fall through */
1143 case 2: /* fall through */
1144 case 3: /* fall through */
1145 case 4: /* fall through */
1146 case 5: /* fall through */
1147 case 6: /* fall through */
1149 mcs = IEEE80211_VHT_MCS_SUPPORT_0_7;
1152 mcs = IEEE80211_VHT_MCS_SUPPORT_0_8;
1155 mcs = IEEE80211_VHT_MCS_SUPPORT_0_9;
1161 mcs = IEEE80211_VHT_MCS_NOT_SUPPORTED;
1165 tx_mcs_set &= ~(0x3 << (nss * 2));
1166 tx_mcs_set |= mcs << (nss * 2);
1172 static void ath11k_peer_assoc_h_vht(struct ath11k *ar,
1173 struct ieee80211_vif *vif,
1174 struct ieee80211_sta *sta,
1175 struct peer_assoc_params *arg)
1177 const struct ieee80211_sta_vht_cap *vht_cap = &sta->vht_cap;
1178 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1179 struct cfg80211_chan_def def;
1180 enum nl80211_band band;
1181 const u16 *vht_mcs_mask;
1183 u8 max_nss, vht_mcs;
1186 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1189 if (!vht_cap->vht_supported)
1192 band = def.chan->band;
1193 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
1195 if (ath11k_peer_assoc_h_vht_masked(vht_mcs_mask))
1198 arg->vht_flag = true;
1200 /* TODO: similar flags required? */
1201 arg->vht_capable = true;
1203 if (def.chan->band == NL80211_BAND_2GHZ)
1204 arg->vht_ng_flag = true;
1206 arg->peer_vht_caps = vht_cap->cap;
1208 ampdu_factor = (vht_cap->cap &
1209 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK) >>
1210 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
1212 /* Workaround: Some Netgear/Linksys 11ac APs set Rx A-MPDU factor to
1213 * zero in VHT IE. Using it would result in degraded throughput.
1214 * arg->peer_max_mpdu at this point contains HT max_mpdu so keep
1215 * it if VHT max_mpdu is smaller.
1217 arg->peer_max_mpdu = max(arg->peer_max_mpdu,
1218 (1U << (IEEE80211_HT_MAX_AMPDU_FACTOR +
1219 ampdu_factor)) - 1);
1221 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1224 if (sta->bandwidth == IEEE80211_STA_RX_BW_160)
1227 /* Calculate peer NSS capability from VHT capabilities if STA
1230 for (i = 0, max_nss = 0, vht_mcs = 0; i < NL80211_VHT_NSS_MAX; i++) {
1231 vht_mcs = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map) >>
1234 if (vht_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED &&
1238 arg->peer_nss = min(sta->rx_nss, max_nss);
1239 arg->rx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.rx_highest);
1240 arg->rx_mcs_set = __le16_to_cpu(vht_cap->vht_mcs.rx_mcs_map);
1241 arg->tx_max_rate = __le16_to_cpu(vht_cap->vht_mcs.tx_highest);
1242 arg->tx_mcs_set = ath11k_peer_assoc_h_vht_limit(
1243 __le16_to_cpu(vht_cap->vht_mcs.tx_mcs_map), vht_mcs_mask);
1245 /* In IPQ8074 platform, VHT mcs rate 10 and 11 is enabled by default.
1246 * VHT mcs rate 10 and 11 is not suppoerted in 11ac standard.
1247 * so explicitly disable the VHT MCS rate 10 and 11 in 11ac mode.
1249 arg->tx_mcs_set &= ~IEEE80211_VHT_MCS_SUPPORT_0_11_MASK;
1250 arg->tx_mcs_set |= IEEE80211_DISABLE_VHT_MCS_SUPPORT_0_11;
1252 if ((arg->tx_mcs_set & IEEE80211_VHT_MCS_NOT_SUPPORTED) ==
1253 IEEE80211_VHT_MCS_NOT_SUPPORTED)
1254 arg->peer_vht_caps &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
1257 arg->tx_max_mcs_nss = 0xFF;
1259 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vht peer %pM max_mpdu %d flags 0x%x\n",
1260 sta->addr, arg->peer_max_mpdu, arg->peer_flags);
1262 /* TODO: rxnss_override */
1265 static void ath11k_peer_assoc_h_he(struct ath11k *ar,
1266 struct ieee80211_vif *vif,
1267 struct ieee80211_sta *sta,
1268 struct peer_assoc_params *arg)
1270 const struct ieee80211_sta_he_cap *he_cap = &sta->he_cap;
1273 if (!he_cap->has_he)
1276 arg->he_flag = true;
1278 memcpy(&arg->peer_he_cap_macinfo, he_cap->he_cap_elem.mac_cap_info,
1279 sizeof(arg->peer_he_cap_macinfo));
1280 memcpy(&arg->peer_he_cap_phyinfo, he_cap->he_cap_elem.phy_cap_info,
1281 sizeof(arg->peer_he_cap_phyinfo));
1282 arg->peer_he_ops = vif->bss_conf.he_oper.params;
1284 /* the top most byte is used to indicate BSS color info */
1285 arg->peer_he_ops &= 0xffffff;
1287 if (he_cap->he_cap_elem.phy_cap_info[6] &
1288 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
1292 arg->peer_ppet.numss_m1 = he_cap->ppe_thres[0] &
1293 IEEE80211_PPE_THRES_NSS_MASK;
1294 arg->peer_ppet.ru_bit_mask =
1295 (he_cap->ppe_thres[0] &
1296 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK) >>
1297 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS;
1299 for (nss = 0; nss <= arg->peer_ppet.numss_m1; nss++) {
1300 for (ru = 0; ru < 4; ru++) {
1304 if ((arg->peer_ppet.ru_bit_mask & BIT(ru)) == 0)
1306 for (i = 0; i < 6; i++) {
1308 val |= ((he_cap->ppe_thres[bit / 8] >>
1309 (bit % 8)) & 0x1) << 5;
1312 arg->peer_ppet.ppet16_ppet8_ru3_ru0[nss] |=
1318 if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_RES)
1319 arg->twt_responder = true;
1320 if (he_cap->he_cap_elem.mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_TWT_REQ)
1321 arg->twt_requester = true;
1323 switch (sta->bandwidth) {
1324 case IEEE80211_STA_RX_BW_160:
1325 if (he_cap->he_cap_elem.phy_cap_info[0] &
1326 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) {
1327 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80p80);
1328 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v;
1330 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80p80);
1331 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80_80] = v;
1333 arg->peer_he_mcs_count++;
1335 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_160);
1336 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v;
1338 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_160);
1339 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_160] = v;
1341 arg->peer_he_mcs_count++;
1345 v = le16_to_cpu(he_cap->he_mcs_nss_supp.rx_mcs_80);
1346 arg->peer_he_rx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v;
1348 v = le16_to_cpu(he_cap->he_mcs_nss_supp.tx_mcs_80);
1349 arg->peer_he_tx_mcs_set[WMI_HECAP_TXRX_MCS_NSS_IDX_80] = v;
1351 arg->peer_he_mcs_count++;
1356 static void ath11k_peer_assoc_h_smps(struct ieee80211_sta *sta,
1357 struct peer_assoc_params *arg)
1359 const struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1362 if (!ht_cap->ht_supported)
1365 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1366 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1369 case WLAN_HT_CAP_SM_PS_STATIC:
1370 arg->static_mimops_flag = true;
1372 case WLAN_HT_CAP_SM_PS_DYNAMIC:
1373 arg->dynamic_mimops_flag = true;
1375 case WLAN_HT_CAP_SM_PS_DISABLED:
1376 arg->spatial_mux_flag = true;
1383 static void ath11k_peer_assoc_h_qos(struct ath11k *ar,
1384 struct ieee80211_vif *vif,
1385 struct ieee80211_sta *sta,
1386 struct peer_assoc_params *arg)
1388 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1390 switch (arvif->vdev_type) {
1391 case WMI_VDEV_TYPE_AP:
1393 /* TODO: Check WME vs QoS */
1394 arg->is_wme_set = true;
1395 arg->qos_flag = true;
1398 if (sta->wme && sta->uapsd_queues) {
1399 /* TODO: Check WME vs QoS */
1400 arg->is_wme_set = true;
1401 arg->apsd_flag = true;
1402 arg->peer_rate_caps |= WMI_HOST_RC_UAPSD_FLAG;
1405 case WMI_VDEV_TYPE_STA:
1407 arg->is_wme_set = true;
1408 arg->qos_flag = true;
1415 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac peer %pM qos %d\n",
1416 sta->addr, arg->qos_flag);
1419 static int ath11k_peer_assoc_qos_ap(struct ath11k *ar,
1420 struct ath11k_vif *arvif,
1421 struct ieee80211_sta *sta)
1423 struct ap_ps_params params;
1428 lockdep_assert_held(&ar->conf_mutex);
1430 params.vdev_id = arvif->vdev_id;
1432 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac uapsd_queues 0x%x max_sp %d\n",
1433 sta->uapsd_queues, sta->max_sp);
1436 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
1437 uapsd |= WMI_AP_PS_UAPSD_AC3_DELIVERY_EN |
1438 WMI_AP_PS_UAPSD_AC3_TRIGGER_EN;
1439 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
1440 uapsd |= WMI_AP_PS_UAPSD_AC2_DELIVERY_EN |
1441 WMI_AP_PS_UAPSD_AC2_TRIGGER_EN;
1442 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
1443 uapsd |= WMI_AP_PS_UAPSD_AC1_DELIVERY_EN |
1444 WMI_AP_PS_UAPSD_AC1_TRIGGER_EN;
1445 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
1446 uapsd |= WMI_AP_PS_UAPSD_AC0_DELIVERY_EN |
1447 WMI_AP_PS_UAPSD_AC0_TRIGGER_EN;
1450 if (sta->max_sp < MAX_WMI_AP_PS_PEER_PARAM_MAX_SP)
1451 max_sp = sta->max_sp;
1453 params.param = WMI_AP_PS_PEER_PARAM_UAPSD;
1454 params.value = uapsd;
1455 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
1459 params.param = WMI_AP_PS_PEER_PARAM_MAX_SP;
1460 params.value = max_sp;
1461 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
1465 /* TODO revisit during testing */
1466 params.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_FRMTYPE;
1467 params.value = DISABLE_SIFS_RESPONSE_TRIGGER;
1468 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
1472 params.param = WMI_AP_PS_PEER_PARAM_SIFS_RESP_UAPSD;
1473 params.value = DISABLE_SIFS_RESPONSE_TRIGGER;
1474 ret = ath11k_wmi_send_set_ap_ps_param_cmd(ar, sta->addr, ¶ms);
1481 ath11k_warn(ar->ab, "failed to set ap ps peer param %d for vdev %i: %d\n",
1482 params.param, arvif->vdev_id, ret);
1486 static bool ath11k_mac_sta_has_ofdm_only(struct ieee80211_sta *sta)
1488 return sta->supp_rates[NL80211_BAND_2GHZ] >>
1489 ATH11K_MAC_FIRST_OFDM_RATE_IDX;
1492 static enum wmi_phy_mode ath11k_mac_get_phymode_vht(struct ath11k *ar,
1493 struct ieee80211_sta *sta)
1495 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
1496 switch (sta->vht_cap.cap &
1497 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
1498 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
1499 return MODE_11AC_VHT160;
1500 case IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
1501 return MODE_11AC_VHT80_80;
1503 /* not sure if this is a valid case? */
1504 return MODE_11AC_VHT160;
1508 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1509 return MODE_11AC_VHT80;
1511 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1512 return MODE_11AC_VHT40;
1514 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1515 return MODE_11AC_VHT20;
1517 return MODE_UNKNOWN;
1520 static enum wmi_phy_mode ath11k_mac_get_phymode_he(struct ath11k *ar,
1521 struct ieee80211_sta *sta)
1523 if (sta->bandwidth == IEEE80211_STA_RX_BW_160) {
1524 if (sta->he_cap.he_cap_elem.phy_cap_info[0] &
1525 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
1526 return MODE_11AX_HE160;
1527 else if (sta->he_cap.he_cap_elem.phy_cap_info[0] &
1528 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)
1529 return MODE_11AX_HE80_80;
1530 /* not sure if this is a valid case? */
1531 return MODE_11AX_HE160;
1534 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1535 return MODE_11AX_HE80;
1537 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1538 return MODE_11AX_HE40;
1540 if (sta->bandwidth == IEEE80211_STA_RX_BW_20)
1541 return MODE_11AX_HE20;
1543 return MODE_UNKNOWN;
1546 static void ath11k_peer_assoc_h_phymode(struct ath11k *ar,
1547 struct ieee80211_vif *vif,
1548 struct ieee80211_sta *sta,
1549 struct peer_assoc_params *arg)
1551 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1552 struct cfg80211_chan_def def;
1553 enum nl80211_band band;
1554 const u8 *ht_mcs_mask;
1555 const u16 *vht_mcs_mask;
1556 enum wmi_phy_mode phymode = MODE_UNKNOWN;
1558 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
1561 band = def.chan->band;
1562 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
1563 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
1566 case NL80211_BAND_2GHZ:
1567 if (sta->he_cap.has_he) {
1568 if (sta->bandwidth == IEEE80211_STA_RX_BW_80)
1569 phymode = MODE_11AX_HE80_2G;
1570 else if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1571 phymode = MODE_11AX_HE40_2G;
1573 phymode = MODE_11AX_HE20_2G;
1574 } else if (sta->vht_cap.vht_supported &&
1575 !ath11k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
1576 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1577 phymode = MODE_11AC_VHT40;
1579 phymode = MODE_11AC_VHT20;
1580 } else if (sta->ht_cap.ht_supported &&
1581 !ath11k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
1582 if (sta->bandwidth == IEEE80211_STA_RX_BW_40)
1583 phymode = MODE_11NG_HT40;
1585 phymode = MODE_11NG_HT20;
1586 } else if (ath11k_mac_sta_has_ofdm_only(sta)) {
1592 case NL80211_BAND_5GHZ:
1593 case NL80211_BAND_6GHZ:
1594 /* Check HE first */
1595 if (sta->he_cap.has_he) {
1596 phymode = ath11k_mac_get_phymode_he(ar, sta);
1597 } else if (sta->vht_cap.vht_supported &&
1598 !ath11k_peer_assoc_h_vht_masked(vht_mcs_mask)) {
1599 phymode = ath11k_mac_get_phymode_vht(ar, sta);
1600 } else if (sta->ht_cap.ht_supported &&
1601 !ath11k_peer_assoc_h_ht_masked(ht_mcs_mask)) {
1602 if (sta->bandwidth >= IEEE80211_STA_RX_BW_40)
1603 phymode = MODE_11NA_HT40;
1605 phymode = MODE_11NA_HT20;
1614 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac peer %pM phymode %s\n",
1615 sta->addr, ath11k_wmi_phymode_str(phymode));
1617 arg->peer_phymode = phymode;
1618 WARN_ON(phymode == MODE_UNKNOWN);
1621 static void ath11k_peer_assoc_prepare(struct ath11k *ar,
1622 struct ieee80211_vif *vif,
1623 struct ieee80211_sta *sta,
1624 struct peer_assoc_params *arg,
1627 lockdep_assert_held(&ar->conf_mutex);
1629 memset(arg, 0, sizeof(*arg));
1631 reinit_completion(&ar->peer_assoc_done);
1633 arg->peer_new_assoc = !reassoc;
1634 ath11k_peer_assoc_h_basic(ar, vif, sta, arg);
1635 ath11k_peer_assoc_h_crypto(ar, vif, sta, arg);
1636 ath11k_peer_assoc_h_rates(ar, vif, sta, arg);
1637 ath11k_peer_assoc_h_ht(ar, vif, sta, arg);
1638 ath11k_peer_assoc_h_vht(ar, vif, sta, arg);
1639 ath11k_peer_assoc_h_he(ar, vif, sta, arg);
1640 ath11k_peer_assoc_h_qos(ar, vif, sta, arg);
1641 ath11k_peer_assoc_h_phymode(ar, vif, sta, arg);
1642 ath11k_peer_assoc_h_smps(sta, arg);
1644 /* TODO: amsdu_disable req? */
1647 static int ath11k_setup_peer_smps(struct ath11k *ar, struct ath11k_vif *arvif,
1649 const struct ieee80211_sta_ht_cap *ht_cap)
1653 if (!ht_cap->ht_supported)
1656 smps = ht_cap->cap & IEEE80211_HT_CAP_SM_PS;
1657 smps >>= IEEE80211_HT_CAP_SM_PS_SHIFT;
1659 if (smps >= ARRAY_SIZE(ath11k_smps_map))
1662 return ath11k_wmi_set_peer_param(ar, addr, arvif->vdev_id,
1663 WMI_PEER_MIMO_PS_STATE,
1664 ath11k_smps_map[smps]);
1667 static void ath11k_bss_assoc(struct ieee80211_hw *hw,
1668 struct ieee80211_vif *vif,
1669 struct ieee80211_bss_conf *bss_conf)
1671 struct ath11k *ar = hw->priv;
1672 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1673 struct peer_assoc_params peer_arg;
1674 struct ieee80211_sta *ap_sta;
1677 lockdep_assert_held(&ar->conf_mutex);
1679 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %i assoc bssid %pM aid %d\n",
1680 arvif->vdev_id, arvif->bssid, arvif->aid);
1684 ap_sta = ieee80211_find_sta(vif, bss_conf->bssid);
1686 ath11k_warn(ar->ab, "failed to find station entry for bss %pM vdev %i\n",
1687 bss_conf->bssid, arvif->vdev_id);
1692 ath11k_peer_assoc_prepare(ar, vif, ap_sta, &peer_arg, false);
1696 ret = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
1698 ath11k_warn(ar->ab, "failed to run peer assoc for %pM vdev %i: %d\n",
1699 bss_conf->bssid, arvif->vdev_id, ret);
1703 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
1704 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
1705 bss_conf->bssid, arvif->vdev_id);
1709 ret = ath11k_setup_peer_smps(ar, arvif, bss_conf->bssid,
1712 ath11k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n",
1713 arvif->vdev_id, ret);
1717 WARN_ON(arvif->is_up);
1719 arvif->aid = bss_conf->aid;
1720 ether_addr_copy(arvif->bssid, bss_conf->bssid);
1722 ret = ath11k_wmi_vdev_up(ar, arvif->vdev_id, arvif->aid, arvif->bssid);
1724 ath11k_warn(ar->ab, "failed to set vdev %d up: %d\n",
1725 arvif->vdev_id, ret);
1729 arvif->is_up = true;
1731 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1732 "mac vdev %d up (associated) bssid %pM aid %d\n",
1733 arvif->vdev_id, bss_conf->bssid, bss_conf->aid);
1735 /* Authorize BSS Peer */
1736 ret = ath11k_wmi_set_peer_param(ar, arvif->bssid,
1741 ath11k_warn(ar->ab, "Unable to authorize BSS peer: %d\n", ret);
1743 ret = ath11k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id,
1744 &bss_conf->he_obss_pd);
1746 ath11k_warn(ar->ab, "failed to set vdev %i OBSS PD parameters: %d\n",
1747 arvif->vdev_id, ret);
1750 static void ath11k_bss_disassoc(struct ieee80211_hw *hw,
1751 struct ieee80211_vif *vif)
1753 struct ath11k *ar = hw->priv;
1754 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1757 lockdep_assert_held(&ar->conf_mutex);
1759 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev %i disassoc bssid %pM\n",
1760 arvif->vdev_id, arvif->bssid);
1762 ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id);
1764 ath11k_warn(ar->ab, "failed to down vdev %i: %d\n",
1765 arvif->vdev_id, ret);
1767 arvif->is_up = false;
1769 /* TODO: cancel connection_loss_work */
1772 static u32 ath11k_mac_get_rate_hw_value(int bitrate)
1779 if (ath11k_mac_bitrate_is_cck(bitrate))
1780 preamble = WMI_RATE_PREAMBLE_CCK;
1782 preamble = WMI_RATE_PREAMBLE_OFDM;
1784 for (i = 0; i < ARRAY_SIZE(ath11k_legacy_rates); i++) {
1785 if (ath11k_legacy_rates[i].bitrate != bitrate)
1788 hw_value = ath11k_legacy_rates[i].hw_value;
1789 rate = ATH11K_HW_RATE_CODE(hw_value, 0, preamble);
1797 static void ath11k_recalculate_mgmt_rate(struct ath11k *ar,
1798 struct ieee80211_vif *vif,
1799 struct cfg80211_chan_def *def)
1801 struct ath11k_vif *arvif = (void *)vif->drv_priv;
1802 const struct ieee80211_supported_band *sband;
1809 lockdep_assert_held(&ar->conf_mutex);
1811 sband = ar->hw->wiphy->bands[def->chan->band];
1812 basic_rate_idx = ffs(vif->bss_conf.basic_rates) - 1;
1813 bitrate = sband->bitrates[basic_rate_idx].bitrate;
1815 hw_rate_code = ath11k_mac_get_rate_hw_value(bitrate);
1816 if (hw_rate_code < 0) {
1817 ath11k_warn(ar->ab, "bitrate not supported %d\n", bitrate);
1821 vdev_param = WMI_VDEV_PARAM_MGMT_RATE;
1822 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
1825 ath11k_warn(ar->ab, "failed to set mgmt tx rate %d\n", ret);
1827 vdev_param = WMI_VDEV_PARAM_BEACON_RATE;
1828 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id, vdev_param,
1831 ath11k_warn(ar->ab, "failed to set beacon tx rate %d\n", ret);
1834 static void ath11k_mac_op_bss_info_changed(struct ieee80211_hw *hw,
1835 struct ieee80211_vif *vif,
1836 struct ieee80211_bss_conf *info,
1839 struct ath11k *ar = hw->priv;
1840 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
1841 struct cfg80211_chan_def def;
1842 u32 param_id, param_value;
1843 enum nl80211_band band;
1853 mutex_lock(&ar->conf_mutex);
1855 if (changed & BSS_CHANGED_BEACON_INT) {
1856 arvif->beacon_interval = info->beacon_int;
1858 param_id = WMI_VDEV_PARAM_BEACON_INTERVAL;
1859 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
1861 arvif->beacon_interval);
1863 ath11k_warn(ar->ab, "Failed to set beacon interval for VDEV: %d\n",
1866 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1867 "Beacon interval: %d set for VDEV: %d\n",
1868 arvif->beacon_interval, arvif->vdev_id);
1871 if (changed & BSS_CHANGED_BEACON) {
1872 param_id = WMI_PDEV_PARAM_BEACON_TX_MODE;
1873 param_value = WMI_BEACON_STAGGERED_MODE;
1874 ret = ath11k_wmi_pdev_set_param(ar, param_id,
1875 param_value, ar->pdev->pdev_id);
1877 ath11k_warn(ar->ab, "Failed to set beacon mode for VDEV: %d\n",
1880 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1881 "Set staggered beacon mode for VDEV: %d\n",
1884 ret = ath11k_mac_setup_bcn_tmpl(arvif);
1886 ath11k_warn(ar->ab, "failed to update bcn template: %d\n",
1889 if (vif->bss_conf.he_support) {
1890 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
1891 WMI_VDEV_PARAM_BA_MODE,
1892 WMI_BA_MODE_BUFFER_SIZE_256);
1895 "failed to set BA BUFFER SIZE 256 for vdev: %d\n",
1898 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1899 "Set BA BUFFER SIZE 256 for VDEV: %d\n",
1904 if (changed & (BSS_CHANGED_BEACON_INFO | BSS_CHANGED_BEACON)) {
1905 arvif->dtim_period = info->dtim_period;
1907 param_id = WMI_VDEV_PARAM_DTIM_PERIOD;
1908 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
1910 arvif->dtim_period);
1913 ath11k_warn(ar->ab, "Failed to set dtim period for VDEV %d: %i\n",
1914 arvif->vdev_id, ret);
1916 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1917 "DTIM period: %d set for VDEV: %d\n",
1918 arvif->dtim_period, arvif->vdev_id);
1921 if (changed & BSS_CHANGED_SSID &&
1922 vif->type == NL80211_IFTYPE_AP) {
1923 arvif->u.ap.ssid_len = info->ssid_len;
1925 memcpy(arvif->u.ap.ssid, info->ssid, info->ssid_len);
1926 arvif->u.ap.hidden_ssid = info->hidden_ssid;
1929 if (changed & BSS_CHANGED_BSSID && !is_zero_ether_addr(info->bssid))
1930 ether_addr_copy(arvif->bssid, info->bssid);
1932 if (changed & BSS_CHANGED_BEACON_ENABLED)
1933 ath11k_control_beaconing(arvif, info);
1935 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1938 cts_prot = !!(info->use_cts_prot);
1939 param_id = WMI_VDEV_PARAM_PROTECTION_MODE;
1941 if (arvif->is_started) {
1942 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
1943 param_id, cts_prot);
1945 ath11k_warn(ar->ab, "Failed to set CTS prot for VDEV: %d\n",
1948 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "Set CTS prot: %d for VDEV: %d\n",
1949 cts_prot, arvif->vdev_id);
1951 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "defer protection mode setup, vdev is not ready yet\n");
1955 if (changed & BSS_CHANGED_ERP_SLOT) {
1958 if (info->use_short_slot)
1959 slottime = WMI_VDEV_SLOT_TIME_SHORT; /* 9us */
1962 slottime = WMI_VDEV_SLOT_TIME_LONG; /* 20us */
1964 param_id = WMI_VDEV_PARAM_SLOT_TIME;
1965 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
1966 param_id, slottime);
1968 ath11k_warn(ar->ab, "Failed to set erp slot for VDEV: %d\n",
1971 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1972 "Set slottime: %d for VDEV: %d\n",
1973 slottime, arvif->vdev_id);
1976 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1979 if (info->use_short_preamble)
1980 preamble = WMI_VDEV_PREAMBLE_SHORT;
1982 preamble = WMI_VDEV_PREAMBLE_LONG;
1984 param_id = WMI_VDEV_PARAM_PREAMBLE;
1985 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
1986 param_id, preamble);
1988 ath11k_warn(ar->ab, "Failed to set preamble for VDEV: %d\n",
1991 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
1992 "Set preamble: %d for VDEV: %d\n",
1993 preamble, arvif->vdev_id);
1996 if (changed & BSS_CHANGED_ASSOC) {
1998 ath11k_bss_assoc(hw, vif, info);
2000 ath11k_bss_disassoc(hw, vif);
2003 if (changed & BSS_CHANGED_TXPOWER) {
2004 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac vdev_id %i txpower %d\n",
2005 arvif->vdev_id, info->txpower);
2007 arvif->txpower = info->txpower;
2008 ath11k_mac_txpower_recalc(ar);
2011 if (changed & BSS_CHANGED_MCAST_RATE &&
2012 !ath11k_mac_vif_chan(arvif->vif, &def)) {
2013 band = def.chan->band;
2014 mcast_rate = vif->bss_conf.mcast_rate[band];
2017 rateidx = mcast_rate - 1;
2019 rateidx = ffs(vif->bss_conf.basic_rates) - 1;
2021 if (ar->pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP)
2022 rateidx += ATH11K_MAC_FIRST_OFDM_RATE_IDX;
2024 bitrate = ath11k_legacy_rates[rateidx].bitrate;
2025 hw_value = ath11k_legacy_rates[rateidx].hw_value;
2027 if (ath11k_mac_bitrate_is_cck(bitrate))
2028 preamble = WMI_RATE_PREAMBLE_CCK;
2030 preamble = WMI_RATE_PREAMBLE_OFDM;
2032 rate = ATH11K_HW_RATE_CODE(hw_value, 0, preamble);
2034 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2035 "mac vdev %d mcast_rate %x\n",
2036 arvif->vdev_id, rate);
2038 vdev_param = WMI_VDEV_PARAM_MCAST_DATA_RATE;
2039 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2043 "failed to set mcast rate on vdev %i: %d\n",
2044 arvif->vdev_id, ret);
2046 vdev_param = WMI_VDEV_PARAM_BCAST_DATA_RATE;
2047 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
2051 "failed to set bcast rate on vdev %i: %d\n",
2052 arvif->vdev_id, ret);
2055 if (changed & BSS_CHANGED_BASIC_RATES &&
2056 !ath11k_mac_vif_chan(arvif->vif, &def))
2057 ath11k_recalculate_mgmt_rate(ar, vif, &def);
2059 if (changed & BSS_CHANGED_TWT) {
2060 if (info->twt_requester || info->twt_responder)
2061 ath11k_wmi_send_twt_enable_cmd(ar, ar->pdev->pdev_id);
2063 ath11k_wmi_send_twt_disable_cmd(ar, ar->pdev->pdev_id);
2066 if (changed & BSS_CHANGED_HE_OBSS_PD)
2067 ath11k_wmi_send_obss_spr_cmd(ar, arvif->vdev_id,
2070 if (changed & BSS_CHANGED_HE_BSS_COLOR) {
2071 if (vif->type == NL80211_IFTYPE_AP) {
2072 ret = ath11k_wmi_send_obss_color_collision_cfg_cmd(
2073 ar, arvif->vdev_id, info->he_bss_color.color,
2074 ATH11K_BSS_COLOR_COLLISION_DETECTION_AP_PERIOD_MS,
2075 !info->he_bss_color.disabled);
2077 ath11k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n",
2078 arvif->vdev_id, ret);
2079 } else if (vif->type == NL80211_IFTYPE_STATION) {
2080 ret = ath11k_wmi_send_bss_color_change_enable_cmd(ar,
2084 ath11k_warn(ar->ab, "failed to enable bss color change on vdev %i: %d\n",
2085 arvif->vdev_id, ret);
2086 ret = ath11k_wmi_send_obss_color_collision_cfg_cmd(
2087 ar, arvif->vdev_id, 0,
2088 ATH11K_BSS_COLOR_COLLISION_DETECTION_STA_PERIOD_MS, 1);
2090 ath11k_warn(ar->ab, "failed to set bss color collision on vdev %i: %d\n",
2091 arvif->vdev_id, ret);
2095 mutex_unlock(&ar->conf_mutex);
2098 void __ath11k_mac_scan_finish(struct ath11k *ar)
2100 lockdep_assert_held(&ar->data_lock);
2102 switch (ar->scan.state) {
2103 case ATH11K_SCAN_IDLE:
2105 case ATH11K_SCAN_RUNNING:
2106 case ATH11K_SCAN_ABORTING:
2107 if (!ar->scan.is_roc) {
2108 struct cfg80211_scan_info info = {
2109 .aborted = (ar->scan.state ==
2110 ATH11K_SCAN_ABORTING),
2113 ieee80211_scan_completed(ar->hw, &info);
2114 } else if (ar->scan.roc_notify) {
2115 ieee80211_remain_on_channel_expired(ar->hw);
2118 case ATH11K_SCAN_STARTING:
2119 ar->scan.state = ATH11K_SCAN_IDLE;
2120 ar->scan_channel = NULL;
2121 ar->scan.roc_freq = 0;
2122 cancel_delayed_work(&ar->scan.timeout);
2123 complete(&ar->scan.completed);
2128 void ath11k_mac_scan_finish(struct ath11k *ar)
2130 spin_lock_bh(&ar->data_lock);
2131 __ath11k_mac_scan_finish(ar);
2132 spin_unlock_bh(&ar->data_lock);
2135 static int ath11k_scan_stop(struct ath11k *ar)
2137 struct scan_cancel_param arg = {
2138 .req_type = WLAN_SCAN_CANCEL_SINGLE,
2139 .scan_id = ATH11K_SCAN_ID,
2143 lockdep_assert_held(&ar->conf_mutex);
2145 /* TODO: Fill other STOP Params */
2146 arg.pdev_id = ar->pdev->pdev_id;
2148 ret = ath11k_wmi_send_scan_stop_cmd(ar, &arg);
2150 ath11k_warn(ar->ab, "failed to stop wmi scan: %d\n", ret);
2154 ret = wait_for_completion_timeout(&ar->scan.completed, 3 * HZ);
2157 "failed to receive scan abort comple: timed out\n");
2159 } else if (ret > 0) {
2164 /* Scan state should be updated upon scan completion but in case
2165 * firmware fails to deliver the event (for whatever reason) it is
2166 * desired to clean up scan state anyway. Firmware may have just
2167 * dropped the scan completion event delivery due to transport pipe
2168 * being overflown with data and/or it can recover on its own before
2169 * next scan request is submitted.
2171 spin_lock_bh(&ar->data_lock);
2172 if (ar->scan.state != ATH11K_SCAN_IDLE)
2173 __ath11k_mac_scan_finish(ar);
2174 spin_unlock_bh(&ar->data_lock);
2179 static void ath11k_scan_abort(struct ath11k *ar)
2183 lockdep_assert_held(&ar->conf_mutex);
2185 spin_lock_bh(&ar->data_lock);
2187 switch (ar->scan.state) {
2188 case ATH11K_SCAN_IDLE:
2189 /* This can happen if timeout worker kicked in and called
2190 * abortion while scan completion was being processed.
2193 case ATH11K_SCAN_STARTING:
2194 case ATH11K_SCAN_ABORTING:
2195 ath11k_warn(ar->ab, "refusing scan abortion due to invalid scan state: %d\n",
2198 case ATH11K_SCAN_RUNNING:
2199 ar->scan.state = ATH11K_SCAN_ABORTING;
2200 spin_unlock_bh(&ar->data_lock);
2202 ret = ath11k_scan_stop(ar);
2204 ath11k_warn(ar->ab, "failed to abort scan: %d\n", ret);
2206 spin_lock_bh(&ar->data_lock);
2210 spin_unlock_bh(&ar->data_lock);
2213 static void ath11k_scan_timeout_work(struct work_struct *work)
2215 struct ath11k *ar = container_of(work, struct ath11k,
2218 mutex_lock(&ar->conf_mutex);
2219 ath11k_scan_abort(ar);
2220 mutex_unlock(&ar->conf_mutex);
2223 static int ath11k_start_scan(struct ath11k *ar,
2224 struct scan_req_params *arg)
2228 lockdep_assert_held(&ar->conf_mutex);
2230 if (ath11k_spectral_get_mode(ar) == ATH11K_SPECTRAL_BACKGROUND)
2231 ath11k_spectral_reset_buffer(ar);
2233 ret = ath11k_wmi_send_scan_start_cmd(ar, arg);
2237 ret = wait_for_completion_timeout(&ar->scan.started, 1 * HZ);
2239 ret = ath11k_scan_stop(ar);
2241 ath11k_warn(ar->ab, "failed to stop scan: %d\n", ret);
2246 /* If we failed to start the scan, return error code at
2247 * this point. This is probably due to some issue in the
2248 * firmware, but no need to wedge the driver due to that...
2250 spin_lock_bh(&ar->data_lock);
2251 if (ar->scan.state == ATH11K_SCAN_IDLE) {
2252 spin_unlock_bh(&ar->data_lock);
2255 spin_unlock_bh(&ar->data_lock);
2260 static int ath11k_mac_op_hw_scan(struct ieee80211_hw *hw,
2261 struct ieee80211_vif *vif,
2262 struct ieee80211_scan_request *hw_req)
2264 struct ath11k *ar = hw->priv;
2265 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
2266 struct cfg80211_scan_request *req = &hw_req->req;
2267 struct scan_req_params arg;
2271 mutex_lock(&ar->conf_mutex);
2273 spin_lock_bh(&ar->data_lock);
2274 switch (ar->scan.state) {
2275 case ATH11K_SCAN_IDLE:
2276 reinit_completion(&ar->scan.started);
2277 reinit_completion(&ar->scan.completed);
2278 ar->scan.state = ATH11K_SCAN_STARTING;
2279 ar->scan.is_roc = false;
2280 ar->scan.vdev_id = arvif->vdev_id;
2283 case ATH11K_SCAN_STARTING:
2284 case ATH11K_SCAN_RUNNING:
2285 case ATH11K_SCAN_ABORTING:
2289 spin_unlock_bh(&ar->data_lock);
2294 memset(&arg, 0, sizeof(arg));
2295 ath11k_wmi_start_scan_init(ar, &arg);
2296 arg.vdev_id = arvif->vdev_id;
2297 arg.scan_id = ATH11K_SCAN_ID;
2300 arg.extraie.len = req->ie_len;
2301 arg.extraie.ptr = kzalloc(req->ie_len, GFP_KERNEL);
2302 memcpy(arg.extraie.ptr, req->ie, req->ie_len);
2306 arg.num_ssids = req->n_ssids;
2307 for (i = 0; i < arg.num_ssids; i++) {
2308 arg.ssid[i].length = req->ssids[i].ssid_len;
2309 memcpy(&arg.ssid[i].ssid, req->ssids[i].ssid,
2310 req->ssids[i].ssid_len);
2313 arg.scan_flags |= WMI_SCAN_FLAG_PASSIVE;
2316 if (req->n_channels) {
2317 arg.num_chan = req->n_channels;
2318 for (i = 0; i < arg.num_chan; i++)
2319 arg.chan_list[i] = req->channels[i]->center_freq;
2322 ret = ath11k_start_scan(ar, &arg);
2324 ath11k_warn(ar->ab, "failed to start hw scan: %d\n", ret);
2325 spin_lock_bh(&ar->data_lock);
2326 ar->scan.state = ATH11K_SCAN_IDLE;
2327 spin_unlock_bh(&ar->data_lock);
2330 /* Add a 200ms margin to account for event/command processing */
2331 ieee80211_queue_delayed_work(ar->hw, &ar->scan.timeout,
2332 msecs_to_jiffies(arg.max_scan_time +
2333 ATH11K_MAC_SCAN_TIMEOUT_MSECS));
2337 kfree(arg.extraie.ptr);
2339 mutex_unlock(&ar->conf_mutex);
2343 static void ath11k_mac_op_cancel_hw_scan(struct ieee80211_hw *hw,
2344 struct ieee80211_vif *vif)
2346 struct ath11k *ar = hw->priv;
2348 mutex_lock(&ar->conf_mutex);
2349 ath11k_scan_abort(ar);
2350 mutex_unlock(&ar->conf_mutex);
2352 cancel_delayed_work_sync(&ar->scan.timeout);
2355 static int ath11k_install_key(struct ath11k_vif *arvif,
2356 struct ieee80211_key_conf *key,
2357 enum set_key_cmd cmd,
2358 const u8 *macaddr, u32 flags)
2361 struct ath11k *ar = arvif->ar;
2362 struct wmi_vdev_install_key_arg arg = {
2363 .vdev_id = arvif->vdev_id,
2364 .key_idx = key->keyidx,
2365 .key_len = key->keylen,
2366 .key_data = key->key,
2371 lockdep_assert_held(&arvif->ar->conf_mutex);
2373 reinit_completion(&ar->install_key_done);
2375 if (cmd == DISABLE_KEY) {
2376 /* TODO: Check if FW expects value other than NONE for del */
2377 /* arg.key_cipher = WMI_CIPHER_NONE; */
2379 arg.key_data = NULL;
2383 switch (key->cipher) {
2384 case WLAN_CIPHER_SUITE_CCMP:
2385 arg.key_cipher = WMI_CIPHER_AES_CCM;
2386 /* TODO: Re-check if flag is valid */
2387 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV_MGMT;
2389 case WLAN_CIPHER_SUITE_TKIP:
2390 arg.key_cipher = WMI_CIPHER_TKIP;
2391 arg.key_txmic_len = 8;
2392 arg.key_rxmic_len = 8;
2394 case WLAN_CIPHER_SUITE_CCMP_256:
2395 arg.key_cipher = WMI_CIPHER_AES_CCM;
2397 case WLAN_CIPHER_SUITE_GCMP:
2398 case WLAN_CIPHER_SUITE_GCMP_256:
2399 arg.key_cipher = WMI_CIPHER_AES_GCM;
2402 ath11k_warn(ar->ab, "cipher %d is not supported\n", key->cipher);
2407 ret = ath11k_wmi_vdev_install_key(arvif->ar, &arg);
2411 if (!wait_for_completion_timeout(&ar->install_key_done, 1 * HZ))
2414 return ar->install_key_status ? -EINVAL : 0;
2417 static int ath11k_clear_peer_keys(struct ath11k_vif *arvif,
2420 struct ath11k *ar = arvif->ar;
2421 struct ath11k_base *ab = ar->ab;
2422 struct ath11k_peer *peer;
2423 int first_errno = 0;
2428 lockdep_assert_held(&ar->conf_mutex);
2430 spin_lock_bh(&ab->base_lock);
2431 peer = ath11k_peer_find(ab, arvif->vdev_id, addr);
2432 spin_unlock_bh(&ab->base_lock);
2437 for (i = 0; i < ARRAY_SIZE(peer->keys); i++) {
2441 /* key flags are not required to delete the key */
2442 ret = ath11k_install_key(arvif, peer->keys[i],
2443 DISABLE_KEY, addr, flags);
2444 if (ret < 0 && first_errno == 0)
2448 ath11k_warn(ab, "failed to remove peer key %d: %d\n",
2451 spin_lock_bh(&ab->base_lock);
2452 peer->keys[i] = NULL;
2453 spin_unlock_bh(&ab->base_lock);
2459 static int ath11k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2460 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
2461 struct ieee80211_key_conf *key)
2463 struct ath11k *ar = hw->priv;
2464 struct ath11k_base *ab = ar->ab;
2465 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
2466 struct ath11k_peer *peer;
2467 struct ath11k_sta *arsta;
2468 const u8 *peer_addr;
2472 /* BIP needs to be done in software */
2473 if (key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2474 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2475 key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256 ||
2476 key->cipher == WLAN_CIPHER_SUITE_BIP_CMAC_256)
2479 if (key->keyidx > WMI_MAX_KEY_INDEX)
2482 mutex_lock(&ar->conf_mutex);
2485 peer_addr = sta->addr;
2486 else if (arvif->vdev_type == WMI_VDEV_TYPE_STA)
2487 peer_addr = vif->bss_conf.bssid;
2489 peer_addr = vif->addr;
2491 key->hw_key_idx = key->keyidx;
2493 /* the peer should not disappear in mid-way (unless FW goes awry) since
2494 * we already hold conf_mutex. we just make sure its there now.
2496 spin_lock_bh(&ab->base_lock);
2497 peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr);
2498 spin_unlock_bh(&ab->base_lock);
2501 if (cmd == SET_KEY) {
2502 ath11k_warn(ab, "cannot install key for non-existent peer %pM\n",
2507 /* if the peer doesn't exist there is no key to disable
2514 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
2515 flags |= WMI_KEY_PAIRWISE;
2517 flags |= WMI_KEY_GROUP;
2519 ret = ath11k_install_key(arvif, key, cmd, peer_addr, flags);
2521 ath11k_warn(ab, "ath11k_install_key failed (%d)\n", ret);
2525 ret = ath11k_dp_peer_rx_pn_replay_config(arvif, peer_addr, cmd, key);
2527 ath11k_warn(ab, "failed to offload PN replay detection %d\n", ret);
2531 spin_lock_bh(&ab->base_lock);
2532 peer = ath11k_peer_find(ab, arvif->vdev_id, peer_addr);
2533 if (peer && cmd == SET_KEY) {
2534 peer->keys[key->keyidx] = key;
2535 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
2536 peer->ucast_keyidx = key->keyidx;
2537 peer->sec_type = ath11k_dp_tx_get_encrypt_type(key->cipher);
2539 peer->mcast_keyidx = key->keyidx;
2540 peer->sec_type_grp = ath11k_dp_tx_get_encrypt_type(key->cipher);
2542 } else if (peer && cmd == DISABLE_KEY) {
2543 peer->keys[key->keyidx] = NULL;
2544 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
2545 peer->ucast_keyidx = 0;
2547 peer->mcast_keyidx = 0;
2549 /* impossible unless FW goes crazy */
2550 ath11k_warn(ab, "peer %pM disappeared!\n", peer_addr);
2553 arsta = (struct ath11k_sta *)sta->drv_priv;
2555 switch (key->cipher) {
2556 case WLAN_CIPHER_SUITE_TKIP:
2557 case WLAN_CIPHER_SUITE_CCMP:
2558 case WLAN_CIPHER_SUITE_CCMP_256:
2559 case WLAN_CIPHER_SUITE_GCMP:
2560 case WLAN_CIPHER_SUITE_GCMP_256:
2562 arsta->pn_type = HAL_PN_TYPE_WPA;
2564 arsta->pn_type = HAL_PN_TYPE_NONE;
2567 arsta->pn_type = HAL_PN_TYPE_NONE;
2572 spin_unlock_bh(&ab->base_lock);
2575 mutex_unlock(&ar->conf_mutex);
2580 ath11k_mac_bitrate_mask_num_vht_rates(struct ath11k *ar,
2581 enum nl80211_band band,
2582 const struct cfg80211_bitrate_mask *mask)
2587 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++)
2588 num_rates += hweight16(mask->control[band].vht_mcs[i]);
2594 ath11k_mac_set_peer_vht_fixed_rate(struct ath11k_vif *arvif,
2595 struct ieee80211_sta *sta,
2596 const struct cfg80211_bitrate_mask *mask,
2597 enum nl80211_band band)
2599 struct ath11k *ar = arvif->ar;
2604 lockdep_assert_held(&ar->conf_mutex);
2608 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
2609 if (hweight16(mask->control[band].vht_mcs[i]) == 1) {
2611 vht_rate = ffs(mask->control[band].vht_mcs[i]) - 1;
2616 ath11k_warn(ar->ab, "No single VHT Fixed rate found to set for %pM",
2621 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
2622 "Setting Fixed VHT Rate for peer %pM. Device will not switch to any other selected rates",
2625 rate_code = ATH11K_HW_RATE_CODE(vht_rate, nss - 1,
2626 WMI_RATE_PREAMBLE_VHT);
2627 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
2629 WMI_PEER_PARAM_FIXED_RATE,
2633 "failed to update STA %pM Fixed Rate %d: %d\n",
2634 sta->addr, rate_code, ret);
2639 static int ath11k_station_assoc(struct ath11k *ar,
2640 struct ieee80211_vif *vif,
2641 struct ieee80211_sta *sta,
2644 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
2645 struct peer_assoc_params peer_arg;
2647 struct cfg80211_chan_def def;
2648 enum nl80211_band band;
2649 struct cfg80211_bitrate_mask *mask;
2652 lockdep_assert_held(&ar->conf_mutex);
2654 if (WARN_ON(ath11k_mac_vif_chan(vif, &def)))
2657 band = def.chan->band;
2658 mask = &arvif->bitrate_mask;
2660 ath11k_peer_assoc_prepare(ar, vif, sta, &peer_arg, reassoc);
2662 ret = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
2664 ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2665 sta->addr, arvif->vdev_id, ret);
2669 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
2670 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
2671 sta->addr, arvif->vdev_id);
2675 num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask);
2677 /* If single VHT rate is configured (by set_bitrate_mask()),
2678 * peer_assoc will disable VHT. This is now enabled by a peer specific
2680 * Note that all other rates and NSS will be disabled for this peer.
2682 if (sta->vht_cap.vht_supported && num_vht_rates == 1) {
2683 ret = ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask,
2689 /* Re-assoc is run only to update supported rates for given station. It
2690 * doesn't make much sense to reconfigure the peer completely.
2695 ret = ath11k_setup_peer_smps(ar, arvif, sta->addr,
2698 ath11k_warn(ar->ab, "failed to setup peer SMPS for vdev %d: %d\n",
2699 arvif->vdev_id, ret);
2704 arvif->num_legacy_stations++;
2705 ret = ath11k_recalc_rtscts_prot(arvif);
2710 if (sta->wme && sta->uapsd_queues) {
2711 ret = ath11k_peer_assoc_qos_ap(ar, arvif, sta);
2713 ath11k_warn(ar->ab, "failed to set qos params for STA %pM for vdev %i: %d\n",
2714 sta->addr, arvif->vdev_id, ret);
2722 static int ath11k_station_disassoc(struct ath11k *ar,
2723 struct ieee80211_vif *vif,
2724 struct ieee80211_sta *sta)
2726 struct ath11k_vif *arvif = (void *)vif->drv_priv;
2729 lockdep_assert_held(&ar->conf_mutex);
2732 arvif->num_legacy_stations--;
2733 ret = ath11k_recalc_rtscts_prot(arvif);
2738 ret = ath11k_clear_peer_keys(arvif, sta->addr);
2740 ath11k_warn(ar->ab, "failed to clear all peer keys for vdev %i: %d\n",
2741 arvif->vdev_id, ret);
2747 static void ath11k_sta_rc_update_wk(struct work_struct *wk)
2750 struct ath11k_vif *arvif;
2751 struct ath11k_sta *arsta;
2752 struct ieee80211_sta *sta;
2753 struct cfg80211_chan_def def;
2754 enum nl80211_band band;
2755 const u8 *ht_mcs_mask;
2756 const u16 *vht_mcs_mask;
2757 u32 changed, bw, nss, smps;
2758 int err, num_vht_rates;
2759 const struct cfg80211_bitrate_mask *mask;
2760 struct peer_assoc_params peer_arg;
2762 arsta = container_of(wk, struct ath11k_sta, update_wk);
2763 sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
2764 arvif = arsta->arvif;
2767 if (WARN_ON(ath11k_mac_vif_chan(arvif->vif, &def)))
2770 band = def.chan->band;
2771 ht_mcs_mask = arvif->bitrate_mask.control[band].ht_mcs;
2772 vht_mcs_mask = arvif->bitrate_mask.control[band].vht_mcs;
2774 spin_lock_bh(&ar->data_lock);
2776 changed = arsta->changed;
2783 spin_unlock_bh(&ar->data_lock);
2785 mutex_lock(&ar->conf_mutex);
2787 nss = max_t(u32, 1, nss);
2788 nss = min(nss, max(ath11k_mac_max_ht_nss(ht_mcs_mask),
2789 ath11k_mac_max_vht_nss(vht_mcs_mask)));
2791 if (changed & IEEE80211_RC_BW_CHANGED) {
2792 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
2793 WMI_PEER_CHWIDTH, bw);
2795 ath11k_warn(ar->ab, "failed to update STA %pM peer bw %d: %d\n",
2796 sta->addr, bw, err);
2799 if (changed & IEEE80211_RC_NSS_CHANGED) {
2800 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM nss %d\n",
2803 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
2806 ath11k_warn(ar->ab, "failed to update STA %pM nss %d: %d\n",
2807 sta->addr, nss, err);
2810 if (changed & IEEE80211_RC_SMPS_CHANGED) {
2811 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM smps %d\n",
2814 err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
2815 WMI_PEER_MIMO_PS_STATE, smps);
2817 ath11k_warn(ar->ab, "failed to update STA %pM smps %d: %d\n",
2818 sta->addr, smps, err);
2821 if (changed & IEEE80211_RC_SUPP_RATES_CHANGED) {
2822 mask = &arvif->bitrate_mask;
2823 num_vht_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band,
2826 /* Peer_assoc_prepare will reject vht rates in
2827 * bitrate_mask if its not available in range format and
2828 * sets vht tx_rateset as unsupported. So multiple VHT MCS
2829 * setting(eg. MCS 4,5,6) per peer is not supported here.
2830 * But, Single rate in VHT mask can be set as per-peer
2831 * fixed rate. But even if any HT rates are configured in
2832 * the bitrate mask, device will not switch to those rates
2833 * when per-peer Fixed rate is set.
2834 * TODO: Check RATEMASK_CMDID to support auto rates selection
2835 * across HT/VHT and for multiple VHT MCS support.
2837 if (sta->vht_cap.vht_supported && num_vht_rates == 1) {
2838 ath11k_mac_set_peer_vht_fixed_rate(arvif, sta, mask,
2841 /* If the peer is non-VHT or no fixed VHT rate
2842 * is provided in the new bitrate mask we set the
2843 * other rates using peer_assoc command.
2845 ath11k_peer_assoc_prepare(ar, arvif->vif, sta,
2848 err = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
2850 ath11k_warn(ar->ab, "failed to run peer assoc for STA %pM vdev %i: %d\n",
2851 sta->addr, arvif->vdev_id, err);
2853 if (!wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ))
2854 ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
2855 sta->addr, arvif->vdev_id);
2859 mutex_unlock(&ar->conf_mutex);
2862 static int ath11k_mac_inc_num_stations(struct ath11k_vif *arvif,
2863 struct ieee80211_sta *sta)
2865 struct ath11k *ar = arvif->ar;
2867 lockdep_assert_held(&ar->conf_mutex);
2869 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
2872 if (ar->num_stations >= ar->max_num_stations)
2880 static void ath11k_mac_dec_num_stations(struct ath11k_vif *arvif,
2881 struct ieee80211_sta *sta)
2883 struct ath11k *ar = arvif->ar;
2885 lockdep_assert_held(&ar->conf_mutex);
2887 if (arvif->vdev_type == WMI_VDEV_TYPE_STA && !sta->tdls)
2893 static int ath11k_mac_station_add(struct ath11k *ar,
2894 struct ieee80211_vif *vif,
2895 struct ieee80211_sta *sta)
2897 struct ath11k_base *ab = ar->ab;
2898 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
2899 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
2900 struct peer_create_params peer_param;
2903 lockdep_assert_held(&ar->conf_mutex);
2905 ret = ath11k_mac_inc_num_stations(arvif, sta);
2907 ath11k_warn(ab, "refusing to associate station: too many connected already (%d)\n",
2908 ar->max_num_stations);
2912 arsta->rx_stats = kzalloc(sizeof(*arsta->rx_stats), GFP_KERNEL);
2913 if (!arsta->rx_stats) {
2915 goto dec_num_station;
2918 peer_param.vdev_id = arvif->vdev_id;
2919 peer_param.peer_addr = sta->addr;
2920 peer_param.peer_type = WMI_PEER_TYPE_DEFAULT;
2922 ret = ath11k_peer_create(ar, arvif, sta, &peer_param);
2924 ath11k_warn(ab, "Failed to add peer: %pM for VDEV: %d\n",
2925 sta->addr, arvif->vdev_id);
2929 ath11k_dbg(ab, ATH11K_DBG_MAC, "Added peer: %pM for VDEV: %d\n",
2930 sta->addr, arvif->vdev_id);
2932 if (ath11k_debug_is_extd_tx_stats_enabled(ar)) {
2933 arsta->tx_stats = kzalloc(sizeof(*arsta->tx_stats), GFP_KERNEL);
2934 if (!arsta->tx_stats) {
2940 if (ieee80211_vif_is_mesh(vif)) {
2941 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
2943 WMI_PEER_USE_4ADDR, 1);
2945 ath11k_warn(ab, "failed to STA %pM 4addr capability: %d\n",
2951 ret = ath11k_dp_peer_setup(ar, arvif->vdev_id, sta->addr);
2953 ath11k_warn(ab, "failed to setup dp for peer %pM on vdev %i (%d)\n",
2954 sta->addr, arvif->vdev_id, ret);
2961 kfree(arsta->tx_stats);
2962 arsta->tx_stats = NULL;
2964 ath11k_peer_delete(ar, arvif->vdev_id, sta->addr);
2966 kfree(arsta->rx_stats);
2967 arsta->rx_stats = NULL;
2969 ath11k_mac_dec_num_stations(arvif, sta);
2974 static int ath11k_mac_op_sta_state(struct ieee80211_hw *hw,
2975 struct ieee80211_vif *vif,
2976 struct ieee80211_sta *sta,
2977 enum ieee80211_sta_state old_state,
2978 enum ieee80211_sta_state new_state)
2980 struct ath11k *ar = hw->priv;
2981 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
2982 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
2983 struct ath11k_peer *peer;
2986 /* cancel must be done outside the mutex to avoid deadlock */
2987 if ((old_state == IEEE80211_STA_NONE &&
2988 new_state == IEEE80211_STA_NOTEXIST))
2989 cancel_work_sync(&arsta->update_wk);
2991 mutex_lock(&ar->conf_mutex);
2993 if (old_state == IEEE80211_STA_NOTEXIST &&
2994 new_state == IEEE80211_STA_NONE) {
2995 memset(arsta, 0, sizeof(*arsta));
2996 arsta->arvif = arvif;
2997 INIT_WORK(&arsta->update_wk, ath11k_sta_rc_update_wk);
2999 ret = ath11k_mac_station_add(ar, vif, sta);
3001 ath11k_warn(ar->ab, "Failed to add station: %pM for VDEV: %d\n",
3002 sta->addr, arvif->vdev_id);
3003 } else if ((old_state == IEEE80211_STA_NONE &&
3004 new_state == IEEE80211_STA_NOTEXIST)) {
3005 ath11k_dp_peer_cleanup(ar, arvif->vdev_id, sta->addr);
3007 ret = ath11k_peer_delete(ar, arvif->vdev_id, sta->addr);
3009 ath11k_warn(ar->ab, "Failed to delete peer: %pM for VDEV: %d\n",
3010 sta->addr, arvif->vdev_id);
3012 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "Removed peer: %pM for VDEV: %d\n",
3013 sta->addr, arvif->vdev_id);
3015 ath11k_mac_dec_num_stations(arvif, sta);
3016 spin_lock_bh(&ar->ab->base_lock);
3017 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
3018 if (peer && peer->sta == sta) {
3019 ath11k_warn(ar->ab, "Found peer entry %pM n vdev %i after it was supposedly removed\n",
3020 vif->addr, arvif->vdev_id);
3022 list_del(&peer->list);
3026 spin_unlock_bh(&ar->ab->base_lock);
3028 kfree(arsta->tx_stats);
3029 arsta->tx_stats = NULL;
3031 kfree(arsta->rx_stats);
3032 arsta->rx_stats = NULL;
3033 } else if (old_state == IEEE80211_STA_AUTH &&
3034 new_state == IEEE80211_STA_ASSOC &&
3035 (vif->type == NL80211_IFTYPE_AP ||
3036 vif->type == NL80211_IFTYPE_MESH_POINT ||
3037 vif->type == NL80211_IFTYPE_ADHOC)) {
3038 ret = ath11k_station_assoc(ar, vif, sta, false);
3040 ath11k_warn(ar->ab, "Failed to associate station: %pM\n",
3042 } else if (old_state == IEEE80211_STA_ASSOC &&
3043 new_state == IEEE80211_STA_AUTH &&
3044 (vif->type == NL80211_IFTYPE_AP ||
3045 vif->type == NL80211_IFTYPE_MESH_POINT ||
3046 vif->type == NL80211_IFTYPE_ADHOC)) {
3047 ret = ath11k_station_disassoc(ar, vif, sta);
3049 ath11k_warn(ar->ab, "Failed to disassociate station: %pM\n",
3053 mutex_unlock(&ar->conf_mutex);
3057 static int ath11k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw,
3058 struct ieee80211_vif *vif,
3059 struct ieee80211_sta *sta)
3061 struct ath11k *ar = hw->priv;
3062 struct ath11k_vif *arvif = (void *)vif->drv_priv;
3066 if (sta->txpwr.type == NL80211_TX_POWER_AUTOMATIC) {
3069 txpwr = sta->txpwr.power;
3074 if (txpwr > ATH11K_TX_POWER_MAX_VAL || txpwr < ATH11K_TX_POWER_MIN_VAL)
3077 mutex_lock(&ar->conf_mutex);
3079 ret = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
3080 WMI_PEER_USE_FIXED_PWR, txpwr);
3082 ath11k_warn(ar->ab, "failed to set tx power for station ret: %d\n",
3088 mutex_unlock(&ar->conf_mutex);
3092 static void ath11k_mac_op_sta_rc_update(struct ieee80211_hw *hw,
3093 struct ieee80211_vif *vif,
3094 struct ieee80211_sta *sta,
3097 struct ath11k *ar = hw->priv;
3098 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
3099 struct ath11k_vif *arvif = (void *)vif->drv_priv;
3100 struct ath11k_peer *peer;
3103 spin_lock_bh(&ar->ab->base_lock);
3105 peer = ath11k_peer_find(ar->ab, arvif->vdev_id, sta->addr);
3107 spin_unlock_bh(&ar->ab->base_lock);
3108 ath11k_warn(ar->ab, "mac sta rc update failed to find peer %pM on vdev %i\n",
3109 sta->addr, arvif->vdev_id);
3113 spin_unlock_bh(&ar->ab->base_lock);
3115 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
3116 "mac sta rc update for %pM changed %08x bw %d nss %d smps %d\n",
3117 sta->addr, changed, sta->bandwidth, sta->rx_nss,
3120 spin_lock_bh(&ar->data_lock);
3122 if (changed & IEEE80211_RC_BW_CHANGED) {
3123 bw = WMI_PEER_CHWIDTH_20MHZ;
3125 switch (sta->bandwidth) {
3126 case IEEE80211_STA_RX_BW_20:
3127 bw = WMI_PEER_CHWIDTH_20MHZ;
3129 case IEEE80211_STA_RX_BW_40:
3130 bw = WMI_PEER_CHWIDTH_40MHZ;
3132 case IEEE80211_STA_RX_BW_80:
3133 bw = WMI_PEER_CHWIDTH_80MHZ;
3135 case IEEE80211_STA_RX_BW_160:
3136 bw = WMI_PEER_CHWIDTH_160MHZ;
3139 ath11k_warn(ar->ab, "Invalid bandwidth %d in rc update for %pM\n",
3140 sta->bandwidth, sta->addr);
3141 bw = WMI_PEER_CHWIDTH_20MHZ;
3148 if (changed & IEEE80211_RC_NSS_CHANGED)
3149 arsta->nss = sta->rx_nss;
3151 if (changed & IEEE80211_RC_SMPS_CHANGED) {
3152 smps = WMI_PEER_SMPS_PS_NONE;
3154 switch (sta->smps_mode) {
3155 case IEEE80211_SMPS_AUTOMATIC:
3156 case IEEE80211_SMPS_OFF:
3157 smps = WMI_PEER_SMPS_PS_NONE;
3159 case IEEE80211_SMPS_STATIC:
3160 smps = WMI_PEER_SMPS_STATIC;
3162 case IEEE80211_SMPS_DYNAMIC:
3163 smps = WMI_PEER_SMPS_DYNAMIC;
3166 ath11k_warn(ar->ab, "Invalid smps %d in sta rc update for %pM\n",
3167 sta->smps_mode, sta->addr);
3168 smps = WMI_PEER_SMPS_PS_NONE;
3175 arsta->changed |= changed;
3177 spin_unlock_bh(&ar->data_lock);
3179 ieee80211_queue_work(hw, &arsta->update_wk);
3182 static int ath11k_conf_tx_uapsd(struct ath11k *ar, struct ieee80211_vif *vif,
3183 u16 ac, bool enable)
3185 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
3189 if (arvif->vdev_type != WMI_VDEV_TYPE_STA)
3193 case IEEE80211_AC_VO:
3194 value = WMI_STA_PS_UAPSD_AC3_DELIVERY_EN |
3195 WMI_STA_PS_UAPSD_AC3_TRIGGER_EN;
3197 case IEEE80211_AC_VI:
3198 value = WMI_STA_PS_UAPSD_AC2_DELIVERY_EN |
3199 WMI_STA_PS_UAPSD_AC2_TRIGGER_EN;
3201 case IEEE80211_AC_BE:
3202 value = WMI_STA_PS_UAPSD_AC1_DELIVERY_EN |
3203 WMI_STA_PS_UAPSD_AC1_TRIGGER_EN;
3205 case IEEE80211_AC_BK:
3206 value = WMI_STA_PS_UAPSD_AC0_DELIVERY_EN |
3207 WMI_STA_PS_UAPSD_AC0_TRIGGER_EN;
3212 arvif->u.sta.uapsd |= value;
3214 arvif->u.sta.uapsd &= ~value;
3216 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3217 WMI_STA_PS_PARAM_UAPSD,
3218 arvif->u.sta.uapsd);
3220 ath11k_warn(ar->ab, "could not set uapsd params %d\n", ret);
3224 if (arvif->u.sta.uapsd)
3225 value = WMI_STA_PS_RX_WAKE_POLICY_POLL_UAPSD;
3227 value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
3229 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
3230 WMI_STA_PS_PARAM_RX_WAKE_POLICY,
3233 ath11k_warn(ar->ab, "could not set rx wake param %d\n", ret);
3239 static int ath11k_mac_op_conf_tx(struct ieee80211_hw *hw,
3240 struct ieee80211_vif *vif, u16 ac,
3241 const struct ieee80211_tx_queue_params *params)
3243 struct ath11k *ar = hw->priv;
3244 struct ath11k_vif *arvif = (void *)vif->drv_priv;
3245 struct wmi_wmm_params_arg *p = NULL;
3248 mutex_lock(&ar->conf_mutex);
3251 case IEEE80211_AC_VO:
3252 p = &arvif->wmm_params.ac_vo;
3254 case IEEE80211_AC_VI:
3255 p = &arvif->wmm_params.ac_vi;
3257 case IEEE80211_AC_BE:
3258 p = &arvif->wmm_params.ac_be;
3260 case IEEE80211_AC_BK:
3261 p = &arvif->wmm_params.ac_bk;
3270 p->cwmin = params->cw_min;
3271 p->cwmax = params->cw_max;
3272 p->aifs = params->aifs;
3273 p->txop = params->txop;
3275 ret = ath11k_wmi_send_wmm_update_cmd_tlv(ar, arvif->vdev_id,
3276 &arvif->wmm_params);
3278 ath11k_warn(ar->ab, "failed to set wmm params: %d\n", ret);
3282 ret = ath11k_conf_tx_uapsd(ar, vif, ac, params->uapsd);
3285 ath11k_warn(ar->ab, "failed to set sta uapsd: %d\n", ret);
3288 mutex_unlock(&ar->conf_mutex);
3292 static struct ieee80211_sta_ht_cap
3293 ath11k_create_ht_cap(struct ath11k *ar, u32 ar_ht_cap, u32 rate_cap_rx_chainmask)
3296 struct ieee80211_sta_ht_cap ht_cap = {0};
3297 u32 ar_vht_cap = ar->pdev->cap.vht_cap;
3299 if (!(ar_ht_cap & WMI_HT_CAP_ENABLED))
3302 ht_cap.ht_supported = 1;
3303 ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
3304 ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
3305 ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
3306 ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
3307 ht_cap.cap |= WLAN_HT_CAP_SM_PS_STATIC << IEEE80211_HT_CAP_SM_PS_SHIFT;
3309 if (ar_ht_cap & WMI_HT_CAP_HT20_SGI)
3310 ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
3312 if (ar_ht_cap & WMI_HT_CAP_HT40_SGI)
3313 ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
3315 if (ar_ht_cap & WMI_HT_CAP_DYNAMIC_SMPS) {
3318 smps = WLAN_HT_CAP_SM_PS_DYNAMIC;
3319 smps <<= IEEE80211_HT_CAP_SM_PS_SHIFT;
3324 if (ar_ht_cap & WMI_HT_CAP_TX_STBC)
3325 ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
3327 if (ar_ht_cap & WMI_HT_CAP_RX_STBC) {
3331 stbc &= WMI_HT_CAP_RX_STBC;
3332 stbc >>= WMI_HT_CAP_RX_STBC_MASK_SHIFT;
3333 stbc <<= IEEE80211_HT_CAP_RX_STBC_SHIFT;
3334 stbc &= IEEE80211_HT_CAP_RX_STBC;
3339 if (ar_ht_cap & WMI_HT_CAP_RX_LDPC)
3340 ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING;
3342 if (ar_ht_cap & WMI_HT_CAP_L_SIG_TXOP_PROT)
3343 ht_cap.cap |= IEEE80211_HT_CAP_LSIG_TXOP_PROT;
3345 if (ar_vht_cap & WMI_VHT_CAP_MAX_MPDU_LEN_MASK)
3346 ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
3348 for (i = 0; i < ar->num_rx_chains; i++) {
3349 if (rate_cap_rx_chainmask & BIT(i))
3350 ht_cap.mcs.rx_mask[i] = 0xFF;
3353 ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
3358 static int ath11k_mac_set_txbf_conf(struct ath11k_vif *arvif)
3361 struct ath11k *ar = arvif->ar;
3364 u32 vht_cap = ar->pdev->cap.vht_cap;
3365 u32 vdev_param = WMI_VDEV_PARAM_TXBF;
3367 if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE)) {
3368 nsts = vht_cap & IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
3369 nsts >>= IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT;
3370 value |= SM(nsts, WMI_TXBF_STS_CAP_OFFSET);
3373 if (vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)) {
3374 sound_dim = vht_cap &
3375 IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
3376 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
3377 if (sound_dim > (ar->num_tx_chains - 1))
3378 sound_dim = ar->num_tx_chains - 1;
3379 value |= SM(sound_dim, WMI_BF_SOUND_DIM_OFFSET);
3385 if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) {
3386 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFER;
3388 if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) &&
3389 arvif->vdev_type == WMI_VDEV_TYPE_AP)
3390 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFER;
3393 /* TODO: SUBFEE not validated in HK, disable here until validated? */
3395 if (vht_cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) {
3396 value |= WMI_VDEV_PARAM_TXBF_SU_TX_BFEE;
3398 if ((vht_cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) &&
3399 arvif->vdev_type == WMI_VDEV_TYPE_STA)
3400 value |= WMI_VDEV_PARAM_TXBF_MU_TX_BFEE;
3403 return ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
3407 static void ath11k_set_vht_txbf_cap(struct ath11k *ar, u32 *vht_cap)
3409 bool subfer, subfee;
3412 subfer = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE));
3413 subfee = !!(*vht_cap & (IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE));
3415 if (ar->num_tx_chains < 2) {
3416 *vht_cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE);
3420 /* If SU Beaformer is not set, then disable MU Beamformer Capability */
3422 *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE);
3424 /* If SU Beaformee is not set, then disable MU Beamformee Capability */
3426 *vht_cap &= ~(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
3428 sound_dim = (*vht_cap & IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK);
3429 sound_dim >>= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
3430 *vht_cap &= ~IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
3432 /* TODO: Need to check invalid STS and Sound_dim values set by FW? */
3434 /* Enable Sounding Dimension Field only if SU BF is enabled */
3436 if (sound_dim > (ar->num_tx_chains - 1))
3437 sound_dim = ar->num_tx_chains - 1;
3439 sound_dim <<= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_SHIFT;
3440 sound_dim &= IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK;
3441 *vht_cap |= sound_dim;
3444 /* Use the STS advertised by FW unless SU Beamformee is not supported*/
3446 *vht_cap &= ~(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK);
3449 static struct ieee80211_sta_vht_cap
3450 ath11k_create_vht_cap(struct ath11k *ar, u32 rate_cap_tx_chainmask,
3451 u32 rate_cap_rx_chainmask)
3453 struct ieee80211_sta_vht_cap vht_cap = {0};
3454 u16 txmcs_map, rxmcs_map;
3457 vht_cap.vht_supported = 1;
3458 vht_cap.cap = ar->pdev->cap.vht_cap;
3460 ath11k_set_vht_txbf_cap(ar, &vht_cap.cap);
3462 /* TODO: Enable back VHT160 mode once association issues are fixed */
3463 /* Disabling VHT160 and VHT80+80 modes */
3464 vht_cap.cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
3465 vht_cap.cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
3469 for (i = 0; i < 8; i++) {
3470 if (i < ar->num_tx_chains && rate_cap_tx_chainmask & BIT(i))
3471 txmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
3473 txmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
3475 if (i < ar->num_rx_chains && rate_cap_rx_chainmask & BIT(i))
3476 rxmcs_map |= IEEE80211_VHT_MCS_SUPPORT_0_9 << (i * 2);
3478 rxmcs_map |= IEEE80211_VHT_MCS_NOT_SUPPORTED << (i * 2);
3481 if (rate_cap_tx_chainmask <= 1)
3482 vht_cap.cap &= ~IEEE80211_VHT_CAP_TXSTBC;
3484 vht_cap.vht_mcs.rx_mcs_map = cpu_to_le16(rxmcs_map);
3485 vht_cap.vht_mcs.tx_mcs_map = cpu_to_le16(txmcs_map);
3490 static void ath11k_mac_setup_ht_vht_cap(struct ath11k *ar,
3491 struct ath11k_pdev_cap *cap,
3494 struct ieee80211_supported_band *band;
3495 u32 rate_cap_tx_chainmask;
3496 u32 rate_cap_rx_chainmask;
3499 rate_cap_tx_chainmask = ar->cfg_tx_chainmask >> cap->tx_chain_mask_shift;
3500 rate_cap_rx_chainmask = ar->cfg_rx_chainmask >> cap->rx_chain_mask_shift;
3502 if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) {
3503 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
3504 ht_cap = cap->band[NL80211_BAND_2GHZ].ht_cap_info;
3506 *ht_cap_info = ht_cap;
3507 band->ht_cap = ath11k_create_ht_cap(ar, ht_cap,
3508 rate_cap_rx_chainmask);
3511 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP && !ar->supports_6ghz) {
3512 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
3513 ht_cap = cap->band[NL80211_BAND_5GHZ].ht_cap_info;
3515 *ht_cap_info = ht_cap;
3516 band->ht_cap = ath11k_create_ht_cap(ar, ht_cap,
3517 rate_cap_rx_chainmask);
3518 band->vht_cap = ath11k_create_vht_cap(ar, rate_cap_tx_chainmask,
3519 rate_cap_rx_chainmask);
3523 static int ath11k_check_chain_mask(struct ath11k *ar, u32 ant, bool is_tx_ant)
3525 /* TODO: Check the request chainmask against the supported
3526 * chainmask table which is advertised in extented_service_ready event
3532 static void ath11k_gen_ppe_thresh(struct ath11k_ppe_threshold *fw_ppet,
3538 he_ppet[0] = fw_ppet->numss_m1 & IEEE80211_PPE_THRES_NSS_MASK;
3539 he_ppet[0] |= (fw_ppet->ru_bit_mask <<
3540 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_POS) &
3541 IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK;
3542 for (nss = 0; nss <= fw_ppet->numss_m1; nss++) {
3543 for (ru = 0; ru < 4; ru++) {
3547 if ((fw_ppet->ru_bit_mask & BIT(ru)) == 0)
3549 val = (fw_ppet->ppet16_ppet8_ru3_ru0[nss] >> (ru * 6)) &
3551 val = ((val >> 3) & 0x7) | ((val & 0x7) << 3);
3552 for (i = 5; i >= 0; i--) {
3554 ((val >> i) & 0x1) << ((bit % 8));
3562 ath11k_mac_filter_he_cap_mesh(struct ieee80211_he_cap_elem *he_cap_elem)
3566 m = IEEE80211_HE_MAC_CAP0_TWT_RES |
3567 IEEE80211_HE_MAC_CAP0_TWT_REQ;
3568 he_cap_elem->mac_cap_info[0] &= ~m;
3570 m = IEEE80211_HE_MAC_CAP2_TRS |
3571 IEEE80211_HE_MAC_CAP2_BCAST_TWT |
3572 IEEE80211_HE_MAC_CAP2_MU_CASCADING;
3573 he_cap_elem->mac_cap_info[2] &= ~m;
3575 m = IEEE80211_HE_MAC_CAP3_FLEX_TWT_SCHED |
3576 IEEE80211_HE_MAC_CAP2_BCAST_TWT |
3577 IEEE80211_HE_MAC_CAP2_MU_CASCADING;
3578 he_cap_elem->mac_cap_info[3] &= ~m;
3580 m = IEEE80211_HE_MAC_CAP4_BSRP_BQRP_A_MPDU_AGG |
3581 IEEE80211_HE_MAC_CAP4_BQR;
3582 he_cap_elem->mac_cap_info[4] &= ~m;
3584 m = IEEE80211_HE_MAC_CAP5_SUBCHAN_SELECVITE_TRANSMISSION |
3585 IEEE80211_HE_MAC_CAP5_UL_2x996_TONE_RU |
3586 IEEE80211_HE_MAC_CAP5_PUNCTURED_SOUNDING |
3587 IEEE80211_HE_MAC_CAP5_HT_VHT_TRIG_FRAME_RX;
3588 he_cap_elem->mac_cap_info[5] &= ~m;
3590 m = IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
3591 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO;
3592 he_cap_elem->phy_cap_info[2] &= ~m;
3594 m = IEEE80211_HE_PHY_CAP3_RX_HE_MU_PPDU_FROM_NON_AP_STA |
3595 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK |
3596 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_MASK;
3597 he_cap_elem->phy_cap_info[3] &= ~m;
3599 m = IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
3600 he_cap_elem->phy_cap_info[4] &= ~m;
3602 m = IEEE80211_HE_PHY_CAP5_NG16_MU_FEEDBACK;
3603 he_cap_elem->phy_cap_info[5] &= ~m;
3605 m = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU |
3606 IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMER_FB |
3607 IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB |
3608 IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO;
3609 he_cap_elem->phy_cap_info[6] &= ~m;
3611 m = IEEE80211_HE_PHY_CAP7_SRP_BASED_SR |
3612 IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_AR |
3613 IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ |
3614 IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ;
3615 he_cap_elem->phy_cap_info[7] &= ~m;
3617 m = IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI |
3618 IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G |
3619 IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU |
3620 IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU;
3621 he_cap_elem->phy_cap_info[8] &= ~m;
3623 m = IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM |
3624 IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK |
3625 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU |
3626 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU |
3627 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB |
3628 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB;
3629 he_cap_elem->phy_cap_info[9] &= ~m;
3632 static __le16 ath11k_mac_setup_he_6ghz_cap(struct ath11k_pdev_cap *pcap,
3633 struct ath11k_band_cap *bcap)
3637 bcap->he_6ghz_capa = IEEE80211_HT_MPDU_DENSITY_NONE;
3638 if (bcap->ht_cap_info & WMI_HT_CAP_DYNAMIC_SMPS)
3639 bcap->he_6ghz_capa |=
3640 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_SM_PS,
3641 WLAN_HT_CAP_SM_PS_DYNAMIC);
3643 bcap->he_6ghz_capa |=
3644 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_SM_PS,
3645 WLAN_HT_CAP_SM_PS_DISABLED);
3646 val = FIELD_GET(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK,
3648 bcap->he_6ghz_capa |=
3649 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP, val);
3650 val = FIELD_GET(IEEE80211_VHT_CAP_MAX_MPDU_MASK, pcap->vht_cap);
3651 bcap->he_6ghz_capa |=
3652 FIELD_PREP(IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN, val);
3653 if (pcap->vht_cap & IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN)
3654 bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS;
3655 if (pcap->vht_cap & IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN)
3656 bcap->he_6ghz_capa |= IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS;
3658 return cpu_to_le16(bcap->he_6ghz_capa);
3661 static int ath11k_mac_copy_he_cap(struct ath11k *ar,
3662 struct ath11k_pdev_cap *cap,
3663 struct ieee80211_sband_iftype_data *data,
3668 for (i = 0; i < NUM_NL80211_IFTYPES; i++) {
3669 struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap;
3670 struct ath11k_band_cap *band_cap = &cap->band[band];
3671 struct ieee80211_he_cap_elem *he_cap_elem =
3672 &he_cap->he_cap_elem;
3675 case NL80211_IFTYPE_STATION:
3676 case NL80211_IFTYPE_AP:
3677 case NL80211_IFTYPE_MESH_POINT:
3684 data[idx].types_mask = BIT(i);
3685 he_cap->has_he = true;
3686 memcpy(he_cap_elem->mac_cap_info, band_cap->he_cap_info,
3687 sizeof(he_cap_elem->mac_cap_info));
3688 memcpy(he_cap_elem->phy_cap_info, band_cap->he_cap_phy_info,
3689 sizeof(he_cap_elem->phy_cap_info));
3691 he_cap_elem->mac_cap_info[1] &=
3692 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_MASK;
3693 he_cap_elem->phy_cap_info[4] &=
3694 ~IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_MASK;
3695 he_cap_elem->phy_cap_info[4] &=
3696 ~IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_MASK;
3697 he_cap_elem->phy_cap_info[4] |= (ar->num_tx_chains - 1) << 2;
3699 he_cap_elem->phy_cap_info[5] &=
3700 ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK;
3701 he_cap_elem->phy_cap_info[5] &=
3702 ~IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK;
3703 he_cap_elem->phy_cap_info[5] |= ar->num_tx_chains - 1;
3706 case NL80211_IFTYPE_AP:
3707 he_cap_elem->phy_cap_info[3] &=
3708 ~IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_MASK;
3709 he_cap_elem->phy_cap_info[9] |=
3710 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU;
3712 case NL80211_IFTYPE_STATION:
3713 he_cap_elem->mac_cap_info[0] &=
3714 ~IEEE80211_HE_MAC_CAP0_TWT_RES;
3715 he_cap_elem->mac_cap_info[0] |=
3716 IEEE80211_HE_MAC_CAP0_TWT_REQ;
3717 he_cap_elem->phy_cap_info[9] |=
3718 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU;
3720 case NL80211_IFTYPE_MESH_POINT:
3721 ath11k_mac_filter_he_cap_mesh(he_cap_elem);
3725 he_cap->he_mcs_nss_supp.rx_mcs_80 =
3726 cpu_to_le16(band_cap->he_mcs & 0xffff);
3727 he_cap->he_mcs_nss_supp.tx_mcs_80 =
3728 cpu_to_le16(band_cap->he_mcs & 0xffff);
3729 he_cap->he_mcs_nss_supp.rx_mcs_160 =
3730 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
3731 he_cap->he_mcs_nss_supp.tx_mcs_160 =
3732 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
3733 he_cap->he_mcs_nss_supp.rx_mcs_80p80 =
3734 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
3735 he_cap->he_mcs_nss_supp.tx_mcs_80p80 =
3736 cpu_to_le16((band_cap->he_mcs >> 16) & 0xffff);
3738 memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres));
3739 if (he_cap_elem->phy_cap_info[6] &
3740 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT)
3741 ath11k_gen_ppe_thresh(&band_cap->he_ppet,
3744 if (band == NL80211_BAND_6GHZ) {
3745 data[idx].he_6ghz_capa.capa =
3746 ath11k_mac_setup_he_6ghz_cap(cap, band_cap);
3754 static void ath11k_mac_setup_he_cap(struct ath11k *ar,
3755 struct ath11k_pdev_cap *cap)
3757 struct ieee80211_supported_band *band;
3760 if (cap->supported_bands & WMI_HOST_WLAN_2G_CAP) {
3761 count = ath11k_mac_copy_he_cap(ar, cap,
3762 ar->mac.iftype[NL80211_BAND_2GHZ],
3764 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
3765 band->iftype_data = ar->mac.iftype[NL80211_BAND_2GHZ];
3766 band->n_iftype_data = count;
3769 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP) {
3770 count = ath11k_mac_copy_he_cap(ar, cap,
3771 ar->mac.iftype[NL80211_BAND_5GHZ],
3773 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
3774 band->iftype_data = ar->mac.iftype[NL80211_BAND_5GHZ];
3775 band->n_iftype_data = count;
3778 if (cap->supported_bands & WMI_HOST_WLAN_5G_CAP &&
3779 ar->supports_6ghz) {
3780 count = ath11k_mac_copy_he_cap(ar, cap,
3781 ar->mac.iftype[NL80211_BAND_6GHZ],
3783 band = &ar->mac.sbands[NL80211_BAND_6GHZ];
3784 band->iftype_data = ar->mac.iftype[NL80211_BAND_6GHZ];
3785 band->n_iftype_data = count;
3789 static int __ath11k_set_antenna(struct ath11k *ar, u32 tx_ant, u32 rx_ant)
3793 lockdep_assert_held(&ar->conf_mutex);
3795 if (ath11k_check_chain_mask(ar, tx_ant, true))
3798 if (ath11k_check_chain_mask(ar, rx_ant, false))
3801 ar->cfg_tx_chainmask = tx_ant;
3802 ar->cfg_rx_chainmask = rx_ant;
3804 if (ar->state != ATH11K_STATE_ON &&
3805 ar->state != ATH11K_STATE_RESTARTED)
3808 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_TX_CHAIN_MASK,
3809 tx_ant, ar->pdev->pdev_id);
3811 ath11k_warn(ar->ab, "failed to set tx-chainmask: %d, req 0x%x\n",
3816 ar->num_tx_chains = get_num_chains(tx_ant);
3818 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_RX_CHAIN_MASK,
3819 rx_ant, ar->pdev->pdev_id);
3821 ath11k_warn(ar->ab, "failed to set rx-chainmask: %d, req 0x%x\n",
3826 ar->num_rx_chains = get_num_chains(rx_ant);
3828 /* Reload HT/VHT/HE capability */
3829 ath11k_mac_setup_ht_vht_cap(ar, &ar->pdev->cap, NULL);
3830 ath11k_mac_setup_he_cap(ar, &ar->pdev->cap);
3835 int ath11k_mac_tx_mgmt_pending_free(int buf_id, void *skb, void *ctx)
3837 struct sk_buff *msdu = skb;
3838 struct ieee80211_tx_info *info;
3839 struct ath11k *ar = ctx;
3840 struct ath11k_base *ab = ar->ab;
3842 spin_lock_bh(&ar->txmgmt_idr_lock);
3843 idr_remove(&ar->txmgmt_idr, buf_id);
3844 spin_unlock_bh(&ar->txmgmt_idr_lock);
3845 dma_unmap_single(ab->dev, ATH11K_SKB_CB(msdu)->paddr, msdu->len,
3848 info = IEEE80211_SKB_CB(msdu);
3849 memset(&info->status, 0, sizeof(info->status));
3851 ieee80211_free_txskb(ar->hw, msdu);
3856 static int ath11k_mac_vif_txmgmt_idr_remove(int buf_id, void *skb, void *ctx)
3858 struct ieee80211_vif *vif = ctx;
3859 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb);
3860 struct sk_buff *msdu = skb;
3861 struct ath11k *ar = skb_cb->ar;
3862 struct ath11k_base *ab = ar->ab;
3864 if (skb_cb->vif == vif) {
3865 spin_lock_bh(&ar->txmgmt_idr_lock);
3866 idr_remove(&ar->txmgmt_idr, buf_id);
3867 spin_unlock_bh(&ar->txmgmt_idr_lock);
3868 dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len,
3875 static int ath11k_mac_mgmt_tx_wmi(struct ath11k *ar, struct ath11k_vif *arvif,
3876 struct sk_buff *skb)
3878 struct ath11k_base *ab = ar->ab;
3879 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
3880 struct ieee80211_tx_info *info;
3885 spin_lock_bh(&ar->txmgmt_idr_lock);
3886 buf_id = idr_alloc(&ar->txmgmt_idr, skb, 0,
3887 ATH11K_TX_MGMT_NUM_PENDING_MAX, GFP_ATOMIC);
3888 spin_unlock_bh(&ar->txmgmt_idr_lock);
3892 info = IEEE80211_SKB_CB(skb);
3893 if (!(info->control.flags & IEEE80211_TX_CTRL_HW_80211_ENCAP)) {
3894 if ((ieee80211_is_action(hdr->frame_control) ||
3895 ieee80211_is_deauth(hdr->frame_control) ||
3896 ieee80211_is_disassoc(hdr->frame_control)) &&
3897 ieee80211_has_protected(hdr->frame_control)) {
3898 skb_put(skb, IEEE80211_CCMP_MIC_LEN);
3902 paddr = dma_map_single(ab->dev, skb->data, skb->len, DMA_TO_DEVICE);
3903 if (dma_mapping_error(ab->dev, paddr)) {
3904 ath11k_warn(ab, "failed to DMA map mgmt Tx buffer\n");
3909 ATH11K_SKB_CB(skb)->paddr = paddr;
3911 ret = ath11k_wmi_mgmt_send(ar, arvif->vdev_id, buf_id, skb);
3913 ath11k_warn(ar->ab, "failed to send mgmt frame: %d\n", ret);
3920 dma_unmap_single(ab->dev, ATH11K_SKB_CB(skb)->paddr,
3921 skb->len, DMA_TO_DEVICE);
3923 spin_lock_bh(&ar->txmgmt_idr_lock);
3924 idr_remove(&ar->txmgmt_idr, buf_id);
3925 spin_unlock_bh(&ar->txmgmt_idr_lock);
3930 static void ath11k_mgmt_over_wmi_tx_purge(struct ath11k *ar)
3932 struct sk_buff *skb;
3934 while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL)
3935 ieee80211_free_txskb(ar->hw, skb);
3938 static void ath11k_mgmt_over_wmi_tx_work(struct work_struct *work)
3940 struct ath11k *ar = container_of(work, struct ath11k, wmi_mgmt_tx_work);
3941 struct ieee80211_tx_info *info;
3942 struct ath11k_vif *arvif;
3943 struct sk_buff *skb;
3946 while ((skb = skb_dequeue(&ar->wmi_mgmt_tx_queue)) != NULL) {
3947 info = IEEE80211_SKB_CB(skb);
3948 if (!info->control.vif) {
3949 ath11k_warn(ar->ab, "no vif found for mgmt frame, flags 0x%x\n",
3950 info->control.flags);
3951 ieee80211_free_txskb(ar->hw, skb);
3955 arvif = ath11k_vif_to_arvif(info->control.vif);
3956 if (ar->allocated_vdev_map & (1LL << arvif->vdev_id) &&
3957 arvif->is_started) {
3958 ret = ath11k_mac_mgmt_tx_wmi(ar, arvif, skb);
3960 ath11k_warn(ar->ab, "failed to tx mgmt frame, vdev_id %d :%d\n",
3961 arvif->vdev_id, ret);
3962 ieee80211_free_txskb(ar->hw, skb);
3964 atomic_inc(&ar->num_pending_mgmt_tx);
3968 "dropping mgmt frame for vdev %d, flags 0x%x is_started %d\n",
3969 arvif->vdev_id, info->control.flags,
3971 ieee80211_free_txskb(ar->hw, skb);
3976 static int ath11k_mac_mgmt_tx(struct ath11k *ar, struct sk_buff *skb,
3979 struct sk_buff_head *q = &ar->wmi_mgmt_tx_queue;
3981 if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))
3984 /* Drop probe response packets when the pending management tx
3985 * count has reached a certain threshold, so as to prioritize
3986 * other mgmt packets like auth and assoc to be sent on time
3987 * for establishing successful connections.
3990 atomic_read(&ar->num_pending_mgmt_tx) > ATH11K_PRB_RSP_DROP_THRESHOLD) {
3992 "dropping probe response as pending queue is almost full\n");
3996 if (skb_queue_len(q) == ATH11K_TX_MGMT_NUM_PENDING_MAX) {
3997 ath11k_warn(ar->ab, "mgmt tx queue is full\n");
4001 skb_queue_tail(q, skb);
4002 ieee80211_queue_work(ar->hw, &ar->wmi_mgmt_tx_work);
4007 static void ath11k_mac_op_tx(struct ieee80211_hw *hw,
4008 struct ieee80211_tx_control *control,
4009 struct sk_buff *skb)
4011 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb);
4012 struct ath11k *ar = hw->priv;
4013 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
4014 struct ieee80211_vif *vif = info->control.vif;
4015 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4016 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
4020 if (info->control.flags & IEEE80211_TX_CTRL_HW_80211_ENCAP) {
4021 skb_cb->flags |= ATH11K_SKB_HW_80211_ENCAP;
4022 } else if (ieee80211_is_mgmt(hdr->frame_control)) {
4023 is_prb_rsp = ieee80211_is_probe_resp(hdr->frame_control);
4024 ret = ath11k_mac_mgmt_tx(ar, skb, is_prb_rsp);
4026 ath11k_warn(ar->ab, "failed to queue management frame %d\n",
4028 ieee80211_free_txskb(ar->hw, skb);
4033 ret = ath11k_dp_tx(ar, arvif, skb);
4035 ath11k_warn(ar->ab, "failed to transmit frame %d\n", ret);
4036 ieee80211_free_txskb(ar->hw, skb);
4040 void ath11k_mac_drain_tx(struct ath11k *ar)
4042 /* make sure rcu-protected mac80211 tx path itself is drained */
4045 cancel_work_sync(&ar->wmi_mgmt_tx_work);
4046 ath11k_mgmt_over_wmi_tx_purge(ar);
4049 static int ath11k_mac_config_mon_status_default(struct ath11k *ar, bool enable)
4051 struct htt_rx_ring_tlv_filter tlv_filter = {0};
4055 tlv_filter = ath11k_mac_mon_status_filter_default;
4056 tlv_filter.rx_filter = ath11k_debug_rx_filter(ar);
4059 ring_id = ar->dp.rx_mon_status_refill_ring.refill_buf_ring.ring_id;
4061 return ath11k_dp_tx_htt_rx_filter_setup(ar->ab, ring_id, ar->dp.mac_id,
4062 HAL_RXDMA_MONITOR_STATUS,
4063 DP_RX_BUFFER_SIZE, &tlv_filter);
4066 static int ath11k_mac_op_start(struct ieee80211_hw *hw)
4068 struct ath11k *ar = hw->priv;
4069 struct ath11k_base *ab = ar->ab;
4070 struct ath11k_pdev *pdev = ar->pdev;
4073 ath11k_mac_drain_tx(ar);
4074 mutex_lock(&ar->conf_mutex);
4076 switch (ar->state) {
4077 case ATH11K_STATE_OFF:
4078 ar->state = ATH11K_STATE_ON;
4080 case ATH11K_STATE_RESTARTING:
4081 ar->state = ATH11K_STATE_RESTARTED;
4083 case ATH11K_STATE_RESTARTED:
4084 case ATH11K_STATE_WEDGED:
4085 case ATH11K_STATE_ON:
4091 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_PMF_QOS,
4095 ath11k_err(ar->ab, "failed to enable PMF QOS: (%d\n", ret);
4099 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_DYNAMIC_BW, 1,
4102 ath11k_err(ar->ab, "failed to enable dynamic bw: %d\n", ret);
4106 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_ARP_AC_OVERRIDE,
4109 ath11k_err(ab, "failed to set ac override for ARP: %d\n",
4114 ret = ath11k_wmi_send_dfs_phyerr_offload_enable_cmd(ar, pdev->pdev_id);
4116 ath11k_err(ab, "failed to offload radar detection: %d\n",
4121 ret = ath11k_dp_tx_htt_h2t_ppdu_stats_req(ar,
4122 HTT_PPDU_STATS_TAG_DEFAULT);
4124 ath11k_err(ab, "failed to req ppdu stats: %d\n", ret);
4128 ret = ath11k_wmi_pdev_set_param(ar, WMI_PDEV_PARAM_MESH_MCAST_ENABLE,
4132 ath11k_err(ar->ab, "failed to enable MESH MCAST ENABLE: (%d\n", ret);
4136 __ath11k_set_antenna(ar, ar->cfg_tx_chainmask, ar->cfg_rx_chainmask);
4138 /* TODO: Do we need to enable ANI? */
4140 ath11k_reg_update_chan_list(ar);
4142 ar->num_started_vdevs = 0;
4143 ar->num_created_vdevs = 0;
4145 ar->allocated_vdev_map = 0;
4147 /* Configure monitor status ring with default rx_filter to get rx status
4148 * such as rssi, rx_duration.
4150 ret = ath11k_mac_config_mon_status_default(ar, true);
4152 ath11k_err(ab, "failed to configure monitor status ring with default rx_filter: (%d)\n",
4157 /* Configure the hash seed for hash based reo dest ring selection */
4158 ath11k_wmi_pdev_lro_cfg(ar, ar->pdev->pdev_id);
4160 mutex_unlock(&ar->conf_mutex);
4162 rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx],
4163 &ab->pdevs[ar->pdev_idx]);
4168 ar->state = ATH11K_STATE_OFF;
4169 mutex_unlock(&ar->conf_mutex);
4174 static void ath11k_mac_op_stop(struct ieee80211_hw *hw)
4176 struct ath11k *ar = hw->priv;
4177 struct htt_ppdu_stats_info *ppdu_stats, *tmp;
4180 ath11k_mac_drain_tx(ar);
4182 mutex_lock(&ar->conf_mutex);
4183 ret = ath11k_mac_config_mon_status_default(ar, false);
4185 ath11k_err(ar->ab, "failed to clear rx_filter for monitor status ring: (%d)\n",
4188 clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
4189 ar->state = ATH11K_STATE_OFF;
4190 mutex_unlock(&ar->conf_mutex);
4192 cancel_delayed_work_sync(&ar->scan.timeout);
4193 cancel_work_sync(&ar->regd_update_work);
4195 spin_lock_bh(&ar->data_lock);
4196 list_for_each_entry_safe(ppdu_stats, tmp, &ar->ppdu_stats_info, list) {
4197 list_del(&ppdu_stats->list);
4200 spin_unlock_bh(&ar->data_lock);
4202 rcu_assign_pointer(ar->ab->pdevs_active[ar->pdev_idx], NULL);
4206 atomic_set(&ar->num_pending_mgmt_tx, 0);
4210 ath11k_mac_setup_vdev_create_params(struct ath11k_vif *arvif,
4211 struct vdev_create_params *params)
4213 struct ath11k *ar = arvif->ar;
4214 struct ath11k_pdev *pdev = ar->pdev;
4216 params->if_id = arvif->vdev_id;
4217 params->type = arvif->vdev_type;
4218 params->subtype = arvif->vdev_subtype;
4219 params->pdev_id = pdev->pdev_id;
4221 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP) {
4222 params->chains[NL80211_BAND_2GHZ].tx = ar->num_tx_chains;
4223 params->chains[NL80211_BAND_2GHZ].rx = ar->num_rx_chains;
4225 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP) {
4226 params->chains[NL80211_BAND_5GHZ].tx = ar->num_tx_chains;
4227 params->chains[NL80211_BAND_5GHZ].rx = ar->num_rx_chains;
4229 if (pdev->cap.supported_bands & WMI_HOST_WLAN_5G_CAP &&
4230 ar->supports_6ghz) {
4231 params->chains[NL80211_BAND_6GHZ].tx = ar->num_tx_chains;
4232 params->chains[NL80211_BAND_6GHZ].rx = ar->num_rx_chains;
4237 ath11k_mac_prepare_he_mode(struct ath11k_pdev *pdev, u32 viftype)
4239 struct ath11k_pdev_cap *pdev_cap = &pdev->cap;
4240 struct ath11k_band_cap *cap_band = NULL;
4241 u32 *hecap_phy_ptr = NULL;
4244 if (pdev->cap.supported_bands & WMI_HOST_WLAN_2G_CAP)
4245 cap_band = &pdev_cap->band[NL80211_BAND_2GHZ];
4247 cap_band = &pdev_cap->band[NL80211_BAND_5GHZ];
4249 hecap_phy_ptr = &cap_band->he_cap_phy_info[0];
4251 hemode = FIELD_PREP(HE_MODE_SU_TX_BFEE, HE_SU_BFEE_ENABLE) |
4252 FIELD_PREP(HE_MODE_SU_TX_BFER, HECAP_PHY_SUBFMR_GET(hecap_phy_ptr)) |
4253 FIELD_PREP(HE_MODE_UL_MUMIMO, HECAP_PHY_ULMUMIMO_GET(hecap_phy_ptr));
4255 /* TODO WDS and other modes */
4256 if (viftype == NL80211_IFTYPE_AP) {
4257 hemode |= FIELD_PREP(HE_MODE_MU_TX_BFER,
4258 HECAP_PHY_MUBFMR_GET(hecap_phy_ptr)) |
4259 FIELD_PREP(HE_MODE_DL_OFDMA, HE_DL_MUOFDMA_ENABLE) |
4260 FIELD_PREP(HE_MODE_UL_OFDMA, HE_UL_MUOFDMA_ENABLE);
4262 hemode |= FIELD_PREP(HE_MODE_MU_TX_BFEE, HE_MU_BFEE_ENABLE);
4268 static int ath11k_set_he_mu_sounding_mode(struct ath11k *ar,
4269 struct ath11k_vif *arvif)
4271 u32 param_id, param_value;
4272 struct ath11k_base *ab = ar->ab;
4275 param_id = WMI_VDEV_PARAM_SET_HEMU_MODE;
4276 param_value = ath11k_mac_prepare_he_mode(ar->pdev, arvif->vif->type);
4277 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4278 param_id, param_value);
4280 ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d param_value %x\n",
4281 arvif->vdev_id, ret, param_value);
4284 param_id = WMI_VDEV_PARAM_SET_HE_SOUNDING_MODE;
4286 FIELD_PREP(HE_VHT_SOUNDING_MODE, HE_VHT_SOUNDING_MODE_ENABLE) |
4287 FIELD_PREP(HE_TRIG_NONTRIG_SOUNDING_MODE,
4288 HE_TRIG_NONTRIG_SOUNDING_MODE_ENABLE);
4289 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4290 param_id, param_value);
4292 ath11k_warn(ab, "failed to set vdev %d HE MU mode: %d\n",
4293 arvif->vdev_id, ret);
4299 static int ath11k_mac_op_add_interface(struct ieee80211_hw *hw,
4300 struct ieee80211_vif *vif)
4302 struct ath11k *ar = hw->priv;
4303 struct ath11k_base *ab = ar->ab;
4304 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4305 struct vdev_create_params vdev_param = {0};
4306 struct peer_create_params peer_param;
4307 u32 param_id, param_value;
4314 vif->driver_flags |= IEEE80211_VIF_SUPPORTS_UAPSD;
4316 mutex_lock(&ar->conf_mutex);
4318 if (vif->type == NL80211_IFTYPE_AP &&
4319 ar->num_peers > (ar->max_num_peers - 1)) {
4320 ath11k_warn(ab, "failed to create vdev due to insufficient peer entry resource in firmware\n");
4325 if (ar->num_created_vdevs > (TARGET_NUM_VDEVS - 1)) {
4326 ath11k_warn(ab, "failed to create vdev, reached max vdev limit %d\n",
4332 memset(arvif, 0, sizeof(*arvif));
4337 INIT_LIST_HEAD(&arvif->list);
4339 /* Should we initialize any worker to handle connection loss indication
4340 * from firmware in sta mode?
4343 for (i = 0; i < ARRAY_SIZE(arvif->bitrate_mask.control); i++) {
4344 arvif->bitrate_mask.control[i].legacy = 0xffffffff;
4345 memset(arvif->bitrate_mask.control[i].ht_mcs, 0xff,
4346 sizeof(arvif->bitrate_mask.control[i].ht_mcs));
4347 memset(arvif->bitrate_mask.control[i].vht_mcs, 0xff,
4348 sizeof(arvif->bitrate_mask.control[i].vht_mcs));
4351 bit = __ffs64(ab->free_vdev_map);
4353 arvif->vdev_id = bit;
4354 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_NONE;
4356 switch (vif->type) {
4357 case NL80211_IFTYPE_UNSPECIFIED:
4358 case NL80211_IFTYPE_STATION:
4359 arvif->vdev_type = WMI_VDEV_TYPE_STA;
4361 case NL80211_IFTYPE_MESH_POINT:
4362 arvif->vdev_subtype = WMI_VDEV_SUBTYPE_MESH_11S;
4364 case NL80211_IFTYPE_AP:
4365 arvif->vdev_type = WMI_VDEV_TYPE_AP;
4367 case NL80211_IFTYPE_MONITOR:
4368 arvif->vdev_type = WMI_VDEV_TYPE_MONITOR;
4375 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac add interface id %d type %d subtype %d map %llx\n",
4376 arvif->vdev_id, arvif->vdev_type, arvif->vdev_subtype,
4379 vif->cab_queue = arvif->vdev_id % (ATH11K_HW_MAX_QUEUES - 1);
4380 for (i = 0; i < ARRAY_SIZE(vif->hw_queue); i++)
4381 vif->hw_queue[i] = i % (ATH11K_HW_MAX_QUEUES - 1);
4383 ath11k_mac_setup_vdev_create_params(arvif, &vdev_param);
4385 ret = ath11k_wmi_vdev_create(ar, vif->addr, &vdev_param);
4387 ath11k_warn(ab, "failed to create WMI vdev %d: %d\n",
4388 arvif->vdev_id, ret);
4392 ar->num_created_vdevs++;
4393 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM created, vdev_id %d\n",
4394 vif->addr, arvif->vdev_id);
4395 ar->allocated_vdev_map |= 1LL << arvif->vdev_id;
4396 ab->free_vdev_map &= ~(1LL << arvif->vdev_id);
4398 spin_lock_bh(&ar->data_lock);
4399 list_add(&arvif->list, &ar->arvifs);
4400 spin_unlock_bh(&ar->data_lock);
4402 param_id = WMI_VDEV_PARAM_TX_ENCAP_TYPE;
4403 if (ath11k_frame_mode == ATH11K_HW_TXRX_ETHERNET)
4404 switch (vif->type) {
4405 case NL80211_IFTYPE_STATION:
4406 case NL80211_IFTYPE_AP_VLAN:
4407 case NL80211_IFTYPE_AP:
4414 if (ieee80211_set_hw_80211_encap(vif, hw_encap))
4415 param_value = ATH11K_HW_TXRX_ETHERNET;
4417 param_value = ATH11K_HW_TXRX_NATIVE_WIFI;
4419 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4420 param_id, param_value);
4422 ath11k_warn(ab, "failed to set vdev %d tx encap mode: %d\n",
4423 arvif->vdev_id, ret);
4427 nss = get_num_chains(ar->cfg_tx_chainmask) ? : 1;
4428 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4429 WMI_VDEV_PARAM_NSS, nss);
4431 ath11k_warn(ab, "failed to set vdev %d chainmask 0x%x, nss %d :%d\n",
4432 arvif->vdev_id, ar->cfg_tx_chainmask, nss, ret);
4436 switch (arvif->vdev_type) {
4437 case WMI_VDEV_TYPE_AP:
4438 peer_param.vdev_id = arvif->vdev_id;
4439 peer_param.peer_addr = vif->addr;
4440 peer_param.peer_type = WMI_PEER_TYPE_DEFAULT;
4441 ret = ath11k_peer_create(ar, arvif, NULL, &peer_param);
4443 ath11k_warn(ab, "failed to vdev %d create peer for AP: %d\n",
4444 arvif->vdev_id, ret);
4448 ret = ath11k_mac_set_kickout(arvif);
4450 ath11k_warn(ar->ab, "failed to set vdev %i kickout parameters: %d\n",
4451 arvif->vdev_id, ret);
4455 case WMI_VDEV_TYPE_STA:
4456 param_id = WMI_STA_PS_PARAM_RX_WAKE_POLICY;
4457 param_value = WMI_STA_PS_RX_WAKE_POLICY_WAKE;
4458 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4459 param_id, param_value);
4461 ath11k_warn(ar->ab, "failed to set vdev %d RX wake policy: %d\n",
4462 arvif->vdev_id, ret);
4466 param_id = WMI_STA_PS_PARAM_TX_WAKE_THRESHOLD;
4467 param_value = WMI_STA_PS_TX_WAKE_THRESHOLD_ALWAYS;
4468 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4469 param_id, param_value);
4471 ath11k_warn(ar->ab, "failed to set vdev %d TX wake threshold: %d\n",
4472 arvif->vdev_id, ret);
4476 param_id = WMI_STA_PS_PARAM_PSPOLL_COUNT;
4477 param_value = WMI_STA_PS_PSPOLL_COUNT_NO_MAX;
4478 ret = ath11k_wmi_set_sta_ps_param(ar, arvif->vdev_id,
4479 param_id, param_value);
4481 ath11k_warn(ar->ab, "failed to set vdev %d pspoll count: %d\n",
4482 arvif->vdev_id, ret);
4486 ret = ath11k_wmi_pdev_set_ps_mode(ar, arvif->vdev_id, false);
4488 ath11k_warn(ar->ab, "failed to disable vdev %d ps mode: %d\n",
4489 arvif->vdev_id, ret);
4497 arvif->txpower = vif->bss_conf.txpower;
4498 ret = ath11k_mac_txpower_recalc(ar);
4502 param_id = WMI_VDEV_PARAM_RTS_THRESHOLD;
4503 param_value = ar->hw->wiphy->rts_threshold;
4504 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
4505 param_id, param_value);
4507 ath11k_warn(ar->ab, "failed to set rts threshold for vdev %d: %d\n",
4508 arvif->vdev_id, ret);
4511 ath11k_dp_vdev_tx_attach(ar, arvif);
4513 mutex_unlock(&ar->conf_mutex);
4518 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4520 ath11k_wmi_send_peer_delete_cmd(ar, vif->addr, arvif->vdev_id);
4524 ath11k_wmi_vdev_delete(ar, arvif->vdev_id);
4525 ar->num_created_vdevs--;
4526 ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id);
4527 ab->free_vdev_map |= 1LL << arvif->vdev_id;
4528 spin_lock_bh(&ar->data_lock);
4529 list_del(&arvif->list);
4530 spin_unlock_bh(&ar->data_lock);
4533 mutex_unlock(&ar->conf_mutex);
4538 static int ath11k_mac_vif_unref(int buf_id, void *skb, void *ctx)
4540 struct ieee80211_vif *vif = (struct ieee80211_vif *)ctx;
4541 struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB((struct sk_buff *)skb);
4543 if (skb_cb->vif == vif)
4549 static void ath11k_mac_op_remove_interface(struct ieee80211_hw *hw,
4550 struct ieee80211_vif *vif)
4552 struct ath11k *ar = hw->priv;
4553 struct ath11k_vif *arvif = ath11k_vif_to_arvif(vif);
4554 struct ath11k_base *ab = ar->ab;
4558 mutex_lock(&ar->conf_mutex);
4560 ath11k_dbg(ab, ATH11K_DBG_MAC, "mac remove interface (vdev %d)\n",
4563 spin_lock_bh(&ar->data_lock);
4564 list_del(&arvif->list);
4565 spin_unlock_bh(&ar->data_lock);
4567 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4568 ret = ath11k_peer_delete(ar, arvif->vdev_id, vif->addr);
4570 ath11k_warn(ab, "failed to submit AP self-peer removal on vdev %d: %d\n",
4571 arvif->vdev_id, ret);
4574 ret = ath11k_wmi_vdev_delete(ar, arvif->vdev_id);
4576 ath11k_warn(ab, "failed to delete WMI vdev %d: %d\n",
4577 arvif->vdev_id, ret);
4579 ar->num_created_vdevs--;
4580 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM deleted, vdev_id %d\n",
4581 vif->addr, arvif->vdev_id);
4582 ar->allocated_vdev_map &= ~(1LL << arvif->vdev_id);
4583 ab->free_vdev_map |= 1LL << (arvif->vdev_id);
4585 ath11k_peer_cleanup(ar, arvif->vdev_id);
4587 idr_for_each(&ar->txmgmt_idr,
4588 ath11k_mac_vif_txmgmt_idr_remove, vif);
4590 for (i = 0; i < DP_TCL_NUM_RING_MAX; i++) {
4591 spin_lock_bh(&ab->dp.tx_ring[i].tx_idr_lock);
4592 idr_for_each(&ab->dp.tx_ring[i].txbuf_idr,
4593 ath11k_mac_vif_unref, vif);
4594 spin_unlock_bh(&ab->dp.tx_ring[i].tx_idr_lock);
4597 /* Recalc txpower for remaining vdev */
4598 ath11k_mac_txpower_recalc(ar);
4599 clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags);
4601 /* TODO: recal traffic pause state based on the available vdevs */
4603 mutex_unlock(&ar->conf_mutex);
4606 /* FIXME: Has to be verified. */
4607 #define SUPPORTED_FILTERS \
4612 FIF_BCN_PRBRESP_PROMISC | \
4616 static void ath11k_mac_op_configure_filter(struct ieee80211_hw *hw,
4617 unsigned int changed_flags,
4618 unsigned int *total_flags,
4621 struct ath11k *ar = hw->priv;
4622 bool reset_flag = false;
4625 mutex_lock(&ar->conf_mutex);
4627 changed_flags &= SUPPORTED_FILTERS;
4628 *total_flags &= SUPPORTED_FILTERS;
4629 ar->filter_flags = *total_flags;
4631 /* For monitor mode */
4632 reset_flag = !(ar->filter_flags & FIF_BCN_PRBRESP_PROMISC);
4634 ret = ath11k_dp_tx_htt_monitor_mode_ring_config(ar, reset_flag);
4637 set_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags);
4639 clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags);
4642 "fail to set monitor filter: %d\n", ret);
4644 mutex_unlock(&ar->conf_mutex);
4647 static int ath11k_mac_op_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
4649 struct ath11k *ar = hw->priv;
4651 mutex_lock(&ar->conf_mutex);
4653 *tx_ant = ar->cfg_tx_chainmask;
4654 *rx_ant = ar->cfg_rx_chainmask;
4656 mutex_unlock(&ar->conf_mutex);
4661 static int ath11k_mac_op_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
4663 struct ath11k *ar = hw->priv;
4666 mutex_lock(&ar->conf_mutex);
4667 ret = __ath11k_set_antenna(ar, tx_ant, rx_ant);
4668 mutex_unlock(&ar->conf_mutex);
4673 static int ath11k_mac_op_ampdu_action(struct ieee80211_hw *hw,
4674 struct ieee80211_vif *vif,
4675 struct ieee80211_ampdu_params *params)
4677 struct ath11k *ar = hw->priv;
4680 mutex_lock(&ar->conf_mutex);
4682 switch (params->action) {
4683 case IEEE80211_AMPDU_RX_START:
4684 ret = ath11k_dp_rx_ampdu_start(ar, params);
4686 case IEEE80211_AMPDU_RX_STOP:
4687 ret = ath11k_dp_rx_ampdu_stop(ar, params);
4689 case IEEE80211_AMPDU_TX_START:
4690 case IEEE80211_AMPDU_TX_STOP_CONT:
4691 case IEEE80211_AMPDU_TX_STOP_FLUSH:
4692 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
4693 case IEEE80211_AMPDU_TX_OPERATIONAL:
4694 /* Tx A-MPDU aggregation offloaded to hw/fw so deny mac80211
4695 * Tx aggregation requests.
4701 mutex_unlock(&ar->conf_mutex);
4706 static int ath11k_mac_op_add_chanctx(struct ieee80211_hw *hw,
4707 struct ieee80211_chanctx_conf *ctx)
4709 struct ath11k *ar = hw->priv;
4710 struct ath11k_base *ab = ar->ab;
4712 ath11k_dbg(ab, ATH11K_DBG_MAC,
4713 "mac chanctx add freq %hu width %d ptr %pK\n",
4714 ctx->def.chan->center_freq, ctx->def.width, ctx);
4716 mutex_lock(&ar->conf_mutex);
4718 spin_lock_bh(&ar->data_lock);
4719 /* TODO: In case of multiple channel context, populate rx_channel from
4720 * Rx PPDU desc information.
4722 ar->rx_channel = ctx->def.chan;
4723 spin_unlock_bh(&ar->data_lock);
4725 mutex_unlock(&ar->conf_mutex);
4730 static void ath11k_mac_op_remove_chanctx(struct ieee80211_hw *hw,
4731 struct ieee80211_chanctx_conf *ctx)
4733 struct ath11k *ar = hw->priv;
4734 struct ath11k_base *ab = ar->ab;
4736 ath11k_dbg(ab, ATH11K_DBG_MAC,
4737 "mac chanctx remove freq %hu width %d ptr %pK\n",
4738 ctx->def.chan->center_freq, ctx->def.width, ctx);
4740 mutex_lock(&ar->conf_mutex);
4742 spin_lock_bh(&ar->data_lock);
4743 /* TODO: In case of there is one more channel context left, populate
4744 * rx_channel with the channel of that remaining channel context.
4746 ar->rx_channel = NULL;
4747 spin_unlock_bh(&ar->data_lock);
4749 mutex_unlock(&ar->conf_mutex);
4752 static inline int ath11k_mac_vdev_setup_sync(struct ath11k *ar)
4754 lockdep_assert_held(&ar->conf_mutex);
4756 if (test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))
4759 if (!wait_for_completion_timeout(&ar->vdev_setup_done,
4760 ATH11K_VDEV_SETUP_TIMEOUT_HZ))
4763 return ar->last_wmi_vdev_start_status ? -EINVAL : 0;
4767 ath11k_mac_vdev_start_restart(struct ath11k_vif *arvif,
4768 const struct cfg80211_chan_def *chandef,
4771 struct ath11k *ar = arvif->ar;
4772 struct ath11k_base *ab = ar->ab;
4773 struct wmi_vdev_start_req_arg arg = {};
4774 int he_support = arvif->vif->bss_conf.he_support;
4777 lockdep_assert_held(&ar->conf_mutex);
4779 reinit_completion(&ar->vdev_setup_done);
4781 arg.vdev_id = arvif->vdev_id;
4782 arg.dtim_period = arvif->dtim_period;
4783 arg.bcn_intval = arvif->beacon_interval;
4785 arg.channel.freq = chandef->chan->center_freq;
4786 arg.channel.band_center_freq1 = chandef->center_freq1;
4787 arg.channel.band_center_freq2 = chandef->center_freq2;
4789 ath11k_phymodes[chandef->chan->band][chandef->width];
4791 arg.channel.min_power = 0;
4792 arg.channel.max_power = chandef->chan->max_power * 2;
4793 arg.channel.max_reg_power = chandef->chan->max_reg_power * 2;
4794 arg.channel.max_antenna_gain = chandef->chan->max_antenna_gain * 2;
4796 arg.pref_tx_streams = ar->num_tx_chains;
4797 arg.pref_rx_streams = ar->num_rx_chains;
4799 if (arvif->vdev_type == WMI_VDEV_TYPE_AP) {
4800 arg.ssid = arvif->u.ap.ssid;
4801 arg.ssid_len = arvif->u.ap.ssid_len;
4802 arg.hidden_ssid = arvif->u.ap.hidden_ssid;
4804 /* For now allow DFS for AP mode */
4805 arg.channel.chan_radar =
4806 !!(chandef->chan->flags & IEEE80211_CHAN_RADAR);
4808 arg.channel.passive = arg.channel.chan_radar;
4810 spin_lock_bh(&ab->base_lock);
4811 arg.regdomain = ar->ab->dfs_region;
4812 spin_unlock_bh(&ab->base_lock);
4814 /* TODO: Notify if secondary 80Mhz also needs radar detection */
4816 ret = ath11k_set_he_mu_sounding_mode(ar, arvif);
4818 ath11k_warn(ar->ab, "failed to set he mode vdev %i\n",
4825 arg.channel.passive |= !!(chandef->chan->flags & IEEE80211_CHAN_NO_IR);
4827 ath11k_dbg(ab, ATH11K_DBG_MAC,
4828 "mac vdev %d start center_freq %d phymode %s\n",
4829 arg.vdev_id, arg.channel.freq,
4830 ath11k_wmi_phymode_str(arg.channel.mode));
4832 ret = ath11k_wmi_vdev_start(ar, &arg, restart);
4834 ath11k_warn(ar->ab, "failed to %s WMI vdev %i\n",
4835 restart ? "restart" : "start", arg.vdev_id);
4839 ret = ath11k_mac_vdev_setup_sync(ar);
4841 ath11k_warn(ab, "failed to synchronize setup for vdev %i %s: %d\n",
4842 arg.vdev_id, restart ? "restart" : "start", ret);
4846 ar->num_started_vdevs++;
4847 ath11k_dbg(ab, ATH11K_DBG_MAC, "vdev %pM started, vdev_id %d\n",
4848 arvif->vif->addr, arvif->vdev_id);
4850 /* Enable CAC Flag in the driver by checking the channel DFS cac time,
4851 * i.e dfs_cac_ms value which will be valid only for radar channels
4852 * and state as NL80211_DFS_USABLE which indicates CAC needs to be
4853 * done before channel usage. This flags is used to drop rx packets.
4856 /* TODO Set the flag for other interface types as required */
4857 if (arvif->vdev_type == WMI_VDEV_TYPE_AP &&
4858 chandef->chan->dfs_cac_ms &&
4859 chandef->chan->dfs_state == NL80211_DFS_USABLE) {
4860 set_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
4861 ath11k_dbg(ab, ATH11K_DBG_MAC,
4862 "CAC Started in chan_freq %d for vdev %d\n",
4863 arg.channel.freq, arg.vdev_id);
4866 ret = ath11k_mac_set_txbf_conf(arvif);
4868 ath11k_warn(ab, "failed to set txbf conf for vdev %d: %d\n",
4869 arvif->vdev_id, ret);
4874 static int ath11k_mac_vdev_stop(struct ath11k_vif *arvif)
4876 struct ath11k *ar = arvif->ar;
4879 lockdep_assert_held(&ar->conf_mutex);
4881 reinit_completion(&ar->vdev_setup_done);
4883 spin_lock_bh(&ar->data_lock);
4885 ar->vdev_stop_status.stop_in_progress = true;
4886 ar->vdev_stop_status.vdev_id = arvif->vdev_id;
4888 spin_unlock_bh(&ar->data_lock);
4890 ret = ath11k_wmi_vdev_stop(ar, arvif->vdev_id);
4892 ath11k_warn(ar->ab, "failed to stop WMI vdev %i: %d\n",
4893 arvif->vdev_id, ret);
4897 ret = ath11k_mac_vdev_setup_sync(ar);
4899 ath11k_warn(ar->ab, "failed to synchronize setup for vdev %i: %d\n",
4900 arvif->vdev_id, ret);
4904 WARN_ON(ar->num_started_vdevs == 0);
4906 ar->num_started_vdevs--;
4907 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "vdev %pM stopped, vdev_id %d\n",
4908 arvif->vif->addr, arvif->vdev_id);
4910 if (test_bit(ATH11K_CAC_RUNNING, &ar->dev_flags)) {
4911 clear_bit(ATH11K_CAC_RUNNING, &ar->dev_flags);
4912 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "CAC Stopped for vdev %d\n",
4918 spin_lock_bh(&ar->data_lock);
4919 ar->vdev_stop_status.stop_in_progress = false;
4920 spin_unlock_bh(&ar->data_lock);
4925 static int ath11k_mac_vdev_start(struct ath11k_vif *arvif,
4926 const struct cfg80211_chan_def *chandef)
4928 return ath11k_mac_vdev_start_restart(arvif, chandef, false);
4931 static int ath11k_mac_vdev_restart(struct ath11k_vif *arvif,
4932 const struct cfg80211_chan_def *chandef)
4934 return ath11k_mac_vdev_start_restart(arvif, chandef, true);
4937 struct ath11k_mac_change_chanctx_arg {
4938 struct ieee80211_chanctx_conf *ctx;
4939 struct ieee80211_vif_chanctx_switch *vifs;
4945 ath11k_mac_change_chanctx_cnt_iter(void *data, u8 *mac,
4946 struct ieee80211_vif *vif)
4948 struct ath11k_mac_change_chanctx_arg *arg = data;
4950 if (rcu_access_pointer(vif->chanctx_conf) != arg->ctx)
4957 ath11k_mac_change_chanctx_fill_iter(void *data, u8 *mac,
4958 struct ieee80211_vif *vif)
4960 struct ath11k_mac_change_chanctx_arg *arg = data;
4961 struct ieee80211_chanctx_conf *ctx;
4963 ctx = rcu_access_pointer(vif->chanctx_conf);
4964 if (ctx != arg->ctx)
4967 if (WARN_ON(arg->next_vif == arg->n_vifs))
4970 arg->vifs[arg->next_vif].vif = vif;
4971 arg->vifs[arg->next_vif].old_ctx = ctx;
4972 arg->vifs[arg->next_vif].new_ctx = ctx;
4977 ath11k_mac_update_vif_chan(struct ath11k *ar,
4978 struct ieee80211_vif_chanctx_switch *vifs,
4981 struct ath11k_base *ab = ar->ab;
4982 struct ath11k_vif *arvif;
4986 lockdep_assert_held(&ar->conf_mutex);
4988 for (i = 0; i < n_vifs; i++) {
4989 arvif = (void *)vifs[i].vif->drv_priv;
4991 ath11k_dbg(ab, ATH11K_DBG_MAC,
4992 "mac chanctx switch vdev_id %i freq %hu->%hu width %d->%d\n",
4994 vifs[i].old_ctx->def.chan->center_freq,
4995 vifs[i].new_ctx->def.chan->center_freq,
4996 vifs[i].old_ctx->def.width,
4997 vifs[i].new_ctx->def.width);
4999 if (WARN_ON(!arvif->is_started))
5002 if (WARN_ON(!arvif->is_up))
5005 ret = ath11k_wmi_vdev_down(ar, arvif->vdev_id);
5007 ath11k_warn(ab, "failed to down vdev %d: %d\n",
5008 arvif->vdev_id, ret);
5013 /* All relevant vdevs are downed and associated channel resources
5014 * should be available for the channel switch now.
5017 /* TODO: Update ar->rx_channel */
5019 for (i = 0; i < n_vifs; i++) {
5020 arvif = (void *)vifs[i].vif->drv_priv;
5022 if (WARN_ON(!arvif->is_started))
5025 if (WARN_ON(!arvif->is_up))
5028 ret = ath11k_mac_setup_bcn_tmpl(arvif);
5030 ath11k_warn(ab, "failed to update bcn tmpl during csa: %d\n",
5033 ret = ath11k_mac_vdev_restart(arvif, &vifs[i].new_ctx->def);
5035 ath11k_warn(ab, "failed to restart vdev %d: %d\n",
5036 arvif->vdev_id, ret);
5040 ret = ath11k_wmi_vdev_up(arvif->ar, arvif->vdev_id, arvif->aid,
5043 ath11k_warn(ab, "failed to bring vdev up %d: %d\n",
5044 arvif->vdev_id, ret);
5051 ath11k_mac_update_active_vif_chan(struct ath11k *ar,
5052 struct ieee80211_chanctx_conf *ctx)
5054 struct ath11k_mac_change_chanctx_arg arg = { .ctx = ctx };
5056 lockdep_assert_held(&ar->conf_mutex);
5058 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5059 IEEE80211_IFACE_ITER_NORMAL,
5060 ath11k_mac_change_chanctx_cnt_iter,
5062 if (arg.n_vifs == 0)
5065 arg.vifs = kcalloc(arg.n_vifs, sizeof(arg.vifs[0]), GFP_KERNEL);
5069 ieee80211_iterate_active_interfaces_atomic(ar->hw,
5070 IEEE80211_IFACE_ITER_NORMAL,
5071 ath11k_mac_change_chanctx_fill_iter,
5074 ath11k_mac_update_vif_chan(ar, arg.vifs, arg.n_vifs);
5079 static void ath11k_mac_op_change_chanctx(struct ieee80211_hw *hw,
5080 struct ieee80211_chanctx_conf *ctx,
5083 struct ath11k *ar = hw->priv;
5084 struct ath11k_base *ab = ar->ab;
5086 mutex_lock(&ar->conf_mutex);
5088 ath11k_dbg(ab, ATH11K_DBG_MAC,
5089 "mac chanctx change freq %hu width %d ptr %pK changed %x\n",
5090 ctx->def.chan->center_freq, ctx->def.width, ctx, changed);
5092 /* This shouldn't really happen because channel switching should use
5093 * switch_vif_chanctx().
5095 if (WARN_ON(changed & IEEE80211_CHANCTX_CHANGE_CHANNEL))
5098 if (changed & IEEE80211_CHANCTX_CHANGE_WIDTH)
5099 ath11k_mac_update_active_vif_chan(ar, ctx);
5101 /* TODO: Recalc radar detection */
5104 mutex_unlock(&ar->conf_mutex);
5108 ath11k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,
5109 struct ieee80211_vif *vif,
5110 struct ieee80211_chanctx_conf *ctx)
5112 struct ath11k *ar = hw->priv;
5113 struct ath11k_base *ab = ar->ab;
5114 struct ath11k_vif *arvif = (void *)vif->drv_priv;
5117 mutex_lock(&ar->conf_mutex);
5119 ath11k_dbg(ab, ATH11K_DBG_MAC,
5120 "mac chanctx assign ptr %pK vdev_id %i\n",
5121 ctx, arvif->vdev_id);
5123 if (WARN_ON(arvif->is_started)) {
5124 mutex_unlock(&ar->conf_mutex);
5128 ret = ath11k_mac_vdev_start(arvif, &ctx->def);
5130 ath11k_warn(ab, "failed to start vdev %i addr %pM on freq %d: %d\n",
5131 arvif->vdev_id, vif->addr,
5132 ctx->def.chan->center_freq, ret);
5135 if (arvif->vdev_type == WMI_VDEV_TYPE_MONITOR) {
5136 ret = ath11k_monitor_vdev_up(ar, arvif->vdev_id);
5141 arvif->is_started = true;
5143 /* TODO: Setup ps and cts/rts protection */
5145 mutex_unlock(&ar->conf_mutex);
5150 mutex_unlock(&ar->conf_mutex);
5156 ath11k_mac_op_unassign_vif_chanctx(struct ieee80211_hw *hw,
5157 struct ieee80211_vif *vif,
5158 struct ieee80211_chanctx_conf *ctx)
5160 struct ath11k *ar = hw->priv;
5161 struct ath11k_base *ab = ar->ab;
5162 struct ath11k_vif *arvif = (void *)vif->drv_priv;
5165 mutex_lock(&ar->conf_mutex);
5167 ath11k_dbg(ab, ATH11K_DBG_MAC,
5168 "mac chanctx unassign ptr %pK vdev_id %i\n",
5169 ctx, arvif->vdev_id);
5171 WARN_ON(!arvif->is_started);
5173 ret = ath11k_mac_vdev_stop(arvif);
5175 ath11k_warn(ab, "failed to stop vdev %i: %d\n",
5176 arvif->vdev_id, ret);
5178 arvif->is_started = false;
5180 mutex_unlock(&ar->conf_mutex);
5184 ath11k_mac_op_switch_vif_chanctx(struct ieee80211_hw *hw,
5185 struct ieee80211_vif_chanctx_switch *vifs,
5187 enum ieee80211_chanctx_switch_mode mode)
5189 struct ath11k *ar = hw->priv;
5191 mutex_lock(&ar->conf_mutex);
5193 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
5194 "mac chanctx switch n_vifs %d mode %d\n",
5196 ath11k_mac_update_vif_chan(ar, vifs, n_vifs);
5198 mutex_unlock(&ar->conf_mutex);
5204 ath11k_set_vdev_param_to_all_vifs(struct ath11k *ar, int param, u32 value)
5206 struct ath11k_vif *arvif;
5209 mutex_lock(&ar->conf_mutex);
5210 list_for_each_entry(arvif, &ar->arvifs, list) {
5211 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "setting mac vdev %d param %d value %d\n",
5212 param, arvif->vdev_id, value);
5214 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5217 ath11k_warn(ar->ab, "failed to set param %d for vdev %d: %d\n",
5218 param, arvif->vdev_id, ret);
5222 mutex_unlock(&ar->conf_mutex);
5226 /* mac80211 stores device specific RTS/Fragmentation threshold value,
5227 * this is set interface specific to firmware from ath11k driver
5229 static int ath11k_mac_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
5231 struct ath11k *ar = hw->priv;
5232 int param_id = WMI_VDEV_PARAM_RTS_THRESHOLD;
5234 return ath11k_set_vdev_param_to_all_vifs(ar, param_id, value);
5237 static int ath11k_mac_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
5239 /* Even though there's a WMI vdev param for fragmentation threshold no
5240 * known firmware actually implements it. Moreover it is not possible to
5241 * rely frame fragmentation to mac80211 because firmware clears the
5242 * "more fragments" bit in frame control making it impossible for remote
5243 * devices to reassemble frames.
5245 * Hence implement a dummy callback just to say fragmentation isn't
5246 * supported. This effectively prevents mac80211 from doing frame
5247 * fragmentation in software.
5252 static void ath11k_mac_op_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
5253 u32 queues, bool drop)
5255 struct ath11k *ar = hw->priv;
5261 time_left = wait_event_timeout(ar->dp.tx_empty_waitq,
5262 (atomic_read(&ar->dp.num_tx_pending) == 0),
5263 ATH11K_FLUSH_TIMEOUT);
5265 ath11k_warn(ar->ab, "failed to flush transmit queue %ld\n", time_left);
5269 ath11k_mac_bitrate_mask_num_ht_rates(struct ath11k *ar,
5270 enum nl80211_band band,
5271 const struct cfg80211_bitrate_mask *mask)
5276 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++)
5277 num_rates += hweight16(mask->control[band].ht_mcs[i]);
5283 ath11k_mac_has_single_legacy_rate(struct ath11k *ar,
5284 enum nl80211_band band,
5285 const struct cfg80211_bitrate_mask *mask)
5289 num_rates = hweight32(mask->control[band].legacy);
5291 if (ath11k_mac_bitrate_mask_num_ht_rates(ar, band, mask))
5294 if (ath11k_mac_bitrate_mask_num_vht_rates(ar, band, mask))
5297 return num_rates == 1;
5301 ath11k_mac_bitrate_mask_get_single_nss(struct ath11k *ar,
5302 enum nl80211_band band,
5303 const struct cfg80211_bitrate_mask *mask,
5306 struct ieee80211_supported_band *sband = &ar->mac.sbands[band];
5307 u16 vht_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
5309 u8 vht_nss_mask = 0;
5312 /* No need to consider legacy here. Basic rates are always present
5316 for (i = 0; i < ARRAY_SIZE(mask->control[band].ht_mcs); i++) {
5317 if (mask->control[band].ht_mcs[i] == 0)
5319 else if (mask->control[band].ht_mcs[i] ==
5320 sband->ht_cap.mcs.rx_mask[i])
5321 ht_nss_mask |= BIT(i);
5326 for (i = 0; i < ARRAY_SIZE(mask->control[band].vht_mcs); i++) {
5327 if (mask->control[band].vht_mcs[i] == 0)
5329 else if (mask->control[band].vht_mcs[i] ==
5330 ath11k_mac_get_max_vht_mcs_map(vht_mcs_map, i))
5331 vht_nss_mask |= BIT(i);
5336 if (ht_nss_mask != vht_nss_mask)
5339 if (ht_nss_mask == 0)
5342 if (BIT(fls(ht_nss_mask)) - 1 != ht_nss_mask)
5345 *nss = fls(ht_nss_mask);
5351 ath11k_mac_get_single_legacy_rate(struct ath11k *ar,
5352 enum nl80211_band band,
5353 const struct cfg80211_bitrate_mask *mask,
5361 if (hweight32(mask->control[band].legacy) != 1)
5364 rate_idx = ffs(mask->control[band].legacy) - 1;
5366 if (band == NL80211_BAND_5GHZ || band == NL80211_BAND_6GHZ)
5367 rate_idx += ATH11K_MAC_FIRST_OFDM_RATE_IDX;
5369 hw_rate = ath11k_legacy_rates[rate_idx].hw_value;
5370 bitrate = ath11k_legacy_rates[rate_idx].bitrate;
5372 if (ath11k_mac_bitrate_is_cck(bitrate))
5373 preamble = WMI_RATE_PREAMBLE_CCK;
5375 preamble = WMI_RATE_PREAMBLE_OFDM;
5378 *rate = ATH11K_HW_RATE_CODE(hw_rate, 0, preamble);
5383 static int ath11k_mac_set_fixed_rate_params(struct ath11k_vif *arvif,
5384 u32 rate, u8 nss, u8 sgi, u8 ldpc)
5386 struct ath11k *ar = arvif->ar;
5390 lockdep_assert_held(&ar->conf_mutex);
5392 ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac set fixed rate params vdev %i rate 0x%02hhx nss %hhu sgi %hhu\n",
5393 arvif->vdev_id, rate, nss, sgi);
5395 vdev_param = WMI_VDEV_PARAM_FIXED_RATE;
5396 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5399 ath11k_warn(ar->ab, "failed to set fixed rate param 0x%02x: %d\n",
5404 vdev_param = WMI_VDEV_PARAM_NSS;
5405 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5408 ath11k_warn(ar->ab, "failed to set nss param %d: %d\n",
5413 vdev_param = WMI_VDEV_PARAM_SGI;
5414 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5417 ath11k_warn(ar->ab, "failed to set sgi param %d: %d\n",
5422 vdev_param = WMI_VDEV_PARAM_LDPC;
5423 ret = ath11k_wmi_vdev_set_param_cmd(ar, arvif->vdev_id,
5426 ath11k_warn(ar->ab, "failed to set ldpc param %d: %d\n",
5435 ath11k_mac_vht_mcs_range_present(struct ath11k *ar,
5436 enum nl80211_band band,
5437 const struct cfg80211_bitrate_mask *mask)
5442 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
5443 vht_mcs = mask->control[band].vht_mcs[i];
5459 static void ath11k_mac_set_bitrate_mask_iter(void *data,
5460 struct ieee80211_sta *sta)
5462 struct ath11k_vif *arvif = data;
5463 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
5464 struct ath11k *ar = arvif->ar;
5466 spin_lock_bh(&ar->data_lock);
5467 arsta->changed |= IEEE80211_RC_SUPP_RATES_CHANGED;
5468 spin_unlock_bh(&ar->data_lock);
5470 ieee80211_queue_work(ar->hw, &arsta->update_wk);
5473 static void ath11k_mac_disable_peer_fixed_rate(void *data,
5474 struct ieee80211_sta *sta)
5476 struct ath11k_vif *arvif = data;
5477 struct ath11k *ar = arvif->ar;
5480 ret = ath11k_wmi_set_peer_param(ar, sta->addr,
5482 WMI_PEER_PARAM_FIXED_RATE,
5483 WMI_FIXED_RATE_NONE);
5486 "failed to disable peer fixed rate for STA %pM ret %d\n",
5491 ath11k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,
5492 struct ieee80211_vif *vif,
5493 const struct cfg80211_bitrate_mask *mask)
5495 struct ath11k_vif *arvif = (void *)vif->drv_priv;
5496 struct cfg80211_chan_def def;
5497 struct ath11k *ar = arvif->ar;
5498 enum nl80211_band band;
5499 const u8 *ht_mcs_mask;
5500 const u16 *vht_mcs_mask;
5509 if (ath11k_mac_vif_chan(vif, &def))
5512 band = def.chan->band;
5513 ht_mcs_mask = mask->control[band].ht_mcs;
5514 vht_mcs_mask = mask->control[band].vht_mcs;
5515 ldpc = !!(ar->ht_cap_info & WMI_HT_CAP_LDPC);
5517 sgi = mask->control[band].gi;
5518 if (sgi == NL80211_TXRATE_FORCE_LGI)
5521 /* mac80211 doesn't support sending a fixed HT/VHT MCS alone, rather it
5522 * requires passing atleast one of used basic rates along with them.
5523 * Fixed rate setting across different preambles(legacy, HT, VHT) is
5524 * not supported by the FW. Hence use of FIXED_RATE vdev param is not
5525 * suitable for setting single HT/VHT rates.
5526 * But, there could be a single basic rate passed from userspace which
5527 * can be done through the FIXED_RATE param.
5529 if (ath11k_mac_has_single_legacy_rate(ar, band, mask)) {
5530 ret = ath11k_mac_get_single_legacy_rate(ar, band, mask, &rate,
5533 ath11k_warn(ar->ab, "failed to get single legacy rate for vdev %i: %d\n",
5534 arvif->vdev_id, ret);
5537 ieee80211_iterate_stations_atomic(ar->hw,
5538 ath11k_mac_disable_peer_fixed_rate,
5540 } else if (ath11k_mac_bitrate_mask_get_single_nss(ar, band, mask,
5542 rate = WMI_FIXED_RATE_NONE;
5545 rate = WMI_FIXED_RATE_NONE;
5546 nss = min_t(u32, ar->num_tx_chains,
5547 max(ath11k_mac_max_ht_nss(ht_mcs_mask),
5548 ath11k_mac_max_vht_nss(vht_mcs_mask)));
5550 /* If multiple rates across different preambles are given
5551 * we can reconfigure this info with all peers using PEER_ASSOC
5552 * command with the below exception cases.
5553 * - Single VHT Rate : peer_assoc command accommodates only MCS
5554 * range values i.e 0-7, 0-8, 0-9 for VHT. Though mac80211
5555 * mandates passing basic rates along with HT/VHT rates, FW
5556 * doesn't allow switching from VHT to Legacy. Hence instead of
5557 * setting legacy and VHT rates using RATEMASK_CMD vdev cmd,
5558 * we could set this VHT rate as peer fixed rate param, which
5559 * will override FIXED rate and FW rate control algorithm.
5560 * If single VHT rate is passed along with HT rates, we select
5561 * the VHT rate as fixed rate for vht peers.
5562 * - Multiple VHT Rates : When Multiple VHT rates are given,this
5563 * can be set using RATEMASK CMD which uses FW rate-ctl alg.
5564 * TODO: Setting multiple VHT MCS and replacing peer_assoc with
5565 * RATEMASK_CMDID can cover all use cases of setting rates
5566 * across multiple preambles and rates within same type.
5567 * But requires more validation of the command at this point.
5570 num_rates = ath11k_mac_bitrate_mask_num_vht_rates(ar, band,
5573 if (!ath11k_mac_vht_mcs_range_present(ar, band, mask) &&
5575 /* TODO: Handle multiple VHT MCS values setting using
5579 "Setting more than one MCS Value in bitrate mask not supported\n");
5583 ieee80211_iterate_stations_atomic(ar->hw,
5584 ath11k_mac_disable_peer_fixed_rate,
5587 mutex_lock(&ar->conf_mutex);
5589 arvif->bitrate_mask = *mask;
5590 ieee80211_iterate_stations_atomic(ar->hw,
5591 ath11k_mac_set_bitrate_mask_iter,
5594 mutex_unlock(&ar->conf_mutex);
5597 mutex_lock(&ar->conf_mutex);
5599 ret = ath11k_mac_set_fixed_rate_params(arvif, rate, nss, sgi, ldpc);
5601 ath11k_warn(ar->ab, "failed to set fixed rate params on vdev %i: %d\n",
5602 arvif->vdev_id, ret);
5605 mutex_unlock(&ar->conf_mutex);
5611 ath11k_mac_op_reconfig_complete(struct ieee80211_hw *hw,
5612 enum ieee80211_reconfig_type reconfig_type)
5614 struct ath11k *ar = hw->priv;
5616 if (reconfig_type != IEEE80211_RECONFIG_TYPE_RESTART)
5619 mutex_lock(&ar->conf_mutex);
5621 if (ar->state == ATH11K_STATE_RESTARTED) {
5622 ath11k_warn(ar->ab, "pdev %d successfully recovered\n",
5624 ar->state = ATH11K_STATE_ON;
5625 ieee80211_wake_queues(ar->hw);
5628 mutex_unlock(&ar->conf_mutex);
5632 ath11k_mac_update_bss_chan_survey(struct ath11k *ar,
5633 struct ieee80211_channel *channel)
5636 enum wmi_bss_chan_info_req_type type = WMI_BSS_SURVEY_REQ_TYPE_READ;
5638 lockdep_assert_held(&ar->conf_mutex);
5640 if (!test_bit(WMI_TLV_SERVICE_BSS_CHANNEL_INFO_64, ar->ab->wmi_ab.svc_map) ||
5641 ar->rx_channel != channel)
5644 if (ar->scan.state != ATH11K_SCAN_IDLE) {
5645 ath11k_dbg(ar->ab, ATH11K_DBG_MAC,
5646 "ignoring bss chan info req while scanning..\n");
5650 reinit_completion(&ar->bss_survey_done);
5652 ret = ath11k_wmi_pdev_bss_chan_info_request(ar, type);
5654 ath11k_warn(ar->ab, "failed to send pdev bss chan info request\n");
5658 ret = wait_for_completion_timeout(&ar->bss_survey_done, 3 * HZ);
5660 ath11k_warn(ar->ab, "bss channel survey timed out\n");
5663 static int ath11k_mac_op_get_survey(struct ieee80211_hw *hw, int idx,
5664 struct survey_info *survey)
5666 struct ath11k *ar = hw->priv;
5667 struct ieee80211_supported_band *sband;
5668 struct survey_info *ar_survey;
5671 if (idx >= ATH11K_NUM_CHANS)
5674 ar_survey = &ar->survey[idx];
5676 mutex_lock(&ar->conf_mutex);
5678 sband = hw->wiphy->bands[NL80211_BAND_2GHZ];
5679 if (sband && idx >= sband->n_channels) {
5680 idx -= sband->n_channels;
5685 sband = hw->wiphy->bands[NL80211_BAND_5GHZ];
5687 if (!sband || idx >= sband->n_channels) {
5692 ath11k_mac_update_bss_chan_survey(ar, &sband->channels[idx]);
5694 spin_lock_bh(&ar->data_lock);
5695 memcpy(survey, ar_survey, sizeof(*survey));
5696 spin_unlock_bh(&ar->data_lock);
5698 survey->channel = &sband->channels[idx];
5700 if (ar->rx_channel == survey->channel)
5701 survey->filled |= SURVEY_INFO_IN_USE;
5704 mutex_unlock(&ar->conf_mutex);
5708 static void ath11k_mac_op_sta_statistics(struct ieee80211_hw *hw,
5709 struct ieee80211_vif *vif,
5710 struct ieee80211_sta *sta,
5711 struct station_info *sinfo)
5713 struct ath11k_sta *arsta = (struct ath11k_sta *)sta->drv_priv;
5715 sinfo->rx_duration = arsta->rx_duration;
5716 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
5718 sinfo->tx_duration = arsta->tx_duration;
5719 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_DURATION);
5721 if (!arsta->txrate.legacy && !arsta->txrate.nss)
5724 if (arsta->txrate.legacy) {
5725 sinfo->txrate.legacy = arsta->txrate.legacy;
5727 sinfo->txrate.mcs = arsta->txrate.mcs;
5728 sinfo->txrate.nss = arsta->txrate.nss;
5729 sinfo->txrate.bw = arsta->txrate.bw;
5730 sinfo->txrate.he_gi = arsta->txrate.he_gi;
5731 sinfo->txrate.he_dcm = arsta->txrate.he_dcm;
5732 sinfo->txrate.he_ru_alloc = arsta->txrate.he_ru_alloc;
5734 sinfo->txrate.flags = arsta->txrate.flags;
5735 sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE);
5737 /* TODO: Use real NF instead of default one. */
5738 sinfo->signal = arsta->rssi_comb + ATH11K_DEFAULT_NOISE_FLOOR;
5741 static const struct ieee80211_ops ath11k_ops = {
5742 .tx = ath11k_mac_op_tx,
5743 .start = ath11k_mac_op_start,
5744 .stop = ath11k_mac_op_stop,
5745 .reconfig_complete = ath11k_mac_op_reconfig_complete,
5746 .add_interface = ath11k_mac_op_add_interface,
5747 .remove_interface = ath11k_mac_op_remove_interface,
5748 .config = ath11k_mac_op_config,
5749 .bss_info_changed = ath11k_mac_op_bss_info_changed,
5750 .configure_filter = ath11k_mac_op_configure_filter,
5751 .hw_scan = ath11k_mac_op_hw_scan,
5752 .cancel_hw_scan = ath11k_mac_op_cancel_hw_scan,
5753 .set_key = ath11k_mac_op_set_key,
5754 .sta_state = ath11k_mac_op_sta_state,
5755 .sta_set_txpwr = ath11k_mac_op_sta_set_txpwr,
5756 .sta_rc_update = ath11k_mac_op_sta_rc_update,
5757 .conf_tx = ath11k_mac_op_conf_tx,
5758 .set_antenna = ath11k_mac_op_set_antenna,
5759 .get_antenna = ath11k_mac_op_get_antenna,
5760 .ampdu_action = ath11k_mac_op_ampdu_action,
5761 .add_chanctx = ath11k_mac_op_add_chanctx,
5762 .remove_chanctx = ath11k_mac_op_remove_chanctx,
5763 .change_chanctx = ath11k_mac_op_change_chanctx,
5764 .assign_vif_chanctx = ath11k_mac_op_assign_vif_chanctx,
5765 .unassign_vif_chanctx = ath11k_mac_op_unassign_vif_chanctx,
5766 .switch_vif_chanctx = ath11k_mac_op_switch_vif_chanctx,
5767 .set_rts_threshold = ath11k_mac_op_set_rts_threshold,
5768 .set_frag_threshold = ath11k_mac_op_set_frag_threshold,
5769 .set_bitrate_mask = ath11k_mac_op_set_bitrate_mask,
5770 .get_survey = ath11k_mac_op_get_survey,
5771 .flush = ath11k_mac_op_flush,
5772 .sta_statistics = ath11k_mac_op_sta_statistics,
5773 CFG80211_TESTMODE_CMD(ath11k_tm_cmd)
5774 #ifdef CONFIG_ATH11K_DEBUGFS
5775 .sta_add_debugfs = ath11k_sta_add_debugfs,
5779 static const struct ieee80211_iface_limit ath11k_if_limits[] = {
5782 .types = BIT(NL80211_IFTYPE_STATION),
5786 .types = BIT(NL80211_IFTYPE_AP)
5787 #ifdef CONFIG_MAC80211_MESH
5788 | BIT(NL80211_IFTYPE_MESH_POINT)
5793 static const struct ieee80211_iface_combination ath11k_if_comb[] = {
5795 .limits = ath11k_if_limits,
5796 .n_limits = ARRAY_SIZE(ath11k_if_limits),
5797 .max_interfaces = 16,
5798 .num_different_channels = 1,
5799 .beacon_int_infra_match = true,
5800 .beacon_int_min_gcd = 100,
5801 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5802 BIT(NL80211_CHAN_WIDTH_20) |
5803 BIT(NL80211_CHAN_WIDTH_40) |
5804 BIT(NL80211_CHAN_WIDTH_80),
5808 static void ath11k_mac_update_ch_list(struct ath11k *ar,
5809 struct ieee80211_supported_band *band,
5810 u32 freq_low, u32 freq_high)
5814 if (!(freq_low && freq_high))
5817 for (i = 0; i < band->n_channels; i++) {
5818 if (band->channels[i].center_freq < freq_low ||
5819 band->channels[i].center_freq > freq_high)
5820 band->channels[i].flags |= IEEE80211_CHAN_DISABLED;
5824 static int ath11k_mac_setup_channels_rates(struct ath11k *ar,
5825 u32 supported_bands)
5827 struct ieee80211_supported_band *band;
5828 struct ath11k_hal_reg_capabilities_ext *reg_cap;
5831 BUILD_BUG_ON((ARRAY_SIZE(ath11k_2ghz_channels) +
5832 ARRAY_SIZE(ath11k_5ghz_channels) +
5833 ARRAY_SIZE(ath11k_6ghz_channels)) !=
5836 reg_cap = &ar->ab->hal_reg_cap[ar->pdev_idx];
5838 if (supported_bands & WMI_HOST_WLAN_2G_CAP) {
5839 channels = kmemdup(ath11k_2ghz_channels,
5840 sizeof(ath11k_2ghz_channels),
5845 band = &ar->mac.sbands[NL80211_BAND_2GHZ];
5846 band->band = NL80211_BAND_2GHZ;
5847 band->n_channels = ARRAY_SIZE(ath11k_2ghz_channels);
5848 band->channels = channels;
5849 band->n_bitrates = ath11k_g_rates_size;
5850 band->bitrates = ath11k_g_rates;
5851 ar->hw->wiphy->bands[NL80211_BAND_2GHZ] = band;
5852 ath11k_mac_update_ch_list(ar, band,
5853 reg_cap->low_2ghz_chan,
5854 reg_cap->high_2ghz_chan);
5857 if (supported_bands & WMI_HOST_WLAN_5G_CAP) {
5858 if (reg_cap->high_5ghz_chan >= ATH11K_MAX_6G_FREQ) {
5859 channels = kmemdup(ath11k_6ghz_channels,
5860 sizeof(ath11k_6ghz_channels), GFP_KERNEL);
5862 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
5866 ar->supports_6ghz = true;
5867 band = &ar->mac.sbands[NL80211_BAND_6GHZ];
5868 band->band = NL80211_BAND_6GHZ;
5869 band->n_channels = ARRAY_SIZE(ath11k_6ghz_channels);
5870 band->channels = channels;
5871 band->n_bitrates = ath11k_a_rates_size;
5872 band->bitrates = ath11k_a_rates;
5873 ar->hw->wiphy->bands[NL80211_BAND_6GHZ] = band;
5874 ath11k_mac_update_ch_list(ar, band,
5875 reg_cap->low_5ghz_chan,
5876 reg_cap->high_5ghz_chan);
5879 if (reg_cap->low_5ghz_chan < ATH11K_MIN_6G_FREQ) {
5880 channels = kmemdup(ath11k_5ghz_channels,
5881 sizeof(ath11k_5ghz_channels),
5884 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
5885 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
5889 band = &ar->mac.sbands[NL80211_BAND_5GHZ];
5890 band->band = NL80211_BAND_5GHZ;
5891 band->n_channels = ARRAY_SIZE(ath11k_5ghz_channels);
5892 band->channels = channels;
5893 band->n_bitrates = ath11k_a_rates_size;
5894 band->bitrates = ath11k_a_rates;
5895 ar->hw->wiphy->bands[NL80211_BAND_5GHZ] = band;
5896 ath11k_mac_update_ch_list(ar, band,
5897 reg_cap->low_5ghz_chan,
5898 reg_cap->high_5ghz_chan);
5905 static const u8 ath11k_if_types_ext_capa[] = {
5906 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
5907 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
5910 static const u8 ath11k_if_types_ext_capa_sta[] = {
5911 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
5912 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
5913 [9] = WLAN_EXT_CAPA10_TWT_REQUESTER_SUPPORT,
5916 static const u8 ath11k_if_types_ext_capa_ap[] = {
5917 [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
5918 [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF,
5919 [9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT,
5922 static const struct wiphy_iftype_ext_capab ath11k_iftypes_ext_capa[] = {
5924 .extended_capabilities = ath11k_if_types_ext_capa,
5925 .extended_capabilities_mask = ath11k_if_types_ext_capa,
5926 .extended_capabilities_len = sizeof(ath11k_if_types_ext_capa),
5928 .iftype = NL80211_IFTYPE_STATION,
5929 .extended_capabilities = ath11k_if_types_ext_capa_sta,
5930 .extended_capabilities_mask = ath11k_if_types_ext_capa_sta,
5931 .extended_capabilities_len =
5932 sizeof(ath11k_if_types_ext_capa_sta),
5934 .iftype = NL80211_IFTYPE_AP,
5935 .extended_capabilities = ath11k_if_types_ext_capa_ap,
5936 .extended_capabilities_mask = ath11k_if_types_ext_capa_ap,
5937 .extended_capabilities_len =
5938 sizeof(ath11k_if_types_ext_capa_ap),
5942 static void __ath11k_mac_unregister(struct ath11k *ar)
5944 cancel_work_sync(&ar->regd_update_work);
5946 ieee80211_unregister_hw(ar->hw);
5948 idr_for_each(&ar->txmgmt_idr, ath11k_mac_tx_mgmt_pending_free, ar);
5949 idr_destroy(&ar->txmgmt_idr);
5951 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
5952 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
5953 kfree(ar->mac.sbands[NL80211_BAND_6GHZ].channels);
5955 SET_IEEE80211_DEV(ar->hw, NULL);
5958 void ath11k_mac_unregister(struct ath11k_base *ab)
5961 struct ath11k_pdev *pdev;
5964 for (i = 0; i < ab->num_radios; i++) {
5965 pdev = &ab->pdevs[i];
5970 __ath11k_mac_unregister(ar);
5974 static int __ath11k_mac_register(struct ath11k *ar)
5976 struct ath11k_base *ab = ar->ab;
5977 struct ath11k_pdev_cap *cap = &ar->pdev->cap;
5978 static const u32 cipher_suites[] = {
5979 WLAN_CIPHER_SUITE_TKIP,
5980 WLAN_CIPHER_SUITE_CCMP,
5981 WLAN_CIPHER_SUITE_AES_CMAC,
5982 WLAN_CIPHER_SUITE_BIP_CMAC_256,
5983 WLAN_CIPHER_SUITE_BIP_GMAC_128,
5984 WLAN_CIPHER_SUITE_BIP_GMAC_256,
5985 WLAN_CIPHER_SUITE_GCMP,
5986 WLAN_CIPHER_SUITE_GCMP_256,
5987 WLAN_CIPHER_SUITE_CCMP_256,
5992 ath11k_pdev_caps_update(ar);
5994 SET_IEEE80211_PERM_ADDR(ar->hw, ar->mac_addr);
5996 SET_IEEE80211_DEV(ar->hw, ab->dev);
5998 ret = ath11k_mac_setup_channels_rates(ar,
5999 cap->supported_bands);
6003 ath11k_mac_setup_ht_vht_cap(ar, cap, &ht_cap);
6004 ath11k_mac_setup_he_cap(ar, cap);
6006 ar->hw->wiphy->available_antennas_rx = cap->rx_chain_mask;
6007 ar->hw->wiphy->available_antennas_tx = cap->tx_chain_mask;
6009 ar->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
6010 BIT(NL80211_IFTYPE_AP) |
6011 BIT(NL80211_IFTYPE_MESH_POINT);
6013 ieee80211_hw_set(ar->hw, SIGNAL_DBM);
6014 ieee80211_hw_set(ar->hw, SUPPORTS_PS);
6015 ieee80211_hw_set(ar->hw, SUPPORTS_DYNAMIC_PS);
6016 ieee80211_hw_set(ar->hw, MFP_CAPABLE);
6017 ieee80211_hw_set(ar->hw, REPORTS_TX_ACK_STATUS);
6018 ieee80211_hw_set(ar->hw, HAS_RATE_CONTROL);
6019 ieee80211_hw_set(ar->hw, AP_LINK_PS);
6020 ieee80211_hw_set(ar->hw, SPECTRUM_MGMT);
6021 ieee80211_hw_set(ar->hw, SUPPORT_FAST_XMIT);
6022 ieee80211_hw_set(ar->hw, CONNECTION_MONITOR);
6023 ieee80211_hw_set(ar->hw, SUPPORTS_PER_STA_GTK);
6024 ieee80211_hw_set(ar->hw, WANT_MONITOR_VIF);
6025 ieee80211_hw_set(ar->hw, CHANCTX_STA_CSA);
6026 ieee80211_hw_set(ar->hw, QUEUE_CONTROL);
6027 ieee80211_hw_set(ar->hw, SUPPORTS_TX_FRAG);
6028 ieee80211_hw_set(ar->hw, REPORTS_LOW_ACK);
6029 if (ht_cap & WMI_HT_CAP_ENABLED) {
6030 ieee80211_hw_set(ar->hw, AMPDU_AGGREGATION);
6031 ieee80211_hw_set(ar->hw, TX_AMPDU_SETUP_IN_HW);
6032 ieee80211_hw_set(ar->hw, SUPPORTS_REORDERING_BUFFER);
6033 ieee80211_hw_set(ar->hw, SUPPORTS_AMSDU_IN_AMPDU);
6034 ieee80211_hw_set(ar->hw, USES_RSS);
6037 ar->hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS;
6038 ar->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
6040 /* TODO: Check if HT capability advertised from firmware is different
6041 * for each band for a dual band capable radio. It will be tricky to
6042 * handle it when the ht capability different for each band.
6044 if (ht_cap & WMI_HT_CAP_DYNAMIC_SMPS)
6045 ar->hw->wiphy->features |= NL80211_FEATURE_DYNAMIC_SMPS;
6047 ar->hw->wiphy->max_scan_ssids = WLAN_SCAN_PARAMS_MAX_SSID;
6048 ar->hw->wiphy->max_scan_ie_len = WLAN_SCAN_PARAMS_MAX_IE_LEN;
6050 ar->hw->max_listen_interval = ATH11K_MAX_HW_LISTEN_INTERVAL;
6052 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
6053 ar->hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
6054 ar->hw->wiphy->max_remain_on_channel_duration = 5000;
6056 ar->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
6057 ar->hw->wiphy->features |= NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
6058 NL80211_FEATURE_AP_SCAN;
6060 ar->max_num_stations = TARGET_NUM_STATIONS;
6061 ar->max_num_peers = TARGET_NUM_PEERS_PDEV;
6063 ar->hw->wiphy->max_ap_assoc_sta = ar->max_num_stations;
6065 ar->hw->queues = ATH11K_HW_MAX_QUEUES;
6066 ar->hw->wiphy->tx_queue_len = ATH11K_QUEUE_LEN;
6067 ar->hw->offchannel_tx_hw_queue = ATH11K_HW_MAX_QUEUES - 1;
6068 ar->hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
6070 ar->hw->vif_data_size = sizeof(struct ath11k_vif);
6071 ar->hw->sta_data_size = sizeof(struct ath11k_sta);
6073 ar->hw->wiphy->iface_combinations = ath11k_if_comb;
6074 ar->hw->wiphy->n_iface_combinations = ARRAY_SIZE(ath11k_if_comb);
6076 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
6077 wiphy_ext_feature_set(ar->hw->wiphy, NL80211_EXT_FEATURE_STA_TX_PWR);
6079 ar->hw->wiphy->cipher_suites = cipher_suites;
6080 ar->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
6082 ar->hw->wiphy->iftype_ext_capab = ath11k_iftypes_ext_capa;
6083 ar->hw->wiphy->num_iftype_ext_capab =
6084 ARRAY_SIZE(ath11k_iftypes_ext_capa);
6086 ath11k_reg_init(ar);
6088 /* advertise HW checksum offload capabilities */
6089 ar->hw->netdev_features = NETIF_F_HW_CSUM;
6091 ret = ieee80211_register_hw(ar->hw);
6093 ath11k_err(ar->ab, "ieee80211 registration failed: %d\n", ret);
6097 /* Apply the regd received during initialization */
6098 ret = ath11k_regd_update(ar, true);
6100 ath11k_err(ar->ab, "ath11k regd update failed: %d\n", ret);
6104 ret = ath11k_debug_register(ar);
6106 ath11k_err(ar->ab, "debugfs registration failed: %d\n", ret);
6113 kfree(ar->mac.sbands[NL80211_BAND_2GHZ].channels);
6114 kfree(ar->mac.sbands[NL80211_BAND_5GHZ].channels);
6116 SET_IEEE80211_DEV(ar->hw, NULL);
6120 int ath11k_mac_register(struct ath11k_base *ab)
6123 struct ath11k_pdev *pdev;
6127 if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags))
6130 for (i = 0; i < ab->num_radios; i++) {
6131 pdev = &ab->pdevs[i];
6133 if (ab->pdevs_macaddr_valid) {
6134 ether_addr_copy(ar->mac_addr, pdev->mac_addr);
6136 ether_addr_copy(ar->mac_addr, ab->mac_addr);
6137 ar->mac_addr[4] += i;
6140 ret = __ath11k_mac_register(ar);
6144 idr_init(&ar->txmgmt_idr);
6145 spin_lock_init(&ar->txmgmt_idr_lock);
6148 /* Initialize channel counters frequency value in hertz */
6149 ab->cc_freq_hz = IPQ8074_CC_FREQ_HERTZ;
6150 ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS)) - 1;
6155 for (i = i - 1; i >= 0; i--) {
6156 pdev = &ab->pdevs[i];
6158 __ath11k_mac_unregister(ar);
6164 int ath11k_mac_allocate(struct ath11k_base *ab)
6166 struct ieee80211_hw *hw;
6168 struct ath11k_pdev *pdev;
6172 if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags))
6175 for (i = 0; i < ab->num_radios; i++) {
6176 pdev = &ab->pdevs[i];
6177 hw = ieee80211_alloc_hw(sizeof(struct ath11k), &ath11k_ops);
6179 ath11k_warn(ab, "failed to allocate mac80211 hw device\n");
6189 ar->lmac_id = ath11k_hw_get_mac_from_pdev_id(&ab->hw_params, i);
6191 ar->wmi = &ab->wmi_ab.wmi[i];
6192 /* FIXME wmi[0] is already initialized during attach,
6193 * Should we do this again?
6195 ath11k_wmi_pdev_attach(ab, i);
6197 ar->cfg_tx_chainmask = pdev->cap.tx_chain_mask;
6198 ar->cfg_rx_chainmask = pdev->cap.rx_chain_mask;
6199 ar->num_tx_chains = get_num_chains(pdev->cap.tx_chain_mask);
6200 ar->num_rx_chains = get_num_chains(pdev->cap.rx_chain_mask);
6203 spin_lock_init(&ar->data_lock);
6204 INIT_LIST_HEAD(&ar->arvifs);
6205 INIT_LIST_HEAD(&ar->ppdu_stats_info);
6206 mutex_init(&ar->conf_mutex);
6207 init_completion(&ar->vdev_setup_done);
6208 init_completion(&ar->peer_assoc_done);
6209 init_completion(&ar->install_key_done);
6210 init_completion(&ar->bss_survey_done);
6211 init_completion(&ar->scan.started);
6212 init_completion(&ar->scan.completed);
6213 init_completion(&ar->thermal.wmi_sync);
6215 INIT_DELAYED_WORK(&ar->scan.timeout, ath11k_scan_timeout_work);
6216 INIT_WORK(&ar->regd_update_work, ath11k_regd_update_work);
6218 INIT_WORK(&ar->wmi_mgmt_tx_work, ath11k_mgmt_over_wmi_tx_work);
6219 skb_queue_head_init(&ar->wmi_mgmt_tx_queue);
6220 clear_bit(ATH11K_FLAG_MONITOR_ENABLED, &ar->monitor_flags);
6226 ath11k_mac_destroy(ab);
6231 void ath11k_mac_destroy(struct ath11k_base *ab)
6234 struct ath11k_pdev *pdev;
6237 for (i = 0; i < ab->num_radios; i++) {
6238 pdev = &ab->pdevs[i];
6243 ieee80211_free_hw(ar->hw);