xref: /openbmc/linux/drivers/net/wireless/ath/ath12k/dp_mon.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1d8899132SKalle Valo // SPDX-License-Identifier: BSD-3-Clause-Clear
2d8899132SKalle Valo /*
3d8899132SKalle Valo  * Copyright (c) 2019-2021 The Linux Foundation. All rights reserved.
4d8899132SKalle Valo  * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
5d8899132SKalle Valo  */
6d8899132SKalle Valo 
7d8899132SKalle Valo #include "dp_mon.h"
8d8899132SKalle Valo #include "debug.h"
9d8899132SKalle Valo #include "dp_rx.h"
10d8899132SKalle Valo #include "dp_tx.h"
11d8899132SKalle Valo #include "peer.h"
12d8899132SKalle Valo 
ath12k_dp_mon_rx_handle_ofdma_info(void * rx_tlv,struct hal_rx_user_status * rx_user_status)13d8899132SKalle Valo static void ath12k_dp_mon_rx_handle_ofdma_info(void *rx_tlv,
14d8899132SKalle Valo 					       struct hal_rx_user_status *rx_user_status)
15d8899132SKalle Valo {
16d8899132SKalle Valo 	struct hal_rx_ppdu_end_user_stats *ppdu_end_user =
17d8899132SKalle Valo 				(struct hal_rx_ppdu_end_user_stats *)rx_tlv;
18d8899132SKalle Valo 
19d8899132SKalle Valo 	rx_user_status->ul_ofdma_user_v0_word0 =
20d8899132SKalle Valo 		__le32_to_cpu(ppdu_end_user->usr_resp_ref);
21d8899132SKalle Valo 	rx_user_status->ul_ofdma_user_v0_word1 =
22d8899132SKalle Valo 		__le32_to_cpu(ppdu_end_user->usr_resp_ref_ext);
23d8899132SKalle Valo }
24d8899132SKalle Valo 
25d8899132SKalle Valo static void
ath12k_dp_mon_rx_populate_byte_count(void * rx_tlv,void * ppduinfo,struct hal_rx_user_status * rx_user_status)26d8899132SKalle Valo ath12k_dp_mon_rx_populate_byte_count(void *rx_tlv, void *ppduinfo,
27d8899132SKalle Valo 				     struct hal_rx_user_status *rx_user_status)
28d8899132SKalle Valo {
29d8899132SKalle Valo 	struct hal_rx_ppdu_end_user_stats *ppdu_end_user =
30d8899132SKalle Valo 		(struct hal_rx_ppdu_end_user_stats *)rx_tlv;
31d8899132SKalle Valo 	u32 mpdu_ok_byte_count = __le32_to_cpu(ppdu_end_user->mpdu_ok_cnt);
32d8899132SKalle Valo 	u32 mpdu_err_byte_count = __le32_to_cpu(ppdu_end_user->mpdu_err_cnt);
33d8899132SKalle Valo 
34d8899132SKalle Valo 	rx_user_status->mpdu_ok_byte_count =
35d8899132SKalle Valo 		u32_get_bits(mpdu_ok_byte_count,
36d8899132SKalle Valo 			     HAL_RX_PPDU_END_USER_STATS_MPDU_DELIM_OK_BYTE_COUNT);
37d8899132SKalle Valo 	rx_user_status->mpdu_err_byte_count =
38d8899132SKalle Valo 		u32_get_bits(mpdu_err_byte_count,
39d8899132SKalle Valo 			     HAL_RX_PPDU_END_USER_STATS_MPDU_DELIM_ERR_BYTE_COUNT);
40d8899132SKalle Valo }
41d8899132SKalle Valo 
42d8899132SKalle Valo static void
ath12k_dp_mon_rx_populate_mu_user_info(void * rx_tlv,struct hal_rx_mon_ppdu_info * ppdu_info,struct hal_rx_user_status * rx_user_status)43d8899132SKalle Valo ath12k_dp_mon_rx_populate_mu_user_info(void *rx_tlv,
44d8899132SKalle Valo 				       struct hal_rx_mon_ppdu_info *ppdu_info,
45d8899132SKalle Valo 				       struct hal_rx_user_status *rx_user_status)
46d8899132SKalle Valo {
47d8899132SKalle Valo 	rx_user_status->ast_index = ppdu_info->ast_index;
48d8899132SKalle Valo 	rx_user_status->tid = ppdu_info->tid;
49d8899132SKalle Valo 	rx_user_status->tcp_ack_msdu_count =
50d8899132SKalle Valo 		ppdu_info->tcp_ack_msdu_count;
51d8899132SKalle Valo 	rx_user_status->tcp_msdu_count =
52d8899132SKalle Valo 		ppdu_info->tcp_msdu_count;
53d8899132SKalle Valo 	rx_user_status->udp_msdu_count =
54d8899132SKalle Valo 		ppdu_info->udp_msdu_count;
55d8899132SKalle Valo 	rx_user_status->other_msdu_count =
56d8899132SKalle Valo 		ppdu_info->other_msdu_count;
57d8899132SKalle Valo 	rx_user_status->frame_control = ppdu_info->frame_control;
58d8899132SKalle Valo 	rx_user_status->frame_control_info_valid =
59d8899132SKalle Valo 		ppdu_info->frame_control_info_valid;
60d8899132SKalle Valo 	rx_user_status->data_sequence_control_info_valid =
61d8899132SKalle Valo 		ppdu_info->data_sequence_control_info_valid;
62d8899132SKalle Valo 	rx_user_status->first_data_seq_ctrl =
63d8899132SKalle Valo 		ppdu_info->first_data_seq_ctrl;
64d8899132SKalle Valo 	rx_user_status->preamble_type = ppdu_info->preamble_type;
65d8899132SKalle Valo 	rx_user_status->ht_flags = ppdu_info->ht_flags;
66d8899132SKalle Valo 	rx_user_status->vht_flags = ppdu_info->vht_flags;
67d8899132SKalle Valo 	rx_user_status->he_flags = ppdu_info->he_flags;
68d8899132SKalle Valo 	rx_user_status->rs_flags = ppdu_info->rs_flags;
69d8899132SKalle Valo 
70d8899132SKalle Valo 	rx_user_status->mpdu_cnt_fcs_ok =
71d8899132SKalle Valo 		ppdu_info->num_mpdu_fcs_ok;
72d8899132SKalle Valo 	rx_user_status->mpdu_cnt_fcs_err =
73d8899132SKalle Valo 		ppdu_info->num_mpdu_fcs_err;
74d8899132SKalle Valo 	memcpy(&rx_user_status->mpdu_fcs_ok_bitmap[0], &ppdu_info->mpdu_fcs_ok_bitmap[0],
75d8899132SKalle Valo 	       HAL_RX_NUM_WORDS_PER_PPDU_BITMAP *
76d8899132SKalle Valo 	       sizeof(ppdu_info->mpdu_fcs_ok_bitmap[0]));
77d8899132SKalle Valo 
78d8899132SKalle Valo 	ath12k_dp_mon_rx_populate_byte_count(rx_tlv, ppdu_info, rx_user_status);
79d8899132SKalle Valo }
80d8899132SKalle Valo 
ath12k_dp_mon_parse_vht_sig_a(u8 * tlv_data,struct hal_rx_mon_ppdu_info * ppdu_info)81d8899132SKalle Valo static void ath12k_dp_mon_parse_vht_sig_a(u8 *tlv_data,
82d8899132SKalle Valo 					  struct hal_rx_mon_ppdu_info *ppdu_info)
83d8899132SKalle Valo {
84d8899132SKalle Valo 	struct hal_rx_vht_sig_a_info *vht_sig =
85d8899132SKalle Valo 			(struct hal_rx_vht_sig_a_info *)tlv_data;
86d8899132SKalle Valo 	u32 nsts, group_id, info0, info1;
87d8899132SKalle Valo 	u8 gi_setting;
88d8899132SKalle Valo 
89d8899132SKalle Valo 	info0 = __le32_to_cpu(vht_sig->info0);
90d8899132SKalle Valo 	info1 = __le32_to_cpu(vht_sig->info1);
91d8899132SKalle Valo 
92d8899132SKalle Valo 	ppdu_info->ldpc = u32_get_bits(info1, HAL_RX_VHT_SIG_A_INFO_INFO1_SU_MU_CODING);
93d8899132SKalle Valo 	ppdu_info->mcs = u32_get_bits(info1, HAL_RX_VHT_SIG_A_INFO_INFO1_MCS);
94d8899132SKalle Valo 	gi_setting = u32_get_bits(info1, HAL_RX_VHT_SIG_A_INFO_INFO1_GI_SETTING);
95d8899132SKalle Valo 	switch (gi_setting) {
96d8899132SKalle Valo 	case HAL_RX_VHT_SIG_A_NORMAL_GI:
97d8899132SKalle Valo 		ppdu_info->gi = HAL_RX_GI_0_8_US;
98d8899132SKalle Valo 		break;
99d8899132SKalle Valo 	case HAL_RX_VHT_SIG_A_SHORT_GI:
100d8899132SKalle Valo 	case HAL_RX_VHT_SIG_A_SHORT_GI_AMBIGUITY:
101d8899132SKalle Valo 		ppdu_info->gi = HAL_RX_GI_0_4_US;
102d8899132SKalle Valo 		break;
103d8899132SKalle Valo 	}
104d8899132SKalle Valo 
105d8899132SKalle Valo 	ppdu_info->is_stbc = u32_get_bits(info0, HAL_RX_VHT_SIG_A_INFO_INFO0_STBC);
106d8899132SKalle Valo 	nsts = u32_get_bits(info0, HAL_RX_VHT_SIG_A_INFO_INFO0_NSTS);
107d8899132SKalle Valo 	if (ppdu_info->is_stbc && nsts > 0)
108d8899132SKalle Valo 		nsts = ((nsts + 1) >> 1) - 1;
109d8899132SKalle Valo 
110d8899132SKalle Valo 	ppdu_info->nss = u32_get_bits(nsts, VHT_SIG_SU_NSS_MASK);
111d8899132SKalle Valo 	ppdu_info->bw = u32_get_bits(info0, HAL_RX_VHT_SIG_A_INFO_INFO0_BW);
112d8899132SKalle Valo 	ppdu_info->beamformed = u32_get_bits(info1,
113d8899132SKalle Valo 					     HAL_RX_VHT_SIG_A_INFO_INFO1_BEAMFORMED);
114d8899132SKalle Valo 	group_id = u32_get_bits(info0, HAL_RX_VHT_SIG_A_INFO_INFO0_GROUP_ID);
115d8899132SKalle Valo 	if (group_id == 0 || group_id == 63)
116d8899132SKalle Valo 		ppdu_info->reception_type = HAL_RX_RECEPTION_TYPE_SU;
117d8899132SKalle Valo 	else
118d8899132SKalle Valo 		ppdu_info->reception_type = HAL_RX_RECEPTION_TYPE_MU_MIMO;
119d8899132SKalle Valo 	ppdu_info->vht_flag_values5 = group_id;
120d8899132SKalle Valo 	ppdu_info->vht_flag_values3[0] = (((ppdu_info->mcs) << 4) |
121d8899132SKalle Valo 					    ppdu_info->nss);
122d8899132SKalle Valo 	ppdu_info->vht_flag_values2 = ppdu_info->bw;
123d8899132SKalle Valo 	ppdu_info->vht_flag_values4 =
124d8899132SKalle Valo 		u32_get_bits(info1, HAL_RX_VHT_SIG_A_INFO_INFO1_SU_MU_CODING);
125d8899132SKalle Valo }
126d8899132SKalle Valo 
ath12k_dp_mon_parse_ht_sig(u8 * tlv_data,struct hal_rx_mon_ppdu_info * ppdu_info)127d8899132SKalle Valo static void ath12k_dp_mon_parse_ht_sig(u8 *tlv_data,
128d8899132SKalle Valo 				       struct hal_rx_mon_ppdu_info *ppdu_info)
129d8899132SKalle Valo {
130d8899132SKalle Valo 	struct hal_rx_ht_sig_info *ht_sig =
131d8899132SKalle Valo 			(struct hal_rx_ht_sig_info *)tlv_data;
132d8899132SKalle Valo 	u32 info0 = __le32_to_cpu(ht_sig->info0);
133d8899132SKalle Valo 	u32 info1 = __le32_to_cpu(ht_sig->info1);
134d8899132SKalle Valo 
135d8899132SKalle Valo 	ppdu_info->mcs = u32_get_bits(info0, HAL_RX_HT_SIG_INFO_INFO0_MCS);
136d8899132SKalle Valo 	ppdu_info->bw = u32_get_bits(info0, HAL_RX_HT_SIG_INFO_INFO0_BW);
137d8899132SKalle Valo 	ppdu_info->is_stbc = u32_get_bits(info1, HAL_RX_HT_SIG_INFO_INFO1_STBC);
138d8899132SKalle Valo 	ppdu_info->ldpc = u32_get_bits(info1, HAL_RX_HT_SIG_INFO_INFO1_FEC_CODING);
139d8899132SKalle Valo 	ppdu_info->gi = u32_get_bits(info1, HAL_RX_HT_SIG_INFO_INFO1_GI);
140d8899132SKalle Valo 	ppdu_info->nss = (ppdu_info->mcs >> 3);
141d8899132SKalle Valo 	ppdu_info->reception_type = HAL_RX_RECEPTION_TYPE_SU;
142d8899132SKalle Valo }
143d8899132SKalle Valo 
ath12k_dp_mon_parse_l_sig_b(u8 * tlv_data,struct hal_rx_mon_ppdu_info * ppdu_info)144d8899132SKalle Valo static void ath12k_dp_mon_parse_l_sig_b(u8 *tlv_data,
145d8899132SKalle Valo 					struct hal_rx_mon_ppdu_info *ppdu_info)
146d8899132SKalle Valo {
147d8899132SKalle Valo 	struct hal_rx_lsig_b_info *lsigb =
148d8899132SKalle Valo 			(struct hal_rx_lsig_b_info *)tlv_data;
149d8899132SKalle Valo 	u32 info0 = __le32_to_cpu(lsigb->info0);
150d8899132SKalle Valo 	u8 rate;
151d8899132SKalle Valo 
152d8899132SKalle Valo 	rate = u32_get_bits(info0, HAL_RX_LSIG_B_INFO_INFO0_RATE);
153d8899132SKalle Valo 	switch (rate) {
154d8899132SKalle Valo 	case 1:
155d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_1_MBPS;
156d8899132SKalle Valo 		break;
157d8899132SKalle Valo 	case 2:
158d8899132SKalle Valo 	case 5:
159d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_2_MBPS;
160d8899132SKalle Valo 		break;
161d8899132SKalle Valo 	case 3:
162d8899132SKalle Valo 	case 6:
163d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_5_5_MBPS;
164d8899132SKalle Valo 		break;
165d8899132SKalle Valo 	case 4:
166d8899132SKalle Valo 	case 7:
167d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_11_MBPS;
168d8899132SKalle Valo 		break;
169d8899132SKalle Valo 	default:
170d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_INVALID;
171d8899132SKalle Valo 	}
172d8899132SKalle Valo 
173d8899132SKalle Valo 	ppdu_info->rate = rate;
174d8899132SKalle Valo 	ppdu_info->cck_flag = 1;
175d8899132SKalle Valo 	ppdu_info->reception_type = HAL_RX_RECEPTION_TYPE_SU;
176d8899132SKalle Valo }
177d8899132SKalle Valo 
ath12k_dp_mon_parse_l_sig_a(u8 * tlv_data,struct hal_rx_mon_ppdu_info * ppdu_info)178d8899132SKalle Valo static void ath12k_dp_mon_parse_l_sig_a(u8 *tlv_data,
179d8899132SKalle Valo 					struct hal_rx_mon_ppdu_info *ppdu_info)
180d8899132SKalle Valo {
181d8899132SKalle Valo 	struct hal_rx_lsig_a_info *lsiga =
182d8899132SKalle Valo 			(struct hal_rx_lsig_a_info *)tlv_data;
183d8899132SKalle Valo 	u32 info0 = __le32_to_cpu(lsiga->info0);
184d8899132SKalle Valo 	u8 rate;
185d8899132SKalle Valo 
186d8899132SKalle Valo 	rate = u32_get_bits(info0, HAL_RX_LSIG_A_INFO_INFO0_RATE);
187d8899132SKalle Valo 	switch (rate) {
188d8899132SKalle Valo 	case 8:
189d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_48_MBPS;
190d8899132SKalle Valo 		break;
191d8899132SKalle Valo 	case 9:
192d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_24_MBPS;
193d8899132SKalle Valo 		break;
194d8899132SKalle Valo 	case 10:
195d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_12_MBPS;
196d8899132SKalle Valo 		break;
197d8899132SKalle Valo 	case 11:
198d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_6_MBPS;
199d8899132SKalle Valo 		break;
200d8899132SKalle Valo 	case 12:
201d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_54_MBPS;
202d8899132SKalle Valo 		break;
203d8899132SKalle Valo 	case 13:
204d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_36_MBPS;
205d8899132SKalle Valo 		break;
206d8899132SKalle Valo 	case 14:
207d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_18_MBPS;
208d8899132SKalle Valo 		break;
209d8899132SKalle Valo 	case 15:
210d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_9_MBPS;
211d8899132SKalle Valo 		break;
212d8899132SKalle Valo 	default:
213d8899132SKalle Valo 		rate = HAL_RX_LEGACY_RATE_INVALID;
214d8899132SKalle Valo 	}
215d8899132SKalle Valo 
216d8899132SKalle Valo 	ppdu_info->rate = rate;
217d8899132SKalle Valo 	ppdu_info->reception_type = HAL_RX_RECEPTION_TYPE_SU;
218d8899132SKalle Valo }
219d8899132SKalle Valo 
ath12k_dp_mon_parse_he_sig_b2_ofdma(u8 * tlv_data,struct hal_rx_mon_ppdu_info * ppdu_info)220d8899132SKalle Valo static void ath12k_dp_mon_parse_he_sig_b2_ofdma(u8 *tlv_data,
221d8899132SKalle Valo 						struct hal_rx_mon_ppdu_info *ppdu_info)
222d8899132SKalle Valo {
223d8899132SKalle Valo 	struct hal_rx_he_sig_b2_ofdma_info *he_sig_b2_ofdma =
224d8899132SKalle Valo 			(struct hal_rx_he_sig_b2_ofdma_info *)tlv_data;
225d8899132SKalle Valo 	u32 info0, value;
226d8899132SKalle Valo 
227d8899132SKalle Valo 	info0 = __le32_to_cpu(he_sig_b2_ofdma->info0);
228d8899132SKalle Valo 
229d8899132SKalle Valo 	ppdu_info->he_data1 |= HE_MCS_KNOWN | HE_DCM_KNOWN | HE_CODING_KNOWN;
230d8899132SKalle Valo 
231d8899132SKalle Valo 	/* HE-data2 */
232d8899132SKalle Valo 	ppdu_info->he_data2 |= HE_TXBF_KNOWN;
233d8899132SKalle Valo 
234d8899132SKalle Valo 	ppdu_info->mcs = u32_get_bits(info0, HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_MCS);
235d8899132SKalle Valo 	value = ppdu_info->mcs << HE_TRANSMIT_MCS_SHIFT;
236d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
237d8899132SKalle Valo 
238d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_DCM);
239d8899132SKalle Valo 	value = value << HE_DCM_SHIFT;
240d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
241d8899132SKalle Valo 
242d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_CODING);
243d8899132SKalle Valo 	ppdu_info->ldpc = value;
244d8899132SKalle Valo 	value = value << HE_CODING_SHIFT;
245d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
246d8899132SKalle Valo 
247d8899132SKalle Valo 	/* HE-data4 */
248d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_ID);
249d8899132SKalle Valo 	value = value << HE_STA_ID_SHIFT;
250d8899132SKalle Valo 	ppdu_info->he_data4 |= value;
251d8899132SKalle Valo 
252d8899132SKalle Valo 	ppdu_info->nss = u32_get_bits(info0, HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_NSTS);
253d8899132SKalle Valo 	ppdu_info->beamformed = u32_get_bits(info0,
254d8899132SKalle Valo 					     HAL_RX_HE_SIG_B2_OFDMA_INFO_INFO0_STA_TXBF);
255d8899132SKalle Valo 	ppdu_info->reception_type = HAL_RX_RECEPTION_TYPE_MU_OFDMA;
256d8899132SKalle Valo }
257d8899132SKalle Valo 
ath12k_dp_mon_parse_he_sig_b2_mu(u8 * tlv_data,struct hal_rx_mon_ppdu_info * ppdu_info)258d8899132SKalle Valo static void ath12k_dp_mon_parse_he_sig_b2_mu(u8 *tlv_data,
259d8899132SKalle Valo 					     struct hal_rx_mon_ppdu_info *ppdu_info)
260d8899132SKalle Valo {
261d8899132SKalle Valo 	struct hal_rx_he_sig_b2_mu_info *he_sig_b2_mu =
262d8899132SKalle Valo 			(struct hal_rx_he_sig_b2_mu_info *)tlv_data;
263d8899132SKalle Valo 	u32 info0, value;
264d8899132SKalle Valo 
265d8899132SKalle Valo 	info0 = __le32_to_cpu(he_sig_b2_mu->info0);
266d8899132SKalle Valo 
267d8899132SKalle Valo 	ppdu_info->he_data1 |= HE_MCS_KNOWN | HE_CODING_KNOWN;
268d8899132SKalle Valo 
269d8899132SKalle Valo 	ppdu_info->mcs = u32_get_bits(info0, HAL_RX_HE_SIG_B2_MU_INFO_INFO0_STA_MCS);
270d8899132SKalle Valo 	value = ppdu_info->mcs << HE_TRANSMIT_MCS_SHIFT;
271d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
272d8899132SKalle Valo 
273d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_B2_MU_INFO_INFO0_STA_CODING);
274d8899132SKalle Valo 	ppdu_info->ldpc = value;
275d8899132SKalle Valo 	value = value << HE_CODING_SHIFT;
276d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
277d8899132SKalle Valo 
278d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_B2_MU_INFO_INFO0_STA_ID);
279d8899132SKalle Valo 	value = value << HE_STA_ID_SHIFT;
280d8899132SKalle Valo 	ppdu_info->he_data4 |= value;
281d8899132SKalle Valo 
282d8899132SKalle Valo 	ppdu_info->nss = u32_get_bits(info0, HAL_RX_HE_SIG_B2_MU_INFO_INFO0_STA_NSTS);
283d8899132SKalle Valo }
284d8899132SKalle Valo 
ath12k_dp_mon_parse_he_sig_b1_mu(u8 * tlv_data,struct hal_rx_mon_ppdu_info * ppdu_info)285d8899132SKalle Valo static void ath12k_dp_mon_parse_he_sig_b1_mu(u8 *tlv_data,
286d8899132SKalle Valo 					     struct hal_rx_mon_ppdu_info *ppdu_info)
287d8899132SKalle Valo {
288d8899132SKalle Valo 	struct hal_rx_he_sig_b1_mu_info *he_sig_b1_mu =
289d8899132SKalle Valo 			(struct hal_rx_he_sig_b1_mu_info *)tlv_data;
290d8899132SKalle Valo 	u32 info0 = __le32_to_cpu(he_sig_b1_mu->info0);
291d8899132SKalle Valo 	u16 ru_tones;
292d8899132SKalle Valo 
293d8899132SKalle Valo 	ru_tones = u32_get_bits(info0,
294d8899132SKalle Valo 				HAL_RX_HE_SIG_B1_MU_INFO_INFO0_RU_ALLOCATION);
295d8899132SKalle Valo 	ppdu_info->ru_alloc = ath12k_he_ru_tones_to_nl80211_he_ru_alloc(ru_tones);
296d8899132SKalle Valo 	ppdu_info->he_RU[0] = ru_tones;
297d8899132SKalle Valo 	ppdu_info->reception_type = HAL_RX_RECEPTION_TYPE_MU_MIMO;
298d8899132SKalle Valo }
299d8899132SKalle Valo 
ath12k_dp_mon_parse_he_sig_mu(u8 * tlv_data,struct hal_rx_mon_ppdu_info * ppdu_info)300d8899132SKalle Valo static void ath12k_dp_mon_parse_he_sig_mu(u8 *tlv_data,
301d8899132SKalle Valo 					  struct hal_rx_mon_ppdu_info *ppdu_info)
302d8899132SKalle Valo {
303d8899132SKalle Valo 	struct hal_rx_he_sig_a_mu_dl_info *he_sig_a_mu_dl =
304d8899132SKalle Valo 			(struct hal_rx_he_sig_a_mu_dl_info *)tlv_data;
305d8899132SKalle Valo 	u32 info0, info1, value;
306d8899132SKalle Valo 	u16 he_gi = 0, he_ltf = 0;
307d8899132SKalle Valo 
308d8899132SKalle Valo 	info0 = __le32_to_cpu(he_sig_a_mu_dl->info0);
309d8899132SKalle Valo 	info1 = __le32_to_cpu(he_sig_a_mu_dl->info1);
310d8899132SKalle Valo 
311d8899132SKalle Valo 	ppdu_info->he_mu_flags = 1;
312d8899132SKalle Valo 
313d8899132SKalle Valo 	ppdu_info->he_data1 = HE_MU_FORMAT_TYPE;
314d8899132SKalle Valo 	ppdu_info->he_data1 |=
315d8899132SKalle Valo 			HE_BSS_COLOR_KNOWN |
316d8899132SKalle Valo 			HE_DL_UL_KNOWN |
317d8899132SKalle Valo 			HE_LDPC_EXTRA_SYMBOL_KNOWN |
318d8899132SKalle Valo 			HE_STBC_KNOWN |
319d8899132SKalle Valo 			HE_DATA_BW_RU_KNOWN |
320d8899132SKalle Valo 			HE_DOPPLER_KNOWN;
321d8899132SKalle Valo 
322d8899132SKalle Valo 	ppdu_info->he_data2 =
323d8899132SKalle Valo 			HE_GI_KNOWN |
324d8899132SKalle Valo 			HE_LTF_SYMBOLS_KNOWN |
325d8899132SKalle Valo 			HE_PRE_FEC_PADDING_KNOWN |
326d8899132SKalle Valo 			HE_PE_DISAMBIGUITY_KNOWN |
327d8899132SKalle Valo 			HE_TXOP_KNOWN |
328d8899132SKalle Valo 			HE_MIDABLE_PERIODICITY_KNOWN;
329d8899132SKalle Valo 
330d8899132SKalle Valo 	/* data3 */
331d8899132SKalle Valo 	ppdu_info->he_data3 = u32_get_bits(info0, HAL_RX_HE_SIG_A_MU_DL_INFO0_BSS_COLOR);
332d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_MU_DL_INFO0_UL_FLAG);
333d8899132SKalle Valo 	value = value << HE_DL_UL_SHIFT;
334d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
335d8899132SKalle Valo 
336d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_MU_DL_INFO1_LDPC_EXTRA);
337d8899132SKalle Valo 	value = value << HE_LDPC_EXTRA_SYMBOL_SHIFT;
338d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
339d8899132SKalle Valo 
340d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_MU_DL_INFO1_STBC);
341d8899132SKalle Valo 	value = value << HE_STBC_SHIFT;
342d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
343d8899132SKalle Valo 
344d8899132SKalle Valo 	/* data4 */
345d8899132SKalle Valo 	ppdu_info->he_data4 = u32_get_bits(info0,
346d8899132SKalle Valo 					   HAL_RX_HE_SIG_A_MU_DL_INFO0_SPATIAL_REUSE);
347d8899132SKalle Valo 	ppdu_info->he_data4 = value;
348d8899132SKalle Valo 
349d8899132SKalle Valo 	/* data5 */
350d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_MU_DL_INFO0_TRANSMIT_BW);
351d8899132SKalle Valo 	ppdu_info->he_data5 = value;
352d8899132SKalle Valo 	ppdu_info->bw = value;
353d8899132SKalle Valo 
354d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_MU_DL_INFO0_CP_LTF_SIZE);
355d8899132SKalle Valo 	switch (value) {
356d8899132SKalle Valo 	case 0:
357d8899132SKalle Valo 		he_gi = HE_GI_0_8;
358d8899132SKalle Valo 		he_ltf = HE_LTF_4_X;
359d8899132SKalle Valo 		break;
360d8899132SKalle Valo 	case 1:
361d8899132SKalle Valo 		he_gi = HE_GI_0_8;
362d8899132SKalle Valo 		he_ltf = HE_LTF_2_X;
363d8899132SKalle Valo 		break;
364d8899132SKalle Valo 	case 2:
365d8899132SKalle Valo 		he_gi = HE_GI_1_6;
366d8899132SKalle Valo 		he_ltf = HE_LTF_2_X;
367d8899132SKalle Valo 		break;
368d8899132SKalle Valo 	case 3:
369d8899132SKalle Valo 		he_gi = HE_GI_3_2;
370d8899132SKalle Valo 		he_ltf = HE_LTF_4_X;
371d8899132SKalle Valo 		break;
372d8899132SKalle Valo 	}
373d8899132SKalle Valo 
374d8899132SKalle Valo 	ppdu_info->gi = he_gi;
375d8899132SKalle Valo 	value = he_gi << HE_GI_SHIFT;
376d8899132SKalle Valo 	ppdu_info->he_data5 |= value;
377d8899132SKalle Valo 
378d8899132SKalle Valo 	value = he_ltf << HE_LTF_SIZE_SHIFT;
379d8899132SKalle Valo 	ppdu_info->he_data5 |= value;
380d8899132SKalle Valo 
381d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_MU_DL_INFO1_NUM_LTF_SYMB);
382d8899132SKalle Valo 	value = (value << HE_LTF_SYM_SHIFT);
383d8899132SKalle Valo 	ppdu_info->he_data5 |= value;
384d8899132SKalle Valo 
385d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_MU_DL_INFO1_PKT_EXT_FACTOR);
386d8899132SKalle Valo 	value = value << HE_PRE_FEC_PAD_SHIFT;
387d8899132SKalle Valo 	ppdu_info->he_data5 |= value;
388d8899132SKalle Valo 
389d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_MU_DL_INFO1_PKT_EXT_PE_DISAM);
390d8899132SKalle Valo 	value = value << HE_PE_DISAMBIGUITY_SHIFT;
391d8899132SKalle Valo 	ppdu_info->he_data5 |= value;
392d8899132SKalle Valo 
393d8899132SKalle Valo 	/*data6*/
394d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_MU_DL_INFO0_DOPPLER_INDICATION);
395d8899132SKalle Valo 	value = value << HE_DOPPLER_SHIFT;
396d8899132SKalle Valo 	ppdu_info->he_data6 |= value;
397d8899132SKalle Valo 
398d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_MU_DL_INFO1_TXOP_DURATION);
399d8899132SKalle Valo 	value = value << HE_TXOP_SHIFT;
400d8899132SKalle Valo 	ppdu_info->he_data6 |= value;
401d8899132SKalle Valo 
402d8899132SKalle Valo 	/* HE-MU Flags */
403d8899132SKalle Valo 	/* HE-MU-flags1 */
404d8899132SKalle Valo 	ppdu_info->he_flags1 =
405d8899132SKalle Valo 		HE_SIG_B_MCS_KNOWN |
406d8899132SKalle Valo 		HE_SIG_B_DCM_KNOWN |
407d8899132SKalle Valo 		HE_SIG_B_COMPRESSION_FLAG_1_KNOWN |
408d8899132SKalle Valo 		HE_SIG_B_SYM_NUM_KNOWN |
409d8899132SKalle Valo 		HE_RU_0_KNOWN;
410d8899132SKalle Valo 
411d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_MU_DL_INFO0_MCS_OF_SIGB);
412d8899132SKalle Valo 	ppdu_info->he_flags1 |= value;
413d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_MU_DL_INFO0_DCM_OF_SIGB);
414d8899132SKalle Valo 	value = value << HE_DCM_FLAG_1_SHIFT;
415d8899132SKalle Valo 	ppdu_info->he_flags1 |= value;
416d8899132SKalle Valo 
417d8899132SKalle Valo 	/* HE-MU-flags2 */
418d8899132SKalle Valo 	ppdu_info->he_flags2 = HE_BW_KNOWN;
419d8899132SKalle Valo 
420d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_MU_DL_INFO0_TRANSMIT_BW);
421d8899132SKalle Valo 	ppdu_info->he_flags2 |= value;
422d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_MU_DL_INFO0_COMP_MODE_SIGB);
423d8899132SKalle Valo 	value = value << HE_SIG_B_COMPRESSION_FLAG_2_SHIFT;
424d8899132SKalle Valo 	ppdu_info->he_flags2 |= value;
425d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_MU_DL_INFO0_NUM_SIGB_SYMB);
426d8899132SKalle Valo 	value = value - 1;
427d8899132SKalle Valo 	value = value << HE_NUM_SIG_B_SYMBOLS_SHIFT;
428d8899132SKalle Valo 	ppdu_info->he_flags2 |= value;
429d8899132SKalle Valo 
430d8899132SKalle Valo 	ppdu_info->is_stbc = info1 &
431d8899132SKalle Valo 			     HAL_RX_HE_SIG_A_MU_DL_INFO1_STBC;
432d8899132SKalle Valo 	ppdu_info->reception_type = HAL_RX_RECEPTION_TYPE_MU_MIMO;
433d8899132SKalle Valo }
434d8899132SKalle Valo 
ath12k_dp_mon_parse_he_sig_su(u8 * tlv_data,struct hal_rx_mon_ppdu_info * ppdu_info)435d8899132SKalle Valo static void ath12k_dp_mon_parse_he_sig_su(u8 *tlv_data,
436d8899132SKalle Valo 					  struct hal_rx_mon_ppdu_info *ppdu_info)
437d8899132SKalle Valo {
438d8899132SKalle Valo 	struct hal_rx_he_sig_a_su_info *he_sig_a =
439d8899132SKalle Valo 			(struct hal_rx_he_sig_a_su_info *)tlv_data;
440d8899132SKalle Valo 	u32 info0, info1, value;
441d8899132SKalle Valo 	u32 dcm;
442d8899132SKalle Valo 	u8 he_dcm = 0, he_stbc = 0;
443d8899132SKalle Valo 	u16 he_gi = 0, he_ltf = 0;
444d8899132SKalle Valo 
445d8899132SKalle Valo 	ppdu_info->he_flags = 1;
446d8899132SKalle Valo 
447d8899132SKalle Valo 	info0 = __le32_to_cpu(he_sig_a->info0);
448d8899132SKalle Valo 	info1 = __le32_to_cpu(he_sig_a->info1);
449d8899132SKalle Valo 
450d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_SU_INFO_INFO0_FORMAT_IND);
451d8899132SKalle Valo 	if (value == 0)
452d8899132SKalle Valo 		ppdu_info->he_data1 = HE_TRIG_FORMAT_TYPE;
453d8899132SKalle Valo 	else
454d8899132SKalle Valo 		ppdu_info->he_data1 = HE_SU_FORMAT_TYPE;
455d8899132SKalle Valo 
456d8899132SKalle Valo 	ppdu_info->he_data1 |=
457d8899132SKalle Valo 			HE_BSS_COLOR_KNOWN |
458d8899132SKalle Valo 			HE_BEAM_CHANGE_KNOWN |
459d8899132SKalle Valo 			HE_DL_UL_KNOWN |
460d8899132SKalle Valo 			HE_MCS_KNOWN |
461d8899132SKalle Valo 			HE_DCM_KNOWN |
462d8899132SKalle Valo 			HE_CODING_KNOWN |
463d8899132SKalle Valo 			HE_LDPC_EXTRA_SYMBOL_KNOWN |
464d8899132SKalle Valo 			HE_STBC_KNOWN |
465d8899132SKalle Valo 			HE_DATA_BW_RU_KNOWN |
466d8899132SKalle Valo 			HE_DOPPLER_KNOWN;
467d8899132SKalle Valo 
468d8899132SKalle Valo 	ppdu_info->he_data2 |=
469d8899132SKalle Valo 			HE_GI_KNOWN |
470d8899132SKalle Valo 			HE_TXBF_KNOWN |
471d8899132SKalle Valo 			HE_PE_DISAMBIGUITY_KNOWN |
472d8899132SKalle Valo 			HE_TXOP_KNOWN |
473d8899132SKalle Valo 			HE_LTF_SYMBOLS_KNOWN |
474d8899132SKalle Valo 			HE_PRE_FEC_PADDING_KNOWN |
475d8899132SKalle Valo 			HE_MIDABLE_PERIODICITY_KNOWN;
476d8899132SKalle Valo 
477d8899132SKalle Valo 	ppdu_info->he_data3 = u32_get_bits(info0,
478d8899132SKalle Valo 					   HAL_RX_HE_SIG_A_SU_INFO_INFO0_BSS_COLOR);
479d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_SU_INFO_INFO0_BEAM_CHANGE);
480d8899132SKalle Valo 	value = value << HE_BEAM_CHANGE_SHIFT;
481d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
482d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_SU_INFO_INFO0_DL_UL_FLAG);
483d8899132SKalle Valo 	value = value << HE_DL_UL_SHIFT;
484d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
485d8899132SKalle Valo 
486d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_SU_INFO_INFO0_TRANSMIT_MCS);
487d8899132SKalle Valo 	ppdu_info->mcs = value;
488d8899132SKalle Valo 	value = value << HE_TRANSMIT_MCS_SHIFT;
489d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
490d8899132SKalle Valo 
491d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_SU_INFO_INFO0_DCM);
492d8899132SKalle Valo 	he_dcm = value;
493d8899132SKalle Valo 	value = value << HE_DCM_SHIFT;
494d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
495d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_SU_INFO_INFO1_CODING);
496d8899132SKalle Valo 	value = value << HE_CODING_SHIFT;
497d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
498d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_SU_INFO_INFO1_LDPC_EXTRA);
499d8899132SKalle Valo 	value = value << HE_LDPC_EXTRA_SYMBOL_SHIFT;
500d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
501d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_SU_INFO_INFO1_STBC);
502d8899132SKalle Valo 	he_stbc = value;
503d8899132SKalle Valo 	value = value << HE_STBC_SHIFT;
504d8899132SKalle Valo 	ppdu_info->he_data3 |= value;
505d8899132SKalle Valo 
506d8899132SKalle Valo 	/* data4 */
507d8899132SKalle Valo 	ppdu_info->he_data4 = u32_get_bits(info0,
508d8899132SKalle Valo 					   HAL_RX_HE_SIG_A_SU_INFO_INFO0_SPATIAL_REUSE);
509d8899132SKalle Valo 
510d8899132SKalle Valo 	/* data5 */
511d8899132SKalle Valo 	value = u32_get_bits(info0,
512d8899132SKalle Valo 			     HAL_RX_HE_SIG_A_SU_INFO_INFO0_TRANSMIT_BW);
513d8899132SKalle Valo 	ppdu_info->he_data5 = value;
514d8899132SKalle Valo 	ppdu_info->bw = value;
515d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_SU_INFO_INFO0_CP_LTF_SIZE);
516d8899132SKalle Valo 	switch (value) {
517d8899132SKalle Valo 	case 0:
518d8899132SKalle Valo 		he_gi = HE_GI_0_8;
519d8899132SKalle Valo 		he_ltf = HE_LTF_1_X;
520d8899132SKalle Valo 		break;
521d8899132SKalle Valo 	case 1:
522d8899132SKalle Valo 		he_gi = HE_GI_0_8;
523d8899132SKalle Valo 		he_ltf = HE_LTF_2_X;
524d8899132SKalle Valo 		break;
525d8899132SKalle Valo 	case 2:
526d8899132SKalle Valo 		he_gi = HE_GI_1_6;
527d8899132SKalle Valo 		he_ltf = HE_LTF_2_X;
528d8899132SKalle Valo 		break;
529d8899132SKalle Valo 	case 3:
530d8899132SKalle Valo 		if (he_dcm && he_stbc) {
531d8899132SKalle Valo 			he_gi = HE_GI_0_8;
532d8899132SKalle Valo 			he_ltf = HE_LTF_4_X;
533d8899132SKalle Valo 		} else {
534d8899132SKalle Valo 			he_gi = HE_GI_3_2;
535d8899132SKalle Valo 			he_ltf = HE_LTF_4_X;
536d8899132SKalle Valo 		}
537d8899132SKalle Valo 		break;
538d8899132SKalle Valo 	}
539d8899132SKalle Valo 	ppdu_info->gi = he_gi;
540d8899132SKalle Valo 	value = he_gi << HE_GI_SHIFT;
541d8899132SKalle Valo 	ppdu_info->he_data5 |= value;
542d8899132SKalle Valo 	value = he_ltf << HE_LTF_SIZE_SHIFT;
543d8899132SKalle Valo 	ppdu_info->ltf_size = he_ltf;
544d8899132SKalle Valo 	ppdu_info->he_data5 |= value;
545d8899132SKalle Valo 
546d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_SU_INFO_INFO0_NSTS);
547d8899132SKalle Valo 	value = (value << HE_LTF_SYM_SHIFT);
548d8899132SKalle Valo 	ppdu_info->he_data5 |= value;
549d8899132SKalle Valo 
550d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_SU_INFO_INFO1_PKT_EXT_FACTOR);
551d8899132SKalle Valo 	value = value << HE_PRE_FEC_PAD_SHIFT;
552d8899132SKalle Valo 	ppdu_info->he_data5 |= value;
553d8899132SKalle Valo 
554d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_SU_INFO_INFO1_TXBF);
555d8899132SKalle Valo 	value = value << HE_TXBF_SHIFT;
556d8899132SKalle Valo 	ppdu_info->he_data5 |= value;
557d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_SU_INFO_INFO1_PKT_EXT_PE_DISAM);
558d8899132SKalle Valo 	value = value << HE_PE_DISAMBIGUITY_SHIFT;
559d8899132SKalle Valo 	ppdu_info->he_data5 |= value;
560d8899132SKalle Valo 
561d8899132SKalle Valo 	/* data6 */
562d8899132SKalle Valo 	value = u32_get_bits(info0, HAL_RX_HE_SIG_A_SU_INFO_INFO0_NSTS);
563d8899132SKalle Valo 	value++;
564d8899132SKalle Valo 	ppdu_info->he_data6 = value;
565d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_SU_INFO_INFO1_DOPPLER_IND);
566d8899132SKalle Valo 	value = value << HE_DOPPLER_SHIFT;
567d8899132SKalle Valo 	ppdu_info->he_data6 |= value;
568d8899132SKalle Valo 	value = u32_get_bits(info1, HAL_RX_HE_SIG_A_SU_INFO_INFO1_TXOP_DURATION);
569d8899132SKalle Valo 	value = value << HE_TXOP_SHIFT;
570d8899132SKalle Valo 	ppdu_info->he_data6 |= value;
571d8899132SKalle Valo 
572d8899132SKalle Valo 	ppdu_info->mcs =
573d8899132SKalle Valo 		u32_get_bits(info0, HAL_RX_HE_SIG_A_SU_INFO_INFO0_TRANSMIT_MCS);
574d8899132SKalle Valo 	ppdu_info->bw =
575d8899132SKalle Valo 		u32_get_bits(info0, HAL_RX_HE_SIG_A_SU_INFO_INFO0_TRANSMIT_BW);
576d8899132SKalle Valo 	ppdu_info->ldpc = u32_get_bits(info1, HAL_RX_HE_SIG_A_SU_INFO_INFO1_CODING);
577d8899132SKalle Valo 	ppdu_info->is_stbc = u32_get_bits(info1, HAL_RX_HE_SIG_A_SU_INFO_INFO1_STBC);
578d8899132SKalle Valo 	ppdu_info->beamformed = u32_get_bits(info1, HAL_RX_HE_SIG_A_SU_INFO_INFO1_TXBF);
579d8899132SKalle Valo 	dcm = u32_get_bits(info0, HAL_RX_HE_SIG_A_SU_INFO_INFO0_DCM);
580d8899132SKalle Valo 	ppdu_info->nss = u32_get_bits(info0, HAL_RX_HE_SIG_A_SU_INFO_INFO0_NSTS);
581d8899132SKalle Valo 	ppdu_info->dcm = dcm;
582d8899132SKalle Valo 	ppdu_info->reception_type = HAL_RX_RECEPTION_TYPE_SU;
583d8899132SKalle Valo }
584d8899132SKalle Valo 
585d8899132SKalle Valo static enum hal_rx_mon_status
ath12k_dp_mon_rx_parse_status_tlv(struct ath12k_base * ab,struct ath12k_mon_data * pmon,u32 tlv_tag,u8 * tlv_data,u32 userid)586d8899132SKalle Valo ath12k_dp_mon_rx_parse_status_tlv(struct ath12k_base *ab,
587d8899132SKalle Valo 				  struct ath12k_mon_data *pmon,
588d8899132SKalle Valo 				  u32 tlv_tag, u8 *tlv_data, u32 userid)
589d8899132SKalle Valo {
590d8899132SKalle Valo 	struct hal_rx_mon_ppdu_info *ppdu_info = &pmon->mon_ppdu_info;
59180166c42SThiraviyam Mariyappan 	u32 info[7];
592d8899132SKalle Valo 
593d8899132SKalle Valo 	switch (tlv_tag) {
594d8899132SKalle Valo 	case HAL_RX_PPDU_START: {
595d8899132SKalle Valo 		struct hal_rx_ppdu_start *ppdu_start =
596d8899132SKalle Valo 			(struct hal_rx_ppdu_start *)tlv_data;
597d8899132SKalle Valo 
598d8899132SKalle Valo 		info[0] = __le32_to_cpu(ppdu_start->info0);
599d8899132SKalle Valo 
600d8899132SKalle Valo 		ppdu_info->ppdu_id =
601d8899132SKalle Valo 			u32_get_bits(info[0], HAL_RX_PPDU_START_INFO0_PPDU_ID);
602d8899132SKalle Valo 		ppdu_info->chan_num = __le32_to_cpu(ppdu_start->chan_num);
603d8899132SKalle Valo 		ppdu_info->ppdu_ts = __le32_to_cpu(ppdu_start->ppdu_start_ts);
604d8899132SKalle Valo 
605d8899132SKalle Valo 		if (ppdu_info->ppdu_id != ppdu_info->last_ppdu_id) {
606d8899132SKalle Valo 			ppdu_info->last_ppdu_id = ppdu_info->ppdu_id;
607d8899132SKalle Valo 			ppdu_info->num_users = 0;
608d8899132SKalle Valo 			memset(&ppdu_info->mpdu_fcs_ok_bitmap, 0,
609d8899132SKalle Valo 			       HAL_RX_NUM_WORDS_PER_PPDU_BITMAP *
610d8899132SKalle Valo 			       sizeof(ppdu_info->mpdu_fcs_ok_bitmap[0]));
611d8899132SKalle Valo 		}
612d8899132SKalle Valo 		break;
613d8899132SKalle Valo 	}
614d8899132SKalle Valo 	case HAL_RX_PPDU_END_USER_STATS: {
615d8899132SKalle Valo 		struct hal_rx_ppdu_end_user_stats *eu_stats =
616d8899132SKalle Valo 			(struct hal_rx_ppdu_end_user_stats *)tlv_data;
617d8899132SKalle Valo 
618d8899132SKalle Valo 		info[0] = __le32_to_cpu(eu_stats->info0);
619d8899132SKalle Valo 		info[1] = __le32_to_cpu(eu_stats->info1);
620d8899132SKalle Valo 		info[2] = __le32_to_cpu(eu_stats->info2);
621d8899132SKalle Valo 		info[4] = __le32_to_cpu(eu_stats->info4);
622d8899132SKalle Valo 		info[5] = __le32_to_cpu(eu_stats->info5);
623d8899132SKalle Valo 		info[6] = __le32_to_cpu(eu_stats->info6);
624d8899132SKalle Valo 
625d8899132SKalle Valo 		ppdu_info->ast_index =
626d8899132SKalle Valo 			u32_get_bits(info[2], HAL_RX_PPDU_END_USER_STATS_INFO2_AST_INDEX);
627d8899132SKalle Valo 		ppdu_info->fc_valid =
628d8899132SKalle Valo 			u32_get_bits(info[1], HAL_RX_PPDU_END_USER_STATS_INFO1_FC_VALID);
629d8899132SKalle Valo 		ppdu_info->tid =
630d8899132SKalle Valo 			ffs(u32_get_bits(info[6],
631d8899132SKalle Valo 					 HAL_RX_PPDU_END_USER_STATS_INFO6_TID_BITMAP)
632d8899132SKalle Valo 					 - 1);
633d8899132SKalle Valo 		ppdu_info->tcp_msdu_count =
634d8899132SKalle Valo 			u32_get_bits(info[4],
635d8899132SKalle Valo 				     HAL_RX_PPDU_END_USER_STATS_INFO4_TCP_MSDU_CNT);
636d8899132SKalle Valo 		ppdu_info->udp_msdu_count =
637d8899132SKalle Valo 			u32_get_bits(info[4],
638d8899132SKalle Valo 				     HAL_RX_PPDU_END_USER_STATS_INFO4_UDP_MSDU_CNT);
639d8899132SKalle Valo 		ppdu_info->other_msdu_count =
640d8899132SKalle Valo 			u32_get_bits(info[5],
641d8899132SKalle Valo 				     HAL_RX_PPDU_END_USER_STATS_INFO5_OTHER_MSDU_CNT);
642d8899132SKalle Valo 		ppdu_info->tcp_ack_msdu_count =
643d8899132SKalle Valo 			u32_get_bits(info[5],
644d8899132SKalle Valo 				     HAL_RX_PPDU_END_USER_STATS_INFO5_TCP_ACK_MSDU_CNT);
645d8899132SKalle Valo 		ppdu_info->preamble_type =
646d8899132SKalle Valo 			u32_get_bits(info[1],
647d8899132SKalle Valo 				     HAL_RX_PPDU_END_USER_STATS_INFO1_PKT_TYPE);
648d8899132SKalle Valo 		ppdu_info->num_mpdu_fcs_ok =
649d8899132SKalle Valo 			u32_get_bits(info[1],
650d8899132SKalle Valo 				     HAL_RX_PPDU_END_USER_STATS_INFO1_MPDU_CNT_FCS_OK);
651d8899132SKalle Valo 		ppdu_info->num_mpdu_fcs_err =
652d8899132SKalle Valo 			u32_get_bits(info[0],
653d8899132SKalle Valo 				     HAL_RX_PPDU_END_USER_STATS_INFO0_MPDU_CNT_FCS_ERR);
654d8899132SKalle Valo 		switch (ppdu_info->preamble_type) {
655d8899132SKalle Valo 		case HAL_RX_PREAMBLE_11N:
656d8899132SKalle Valo 			ppdu_info->ht_flags = 1;
657d8899132SKalle Valo 			break;
658d8899132SKalle Valo 		case HAL_RX_PREAMBLE_11AC:
659d8899132SKalle Valo 			ppdu_info->vht_flags = 1;
660d8899132SKalle Valo 			break;
661d8899132SKalle Valo 		case HAL_RX_PREAMBLE_11AX:
662d8899132SKalle Valo 			ppdu_info->he_flags = 1;
663d8899132SKalle Valo 			break;
664d8899132SKalle Valo 		default:
665d8899132SKalle Valo 			break;
666d8899132SKalle Valo 		}
667d8899132SKalle Valo 
668d8899132SKalle Valo 		if (userid < HAL_MAX_UL_MU_USERS) {
669d8899132SKalle Valo 			struct hal_rx_user_status *rxuser_stats =
670d8899132SKalle Valo 				&ppdu_info->userstats[userid];
671d8899132SKalle Valo 			ppdu_info->num_users += 1;
672d8899132SKalle Valo 
673d8899132SKalle Valo 			ath12k_dp_mon_rx_handle_ofdma_info(tlv_data, rxuser_stats);
674d8899132SKalle Valo 			ath12k_dp_mon_rx_populate_mu_user_info(tlv_data, ppdu_info,
675d8899132SKalle Valo 							       rxuser_stats);
676d8899132SKalle Valo 		}
677d8899132SKalle Valo 		ppdu_info->mpdu_fcs_ok_bitmap[0] = __le32_to_cpu(eu_stats->rsvd1[0]);
678d8899132SKalle Valo 		ppdu_info->mpdu_fcs_ok_bitmap[1] = __le32_to_cpu(eu_stats->rsvd1[1]);
679d8899132SKalle Valo 		break;
680d8899132SKalle Valo 	}
681d8899132SKalle Valo 	case HAL_RX_PPDU_END_USER_STATS_EXT: {
682d8899132SKalle Valo 		struct hal_rx_ppdu_end_user_stats_ext *eu_stats =
683d8899132SKalle Valo 			(struct hal_rx_ppdu_end_user_stats_ext *)tlv_data;
684d8899132SKalle Valo 		ppdu_info->mpdu_fcs_ok_bitmap[2] = __le32_to_cpu(eu_stats->info1);
685d8899132SKalle Valo 		ppdu_info->mpdu_fcs_ok_bitmap[3] = __le32_to_cpu(eu_stats->info2);
686d8899132SKalle Valo 		ppdu_info->mpdu_fcs_ok_bitmap[4] = __le32_to_cpu(eu_stats->info3);
687d8899132SKalle Valo 		ppdu_info->mpdu_fcs_ok_bitmap[5] = __le32_to_cpu(eu_stats->info4);
688d8899132SKalle Valo 		ppdu_info->mpdu_fcs_ok_bitmap[6] = __le32_to_cpu(eu_stats->info5);
689d8899132SKalle Valo 		ppdu_info->mpdu_fcs_ok_bitmap[7] = __le32_to_cpu(eu_stats->info6);
690d8899132SKalle Valo 		break;
691d8899132SKalle Valo 	}
692d8899132SKalle Valo 	case HAL_PHYRX_HT_SIG:
693d8899132SKalle Valo 		ath12k_dp_mon_parse_ht_sig(tlv_data, ppdu_info);
694d8899132SKalle Valo 		break;
695d8899132SKalle Valo 
696d8899132SKalle Valo 	case HAL_PHYRX_L_SIG_B:
697d8899132SKalle Valo 		ath12k_dp_mon_parse_l_sig_b(tlv_data, ppdu_info);
698d8899132SKalle Valo 		break;
699d8899132SKalle Valo 
700d8899132SKalle Valo 	case HAL_PHYRX_L_SIG_A:
701d8899132SKalle Valo 		ath12k_dp_mon_parse_l_sig_a(tlv_data, ppdu_info);
702d8899132SKalle Valo 		break;
703d8899132SKalle Valo 
704d8899132SKalle Valo 	case HAL_PHYRX_VHT_SIG_A:
705d8899132SKalle Valo 		ath12k_dp_mon_parse_vht_sig_a(tlv_data, ppdu_info);
706d8899132SKalle Valo 		break;
707d8899132SKalle Valo 
708d8899132SKalle Valo 	case HAL_PHYRX_HE_SIG_A_SU:
709d8899132SKalle Valo 		ath12k_dp_mon_parse_he_sig_su(tlv_data, ppdu_info);
710d8899132SKalle Valo 		break;
711d8899132SKalle Valo 
712d8899132SKalle Valo 	case HAL_PHYRX_HE_SIG_A_MU_DL:
713d8899132SKalle Valo 		ath12k_dp_mon_parse_he_sig_mu(tlv_data, ppdu_info);
714d8899132SKalle Valo 		break;
715d8899132SKalle Valo 
716d8899132SKalle Valo 	case HAL_PHYRX_HE_SIG_B1_MU:
717d8899132SKalle Valo 		ath12k_dp_mon_parse_he_sig_b1_mu(tlv_data, ppdu_info);
718d8899132SKalle Valo 		break;
719d8899132SKalle Valo 
720d8899132SKalle Valo 	case HAL_PHYRX_HE_SIG_B2_MU:
721d8899132SKalle Valo 		ath12k_dp_mon_parse_he_sig_b2_mu(tlv_data, ppdu_info);
722d8899132SKalle Valo 		break;
723d8899132SKalle Valo 
724d8899132SKalle Valo 	case HAL_PHYRX_HE_SIG_B2_OFDMA:
725d8899132SKalle Valo 		ath12k_dp_mon_parse_he_sig_b2_ofdma(tlv_data, ppdu_info);
726d8899132SKalle Valo 		break;
727d8899132SKalle Valo 
728d8899132SKalle Valo 	case HAL_PHYRX_RSSI_LEGACY: {
729d8899132SKalle Valo 		struct hal_rx_phyrx_rssi_legacy_info *rssi =
730d8899132SKalle Valo 			(struct hal_rx_phyrx_rssi_legacy_info *)tlv_data;
731d8899132SKalle Valo 		u32 reception_type = 0;
732d8899132SKalle Valo 		u32 rssi_legacy_info = __le32_to_cpu(rssi->rsvd[0]);
733d8899132SKalle Valo 
734d8899132SKalle Valo 		info[0] = __le32_to_cpu(rssi->info0);
735d8899132SKalle Valo 
736d8899132SKalle Valo 		/* TODO: Please note that the combined rssi will not be accurate
737d8899132SKalle Valo 		 * in MU case. Rssi in MU needs to be retrieved from
738d8899132SKalle Valo 		 * PHYRX_OTHER_RECEIVE_INFO TLV.
739d8899132SKalle Valo 		 */
740d8899132SKalle Valo 		ppdu_info->rssi_comb =
741d8899132SKalle Valo 			u32_get_bits(info[0],
742d8899132SKalle Valo 				     HAL_RX_PHYRX_RSSI_LEGACY_INFO_INFO0_RSSI_COMB);
743d8899132SKalle Valo 		reception_type =
744d8899132SKalle Valo 			u32_get_bits(rssi_legacy_info,
745d8899132SKalle Valo 				     HAL_RX_PHYRX_RSSI_LEGACY_INFO_RSVD1_RECEPTION);
746d8899132SKalle Valo 
747d8899132SKalle Valo 		switch (reception_type) {
748d8899132SKalle Valo 		case HAL_RECEPTION_TYPE_ULOFMDA:
749d8899132SKalle Valo 			ppdu_info->reception_type = HAL_RX_RECEPTION_TYPE_MU_OFDMA;
750d8899132SKalle Valo 			break;
751d8899132SKalle Valo 		case HAL_RECEPTION_TYPE_ULMIMO:
752d8899132SKalle Valo 			ppdu_info->reception_type = HAL_RX_RECEPTION_TYPE_MU_MIMO;
753d8899132SKalle Valo 			break;
754d8899132SKalle Valo 		default:
755d8899132SKalle Valo 			ppdu_info->reception_type = HAL_RX_RECEPTION_TYPE_SU;
756d8899132SKalle Valo 			break;
757d8899132SKalle Valo 		}
758d8899132SKalle Valo 		break;
759d8899132SKalle Valo 	}
760d8899132SKalle Valo 	case HAL_RXPCU_PPDU_END_INFO: {
761d8899132SKalle Valo 		struct hal_rx_ppdu_end_duration *ppdu_rx_duration =
762d8899132SKalle Valo 			(struct hal_rx_ppdu_end_duration *)tlv_data;
763d8899132SKalle Valo 
764d8899132SKalle Valo 		info[0] = __le32_to_cpu(ppdu_rx_duration->info0);
765d8899132SKalle Valo 		ppdu_info->rx_duration =
766d8899132SKalle Valo 			u32_get_bits(info[0], HAL_RX_PPDU_END_DURATION);
767d8899132SKalle Valo 		ppdu_info->tsft = __le32_to_cpu(ppdu_rx_duration->rsvd0[1]);
768d8899132SKalle Valo 		ppdu_info->tsft = (ppdu_info->tsft << 32) |
769d8899132SKalle Valo 				   __le32_to_cpu(ppdu_rx_duration->rsvd0[0]);
770d8899132SKalle Valo 		break;
771d8899132SKalle Valo 	}
772d8899132SKalle Valo 	case HAL_RX_MPDU_START: {
773d8899132SKalle Valo 		struct hal_rx_mpdu_start *mpdu_start =
774d8899132SKalle Valo 			(struct hal_rx_mpdu_start *)tlv_data;
775d8899132SKalle Valo 		struct dp_mon_mpdu *mon_mpdu = pmon->mon_mpdu;
776d8899132SKalle Valo 		u16 peer_id;
777d8899132SKalle Valo 
778d8899132SKalle Valo 		info[1] = __le32_to_cpu(mpdu_start->info1);
779d8899132SKalle Valo 		peer_id = u32_get_bits(info[1], HAL_RX_MPDU_START_INFO1_PEERID);
780d8899132SKalle Valo 		if (peer_id)
781d8899132SKalle Valo 			ppdu_info->peer_id = peer_id;
782d8899132SKalle Valo 
783d8899132SKalle Valo 		ppdu_info->mpdu_len += u32_get_bits(info[1],
784d8899132SKalle Valo 						    HAL_RX_MPDU_START_INFO2_MPDU_LEN);
785d8899132SKalle Valo 		if (userid < HAL_MAX_UL_MU_USERS) {
786d8899132SKalle Valo 			info[0] = __le32_to_cpu(mpdu_start->info0);
787d8899132SKalle Valo 			ppdu_info->userid = userid;
788d8899132SKalle Valo 			ppdu_info->ampdu_id[userid] =
789d8899132SKalle Valo 				u32_get_bits(info[0], HAL_RX_MPDU_START_INFO1_PEERID);
790d8899132SKalle Valo 		}
791d8899132SKalle Valo 
792d8899132SKalle Valo 		mon_mpdu = kzalloc(sizeof(*mon_mpdu), GFP_ATOMIC);
793d8899132SKalle Valo 		if (!mon_mpdu)
794d8899132SKalle Valo 			return HAL_RX_MON_STATUS_PPDU_NOT_DONE;
795d8899132SKalle Valo 
796d8899132SKalle Valo 		break;
797d8899132SKalle Valo 	}
798d8899132SKalle Valo 	case HAL_RX_MSDU_START:
799d8899132SKalle Valo 		/* TODO: add msdu start parsing logic */
800d8899132SKalle Valo 		break;
801d8899132SKalle Valo 	case HAL_MON_BUF_ADDR: {
802d8899132SKalle Valo 		struct dp_rxdma_ring *buf_ring = &ab->dp.rxdma_mon_buf_ring;
803d8899132SKalle Valo 		struct dp_mon_packet_info *packet_info =
804d8899132SKalle Valo 			(struct dp_mon_packet_info *)tlv_data;
805d8899132SKalle Valo 		int buf_id = u32_get_bits(packet_info->cookie,
806d8899132SKalle Valo 					  DP_RXDMA_BUF_COOKIE_BUF_ID);
807d8899132SKalle Valo 		struct sk_buff *msdu;
808d8899132SKalle Valo 		struct dp_mon_mpdu *mon_mpdu = pmon->mon_mpdu;
809d8899132SKalle Valo 		struct ath12k_skb_rxcb *rxcb;
810d8899132SKalle Valo 
811d8899132SKalle Valo 		spin_lock_bh(&buf_ring->idr_lock);
812d8899132SKalle Valo 		msdu = idr_remove(&buf_ring->bufs_idr, buf_id);
813d8899132SKalle Valo 		spin_unlock_bh(&buf_ring->idr_lock);
814d8899132SKalle Valo 
815d8899132SKalle Valo 		if (unlikely(!msdu)) {
816480c9df5SColin Ian King 			ath12k_warn(ab, "monitor destination with invalid buf_id %d\n",
817d8899132SKalle Valo 				    buf_id);
818d8899132SKalle Valo 			return HAL_RX_MON_STATUS_PPDU_NOT_DONE;
819d8899132SKalle Valo 		}
820d8899132SKalle Valo 
821d8899132SKalle Valo 		rxcb = ATH12K_SKB_RXCB(msdu);
822d8899132SKalle Valo 		dma_unmap_single(ab->dev, rxcb->paddr,
823d8899132SKalle Valo 				 msdu->len + skb_tailroom(msdu),
824d8899132SKalle Valo 				 DMA_FROM_DEVICE);
825d8899132SKalle Valo 
826d8899132SKalle Valo 		if (mon_mpdu->tail)
827d8899132SKalle Valo 			mon_mpdu->tail->next = msdu;
828d8899132SKalle Valo 		else
829d8899132SKalle Valo 			mon_mpdu->tail = msdu;
830d8899132SKalle Valo 
831d8899132SKalle Valo 		ath12k_dp_mon_buf_replenish(ab, buf_ring, 1);
832d8899132SKalle Valo 
833d8899132SKalle Valo 		break;
834d8899132SKalle Valo 	}
835d8899132SKalle Valo 	case HAL_RX_MSDU_END: {
836d8899132SKalle Valo 		struct rx_msdu_end_qcn9274 *msdu_end =
837d8899132SKalle Valo 			(struct rx_msdu_end_qcn9274 *)tlv_data;
838d8899132SKalle Valo 		bool is_first_msdu_in_mpdu;
839d8899132SKalle Valo 		u16 msdu_end_info;
840d8899132SKalle Valo 
841d8899132SKalle Valo 		msdu_end_info = __le16_to_cpu(msdu_end->info5);
842d8899132SKalle Valo 		is_first_msdu_in_mpdu = u32_get_bits(msdu_end_info,
843d8899132SKalle Valo 						     RX_MSDU_END_INFO5_FIRST_MSDU);
844d8899132SKalle Valo 		if (is_first_msdu_in_mpdu) {
845d8899132SKalle Valo 			pmon->mon_mpdu->head = pmon->mon_mpdu->tail;
846d8899132SKalle Valo 			pmon->mon_mpdu->tail = NULL;
847d8899132SKalle Valo 		}
848d8899132SKalle Valo 		break;
849d8899132SKalle Valo 	}
850d8899132SKalle Valo 	case HAL_RX_MPDU_END:
851d8899132SKalle Valo 		list_add_tail(&pmon->mon_mpdu->list, &pmon->dp_rx_mon_mpdu_list);
852d8899132SKalle Valo 		break;
853d8899132SKalle Valo 	case HAL_DUMMY:
854d8899132SKalle Valo 		return HAL_RX_MON_STATUS_BUF_DONE;
855d8899132SKalle Valo 	case HAL_RX_PPDU_END_STATUS_DONE:
856d8899132SKalle Valo 	case 0:
857d8899132SKalle Valo 		return HAL_RX_MON_STATUS_PPDU_DONE;
858d8899132SKalle Valo 	default:
859d8899132SKalle Valo 		break;
860d8899132SKalle Valo 	}
861d8899132SKalle Valo 
862d8899132SKalle Valo 	return HAL_RX_MON_STATUS_PPDU_NOT_DONE;
863d8899132SKalle Valo }
864d8899132SKalle Valo 
ath12k_dp_mon_rx_msdus_set_payload(struct ath12k * ar,struct sk_buff * msdu)865d8899132SKalle Valo static void ath12k_dp_mon_rx_msdus_set_payload(struct ath12k *ar, struct sk_buff *msdu)
866d8899132SKalle Valo {
867d8899132SKalle Valo 	u32 rx_pkt_offset, l2_hdr_offset;
868d8899132SKalle Valo 
869d8899132SKalle Valo 	rx_pkt_offset = ar->ab->hw_params->hal_desc_sz;
870d8899132SKalle Valo 	l2_hdr_offset = ath12k_dp_rx_h_l3pad(ar->ab,
871d8899132SKalle Valo 					     (struct hal_rx_desc *)msdu->data);
872d8899132SKalle Valo 	skb_pull(msdu, rx_pkt_offset + l2_hdr_offset);
873d8899132SKalle Valo }
874d8899132SKalle Valo 
875d8899132SKalle Valo static struct sk_buff *
ath12k_dp_mon_rx_merg_msdus(struct ath12k * ar,u32 mac_id,struct sk_buff * head_msdu,struct ieee80211_rx_status * rxs,bool * fcs_err)876d8899132SKalle Valo ath12k_dp_mon_rx_merg_msdus(struct ath12k *ar,
877d8899132SKalle Valo 			    u32 mac_id, struct sk_buff *head_msdu,
878d8899132SKalle Valo 			    struct ieee80211_rx_status *rxs, bool *fcs_err)
879d8899132SKalle Valo {
880d8899132SKalle Valo 	struct ath12k_base *ab = ar->ab;
881d8899132SKalle Valo 	struct sk_buff *msdu, *mpdu_buf, *prev_buf;
882d8899132SKalle Valo 	struct hal_rx_desc *rx_desc;
883d8899132SKalle Valo 	u8 *hdr_desc, *dest, decap_format;
884d8899132SKalle Valo 	struct ieee80211_hdr_3addr *wh;
885d8899132SKalle Valo 	u32 err_bitmap;
886d8899132SKalle Valo 
887d8899132SKalle Valo 	mpdu_buf = NULL;
888d8899132SKalle Valo 
889d8899132SKalle Valo 	if (!head_msdu)
890d8899132SKalle Valo 		goto err_merge_fail;
891d8899132SKalle Valo 
892d8899132SKalle Valo 	rx_desc = (struct hal_rx_desc *)head_msdu->data;
893d8899132SKalle Valo 	err_bitmap = ath12k_dp_rx_h_mpdu_err(ab, rx_desc);
894d8899132SKalle Valo 
895d8899132SKalle Valo 	if (err_bitmap & HAL_RX_MPDU_ERR_FCS)
896d8899132SKalle Valo 		*fcs_err = true;
897d8899132SKalle Valo 
898d8899132SKalle Valo 	decap_format = ath12k_dp_rx_h_decap_type(ab, rx_desc);
899d8899132SKalle Valo 
900d8899132SKalle Valo 	ath12k_dp_rx_h_ppdu(ar, rx_desc, rxs);
901d8899132SKalle Valo 
902d8899132SKalle Valo 	if (decap_format == DP_RX_DECAP_TYPE_RAW) {
903d8899132SKalle Valo 		ath12k_dp_mon_rx_msdus_set_payload(ar, head_msdu);
904d8899132SKalle Valo 
905d8899132SKalle Valo 		prev_buf = head_msdu;
906d8899132SKalle Valo 		msdu = head_msdu->next;
907d8899132SKalle Valo 
908d8899132SKalle Valo 		while (msdu) {
909d8899132SKalle Valo 			ath12k_dp_mon_rx_msdus_set_payload(ar, msdu);
910d8899132SKalle Valo 
911d8899132SKalle Valo 			prev_buf = msdu;
912d8899132SKalle Valo 			msdu = msdu->next;
913d8899132SKalle Valo 		}
914d8899132SKalle Valo 
915d8899132SKalle Valo 		prev_buf->next = NULL;
916d8899132SKalle Valo 
917d8899132SKalle Valo 		skb_trim(prev_buf, prev_buf->len - HAL_RX_FCS_LEN);
918d8899132SKalle Valo 	} else if (decap_format == DP_RX_DECAP_TYPE_NATIVE_WIFI) {
919d8899132SKalle Valo 		u8 qos_pkt = 0;
920d8899132SKalle Valo 
921d8899132SKalle Valo 		rx_desc = (struct hal_rx_desc *)head_msdu->data;
922d8899132SKalle Valo 		hdr_desc = ab->hw_params->hal_ops->rx_desc_get_msdu_payload(rx_desc);
923d8899132SKalle Valo 
924d8899132SKalle Valo 		/* Base size */
925d8899132SKalle Valo 		wh = (struct ieee80211_hdr_3addr *)hdr_desc;
926d8899132SKalle Valo 
927d8899132SKalle Valo 		if (ieee80211_is_data_qos(wh->frame_control))
928d8899132SKalle Valo 			qos_pkt = 1;
929d8899132SKalle Valo 
930d8899132SKalle Valo 		msdu = head_msdu;
931d8899132SKalle Valo 
932d8899132SKalle Valo 		while (msdu) {
933d8899132SKalle Valo 			ath12k_dp_mon_rx_msdus_set_payload(ar, msdu);
934d8899132SKalle Valo 			if (qos_pkt) {
935d8899132SKalle Valo 				dest = skb_push(msdu, sizeof(__le16));
936d8899132SKalle Valo 				if (!dest)
937d8899132SKalle Valo 					goto err_merge_fail;
938d8899132SKalle Valo 				memcpy(dest, hdr_desc, sizeof(struct ieee80211_qos_hdr));
939d8899132SKalle Valo 			}
940d8899132SKalle Valo 			prev_buf = msdu;
941d8899132SKalle Valo 			msdu = msdu->next;
942d8899132SKalle Valo 		}
943d8899132SKalle Valo 		dest = skb_put(prev_buf, HAL_RX_FCS_LEN);
944d8899132SKalle Valo 		if (!dest)
945d8899132SKalle Valo 			goto err_merge_fail;
946d8899132SKalle Valo 
947d8899132SKalle Valo 		ath12k_dbg(ab, ATH12K_DBG_DATA,
948d8899132SKalle Valo 			   "mpdu_buf %pK mpdu_buf->len %u",
949d8899132SKalle Valo 			   prev_buf, prev_buf->len);
950d8899132SKalle Valo 	} else {
951d8899132SKalle Valo 		ath12k_dbg(ab, ATH12K_DBG_DATA,
952d8899132SKalle Valo 			   "decap format %d is not supported!\n",
953d8899132SKalle Valo 			   decap_format);
954d8899132SKalle Valo 		goto err_merge_fail;
955d8899132SKalle Valo 	}
956d8899132SKalle Valo 
957d8899132SKalle Valo 	return head_msdu;
958d8899132SKalle Valo 
959d8899132SKalle Valo err_merge_fail:
960d8899132SKalle Valo 	if (mpdu_buf && decap_format != DP_RX_DECAP_TYPE_RAW) {
961d8899132SKalle Valo 		ath12k_dbg(ab, ATH12K_DBG_DATA,
962d8899132SKalle Valo 			   "err_merge_fail mpdu_buf %pK", mpdu_buf);
963d8899132SKalle Valo 		/* Free the head buffer */
964d8899132SKalle Valo 		dev_kfree_skb_any(mpdu_buf);
965d8899132SKalle Valo 	}
966d8899132SKalle Valo 	return NULL;
967d8899132SKalle Valo }
968d8899132SKalle Valo 
969d8899132SKalle Valo static void
ath12k_dp_mon_rx_update_radiotap_he(struct hal_rx_mon_ppdu_info * rx_status,u8 * rtap_buf)970d8899132SKalle Valo ath12k_dp_mon_rx_update_radiotap_he(struct hal_rx_mon_ppdu_info *rx_status,
971d8899132SKalle Valo 				    u8 *rtap_buf)
972d8899132SKalle Valo {
973d8899132SKalle Valo 	u32 rtap_len = 0;
974d8899132SKalle Valo 
975d8899132SKalle Valo 	put_unaligned_le16(rx_status->he_data1, &rtap_buf[rtap_len]);
976d8899132SKalle Valo 	rtap_len += 2;
977d8899132SKalle Valo 
978d8899132SKalle Valo 	put_unaligned_le16(rx_status->he_data2, &rtap_buf[rtap_len]);
979d8899132SKalle Valo 	rtap_len += 2;
980d8899132SKalle Valo 
981d8899132SKalle Valo 	put_unaligned_le16(rx_status->he_data3, &rtap_buf[rtap_len]);
982d8899132SKalle Valo 	rtap_len += 2;
983d8899132SKalle Valo 
984d8899132SKalle Valo 	put_unaligned_le16(rx_status->he_data4, &rtap_buf[rtap_len]);
985d8899132SKalle Valo 	rtap_len += 2;
986d8899132SKalle Valo 
987d8899132SKalle Valo 	put_unaligned_le16(rx_status->he_data5, &rtap_buf[rtap_len]);
988d8899132SKalle Valo 	rtap_len += 2;
989d8899132SKalle Valo 
990d8899132SKalle Valo 	put_unaligned_le16(rx_status->he_data6, &rtap_buf[rtap_len]);
991d8899132SKalle Valo }
992d8899132SKalle Valo 
993d8899132SKalle Valo static void
ath12k_dp_mon_rx_update_radiotap_he_mu(struct hal_rx_mon_ppdu_info * rx_status,u8 * rtap_buf)994d8899132SKalle Valo ath12k_dp_mon_rx_update_radiotap_he_mu(struct hal_rx_mon_ppdu_info *rx_status,
995d8899132SKalle Valo 				       u8 *rtap_buf)
996d8899132SKalle Valo {
997d8899132SKalle Valo 	u32 rtap_len = 0;
998d8899132SKalle Valo 
999d8899132SKalle Valo 	put_unaligned_le16(rx_status->he_flags1, &rtap_buf[rtap_len]);
1000d8899132SKalle Valo 	rtap_len += 2;
1001d8899132SKalle Valo 
1002d8899132SKalle Valo 	put_unaligned_le16(rx_status->he_flags2, &rtap_buf[rtap_len]);
1003d8899132SKalle Valo 	rtap_len += 2;
1004d8899132SKalle Valo 
1005d8899132SKalle Valo 	rtap_buf[rtap_len] = rx_status->he_RU[0];
1006d8899132SKalle Valo 	rtap_len += 1;
1007d8899132SKalle Valo 
1008d8899132SKalle Valo 	rtap_buf[rtap_len] = rx_status->he_RU[1];
1009d8899132SKalle Valo 	rtap_len += 1;
1010d8899132SKalle Valo 
1011d8899132SKalle Valo 	rtap_buf[rtap_len] = rx_status->he_RU[2];
1012d8899132SKalle Valo 	rtap_len += 1;
1013d8899132SKalle Valo 
1014d8899132SKalle Valo 	rtap_buf[rtap_len] = rx_status->he_RU[3];
1015d8899132SKalle Valo }
1016d8899132SKalle Valo 
ath12k_dp_mon_update_radiotap(struct ath12k * ar,struct hal_rx_mon_ppdu_info * ppduinfo,struct sk_buff * mon_skb,struct ieee80211_rx_status * rxs)1017d8899132SKalle Valo static void ath12k_dp_mon_update_radiotap(struct ath12k *ar,
1018d8899132SKalle Valo 					  struct hal_rx_mon_ppdu_info *ppduinfo,
1019d8899132SKalle Valo 					  struct sk_buff *mon_skb,
1020d8899132SKalle Valo 					  struct ieee80211_rx_status *rxs)
1021d8899132SKalle Valo {
1022d8899132SKalle Valo 	struct ieee80211_supported_band *sband;
1023d8899132SKalle Valo 	u8 *ptr = NULL;
1024d8899132SKalle Valo 	u16 ampdu_id = ppduinfo->ampdu_id[ppduinfo->userid];
1025d8899132SKalle Valo 
1026d8899132SKalle Valo 	rxs->flag |= RX_FLAG_MACTIME_START;
1027d8899132SKalle Valo 	rxs->signal = ppduinfo->rssi_comb + ATH12K_DEFAULT_NOISE_FLOOR;
1028d8899132SKalle Valo 	rxs->nss = ppduinfo->nss + 1;
1029d8899132SKalle Valo 
1030d8899132SKalle Valo 	if (ampdu_id) {
1031d8899132SKalle Valo 		rxs->flag |= RX_FLAG_AMPDU_DETAILS;
1032d8899132SKalle Valo 		rxs->ampdu_reference = ampdu_id;
1033d8899132SKalle Valo 	}
1034d8899132SKalle Valo 
1035d8899132SKalle Valo 	if (ppduinfo->he_mu_flags) {
1036d8899132SKalle Valo 		rxs->flag |= RX_FLAG_RADIOTAP_HE_MU;
1037d8899132SKalle Valo 		rxs->encoding = RX_ENC_HE;
1038d8899132SKalle Valo 		ptr = skb_push(mon_skb, sizeof(struct ieee80211_radiotap_he_mu));
1039d8899132SKalle Valo 		ath12k_dp_mon_rx_update_radiotap_he_mu(ppduinfo, ptr);
1040d8899132SKalle Valo 	} else if (ppduinfo->he_flags) {
1041d8899132SKalle Valo 		rxs->flag |= RX_FLAG_RADIOTAP_HE;
1042d8899132SKalle Valo 		rxs->encoding = RX_ENC_HE;
1043d8899132SKalle Valo 		ptr = skb_push(mon_skb, sizeof(struct ieee80211_radiotap_he));
1044d8899132SKalle Valo 		ath12k_dp_mon_rx_update_radiotap_he(ppduinfo, ptr);
1045d8899132SKalle Valo 		rxs->rate_idx = ppduinfo->rate;
1046d8899132SKalle Valo 	} else if (ppduinfo->vht_flags) {
1047d8899132SKalle Valo 		rxs->encoding = RX_ENC_VHT;
1048d8899132SKalle Valo 		rxs->rate_idx = ppduinfo->rate;
1049d8899132SKalle Valo 	} else if (ppduinfo->ht_flags) {
1050d8899132SKalle Valo 		rxs->encoding = RX_ENC_HT;
1051d8899132SKalle Valo 		rxs->rate_idx = ppduinfo->rate;
1052d8899132SKalle Valo 	} else {
1053d8899132SKalle Valo 		rxs->encoding = RX_ENC_LEGACY;
1054d8899132SKalle Valo 		sband = &ar->mac.sbands[rxs->band];
1055d8899132SKalle Valo 		rxs->rate_idx = ath12k_mac_hw_rate_to_idx(sband, ppduinfo->rate,
1056d8899132SKalle Valo 							  ppduinfo->cck_flag);
1057d8899132SKalle Valo 	}
1058d8899132SKalle Valo 
1059d8899132SKalle Valo 	rxs->mactime = ppduinfo->tsft;
1060d8899132SKalle Valo }
1061d8899132SKalle Valo 
ath12k_dp_mon_rx_deliver_msdu(struct ath12k * ar,struct napi_struct * napi,struct sk_buff * msdu,struct ieee80211_rx_status * status)1062d8899132SKalle Valo static void ath12k_dp_mon_rx_deliver_msdu(struct ath12k *ar, struct napi_struct *napi,
1063d8899132SKalle Valo 					  struct sk_buff *msdu,
1064d8899132SKalle Valo 					  struct ieee80211_rx_status *status)
1065d8899132SKalle Valo {
1066d8899132SKalle Valo 	static const struct ieee80211_radiotap_he known = {
1067d8899132SKalle Valo 		.data1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_DATA_MCS_KNOWN |
1068d8899132SKalle Valo 				     IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN),
1069d8899132SKalle Valo 		.data2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_GI_KNOWN),
1070d8899132SKalle Valo 	};
1071d8899132SKalle Valo 	struct ieee80211_rx_status *rx_status;
1072d8899132SKalle Valo 	struct ieee80211_radiotap_he *he = NULL;
1073d8899132SKalle Valo 	struct ieee80211_sta *pubsta = NULL;
1074d8899132SKalle Valo 	struct ath12k_peer *peer;
1075d8899132SKalle Valo 	struct ath12k_skb_rxcb *rxcb = ATH12K_SKB_RXCB(msdu);
1076d8899132SKalle Valo 	u8 decap = DP_RX_DECAP_TYPE_RAW;
1077d8899132SKalle Valo 	bool is_mcbc = rxcb->is_mcbc;
1078d8899132SKalle Valo 	bool is_eapol_tkip = rxcb->is_eapol;
1079d8899132SKalle Valo 
1080d8899132SKalle Valo 	if ((status->encoding == RX_ENC_HE) && !(status->flag & RX_FLAG_RADIOTAP_HE) &&
1081d8899132SKalle Valo 	    !(status->flag & RX_FLAG_SKIP_MONITOR)) {
1082d8899132SKalle Valo 		he = skb_push(msdu, sizeof(known));
1083d8899132SKalle Valo 		memcpy(he, &known, sizeof(known));
1084d8899132SKalle Valo 		status->flag |= RX_FLAG_RADIOTAP_HE;
1085d8899132SKalle Valo 	}
1086d8899132SKalle Valo 
1087d8899132SKalle Valo 	if (!(status->flag & RX_FLAG_ONLY_MONITOR))
1088d8899132SKalle Valo 		decap = ath12k_dp_rx_h_decap_type(ar->ab, rxcb->rx_desc);
1089d8899132SKalle Valo 	spin_lock_bh(&ar->ab->base_lock);
1090d8899132SKalle Valo 	peer = ath12k_dp_rx_h_find_peer(ar->ab, msdu);
1091d8899132SKalle Valo 	if (peer && peer->sta)
1092d8899132SKalle Valo 		pubsta = peer->sta;
1093d8899132SKalle Valo 	spin_unlock_bh(&ar->ab->base_lock);
1094d8899132SKalle Valo 
1095d8899132SKalle Valo 	ath12k_dbg(ar->ab, ATH12K_DBG_DATA,
1096d8899132SKalle Valo 		   "rx skb %pK len %u peer %pM %u %s %s%s%s%s%s%s%s %srate_idx %u vht_nss %u freq %u band %u flag 0x%x fcs-err %i mic-err %i amsdu-more %i\n",
1097d8899132SKalle Valo 		   msdu,
1098d8899132SKalle Valo 		   msdu->len,
1099d8899132SKalle Valo 		   peer ? peer->addr : NULL,
1100d8899132SKalle Valo 		   rxcb->tid,
1101d8899132SKalle Valo 		   (is_mcbc) ? "mcast" : "ucast",
1102d8899132SKalle Valo 		   (status->encoding == RX_ENC_LEGACY) ? "legacy" : "",
1103d8899132SKalle Valo 		   (status->encoding == RX_ENC_HT) ? "ht" : "",
1104d8899132SKalle Valo 		   (status->encoding == RX_ENC_VHT) ? "vht" : "",
1105d8899132SKalle Valo 		   (status->encoding == RX_ENC_HE) ? "he" : "",
1106d8899132SKalle Valo 		   (status->bw == RATE_INFO_BW_40) ? "40" : "",
1107d8899132SKalle Valo 		   (status->bw == RATE_INFO_BW_80) ? "80" : "",
1108d8899132SKalle Valo 		   (status->bw == RATE_INFO_BW_160) ? "160" : "",
1109d8899132SKalle Valo 		   status->enc_flags & RX_ENC_FLAG_SHORT_GI ? "sgi " : "",
1110d8899132SKalle Valo 		   status->rate_idx,
1111d8899132SKalle Valo 		   status->nss,
1112d8899132SKalle Valo 		   status->freq,
1113d8899132SKalle Valo 		   status->band, status->flag,
1114d8899132SKalle Valo 		   !!(status->flag & RX_FLAG_FAILED_FCS_CRC),
1115d8899132SKalle Valo 		   !!(status->flag & RX_FLAG_MMIC_ERROR),
1116d8899132SKalle Valo 		   !!(status->flag & RX_FLAG_AMSDU_MORE));
1117d8899132SKalle Valo 
1118d8899132SKalle Valo 	ath12k_dbg_dump(ar->ab, ATH12K_DBG_DP_RX, NULL, "dp rx msdu: ",
1119d8899132SKalle Valo 			msdu->data, msdu->len);
1120d8899132SKalle Valo 	rx_status = IEEE80211_SKB_RXCB(msdu);
1121d8899132SKalle Valo 	*rx_status = *status;
1122d8899132SKalle Valo 
1123d8899132SKalle Valo 	/* TODO: trace rx packet */
1124d8899132SKalle Valo 
1125d8899132SKalle Valo 	/* PN for multicast packets are not validate in HW,
1126d8899132SKalle Valo 	 * so skip 802.3 rx path
1127480c9df5SColin Ian King 	 * Also, fast_rx expects the STA to be authorized, hence
1128d8899132SKalle Valo 	 * eapol packets are sent in slow path.
1129d8899132SKalle Valo 	 */
1130d8899132SKalle Valo 	if (decap == DP_RX_DECAP_TYPE_ETHERNET2_DIX && !is_eapol_tkip &&
1131d8899132SKalle Valo 	    !(is_mcbc && rx_status->flag & RX_FLAG_DECRYPTED))
1132d8899132SKalle Valo 		rx_status->flag |= RX_FLAG_8023;
1133d8899132SKalle Valo 
1134d8899132SKalle Valo 	ieee80211_rx_napi(ar->hw, pubsta, msdu, napi);
1135d8899132SKalle Valo }
1136d8899132SKalle Valo 
ath12k_dp_mon_rx_deliver(struct ath12k * ar,u32 mac_id,struct sk_buff * head_msdu,struct hal_rx_mon_ppdu_info * ppduinfo,struct napi_struct * napi)1137d8899132SKalle Valo static int ath12k_dp_mon_rx_deliver(struct ath12k *ar, u32 mac_id,
1138d8899132SKalle Valo 				    struct sk_buff *head_msdu,
1139d8899132SKalle Valo 				    struct hal_rx_mon_ppdu_info *ppduinfo,
1140d8899132SKalle Valo 				    struct napi_struct *napi)
1141d8899132SKalle Valo {
1142d8899132SKalle Valo 	struct ath12k_pdev_dp *dp = &ar->dp;
1143d8899132SKalle Valo 	struct sk_buff *mon_skb, *skb_next, *header;
1144d8899132SKalle Valo 	struct ieee80211_rx_status *rxs = &dp->rx_status;
1145d8899132SKalle Valo 	bool fcs_err = false;
1146d8899132SKalle Valo 
1147d8899132SKalle Valo 	mon_skb = ath12k_dp_mon_rx_merg_msdus(ar, mac_id, head_msdu,
1148d8899132SKalle Valo 					      rxs, &fcs_err);
1149d8899132SKalle Valo 	if (!mon_skb)
1150d8899132SKalle Valo 		goto mon_deliver_fail;
1151d8899132SKalle Valo 
1152d8899132SKalle Valo 	header = mon_skb;
1153d8899132SKalle Valo 	rxs->flag = 0;
1154d8899132SKalle Valo 
1155d8899132SKalle Valo 	if (fcs_err)
1156d8899132SKalle Valo 		rxs->flag = RX_FLAG_FAILED_FCS_CRC;
1157d8899132SKalle Valo 
1158d8899132SKalle Valo 	do {
1159d8899132SKalle Valo 		skb_next = mon_skb->next;
1160d8899132SKalle Valo 		if (!skb_next)
1161d8899132SKalle Valo 			rxs->flag &= ~RX_FLAG_AMSDU_MORE;
1162d8899132SKalle Valo 		else
1163d8899132SKalle Valo 			rxs->flag |= RX_FLAG_AMSDU_MORE;
1164d8899132SKalle Valo 
1165d8899132SKalle Valo 		if (mon_skb == header) {
1166d8899132SKalle Valo 			header = NULL;
1167d8899132SKalle Valo 			rxs->flag &= ~RX_FLAG_ALLOW_SAME_PN;
1168d8899132SKalle Valo 		} else {
1169d8899132SKalle Valo 			rxs->flag |= RX_FLAG_ALLOW_SAME_PN;
1170d8899132SKalle Valo 		}
1171d8899132SKalle Valo 		rxs->flag |= RX_FLAG_ONLY_MONITOR;
1172d8899132SKalle Valo 		ath12k_dp_mon_update_radiotap(ar, ppduinfo, mon_skb, rxs);
1173d8899132SKalle Valo 		ath12k_dp_mon_rx_deliver_msdu(ar, napi, mon_skb, rxs);
1174d8899132SKalle Valo 		mon_skb = skb_next;
1175d8899132SKalle Valo 	} while (mon_skb);
1176d8899132SKalle Valo 	rxs->flag = 0;
1177d8899132SKalle Valo 
1178d8899132SKalle Valo 	return 0;
1179d8899132SKalle Valo 
1180d8899132SKalle Valo mon_deliver_fail:
1181d8899132SKalle Valo 	mon_skb = head_msdu;
1182d8899132SKalle Valo 	while (mon_skb) {
1183d8899132SKalle Valo 		skb_next = mon_skb->next;
1184d8899132SKalle Valo 		dev_kfree_skb_any(mon_skb);
1185d8899132SKalle Valo 		mon_skb = skb_next;
1186d8899132SKalle Valo 	}
1187d8899132SKalle Valo 	return -EINVAL;
1188d8899132SKalle Valo }
1189d8899132SKalle Valo 
1190d8899132SKalle Valo static enum hal_rx_mon_status
ath12k_dp_mon_parse_rx_dest(struct ath12k_base * ab,struct ath12k_mon_data * pmon,struct sk_buff * skb)1191d8899132SKalle Valo ath12k_dp_mon_parse_rx_dest(struct ath12k_base *ab, struct ath12k_mon_data *pmon,
1192d8899132SKalle Valo 			    struct sk_buff *skb)
1193d8899132SKalle Valo {
1194d8899132SKalle Valo 	struct hal_rx_mon_ppdu_info *ppdu_info = &pmon->mon_ppdu_info;
1195d8899132SKalle Valo 	struct hal_tlv_hdr *tlv;
1196d8899132SKalle Valo 	enum hal_rx_mon_status hal_status;
1197d8899132SKalle Valo 	u32 tlv_userid = 0;
1198d8899132SKalle Valo 	u16 tlv_tag, tlv_len;
1199d8899132SKalle Valo 	u8 *ptr = skb->data;
1200d8899132SKalle Valo 
1201d8899132SKalle Valo 	memset(ppdu_info, 0, sizeof(struct hal_rx_mon_ppdu_info));
1202d8899132SKalle Valo 
1203d8899132SKalle Valo 	do {
1204d8899132SKalle Valo 		tlv = (struct hal_tlv_hdr *)ptr;
1205d8899132SKalle Valo 		tlv_tag = le32_get_bits(tlv->tl, HAL_TLV_HDR_TAG);
1206d8899132SKalle Valo 		tlv_len = le32_get_bits(tlv->tl, HAL_TLV_HDR_LEN);
1207d8899132SKalle Valo 		tlv_userid = le32_get_bits(tlv->tl, HAL_TLV_USR_ID);
1208d8899132SKalle Valo 		ptr += sizeof(*tlv);
1209d8899132SKalle Valo 
1210d8899132SKalle Valo 		/* The actual length of PPDU_END is the combined length of many PHY
1211d8899132SKalle Valo 		 * TLVs that follow. Skip the TLV header and
1212d8899132SKalle Valo 		 * rx_rxpcu_classification_overview that follows the header to get to
1213d8899132SKalle Valo 		 * next TLV.
1214d8899132SKalle Valo 		 */
1215d8899132SKalle Valo 
1216d8899132SKalle Valo 		if (tlv_tag == HAL_RX_PPDU_END)
1217d8899132SKalle Valo 			tlv_len = sizeof(struct hal_rx_rxpcu_classification_overview);
1218d8899132SKalle Valo 
1219d8899132SKalle Valo 		hal_status = ath12k_dp_mon_rx_parse_status_tlv(ab, pmon,
1220d8899132SKalle Valo 							       tlv_tag, ptr, tlv_userid);
1221d8899132SKalle Valo 		ptr += tlv_len;
1222d8899132SKalle Valo 		ptr = PTR_ALIGN(ptr, HAL_TLV_ALIGN);
1223d8899132SKalle Valo 
1224d8899132SKalle Valo 		if ((ptr - skb->data) >= DP_RX_BUFFER_SIZE)
1225d8899132SKalle Valo 			break;
1226d8899132SKalle Valo 
1227d8899132SKalle Valo 	} while (hal_status == HAL_RX_MON_STATUS_PPDU_NOT_DONE);
1228d8899132SKalle Valo 
1229d8899132SKalle Valo 	return hal_status;
1230d8899132SKalle Valo }
1231d8899132SKalle Valo 
1232d8899132SKalle Valo enum hal_rx_mon_status
ath12k_dp_mon_rx_parse_mon_status(struct ath12k * ar,struct ath12k_mon_data * pmon,int mac_id,struct sk_buff * skb,struct napi_struct * napi)1233d8899132SKalle Valo ath12k_dp_mon_rx_parse_mon_status(struct ath12k *ar,
1234d8899132SKalle Valo 				  struct ath12k_mon_data *pmon,
1235d8899132SKalle Valo 				  int mac_id,
1236d8899132SKalle Valo 				  struct sk_buff *skb,
1237d8899132SKalle Valo 				  struct napi_struct *napi)
1238d8899132SKalle Valo {
1239d8899132SKalle Valo 	struct ath12k_base *ab = ar->ab;
1240d8899132SKalle Valo 	struct hal_rx_mon_ppdu_info *ppdu_info = &pmon->mon_ppdu_info;
1241d8899132SKalle Valo 	struct dp_mon_mpdu *tmp;
1242d8899132SKalle Valo 	struct dp_mon_mpdu *mon_mpdu = pmon->mon_mpdu;
1243d8899132SKalle Valo 	struct sk_buff *head_msdu, *tail_msdu;
1244d8899132SKalle Valo 	enum hal_rx_mon_status hal_status = HAL_RX_MON_STATUS_BUF_DONE;
1245d8899132SKalle Valo 
1246d8899132SKalle Valo 	ath12k_dp_mon_parse_rx_dest(ab, pmon, skb);
1247d8899132SKalle Valo 
1248d8899132SKalle Valo 	list_for_each_entry_safe(mon_mpdu, tmp, &pmon->dp_rx_mon_mpdu_list, list) {
1249d8899132SKalle Valo 		list_del(&mon_mpdu->list);
1250d8899132SKalle Valo 		head_msdu = mon_mpdu->head;
1251d8899132SKalle Valo 		tail_msdu = mon_mpdu->tail;
1252d8899132SKalle Valo 
1253d8899132SKalle Valo 		if (head_msdu && tail_msdu) {
1254d8899132SKalle Valo 			ath12k_dp_mon_rx_deliver(ar, mac_id, head_msdu,
1255d8899132SKalle Valo 						 ppdu_info, napi);
1256d8899132SKalle Valo 		}
1257d8899132SKalle Valo 
1258d8899132SKalle Valo 		kfree(mon_mpdu);
1259d8899132SKalle Valo 	}
1260d8899132SKalle Valo 	return hal_status;
1261d8899132SKalle Valo }
1262d8899132SKalle Valo 
ath12k_dp_mon_buf_replenish(struct ath12k_base * ab,struct dp_rxdma_ring * buf_ring,int req_entries)1263d8899132SKalle Valo int ath12k_dp_mon_buf_replenish(struct ath12k_base *ab,
1264d8899132SKalle Valo 				struct dp_rxdma_ring *buf_ring,
1265d8899132SKalle Valo 				int req_entries)
1266d8899132SKalle Valo {
1267d8899132SKalle Valo 	struct hal_mon_buf_ring *mon_buf;
1268d8899132SKalle Valo 	struct sk_buff *skb;
1269d8899132SKalle Valo 	struct hal_srng *srng;
1270d8899132SKalle Valo 	dma_addr_t paddr;
1271*731e1b36SYang Li 	u32 cookie;
1272*731e1b36SYang Li 	int buf_id;
1273d8899132SKalle Valo 
1274d8899132SKalle Valo 	srng = &ab->hal.srng_list[buf_ring->refill_buf_ring.ring_id];
1275d8899132SKalle Valo 	spin_lock_bh(&srng->lock);
1276d8899132SKalle Valo 	ath12k_hal_srng_access_begin(ab, srng);
1277d8899132SKalle Valo 
1278d8899132SKalle Valo 	while (req_entries > 0) {
1279d8899132SKalle Valo 		skb = dev_alloc_skb(DP_RX_BUFFER_SIZE + DP_RX_BUFFER_ALIGN_SIZE);
1280d8899132SKalle Valo 		if (unlikely(!skb))
1281d8899132SKalle Valo 			goto fail_alloc_skb;
1282d8899132SKalle Valo 
1283d8899132SKalle Valo 		if (!IS_ALIGNED((unsigned long)skb->data, DP_RX_BUFFER_ALIGN_SIZE)) {
1284d8899132SKalle Valo 			skb_pull(skb,
1285d8899132SKalle Valo 				 PTR_ALIGN(skb->data, DP_RX_BUFFER_ALIGN_SIZE) -
1286d8899132SKalle Valo 				 skb->data);
1287d8899132SKalle Valo 		}
1288d8899132SKalle Valo 
1289d8899132SKalle Valo 		paddr = dma_map_single(ab->dev, skb->data,
1290d8899132SKalle Valo 				       skb->len + skb_tailroom(skb),
1291d8899132SKalle Valo 				       DMA_FROM_DEVICE);
1292d8899132SKalle Valo 
1293d8899132SKalle Valo 		if (unlikely(dma_mapping_error(ab->dev, paddr)))
1294d8899132SKalle Valo 			goto fail_free_skb;
1295d8899132SKalle Valo 
1296d8899132SKalle Valo 		spin_lock_bh(&buf_ring->idr_lock);
1297d8899132SKalle Valo 		buf_id = idr_alloc(&buf_ring->bufs_idr, skb, 0,
1298d8899132SKalle Valo 				   buf_ring->bufs_max * 3, GFP_ATOMIC);
1299d8899132SKalle Valo 		spin_unlock_bh(&buf_ring->idr_lock);
1300d8899132SKalle Valo 
1301d8899132SKalle Valo 		if (unlikely(buf_id < 0))
1302d8899132SKalle Valo 			goto fail_dma_unmap;
1303d8899132SKalle Valo 
1304d8899132SKalle Valo 		mon_buf = ath12k_hal_srng_src_get_next_entry(ab, srng);
1305d8899132SKalle Valo 		if (unlikely(!mon_buf))
1306d8899132SKalle Valo 			goto fail_idr_remove;
1307d8899132SKalle Valo 
1308d8899132SKalle Valo 		ATH12K_SKB_RXCB(skb)->paddr = paddr;
1309d8899132SKalle Valo 
1310d8899132SKalle Valo 		cookie = u32_encode_bits(buf_id, DP_RXDMA_BUF_COOKIE_BUF_ID);
1311d8899132SKalle Valo 
1312d8899132SKalle Valo 		mon_buf->paddr_lo = cpu_to_le32(lower_32_bits(paddr));
1313d8899132SKalle Valo 		mon_buf->paddr_hi = cpu_to_le32(upper_32_bits(paddr));
1314d8899132SKalle Valo 		mon_buf->cookie = cpu_to_le64(cookie);
1315d8899132SKalle Valo 
1316d8899132SKalle Valo 		req_entries--;
1317d8899132SKalle Valo 	}
1318d8899132SKalle Valo 
1319d8899132SKalle Valo 	ath12k_hal_srng_access_end(ab, srng);
1320d8899132SKalle Valo 	spin_unlock_bh(&srng->lock);
1321d8899132SKalle Valo 	return 0;
1322d8899132SKalle Valo 
1323d8899132SKalle Valo fail_idr_remove:
1324d8899132SKalle Valo 	spin_lock_bh(&buf_ring->idr_lock);
1325d8899132SKalle Valo 	idr_remove(&buf_ring->bufs_idr, buf_id);
1326d8899132SKalle Valo 	spin_unlock_bh(&buf_ring->idr_lock);
1327d8899132SKalle Valo fail_dma_unmap:
1328d8899132SKalle Valo 	dma_unmap_single(ab->dev, paddr, skb->len + skb_tailroom(skb),
1329d8899132SKalle Valo 			 DMA_FROM_DEVICE);
1330d8899132SKalle Valo fail_free_skb:
1331d8899132SKalle Valo 	dev_kfree_skb_any(skb);
1332d8899132SKalle Valo fail_alloc_skb:
1333d8899132SKalle Valo 	ath12k_hal_srng_access_end(ab, srng);
1334d8899132SKalle Valo 	spin_unlock_bh(&srng->lock);
1335d8899132SKalle Valo 	return -ENOMEM;
1336d8899132SKalle Valo }
1337d8899132SKalle Valo 
1338d8899132SKalle Valo static struct dp_mon_tx_ppdu_info *
ath12k_dp_mon_tx_get_ppdu_info(struct ath12k_mon_data * pmon,unsigned int ppdu_id,enum dp_mon_tx_ppdu_info_type type)1339d8899132SKalle Valo ath12k_dp_mon_tx_get_ppdu_info(struct ath12k_mon_data *pmon,
1340d8899132SKalle Valo 			       unsigned int ppdu_id,
1341d8899132SKalle Valo 			       enum dp_mon_tx_ppdu_info_type type)
1342d8899132SKalle Valo {
1343d8899132SKalle Valo 	struct dp_mon_tx_ppdu_info *tx_ppdu_info;
1344d8899132SKalle Valo 
1345d8899132SKalle Valo 	if (type == DP_MON_TX_PROT_PPDU_INFO) {
1346d8899132SKalle Valo 		tx_ppdu_info = pmon->tx_prot_ppdu_info;
1347d8899132SKalle Valo 
1348d8899132SKalle Valo 		if (tx_ppdu_info && !tx_ppdu_info->is_used)
1349d8899132SKalle Valo 			return tx_ppdu_info;
1350d8899132SKalle Valo 		kfree(tx_ppdu_info);
1351d8899132SKalle Valo 	} else {
1352d8899132SKalle Valo 		tx_ppdu_info = pmon->tx_data_ppdu_info;
1353d8899132SKalle Valo 
1354d8899132SKalle Valo 		if (tx_ppdu_info && !tx_ppdu_info->is_used)
1355d8899132SKalle Valo 			return tx_ppdu_info;
1356d8899132SKalle Valo 		kfree(tx_ppdu_info);
1357d8899132SKalle Valo 	}
1358d8899132SKalle Valo 
1359d8899132SKalle Valo 	/* allocate new tx_ppdu_info */
1360d8899132SKalle Valo 	tx_ppdu_info = kzalloc(sizeof(*tx_ppdu_info), GFP_ATOMIC);
1361d8899132SKalle Valo 	if (!tx_ppdu_info)
1362d8899132SKalle Valo 		return NULL;
1363d8899132SKalle Valo 
1364d8899132SKalle Valo 	tx_ppdu_info->is_used = 0;
1365d8899132SKalle Valo 	tx_ppdu_info->ppdu_id = ppdu_id;
1366d8899132SKalle Valo 
1367d8899132SKalle Valo 	if (type == DP_MON_TX_PROT_PPDU_INFO)
1368d8899132SKalle Valo 		pmon->tx_prot_ppdu_info = tx_ppdu_info;
1369d8899132SKalle Valo 	else
1370d8899132SKalle Valo 		pmon->tx_data_ppdu_info = tx_ppdu_info;
1371d8899132SKalle Valo 
1372d8899132SKalle Valo 	return tx_ppdu_info;
1373d8899132SKalle Valo }
1374d8899132SKalle Valo 
1375d8899132SKalle Valo static struct dp_mon_tx_ppdu_info *
ath12k_dp_mon_hal_tx_ppdu_info(struct ath12k_mon_data * pmon,u16 tlv_tag)1376d8899132SKalle Valo ath12k_dp_mon_hal_tx_ppdu_info(struct ath12k_mon_data *pmon,
1377d8899132SKalle Valo 			       u16 tlv_tag)
1378d8899132SKalle Valo {
1379d8899132SKalle Valo 	switch (tlv_tag) {
1380d8899132SKalle Valo 	case HAL_TX_FES_SETUP:
1381d8899132SKalle Valo 	case HAL_TX_FLUSH:
1382d8899132SKalle Valo 	case HAL_PCU_PPDU_SETUP_INIT:
1383d8899132SKalle Valo 	case HAL_TX_PEER_ENTRY:
1384d8899132SKalle Valo 	case HAL_TX_QUEUE_EXTENSION:
1385d8899132SKalle Valo 	case HAL_TX_MPDU_START:
1386d8899132SKalle Valo 	case HAL_TX_MSDU_START:
1387d8899132SKalle Valo 	case HAL_TX_DATA:
1388d8899132SKalle Valo 	case HAL_MON_BUF_ADDR:
1389d8899132SKalle Valo 	case HAL_TX_MPDU_END:
1390d8899132SKalle Valo 	case HAL_TX_LAST_MPDU_FETCHED:
1391d8899132SKalle Valo 	case HAL_TX_LAST_MPDU_END:
1392d8899132SKalle Valo 	case HAL_COEX_TX_REQ:
1393d8899132SKalle Valo 	case HAL_TX_RAW_OR_NATIVE_FRAME_SETUP:
1394d8899132SKalle Valo 	case HAL_SCH_CRITICAL_TLV_REFERENCE:
1395d8899132SKalle Valo 	case HAL_TX_FES_SETUP_COMPLETE:
1396d8899132SKalle Valo 	case HAL_TQM_MPDU_GLOBAL_START:
1397d8899132SKalle Valo 	case HAL_SCHEDULER_END:
1398d8899132SKalle Valo 	case HAL_TX_FES_STATUS_USER_PPDU:
1399d8899132SKalle Valo 		break;
1400d8899132SKalle Valo 	case HAL_TX_FES_STATUS_PROT: {
1401d8899132SKalle Valo 		if (!pmon->tx_prot_ppdu_info->is_used)
1402d8899132SKalle Valo 			pmon->tx_prot_ppdu_info->is_used = true;
1403d8899132SKalle Valo 
1404d8899132SKalle Valo 		return pmon->tx_prot_ppdu_info;
1405d8899132SKalle Valo 	}
1406d8899132SKalle Valo 	}
1407d8899132SKalle Valo 
1408d8899132SKalle Valo 	if (!pmon->tx_data_ppdu_info->is_used)
1409d8899132SKalle Valo 		pmon->tx_data_ppdu_info->is_used = true;
1410d8899132SKalle Valo 
1411d8899132SKalle Valo 	return pmon->tx_data_ppdu_info;
1412d8899132SKalle Valo }
1413d8899132SKalle Valo 
1414d8899132SKalle Valo #define MAX_MONITOR_HEADER 512
1415d8899132SKalle Valo #define MAX_DUMMY_FRM_BODY 128
1416d8899132SKalle Valo 
ath12k_dp_mon_tx_alloc_skb(void)1417d8899132SKalle Valo struct sk_buff *ath12k_dp_mon_tx_alloc_skb(void)
1418d8899132SKalle Valo {
1419d8899132SKalle Valo 	struct sk_buff *skb;
1420d8899132SKalle Valo 
1421d8899132SKalle Valo 	skb = dev_alloc_skb(MAX_MONITOR_HEADER + MAX_DUMMY_FRM_BODY);
1422d8899132SKalle Valo 	if (!skb)
1423d8899132SKalle Valo 		return NULL;
1424d8899132SKalle Valo 
1425d8899132SKalle Valo 	skb_reserve(skb, MAX_MONITOR_HEADER);
1426d8899132SKalle Valo 
1427d8899132SKalle Valo 	if (!IS_ALIGNED((unsigned long)skb->data, 4))
1428d8899132SKalle Valo 		skb_pull(skb, PTR_ALIGN(skb->data, 4) - skb->data);
1429d8899132SKalle Valo 
1430d8899132SKalle Valo 	return skb;
1431d8899132SKalle Valo }
1432d8899132SKalle Valo 
1433d8899132SKalle Valo static int
ath12k_dp_mon_tx_gen_cts2self_frame(struct dp_mon_tx_ppdu_info * tx_ppdu_info)1434d8899132SKalle Valo ath12k_dp_mon_tx_gen_cts2self_frame(struct dp_mon_tx_ppdu_info *tx_ppdu_info)
1435d8899132SKalle Valo {
1436d8899132SKalle Valo 	struct sk_buff *skb;
1437d8899132SKalle Valo 	struct ieee80211_cts *cts;
1438d8899132SKalle Valo 
1439d8899132SKalle Valo 	skb = ath12k_dp_mon_tx_alloc_skb();
1440d8899132SKalle Valo 	if (!skb)
1441d8899132SKalle Valo 		return -ENOMEM;
1442d8899132SKalle Valo 
1443d8899132SKalle Valo 	cts = (struct ieee80211_cts *)skb->data;
1444d8899132SKalle Valo 	memset(cts, 0, MAX_DUMMY_FRM_BODY);
1445d8899132SKalle Valo 	cts->frame_control =
1446d8899132SKalle Valo 		cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
1447d8899132SKalle Valo 	cts->duration = cpu_to_le16(tx_ppdu_info->rx_status.rx_duration);
1448d8899132SKalle Valo 	memcpy(cts->ra, tx_ppdu_info->rx_status.addr1, sizeof(cts->ra));
1449d8899132SKalle Valo 
1450d8899132SKalle Valo 	skb_put(skb, sizeof(*cts));
1451d8899132SKalle Valo 	tx_ppdu_info->tx_mon_mpdu->head = skb;
1452d8899132SKalle Valo 	tx_ppdu_info->tx_mon_mpdu->tail = NULL;
1453d8899132SKalle Valo 	list_add_tail(&tx_ppdu_info->tx_mon_mpdu->list,
1454d8899132SKalle Valo 		      &tx_ppdu_info->dp_tx_mon_mpdu_list);
1455d8899132SKalle Valo 
1456d8899132SKalle Valo 	return 0;
1457d8899132SKalle Valo }
1458d8899132SKalle Valo 
1459d8899132SKalle Valo static int
ath12k_dp_mon_tx_gen_rts_frame(struct dp_mon_tx_ppdu_info * tx_ppdu_info)1460d8899132SKalle Valo ath12k_dp_mon_tx_gen_rts_frame(struct dp_mon_tx_ppdu_info *tx_ppdu_info)
1461d8899132SKalle Valo {
1462d8899132SKalle Valo 	struct sk_buff *skb;
1463d8899132SKalle Valo 	struct ieee80211_rts *rts;
1464d8899132SKalle Valo 
1465d8899132SKalle Valo 	skb = ath12k_dp_mon_tx_alloc_skb();
1466d8899132SKalle Valo 	if (!skb)
1467d8899132SKalle Valo 		return -ENOMEM;
1468d8899132SKalle Valo 
1469d8899132SKalle Valo 	rts = (struct ieee80211_rts *)skb->data;
1470d8899132SKalle Valo 	memset(rts, 0, MAX_DUMMY_FRM_BODY);
1471d8899132SKalle Valo 	rts->frame_control =
1472d8899132SKalle Valo 		cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
1473d8899132SKalle Valo 	rts->duration = cpu_to_le16(tx_ppdu_info->rx_status.rx_duration);
1474d8899132SKalle Valo 	memcpy(rts->ra, tx_ppdu_info->rx_status.addr1, sizeof(rts->ra));
1475d8899132SKalle Valo 	memcpy(rts->ta, tx_ppdu_info->rx_status.addr2, sizeof(rts->ta));
1476d8899132SKalle Valo 
1477d8899132SKalle Valo 	skb_put(skb, sizeof(*rts));
1478d8899132SKalle Valo 	tx_ppdu_info->tx_mon_mpdu->head = skb;
1479d8899132SKalle Valo 	tx_ppdu_info->tx_mon_mpdu->tail = NULL;
1480d8899132SKalle Valo 	list_add_tail(&tx_ppdu_info->tx_mon_mpdu->list,
1481d8899132SKalle Valo 		      &tx_ppdu_info->dp_tx_mon_mpdu_list);
1482d8899132SKalle Valo 
1483d8899132SKalle Valo 	return 0;
1484d8899132SKalle Valo }
1485d8899132SKalle Valo 
1486d8899132SKalle Valo static int
ath12k_dp_mon_tx_gen_3addr_qos_null_frame(struct dp_mon_tx_ppdu_info * tx_ppdu_info)1487d8899132SKalle Valo ath12k_dp_mon_tx_gen_3addr_qos_null_frame(struct dp_mon_tx_ppdu_info *tx_ppdu_info)
1488d8899132SKalle Valo {
1489d8899132SKalle Valo 	struct sk_buff *skb;
1490d8899132SKalle Valo 	struct ieee80211_qos_hdr *qhdr;
1491d8899132SKalle Valo 
1492d8899132SKalle Valo 	skb = ath12k_dp_mon_tx_alloc_skb();
1493d8899132SKalle Valo 	if (!skb)
1494d8899132SKalle Valo 		return -ENOMEM;
1495d8899132SKalle Valo 
1496d8899132SKalle Valo 	qhdr = (struct ieee80211_qos_hdr *)skb->data;
1497d8899132SKalle Valo 	memset(qhdr, 0, MAX_DUMMY_FRM_BODY);
1498d8899132SKalle Valo 	qhdr->frame_control =
1499d8899132SKalle Valo 		cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_NULLFUNC);
1500d8899132SKalle Valo 	qhdr->duration_id = cpu_to_le16(tx_ppdu_info->rx_status.rx_duration);
1501d8899132SKalle Valo 	memcpy(qhdr->addr1, tx_ppdu_info->rx_status.addr1, ETH_ALEN);
1502d8899132SKalle Valo 	memcpy(qhdr->addr2, tx_ppdu_info->rx_status.addr2, ETH_ALEN);
1503d8899132SKalle Valo 	memcpy(qhdr->addr3, tx_ppdu_info->rx_status.addr3, ETH_ALEN);
1504d8899132SKalle Valo 
1505d8899132SKalle Valo 	skb_put(skb, sizeof(*qhdr));
1506d8899132SKalle Valo 	tx_ppdu_info->tx_mon_mpdu->head = skb;
1507d8899132SKalle Valo 	tx_ppdu_info->tx_mon_mpdu->tail = NULL;
1508d8899132SKalle Valo 	list_add_tail(&tx_ppdu_info->tx_mon_mpdu->list,
1509d8899132SKalle Valo 		      &tx_ppdu_info->dp_tx_mon_mpdu_list);
1510d8899132SKalle Valo 
1511d8899132SKalle Valo 	return 0;
1512d8899132SKalle Valo }
1513d8899132SKalle Valo 
1514d8899132SKalle Valo static int
ath12k_dp_mon_tx_gen_4addr_qos_null_frame(struct dp_mon_tx_ppdu_info * tx_ppdu_info)1515d8899132SKalle Valo ath12k_dp_mon_tx_gen_4addr_qos_null_frame(struct dp_mon_tx_ppdu_info *tx_ppdu_info)
1516d8899132SKalle Valo {
1517d8899132SKalle Valo 	struct sk_buff *skb;
1518d8899132SKalle Valo 	struct dp_mon_qosframe_addr4 *qhdr;
1519d8899132SKalle Valo 
1520d8899132SKalle Valo 	skb = ath12k_dp_mon_tx_alloc_skb();
1521d8899132SKalle Valo 	if (!skb)
1522d8899132SKalle Valo 		return -ENOMEM;
1523d8899132SKalle Valo 
1524d8899132SKalle Valo 	qhdr = (struct dp_mon_qosframe_addr4 *)skb->data;
1525d8899132SKalle Valo 	memset(qhdr, 0, MAX_DUMMY_FRM_BODY);
1526d8899132SKalle Valo 	qhdr->frame_control =
1527d8899132SKalle Valo 		cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_NULLFUNC);
1528d8899132SKalle Valo 	qhdr->duration = cpu_to_le16(tx_ppdu_info->rx_status.rx_duration);
1529d8899132SKalle Valo 	memcpy(qhdr->addr1, tx_ppdu_info->rx_status.addr1, ETH_ALEN);
1530d8899132SKalle Valo 	memcpy(qhdr->addr2, tx_ppdu_info->rx_status.addr2, ETH_ALEN);
1531d8899132SKalle Valo 	memcpy(qhdr->addr3, tx_ppdu_info->rx_status.addr3, ETH_ALEN);
1532d8899132SKalle Valo 	memcpy(qhdr->addr4, tx_ppdu_info->rx_status.addr4, ETH_ALEN);
1533d8899132SKalle Valo 
1534d8899132SKalle Valo 	skb_put(skb, sizeof(*qhdr));
1535d8899132SKalle Valo 	tx_ppdu_info->tx_mon_mpdu->head = skb;
1536d8899132SKalle Valo 	tx_ppdu_info->tx_mon_mpdu->tail = NULL;
1537d8899132SKalle Valo 	list_add_tail(&tx_ppdu_info->tx_mon_mpdu->list,
1538d8899132SKalle Valo 		      &tx_ppdu_info->dp_tx_mon_mpdu_list);
1539d8899132SKalle Valo 
1540d8899132SKalle Valo 	return 0;
1541d8899132SKalle Valo }
1542d8899132SKalle Valo 
1543d8899132SKalle Valo static int
ath12k_dp_mon_tx_gen_ack_frame(struct dp_mon_tx_ppdu_info * tx_ppdu_info)1544d8899132SKalle Valo ath12k_dp_mon_tx_gen_ack_frame(struct dp_mon_tx_ppdu_info *tx_ppdu_info)
1545d8899132SKalle Valo {
1546d8899132SKalle Valo 	struct sk_buff *skb;
1547d8899132SKalle Valo 	struct dp_mon_frame_min_one *fbmhdr;
1548d8899132SKalle Valo 
1549d8899132SKalle Valo 	skb = ath12k_dp_mon_tx_alloc_skb();
1550d8899132SKalle Valo 	if (!skb)
1551d8899132SKalle Valo 		return -ENOMEM;
1552d8899132SKalle Valo 
1553d8899132SKalle Valo 	fbmhdr = (struct dp_mon_frame_min_one *)skb->data;
1554d8899132SKalle Valo 	memset(fbmhdr, 0, MAX_DUMMY_FRM_BODY);
1555d8899132SKalle Valo 	fbmhdr->frame_control =
1556d8899132SKalle Valo 		cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_CFACK);
1557d8899132SKalle Valo 	memcpy(fbmhdr->addr1, tx_ppdu_info->rx_status.addr1, ETH_ALEN);
1558d8899132SKalle Valo 
1559d8899132SKalle Valo 	/* set duration zero for ack frame */
1560d8899132SKalle Valo 	fbmhdr->duration = 0;
1561d8899132SKalle Valo 
1562d8899132SKalle Valo 	skb_put(skb, sizeof(*fbmhdr));
1563d8899132SKalle Valo 	tx_ppdu_info->tx_mon_mpdu->head = skb;
1564d8899132SKalle Valo 	tx_ppdu_info->tx_mon_mpdu->tail = NULL;
1565d8899132SKalle Valo 	list_add_tail(&tx_ppdu_info->tx_mon_mpdu->list,
1566d8899132SKalle Valo 		      &tx_ppdu_info->dp_tx_mon_mpdu_list);
1567d8899132SKalle Valo 
1568d8899132SKalle Valo 	return 0;
1569d8899132SKalle Valo }
1570d8899132SKalle Valo 
1571d8899132SKalle Valo static int
ath12k_dp_mon_tx_gen_prot_frame(struct dp_mon_tx_ppdu_info * tx_ppdu_info)1572d8899132SKalle Valo ath12k_dp_mon_tx_gen_prot_frame(struct dp_mon_tx_ppdu_info *tx_ppdu_info)
1573d8899132SKalle Valo {
1574d8899132SKalle Valo 	int ret = 0;
1575d8899132SKalle Valo 
1576d8899132SKalle Valo 	switch (tx_ppdu_info->rx_status.medium_prot_type) {
1577d8899132SKalle Valo 	case DP_MON_TX_MEDIUM_RTS_LEGACY:
1578d8899132SKalle Valo 	case DP_MON_TX_MEDIUM_RTS_11AC_STATIC_BW:
1579d8899132SKalle Valo 	case DP_MON_TX_MEDIUM_RTS_11AC_DYNAMIC_BW:
1580d8899132SKalle Valo 		ret = ath12k_dp_mon_tx_gen_rts_frame(tx_ppdu_info);
1581d8899132SKalle Valo 		break;
1582d8899132SKalle Valo 	case DP_MON_TX_MEDIUM_CTS2SELF:
1583d8899132SKalle Valo 		ret = ath12k_dp_mon_tx_gen_cts2self_frame(tx_ppdu_info);
1584d8899132SKalle Valo 		break;
1585d8899132SKalle Valo 	case DP_MON_TX_MEDIUM_QOS_NULL_NO_ACK_3ADDR:
1586d8899132SKalle Valo 		ret = ath12k_dp_mon_tx_gen_3addr_qos_null_frame(tx_ppdu_info);
1587d8899132SKalle Valo 		break;
1588d8899132SKalle Valo 	case DP_MON_TX_MEDIUM_QOS_NULL_NO_ACK_4ADDR:
1589d8899132SKalle Valo 		ret = ath12k_dp_mon_tx_gen_4addr_qos_null_frame(tx_ppdu_info);
1590d8899132SKalle Valo 		break;
1591d8899132SKalle Valo 	}
1592d8899132SKalle Valo 
1593d8899132SKalle Valo 	return ret;
1594d8899132SKalle Valo }
1595d8899132SKalle Valo 
1596d8899132SKalle Valo static enum dp_mon_tx_tlv_status
ath12k_dp_mon_tx_parse_status_tlv(struct ath12k_base * ab,struct ath12k_mon_data * pmon,u16 tlv_tag,u8 * tlv_data,u32 userid)1597d8899132SKalle Valo ath12k_dp_mon_tx_parse_status_tlv(struct ath12k_base *ab,
1598d8899132SKalle Valo 				  struct ath12k_mon_data *pmon,
1599d8899132SKalle Valo 				  u16 tlv_tag, u8 *tlv_data, u32 userid)
1600d8899132SKalle Valo {
1601d8899132SKalle Valo 	struct dp_mon_tx_ppdu_info *tx_ppdu_info;
1602d8899132SKalle Valo 	enum dp_mon_tx_tlv_status status = DP_MON_TX_STATUS_PPDU_NOT_DONE;
1603d8899132SKalle Valo 	u32 info[7];
1604d8899132SKalle Valo 
1605d8899132SKalle Valo 	tx_ppdu_info = ath12k_dp_mon_hal_tx_ppdu_info(pmon, tlv_tag);
1606d8899132SKalle Valo 
1607d8899132SKalle Valo 	switch (tlv_tag) {
1608d8899132SKalle Valo 	case HAL_TX_FES_SETUP: {
1609d8899132SKalle Valo 		struct hal_tx_fes_setup *tx_fes_setup =
1610d8899132SKalle Valo 					(struct hal_tx_fes_setup *)tlv_data;
1611d8899132SKalle Valo 
1612d8899132SKalle Valo 		info[0] = __le32_to_cpu(tx_fes_setup->info0);
1613d8899132SKalle Valo 		tx_ppdu_info->ppdu_id = __le32_to_cpu(tx_fes_setup->schedule_id);
1614d8899132SKalle Valo 		tx_ppdu_info->num_users =
1615d8899132SKalle Valo 			u32_get_bits(info[0], HAL_TX_FES_SETUP_INFO0_NUM_OF_USERS);
1616d8899132SKalle Valo 		status = DP_MON_TX_FES_SETUP;
1617d8899132SKalle Valo 		break;
1618d8899132SKalle Valo 	}
1619d8899132SKalle Valo 
1620d8899132SKalle Valo 	case HAL_TX_FES_STATUS_END: {
1621d8899132SKalle Valo 		struct hal_tx_fes_status_end *tx_fes_status_end =
1622d8899132SKalle Valo 			(struct hal_tx_fes_status_end *)tlv_data;
1623d8899132SKalle Valo 		u32 tst_15_0, tst_31_16;
1624d8899132SKalle Valo 
1625d8899132SKalle Valo 		info[0] = __le32_to_cpu(tx_fes_status_end->info0);
1626d8899132SKalle Valo 		tst_15_0 =
1627d8899132SKalle Valo 			u32_get_bits(info[0],
1628d8899132SKalle Valo 				     HAL_TX_FES_STATUS_END_INFO0_START_TIMESTAMP_15_0);
1629d8899132SKalle Valo 		tst_31_16 =
1630d8899132SKalle Valo 			u32_get_bits(info[0],
1631d8899132SKalle Valo 				     HAL_TX_FES_STATUS_END_INFO0_START_TIMESTAMP_31_16);
1632d8899132SKalle Valo 
1633d8899132SKalle Valo 		tx_ppdu_info->rx_status.ppdu_ts = (tst_15_0 | (tst_31_16 << 16));
1634d8899132SKalle Valo 		status = DP_MON_TX_FES_STATUS_END;
1635d8899132SKalle Valo 		break;
1636d8899132SKalle Valo 	}
1637d8899132SKalle Valo 
1638d8899132SKalle Valo 	case HAL_RX_RESPONSE_REQUIRED_INFO: {
1639d8899132SKalle Valo 		struct hal_rx_resp_req_info *rx_resp_req_info =
1640d8899132SKalle Valo 			(struct hal_rx_resp_req_info *)tlv_data;
1641d8899132SKalle Valo 		u32 addr_32;
1642d8899132SKalle Valo 		u16 addr_16;
1643d8899132SKalle Valo 
1644d8899132SKalle Valo 		info[0] = __le32_to_cpu(rx_resp_req_info->info0);
1645d8899132SKalle Valo 		info[1] = __le32_to_cpu(rx_resp_req_info->info1);
1646d8899132SKalle Valo 		info[2] = __le32_to_cpu(rx_resp_req_info->info2);
1647d8899132SKalle Valo 		info[3] = __le32_to_cpu(rx_resp_req_info->info3);
1648d8899132SKalle Valo 		info[4] = __le32_to_cpu(rx_resp_req_info->info4);
1649d8899132SKalle Valo 		info[5] = __le32_to_cpu(rx_resp_req_info->info5);
1650d8899132SKalle Valo 
1651d8899132SKalle Valo 		tx_ppdu_info->rx_status.ppdu_id =
1652d8899132SKalle Valo 			u32_get_bits(info[0], HAL_RX_RESP_REQ_INFO0_PPDU_ID);
1653d8899132SKalle Valo 		tx_ppdu_info->rx_status.reception_type =
1654d8899132SKalle Valo 			u32_get_bits(info[0], HAL_RX_RESP_REQ_INFO0_RECEPTION_TYPE);
1655d8899132SKalle Valo 		tx_ppdu_info->rx_status.rx_duration =
1656d8899132SKalle Valo 			u32_get_bits(info[1], HAL_RX_RESP_REQ_INFO1_DURATION);
1657d8899132SKalle Valo 		tx_ppdu_info->rx_status.mcs =
1658d8899132SKalle Valo 			u32_get_bits(info[1], HAL_RX_RESP_REQ_INFO1_RATE_MCS);
1659d8899132SKalle Valo 		tx_ppdu_info->rx_status.sgi =
1660d8899132SKalle Valo 			u32_get_bits(info[1], HAL_RX_RESP_REQ_INFO1_SGI);
1661d8899132SKalle Valo 		tx_ppdu_info->rx_status.is_stbc =
1662d8899132SKalle Valo 			u32_get_bits(info[1], HAL_RX_RESP_REQ_INFO1_STBC);
1663d8899132SKalle Valo 		tx_ppdu_info->rx_status.ldpc =
1664d8899132SKalle Valo 			u32_get_bits(info[1], HAL_RX_RESP_REQ_INFO1_LDPC);
1665d8899132SKalle Valo 		tx_ppdu_info->rx_status.is_ampdu =
1666d8899132SKalle Valo 			u32_get_bits(info[1], HAL_RX_RESP_REQ_INFO1_IS_AMPDU);
1667d8899132SKalle Valo 		tx_ppdu_info->rx_status.num_users =
1668d8899132SKalle Valo 			u32_get_bits(info[2], HAL_RX_RESP_REQ_INFO2_NUM_USER);
1669d8899132SKalle Valo 
1670d8899132SKalle Valo 		addr_32 = u32_get_bits(info[3], HAL_RX_RESP_REQ_INFO3_ADDR1_31_0);
1671d8899132SKalle Valo 		addr_16 = u32_get_bits(info[3], HAL_RX_RESP_REQ_INFO4_ADDR1_47_32);
1672d8899132SKalle Valo 		ath12k_dp_get_mac_addr(addr_32, addr_16, tx_ppdu_info->rx_status.addr1);
1673d8899132SKalle Valo 
1674d8899132SKalle Valo 		addr_16 = u32_get_bits(info[4], HAL_RX_RESP_REQ_INFO4_ADDR1_15_0);
1675d8899132SKalle Valo 		addr_32 = u32_get_bits(info[5], HAL_RX_RESP_REQ_INFO5_ADDR1_47_16);
1676d8899132SKalle Valo 		ath12k_dp_get_mac_addr(addr_32, addr_16, tx_ppdu_info->rx_status.addr2);
1677d8899132SKalle Valo 
1678d8899132SKalle Valo 		if (tx_ppdu_info->rx_status.reception_type == 0)
1679d8899132SKalle Valo 			ath12k_dp_mon_tx_gen_cts2self_frame(tx_ppdu_info);
1680d8899132SKalle Valo 		status = DP_MON_RX_RESPONSE_REQUIRED_INFO;
1681d8899132SKalle Valo 		break;
1682d8899132SKalle Valo 	}
1683d8899132SKalle Valo 
1684d8899132SKalle Valo 	case HAL_PCU_PPDU_SETUP_INIT: {
1685d8899132SKalle Valo 		struct hal_tx_pcu_ppdu_setup_init *ppdu_setup =
1686d8899132SKalle Valo 			(struct hal_tx_pcu_ppdu_setup_init *)tlv_data;
1687d8899132SKalle Valo 		u32 addr_32;
1688d8899132SKalle Valo 		u16 addr_16;
1689d8899132SKalle Valo 
1690d8899132SKalle Valo 		info[0] = __le32_to_cpu(ppdu_setup->info0);
1691d8899132SKalle Valo 		info[1] = __le32_to_cpu(ppdu_setup->info1);
1692d8899132SKalle Valo 		info[2] = __le32_to_cpu(ppdu_setup->info2);
1693d8899132SKalle Valo 		info[3] = __le32_to_cpu(ppdu_setup->info3);
1694d8899132SKalle Valo 		info[4] = __le32_to_cpu(ppdu_setup->info4);
1695d8899132SKalle Valo 		info[5] = __le32_to_cpu(ppdu_setup->info5);
1696d8899132SKalle Valo 		info[6] = __le32_to_cpu(ppdu_setup->info6);
1697d8899132SKalle Valo 
1698d8899132SKalle Valo 		/* protection frame address 1 */
1699d8899132SKalle Valo 		addr_32 = u32_get_bits(info[1],
1700d8899132SKalle Valo 				       HAL_TX_PPDU_SETUP_INFO1_PROT_FRAME_ADDR1_31_0);
1701d8899132SKalle Valo 		addr_16 = u32_get_bits(info[2],
1702d8899132SKalle Valo 				       HAL_TX_PPDU_SETUP_INFO2_PROT_FRAME_ADDR1_47_32);
1703d8899132SKalle Valo 		ath12k_dp_get_mac_addr(addr_32, addr_16, tx_ppdu_info->rx_status.addr1);
1704d8899132SKalle Valo 
1705d8899132SKalle Valo 		/* protection frame address 2 */
1706d8899132SKalle Valo 		addr_16 = u32_get_bits(info[2],
1707d8899132SKalle Valo 				       HAL_TX_PPDU_SETUP_INFO2_PROT_FRAME_ADDR2_15_0);
1708d8899132SKalle Valo 		addr_32 = u32_get_bits(info[3],
1709d8899132SKalle Valo 				       HAL_TX_PPDU_SETUP_INFO3_PROT_FRAME_ADDR2_47_16);
1710d8899132SKalle Valo 		ath12k_dp_get_mac_addr(addr_32, addr_16, tx_ppdu_info->rx_status.addr2);
1711d8899132SKalle Valo 
1712d8899132SKalle Valo 		/* protection frame address 3 */
1713d8899132SKalle Valo 		addr_32 = u32_get_bits(info[4],
1714d8899132SKalle Valo 				       HAL_TX_PPDU_SETUP_INFO4_PROT_FRAME_ADDR3_31_0);
1715d8899132SKalle Valo 		addr_16 = u32_get_bits(info[5],
1716d8899132SKalle Valo 				       HAL_TX_PPDU_SETUP_INFO5_PROT_FRAME_ADDR3_47_32);
1717d8899132SKalle Valo 		ath12k_dp_get_mac_addr(addr_32, addr_16, tx_ppdu_info->rx_status.addr3);
1718d8899132SKalle Valo 
1719d8899132SKalle Valo 		/* protection frame address 4 */
1720d8899132SKalle Valo 		addr_16 = u32_get_bits(info[5],
1721d8899132SKalle Valo 				       HAL_TX_PPDU_SETUP_INFO5_PROT_FRAME_ADDR4_15_0);
1722d8899132SKalle Valo 		addr_32 = u32_get_bits(info[6],
1723d8899132SKalle Valo 				       HAL_TX_PPDU_SETUP_INFO6_PROT_FRAME_ADDR4_47_16);
1724d8899132SKalle Valo 		ath12k_dp_get_mac_addr(addr_32, addr_16, tx_ppdu_info->rx_status.addr4);
1725d8899132SKalle Valo 
1726d8899132SKalle Valo 		status = u32_get_bits(info[0],
1727d8899132SKalle Valo 				      HAL_TX_PPDU_SETUP_INFO0_MEDIUM_PROT_TYPE);
1728d8899132SKalle Valo 		break;
1729d8899132SKalle Valo 	}
1730d8899132SKalle Valo 
1731d8899132SKalle Valo 	case HAL_TX_QUEUE_EXTENSION: {
1732d8899132SKalle Valo 		struct hal_tx_queue_exten *tx_q_exten =
1733d8899132SKalle Valo 			(struct hal_tx_queue_exten *)tlv_data;
1734d8899132SKalle Valo 
1735d8899132SKalle Valo 		info[0] = __le32_to_cpu(tx_q_exten->info0);
1736d8899132SKalle Valo 
1737d8899132SKalle Valo 		tx_ppdu_info->rx_status.frame_control =
1738d8899132SKalle Valo 			u32_get_bits(info[0],
1739d8899132SKalle Valo 				     HAL_TX_Q_EXT_INFO0_FRAME_CTRL);
1740d8899132SKalle Valo 		tx_ppdu_info->rx_status.fc_valid = true;
1741d8899132SKalle Valo 		break;
1742d8899132SKalle Valo 	}
1743d8899132SKalle Valo 
1744d8899132SKalle Valo 	case HAL_TX_FES_STATUS_START: {
1745d8899132SKalle Valo 		struct hal_tx_fes_status_start *tx_fes_start =
1746d8899132SKalle Valo 			(struct hal_tx_fes_status_start *)tlv_data;
1747d8899132SKalle Valo 
1748d8899132SKalle Valo 		info[0] = __le32_to_cpu(tx_fes_start->info0);
1749d8899132SKalle Valo 
1750d8899132SKalle Valo 		tx_ppdu_info->rx_status.medium_prot_type =
1751d8899132SKalle Valo 			u32_get_bits(info[0],
1752d8899132SKalle Valo 				     HAL_TX_FES_STATUS_START_INFO0_MEDIUM_PROT_TYPE);
1753d8899132SKalle Valo 		break;
1754d8899132SKalle Valo 	}
1755d8899132SKalle Valo 
1756d8899132SKalle Valo 	case HAL_TX_FES_STATUS_PROT: {
1757d8899132SKalle Valo 		struct hal_tx_fes_status_prot *tx_fes_status =
1758d8899132SKalle Valo 			(struct hal_tx_fes_status_prot *)tlv_data;
1759d8899132SKalle Valo 		u32 start_timestamp;
1760d8899132SKalle Valo 		u32 end_timestamp;
1761d8899132SKalle Valo 
1762d8899132SKalle Valo 		info[0] = __le32_to_cpu(tx_fes_status->info0);
1763d8899132SKalle Valo 		info[1] = __le32_to_cpu(tx_fes_status->info1);
1764d8899132SKalle Valo 
1765d8899132SKalle Valo 		start_timestamp =
1766d8899132SKalle Valo 			u32_get_bits(info[0],
1767d8899132SKalle Valo 				     HAL_TX_FES_STAT_PROT_INFO0_STRT_FRM_TS_15_0);
1768d8899132SKalle Valo 		start_timestamp |=
1769d8899132SKalle Valo 			u32_get_bits(info[0],
1770d8899132SKalle Valo 				     HAL_TX_FES_STAT_PROT_INFO0_STRT_FRM_TS_31_16) << 15;
1771d8899132SKalle Valo 		end_timestamp =
1772d8899132SKalle Valo 			u32_get_bits(info[1],
1773d8899132SKalle Valo 				     HAL_TX_FES_STAT_PROT_INFO1_END_FRM_TS_15_0);
1774d8899132SKalle Valo 		end_timestamp |=
1775d8899132SKalle Valo 			u32_get_bits(info[1],
1776d8899132SKalle Valo 				     HAL_TX_FES_STAT_PROT_INFO1_END_FRM_TS_31_16) << 15;
1777d8899132SKalle Valo 		tx_ppdu_info->rx_status.rx_duration = end_timestamp - start_timestamp;
1778d8899132SKalle Valo 
1779d8899132SKalle Valo 		ath12k_dp_mon_tx_gen_prot_frame(tx_ppdu_info);
1780d8899132SKalle Valo 		break;
1781d8899132SKalle Valo 	}
1782d8899132SKalle Valo 
1783d8899132SKalle Valo 	case HAL_TX_FES_STATUS_START_PPDU:
1784d8899132SKalle Valo 	case HAL_TX_FES_STATUS_START_PROT: {
1785d8899132SKalle Valo 		struct hal_tx_fes_status_start_prot *tx_fes_stat_start =
1786d8899132SKalle Valo 			(struct hal_tx_fes_status_start_prot *)tlv_data;
1787d8899132SKalle Valo 		u64 ppdu_ts;
1788d8899132SKalle Valo 
1789d8899132SKalle Valo 		info[0] = __le32_to_cpu(tx_fes_stat_start->info0);
1790d8899132SKalle Valo 
1791d8899132SKalle Valo 		tx_ppdu_info->rx_status.ppdu_ts =
1792d8899132SKalle Valo 			u32_get_bits(info[0],
1793d8899132SKalle Valo 				     HAL_TX_FES_STAT_STRT_INFO0_PROT_TS_LOWER_32);
1794d8899132SKalle Valo 		ppdu_ts = (u32_get_bits(info[1],
1795d8899132SKalle Valo 					HAL_TX_FES_STAT_STRT_INFO1_PROT_TS_UPPER_32));
1796d8899132SKalle Valo 		tx_ppdu_info->rx_status.ppdu_ts |= ppdu_ts << 32;
1797d8899132SKalle Valo 		break;
1798d8899132SKalle Valo 	}
1799d8899132SKalle Valo 
1800d8899132SKalle Valo 	case HAL_TX_FES_STATUS_USER_PPDU: {
1801d8899132SKalle Valo 		struct hal_tx_fes_status_user_ppdu *tx_fes_usr_ppdu =
1802d8899132SKalle Valo 			(struct hal_tx_fes_status_user_ppdu *)tlv_data;
1803d8899132SKalle Valo 
1804d8899132SKalle Valo 		info[0] = __le32_to_cpu(tx_fes_usr_ppdu->info0);
1805d8899132SKalle Valo 
1806d8899132SKalle Valo 		tx_ppdu_info->rx_status.rx_duration =
1807d8899132SKalle Valo 			u32_get_bits(info[0],
1808d8899132SKalle Valo 				     HAL_TX_FES_STAT_USR_PPDU_INFO0_DURATION);
1809d8899132SKalle Valo 		break;
1810d8899132SKalle Valo 	}
1811d8899132SKalle Valo 
1812d8899132SKalle Valo 	case HAL_MACTX_HE_SIG_A_SU:
1813d8899132SKalle Valo 		ath12k_dp_mon_parse_he_sig_su(tlv_data, &tx_ppdu_info->rx_status);
1814d8899132SKalle Valo 		break;
1815d8899132SKalle Valo 
1816d8899132SKalle Valo 	case HAL_MACTX_HE_SIG_A_MU_DL:
1817d8899132SKalle Valo 		ath12k_dp_mon_parse_he_sig_mu(tlv_data, &tx_ppdu_info->rx_status);
1818d8899132SKalle Valo 		break;
1819d8899132SKalle Valo 
1820d8899132SKalle Valo 	case HAL_MACTX_HE_SIG_B1_MU:
1821d8899132SKalle Valo 		ath12k_dp_mon_parse_he_sig_b1_mu(tlv_data, &tx_ppdu_info->rx_status);
1822d8899132SKalle Valo 		break;
1823d8899132SKalle Valo 
1824d8899132SKalle Valo 	case HAL_MACTX_HE_SIG_B2_MU:
1825d8899132SKalle Valo 		ath12k_dp_mon_parse_he_sig_b2_mu(tlv_data, &tx_ppdu_info->rx_status);
1826d8899132SKalle Valo 		break;
1827d8899132SKalle Valo 
1828d8899132SKalle Valo 	case HAL_MACTX_HE_SIG_B2_OFDMA:
1829d8899132SKalle Valo 		ath12k_dp_mon_parse_he_sig_b2_ofdma(tlv_data, &tx_ppdu_info->rx_status);
1830d8899132SKalle Valo 		break;
1831d8899132SKalle Valo 
1832d8899132SKalle Valo 	case HAL_MACTX_VHT_SIG_A:
1833d8899132SKalle Valo 		ath12k_dp_mon_parse_vht_sig_a(tlv_data, &tx_ppdu_info->rx_status);
1834d8899132SKalle Valo 		break;
1835d8899132SKalle Valo 
1836d8899132SKalle Valo 	case HAL_MACTX_L_SIG_A:
1837d8899132SKalle Valo 		ath12k_dp_mon_parse_l_sig_a(tlv_data, &tx_ppdu_info->rx_status);
1838d8899132SKalle Valo 		break;
1839d8899132SKalle Valo 
1840d8899132SKalle Valo 	case HAL_MACTX_L_SIG_B:
1841d8899132SKalle Valo 		ath12k_dp_mon_parse_l_sig_b(tlv_data, &tx_ppdu_info->rx_status);
1842d8899132SKalle Valo 		break;
1843d8899132SKalle Valo 
1844d8899132SKalle Valo 	case HAL_RX_FRAME_BITMAP_ACK: {
1845d8899132SKalle Valo 		struct hal_rx_frame_bitmap_ack *fbm_ack =
1846d8899132SKalle Valo 			(struct hal_rx_frame_bitmap_ack *)tlv_data;
1847d8899132SKalle Valo 		u32 addr_32;
1848d8899132SKalle Valo 		u16 addr_16;
1849d8899132SKalle Valo 
1850d8899132SKalle Valo 		info[0] = __le32_to_cpu(fbm_ack->info0);
1851d8899132SKalle Valo 		info[1] = __le32_to_cpu(fbm_ack->info1);
1852d8899132SKalle Valo 
1853d8899132SKalle Valo 		addr_32 = u32_get_bits(info[0],
1854d8899132SKalle Valo 				       HAL_RX_FBM_ACK_INFO0_ADDR1_31_0);
1855d8899132SKalle Valo 		addr_16 = u32_get_bits(info[1],
1856d8899132SKalle Valo 				       HAL_RX_FBM_ACK_INFO1_ADDR1_47_32);
1857d8899132SKalle Valo 		ath12k_dp_get_mac_addr(addr_32, addr_16, tx_ppdu_info->rx_status.addr1);
1858d8899132SKalle Valo 
1859d8899132SKalle Valo 		ath12k_dp_mon_tx_gen_ack_frame(tx_ppdu_info);
1860d8899132SKalle Valo 		break;
1861d8899132SKalle Valo 	}
1862d8899132SKalle Valo 
1863d8899132SKalle Valo 	case HAL_MACTX_PHY_DESC: {
1864d8899132SKalle Valo 		struct hal_tx_phy_desc *tx_phy_desc =
1865d8899132SKalle Valo 			(struct hal_tx_phy_desc *)tlv_data;
1866d8899132SKalle Valo 
1867d8899132SKalle Valo 		info[0] = __le32_to_cpu(tx_phy_desc->info0);
1868d8899132SKalle Valo 		info[1] = __le32_to_cpu(tx_phy_desc->info1);
1869d8899132SKalle Valo 		info[2] = __le32_to_cpu(tx_phy_desc->info2);
1870d8899132SKalle Valo 		info[3] = __le32_to_cpu(tx_phy_desc->info3);
1871d8899132SKalle Valo 
1872d8899132SKalle Valo 		tx_ppdu_info->rx_status.beamformed =
1873d8899132SKalle Valo 			u32_get_bits(info[0],
1874d8899132SKalle Valo 				     HAL_TX_PHY_DESC_INFO0_BF_TYPE);
1875d8899132SKalle Valo 		tx_ppdu_info->rx_status.preamble_type =
1876d8899132SKalle Valo 			u32_get_bits(info[0],
1877d8899132SKalle Valo 				     HAL_TX_PHY_DESC_INFO0_PREAMBLE_11B);
1878d8899132SKalle Valo 		tx_ppdu_info->rx_status.mcs =
1879d8899132SKalle Valo 			u32_get_bits(info[1],
1880d8899132SKalle Valo 				     HAL_TX_PHY_DESC_INFO1_MCS);
1881d8899132SKalle Valo 		tx_ppdu_info->rx_status.ltf_size =
1882d8899132SKalle Valo 			u32_get_bits(info[3],
1883d8899132SKalle Valo 				     HAL_TX_PHY_DESC_INFO3_LTF_SIZE);
1884d8899132SKalle Valo 		tx_ppdu_info->rx_status.nss =
1885d8899132SKalle Valo 			u32_get_bits(info[2],
1886d8899132SKalle Valo 				     HAL_TX_PHY_DESC_INFO2_NSS);
1887d8899132SKalle Valo 		tx_ppdu_info->rx_status.chan_num =
1888d8899132SKalle Valo 			u32_get_bits(info[3],
1889d8899132SKalle Valo 				     HAL_TX_PHY_DESC_INFO3_ACTIVE_CHANNEL);
1890d8899132SKalle Valo 		tx_ppdu_info->rx_status.bw =
1891d8899132SKalle Valo 			u32_get_bits(info[0],
1892d8899132SKalle Valo 				     HAL_TX_PHY_DESC_INFO0_BANDWIDTH);
1893d8899132SKalle Valo 		break;
1894d8899132SKalle Valo 	}
1895d8899132SKalle Valo 
1896d8899132SKalle Valo 	case HAL_TX_MPDU_START: {
1897d8899132SKalle Valo 		struct dp_mon_mpdu *mon_mpdu = tx_ppdu_info->tx_mon_mpdu;
1898d8899132SKalle Valo 
1899d8899132SKalle Valo 		mon_mpdu = kzalloc(sizeof(*mon_mpdu), GFP_ATOMIC);
1900d8899132SKalle Valo 		if (!mon_mpdu)
1901d8899132SKalle Valo 			return DP_MON_TX_STATUS_PPDU_NOT_DONE;
1902d8899132SKalle Valo 		status = DP_MON_TX_MPDU_START;
1903d8899132SKalle Valo 		break;
1904d8899132SKalle Valo 	}
1905d8899132SKalle Valo 
1906d8899132SKalle Valo 	case HAL_MON_BUF_ADDR: {
1907d8899132SKalle Valo 		struct dp_rxdma_ring *buf_ring = &ab->dp.tx_mon_buf_ring;
1908d8899132SKalle Valo 		struct dp_mon_packet_info *packet_info =
1909d8899132SKalle Valo 			(struct dp_mon_packet_info *)tlv_data;
1910d8899132SKalle Valo 		int buf_id = u32_get_bits(packet_info->cookie,
1911d8899132SKalle Valo 					  DP_RXDMA_BUF_COOKIE_BUF_ID);
1912d8899132SKalle Valo 		struct sk_buff *msdu;
1913d8899132SKalle Valo 		struct dp_mon_mpdu *mon_mpdu = tx_ppdu_info->tx_mon_mpdu;
1914d8899132SKalle Valo 		struct ath12k_skb_rxcb *rxcb;
1915d8899132SKalle Valo 
1916d8899132SKalle Valo 		spin_lock_bh(&buf_ring->idr_lock);
1917d8899132SKalle Valo 		msdu = idr_remove(&buf_ring->bufs_idr, buf_id);
1918d8899132SKalle Valo 		spin_unlock_bh(&buf_ring->idr_lock);
1919d8899132SKalle Valo 
1920d8899132SKalle Valo 		if (unlikely(!msdu)) {
1921480c9df5SColin Ian King 			ath12k_warn(ab, "monitor destination with invalid buf_id %d\n",
1922d8899132SKalle Valo 				    buf_id);
1923d8899132SKalle Valo 			return DP_MON_TX_STATUS_PPDU_NOT_DONE;
1924d8899132SKalle Valo 		}
1925d8899132SKalle Valo 
1926d8899132SKalle Valo 		rxcb = ATH12K_SKB_RXCB(msdu);
1927d8899132SKalle Valo 		dma_unmap_single(ab->dev, rxcb->paddr,
1928d8899132SKalle Valo 				 msdu->len + skb_tailroom(msdu),
1929d8899132SKalle Valo 				 DMA_FROM_DEVICE);
1930d8899132SKalle Valo 
1931d8899132SKalle Valo 		if (!mon_mpdu->head)
1932d8899132SKalle Valo 			mon_mpdu->head = msdu;
1933d8899132SKalle Valo 		else if (mon_mpdu->tail)
1934d8899132SKalle Valo 			mon_mpdu->tail->next = msdu;
1935d8899132SKalle Valo 
1936d8899132SKalle Valo 		mon_mpdu->tail = msdu;
1937d8899132SKalle Valo 
1938d8899132SKalle Valo 		ath12k_dp_mon_buf_replenish(ab, buf_ring, 1);
1939d8899132SKalle Valo 		status = DP_MON_TX_BUFFER_ADDR;
1940d8899132SKalle Valo 		break;
1941d8899132SKalle Valo 	}
1942d8899132SKalle Valo 
1943d8899132SKalle Valo 	case HAL_TX_MPDU_END:
1944d8899132SKalle Valo 		list_add_tail(&tx_ppdu_info->tx_mon_mpdu->list,
1945d8899132SKalle Valo 			      &tx_ppdu_info->dp_tx_mon_mpdu_list);
1946d8899132SKalle Valo 		break;
1947d8899132SKalle Valo 	}
1948d8899132SKalle Valo 
1949d8899132SKalle Valo 	return status;
1950d8899132SKalle Valo }
1951d8899132SKalle Valo 
1952d8899132SKalle Valo enum dp_mon_tx_tlv_status
ath12k_dp_mon_tx_status_get_num_user(u16 tlv_tag,struct hal_tlv_hdr * tx_tlv,u8 * num_users)1953d8899132SKalle Valo ath12k_dp_mon_tx_status_get_num_user(u16 tlv_tag,
1954d8899132SKalle Valo 				     struct hal_tlv_hdr *tx_tlv,
1955d8899132SKalle Valo 				     u8 *num_users)
1956d8899132SKalle Valo {
1957d8899132SKalle Valo 	u32 tlv_status = DP_MON_TX_STATUS_PPDU_NOT_DONE;
1958d8899132SKalle Valo 	u32 info0;
1959d8899132SKalle Valo 
1960d8899132SKalle Valo 	switch (tlv_tag) {
1961d8899132SKalle Valo 	case HAL_TX_FES_SETUP: {
1962d8899132SKalle Valo 		struct hal_tx_fes_setup *tx_fes_setup =
1963d8899132SKalle Valo 				(struct hal_tx_fes_setup *)tx_tlv;
1964d8899132SKalle Valo 
1965d8899132SKalle Valo 		info0 = __le32_to_cpu(tx_fes_setup->info0);
1966d8899132SKalle Valo 
1967d8899132SKalle Valo 		*num_users = u32_get_bits(info0, HAL_TX_FES_SETUP_INFO0_NUM_OF_USERS);
1968d8899132SKalle Valo 		tlv_status = DP_MON_TX_FES_SETUP;
1969d8899132SKalle Valo 		break;
1970d8899132SKalle Valo 	}
1971d8899132SKalle Valo 
1972d8899132SKalle Valo 	case HAL_RX_RESPONSE_REQUIRED_INFO: {
1973d8899132SKalle Valo 		/* TODO: need to update *num_users */
1974d8899132SKalle Valo 		tlv_status = DP_MON_RX_RESPONSE_REQUIRED_INFO;
1975d8899132SKalle Valo 		break;
1976d8899132SKalle Valo 	}
1977d8899132SKalle Valo 	}
1978d8899132SKalle Valo 
1979d8899132SKalle Valo 	return tlv_status;
1980d8899132SKalle Valo }
1981d8899132SKalle Valo 
1982d8899132SKalle Valo static void
ath12k_dp_mon_tx_process_ppdu_info(struct ath12k * ar,int mac_id,struct napi_struct * napi,struct dp_mon_tx_ppdu_info * tx_ppdu_info)1983d8899132SKalle Valo ath12k_dp_mon_tx_process_ppdu_info(struct ath12k *ar, int mac_id,
1984d8899132SKalle Valo 				   struct napi_struct *napi,
1985d8899132SKalle Valo 				   struct dp_mon_tx_ppdu_info *tx_ppdu_info)
1986d8899132SKalle Valo {
1987d8899132SKalle Valo 	struct dp_mon_mpdu *tmp, *mon_mpdu;
1988d8899132SKalle Valo 	struct sk_buff *head_msdu;
1989d8899132SKalle Valo 
1990d8899132SKalle Valo 	list_for_each_entry_safe(mon_mpdu, tmp,
1991d8899132SKalle Valo 				 &tx_ppdu_info->dp_tx_mon_mpdu_list, list) {
1992d8899132SKalle Valo 		list_del(&mon_mpdu->list);
1993d8899132SKalle Valo 		head_msdu = mon_mpdu->head;
1994d8899132SKalle Valo 
1995d8899132SKalle Valo 		if (head_msdu)
1996d8899132SKalle Valo 			ath12k_dp_mon_rx_deliver(ar, mac_id, head_msdu,
1997d8899132SKalle Valo 						 &tx_ppdu_info->rx_status, napi);
1998d8899132SKalle Valo 
1999d8899132SKalle Valo 		kfree(mon_mpdu);
2000d8899132SKalle Valo 	}
2001d8899132SKalle Valo }
2002d8899132SKalle Valo 
2003d8899132SKalle Valo enum hal_rx_mon_status
ath12k_dp_mon_tx_parse_mon_status(struct ath12k * ar,struct ath12k_mon_data * pmon,int mac_id,struct sk_buff * skb,struct napi_struct * napi,u32 ppdu_id)2004d8899132SKalle Valo ath12k_dp_mon_tx_parse_mon_status(struct ath12k *ar,
2005d8899132SKalle Valo 				  struct ath12k_mon_data *pmon,
2006d8899132SKalle Valo 				  int mac_id,
2007d8899132SKalle Valo 				  struct sk_buff *skb,
2008d8899132SKalle Valo 				  struct napi_struct *napi,
2009d8899132SKalle Valo 				  u32 ppdu_id)
2010d8899132SKalle Valo {
2011d8899132SKalle Valo 	struct ath12k_base *ab = ar->ab;
2012d8899132SKalle Valo 	struct dp_mon_tx_ppdu_info *tx_prot_ppdu_info, *tx_data_ppdu_info;
2013d8899132SKalle Valo 	struct hal_tlv_hdr *tlv;
2014d8899132SKalle Valo 	u8 *ptr = skb->data;
2015d8899132SKalle Valo 	u16 tlv_tag;
2016d8899132SKalle Valo 	u16 tlv_len;
2017d8899132SKalle Valo 	u32 tlv_userid = 0;
2018d8899132SKalle Valo 	u8 num_user;
2019d8899132SKalle Valo 	u32 tlv_status = DP_MON_TX_STATUS_PPDU_NOT_DONE;
2020d8899132SKalle Valo 
2021d8899132SKalle Valo 	tx_prot_ppdu_info = ath12k_dp_mon_tx_get_ppdu_info(pmon, ppdu_id,
2022d8899132SKalle Valo 							   DP_MON_TX_PROT_PPDU_INFO);
2023d8899132SKalle Valo 	if (!tx_prot_ppdu_info)
2024d8899132SKalle Valo 		return -ENOMEM;
2025d8899132SKalle Valo 
2026d8899132SKalle Valo 	tlv = (struct hal_tlv_hdr *)ptr;
2027d8899132SKalle Valo 	tlv_tag = le32_get_bits(tlv->tl, HAL_TLV_HDR_TAG);
2028d8899132SKalle Valo 
2029d8899132SKalle Valo 	tlv_status = ath12k_dp_mon_tx_status_get_num_user(tlv_tag, tlv, &num_user);
2030d8899132SKalle Valo 	if (tlv_status == DP_MON_TX_STATUS_PPDU_NOT_DONE || !num_user)
2031d8899132SKalle Valo 		return -EINVAL;
2032d8899132SKalle Valo 
2033d8899132SKalle Valo 	tx_data_ppdu_info = ath12k_dp_mon_tx_get_ppdu_info(pmon, ppdu_id,
2034d8899132SKalle Valo 							   DP_MON_TX_DATA_PPDU_INFO);
2035d8899132SKalle Valo 	if (!tx_data_ppdu_info)
2036d8899132SKalle Valo 		return -ENOMEM;
2037d8899132SKalle Valo 
2038d8899132SKalle Valo 	do {
2039d8899132SKalle Valo 		tlv = (struct hal_tlv_hdr *)ptr;
2040d8899132SKalle Valo 		tlv_tag = le32_get_bits(tlv->tl, HAL_TLV_HDR_TAG);
2041d8899132SKalle Valo 		tlv_len = le32_get_bits(tlv->tl, HAL_TLV_HDR_LEN);
2042d8899132SKalle Valo 		tlv_userid = le32_get_bits(tlv->tl, HAL_TLV_USR_ID);
2043d8899132SKalle Valo 
2044d8899132SKalle Valo 		tlv_status = ath12k_dp_mon_tx_parse_status_tlv(ab, pmon,
2045d8899132SKalle Valo 							       tlv_tag, ptr,
2046d8899132SKalle Valo 							       tlv_userid);
2047d8899132SKalle Valo 		ptr += tlv_len;
2048d8899132SKalle Valo 		ptr = PTR_ALIGN(ptr, HAL_TLV_ALIGN);
2049d8899132SKalle Valo 		if ((ptr - skb->data) >= DP_TX_MONITOR_BUF_SIZE)
2050d8899132SKalle Valo 			break;
2051d8899132SKalle Valo 	} while (tlv_status != DP_MON_TX_FES_STATUS_END);
2052d8899132SKalle Valo 
2053d8899132SKalle Valo 	ath12k_dp_mon_tx_process_ppdu_info(ar, mac_id, napi, tx_data_ppdu_info);
2054d8899132SKalle Valo 	ath12k_dp_mon_tx_process_ppdu_info(ar, mac_id, napi, tx_prot_ppdu_info);
2055d8899132SKalle Valo 
2056d8899132SKalle Valo 	return tlv_status;
2057d8899132SKalle Valo }
2058d8899132SKalle Valo 
ath12k_dp_mon_srng_process(struct ath12k * ar,int mac_id,int * budget,enum dp_monitor_mode monitor_mode,struct napi_struct * napi)2059d8899132SKalle Valo int ath12k_dp_mon_srng_process(struct ath12k *ar, int mac_id, int *budget,
2060d8899132SKalle Valo 			       enum dp_monitor_mode monitor_mode,
2061d8899132SKalle Valo 			       struct napi_struct *napi)
2062d8899132SKalle Valo {
2063d8899132SKalle Valo 	struct hal_mon_dest_desc *mon_dst_desc;
2064d8899132SKalle Valo 	struct ath12k_pdev_dp *pdev_dp = &ar->dp;
2065d8899132SKalle Valo 	struct ath12k_mon_data *pmon = (struct ath12k_mon_data *)&pdev_dp->mon_data;
2066d8899132SKalle Valo 	struct ath12k_base *ab = ar->ab;
2067d8899132SKalle Valo 	struct ath12k_dp *dp = &ab->dp;
2068d8899132SKalle Valo 	struct sk_buff *skb;
2069d8899132SKalle Valo 	struct ath12k_skb_rxcb *rxcb;
2070d8899132SKalle Valo 	struct dp_srng *mon_dst_ring;
2071d8899132SKalle Valo 	struct hal_srng *srng;
2072d8899132SKalle Valo 	struct dp_rxdma_ring *buf_ring;
2073d8899132SKalle Valo 	u64 cookie;
2074d8899132SKalle Valo 	u32 ppdu_id;
2075d8899132SKalle Valo 	int num_buffs_reaped = 0, srng_id, buf_id;
2076d8899132SKalle Valo 	u8 dest_idx = 0, i;
2077d8899132SKalle Valo 	bool end_of_ppdu;
2078d8899132SKalle Valo 	struct hal_rx_mon_ppdu_info *ppdu_info;
2079d8899132SKalle Valo 	struct ath12k_peer *peer = NULL;
2080d8899132SKalle Valo 
2081d8899132SKalle Valo 	ppdu_info = &pmon->mon_ppdu_info;
2082d8899132SKalle Valo 	memset(ppdu_info, 0, sizeof(*ppdu_info));
2083d8899132SKalle Valo 	ppdu_info->peer_id = HAL_INVALID_PEERID;
2084d8899132SKalle Valo 
2085d8899132SKalle Valo 	srng_id = ath12k_hw_mac_id_to_srng_id(ab->hw_params, mac_id);
2086d8899132SKalle Valo 
2087d8899132SKalle Valo 	if (monitor_mode == ATH12K_DP_RX_MONITOR_MODE) {
2088d8899132SKalle Valo 		mon_dst_ring = &pdev_dp->rxdma_mon_dst_ring[srng_id];
2089d8899132SKalle Valo 		buf_ring = &dp->rxdma_mon_buf_ring;
2090d8899132SKalle Valo 	} else {
2091d8899132SKalle Valo 		mon_dst_ring = &pdev_dp->tx_mon_dst_ring[srng_id];
2092d8899132SKalle Valo 		buf_ring = &dp->tx_mon_buf_ring;
2093d8899132SKalle Valo 	}
2094d8899132SKalle Valo 
2095d8899132SKalle Valo 	srng = &ab->hal.srng_list[mon_dst_ring->ring_id];
2096d8899132SKalle Valo 
2097d8899132SKalle Valo 	spin_lock_bh(&srng->lock);
2098d8899132SKalle Valo 	ath12k_hal_srng_access_begin(ab, srng);
2099d8899132SKalle Valo 
2100d8899132SKalle Valo 	while (likely(*budget)) {
2101d8899132SKalle Valo 		*budget -= 1;
2102d8899132SKalle Valo 		mon_dst_desc = ath12k_hal_srng_dst_peek(ab, srng);
2103d8899132SKalle Valo 		if (unlikely(!mon_dst_desc))
2104d8899132SKalle Valo 			break;
2105d8899132SKalle Valo 
2106d8899132SKalle Valo 		cookie = le32_to_cpu(mon_dst_desc->cookie);
2107d8899132SKalle Valo 		buf_id = u32_get_bits(cookie, DP_RXDMA_BUF_COOKIE_BUF_ID);
2108d8899132SKalle Valo 
2109d8899132SKalle Valo 		spin_lock_bh(&buf_ring->idr_lock);
2110d8899132SKalle Valo 		skb = idr_remove(&buf_ring->bufs_idr, buf_id);
2111d8899132SKalle Valo 		spin_unlock_bh(&buf_ring->idr_lock);
2112d8899132SKalle Valo 
2113d8899132SKalle Valo 		if (unlikely(!skb)) {
2114480c9df5SColin Ian King 			ath12k_warn(ab, "monitor destination with invalid buf_id %d\n",
2115d8899132SKalle Valo 				    buf_id);
2116d8899132SKalle Valo 			goto move_next;
2117d8899132SKalle Valo 		}
2118d8899132SKalle Valo 
2119d8899132SKalle Valo 		rxcb = ATH12K_SKB_RXCB(skb);
2120d8899132SKalle Valo 		dma_unmap_single(ab->dev, rxcb->paddr,
2121d8899132SKalle Valo 				 skb->len + skb_tailroom(skb),
2122d8899132SKalle Valo 				 DMA_FROM_DEVICE);
2123d8899132SKalle Valo 
2124d8899132SKalle Valo 		pmon->dest_skb_q[dest_idx] = skb;
2125d8899132SKalle Valo 		dest_idx++;
2126d8899132SKalle Valo 		ppdu_id = le32_to_cpu(mon_dst_desc->ppdu_id);
2127d8899132SKalle Valo 		end_of_ppdu = le32_get_bits(mon_dst_desc->info0,
2128d8899132SKalle Valo 					    HAL_MON_DEST_INFO0_END_OF_PPDU);
2129d8899132SKalle Valo 		if (!end_of_ppdu)
2130d8899132SKalle Valo 			continue;
2131d8899132SKalle Valo 
2132d8899132SKalle Valo 		for (i = 0; i < dest_idx; i++) {
2133d8899132SKalle Valo 			skb = pmon->dest_skb_q[i];
2134d8899132SKalle Valo 
2135d8899132SKalle Valo 			if (monitor_mode == ATH12K_DP_RX_MONITOR_MODE)
2136d8899132SKalle Valo 				ath12k_dp_mon_rx_parse_mon_status(ar, pmon, mac_id,
2137d8899132SKalle Valo 								  skb, napi);
2138d8899132SKalle Valo 			else
2139d8899132SKalle Valo 				ath12k_dp_mon_tx_parse_mon_status(ar, pmon, mac_id,
2140d8899132SKalle Valo 								  skb, napi, ppdu_id);
2141d8899132SKalle Valo 
2142d8899132SKalle Valo 			peer = ath12k_peer_find_by_id(ab, ppdu_info->peer_id);
2143d8899132SKalle Valo 
2144d8899132SKalle Valo 			if (!peer || !peer->sta) {
2145d8899132SKalle Valo 				ath12k_dbg(ab, ATH12K_DBG_DATA,
2146d8899132SKalle Valo 					   "failed to find the peer with peer_id %d\n",
2147d8899132SKalle Valo 					   ppdu_info->peer_id);
2148d8899132SKalle Valo 				dev_kfree_skb_any(skb);
2149d8899132SKalle Valo 				continue;
2150d8899132SKalle Valo 			}
2151d8899132SKalle Valo 
2152d8899132SKalle Valo 			dev_kfree_skb_any(skb);
2153d8899132SKalle Valo 			pmon->dest_skb_q[i] = NULL;
2154d8899132SKalle Valo 		}
2155d8899132SKalle Valo 
2156d8899132SKalle Valo 		dest_idx = 0;
2157d8899132SKalle Valo move_next:
2158d8899132SKalle Valo 		ath12k_dp_mon_buf_replenish(ab, buf_ring, 1);
2159d8899132SKalle Valo 		ath12k_hal_srng_src_get_next_entry(ab, srng);
2160d8899132SKalle Valo 		num_buffs_reaped++;
2161d8899132SKalle Valo 	}
2162d8899132SKalle Valo 
2163d8899132SKalle Valo 	ath12k_hal_srng_access_end(ab, srng);
2164d8899132SKalle Valo 	spin_unlock_bh(&srng->lock);
2165d8899132SKalle Valo 
2166d8899132SKalle Valo 	return num_buffs_reaped;
2167d8899132SKalle Valo }
2168d8899132SKalle Valo 
2169d8899132SKalle Valo static void
ath12k_dp_mon_rx_update_peer_rate_table_stats(struct ath12k_rx_peer_stats * rx_stats,struct hal_rx_mon_ppdu_info * ppdu_info,struct hal_rx_user_status * user_stats,u32 num_msdu)2170d8899132SKalle Valo ath12k_dp_mon_rx_update_peer_rate_table_stats(struct ath12k_rx_peer_stats *rx_stats,
2171d8899132SKalle Valo 					      struct hal_rx_mon_ppdu_info *ppdu_info,
2172d8899132SKalle Valo 					      struct hal_rx_user_status *user_stats,
2173d8899132SKalle Valo 					      u32 num_msdu)
2174d8899132SKalle Valo {
2175d8899132SKalle Valo 	u32 rate_idx = 0;
2176d8899132SKalle Valo 	u32 mcs_idx = (user_stats) ? user_stats->mcs : ppdu_info->mcs;
2177d8899132SKalle Valo 	u32 nss_idx = (user_stats) ? user_stats->nss - 1 : ppdu_info->nss - 1;
2178d8899132SKalle Valo 	u32 bw_idx = ppdu_info->bw;
2179d8899132SKalle Valo 	u32 gi_idx = ppdu_info->gi;
2180d8899132SKalle Valo 
2181d8899132SKalle Valo 	if ((mcs_idx > HAL_RX_MAX_MCS_HE) || (nss_idx >= HAL_RX_MAX_NSS) ||
2182d8899132SKalle Valo 	    (bw_idx >= HAL_RX_BW_MAX) || (gi_idx >= HAL_RX_GI_MAX)) {
2183d8899132SKalle Valo 		return;
2184d8899132SKalle Valo 	}
2185d8899132SKalle Valo 
2186d8899132SKalle Valo 	if (ppdu_info->preamble_type == HAL_RX_PREAMBLE_11N ||
2187d8899132SKalle Valo 	    ppdu_info->preamble_type == HAL_RX_PREAMBLE_11AC) {
2188d8899132SKalle Valo 		rate_idx = mcs_idx * 8 + 8 * 10 * nss_idx;
2189d8899132SKalle Valo 		rate_idx += bw_idx * 2 + gi_idx;
2190d8899132SKalle Valo 	} else if (ppdu_info->preamble_type == HAL_RX_PREAMBLE_11AX) {
2191d8899132SKalle Valo 		gi_idx = ath12k_he_gi_to_nl80211_he_gi(ppdu_info->gi);
2192d8899132SKalle Valo 		rate_idx = mcs_idx * 12 + 12 * 12 * nss_idx;
2193d8899132SKalle Valo 		rate_idx += bw_idx * 3 + gi_idx;
2194d8899132SKalle Valo 	} else {
2195d8899132SKalle Valo 		return;
2196d8899132SKalle Valo 	}
2197d8899132SKalle Valo 
2198d8899132SKalle Valo 	rx_stats->pkt_stats.rx_rate[rate_idx] += num_msdu;
2199d8899132SKalle Valo 	if (user_stats)
2200d8899132SKalle Valo 		rx_stats->byte_stats.rx_rate[rate_idx] += user_stats->mpdu_ok_byte_count;
2201d8899132SKalle Valo 	else
2202d8899132SKalle Valo 		rx_stats->byte_stats.rx_rate[rate_idx] += ppdu_info->mpdu_len;
2203d8899132SKalle Valo }
2204d8899132SKalle Valo 
ath12k_dp_mon_rx_update_peer_su_stats(struct ath12k * ar,struct ath12k_sta * arsta,struct hal_rx_mon_ppdu_info * ppdu_info)2205d8899132SKalle Valo static void ath12k_dp_mon_rx_update_peer_su_stats(struct ath12k *ar,
2206d8899132SKalle Valo 						  struct ath12k_sta *arsta,
2207d8899132SKalle Valo 						  struct hal_rx_mon_ppdu_info *ppdu_info)
2208d8899132SKalle Valo {
2209d8899132SKalle Valo 	struct ath12k_rx_peer_stats *rx_stats = arsta->rx_stats;
2210d8899132SKalle Valo 	u32 num_msdu;
2211d8899132SKalle Valo 
2212d8899132SKalle Valo 	if (!rx_stats)
2213d8899132SKalle Valo 		return;
2214d8899132SKalle Valo 
2215d8899132SKalle Valo 	arsta->rssi_comb = ppdu_info->rssi_comb;
2216d8899132SKalle Valo 
2217d8899132SKalle Valo 	num_msdu = ppdu_info->tcp_msdu_count + ppdu_info->tcp_ack_msdu_count +
2218d8899132SKalle Valo 		   ppdu_info->udp_msdu_count + ppdu_info->other_msdu_count;
2219d8899132SKalle Valo 
2220d8899132SKalle Valo 	rx_stats->num_msdu += num_msdu;
2221d8899132SKalle Valo 	rx_stats->tcp_msdu_count += ppdu_info->tcp_msdu_count +
2222d8899132SKalle Valo 				    ppdu_info->tcp_ack_msdu_count;
2223d8899132SKalle Valo 	rx_stats->udp_msdu_count += ppdu_info->udp_msdu_count;
2224d8899132SKalle Valo 	rx_stats->other_msdu_count += ppdu_info->other_msdu_count;
2225d8899132SKalle Valo 
2226d8899132SKalle Valo 	if (ppdu_info->preamble_type == HAL_RX_PREAMBLE_11A ||
2227d8899132SKalle Valo 	    ppdu_info->preamble_type == HAL_RX_PREAMBLE_11B) {
2228d8899132SKalle Valo 		ppdu_info->nss = 1;
2229d8899132SKalle Valo 		ppdu_info->mcs = HAL_RX_MAX_MCS;
2230d8899132SKalle Valo 		ppdu_info->tid = IEEE80211_NUM_TIDS;
2231d8899132SKalle Valo 	}
2232d8899132SKalle Valo 
2233d8899132SKalle Valo 	if (ppdu_info->ldpc < HAL_RX_SU_MU_CODING_MAX)
2234d8899132SKalle Valo 		rx_stats->coding_count[ppdu_info->ldpc] += num_msdu;
2235d8899132SKalle Valo 
2236d8899132SKalle Valo 	if (ppdu_info->tid <= IEEE80211_NUM_TIDS)
2237d8899132SKalle Valo 		rx_stats->tid_count[ppdu_info->tid] += num_msdu;
2238d8899132SKalle Valo 
2239d8899132SKalle Valo 	if (ppdu_info->preamble_type < HAL_RX_PREAMBLE_MAX)
2240d8899132SKalle Valo 		rx_stats->pream_cnt[ppdu_info->preamble_type] += num_msdu;
2241d8899132SKalle Valo 
2242d8899132SKalle Valo 	if (ppdu_info->reception_type < HAL_RX_RECEPTION_TYPE_MAX)
2243d8899132SKalle Valo 		rx_stats->reception_type[ppdu_info->reception_type] += num_msdu;
2244d8899132SKalle Valo 
2245d8899132SKalle Valo 	if (ppdu_info->is_stbc)
2246d8899132SKalle Valo 		rx_stats->stbc_count += num_msdu;
2247d8899132SKalle Valo 
2248d8899132SKalle Valo 	if (ppdu_info->beamformed)
2249d8899132SKalle Valo 		rx_stats->beamformed_count += num_msdu;
2250d8899132SKalle Valo 
2251d8899132SKalle Valo 	if (ppdu_info->num_mpdu_fcs_ok > 1)
2252d8899132SKalle Valo 		rx_stats->ampdu_msdu_count += num_msdu;
2253d8899132SKalle Valo 	else
2254d8899132SKalle Valo 		rx_stats->non_ampdu_msdu_count += num_msdu;
2255d8899132SKalle Valo 
2256d8899132SKalle Valo 	rx_stats->num_mpdu_fcs_ok += ppdu_info->num_mpdu_fcs_ok;
2257d8899132SKalle Valo 	rx_stats->num_mpdu_fcs_err += ppdu_info->num_mpdu_fcs_err;
2258d8899132SKalle Valo 	rx_stats->dcm_count += ppdu_info->dcm;
2259d8899132SKalle Valo 
2260d8899132SKalle Valo 	rx_stats->rx_duration += ppdu_info->rx_duration;
2261d8899132SKalle Valo 	arsta->rx_duration = rx_stats->rx_duration;
2262d8899132SKalle Valo 
2263d8899132SKalle Valo 	if (ppdu_info->nss > 0 && ppdu_info->nss <= HAL_RX_MAX_NSS) {
2264d8899132SKalle Valo 		rx_stats->pkt_stats.nss_count[ppdu_info->nss - 1] += num_msdu;
2265d8899132SKalle Valo 		rx_stats->byte_stats.nss_count[ppdu_info->nss - 1] += ppdu_info->mpdu_len;
2266d8899132SKalle Valo 	}
2267d8899132SKalle Valo 
2268d8899132SKalle Valo 	if (ppdu_info->preamble_type == HAL_RX_PREAMBLE_11N &&
2269d8899132SKalle Valo 	    ppdu_info->mcs <= HAL_RX_MAX_MCS_HT) {
2270d8899132SKalle Valo 		rx_stats->pkt_stats.ht_mcs_count[ppdu_info->mcs] += num_msdu;
2271d8899132SKalle Valo 		rx_stats->byte_stats.ht_mcs_count[ppdu_info->mcs] += ppdu_info->mpdu_len;
2272d8899132SKalle Valo 		/* To fit into rate table for HT packets */
2273d8899132SKalle Valo 		ppdu_info->mcs = ppdu_info->mcs % 8;
2274d8899132SKalle Valo 	}
2275d8899132SKalle Valo 
2276d8899132SKalle Valo 	if (ppdu_info->preamble_type == HAL_RX_PREAMBLE_11AC &&
2277d8899132SKalle Valo 	    ppdu_info->mcs <= HAL_RX_MAX_MCS_VHT) {
2278d8899132SKalle Valo 		rx_stats->pkt_stats.vht_mcs_count[ppdu_info->mcs] += num_msdu;
2279d8899132SKalle Valo 		rx_stats->byte_stats.vht_mcs_count[ppdu_info->mcs] += ppdu_info->mpdu_len;
2280d8899132SKalle Valo 	}
2281d8899132SKalle Valo 
2282d8899132SKalle Valo 	if (ppdu_info->preamble_type == HAL_RX_PREAMBLE_11AX &&
2283d8899132SKalle Valo 	    ppdu_info->mcs <= HAL_RX_MAX_MCS_HE) {
2284d8899132SKalle Valo 		rx_stats->pkt_stats.he_mcs_count[ppdu_info->mcs] += num_msdu;
2285d8899132SKalle Valo 		rx_stats->byte_stats.he_mcs_count[ppdu_info->mcs] += ppdu_info->mpdu_len;
2286d8899132SKalle Valo 	}
2287d8899132SKalle Valo 
2288d8899132SKalle Valo 	if ((ppdu_info->preamble_type == HAL_RX_PREAMBLE_11A ||
2289d8899132SKalle Valo 	     ppdu_info->preamble_type == HAL_RX_PREAMBLE_11B) &&
2290d8899132SKalle Valo 	     ppdu_info->rate < HAL_RX_LEGACY_RATE_INVALID) {
2291d8899132SKalle Valo 		rx_stats->pkt_stats.legacy_count[ppdu_info->rate] += num_msdu;
2292d8899132SKalle Valo 		rx_stats->byte_stats.legacy_count[ppdu_info->rate] += ppdu_info->mpdu_len;
2293d8899132SKalle Valo 	}
2294d8899132SKalle Valo 
2295d8899132SKalle Valo 	if (ppdu_info->gi < HAL_RX_GI_MAX) {
2296d8899132SKalle Valo 		rx_stats->pkt_stats.gi_count[ppdu_info->gi] += num_msdu;
2297d8899132SKalle Valo 		rx_stats->byte_stats.gi_count[ppdu_info->gi] += ppdu_info->mpdu_len;
2298d8899132SKalle Valo 	}
2299d8899132SKalle Valo 
2300d8899132SKalle Valo 	if (ppdu_info->bw < HAL_RX_BW_MAX) {
2301d8899132SKalle Valo 		rx_stats->pkt_stats.bw_count[ppdu_info->bw] += num_msdu;
2302d8899132SKalle Valo 		rx_stats->byte_stats.bw_count[ppdu_info->bw] += ppdu_info->mpdu_len;
2303d8899132SKalle Valo 	}
2304d8899132SKalle Valo 
2305d8899132SKalle Valo 	ath12k_dp_mon_rx_update_peer_rate_table_stats(rx_stats, ppdu_info,
2306d8899132SKalle Valo 						      NULL, num_msdu);
2307d8899132SKalle Valo }
2308d8899132SKalle Valo 
ath12k_dp_mon_rx_process_ulofdma(struct hal_rx_mon_ppdu_info * ppdu_info)2309d8899132SKalle Valo void ath12k_dp_mon_rx_process_ulofdma(struct hal_rx_mon_ppdu_info *ppdu_info)
2310d8899132SKalle Valo {
2311d8899132SKalle Valo 	struct hal_rx_user_status *rx_user_status;
2312d8899132SKalle Valo 	u32 num_users, i, mu_ul_user_v0_word0, mu_ul_user_v0_word1, ru_size;
2313d8899132SKalle Valo 
2314d8899132SKalle Valo 	if (!(ppdu_info->reception_type == HAL_RX_RECEPTION_TYPE_MU_MIMO ||
2315d8899132SKalle Valo 	      ppdu_info->reception_type == HAL_RX_RECEPTION_TYPE_MU_OFDMA ||
2316d8899132SKalle Valo 	      ppdu_info->reception_type == HAL_RX_RECEPTION_TYPE_MU_OFDMA_MIMO))
2317d8899132SKalle Valo 		return;
2318d8899132SKalle Valo 
2319d8899132SKalle Valo 	num_users = ppdu_info->num_users;
2320d8899132SKalle Valo 	if (num_users > HAL_MAX_UL_MU_USERS)
2321d8899132SKalle Valo 		num_users = HAL_MAX_UL_MU_USERS;
2322d8899132SKalle Valo 
2323d8899132SKalle Valo 	for (i = 0; i < num_users; i++) {
2324d8899132SKalle Valo 		rx_user_status = &ppdu_info->userstats[i];
2325d8899132SKalle Valo 		mu_ul_user_v0_word0 =
2326d8899132SKalle Valo 			rx_user_status->ul_ofdma_user_v0_word0;
2327d8899132SKalle Valo 		mu_ul_user_v0_word1 =
2328d8899132SKalle Valo 			rx_user_status->ul_ofdma_user_v0_word1;
2329d8899132SKalle Valo 
2330d8899132SKalle Valo 		if (u32_get_bits(mu_ul_user_v0_word0,
2331d8899132SKalle Valo 				 HAL_RX_UL_OFDMA_USER_INFO_V0_W0_VALID) &&
2332d8899132SKalle Valo 		    !u32_get_bits(mu_ul_user_v0_word0,
2333d8899132SKalle Valo 				  HAL_RX_UL_OFDMA_USER_INFO_V0_W0_VER)) {
2334d8899132SKalle Valo 			rx_user_status->mcs =
2335d8899132SKalle Valo 				u32_get_bits(mu_ul_user_v0_word1,
2336d8899132SKalle Valo 					     HAL_RX_UL_OFDMA_USER_INFO_V0_W1_MCS);
2337d8899132SKalle Valo 			rx_user_status->nss =
2338d8899132SKalle Valo 				u32_get_bits(mu_ul_user_v0_word1,
2339d8899132SKalle Valo 					     HAL_RX_UL_OFDMA_USER_INFO_V0_W1_NSS) + 1;
2340d8899132SKalle Valo 
2341d8899132SKalle Valo 			rx_user_status->ofdma_info_valid = 1;
2342d8899132SKalle Valo 			rx_user_status->ul_ofdma_ru_start_index =
2343d8899132SKalle Valo 				u32_get_bits(mu_ul_user_v0_word1,
2344d8899132SKalle Valo 					     HAL_RX_UL_OFDMA_USER_INFO_V0_W1_RU_START);
2345d8899132SKalle Valo 
2346d8899132SKalle Valo 			ru_size = u32_get_bits(mu_ul_user_v0_word1,
2347d8899132SKalle Valo 					       HAL_RX_UL_OFDMA_USER_INFO_V0_W1_RU_SIZE);
2348d8899132SKalle Valo 			rx_user_status->ul_ofdma_ru_width = ru_size;
2349d8899132SKalle Valo 			rx_user_status->ul_ofdma_ru_size = ru_size;
2350d8899132SKalle Valo 		}
2351d8899132SKalle Valo 		rx_user_status->ldpc = u32_get_bits(mu_ul_user_v0_word1,
2352d8899132SKalle Valo 						    HAL_RX_UL_OFDMA_USER_INFO_V0_W1_LDPC);
2353d8899132SKalle Valo 	}
2354d8899132SKalle Valo 	ppdu_info->ldpc = 1;
2355d8899132SKalle Valo }
2356d8899132SKalle Valo 
2357d8899132SKalle Valo static void
ath12k_dp_mon_rx_update_user_stats(struct ath12k * ar,struct hal_rx_mon_ppdu_info * ppdu_info,u32 uid)2358d8899132SKalle Valo ath12k_dp_mon_rx_update_user_stats(struct ath12k *ar,
2359d8899132SKalle Valo 				   struct hal_rx_mon_ppdu_info *ppdu_info,
2360d8899132SKalle Valo 				   u32 uid)
2361d8899132SKalle Valo {
2362d8899132SKalle Valo 	struct ath12k_sta *arsta = NULL;
2363d8899132SKalle Valo 	struct ath12k_rx_peer_stats *rx_stats = NULL;
2364d8899132SKalle Valo 	struct hal_rx_user_status *user_stats = &ppdu_info->userstats[uid];
2365d8899132SKalle Valo 	struct ath12k_peer *peer;
2366d8899132SKalle Valo 	u32 num_msdu;
2367d8899132SKalle Valo 
2368d8899132SKalle Valo 	if (user_stats->ast_index == 0 || user_stats->ast_index == 0xFFFF)
2369d8899132SKalle Valo 		return;
2370d8899132SKalle Valo 
2371d8899132SKalle Valo 	peer = ath12k_peer_find_by_ast(ar->ab, user_stats->ast_index);
2372d8899132SKalle Valo 
2373d8899132SKalle Valo 	if (!peer) {
2374d8899132SKalle Valo 		ath12k_warn(ar->ab, "peer ast idx %d can't be found\n",
2375d8899132SKalle Valo 			    user_stats->ast_index);
2376d8899132SKalle Valo 		return;
2377d8899132SKalle Valo 	}
2378d8899132SKalle Valo 
2379d8899132SKalle Valo 	arsta = (struct ath12k_sta *)peer->sta->drv_priv;
2380d8899132SKalle Valo 	rx_stats = arsta->rx_stats;
2381d8899132SKalle Valo 
2382d8899132SKalle Valo 	if (!rx_stats)
2383d8899132SKalle Valo 		return;
2384d8899132SKalle Valo 
2385d8899132SKalle Valo 	arsta->rssi_comb = ppdu_info->rssi_comb;
2386d8899132SKalle Valo 
2387d8899132SKalle Valo 	num_msdu = user_stats->tcp_msdu_count + user_stats->tcp_ack_msdu_count +
2388d8899132SKalle Valo 		   user_stats->udp_msdu_count + user_stats->other_msdu_count;
2389d8899132SKalle Valo 
2390d8899132SKalle Valo 	rx_stats->num_msdu += num_msdu;
2391d8899132SKalle Valo 	rx_stats->tcp_msdu_count += user_stats->tcp_msdu_count +
2392d8899132SKalle Valo 				    user_stats->tcp_ack_msdu_count;
2393d8899132SKalle Valo 	rx_stats->udp_msdu_count += user_stats->udp_msdu_count;
2394d8899132SKalle Valo 	rx_stats->other_msdu_count += user_stats->other_msdu_count;
2395d8899132SKalle Valo 
2396d8899132SKalle Valo 	if (ppdu_info->ldpc < HAL_RX_SU_MU_CODING_MAX)
2397d8899132SKalle Valo 		rx_stats->coding_count[ppdu_info->ldpc] += num_msdu;
2398d8899132SKalle Valo 
2399d8899132SKalle Valo 	if (user_stats->tid <= IEEE80211_NUM_TIDS)
2400d8899132SKalle Valo 		rx_stats->tid_count[user_stats->tid] += num_msdu;
2401d8899132SKalle Valo 
2402d8899132SKalle Valo 	if (user_stats->preamble_type < HAL_RX_PREAMBLE_MAX)
2403d8899132SKalle Valo 		rx_stats->pream_cnt[user_stats->preamble_type] += num_msdu;
2404d8899132SKalle Valo 
2405d8899132SKalle Valo 	if (ppdu_info->reception_type < HAL_RX_RECEPTION_TYPE_MAX)
2406d8899132SKalle Valo 		rx_stats->reception_type[ppdu_info->reception_type] += num_msdu;
2407d8899132SKalle Valo 
2408d8899132SKalle Valo 	if (ppdu_info->is_stbc)
2409d8899132SKalle Valo 		rx_stats->stbc_count += num_msdu;
2410d8899132SKalle Valo 
2411d8899132SKalle Valo 	if (ppdu_info->beamformed)
2412d8899132SKalle Valo 		rx_stats->beamformed_count += num_msdu;
2413d8899132SKalle Valo 
2414d8899132SKalle Valo 	if (user_stats->mpdu_cnt_fcs_ok > 1)
2415d8899132SKalle Valo 		rx_stats->ampdu_msdu_count += num_msdu;
2416d8899132SKalle Valo 	else
2417d8899132SKalle Valo 		rx_stats->non_ampdu_msdu_count += num_msdu;
2418d8899132SKalle Valo 
2419d8899132SKalle Valo 	rx_stats->num_mpdu_fcs_ok += user_stats->mpdu_cnt_fcs_ok;
2420d8899132SKalle Valo 	rx_stats->num_mpdu_fcs_err += user_stats->mpdu_cnt_fcs_err;
2421d8899132SKalle Valo 	rx_stats->dcm_count += ppdu_info->dcm;
2422d8899132SKalle Valo 	if (ppdu_info->reception_type == HAL_RX_RECEPTION_TYPE_MU_OFDMA ||
2423d8899132SKalle Valo 	    ppdu_info->reception_type == HAL_RX_RECEPTION_TYPE_MU_OFDMA_MIMO)
2424d8899132SKalle Valo 		rx_stats->ru_alloc_cnt[user_stats->ul_ofdma_ru_size] += num_msdu;
2425d8899132SKalle Valo 
2426d8899132SKalle Valo 	rx_stats->rx_duration += ppdu_info->rx_duration;
2427d8899132SKalle Valo 	arsta->rx_duration = rx_stats->rx_duration;
2428d8899132SKalle Valo 
2429d8899132SKalle Valo 	if (user_stats->nss > 0 && user_stats->nss <= HAL_RX_MAX_NSS) {
2430d8899132SKalle Valo 		rx_stats->pkt_stats.nss_count[user_stats->nss - 1] += num_msdu;
2431d8899132SKalle Valo 		rx_stats->byte_stats.nss_count[user_stats->nss - 1] +=
2432d8899132SKalle Valo 						user_stats->mpdu_ok_byte_count;
2433d8899132SKalle Valo 	}
2434d8899132SKalle Valo 
2435d8899132SKalle Valo 	if (user_stats->preamble_type == HAL_RX_PREAMBLE_11AX &&
2436d8899132SKalle Valo 	    user_stats->mcs <= HAL_RX_MAX_MCS_HE) {
2437d8899132SKalle Valo 		rx_stats->pkt_stats.he_mcs_count[user_stats->mcs] += num_msdu;
2438d8899132SKalle Valo 		rx_stats->byte_stats.he_mcs_count[user_stats->mcs] +=
2439d8899132SKalle Valo 						user_stats->mpdu_ok_byte_count;
2440d8899132SKalle Valo 	}
2441d8899132SKalle Valo 
2442d8899132SKalle Valo 	if (ppdu_info->gi < HAL_RX_GI_MAX) {
2443d8899132SKalle Valo 		rx_stats->pkt_stats.gi_count[ppdu_info->gi] += num_msdu;
2444d8899132SKalle Valo 		rx_stats->byte_stats.gi_count[ppdu_info->gi] +=
2445d8899132SKalle Valo 						user_stats->mpdu_ok_byte_count;
2446d8899132SKalle Valo 	}
2447d8899132SKalle Valo 
2448d8899132SKalle Valo 	if (ppdu_info->bw < HAL_RX_BW_MAX) {
2449d8899132SKalle Valo 		rx_stats->pkt_stats.bw_count[ppdu_info->bw] += num_msdu;
2450d8899132SKalle Valo 		rx_stats->byte_stats.bw_count[ppdu_info->bw] +=
2451d8899132SKalle Valo 						user_stats->mpdu_ok_byte_count;
2452d8899132SKalle Valo 	}
2453d8899132SKalle Valo 
2454d8899132SKalle Valo 	ath12k_dp_mon_rx_update_peer_rate_table_stats(rx_stats, ppdu_info,
2455d8899132SKalle Valo 						      user_stats, num_msdu);
2456d8899132SKalle Valo }
2457d8899132SKalle Valo 
2458d8899132SKalle Valo static void
ath12k_dp_mon_rx_update_peer_mu_stats(struct ath12k * ar,struct hal_rx_mon_ppdu_info * ppdu_info)2459d8899132SKalle Valo ath12k_dp_mon_rx_update_peer_mu_stats(struct ath12k *ar,
2460d8899132SKalle Valo 				      struct hal_rx_mon_ppdu_info *ppdu_info)
2461d8899132SKalle Valo {
2462d8899132SKalle Valo 	u32 num_users, i;
2463d8899132SKalle Valo 
2464d8899132SKalle Valo 	num_users = ppdu_info->num_users;
2465d8899132SKalle Valo 	if (num_users > HAL_MAX_UL_MU_USERS)
2466d8899132SKalle Valo 		num_users = HAL_MAX_UL_MU_USERS;
2467d8899132SKalle Valo 
2468d8899132SKalle Valo 	for (i = 0; i < num_users; i++)
2469d8899132SKalle Valo 		ath12k_dp_mon_rx_update_user_stats(ar, ppdu_info, i);
2470d8899132SKalle Valo }
2471d8899132SKalle Valo 
ath12k_dp_mon_rx_process_stats(struct ath12k * ar,int mac_id,struct napi_struct * napi,int * budget)2472d8899132SKalle Valo int ath12k_dp_mon_rx_process_stats(struct ath12k *ar, int mac_id,
2473d8899132SKalle Valo 				   struct napi_struct *napi, int *budget)
2474d8899132SKalle Valo {
2475d8899132SKalle Valo 	struct ath12k_base *ab = ar->ab;
2476d8899132SKalle Valo 	struct ath12k_pdev_dp *pdev_dp = &ar->dp;
2477d8899132SKalle Valo 	struct ath12k_mon_data *pmon = (struct ath12k_mon_data *)&pdev_dp->mon_data;
2478d8899132SKalle Valo 	struct hal_rx_mon_ppdu_info *ppdu_info = &pmon->mon_ppdu_info;
2479d8899132SKalle Valo 	struct ath12k_dp *dp = &ab->dp;
2480d8899132SKalle Valo 	struct hal_mon_dest_desc *mon_dst_desc;
2481d8899132SKalle Valo 	struct sk_buff *skb;
2482d8899132SKalle Valo 	struct ath12k_skb_rxcb *rxcb;
2483d8899132SKalle Valo 	struct dp_srng *mon_dst_ring;
2484d8899132SKalle Valo 	struct hal_srng *srng;
2485d8899132SKalle Valo 	struct dp_rxdma_ring *buf_ring;
2486d8899132SKalle Valo 	struct ath12k_sta *arsta = NULL;
2487d8899132SKalle Valo 	struct ath12k_peer *peer;
2488d8899132SKalle Valo 	u64 cookie;
2489d8899132SKalle Valo 	int num_buffs_reaped = 0, srng_id, buf_id;
2490d8899132SKalle Valo 	u8 dest_idx = 0, i;
2491d8899132SKalle Valo 	bool end_of_ppdu;
2492d8899132SKalle Valo 	u32 hal_status;
2493d8899132SKalle Valo 
2494d8899132SKalle Valo 	srng_id = ath12k_hw_mac_id_to_srng_id(ab->hw_params, mac_id);
2495d8899132SKalle Valo 	mon_dst_ring = &pdev_dp->rxdma_mon_dst_ring[srng_id];
2496d8899132SKalle Valo 	buf_ring = &dp->rxdma_mon_buf_ring;
2497d8899132SKalle Valo 
2498d8899132SKalle Valo 	srng = &ab->hal.srng_list[mon_dst_ring->ring_id];
2499d8899132SKalle Valo 	spin_lock_bh(&srng->lock);
2500d8899132SKalle Valo 	ath12k_hal_srng_access_begin(ab, srng);
2501d8899132SKalle Valo 
2502d8899132SKalle Valo 	while (likely(*budget)) {
2503d8899132SKalle Valo 		*budget -= 1;
2504d8899132SKalle Valo 		mon_dst_desc = ath12k_hal_srng_dst_peek(ab, srng);
2505d8899132SKalle Valo 		if (unlikely(!mon_dst_desc))
2506d8899132SKalle Valo 			break;
2507d8899132SKalle Valo 		cookie = le32_to_cpu(mon_dst_desc->cookie);
2508d8899132SKalle Valo 		buf_id = u32_get_bits(cookie, DP_RXDMA_BUF_COOKIE_BUF_ID);
2509d8899132SKalle Valo 
2510d8899132SKalle Valo 		spin_lock_bh(&buf_ring->idr_lock);
2511d8899132SKalle Valo 		skb = idr_remove(&buf_ring->bufs_idr, buf_id);
2512d8899132SKalle Valo 		spin_unlock_bh(&buf_ring->idr_lock);
2513d8899132SKalle Valo 
2514d8899132SKalle Valo 		if (unlikely(!skb)) {
2515480c9df5SColin Ian King 			ath12k_warn(ab, "monitor destination with invalid buf_id %d\n",
2516d8899132SKalle Valo 				    buf_id);
2517d8899132SKalle Valo 			goto move_next;
2518d8899132SKalle Valo 		}
2519d8899132SKalle Valo 
2520d8899132SKalle Valo 		rxcb = ATH12K_SKB_RXCB(skb);
2521d8899132SKalle Valo 		dma_unmap_single(ab->dev, rxcb->paddr,
2522d8899132SKalle Valo 				 skb->len + skb_tailroom(skb),
2523d8899132SKalle Valo 				 DMA_FROM_DEVICE);
2524d8899132SKalle Valo 		pmon->dest_skb_q[dest_idx] = skb;
2525d8899132SKalle Valo 		dest_idx++;
2526d8899132SKalle Valo 		end_of_ppdu = le32_get_bits(mon_dst_desc->info0,
2527d8899132SKalle Valo 					    HAL_MON_DEST_INFO0_END_OF_PPDU);
2528d8899132SKalle Valo 		if (!end_of_ppdu)
2529d8899132SKalle Valo 			continue;
2530d8899132SKalle Valo 
2531d8899132SKalle Valo 		for (i = 0; i < dest_idx; i++) {
2532d8899132SKalle Valo 			skb = pmon->dest_skb_q[i];
2533d8899132SKalle Valo 			hal_status = ath12k_dp_mon_parse_rx_dest(ab, pmon, skb);
2534d8899132SKalle Valo 
2535d8899132SKalle Valo 			if (ppdu_info->peer_id == HAL_INVALID_PEERID ||
2536d8899132SKalle Valo 			    hal_status != HAL_RX_MON_STATUS_PPDU_DONE) {
2537d8899132SKalle Valo 				dev_kfree_skb_any(skb);
2538d8899132SKalle Valo 				continue;
2539d8899132SKalle Valo 			}
2540d8899132SKalle Valo 
2541d8899132SKalle Valo 			rcu_read_lock();
2542d8899132SKalle Valo 			spin_lock_bh(&ab->base_lock);
2543d8899132SKalle Valo 			peer = ath12k_peer_find_by_id(ab, ppdu_info->peer_id);
2544d8899132SKalle Valo 			if (!peer || !peer->sta) {
2545d8899132SKalle Valo 				ath12k_dbg(ab, ATH12K_DBG_DATA,
2546d8899132SKalle Valo 					   "failed to find the peer with peer_id %d\n",
2547d8899132SKalle Valo 					   ppdu_info->peer_id);
2548d8899132SKalle Valo 				spin_unlock_bh(&ab->base_lock);
2549d8899132SKalle Valo 				rcu_read_unlock();
2550d8899132SKalle Valo 				dev_kfree_skb_any(skb);
2551d8899132SKalle Valo 				continue;
2552d8899132SKalle Valo 			}
2553d8899132SKalle Valo 
2554d8899132SKalle Valo 			if (ppdu_info->reception_type == HAL_RX_RECEPTION_TYPE_SU) {
2555d8899132SKalle Valo 				arsta = (struct ath12k_sta *)peer->sta->drv_priv;
2556d8899132SKalle Valo 				ath12k_dp_mon_rx_update_peer_su_stats(ar, arsta,
2557d8899132SKalle Valo 								      ppdu_info);
2558d8899132SKalle Valo 			} else if ((ppdu_info->fc_valid) &&
2559d8899132SKalle Valo 				   (ppdu_info->ast_index != HAL_AST_IDX_INVALID)) {
2560d8899132SKalle Valo 				ath12k_dp_mon_rx_process_ulofdma(ppdu_info);
2561d8899132SKalle Valo 				ath12k_dp_mon_rx_update_peer_mu_stats(ar, ppdu_info);
2562d8899132SKalle Valo 			}
2563d8899132SKalle Valo 
2564d8899132SKalle Valo 			spin_unlock_bh(&ab->base_lock);
2565d8899132SKalle Valo 			rcu_read_unlock();
2566d8899132SKalle Valo 			dev_kfree_skb_any(skb);
2567d8899132SKalle Valo 			memset(ppdu_info, 0, sizeof(*ppdu_info));
2568d8899132SKalle Valo 			ppdu_info->peer_id = HAL_INVALID_PEERID;
2569d8899132SKalle Valo 		}
2570d8899132SKalle Valo 
2571d8899132SKalle Valo 		dest_idx = 0;
2572d8899132SKalle Valo move_next:
2573d8899132SKalle Valo 		ath12k_dp_mon_buf_replenish(ab, buf_ring, 1);
2574d8899132SKalle Valo 		ath12k_hal_srng_src_get_next_entry(ab, srng);
2575d8899132SKalle Valo 		num_buffs_reaped++;
2576d8899132SKalle Valo 	}
2577d8899132SKalle Valo 
2578d8899132SKalle Valo 	ath12k_hal_srng_access_end(ab, srng);
2579d8899132SKalle Valo 	spin_unlock_bh(&srng->lock);
2580d8899132SKalle Valo 	return num_buffs_reaped;
2581d8899132SKalle Valo }
2582d8899132SKalle Valo 
ath12k_dp_mon_process_ring(struct ath12k_base * ab,int mac_id,struct napi_struct * napi,int budget,enum dp_monitor_mode monitor_mode)2583d8899132SKalle Valo int ath12k_dp_mon_process_ring(struct ath12k_base *ab, int mac_id,
2584d8899132SKalle Valo 			       struct napi_struct *napi, int budget,
2585d8899132SKalle Valo 			       enum dp_monitor_mode monitor_mode)
2586d8899132SKalle Valo {
2587d8899132SKalle Valo 	struct ath12k *ar = ath12k_ab_to_ar(ab, mac_id);
2588d8899132SKalle Valo 	int num_buffs_reaped = 0;
2589d8899132SKalle Valo 
2590d8899132SKalle Valo 	if (!ar->monitor_started)
2591d8899132SKalle Valo 		ath12k_dp_mon_rx_process_stats(ar, mac_id, napi, &budget);
2592d8899132SKalle Valo 	else
2593d8899132SKalle Valo 		num_buffs_reaped = ath12k_dp_mon_srng_process(ar, mac_id, &budget,
2594d8899132SKalle Valo 							      monitor_mode, napi);
2595d8899132SKalle Valo 
2596d8899132SKalle Valo 	return num_buffs_reaped;
2597d8899132SKalle Valo }
2598