xref: /dpdk/app/test-bbdev/test_bbdev_vector.c (revision 10ea15e3)
1f714a188SAmr Mokhtar /* SPDX-License-Identifier: BSD-3-Clause
2f714a188SAmr Mokhtar  * Copyright(c) 2017 Intel Corporation
3f714a188SAmr Mokhtar  */
4f714a188SAmr Mokhtar 
55fbc1d49SBruce Richardson #ifdef RTE_EXEC_ENV_FREEBSD
6f714a188SAmr Mokhtar 	#define _WITH_GETLINE
7f714a188SAmr Mokhtar #endif
8f714a188SAmr Mokhtar #include <stdio.h>
9f714a188SAmr Mokhtar #include <stdbool.h>
10f714a188SAmr Mokhtar #include <rte_malloc.h>
11f714a188SAmr Mokhtar 
12f714a188SAmr Mokhtar #include "test_bbdev_vector.h"
13f714a188SAmr Mokhtar 
14f714a188SAmr Mokhtar #define VALUE_DELIMITER ","
15f714a188SAmr Mokhtar #define ENTRY_DELIMITER "="
16f714a188SAmr Mokhtar 
17f714a188SAmr Mokhtar const char *op_data_prefixes[] = {
18f714a188SAmr Mokhtar 	"input",
19f714a188SAmr Mokhtar 	"soft_output",
20f714a188SAmr Mokhtar 	"hard_output",
21d819c083SNicolas Chautru 	"harq_input",
22d819c083SNicolas Chautru 	"harq_output",
23f714a188SAmr Mokhtar };
24f714a188SAmr Mokhtar 
25f714a188SAmr Mokhtar /* trim leading and trailing spaces */
26f714a188SAmr Mokhtar static void
trim_space(char * str)27f714a188SAmr Mokhtar trim_space(char *str)
28f714a188SAmr Mokhtar {
29f714a188SAmr Mokhtar 	char *start, *end;
30f714a188SAmr Mokhtar 
31f714a188SAmr Mokhtar 	for (start = str; *start; start++) {
32f714a188SAmr Mokhtar 		if (!isspace((unsigned char) start[0]))
33f714a188SAmr Mokhtar 			break;
34f714a188SAmr Mokhtar 	}
35f714a188SAmr Mokhtar 
36f714a188SAmr Mokhtar 	for (end = start + strlen(start); end > start + 1; end--) {
37f714a188SAmr Mokhtar 		if (!isspace((unsigned char) end[-1]))
38f714a188SAmr Mokhtar 			break;
39f714a188SAmr Mokhtar 	}
40f714a188SAmr Mokhtar 
41f714a188SAmr Mokhtar 	*end = 0;
42f714a188SAmr Mokhtar 
43f714a188SAmr Mokhtar 	/* Shift from "start" to the beginning of the string */
44f714a188SAmr Mokhtar 	if (start > str)
45f714a188SAmr Mokhtar 		memmove(str, start, (end - start) + 1);
46f714a188SAmr Mokhtar }
47f714a188SAmr Mokhtar 
48f714a188SAmr Mokhtar static bool
starts_with(const char * str,const char * pre)49f714a188SAmr Mokhtar starts_with(const char *str, const char *pre)
50f714a188SAmr Mokhtar {
51f714a188SAmr Mokhtar 	return strncmp(pre, str, strlen(pre)) == 0;
52f714a188SAmr Mokhtar }
53f714a188SAmr Mokhtar 
54f714a188SAmr Mokhtar /* tokenization test values separated by a comma */
55f714a188SAmr Mokhtar static int
parse_values(char * tokens,uint32_t ** data,uint32_t * data_length)56f714a188SAmr Mokhtar parse_values(char *tokens, uint32_t **data, uint32_t *data_length)
57f714a188SAmr Mokhtar {
58f714a188SAmr Mokhtar 	uint32_t n_tokens = 0;
59f714a188SAmr Mokhtar 	uint32_t data_size = 32;
60f714a188SAmr Mokhtar 
61f714a188SAmr Mokhtar 	uint32_t *values, *values_resized;
62f714a188SAmr Mokhtar 	char *tok, *error = NULL;
63f714a188SAmr Mokhtar 
64f714a188SAmr Mokhtar 	tok = strtok(tokens, VALUE_DELIMITER);
65f714a188SAmr Mokhtar 	if (tok == NULL)
66f714a188SAmr Mokhtar 		return -1;
67f714a188SAmr Mokhtar 
68f714a188SAmr Mokhtar 	values = (uint32_t *)
69f714a188SAmr Mokhtar 			rte_zmalloc(NULL, sizeof(uint32_t) * data_size, 0);
70f714a188SAmr Mokhtar 	if (values == NULL)
71f714a188SAmr Mokhtar 		return -1;
72f714a188SAmr Mokhtar 
73f714a188SAmr Mokhtar 	while (tok != NULL) {
74f714a188SAmr Mokhtar 		values_resized = NULL;
75f714a188SAmr Mokhtar 
76f714a188SAmr Mokhtar 		if (n_tokens >= data_size) {
77f714a188SAmr Mokhtar 			data_size *= 2;
78f714a188SAmr Mokhtar 
79f714a188SAmr Mokhtar 			values_resized = (uint32_t *) rte_realloc(values,
80f714a188SAmr Mokhtar 				sizeof(uint32_t) * data_size, 0);
81f714a188SAmr Mokhtar 			if (values_resized == NULL) {
82f714a188SAmr Mokhtar 				rte_free(values);
83f714a188SAmr Mokhtar 				return -1;
84f714a188SAmr Mokhtar 			}
85f714a188SAmr Mokhtar 			values = values_resized;
86f714a188SAmr Mokhtar 		}
87f714a188SAmr Mokhtar 
88f714a188SAmr Mokhtar 		values[n_tokens] = (uint32_t) strtoul(tok, &error, 0);
89d819c083SNicolas Chautru 
90f714a188SAmr Mokhtar 		if ((error == NULL) || (*error != '\0')) {
91f714a188SAmr Mokhtar 			printf("Failed with convert '%s'\n", tok);
92f714a188SAmr Mokhtar 			rte_free(values);
93f714a188SAmr Mokhtar 			return -1;
94f714a188SAmr Mokhtar 		}
95f714a188SAmr Mokhtar 
96f714a188SAmr Mokhtar 		*data_length = *data_length + (strlen(tok) - strlen("0x"))/2;
97f714a188SAmr Mokhtar 
98f714a188SAmr Mokhtar 		tok = strtok(NULL, VALUE_DELIMITER);
99f714a188SAmr Mokhtar 		if (tok == NULL)
100f714a188SAmr Mokhtar 			break;
101f714a188SAmr Mokhtar 
102f714a188SAmr Mokhtar 		n_tokens++;
103f714a188SAmr Mokhtar 	}
104f714a188SAmr Mokhtar 
105f714a188SAmr Mokhtar 	values_resized = (uint32_t *) rte_realloc(values,
106f714a188SAmr Mokhtar 		sizeof(uint32_t) * (n_tokens + 1), 0);
107f714a188SAmr Mokhtar 
108f714a188SAmr Mokhtar 	if (values_resized == NULL) {
109f714a188SAmr Mokhtar 		rte_free(values);
110f714a188SAmr Mokhtar 		return -1;
111f714a188SAmr Mokhtar 	}
112f714a188SAmr Mokhtar 
113f714a188SAmr Mokhtar 	*data = values_resized;
114f714a188SAmr Mokhtar 
115f714a188SAmr Mokhtar 	return 0;
116f714a188SAmr Mokhtar }
117f714a188SAmr Mokhtar 
118f714a188SAmr Mokhtar /* convert turbo decoder flag from string to unsigned long int*/
119f714a188SAmr Mokhtar static int
op_decoder_flag_strtoul(char * token,uint32_t * op_flag_value)120f714a188SAmr Mokhtar op_decoder_flag_strtoul(char *token, uint32_t *op_flag_value)
121f714a188SAmr Mokhtar {
122f714a188SAmr Mokhtar 	if (!strcmp(token, "RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE"))
123f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE;
124f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_CRC_TYPE_24B"))
125f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_CRC_TYPE_24B;
126f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_EQUALIZER"))
127f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_EQUALIZER;
128f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_SOFT_OUT_SATURATE"))
129f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_SOFT_OUT_SATURATE;
130f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_HALF_ITERATION_EVEN"))
131f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_HALF_ITERATION_EVEN;
132f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_CONTINUE_CRC_MATCH"))
133f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_CONTINUE_CRC_MATCH;
134f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_SOFT_OUTPUT"))
135f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_SOFT_OUTPUT;
136f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_EARLY_TERMINATION"))
137f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_EARLY_TERMINATION;
138f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN"))
139f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN;
140f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN"))
141f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN;
142f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT"))
143f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT;
144f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT"))
145f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT;
146f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_MAP_DEC"))
147f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_MAP_DEC;
148f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_DEC_SCATTER_GATHER"))
149f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_DEC_SCATTER_GATHER;
150795ae2dfSKamil Chalupnik 	else if (!strcmp(token, "RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP"))
151795ae2dfSKamil Chalupnik 		*op_flag_value = RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP;
152*10ea15e3SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_TURBO_DEC_CRC_24B_DROP"))
153*10ea15e3SNicolas Chautru 		*op_flag_value = RTE_BBDEV_TURBO_DEC_CRC_24B_DROP;
154f714a188SAmr Mokhtar 	else {
155f714a188SAmr Mokhtar 		printf("The given value is not a turbo decoder flag\n");
156f714a188SAmr Mokhtar 		return -1;
157f714a188SAmr Mokhtar 	}
158f714a188SAmr Mokhtar 
159f714a188SAmr Mokhtar 	return 0;
160f714a188SAmr Mokhtar }
161f714a188SAmr Mokhtar 
162d819c083SNicolas Chautru /* convert LDPC flag from string to unsigned long int*/
163d819c083SNicolas Chautru static int
op_ldpc_decoder_flag_strtoul(char * token,uint32_t * op_flag_value)164d819c083SNicolas Chautru op_ldpc_decoder_flag_strtoul(char *token, uint32_t *op_flag_value)
165d819c083SNicolas Chautru {
166d819c083SNicolas Chautru 	if (!strcmp(token, "RTE_BBDEV_LDPC_CRC_TYPE_24A_CHECK"))
167d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_CRC_TYPE_24A_CHECK;
168d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK"))
169d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK;
170d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP"))
171d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP;
172cc360fd3SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_CRC_TYPE_16_CHECK"))
173cc360fd3SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_CRC_TYPE_16_CHECK;
174d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_DEINTERLEAVER_BYPASS"))
175d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_DEINTERLEAVER_BYPASS;
176d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE"))
177d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE;
178d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE"))
179d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE;
180d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_DECODE_BYPASS"))
181d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_DECODE_BYPASS;
182d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_SOFT_OUT_ENABLE"))
183d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_SOFT_OUT_ENABLE;
184d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_SOFT_OUT_RM_BYPASS"))
185d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_SOFT_OUT_RM_BYPASS;
186d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_SOFT_OUT_DEINTERLEAVER_BYPASS"))
187d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_SOFT_OUT_DEINTERLEAVER_BYPASS;
188d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE"))
189d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE;
190d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_DEC_INTERRUPTS"))
191d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_DEC_INTERRUPTS;
192d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_DEC_SCATTER_GATHER"))
193d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_DEC_SCATTER_GATHER;
194d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION"))
195d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION;
196d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_LLR_COMPRESSION"))
197d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_LLR_COMPRESSION;
198d819c083SNicolas Chautru 	else if (!strcmp(token,
199d819c083SNicolas Chautru 			"RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_IN_ENABLE"))
200d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_IN_ENABLE;
201d819c083SNicolas Chautru 	else if (!strcmp(token,
202d819c083SNicolas Chautru 			"RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_OUT_ENABLE"))
203d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_OUT_ENABLE;
204335c11fdSNicolas Chautru 	else if (!strcmp(token,
205335c11fdSNicolas Chautru 			"RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK"))
206335c11fdSNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK;
207d819c083SNicolas Chautru 	else {
208d819c083SNicolas Chautru 		printf("The given value is not a LDPC decoder flag\n");
209d819c083SNicolas Chautru 		return -1;
210d819c083SNicolas Chautru 	}
211d819c083SNicolas Chautru 
212d819c083SNicolas Chautru 	return 0;
213d819c083SNicolas Chautru }
214d819c083SNicolas Chautru 
215f714a188SAmr Mokhtar /* convert turbo encoder flag from string to unsigned long int*/
216f714a188SAmr Mokhtar static int
op_encoder_flag_strtoul(char * token,uint32_t * op_flag_value)217f714a188SAmr Mokhtar op_encoder_flag_strtoul(char *token, uint32_t *op_flag_value)
218f714a188SAmr Mokhtar {
219f714a188SAmr Mokhtar 	if (!strcmp(token, "RTE_BBDEV_TURBO_RV_INDEX_BYPASS"))
220f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_RV_INDEX_BYPASS;
221f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_RATE_MATCH"))
222f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_RATE_MATCH;
223f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_CRC_24B_ATTACH"))
224f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_CRC_24B_ATTACH;
225f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_CRC_24A_ATTACH"))
226f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_CRC_24A_ATTACH;
227f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_TURBO_ENC_SCATTER_GATHER"))
228f714a188SAmr Mokhtar 		*op_flag_value = RTE_BBDEV_TURBO_ENC_SCATTER_GATHER;
229f714a188SAmr Mokhtar 	else {
230f714a188SAmr Mokhtar 		printf("The given value is not a turbo encoder flag\n");
231f714a188SAmr Mokhtar 		return -1;
232f714a188SAmr Mokhtar 	}
233f714a188SAmr Mokhtar 
234f714a188SAmr Mokhtar 	return 0;
235f714a188SAmr Mokhtar }
236f714a188SAmr Mokhtar 
237d819c083SNicolas Chautru /* convert LDPC encoder flag from string to unsigned long int*/
238d819c083SNicolas Chautru static int
op_ldpc_encoder_flag_strtoul(char * token,uint32_t * op_flag_value)239d819c083SNicolas Chautru op_ldpc_encoder_flag_strtoul(char *token, uint32_t *op_flag_value)
240d819c083SNicolas Chautru {
241d819c083SNicolas Chautru 	if (!strcmp(token, "RTE_BBDEV_LDPC_INTERLEAVER_BYPASS"))
242d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_INTERLEAVER_BYPASS;
243d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_RATE_MATCH"))
244d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_RATE_MATCH;
245d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_CRC_24A_ATTACH"))
246d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_CRC_24A_ATTACH;
247d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_CRC_24B_ATTACH"))
248d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_CRC_24B_ATTACH;
249d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_CRC_16_ATTACH"))
250d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_CRC_16_ATTACH;
251d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_ENC_INTERRUPTS"))
252d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_ENC_INTERRUPTS;
253d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_LDPC_ENC_SCATTER_GATHER"))
254d819c083SNicolas Chautru 		*op_flag_value = RTE_BBDEV_LDPC_ENC_SCATTER_GATHER;
255d819c083SNicolas Chautru 	else {
256d819c083SNicolas Chautru 		printf("The given value is not a turbo encoder flag\n");
257d819c083SNicolas Chautru 		return -1;
258d819c083SNicolas Chautru 	}
259d819c083SNicolas Chautru 
260d819c083SNicolas Chautru 	return 0;
261d819c083SNicolas Chautru }
262d819c083SNicolas Chautru 
263f714a188SAmr Mokhtar /* tokenization turbo decoder/encoder flags values separated by a comma */
264f714a188SAmr Mokhtar static int
parse_turbo_flags(char * tokens,uint32_t * op_flags,enum rte_bbdev_op_type op_type)265f714a188SAmr Mokhtar parse_turbo_flags(char *tokens, uint32_t *op_flags,
266f714a188SAmr Mokhtar 		enum rte_bbdev_op_type op_type)
267f714a188SAmr Mokhtar {
268f714a188SAmr Mokhtar 	char *tok = NULL;
269f714a188SAmr Mokhtar 	uint32_t op_flag_value = 0;
270f714a188SAmr Mokhtar 
271f714a188SAmr Mokhtar 	tok = strtok(tokens, VALUE_DELIMITER);
272f714a188SAmr Mokhtar 	if (tok == NULL)
273f714a188SAmr Mokhtar 		return -1;
274f714a188SAmr Mokhtar 
275f714a188SAmr Mokhtar 	while (tok != NULL) {
276f714a188SAmr Mokhtar 		trim_space(tok);
277f714a188SAmr Mokhtar 		if (op_type == RTE_BBDEV_OP_TURBO_DEC) {
278f714a188SAmr Mokhtar 			if (op_decoder_flag_strtoul(tok, &op_flag_value) == -1)
279f714a188SAmr Mokhtar 				return -1;
280f714a188SAmr Mokhtar 		} else if (op_type == RTE_BBDEV_OP_TURBO_ENC) {
281f714a188SAmr Mokhtar 			if (op_encoder_flag_strtoul(tok, &op_flag_value) == -1)
282f714a188SAmr Mokhtar 				return -1;
283d819c083SNicolas Chautru 		} else if (op_type == RTE_BBDEV_OP_LDPC_ENC) {
284d819c083SNicolas Chautru 			if (op_ldpc_encoder_flag_strtoul(tok, &op_flag_value)
285d819c083SNicolas Chautru 					== -1)
286d819c083SNicolas Chautru 				return -1;
287d819c083SNicolas Chautru 		} else if (op_type == RTE_BBDEV_OP_LDPC_DEC) {
288d819c083SNicolas Chautru 			if (op_ldpc_decoder_flag_strtoul(tok, &op_flag_value)
289d819c083SNicolas Chautru 					== -1)
290d819c083SNicolas Chautru 				return -1;
291f714a188SAmr Mokhtar 		} else {
292f714a188SAmr Mokhtar 			return -1;
293f714a188SAmr Mokhtar 		}
294f714a188SAmr Mokhtar 
295f714a188SAmr Mokhtar 		*op_flags = *op_flags | op_flag_value;
296f714a188SAmr Mokhtar 
297f714a188SAmr Mokhtar 		tok = strtok(NULL, VALUE_DELIMITER);
298f714a188SAmr Mokhtar 		if (tok == NULL)
299f714a188SAmr Mokhtar 			break;
300f714a188SAmr Mokhtar 	}
301f714a188SAmr Mokhtar 
302f714a188SAmr Mokhtar 	return 0;
303f714a188SAmr Mokhtar }
304f714a188SAmr Mokhtar 
305f714a188SAmr Mokhtar /* convert turbo encoder/decoder op_type from string to enum*/
306f714a188SAmr Mokhtar static int
op_turbo_type_strtol(char * token,enum rte_bbdev_op_type * op_type)307f714a188SAmr Mokhtar op_turbo_type_strtol(char *token, enum rte_bbdev_op_type *op_type)
308f714a188SAmr Mokhtar {
309f714a188SAmr Mokhtar 	trim_space(token);
310f714a188SAmr Mokhtar 	if (!strcmp(token, "RTE_BBDEV_OP_TURBO_DEC"))
311f714a188SAmr Mokhtar 		*op_type = RTE_BBDEV_OP_TURBO_DEC;
312f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_OP_TURBO_ENC"))
313f714a188SAmr Mokhtar 		*op_type = RTE_BBDEV_OP_TURBO_ENC;
314d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_OP_LDPC_ENC"))
315d819c083SNicolas Chautru 		*op_type = RTE_BBDEV_OP_LDPC_ENC;
316d819c083SNicolas Chautru 	else if (!strcmp(token, "RTE_BBDEV_OP_LDPC_DEC"))
317d819c083SNicolas Chautru 		*op_type = RTE_BBDEV_OP_LDPC_DEC;
318f714a188SAmr Mokhtar 	else if (!strcmp(token, "RTE_BBDEV_OP_NONE"))
319f714a188SAmr Mokhtar 		*op_type = RTE_BBDEV_OP_NONE;
320f714a188SAmr Mokhtar 	else {
321f714a188SAmr Mokhtar 		printf("Not valid turbo op_type: '%s'\n", token);
322f714a188SAmr Mokhtar 		return -1;
323f714a188SAmr Mokhtar 	}
324f714a188SAmr Mokhtar 
325f714a188SAmr Mokhtar 	return 0;
326f714a188SAmr Mokhtar }
327f714a188SAmr Mokhtar 
328f714a188SAmr Mokhtar /* tokenization expected status values separated by a comma */
329f714a188SAmr Mokhtar static int
parse_expected_status(char * tokens,int * status,enum rte_bbdev_op_type op_type)330f714a188SAmr Mokhtar parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type)
331f714a188SAmr Mokhtar {
332f714a188SAmr Mokhtar 	char *tok = NULL;
333f714a188SAmr Mokhtar 	bool status_ok = false;
334f714a188SAmr Mokhtar 
335f714a188SAmr Mokhtar 	tok = strtok(tokens, VALUE_DELIMITER);
336f714a188SAmr Mokhtar 	if (tok == NULL)
337f714a188SAmr Mokhtar 		return -1;
338f714a188SAmr Mokhtar 
339f714a188SAmr Mokhtar 	while (tok != NULL) {
340f714a188SAmr Mokhtar 		trim_space(tok);
341f714a188SAmr Mokhtar 		if (!strcmp(tok, "OK"))
342f714a188SAmr Mokhtar 			status_ok = true;
343f714a188SAmr Mokhtar 		else if (!strcmp(tok, "DMA"))
344f714a188SAmr Mokhtar 			*status = *status | (1 << RTE_BBDEV_DRV_ERROR);
345f714a188SAmr Mokhtar 		else if (!strcmp(tok, "FCW"))
346f714a188SAmr Mokhtar 			*status = *status | (1 << RTE_BBDEV_DATA_ERROR);
347d819c083SNicolas Chautru 		else if (!strcmp(tok, "SYNCRC")) {
348d819c083SNicolas Chautru 			*status = *status | (1 << RTE_BBDEV_SYNDROME_ERROR);
349d819c083SNicolas Chautru 			*status = *status | (1 << RTE_BBDEV_CRC_ERROR);
350d819c083SNicolas Chautru 		} else if (!strcmp(tok, "SYN"))
351d819c083SNicolas Chautru 			*status = *status | (1 << RTE_BBDEV_SYNDROME_ERROR);
352f714a188SAmr Mokhtar 		else if (!strcmp(tok, "CRC")) {
353d819c083SNicolas Chautru 			if ((op_type == RTE_BBDEV_OP_TURBO_DEC) ||
354d819c083SNicolas Chautru 					(op_type == RTE_BBDEV_OP_LDPC_DEC))
355f714a188SAmr Mokhtar 				*status = *status | (1 << RTE_BBDEV_CRC_ERROR);
356f714a188SAmr Mokhtar 			else {
357f714a188SAmr Mokhtar 				printf(
358d819c083SNicolas Chautru 						"CRC is only a valid value for decoder\n");
359f714a188SAmr Mokhtar 				return -1;
360f714a188SAmr Mokhtar 			}
361f714a188SAmr Mokhtar 		} else {
362f714a188SAmr Mokhtar 			printf("Not valid status: '%s'\n", tok);
363f714a188SAmr Mokhtar 			return -1;
364f714a188SAmr Mokhtar 		}
365f714a188SAmr Mokhtar 
366f714a188SAmr Mokhtar 		tok = strtok(NULL, VALUE_DELIMITER);
367f714a188SAmr Mokhtar 		if (tok == NULL)
368f714a188SAmr Mokhtar 			break;
369f714a188SAmr Mokhtar 	}
370f714a188SAmr Mokhtar 
371f714a188SAmr Mokhtar 	if (status_ok && *status != 0) {
372f714a188SAmr Mokhtar 		printf(
373f714a188SAmr Mokhtar 				"Not valid status values. Cannot be OK and ERROR at the same time.\n");
374f714a188SAmr Mokhtar 		return -1;
375f714a188SAmr Mokhtar 	}
376f714a188SAmr Mokhtar 
377f714a188SAmr Mokhtar 	return 0;
378f714a188SAmr Mokhtar }
379f714a188SAmr Mokhtar 
380f714a188SAmr Mokhtar /* parse ops data entry (there can be more than 1 input entry, each will be
381f714a188SAmr Mokhtar  * contained in a separate op_data_buf struct)
382f714a188SAmr Mokhtar  */
383f714a188SAmr Mokhtar static int
parse_data_entry(const char * key_token,char * token,struct test_bbdev_vector * vector,enum op_data_type type,const char * prefix)384f714a188SAmr Mokhtar parse_data_entry(const char *key_token, char *token,
385f714a188SAmr Mokhtar 		struct test_bbdev_vector *vector, enum op_data_type type,
386f714a188SAmr Mokhtar 		const char *prefix)
387f714a188SAmr Mokhtar {
388f714a188SAmr Mokhtar 	int ret;
389f714a188SAmr Mokhtar 	uint32_t data_length = 0;
390f714a188SAmr Mokhtar 	uint32_t *data = NULL;
391f714a188SAmr Mokhtar 	unsigned int id;
392f714a188SAmr Mokhtar 	struct op_data_buf *op_data;
393f714a188SAmr Mokhtar 	unsigned int *nb_ops;
394f714a188SAmr Mokhtar 
39521820350SAmr Mokhtar 	if (type >= DATA_NUM_TYPES) {
396f714a188SAmr Mokhtar 		printf("Unknown op type: %d!\n", type);
397f714a188SAmr Mokhtar 		return -1;
398f714a188SAmr Mokhtar 	}
399f714a188SAmr Mokhtar 
400f714a188SAmr Mokhtar 	op_data = vector->entries[type].segments;
401f714a188SAmr Mokhtar 	nb_ops = &vector->entries[type].nb_segments;
402f714a188SAmr Mokhtar 
403c4b0d663SNicolas Chautru 	if (*nb_ops >= RTE_BBDEV_TURBO_MAX_CODE_BLOCKS) {
404f714a188SAmr Mokhtar 		printf("Too many segments (code blocks defined): %u, max %d!\n",
405c4b0d663SNicolas Chautru 				*nb_ops, RTE_BBDEV_TURBO_MAX_CODE_BLOCKS);
406f714a188SAmr Mokhtar 		return -1;
407f714a188SAmr Mokhtar 	}
408f714a188SAmr Mokhtar 
409f714a188SAmr Mokhtar 	if (sscanf(key_token + strlen(prefix), "%u", &id) != 1) {
410f714a188SAmr Mokhtar 		printf("Missing ID of %s\n", prefix);
411f714a188SAmr Mokhtar 		return -1;
412f714a188SAmr Mokhtar 	}
413f714a188SAmr Mokhtar 	if (id != *nb_ops) {
414f714a188SAmr Mokhtar 		printf(
415f714a188SAmr Mokhtar 			"Please order data entries sequentially, i.e. %s0, %s1, ...\n",
416f714a188SAmr Mokhtar 				prefix, prefix);
417f714a188SAmr Mokhtar 		return -1;
418f714a188SAmr Mokhtar 	}
419f714a188SAmr Mokhtar 
420f714a188SAmr Mokhtar 	/* Clear new op data struct */
421f714a188SAmr Mokhtar 	memset(op_data + *nb_ops, 0, sizeof(struct op_data_buf));
422f714a188SAmr Mokhtar 
423f714a188SAmr Mokhtar 	ret = parse_values(token, &data, &data_length);
424f714a188SAmr Mokhtar 	if (!ret) {
425f714a188SAmr Mokhtar 		op_data[*nb_ops].addr = data;
426f714a188SAmr Mokhtar 		op_data[*nb_ops].length = data_length;
427f714a188SAmr Mokhtar 		++(*nb_ops);
428f714a188SAmr Mokhtar 	}
429f714a188SAmr Mokhtar 
430f714a188SAmr Mokhtar 	return ret;
431f714a188SAmr Mokhtar }
432f714a188SAmr Mokhtar 
433f714a188SAmr Mokhtar /* parses turbo decoder parameters and assigns to global variable */
434f714a188SAmr Mokhtar static int
parse_decoder_params(const char * key_token,char * token,struct test_bbdev_vector * vector)435f714a188SAmr Mokhtar parse_decoder_params(const char *key_token, char *token,
436f714a188SAmr Mokhtar 		struct test_bbdev_vector *vector)
437f714a188SAmr Mokhtar {
438f714a188SAmr Mokhtar 	int ret = 0, status = 0;
439f714a188SAmr Mokhtar 	uint32_t op_flags = 0;
440f714a188SAmr Mokhtar 	char *err = NULL;
441f714a188SAmr Mokhtar 
442f714a188SAmr Mokhtar 	struct rte_bbdev_op_turbo_dec *turbo_dec = &vector->turbo_dec;
443f714a188SAmr Mokhtar 
444f714a188SAmr Mokhtar 	/* compare keys */
445f714a188SAmr Mokhtar 	if (starts_with(key_token, op_data_prefixes[DATA_INPUT]))
446f714a188SAmr Mokhtar 		ret = parse_data_entry(key_token, token, vector,
447f714a188SAmr Mokhtar 				DATA_INPUT, op_data_prefixes[DATA_INPUT]);
448f714a188SAmr Mokhtar 
449f714a188SAmr Mokhtar 	else if (starts_with(key_token, op_data_prefixes[DATA_SOFT_OUTPUT]))
450f714a188SAmr Mokhtar 		ret = parse_data_entry(key_token, token, vector,
451f714a188SAmr Mokhtar 				DATA_SOFT_OUTPUT,
452f714a188SAmr Mokhtar 				op_data_prefixes[DATA_SOFT_OUTPUT]);
453f714a188SAmr Mokhtar 
454f714a188SAmr Mokhtar 	else if (starts_with(key_token, op_data_prefixes[DATA_HARD_OUTPUT]))
455f714a188SAmr Mokhtar 		ret = parse_data_entry(key_token, token, vector,
456f714a188SAmr Mokhtar 				DATA_HARD_OUTPUT,
457f714a188SAmr Mokhtar 				op_data_prefixes[DATA_HARD_OUTPUT]);
458f714a188SAmr Mokhtar 	else if (!strcmp(key_token, "e")) {
459f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_E;
460f714a188SAmr Mokhtar 		turbo_dec->cb_params.e = (uint32_t) strtoul(token, &err, 0);
461f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "ea")) {
462f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_EA;
463f714a188SAmr Mokhtar 		turbo_dec->tb_params.ea = (uint32_t) strtoul(token, &err, 0);
464f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
465f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "eb")) {
466f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_EB;
467f714a188SAmr Mokhtar 		turbo_dec->tb_params.eb = (uint32_t) strtoul(token, &err, 0);
468f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
469f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "k")) {
470f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_K;
471f714a188SAmr Mokhtar 		turbo_dec->cb_params.k = (uint16_t) strtoul(token, &err, 0);
472f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
473f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "k_pos")) {
474f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_K_POS;
475f714a188SAmr Mokhtar 		turbo_dec->tb_params.k_pos = (uint16_t) strtoul(token, &err, 0);
476f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
477f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "k_neg")) {
478f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_K_NEG;
479f714a188SAmr Mokhtar 		turbo_dec->tb_params.k_neg = (uint16_t) strtoul(token, &err, 0);
480f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
481f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "c")) {
482f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_C;
483f714a188SAmr Mokhtar 		turbo_dec->tb_params.c = (uint16_t) strtoul(token, &err, 0);
484f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
485f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "c_neg")) {
486f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_C_NEG;
487f714a188SAmr Mokhtar 		turbo_dec->tb_params.c_neg = (uint16_t) strtoul(token, &err, 0);
488f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
489f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "cab")) {
490f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_CAB;
491f714a188SAmr Mokhtar 		turbo_dec->tb_params.cab = (uint8_t) strtoul(token, &err, 0);
492f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
493f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "rv_index")) {
494f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_RV_INDEX;
495f714a188SAmr Mokhtar 		turbo_dec->rv_index = (uint8_t) strtoul(token, &err, 0);
496f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
497f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "iter_max")) {
498f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_ITER_MAX;
499f714a188SAmr Mokhtar 		turbo_dec->iter_max = (uint8_t) strtoul(token, &err, 0);
500f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
501f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "iter_min")) {
502f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_ITER_MIN;
503f714a188SAmr Mokhtar 		turbo_dec->iter_min = (uint8_t) strtoul(token, &err, 0);
504f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
505f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "expected_iter_count")) {
506f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_EXPECTED_ITER_COUNT;
507f714a188SAmr Mokhtar 		turbo_dec->iter_count = (uint8_t) strtoul(token, &err, 0);
508f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
509f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "ext_scale")) {
510f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_EXT_SCALE;
511f714a188SAmr Mokhtar 		turbo_dec->ext_scale = (uint8_t) strtoul(token, &err, 0);
512f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
513f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "num_maps")) {
514f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_NUM_MAPS;
515f714a188SAmr Mokhtar 		turbo_dec->num_maps = (uint8_t) strtoul(token, &err, 0);
516f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
5170b98d574SKamil Chalupnik 	} else if (!strcmp(key_token, "r")) {
5180b98d574SKamil Chalupnik 		vector->mask |= TEST_BBDEV_VF_R;
5190b98d574SKamil Chalupnik 		turbo_dec->tb_params.r = (uint8_t)strtoul(token, &err, 0);
5200b98d574SKamil Chalupnik 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
521f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "code_block_mode")) {
522f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_CODE_BLOCK_MODE;
523f714a188SAmr Mokhtar 		turbo_dec->code_block_mode = (uint8_t) strtoul(token, &err, 0);
524f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
525f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "op_flags")) {
526f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_OP_FLAGS;
527f714a188SAmr Mokhtar 		ret = parse_turbo_flags(token, &op_flags,
528f714a188SAmr Mokhtar 			vector->op_type);
529f714a188SAmr Mokhtar 		if (!ret)
530f714a188SAmr Mokhtar 			turbo_dec->op_flags = op_flags;
531f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "expected_status")) {
532f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_EXPECTED_STATUS;
533f714a188SAmr Mokhtar 		ret = parse_expected_status(token, &status, vector->op_type);
534f714a188SAmr Mokhtar 		if (!ret)
535f714a188SAmr Mokhtar 			vector->expected_status = status;
536f714a188SAmr Mokhtar 	} else {
537f714a188SAmr Mokhtar 		printf("Not valid dec key: '%s'\n", key_token);
538f714a188SAmr Mokhtar 		return -1;
539f714a188SAmr Mokhtar 	}
540f714a188SAmr Mokhtar 
541f714a188SAmr Mokhtar 	if (ret != 0) {
542f714a188SAmr Mokhtar 		printf("Failed with convert '%s\t%s'\n", key_token, token);
543f714a188SAmr Mokhtar 		return -1;
544f714a188SAmr Mokhtar 	}
545f714a188SAmr Mokhtar 
546f714a188SAmr Mokhtar 	return 0;
547f714a188SAmr Mokhtar }
548f714a188SAmr Mokhtar 
549f714a188SAmr Mokhtar /* parses turbo encoder parameters and assigns to global variable */
550f714a188SAmr Mokhtar static int
parse_encoder_params(const char * key_token,char * token,struct test_bbdev_vector * vector)551f714a188SAmr Mokhtar parse_encoder_params(const char *key_token, char *token,
552f714a188SAmr Mokhtar 		struct test_bbdev_vector *vector)
553f714a188SAmr Mokhtar {
554f714a188SAmr Mokhtar 	int ret = 0, status = 0;
555f714a188SAmr Mokhtar 	uint32_t op_flags = 0;
556f714a188SAmr Mokhtar 	char *err = NULL;
557f714a188SAmr Mokhtar 
558f714a188SAmr Mokhtar 
559f714a188SAmr Mokhtar 	struct rte_bbdev_op_turbo_enc *turbo_enc = &vector->turbo_enc;
560f714a188SAmr Mokhtar 
561f714a188SAmr Mokhtar 	if (starts_with(key_token, op_data_prefixes[DATA_INPUT]))
562f714a188SAmr Mokhtar 		ret = parse_data_entry(key_token, token, vector,
563f714a188SAmr Mokhtar 				DATA_INPUT, op_data_prefixes[DATA_INPUT]);
564f714a188SAmr Mokhtar 	else if (starts_with(key_token, "output"))
565f714a188SAmr Mokhtar 		ret = parse_data_entry(key_token, token, vector,
566f714a188SAmr Mokhtar 				DATA_HARD_OUTPUT, "output");
567f714a188SAmr Mokhtar 	else if (!strcmp(key_token, "e")) {
568f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_E;
569f714a188SAmr Mokhtar 		turbo_enc->cb_params.e = (uint32_t) strtoul(token, &err, 0);
570f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
571f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "ea")) {
572f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_EA;
573f714a188SAmr Mokhtar 		turbo_enc->tb_params.ea = (uint32_t) strtoul(token, &err, 0);
574f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
575f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "eb")) {
576f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_EB;
577f714a188SAmr Mokhtar 		turbo_enc->tb_params.eb = (uint32_t) strtoul(token, &err, 0);
578f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
579f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "k")) {
580f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_K;
581f714a188SAmr Mokhtar 		turbo_enc->cb_params.k = (uint16_t) strtoul(token, &err, 0);
582f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
583f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "k_neg")) {
584f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_K_NEG;
585f714a188SAmr Mokhtar 		turbo_enc->tb_params.k_neg = (uint16_t) strtoul(token, &err, 0);
586f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
587f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "k_pos")) {
588f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_K_POS;
589f714a188SAmr Mokhtar 		turbo_enc->tb_params.k_pos = (uint16_t) strtoul(token, &err, 0);
590f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
591f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "c_neg")) {
592f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_C_NEG;
593f714a188SAmr Mokhtar 		turbo_enc->tb_params.c_neg = (uint8_t) strtoul(token, &err, 0);
594f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
595f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "c")) {
596f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_C;
597f714a188SAmr Mokhtar 		turbo_enc->tb_params.c = (uint8_t) strtoul(token, &err, 0);
598f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
599f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "cab")) {
600f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_CAB;
601f714a188SAmr Mokhtar 		turbo_enc->tb_params.cab = (uint8_t) strtoul(token, &err, 0);
602f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
603f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "rv_index")) {
604f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_RV_INDEX;
605f714a188SAmr Mokhtar 		turbo_enc->rv_index = (uint8_t) strtoul(token, &err, 0);
606f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
607f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "ncb")) {
608f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_NCB;
609f714a188SAmr Mokhtar 		turbo_enc->cb_params.ncb = (uint16_t) strtoul(token, &err, 0);
610f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
611f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "ncb_neg")) {
612f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_NCB_NEG;
613f714a188SAmr Mokhtar 		turbo_enc->tb_params.ncb_neg =
614f714a188SAmr Mokhtar 				(uint16_t) strtoul(token, &err, 0);
615f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
616f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "ncb_pos")) {
617f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_NCB_POS;
618f714a188SAmr Mokhtar 		turbo_enc->tb_params.ncb_pos =
619f714a188SAmr Mokhtar 				(uint16_t) strtoul(token, &err, 0);
620f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
621f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "r")) {
622f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_R;
623f714a188SAmr Mokhtar 		turbo_enc->tb_params.r = (uint8_t) strtoul(token, &err, 0);
624f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
625f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "code_block_mode")) {
626f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_CODE_BLOCK_MODE;
627f714a188SAmr Mokhtar 		turbo_enc->code_block_mode = (uint8_t) strtoul(token, &err, 0);
628f714a188SAmr Mokhtar 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
629f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "op_flags")) {
630f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_OP_FLAGS;
631f714a188SAmr Mokhtar 		ret = parse_turbo_flags(token, &op_flags,
632f714a188SAmr Mokhtar 				vector->op_type);
633f714a188SAmr Mokhtar 		if (!ret)
634f714a188SAmr Mokhtar 			turbo_enc->op_flags = op_flags;
635f714a188SAmr Mokhtar 	} else if (!strcmp(key_token, "expected_status")) {
636f714a188SAmr Mokhtar 		vector->mask |= TEST_BBDEV_VF_EXPECTED_STATUS;
637f714a188SAmr Mokhtar 		ret = parse_expected_status(token, &status, vector->op_type);
638f714a188SAmr Mokhtar 		if (!ret)
639f714a188SAmr Mokhtar 			vector->expected_status = status;
640f714a188SAmr Mokhtar 	} else {
641f714a188SAmr Mokhtar 		printf("Not valid enc key: '%s'\n", key_token);
642f714a188SAmr Mokhtar 		return -1;
643f714a188SAmr Mokhtar 	}
644f714a188SAmr Mokhtar 
645f714a188SAmr Mokhtar 	if (ret != 0) {
646f714a188SAmr Mokhtar 		printf("Failed with convert '%s\t%s'\n", key_token, token);
647f714a188SAmr Mokhtar 		return -1;
648f714a188SAmr Mokhtar 	}
649f714a188SAmr Mokhtar 
650f714a188SAmr Mokhtar 	return 0;
651f714a188SAmr Mokhtar }
652f714a188SAmr Mokhtar 
653d819c083SNicolas Chautru 
654d819c083SNicolas Chautru /* parses LDPC encoder parameters and assigns to global variable */
655d819c083SNicolas Chautru static int
parse_ldpc_encoder_params(const char * key_token,char * token,struct test_bbdev_vector * vector)656d819c083SNicolas Chautru parse_ldpc_encoder_params(const char *key_token, char *token,
657d819c083SNicolas Chautru 		struct test_bbdev_vector *vector)
658d819c083SNicolas Chautru {
659d819c083SNicolas Chautru 	int ret = 0, status = 0;
660d819c083SNicolas Chautru 	uint32_t op_flags = 0;
661d819c083SNicolas Chautru 	char *err = NULL;
662d819c083SNicolas Chautru 
663d819c083SNicolas Chautru 	struct rte_bbdev_op_ldpc_enc *ldpc_enc = &vector->ldpc_enc;
664d819c083SNicolas Chautru 
665d819c083SNicolas Chautru 	if (starts_with(key_token, op_data_prefixes[DATA_INPUT]))
666d819c083SNicolas Chautru 		ret = parse_data_entry(key_token, token, vector,
667d819c083SNicolas Chautru 				DATA_INPUT,
668d819c083SNicolas Chautru 				op_data_prefixes[DATA_INPUT]);
669d819c083SNicolas Chautru 	else if (starts_with(key_token, "output"))
670d819c083SNicolas Chautru 		ret = parse_data_entry(key_token, token, vector,
671d819c083SNicolas Chautru 				DATA_HARD_OUTPUT,
672d819c083SNicolas Chautru 				"output");
673d819c083SNicolas Chautru 	else if (!strcmp(key_token, "e")) {
674d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_E;
675d819c083SNicolas Chautru 		ldpc_enc->cb_params.e = (uint32_t) strtoul(token, &err, 0);
676d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
677d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "ea")) {
678d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_EA;
679d819c083SNicolas Chautru 		ldpc_enc->tb_params.ea = (uint32_t) strtoul(token, &err, 0);
680d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
681d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "eb")) {
682d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_EB;
683d819c083SNicolas Chautru 		ldpc_enc->tb_params.eb = (uint32_t) strtoul(token, &err, 0);
684d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
685d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "c")) {
686d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_C;
687d819c083SNicolas Chautru 		ldpc_enc->tb_params.c = (uint8_t) strtoul(token, &err, 0);
688d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
689d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "cab")) {
690d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_CAB;
691d819c083SNicolas Chautru 		ldpc_enc->tb_params.cab = (uint8_t) strtoul(token, &err, 0);
692d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
693d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "rv_index")) {
694d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_RV_INDEX;
695d819c083SNicolas Chautru 		ldpc_enc->rv_index = (uint8_t) strtoul(token, &err, 0);
696d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
697d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "n_cb")) {
698d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_NCB;
699d819c083SNicolas Chautru 		ldpc_enc->n_cb = (uint16_t) strtoul(token, &err, 0);
700d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
701d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "r")) {
702d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_R;
703d819c083SNicolas Chautru 		ldpc_enc->tb_params.r = (uint8_t) strtoul(token, &err, 0);
704d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
705d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "q_m")) {
706d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_QM;
707d819c083SNicolas Chautru 		ldpc_enc->q_m = (uint8_t) strtoul(token, &err, 0);
708d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
709d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "basegraph")) {
710d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_BG;
711d819c083SNicolas Chautru 		ldpc_enc->basegraph = (uint8_t) strtoul(token, &err, 0);
712d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
713d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "z_c")) {
714d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_ZC;
715d819c083SNicolas Chautru 		ldpc_enc->z_c = (uint16_t) strtoul(token, &err, 0);
716d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
717d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "n_filler")) {
718d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_F;
719d819c083SNicolas Chautru 		ldpc_enc->n_filler = (uint16_t) strtoul(token, &err, 0);
720d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
721d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "code_block_mode")) {
722d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_CODE_BLOCK_MODE;
723d819c083SNicolas Chautru 		ldpc_enc->code_block_mode = (uint8_t) strtoul(token, &err, 0);
724d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
725d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "op_flags")) {
726d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_OP_FLAGS;
727d819c083SNicolas Chautru 		ret = parse_turbo_flags(token, &op_flags, vector->op_type);
728d819c083SNicolas Chautru 		if (!ret)
729d819c083SNicolas Chautru 			ldpc_enc->op_flags = op_flags;
730d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "expected_status")) {
731d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_EXPECTED_STATUS;
732d819c083SNicolas Chautru 		ret = parse_expected_status(token, &status, vector->op_type);
733d819c083SNicolas Chautru 		if (!ret)
734d819c083SNicolas Chautru 			vector->expected_status = status;
735d819c083SNicolas Chautru 	} else {
736d819c083SNicolas Chautru 		printf("Not valid ldpc enc key: '%s'\n", key_token);
737d819c083SNicolas Chautru 		return -1;
738d819c083SNicolas Chautru 	}
739d819c083SNicolas Chautru 
740d819c083SNicolas Chautru 	if (ret != 0) {
741d819c083SNicolas Chautru 		printf("Failed with convert '%s\t%s'\n", key_token, token);
742d819c083SNicolas Chautru 		return -1;
743d819c083SNicolas Chautru 	}
744d819c083SNicolas Chautru 
745d819c083SNicolas Chautru 	return 0;
746d819c083SNicolas Chautru }
747d819c083SNicolas Chautru 
748d819c083SNicolas Chautru /* parses LDPC decoder parameters and assigns to global variable */
749d819c083SNicolas Chautru static int
parse_ldpc_decoder_params(const char * key_token,char * token,struct test_bbdev_vector * vector)750d819c083SNicolas Chautru parse_ldpc_decoder_params(const char *key_token, char *token,
751d819c083SNicolas Chautru 		struct test_bbdev_vector *vector)
752d819c083SNicolas Chautru {
753d819c083SNicolas Chautru 	int ret = 0, status = 0;
754d819c083SNicolas Chautru 	uint32_t op_flags = 0;
755d819c083SNicolas Chautru 	char *err = NULL;
756d819c083SNicolas Chautru 
757d819c083SNicolas Chautru 	struct rte_bbdev_op_ldpc_dec *ldpc_dec = &vector->ldpc_dec;
758d819c083SNicolas Chautru 
759d819c083SNicolas Chautru 	if (starts_with(key_token, op_data_prefixes[DATA_INPUT]))
760d819c083SNicolas Chautru 		ret = parse_data_entry(key_token, token, vector,
761d819c083SNicolas Chautru 				DATA_INPUT,
762d819c083SNicolas Chautru 				op_data_prefixes[DATA_INPUT]);
763d819c083SNicolas Chautru 	else if (starts_with(key_token, "output"))
764d819c083SNicolas Chautru 		ret = parse_data_entry(key_token, token, vector,
765d819c083SNicolas Chautru 				DATA_HARD_OUTPUT,
766d819c083SNicolas Chautru 				"output");
767d819c083SNicolas Chautru 	else if (starts_with(key_token, op_data_prefixes[DATA_HARQ_INPUT]))
768d819c083SNicolas Chautru 		ret = parse_data_entry(key_token, token, vector,
769d819c083SNicolas Chautru 				DATA_HARQ_INPUT,
770d819c083SNicolas Chautru 				op_data_prefixes[DATA_HARQ_INPUT]);
771d819c083SNicolas Chautru 	else if (starts_with(key_token, op_data_prefixes[DATA_HARQ_OUTPUT]))
772d819c083SNicolas Chautru 		ret = parse_data_entry(key_token, token, vector,
773d819c083SNicolas Chautru 				DATA_HARQ_OUTPUT,
774d819c083SNicolas Chautru 				op_data_prefixes[DATA_HARQ_OUTPUT]);
775d819c083SNicolas Chautru 	else if (!strcmp(key_token, "e")) {
776d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_E;
777d819c083SNicolas Chautru 		ldpc_dec->cb_params.e = (uint32_t) strtoul(token, &err, 0);
778d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
779d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "ea")) {
780d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_EA;
781d819c083SNicolas Chautru 		ldpc_dec->tb_params.ea = (uint32_t) strtoul(token, &err, 0);
782d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
783d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "eb")) {
784d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_EB;
785d819c083SNicolas Chautru 		ldpc_dec->tb_params.eb = (uint32_t) strtoul(token, &err, 0);
786d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
787d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "c")) {
788d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_C;
789d819c083SNicolas Chautru 		ldpc_dec->tb_params.c = (uint8_t) strtoul(token, &err, 0);
790d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
791d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "cab")) {
792d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_CAB;
793d819c083SNicolas Chautru 		ldpc_dec->tb_params.cab = (uint8_t) strtoul(token, &err, 0);
794d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
795d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "rv_index")) {
796d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_RV_INDEX;
797d819c083SNicolas Chautru 		ldpc_dec->rv_index = (uint8_t) strtoul(token, &err, 0);
798d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
799d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "n_cb")) {
800d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_NCB;
801d819c083SNicolas Chautru 		ldpc_dec->n_cb = (uint16_t) strtoul(token, &err, 0);
802d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
803d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "r")) {
804d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_R;
805d819c083SNicolas Chautru 		ldpc_dec->tb_params.r = (uint8_t) strtoul(token, &err, 0);
806d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
807d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "q_m")) {
808d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_QM;
809d819c083SNicolas Chautru 		ldpc_dec->q_m = (uint8_t) strtoul(token, &err, 0);
810d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
811d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "basegraph")) {
812d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_BG;
813d819c083SNicolas Chautru 		ldpc_dec->basegraph = (uint8_t) strtoul(token, &err, 0);
814d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
815d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "z_c")) {
816d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_ZC;
817d819c083SNicolas Chautru 		ldpc_dec->z_c = (uint16_t) strtoul(token, &err, 0);
818d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
819d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "n_filler")) {
820d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_F;
821d819c083SNicolas Chautru 		ldpc_dec->n_filler = (uint16_t) strtoul(token, &err, 0);
822d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
823d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "expected_iter_count")) {
824d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_EXPECTED_ITER_COUNT;
825d819c083SNicolas Chautru 		ldpc_dec->iter_count = (uint8_t) strtoul(token, &err, 0);
826d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
827d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "iter_max")) {
828d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_ITER_MAX;
829d819c083SNicolas Chautru 		ldpc_dec->iter_max = (uint8_t) strtoul(token, &err, 0);
830d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
831d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "code_block_mode")) {
832d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_CODE_BLOCK_MODE;
833d819c083SNicolas Chautru 		ldpc_dec->code_block_mode = (uint8_t) strtoul(token, &err, 0);
834d819c083SNicolas Chautru 		ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
835d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "op_flags")) {
836d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_OP_FLAGS;
837d819c083SNicolas Chautru 		ret = parse_turbo_flags(token, &op_flags, vector->op_type);
838d819c083SNicolas Chautru 		if (!ret)
839d819c083SNicolas Chautru 			ldpc_dec->op_flags = op_flags;
840d819c083SNicolas Chautru 	} else if (!strcmp(key_token, "expected_status")) {
841d819c083SNicolas Chautru 		vector->mask |= TEST_BBDEV_VF_EXPECTED_STATUS;
842d819c083SNicolas Chautru 		ret = parse_expected_status(token, &status, vector->op_type);
843d819c083SNicolas Chautru 		if (!ret)
844d819c083SNicolas Chautru 			vector->expected_status = status;
845d819c083SNicolas Chautru 	} else {
846d819c083SNicolas Chautru 		printf("Not valid ldpc dec key: '%s'\n", key_token);
847d819c083SNicolas Chautru 		return -1;
848d819c083SNicolas Chautru 	}
849d819c083SNicolas Chautru 
850d819c083SNicolas Chautru 	if (ret != 0) {
851d819c083SNicolas Chautru 		printf("Failed with convert '%s\t%s'\n", key_token, token);
852d819c083SNicolas Chautru 		return -1;
853d819c083SNicolas Chautru 	}
854d819c083SNicolas Chautru 
855d819c083SNicolas Chautru 	return 0;
856d819c083SNicolas Chautru }
857d819c083SNicolas Chautru 
858f714a188SAmr Mokhtar /* checks the type of key and assigns data */
859f714a188SAmr Mokhtar static int
parse_entry(char * entry,struct test_bbdev_vector * vector)860f714a188SAmr Mokhtar parse_entry(char *entry, struct test_bbdev_vector *vector)
861f714a188SAmr Mokhtar {
862f714a188SAmr Mokhtar 	int ret = 0;
863f714a188SAmr Mokhtar 	char *token, *key_token;
864f714a188SAmr Mokhtar 	enum rte_bbdev_op_type op_type = RTE_BBDEV_OP_NONE;
865f714a188SAmr Mokhtar 
866f714a188SAmr Mokhtar 	if (entry == NULL) {
867f714a188SAmr Mokhtar 		printf("Expected entry value\n");
868f714a188SAmr Mokhtar 		return -1;
869f714a188SAmr Mokhtar 	}
870f714a188SAmr Mokhtar 
871f714a188SAmr Mokhtar 	/* get key */
872f714a188SAmr Mokhtar 	token = strtok(entry, ENTRY_DELIMITER);
873f714a188SAmr Mokhtar 	key_token = token;
874f714a188SAmr Mokhtar 	/* get values for key */
875f714a188SAmr Mokhtar 	token = strtok(NULL, ENTRY_DELIMITER);
876f714a188SAmr Mokhtar 
877f714a188SAmr Mokhtar 	if (key_token == NULL || token == NULL) {
878f714a188SAmr Mokhtar 		printf("Expected 'key = values' but was '%.40s'..\n", entry);
879f714a188SAmr Mokhtar 		return -1;
880f714a188SAmr Mokhtar 	}
881f714a188SAmr Mokhtar 	trim_space(key_token);
882f714a188SAmr Mokhtar 
883f714a188SAmr Mokhtar 	/* first key_token has to specify type of operation */
884f714a188SAmr Mokhtar 	if (vector->op_type == RTE_BBDEV_OP_NONE) {
885f714a188SAmr Mokhtar 		if (!strcmp(key_token, "op_type")) {
886f714a188SAmr Mokhtar 			ret = op_turbo_type_strtol(token, &op_type);
887f714a188SAmr Mokhtar 			if (!ret)
888f714a188SAmr Mokhtar 				vector->op_type = op_type;
889f714a188SAmr Mokhtar 			return (!ret) ? 0 : -1;
890f714a188SAmr Mokhtar 		}
891f714a188SAmr Mokhtar 		printf("First key_token (%s) does not specify op_type\n",
892f714a188SAmr Mokhtar 				key_token);
893f714a188SAmr Mokhtar 		return -1;
894f714a188SAmr Mokhtar 	}
895f714a188SAmr Mokhtar 
896f714a188SAmr Mokhtar 	/* compare keys */
897f714a188SAmr Mokhtar 	if (vector->op_type == RTE_BBDEV_OP_TURBO_DEC) {
898f714a188SAmr Mokhtar 		if (parse_decoder_params(key_token, token, vector) == -1)
899f714a188SAmr Mokhtar 			return -1;
900f714a188SAmr Mokhtar 	} else if (vector->op_type == RTE_BBDEV_OP_TURBO_ENC) {
901f714a188SAmr Mokhtar 		if (parse_encoder_params(key_token, token, vector) == -1)
902f714a188SAmr Mokhtar 			return -1;
903d819c083SNicolas Chautru 	} else if (vector->op_type == RTE_BBDEV_OP_LDPC_ENC) {
904d819c083SNicolas Chautru 		if (parse_ldpc_encoder_params(key_token, token, vector) == -1)
905d819c083SNicolas Chautru 			return -1;
906d819c083SNicolas Chautru 	} else if (vector->op_type == RTE_BBDEV_OP_LDPC_DEC) {
907d819c083SNicolas Chautru 		if (parse_ldpc_decoder_params(key_token, token, vector) == -1)
908d819c083SNicolas Chautru 			return -1;
909f714a188SAmr Mokhtar 	}
910f714a188SAmr Mokhtar 
911f714a188SAmr Mokhtar 	return 0;
912f714a188SAmr Mokhtar }
913f714a188SAmr Mokhtar 
914f714a188SAmr Mokhtar static int
check_decoder_segments(struct test_bbdev_vector * vector)915f714a188SAmr Mokhtar check_decoder_segments(struct test_bbdev_vector *vector)
916f714a188SAmr Mokhtar {
917f714a188SAmr Mokhtar 	unsigned char i;
918f714a188SAmr Mokhtar 	struct rte_bbdev_op_turbo_dec *turbo_dec = &vector->turbo_dec;
919f714a188SAmr Mokhtar 
920f714a188SAmr Mokhtar 	if (vector->entries[DATA_INPUT].nb_segments == 0)
921f714a188SAmr Mokhtar 		return -1;
922f714a188SAmr Mokhtar 
923f714a188SAmr Mokhtar 	for (i = 0; i < vector->entries[DATA_INPUT].nb_segments; i++)
924f714a188SAmr Mokhtar 		if (vector->entries[DATA_INPUT].segments[i].addr == NULL)
925f714a188SAmr Mokhtar 			return -1;
926f714a188SAmr Mokhtar 
927f714a188SAmr Mokhtar 	if (vector->entries[DATA_HARD_OUTPUT].nb_segments == 0)
928f714a188SAmr Mokhtar 		return -1;
929f714a188SAmr Mokhtar 
930f714a188SAmr Mokhtar 	for (i = 0; i < vector->entries[DATA_HARD_OUTPUT].nb_segments;
931f714a188SAmr Mokhtar 			i++)
932f714a188SAmr Mokhtar 		if (vector->entries[DATA_HARD_OUTPUT].segments[i].addr == NULL)
933f714a188SAmr Mokhtar 			return -1;
934f714a188SAmr Mokhtar 
935f714a188SAmr Mokhtar 	if ((turbo_dec->op_flags & RTE_BBDEV_TURBO_SOFT_OUTPUT) &&
936f714a188SAmr Mokhtar 			(vector->entries[DATA_SOFT_OUTPUT].nb_segments == 0))
937f714a188SAmr Mokhtar 		return -1;
938f714a188SAmr Mokhtar 
939f714a188SAmr Mokhtar 	for (i = 0; i < vector->entries[DATA_SOFT_OUTPUT].nb_segments;
940f714a188SAmr Mokhtar 			i++)
941f714a188SAmr Mokhtar 		if (vector->entries[DATA_SOFT_OUTPUT].segments[i].addr == NULL)
942f714a188SAmr Mokhtar 			return -1;
943f714a188SAmr Mokhtar 
944f714a188SAmr Mokhtar 	return 0;
945f714a188SAmr Mokhtar }
946f714a188SAmr Mokhtar 
947f714a188SAmr Mokhtar static int
check_ldpc_decoder_segments(struct test_bbdev_vector * vector)948d819c083SNicolas Chautru check_ldpc_decoder_segments(struct test_bbdev_vector *vector)
949d819c083SNicolas Chautru {
950d819c083SNicolas Chautru 	unsigned char i;
951d819c083SNicolas Chautru 	struct rte_bbdev_op_ldpc_dec *ldpc_dec = &vector->ldpc_dec;
952d819c083SNicolas Chautru 
953d819c083SNicolas Chautru 	for (i = 0; i < vector->entries[DATA_INPUT].nb_segments; i++)
954d819c083SNicolas Chautru 		if (vector->entries[DATA_INPUT].segments[i].addr == NULL)
955d819c083SNicolas Chautru 			return -1;
956d819c083SNicolas Chautru 
957d819c083SNicolas Chautru 	for (i = 0; i < vector->entries[DATA_HARD_OUTPUT].nb_segments; i++)
958d819c083SNicolas Chautru 		if (vector->entries[DATA_HARD_OUTPUT].segments[i].addr == NULL)
959d819c083SNicolas Chautru 			return -1;
960d819c083SNicolas Chautru 
961d819c083SNicolas Chautru 	if ((ldpc_dec->op_flags & RTE_BBDEV_LDPC_SOFT_OUT_ENABLE) &&
962d819c083SNicolas Chautru 			(vector->entries[DATA_SOFT_OUTPUT].nb_segments == 0))
963d819c083SNicolas Chautru 		return -1;
964d819c083SNicolas Chautru 
965d819c083SNicolas Chautru 	for (i = 0; i < vector->entries[DATA_SOFT_OUTPUT].nb_segments; i++)
966d819c083SNicolas Chautru 		if (vector->entries[DATA_SOFT_OUTPUT].segments[i].addr == NULL)
967d819c083SNicolas Chautru 			return -1;
968d819c083SNicolas Chautru 
969d819c083SNicolas Chautru 	if ((ldpc_dec->op_flags & RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE) &&
970d819c083SNicolas Chautru 			(vector->entries[DATA_HARQ_OUTPUT].nb_segments == 0))
971d819c083SNicolas Chautru 		return -1;
972d819c083SNicolas Chautru 
973d819c083SNicolas Chautru 	for (i = 0; i < vector->entries[DATA_HARQ_OUTPUT].nb_segments; i++)
974d819c083SNicolas Chautru 		if (vector->entries[DATA_HARQ_OUTPUT].segments[i].addr == NULL)
975d819c083SNicolas Chautru 			return -1;
976d819c083SNicolas Chautru 
977d819c083SNicolas Chautru 	return 0;
978d819c083SNicolas Chautru }
979d819c083SNicolas Chautru 
980d819c083SNicolas Chautru static int
check_decoder_llr_spec(struct test_bbdev_vector * vector)981f714a188SAmr Mokhtar check_decoder_llr_spec(struct test_bbdev_vector *vector)
982f714a188SAmr Mokhtar {
983f714a188SAmr Mokhtar 	struct rte_bbdev_op_turbo_dec *turbo_dec = &vector->turbo_dec;
984f714a188SAmr Mokhtar 
985f714a188SAmr Mokhtar 	/* Check input LLR sign formalism specification */
986f714a188SAmr Mokhtar 	if ((turbo_dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN) &&
987f714a188SAmr Mokhtar 			(turbo_dec->op_flags &
988f714a188SAmr Mokhtar 			RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN)) {
989f714a188SAmr Mokhtar 		printf(
990f714a188SAmr Mokhtar 			"Both positive and negative LLR input flags were set!\n");
991f714a188SAmr Mokhtar 		return -1;
992f714a188SAmr Mokhtar 	}
993f714a188SAmr Mokhtar 	if (!(turbo_dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN) &&
994f714a188SAmr Mokhtar 			!(turbo_dec->op_flags &
995f714a188SAmr Mokhtar 			RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN)) {
996f714a188SAmr Mokhtar 		printf(
997d819c083SNicolas Chautru 			"INFO: input LLR sign formalism was not specified and will be set to negative LLR for '1' bit\n");
998f714a188SAmr Mokhtar 		turbo_dec->op_flags |= RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN;
999f714a188SAmr Mokhtar 	}
1000f714a188SAmr Mokhtar 
1001f714a188SAmr Mokhtar 	if (!(turbo_dec->op_flags & RTE_BBDEV_TURBO_SOFT_OUTPUT))
1002f714a188SAmr Mokhtar 		return 0;
1003f714a188SAmr Mokhtar 
1004f714a188SAmr Mokhtar 	/* Check output LLR sign formalism specification */
1005f714a188SAmr Mokhtar 	if ((turbo_dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT) &&
1006f714a188SAmr Mokhtar 			(turbo_dec->op_flags &
1007f714a188SAmr Mokhtar 			RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT)) {
1008f714a188SAmr Mokhtar 		printf(
1009f714a188SAmr Mokhtar 			"Both positive and negative LLR output flags were set!\n");
1010f714a188SAmr Mokhtar 		return -1;
1011f714a188SAmr Mokhtar 	}
1012f714a188SAmr Mokhtar 	if (!(turbo_dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT) &&
1013f714a188SAmr Mokhtar 			!(turbo_dec->op_flags &
1014f714a188SAmr Mokhtar 			RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT)) {
1015f714a188SAmr Mokhtar 		printf(
1016d819c083SNicolas Chautru 			"INFO: soft output LLR sign formalism was not specified and will be set to negative LLR for '1' bit\n");
1017f714a188SAmr Mokhtar 		turbo_dec->op_flags |=
1018f714a188SAmr Mokhtar 				RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT;
1019f714a188SAmr Mokhtar 	}
1020f714a188SAmr Mokhtar 
1021f714a188SAmr Mokhtar 	return 0;
1022f714a188SAmr Mokhtar }
1023f714a188SAmr Mokhtar 
1024d819c083SNicolas Chautru static int
check_decoder_op_flags(struct test_bbdev_vector * vector)1025d819c083SNicolas Chautru check_decoder_op_flags(struct test_bbdev_vector *vector)
1026d819c083SNicolas Chautru {
1027d819c083SNicolas Chautru 	struct rte_bbdev_op_turbo_dec *turbo_dec = &vector->turbo_dec;
1028d819c083SNicolas Chautru 
1029d819c083SNicolas Chautru 	if ((turbo_dec->op_flags & RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP) &&
1030d819c083SNicolas Chautru 		!(turbo_dec->op_flags & RTE_BBDEV_TURBO_CRC_TYPE_24B)) {
1031d819c083SNicolas Chautru 		printf(
1032d819c083SNicolas Chautru 			"WARNING: RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP flag is missing RTE_BBDEV_TURBO_CRC_TYPE_24B\n");
1033d819c083SNicolas Chautru 		return -1;
1034d819c083SNicolas Chautru 	}
1035d819c083SNicolas Chautru 
1036d819c083SNicolas Chautru 	return 0;
1037d819c083SNicolas Chautru }
1038d819c083SNicolas Chautru 
1039f714a188SAmr Mokhtar /* checks decoder parameters */
1040f714a188SAmr Mokhtar static int
check_decoder(struct test_bbdev_vector * vector)1041f714a188SAmr Mokhtar check_decoder(struct test_bbdev_vector *vector)
1042f714a188SAmr Mokhtar {
1043f714a188SAmr Mokhtar 	struct rte_bbdev_op_turbo_dec *turbo_dec = &vector->turbo_dec;
1044f714a188SAmr Mokhtar 	const int mask = vector->mask;
1045f714a188SAmr Mokhtar 
1046f714a188SAmr Mokhtar 	if (check_decoder_segments(vector) < 0)
1047f714a188SAmr Mokhtar 		return -1;
1048f714a188SAmr Mokhtar 
1049f714a188SAmr Mokhtar 	if (check_decoder_llr_spec(vector) < 0)
1050f714a188SAmr Mokhtar 		return -1;
1051f714a188SAmr Mokhtar 
1052d819c083SNicolas Chautru 	if (check_decoder_op_flags(vector) < 0)
1053d819c083SNicolas Chautru 		return -1;
1054d819c083SNicolas Chautru 
1055f714a188SAmr Mokhtar 	/* Check which params were set */
1056f714a188SAmr Mokhtar 	if (!(mask & TEST_BBDEV_VF_CODE_BLOCK_MODE)) {
1057f714a188SAmr Mokhtar 		printf(
1058f714a188SAmr Mokhtar 			"WARNING: code_block_mode was not specified in vector file and will be set to 1 (0 - TB Mode, 1 - CB mode)\n");
105948fc315fSNicolas Chautru 		turbo_dec->code_block_mode = RTE_BBDEV_CODE_BLOCK;
1060f714a188SAmr Mokhtar 	}
106148fc315fSNicolas Chautru 	if (turbo_dec->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1062f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_EA))
1063f714a188SAmr Mokhtar 			printf(
1064f714a188SAmr Mokhtar 				"WARNING: ea was not specified in vector file and will be set to 0\n");
1065f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_EB))
1066f714a188SAmr Mokhtar 			printf(
1067f714a188SAmr Mokhtar 				"WARNING: eb was not specified in vector file and will be set to 0\n");
1068f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_K_NEG))
1069f714a188SAmr Mokhtar 			printf(
1070f714a188SAmr Mokhtar 				"WARNING: k_neg was not specified in vector file and will be set to 0\n");
1071f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_K_POS))
1072f714a188SAmr Mokhtar 			printf(
1073f714a188SAmr Mokhtar 				"WARNING: k_pos was not specified in vector file and will be set to 0\n");
1074f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_C_NEG))
1075f714a188SAmr Mokhtar 			printf(
1076f714a188SAmr Mokhtar 				"WARNING: c_neg was not specified in vector file and will be set to 0\n");
1077f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_C)) {
1078f714a188SAmr Mokhtar 			printf(
1079f714a188SAmr Mokhtar 				"WARNING: c was not specified in vector file and will be set to 1\n");
1080f714a188SAmr Mokhtar 			turbo_dec->tb_params.c = 1;
1081f714a188SAmr Mokhtar 		}
1082f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_CAB))
1083f714a188SAmr Mokhtar 			printf(
1084f714a188SAmr Mokhtar 				"WARNING: cab was not specified in vector file and will be set to 0\n");
10850b98d574SKamil Chalupnik 		if (!(mask & TEST_BBDEV_VF_R))
10860b98d574SKamil Chalupnik 			printf(
10870b98d574SKamil Chalupnik 				"WARNING: r was not specified in vector file and will be set to 0\n");
1088f714a188SAmr Mokhtar 	} else {
1089f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_E))
1090f714a188SAmr Mokhtar 			printf(
1091f714a188SAmr Mokhtar 				"WARNING: e was not specified in vector file and will be set to 0\n");
1092f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_K))
1093f714a188SAmr Mokhtar 			printf(
1094f714a188SAmr Mokhtar 				"WARNING: k was not specified in vector file and will be set to 0\n");
1095f714a188SAmr Mokhtar 	}
1096f714a188SAmr Mokhtar 	if (!(mask & TEST_BBDEV_VF_RV_INDEX))
1097f714a188SAmr Mokhtar 		printf(
1098d819c083SNicolas Chautru 			"INFO: rv_index was not specified in vector file and will be set to 0\n");
1099f714a188SAmr Mokhtar 	if (!(mask & TEST_BBDEV_VF_ITER_MIN))
1100f714a188SAmr Mokhtar 		printf(
1101f714a188SAmr Mokhtar 			"WARNING: iter_min was not specified in vector file and will be set to 0\n");
1102f714a188SAmr Mokhtar 	if (!(mask & TEST_BBDEV_VF_ITER_MAX))
1103f714a188SAmr Mokhtar 		printf(
1104f714a188SAmr Mokhtar 			"WARNING: iter_max was not specified in vector file and will be set to 0\n");
1105f714a188SAmr Mokhtar 	if (!(mask & TEST_BBDEV_VF_EXPECTED_ITER_COUNT))
1106f714a188SAmr Mokhtar 		printf(
1107f714a188SAmr Mokhtar 			"WARNING: expected_iter_count was not specified in vector file and iter_count will not be validated\n");
1108f714a188SAmr Mokhtar 	if (!(mask & TEST_BBDEV_VF_EXT_SCALE))
1109f714a188SAmr Mokhtar 		printf(
1110f714a188SAmr Mokhtar 			"WARNING: ext_scale was not specified in vector file and will be set to 0\n");
1111f714a188SAmr Mokhtar 	if (!(mask & TEST_BBDEV_VF_OP_FLAGS)) {
1112f714a188SAmr Mokhtar 		printf(
1113f714a188SAmr Mokhtar 			"WARNING: op_flags was not specified in vector file and capabilities will not be validated\n");
1114f714a188SAmr Mokhtar 		turbo_dec->num_maps = 0;
1115f714a188SAmr Mokhtar 	} else if (!(turbo_dec->op_flags & RTE_BBDEV_TURBO_MAP_DEC) &&
1116f714a188SAmr Mokhtar 			mask & TEST_BBDEV_VF_NUM_MAPS) {
1117f714a188SAmr Mokhtar 		printf(
1118d819c083SNicolas Chautru 			"INFO: RTE_BBDEV_TURBO_MAP_DEC was not set in vector file and num_maps will be set to 0\n");
1119f714a188SAmr Mokhtar 		turbo_dec->num_maps = 0;
1120f714a188SAmr Mokhtar 	}
1121f714a188SAmr Mokhtar 	if (!(mask & TEST_BBDEV_VF_EXPECTED_STATUS))
1122f714a188SAmr Mokhtar 		printf(
1123f714a188SAmr Mokhtar 			"WARNING: expected_status was not specified in vector file and will be set to 0\n");
1124f714a188SAmr Mokhtar 	return 0;
1125f714a188SAmr Mokhtar }
1126f714a188SAmr Mokhtar 
1127d819c083SNicolas Chautru /* checks LDPC decoder parameters */
1128d819c083SNicolas Chautru static int
check_ldpc_decoder(struct test_bbdev_vector * vector)1129d819c083SNicolas Chautru check_ldpc_decoder(struct test_bbdev_vector *vector)
1130d819c083SNicolas Chautru {
1131d819c083SNicolas Chautru 	struct rte_bbdev_op_ldpc_dec *ldpc_dec = &vector->ldpc_dec;
1132d819c083SNicolas Chautru 	const int mask = vector->mask;
1133d819c083SNicolas Chautru 
1134d819c083SNicolas Chautru 	if (check_ldpc_decoder_segments(vector) < 0)
1135d819c083SNicolas Chautru 		return -1;
1136d819c083SNicolas Chautru 
1137d819c083SNicolas Chautru 	/*
1138d819c083SNicolas Chautru 	 * if (check_ldpc_decoder_llr_spec(vector) < 0)
1139d819c083SNicolas Chautru 	 *	return -1;
1140d819c083SNicolas Chautru 	 *
1141d819c083SNicolas Chautru 	 * if (check_ldpc_decoder_op_flags(vector) < 0)
1142d819c083SNicolas Chautru 	 *	return -1;
1143d819c083SNicolas Chautru 	 */
1144d819c083SNicolas Chautru 
1145d819c083SNicolas Chautru 	/* Check which params were set */
1146d819c083SNicolas Chautru 	if (!(mask & TEST_BBDEV_VF_CODE_BLOCK_MODE)) {
1147d819c083SNicolas Chautru 		printf(
1148d819c083SNicolas Chautru 			"WARNING: code_block_mode was not specified in vector file and will be set to 1 (0 - TB Mode, 1 - CB mode)\n");
114948fc315fSNicolas Chautru 		ldpc_dec->code_block_mode = RTE_BBDEV_CODE_BLOCK;
1150d819c083SNicolas Chautru 	}
115148fc315fSNicolas Chautru 	if (ldpc_dec->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1152d819c083SNicolas Chautru 		if (!(mask & TEST_BBDEV_VF_EA))
1153d819c083SNicolas Chautru 			printf(
1154d819c083SNicolas Chautru 				"WARNING: ea was not specified in vector file and will be set to 0\n");
1155d819c083SNicolas Chautru 		if (!(mask & TEST_BBDEV_VF_EB))
1156d819c083SNicolas Chautru 			printf(
1157d819c083SNicolas Chautru 				"WARNING: eb was not specified in vector file and will be set to 0\n");
1158d819c083SNicolas Chautru 		if (!(mask & TEST_BBDEV_VF_C)) {
1159d819c083SNicolas Chautru 			printf(
1160d819c083SNicolas Chautru 				"WARNING: c was not specified in vector file and will be set to 1\n");
1161d819c083SNicolas Chautru 			ldpc_dec->tb_params.c = 1;
1162d819c083SNicolas Chautru 		}
1163d819c083SNicolas Chautru 		if (!(mask & TEST_BBDEV_VF_CAB))
1164d819c083SNicolas Chautru 			printf(
1165d819c083SNicolas Chautru 				"WARNING: cab was not specified in vector file and will be set to 0\n");
1166d819c083SNicolas Chautru 		if (!(mask & TEST_BBDEV_VF_R))
1167d819c083SNicolas Chautru 			printf(
1168d819c083SNicolas Chautru 				"WARNING: r was not specified in vector file and will be set to 0\n");
1169d819c083SNicolas Chautru 	} else {
1170d819c083SNicolas Chautru 		if (!(mask & TEST_BBDEV_VF_E))
1171d819c083SNicolas Chautru 			printf(
1172d819c083SNicolas Chautru 				"WARNING: e was not specified in vector file and will be set to 0\n");
1173d819c083SNicolas Chautru 	}
1174d819c083SNicolas Chautru 	if (!(mask & TEST_BBDEV_VF_RV_INDEX))
1175d819c083SNicolas Chautru 		printf(
1176d819c083SNicolas Chautru 			"INFO: rv_index was not specified in vector file and will be set to 0\n");
1177d819c083SNicolas Chautru 	if (!(mask & TEST_BBDEV_VF_ITER_MAX))
1178d819c083SNicolas Chautru 		printf(
1179d819c083SNicolas Chautru 			"WARNING: iter_max was not specified in vector file and will be set to 0\n");
1180d819c083SNicolas Chautru 	if (!(mask & TEST_BBDEV_VF_EXPECTED_ITER_COUNT))
1181d819c083SNicolas Chautru 		printf(
1182d819c083SNicolas Chautru 			"WARNING: expected_iter_count was not specified in vector file and iter_count will not be validated\n");
1183d819c083SNicolas Chautru 	if (!(mask & TEST_BBDEV_VF_OP_FLAGS)) {
1184d819c083SNicolas Chautru 		printf(
1185d819c083SNicolas Chautru 			"WARNING: op_flags was not specified in vector file and capabilities will not be validated\n");
1186d819c083SNicolas Chautru 	}
1187d819c083SNicolas Chautru 	if (!(mask & TEST_BBDEV_VF_EXPECTED_STATUS))
1188d819c083SNicolas Chautru 		printf(
1189d819c083SNicolas Chautru 			"WARNING: expected_status was not specified in vector file and will be set to 0\n");
1190d819c083SNicolas Chautru 	return 0;
1191d819c083SNicolas Chautru }
1192d819c083SNicolas Chautru 
1193f714a188SAmr Mokhtar /* checks encoder parameters */
1194f714a188SAmr Mokhtar static int
check_encoder(struct test_bbdev_vector * vector)1195f714a188SAmr Mokhtar check_encoder(struct test_bbdev_vector *vector)
1196f714a188SAmr Mokhtar {
1197f714a188SAmr Mokhtar 	unsigned char i;
1198f714a188SAmr Mokhtar 	const int mask = vector->mask;
1199f714a188SAmr Mokhtar 
1200f714a188SAmr Mokhtar 	if (vector->entries[DATA_INPUT].nb_segments == 0)
1201f714a188SAmr Mokhtar 		return -1;
1202f714a188SAmr Mokhtar 
1203f714a188SAmr Mokhtar 	for (i = 0; i < vector->entries[DATA_INPUT].nb_segments; i++)
1204f714a188SAmr Mokhtar 		if (vector->entries[DATA_INPUT].segments[i].addr == NULL)
1205f714a188SAmr Mokhtar 			return -1;
1206f714a188SAmr Mokhtar 
1207f714a188SAmr Mokhtar 	if (vector->entries[DATA_HARD_OUTPUT].nb_segments == 0)
1208f714a188SAmr Mokhtar 		return -1;
1209f714a188SAmr Mokhtar 
1210f714a188SAmr Mokhtar 	for (i = 0; i < vector->entries[DATA_HARD_OUTPUT].nb_segments; i++)
1211f714a188SAmr Mokhtar 		if (vector->entries[DATA_HARD_OUTPUT].segments[i].addr == NULL)
1212f714a188SAmr Mokhtar 			return -1;
1213f714a188SAmr Mokhtar 
1214f714a188SAmr Mokhtar 	if (!(mask & TEST_BBDEV_VF_CODE_BLOCK_MODE)) {
1215f714a188SAmr Mokhtar 		printf(
1216f714a188SAmr Mokhtar 			"WARNING: code_block_mode was not specified in vector file and will be set to 1\n");
121748fc315fSNicolas Chautru 		vector->turbo_enc.code_block_mode = RTE_BBDEV_CODE_BLOCK;
1218f714a188SAmr Mokhtar 	}
121948fc315fSNicolas Chautru 	if (vector->turbo_enc.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1220f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_EA) && (vector->turbo_enc.op_flags &
1221f714a188SAmr Mokhtar 				RTE_BBDEV_TURBO_RATE_MATCH))
1222f714a188SAmr Mokhtar 			printf(
1223f714a188SAmr Mokhtar 				"WARNING: ea was not specified in vector file and will be set to 0\n");
1224f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_EB) && (vector->turbo_enc.op_flags &
1225f714a188SAmr Mokhtar 				RTE_BBDEV_TURBO_RATE_MATCH))
1226f714a188SAmr Mokhtar 			printf(
1227f714a188SAmr Mokhtar 				"WARNING: eb was not specified in vector file and will be set to 0\n");
1228f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_K_NEG))
1229f714a188SAmr Mokhtar 			printf(
1230f714a188SAmr Mokhtar 				"WARNING: k_neg was not specified in vector file and will be set to 0\n");
1231f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_K_POS))
1232f714a188SAmr Mokhtar 			printf(
1233f714a188SAmr Mokhtar 				"WARNING: k_pos was not specified in vector file and will be set to 0\n");
1234f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_C_NEG))
1235f714a188SAmr Mokhtar 			printf(
1236f714a188SAmr Mokhtar 				"WARNING: c_neg was not specified in vector file and will be set to 0\n");
1237f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_C)) {
1238f714a188SAmr Mokhtar 			printf(
1239f714a188SAmr Mokhtar 				"WARNING: c was not specified in vector file and will be set to 1\n");
1240f714a188SAmr Mokhtar 			vector->turbo_enc.tb_params.c = 1;
1241f714a188SAmr Mokhtar 		}
1242f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_CAB) && (vector->turbo_enc.op_flags &
1243f714a188SAmr Mokhtar 				RTE_BBDEV_TURBO_RATE_MATCH))
1244f714a188SAmr Mokhtar 			printf(
1245f714a188SAmr Mokhtar 				"WARNING: cab was not specified in vector file and will be set to 0\n");
1246f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_NCB_NEG))
1247f714a188SAmr Mokhtar 			printf(
1248f714a188SAmr Mokhtar 				"WARNING: ncb_neg was not specified in vector file and will be set to 0\n");
1249f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_NCB_POS))
1250f714a188SAmr Mokhtar 			printf(
1251f714a188SAmr Mokhtar 				"WARNING: ncb_pos was not specified in vector file and will be set to 0\n");
1252f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_R))
1253f714a188SAmr Mokhtar 			printf(
1254f714a188SAmr Mokhtar 				"WARNING: r was not specified in vector file and will be set to 0\n");
1255f714a188SAmr Mokhtar 	} else {
1256f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_E) && (vector->turbo_enc.op_flags &
1257f714a188SAmr Mokhtar 				RTE_BBDEV_TURBO_RATE_MATCH))
1258f714a188SAmr Mokhtar 			printf(
1259f714a188SAmr Mokhtar 				"WARNING: e was not specified in vector file and will be set to 0\n");
1260f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_K))
1261f714a188SAmr Mokhtar 			printf(
1262f714a188SAmr Mokhtar 				"WARNING: k was not specified in vector file and will be set to 0\n");
1263f714a188SAmr Mokhtar 		if (!(mask & TEST_BBDEV_VF_NCB))
1264f714a188SAmr Mokhtar 			printf(
1265f714a188SAmr Mokhtar 				"WARNING: ncb was not specified in vector file and will be set to 0\n");
1266f714a188SAmr Mokhtar 	}
1267f714a188SAmr Mokhtar 	if (!(mask & TEST_BBDEV_VF_RV_INDEX))
1268f714a188SAmr Mokhtar 		printf(
1269d819c083SNicolas Chautru 			"INFO: rv_index was not specified in vector file and will be set to 0\n");
1270f714a188SAmr Mokhtar 	if (!(mask & TEST_BBDEV_VF_OP_FLAGS))
1271f714a188SAmr Mokhtar 		printf(
1272d819c083SNicolas Chautru 			"INFO: op_flags was not specified in vector file and capabilities will not be validated\n");
1273d819c083SNicolas Chautru 	if (!(mask & TEST_BBDEV_VF_EXPECTED_STATUS))
1274d819c083SNicolas Chautru 		printf(
1275d819c083SNicolas Chautru 			"WARNING: expected_status was not specified in vector file and will be set to 0\n");
1276d819c083SNicolas Chautru 
1277d819c083SNicolas Chautru 	return 0;
1278d819c083SNicolas Chautru }
1279d819c083SNicolas Chautru 
1280d819c083SNicolas Chautru 
1281d819c083SNicolas Chautru /* checks encoder parameters */
1282d819c083SNicolas Chautru static int
check_ldpc_encoder(struct test_bbdev_vector * vector)1283d819c083SNicolas Chautru check_ldpc_encoder(struct test_bbdev_vector *vector)
1284d819c083SNicolas Chautru {
1285d819c083SNicolas Chautru 	unsigned char i;
1286d819c083SNicolas Chautru 	const int mask = vector->mask;
1287d819c083SNicolas Chautru 
1288d819c083SNicolas Chautru 	if (vector->entries[DATA_INPUT].nb_segments == 0)
1289d819c083SNicolas Chautru 		return -1;
1290d819c083SNicolas Chautru 
1291d819c083SNicolas Chautru 	for (i = 0; i < vector->entries[DATA_INPUT].nb_segments; i++)
1292d819c083SNicolas Chautru 		if (vector->entries[DATA_INPUT].segments[i].addr == NULL)
1293d819c083SNicolas Chautru 			return -1;
1294d819c083SNicolas Chautru 
1295d819c083SNicolas Chautru 	if (vector->entries[DATA_HARD_OUTPUT].nb_segments == 0)
1296d819c083SNicolas Chautru 		return -1;
1297d819c083SNicolas Chautru 
1298d819c083SNicolas Chautru 	for (i = 0; i < vector->entries[DATA_HARD_OUTPUT].nb_segments; i++)
1299d819c083SNicolas Chautru 		if (vector->entries[DATA_HARD_OUTPUT].segments[i].addr == NULL)
1300d819c083SNicolas Chautru 			return -1;
1301d819c083SNicolas Chautru 
1302d819c083SNicolas Chautru 	if (!(mask & TEST_BBDEV_VF_CODE_BLOCK_MODE)) {
1303d819c083SNicolas Chautru 		printf(
1304d819c083SNicolas Chautru 			"WARNING: code_block_mode was not specified in vector file and will be set to 1\n");
130548fc315fSNicolas Chautru 		vector->turbo_enc.code_block_mode = RTE_BBDEV_CODE_BLOCK;
1306d819c083SNicolas Chautru 	}
130748fc315fSNicolas Chautru 	if (vector->turbo_enc.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1308d819c083SNicolas Chautru 	} else {
1309d819c083SNicolas Chautru 		if (!(mask & TEST_BBDEV_VF_E) && (vector->turbo_enc.op_flags &
1310d819c083SNicolas Chautru 				RTE_BBDEV_TURBO_RATE_MATCH))
1311d819c083SNicolas Chautru 			printf(
1312d819c083SNicolas Chautru 				"WARNING: e was not specified in vector file and will be set to 0\n");
1313d819c083SNicolas Chautru 		if (!(mask & TEST_BBDEV_VF_NCB))
1314d819c083SNicolas Chautru 			printf(
1315d819c083SNicolas Chautru 				"WARNING: ncb was not specified in vector file and will be set to 0\n");
1316d819c083SNicolas Chautru 	}
1317d819c083SNicolas Chautru 	if (!(mask & TEST_BBDEV_VF_BG))
1318d819c083SNicolas Chautru 		printf(
1319d819c083SNicolas Chautru 			"WARNING: BG was not specified in vector file and will be set to 0\n");
1320d819c083SNicolas Chautru 	if (!(mask & TEST_BBDEV_VF_ZC))
1321d819c083SNicolas Chautru 		printf(
1322d819c083SNicolas Chautru 			"WARNING: Zc was not specified in vector file and will be set to 0\n");
1323d819c083SNicolas Chautru 	if (!(mask & TEST_BBDEV_VF_RV_INDEX))
1324d819c083SNicolas Chautru 		printf(
1325d819c083SNicolas Chautru 			"INFO: rv_index was not specified in vector file and will be set to 0\n");
1326d819c083SNicolas Chautru 	if (!(mask & TEST_BBDEV_VF_OP_FLAGS))
1327d819c083SNicolas Chautru 		printf(
1328d819c083SNicolas Chautru 			"INFO: op_flags was not specified in vector file and capabilities will not be validated\n");
1329f714a188SAmr Mokhtar 	if (!(mask & TEST_BBDEV_VF_EXPECTED_STATUS))
1330f714a188SAmr Mokhtar 		printf(
1331f714a188SAmr Mokhtar 			"WARNING: expected_status was not specified in vector file and will be set to 0\n");
1332f714a188SAmr Mokhtar 
1333f714a188SAmr Mokhtar 	return 0;
1334f714a188SAmr Mokhtar }
1335f714a188SAmr Mokhtar 
1336f714a188SAmr Mokhtar static int
bbdev_check_vector(struct test_bbdev_vector * vector)1337f714a188SAmr Mokhtar bbdev_check_vector(struct test_bbdev_vector *vector)
1338f714a188SAmr Mokhtar {
1339f714a188SAmr Mokhtar 	if (vector->op_type == RTE_BBDEV_OP_TURBO_DEC) {
1340f714a188SAmr Mokhtar 		if (check_decoder(vector) == -1)
1341f714a188SAmr Mokhtar 			return -1;
1342f714a188SAmr Mokhtar 	} else if (vector->op_type == RTE_BBDEV_OP_TURBO_ENC) {
1343f714a188SAmr Mokhtar 		if (check_encoder(vector) == -1)
1344f714a188SAmr Mokhtar 			return -1;
1345d819c083SNicolas Chautru 	} else if (vector->op_type == RTE_BBDEV_OP_LDPC_ENC) {
1346d819c083SNicolas Chautru 		if (check_ldpc_encoder(vector) == -1)
1347d819c083SNicolas Chautru 			return -1;
1348d819c083SNicolas Chautru 	} else if (vector->op_type == RTE_BBDEV_OP_LDPC_DEC) {
1349d819c083SNicolas Chautru 		if (check_ldpc_decoder(vector) == -1)
1350d819c083SNicolas Chautru 			return -1;
1351f714a188SAmr Mokhtar 	} else if (vector->op_type != RTE_BBDEV_OP_NONE) {
1352f714a188SAmr Mokhtar 		printf("Vector was not filled\n");
1353f714a188SAmr Mokhtar 		return -1;
1354f714a188SAmr Mokhtar 	}
1355f714a188SAmr Mokhtar 
1356f714a188SAmr Mokhtar 	return 0;
1357f714a188SAmr Mokhtar }
1358f714a188SAmr Mokhtar 
1359f714a188SAmr Mokhtar int
test_bbdev_vector_read(const char * filename,struct test_bbdev_vector * vector)1360f714a188SAmr Mokhtar test_bbdev_vector_read(const char *filename,
1361f714a188SAmr Mokhtar 		struct test_bbdev_vector *vector)
1362f714a188SAmr Mokhtar {
1363f714a188SAmr Mokhtar 	int ret = 0;
1364f714a188SAmr Mokhtar 	size_t len = 0;
1365f714a188SAmr Mokhtar 
1366f714a188SAmr Mokhtar 	FILE *fp = NULL;
1367f714a188SAmr Mokhtar 	char *line = NULL;
1368f714a188SAmr Mokhtar 	char *entry = NULL;
1369f714a188SAmr Mokhtar 
1370f714a188SAmr Mokhtar 	fp = fopen(filename, "r");
1371f714a188SAmr Mokhtar 	if (fp == NULL) {
1372f714a188SAmr Mokhtar 		printf("File %s does not exist\n", filename);
1373f714a188SAmr Mokhtar 		return -1;
1374f714a188SAmr Mokhtar 	}
1375f714a188SAmr Mokhtar 
1376f714a188SAmr Mokhtar 	while (getline(&line, &len, fp) != -1) {
1377f714a188SAmr Mokhtar 
1378f714a188SAmr Mokhtar 		/* ignore comments and new lines */
1379f714a188SAmr Mokhtar 		if (line[0] == '#' || line[0] == '/' || line[0] == '\n'
1380f714a188SAmr Mokhtar 			|| line[0] == '\r')
1381f714a188SAmr Mokhtar 			continue;
1382f714a188SAmr Mokhtar 
1383f714a188SAmr Mokhtar 		trim_space(line);
1384f714a188SAmr Mokhtar 
1385f714a188SAmr Mokhtar 		/* buffer for multiline */
1386f714a188SAmr Mokhtar 		entry = realloc(entry, strlen(line) + 1);
1387f714a188SAmr Mokhtar 		if (entry == NULL) {
1388f714a188SAmr Mokhtar 			printf("Fail to realloc %zu bytes\n", strlen(line) + 1);
1389f714a188SAmr Mokhtar 			ret = -ENOMEM;
1390f714a188SAmr Mokhtar 			goto exit;
1391f714a188SAmr Mokhtar 		}
1392f714a188SAmr Mokhtar 
1393f2790f9cSAndy Green 		strcpy(entry, line);
1394f714a188SAmr Mokhtar 
1395f714a188SAmr Mokhtar 		/* check if entry ends with , or = */
1396f714a188SAmr Mokhtar 		if (entry[strlen(entry) - 1] == ','
1397f714a188SAmr Mokhtar 			|| entry[strlen(entry) - 1] == '=') {
1398f714a188SAmr Mokhtar 			while (getline(&line, &len, fp) != -1) {
1399f714a188SAmr Mokhtar 				trim_space(line);
1400f714a188SAmr Mokhtar 
1401f714a188SAmr Mokhtar 				/* extend entry about length of new line */
1402f714a188SAmr Mokhtar 				char *entry_extended = realloc(entry,
1403f714a188SAmr Mokhtar 						strlen(line) +
1404f714a188SAmr Mokhtar 						strlen(entry) + 1);
1405f714a188SAmr Mokhtar 
1406f714a188SAmr Mokhtar 				if (entry_extended == NULL) {
1407f714a188SAmr Mokhtar 					printf("Fail to allocate %zu bytes\n",
1408f714a188SAmr Mokhtar 							strlen(line) +
1409f714a188SAmr Mokhtar 							strlen(entry) + 1);
1410f714a188SAmr Mokhtar 					ret = -ENOMEM;
1411f714a188SAmr Mokhtar 					goto exit;
1412f714a188SAmr Mokhtar 				}
1413f714a188SAmr Mokhtar 
1414f714a188SAmr Mokhtar 				entry = entry_extended;
1415f2790f9cSAndy Green 				/* entry has been allocated accordingly */
1416f2790f9cSAndy Green 				strcpy(&entry[strlen(entry)], line);
1417f714a188SAmr Mokhtar 
1418f714a188SAmr Mokhtar 				if (entry[strlen(entry) - 1] != ',')
1419f714a188SAmr Mokhtar 					break;
1420f714a188SAmr Mokhtar 			}
1421f714a188SAmr Mokhtar 		}
1422f714a188SAmr Mokhtar 		ret = parse_entry(entry, vector);
1423f714a188SAmr Mokhtar 		if (ret != 0) {
1424f714a188SAmr Mokhtar 			printf("An error occurred while parsing!\n");
1425f714a188SAmr Mokhtar 			goto exit;
1426f714a188SAmr Mokhtar 		}
1427f714a188SAmr Mokhtar 	}
1428f714a188SAmr Mokhtar 	ret = bbdev_check_vector(vector);
1429f714a188SAmr Mokhtar 	if (ret != 0)
1430f714a188SAmr Mokhtar 		printf("An error occurred while checking!\n");
1431f714a188SAmr Mokhtar 
1432f714a188SAmr Mokhtar exit:
1433f714a188SAmr Mokhtar 	fclose(fp);
1434f714a188SAmr Mokhtar 	free(line);
1435f714a188SAmr Mokhtar 	free(entry);
1436f714a188SAmr Mokhtar 
1437f714a188SAmr Mokhtar 	return ret;
1438f714a188SAmr Mokhtar }
1439