xref: /wlan-dirver/qca-wifi-host-cmn/hal/wifi3.0/qca8074v1/hal_8074v1_rx.h (revision 302a1d9701784af5f4797b1a9fe07ae820b51907)
1 /*
2  * Copyright (c) 2016-2018 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 #include "hal_hw_headers.h"
19 #include "hal_internal.h"
20 #include "cdp_txrx_mon_struct.h"
21 #include "qdf_trace.h"
22 #include "hal_rx.h"
23 #include "hal_tx.h"
24 #include "dp_types.h"
25 #include "hal_api_mon.h"
26 
27 /*
28  * hal_rx_msdu_start_nss_get_8074(): API to get the NSS
29  * Interval from rx_msdu_start
30  *
31  * @buf: pointer to the start of RX PKT TLV header
32  * Return: uint32_t(nss)
33  */
34 static uint32_t
35 hal_rx_msdu_start_nss_get_8074(uint8_t *buf)
36 {
37 	struct rx_pkt_tlvs *pkt_tlvs = (struct rx_pkt_tlvs *)buf;
38 	struct rx_msdu_start *msdu_start =
39 			&pkt_tlvs->msdu_start_tlv.rx_msdu_start;
40 	uint32_t nss;
41 
42 	nss = HAL_RX_MSDU_START_NSS_GET(msdu_start);
43 	return nss;
44 }
45 
46 /**
47  * hal_rx_mon_hw_desc_get_mpdu_status_8074(): Retrieve MPDU status
48  *
49  * @ hw_desc_addr: Start address of Rx HW TLVs
50  * @ rs: Status for monitor mode
51  *
52  * Return: void
53  */
54 static void hal_rx_mon_hw_desc_get_mpdu_status_8074(void *hw_desc_addr,
55 						    struct mon_rx_status *rs)
56 {
57 	struct rx_msdu_start *rx_msdu_start;
58 	struct rx_pkt_tlvs *rx_desc = (struct rx_pkt_tlvs *)hw_desc_addr;
59 	uint32_t reg_value;
60 	const uint32_t sgi_hw_to_cdp[] = {
61 		CDP_SGI_0_8_US,
62 		CDP_SGI_0_4_US,
63 		CDP_SGI_1_6_US,
64 		CDP_SGI_3_2_US,
65 	};
66 
67 	rx_msdu_start = &rx_desc->msdu_start_tlv.rx_msdu_start;
68 
69 	HAL_RX_GET_MSDU_AGGREGATION(rx_desc, rs);
70 
71 	rs->ant_signal_db = HAL_RX_GET(rx_msdu_start,
72 				RX_MSDU_START_5, USER_RSSI);
73 	rs->is_stbc = HAL_RX_GET(rx_msdu_start, RX_MSDU_START_5, STBC);
74 
75 	reg_value = HAL_RX_GET(rx_msdu_start, RX_MSDU_START_5, SGI);
76 	rs->sgi = sgi_hw_to_cdp[reg_value];
77 	rs->nr_ant = HAL_RX_GET(rx_msdu_start, RX_MSDU_START_5, NSS);
78 	reg_value = HAL_RX_GET(rx_msdu_start, RX_MSDU_START_5, PKT_TYPE);
79 	switch (reg_value) {
80 	case HAL_RX_PKT_TYPE_11N:
81 		rs->ht_flags = 1;
82 		break;
83 	case HAL_RX_PKT_TYPE_11AC:
84 		rs->vht_flags = 1;
85 		reg_value = HAL_RX_GET(rx_msdu_start, RX_MSDU_START_5,
86 				       RECEIVE_BANDWIDTH);
87 		rs->vht_flag_values2 = reg_value;
88 		break;
89 	case HAL_RX_PKT_TYPE_11AX:
90 		rs->he_flags = 1;
91 		break;
92 	default:
93 		break;
94 	}
95 	reg_value = HAL_RX_GET(rx_msdu_start, RX_MSDU_START_5, RECEPTION_TYPE);
96 	rs->beamformed = (reg_value == HAL_RX_RECEPTION_TYPE_MU_MIMO) ? 1 : 0;
97 	/* TODO: rs->beamformed should be set for SU beamforming also */
98 }
99 
100 #define LINK_DESC_SIZE (NUM_OF_DWORDS_RX_MSDU_LINK << 2)
101 static uint32_t hal_get_link_desc_size_8074(void)
102 {
103 	return LINK_DESC_SIZE;
104 }
105 
106 /*
107  * hal_rx_get_tlv_8074(): API to get the tlv
108  *
109  * @rx_tlv: TLV data extracted from the rx packet
110  * Return: uint8_t
111  */
112 static uint8_t hal_rx_get_tlv_8074(void *rx_tlv)
113 {
114 	return HAL_RX_GET(rx_tlv, PHYRX_RSSI_LEGACY_35, RECEIVE_BANDWIDTH);
115 }
116 
117 /**
118  * hal_rx_proc_phyrx_other_receive_info_tlv_8074()
119  *				      -process other receive info TLV
120  * @rx_tlv_hdr: pointer to TLV header
121  * @ppdu_info: pointer to ppdu_info
122  *
123  * Return: None
124  */
125 static
126 void hal_rx_proc_phyrx_other_receive_info_tlv_8074(void *rx_tlv_hdr,
127 						   void *ppdu_info)
128 {
129 }
130 
131 
132 /**
133  * hal_rx_dump_msdu_start_tlv_8074() : dump RX msdu_start TLV in structured
134  *			     human readable format.
135  * @ msdu_start: pointer the msdu_start TLV in pkt.
136  * @ dbg_level: log level.
137  *
138  * Return: void
139  */
140 static void hal_rx_dump_msdu_start_tlv_8074(void *msdustart,
141 					    uint8_t dbg_level)
142 {
143 	struct rx_msdu_start *msdu_start = (struct rx_msdu_start *)msdustart;
144 
145 	QDF_TRACE(QDF_MODULE_ID_DP, dbg_level,
146 			"rx_msdu_start tlv - "
147 			"rxpcu_mpdu_filter_in_category: %d "
148 			"sw_frame_group_id: %d "
149 			"phy_ppdu_id: %d "
150 			"msdu_length: %d "
151 			"ipsec_esp: %d "
152 			"l3_offset: %d "
153 			"ipsec_ah: %d "
154 			"l4_offset: %d "
155 			"msdu_number: %d "
156 			"decap_format: %d "
157 			"ipv4_proto: %d "
158 			"ipv6_proto: %d "
159 			"tcp_proto: %d "
160 			"udp_proto: %d "
161 			"ip_frag: %d "
162 			"tcp_only_ack: %d "
163 			"da_is_bcast_mcast: %d "
164 			"ip4_protocol_ip6_next_header: %d "
165 			"toeplitz_hash_2_or_4: %d "
166 			"flow_id_toeplitz: %d "
167 			"user_rssi: %d "
168 			"pkt_type: %d "
169 			"stbc: %d "
170 			"sgi: %d "
171 			"rate_mcs: %d "
172 			"receive_bandwidth: %d "
173 			"reception_type: %d "
174 			"toeplitz_hash: %d "
175 			"nss: %d "
176 			"ppdu_start_timestamp: %d "
177 			"sw_phy_meta_data: %d ",
178 			msdu_start->rxpcu_mpdu_filter_in_category,
179 			msdu_start->sw_frame_group_id,
180 			msdu_start->phy_ppdu_id,
181 			msdu_start->msdu_length,
182 			msdu_start->ipsec_esp,
183 			msdu_start->l3_offset,
184 			msdu_start->ipsec_ah,
185 			msdu_start->l4_offset,
186 			msdu_start->msdu_number,
187 			msdu_start->decap_format,
188 			msdu_start->ipv4_proto,
189 			msdu_start->ipv6_proto,
190 			msdu_start->tcp_proto,
191 			msdu_start->udp_proto,
192 			msdu_start->ip_frag,
193 			msdu_start->tcp_only_ack,
194 			msdu_start->da_is_bcast_mcast,
195 			msdu_start->ip4_protocol_ip6_next_header,
196 			msdu_start->toeplitz_hash_2_or_4,
197 			msdu_start->flow_id_toeplitz,
198 			msdu_start->user_rssi,
199 			msdu_start->pkt_type,
200 			msdu_start->stbc,
201 			msdu_start->sgi,
202 			msdu_start->rate_mcs,
203 			msdu_start->receive_bandwidth,
204 			msdu_start->reception_type,
205 			msdu_start->toeplitz_hash,
206 			msdu_start->nss,
207 			msdu_start->ppdu_start_timestamp,
208 			msdu_start->sw_phy_meta_data);
209 }
210 
211 /**
212  * hal_rx_dump_msdu_end_tlv_8074: dump RX msdu_end TLV in structured
213  *			     human readable format.
214  * @ msdu_end: pointer the msdu_end TLV in pkt.
215  * @ dbg_level: log level.
216  *
217  * Return: void
218  */
219 static void hal_rx_dump_msdu_end_tlv_8074(void *msduend,
220 					  uint8_t dbg_level)
221 {
222 	struct rx_msdu_end *msdu_end = (struct rx_msdu_end *)msduend;
223 
224 	QDF_TRACE(QDF_MODULE_ID_DP, dbg_level,
225 			"rx_msdu_end tlv - "
226 			"rxpcu_mpdu_filter_in_category: %d "
227 			"sw_frame_group_id: %d "
228 			"phy_ppdu_id: %d "
229 			"ip_hdr_chksum: %d "
230 			"tcp_udp_chksum: %d "
231 			"key_id_octet: %d "
232 			"cce_super_rule: %d "
233 			"cce_classify_not_done_truncat: %d "
234 			"cce_classify_not_done_cce_dis: %d "
235 			"ext_wapi_pn_63_48: %d "
236 			"ext_wapi_pn_95_64: %d "
237 			"ext_wapi_pn_127_96: %d "
238 			"reported_mpdu_length: %d "
239 			"first_msdu: %d "
240 			"last_msdu: %d "
241 			"sa_idx_timeout: %d "
242 			"da_idx_timeout: %d "
243 			"msdu_limit_error: %d "
244 			"flow_idx_timeout: %d "
245 			"flow_idx_invalid: %d "
246 			"wifi_parser_error: %d "
247 			"amsdu_parser_error: %d "
248 			"sa_is_valid: %d "
249 			"da_is_valid: %d "
250 			"da_is_mcbc: %d "
251 			"l3_header_padding: %d "
252 			"ipv6_options_crc: %d "
253 			"tcp_seq_number: %d "
254 			"tcp_ack_number: %d "
255 			"tcp_flag: %d "
256 			"lro_eligible: %d "
257 			"window_size: %d "
258 			"da_offset: %d "
259 			"sa_offset: %d "
260 			"da_offset_valid: %d "
261 			"sa_offset_valid: %d "
262 			"rule_indication_31_0: %d "
263 			"rule_indication_63_32: %d "
264 			"sa_idx: %d "
265 			"da_idx: %d "
266 			"msdu_drop: %d "
267 			"reo_destination_indication: %d "
268 			"flow_idx: %d "
269 			"fse_metadata: %d "
270 			"cce_metadata: %d "
271 			"sa_sw_peer_id: %d ",
272 			msdu_end->rxpcu_mpdu_filter_in_category,
273 			msdu_end->sw_frame_group_id,
274 			msdu_end->phy_ppdu_id,
275 			msdu_end->ip_hdr_chksum,
276 			msdu_end->tcp_udp_chksum,
277 			msdu_end->key_id_octet,
278 			msdu_end->cce_super_rule,
279 			msdu_end->cce_classify_not_done_truncate,
280 			msdu_end->cce_classify_not_done_cce_dis,
281 			msdu_end->ext_wapi_pn_63_48,
282 			msdu_end->ext_wapi_pn_95_64,
283 			msdu_end->ext_wapi_pn_127_96,
284 			msdu_end->reported_mpdu_length,
285 			msdu_end->first_msdu,
286 			msdu_end->last_msdu,
287 			msdu_end->sa_idx_timeout,
288 			msdu_end->da_idx_timeout,
289 			msdu_end->msdu_limit_error,
290 			msdu_end->flow_idx_timeout,
291 			msdu_end->flow_idx_invalid,
292 			msdu_end->wifi_parser_error,
293 			msdu_end->amsdu_parser_error,
294 			msdu_end->sa_is_valid,
295 			msdu_end->da_is_valid,
296 			msdu_end->da_is_mcbc,
297 			msdu_end->l3_header_padding,
298 			msdu_end->ipv6_options_crc,
299 			msdu_end->tcp_seq_number,
300 			msdu_end->tcp_ack_number,
301 			msdu_end->tcp_flag,
302 			msdu_end->lro_eligible,
303 			msdu_end->window_size,
304 			msdu_end->da_offset,
305 			msdu_end->sa_offset,
306 			msdu_end->da_offset_valid,
307 			msdu_end->sa_offset_valid,
308 			msdu_end->rule_indication_31_0,
309 			msdu_end->rule_indication_63_32,
310 			msdu_end->sa_idx,
311 			msdu_end->da_idx,
312 			msdu_end->msdu_drop,
313 			msdu_end->reo_destination_indication,
314 			msdu_end->flow_idx,
315 			msdu_end->fse_metadata,
316 			msdu_end->cce_metadata,
317 			msdu_end->sa_sw_peer_id);
318 }
319 
320 
321 /*
322  * Get tid from RX_MPDU_START
323  */
324 #define HAL_RX_MPDU_INFO_TID_GET(_rx_mpdu_info) \
325 	(_HAL_MS((*_OFFSET_TO_WORD_PTR((_rx_mpdu_info),	\
326 		RX_MPDU_INFO_3_TID_OFFSET)),		\
327 		RX_MPDU_INFO_3_TID_MASK,		\
328 		RX_MPDU_INFO_3_TID_LSB))
329 
330 static uint32_t hal_rx_mpdu_start_tid_get_8074(uint8_t *buf)
331 {
332 	struct rx_pkt_tlvs *pkt_tlvs = (struct rx_pkt_tlvs *)buf;
333 	struct rx_mpdu_start *mpdu_start =
334 			&pkt_tlvs->mpdu_start_tlv.rx_mpdu_start;
335 	uint32_t tid;
336 
337 	tid = HAL_RX_MPDU_INFO_TID_GET(&mpdu_start->rx_mpdu_info_details);
338 
339 	return tid;
340 }
341 
342 #define HAL_RX_MSDU_START_RECEPTION_TYPE_GET(_rx_msdu_start) \
343 	(_HAL_MS((*_OFFSET_TO_WORD_PTR((_rx_msdu_start),	\
344 	RX_MSDU_START_5_RECEPTION_TYPE_OFFSET)),	\
345 	RX_MSDU_START_5_RECEPTION_TYPE_MASK,		\
346 	RX_MSDU_START_5_RECEPTION_TYPE_LSB))
347 
348 /*
349  * hal_rx_msdu_start_reception_type_get(): API to get the reception type
350  * Interval from rx_msdu_start
351  *
352  * @buf: pointer to the start of RX PKT TLV header
353  * Return: uint32_t(reception_type)
354  */
355 static uint32_t hal_rx_msdu_start_reception_type_get_8074(uint8_t *buf)
356 {
357 	struct rx_pkt_tlvs *pkt_tlvs = (struct rx_pkt_tlvs *)buf;
358 	struct rx_msdu_start *msdu_start =
359 		&pkt_tlvs->msdu_start_tlv.rx_msdu_start;
360 	uint32_t reception_type;
361 
362 	reception_type = HAL_RX_MSDU_START_RECEPTION_TYPE_GET(msdu_start);
363 
364 	return reception_type;
365 }
366 
367 #define HAL_RX_MSDU_END_DA_IDX_GET(_rx_msdu_end)	\
368 	(_HAL_MS((*_OFFSET_TO_WORD_PTR(_rx_msdu_end,	\
369 		RX_MSDU_END_13_DA_IDX_OFFSET)),		\
370 		RX_MSDU_END_13_DA_IDX_MASK,		\
371 		RX_MSDU_END_13_DA_IDX_LSB))
372 
373  /**
374  * hal_rx_msdu_end_da_idx_get_8074: API to get da_idx
375  * from rx_msdu_end TLV
376  *
377  * @ buf: pointer to the start of RX PKT TLV headers
378  * Return: da index
379  */
380 static uint16_t hal_rx_msdu_end_da_idx_get_8074(uint8_t *buf)
381 {
382 	struct rx_pkt_tlvs *pkt_tlvs = (struct rx_pkt_tlvs *)buf;
383 	struct rx_msdu_end *msdu_end = &pkt_tlvs->msdu_end_tlv.rx_msdu_end;
384 	uint16_t da_idx;
385 
386 	da_idx = HAL_RX_MSDU_END_DA_IDX_GET(msdu_end);
387 
388 	return da_idx;
389 }
390