1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
5 #ifdef RTE_EXEC_ENV_BSDAPP
10 #include <rte_malloc.h>
12 #include "test_bbdev_vector.h"
14 #define VALUE_DELIMITER ","
15 #define ENTRY_DELIMITER "="
17 const char *op_data_prefixes[] = {
23 /* trim leading and trailing spaces */
29 for (start = str; *start; start++) {
30 if (!isspace((unsigned char) start[0]))
34 for (end = start + strlen(start); end > start + 1; end--) {
35 if (!isspace((unsigned char) end[-1]))
41 /* Shift from "start" to the beginning of the string */
43 memmove(str, start, (end - start) + 1);
47 starts_with(const char *str, const char *pre)
49 return strncmp(pre, str, strlen(pre)) == 0;
52 /* tokenization test values separated by a comma */
54 parse_values(char *tokens, uint32_t **data, uint32_t *data_length)
56 uint32_t n_tokens = 0;
57 uint32_t data_size = 32;
59 uint32_t *values, *values_resized;
60 char *tok, *error = NULL;
62 tok = strtok(tokens, VALUE_DELIMITER);
67 rte_zmalloc(NULL, sizeof(uint32_t) * data_size, 0);
72 values_resized = NULL;
74 if (n_tokens >= data_size) {
77 values_resized = (uint32_t *) rte_realloc(values,
78 sizeof(uint32_t) * data_size, 0);
79 if (values_resized == NULL) {
83 values = values_resized;
86 values[n_tokens] = (uint32_t) strtoul(tok, &error, 0);
87 if ((error == NULL) || (*error != '\0')) {
88 printf("Failed with convert '%s'\n", tok);
93 *data_length = *data_length + (strlen(tok) - strlen("0x"))/2;
95 tok = strtok(NULL, VALUE_DELIMITER);
102 values_resized = (uint32_t *) rte_realloc(values,
103 sizeof(uint32_t) * (n_tokens + 1), 0);
105 if (values_resized == NULL) {
110 *data = values_resized;
115 /* convert turbo decoder flag from string to unsigned long int*/
117 op_decoder_flag_strtoul(char *token, uint32_t *op_flag_value)
119 if (!strcmp(token, "RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE"))
120 *op_flag_value = RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE;
121 else if (!strcmp(token, "RTE_BBDEV_TURBO_CRC_TYPE_24B"))
122 *op_flag_value = RTE_BBDEV_TURBO_CRC_TYPE_24B;
123 else if (!strcmp(token, "RTE_BBDEV_TURBO_EQUALIZER"))
124 *op_flag_value = RTE_BBDEV_TURBO_EQUALIZER;
125 else if (!strcmp(token, "RTE_BBDEV_TURBO_SOFT_OUT_SATURATE"))
126 *op_flag_value = RTE_BBDEV_TURBO_SOFT_OUT_SATURATE;
127 else if (!strcmp(token, "RTE_BBDEV_TURBO_HALF_ITERATION_EVEN"))
128 *op_flag_value = RTE_BBDEV_TURBO_HALF_ITERATION_EVEN;
129 else if (!strcmp(token, "RTE_BBDEV_TURBO_CONTINUE_CRC_MATCH"))
130 *op_flag_value = RTE_BBDEV_TURBO_CONTINUE_CRC_MATCH;
131 else if (!strcmp(token, "RTE_BBDEV_TURBO_SOFT_OUTPUT"))
132 *op_flag_value = RTE_BBDEV_TURBO_SOFT_OUTPUT;
133 else if (!strcmp(token, "RTE_BBDEV_TURBO_EARLY_TERMINATION"))
134 *op_flag_value = RTE_BBDEV_TURBO_EARLY_TERMINATION;
135 else if (!strcmp(token, "RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN"))
136 *op_flag_value = RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN;
137 else if (!strcmp(token, "RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN"))
138 *op_flag_value = RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN;
139 else if (!strcmp(token, "RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT"))
140 *op_flag_value = RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT;
141 else if (!strcmp(token, "RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT"))
142 *op_flag_value = RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT;
143 else if (!strcmp(token, "RTE_BBDEV_TURBO_MAP_DEC"))
144 *op_flag_value = RTE_BBDEV_TURBO_MAP_DEC;
145 else if (!strcmp(token, "RTE_BBDEV_TURBO_DEC_SCATTER_GATHER"))
146 *op_flag_value = RTE_BBDEV_TURBO_DEC_SCATTER_GATHER;
147 else if (!strcmp(token, "RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP"))
148 *op_flag_value = RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP;
150 printf("The given value is not a turbo decoder flag\n");
157 /* convert turbo encoder flag from string to unsigned long int*/
159 op_encoder_flag_strtoul(char *token, uint32_t *op_flag_value)
161 if (!strcmp(token, "RTE_BBDEV_TURBO_RV_INDEX_BYPASS"))
162 *op_flag_value = RTE_BBDEV_TURBO_RV_INDEX_BYPASS;
163 else if (!strcmp(token, "RTE_BBDEV_TURBO_RATE_MATCH"))
164 *op_flag_value = RTE_BBDEV_TURBO_RATE_MATCH;
165 else if (!strcmp(token, "RTE_BBDEV_TURBO_CRC_24B_ATTACH"))
166 *op_flag_value = RTE_BBDEV_TURBO_CRC_24B_ATTACH;
167 else if (!strcmp(token, "RTE_BBDEV_TURBO_CRC_24A_ATTACH"))
168 *op_flag_value = RTE_BBDEV_TURBO_CRC_24A_ATTACH;
169 else if (!strcmp(token, "RTE_BBDEV_TURBO_ENC_SCATTER_GATHER"))
170 *op_flag_value = RTE_BBDEV_TURBO_ENC_SCATTER_GATHER;
172 printf("The given value is not a turbo encoder flag\n");
179 /* tokenization turbo decoder/encoder flags values separated by a comma */
181 parse_turbo_flags(char *tokens, uint32_t *op_flags,
182 enum rte_bbdev_op_type op_type)
185 uint32_t op_flag_value = 0;
187 tok = strtok(tokens, VALUE_DELIMITER);
191 while (tok != NULL) {
193 if (op_type == RTE_BBDEV_OP_TURBO_DEC) {
194 if (op_decoder_flag_strtoul(tok, &op_flag_value) == -1)
196 } else if (op_type == RTE_BBDEV_OP_TURBO_ENC) {
197 if (op_encoder_flag_strtoul(tok, &op_flag_value) == -1)
203 *op_flags = *op_flags | op_flag_value;
205 tok = strtok(NULL, VALUE_DELIMITER);
213 /* convert turbo encoder/decoder op_type from string to enum*/
215 op_turbo_type_strtol(char *token, enum rte_bbdev_op_type *op_type)
218 if (!strcmp(token, "RTE_BBDEV_OP_TURBO_DEC"))
219 *op_type = RTE_BBDEV_OP_TURBO_DEC;
220 else if (!strcmp(token, "RTE_BBDEV_OP_TURBO_ENC"))
221 *op_type = RTE_BBDEV_OP_TURBO_ENC;
222 else if (!strcmp(token, "RTE_BBDEV_OP_NONE"))
223 *op_type = RTE_BBDEV_OP_NONE;
225 printf("Not valid turbo op_type: '%s'\n", token);
232 /* tokenization expected status values separated by a comma */
234 parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type)
237 bool status_ok = false;
239 tok = strtok(tokens, VALUE_DELIMITER);
243 while (tok != NULL) {
245 if (!strcmp(tok, "OK"))
247 else if (!strcmp(tok, "DMA"))
248 *status = *status | (1 << RTE_BBDEV_DRV_ERROR);
249 else if (!strcmp(tok, "FCW"))
250 *status = *status | (1 << RTE_BBDEV_DATA_ERROR);
251 else if (!strcmp(tok, "CRC")) {
252 if (op_type == RTE_BBDEV_OP_TURBO_DEC)
253 *status = *status | (1 << RTE_BBDEV_CRC_ERROR);
256 "CRC is only a valid value for turbo decoder\n");
260 printf("Not valid status: '%s'\n", tok);
264 tok = strtok(NULL, VALUE_DELIMITER);
269 if (status_ok && *status != 0) {
271 "Not valid status values. Cannot be OK and ERROR at the same time.\n");
278 /* parse ops data entry (there can be more than 1 input entry, each will be
279 * contained in a separate op_data_buf struct)
282 parse_data_entry(const char *key_token, char *token,
283 struct test_bbdev_vector *vector, enum op_data_type type,
287 uint32_t data_length = 0;
288 uint32_t *data = NULL;
290 struct op_data_buf *op_data;
291 unsigned int *nb_ops;
293 if (type >= DATA_NUM_TYPES) {
294 printf("Unknown op type: %d!\n", type);
298 op_data = vector->entries[type].segments;
299 nb_ops = &vector->entries[type].nb_segments;
301 if (*nb_ops >= RTE_BBDEV_MAX_CODE_BLOCKS) {
302 printf("Too many segments (code blocks defined): %u, max %d!\n",
303 *nb_ops, RTE_BBDEV_MAX_CODE_BLOCKS);
307 if (sscanf(key_token + strlen(prefix), "%u", &id) != 1) {
308 printf("Missing ID of %s\n", prefix);
313 "Please order data entries sequentially, i.e. %s0, %s1, ...\n",
318 /* Clear new op data struct */
319 memset(op_data + *nb_ops, 0, sizeof(struct op_data_buf));
321 ret = parse_values(token, &data, &data_length);
323 op_data[*nb_ops].addr = data;
324 op_data[*nb_ops].length = data_length;
331 /* parses turbo decoder parameters and assigns to global variable */
333 parse_decoder_params(const char *key_token, char *token,
334 struct test_bbdev_vector *vector)
336 int ret = 0, status = 0;
337 uint32_t op_flags = 0;
340 struct rte_bbdev_op_turbo_dec *turbo_dec = &vector->turbo_dec;
343 if (starts_with(key_token, op_data_prefixes[DATA_INPUT]))
344 ret = parse_data_entry(key_token, token, vector,
345 DATA_INPUT, op_data_prefixes[DATA_INPUT]);
347 else if (starts_with(key_token, op_data_prefixes[DATA_SOFT_OUTPUT]))
348 ret = parse_data_entry(key_token, token, vector,
350 op_data_prefixes[DATA_SOFT_OUTPUT]);
352 else if (starts_with(key_token, op_data_prefixes[DATA_HARD_OUTPUT]))
353 ret = parse_data_entry(key_token, token, vector,
355 op_data_prefixes[DATA_HARD_OUTPUT]);
356 else if (!strcmp(key_token, "e")) {
357 vector->mask |= TEST_BBDEV_VF_E;
358 turbo_dec->cb_params.e = (uint32_t) strtoul(token, &err, 0);
359 } else if (!strcmp(key_token, "ea")) {
360 vector->mask |= TEST_BBDEV_VF_EA;
361 turbo_dec->tb_params.ea = (uint32_t) strtoul(token, &err, 0);
362 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
363 } else if (!strcmp(key_token, "eb")) {
364 vector->mask |= TEST_BBDEV_VF_EB;
365 turbo_dec->tb_params.eb = (uint32_t) strtoul(token, &err, 0);
366 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
367 } else if (!strcmp(key_token, "k")) {
368 vector->mask |= TEST_BBDEV_VF_K;
369 turbo_dec->cb_params.k = (uint16_t) strtoul(token, &err, 0);
370 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
371 } else if (!strcmp(key_token, "k_pos")) {
372 vector->mask |= TEST_BBDEV_VF_K_POS;
373 turbo_dec->tb_params.k_pos = (uint16_t) strtoul(token, &err, 0);
374 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
375 } else if (!strcmp(key_token, "k_neg")) {
376 vector->mask |= TEST_BBDEV_VF_K_NEG;
377 turbo_dec->tb_params.k_neg = (uint16_t) strtoul(token, &err, 0);
378 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
379 } else if (!strcmp(key_token, "c")) {
380 vector->mask |= TEST_BBDEV_VF_C;
381 turbo_dec->tb_params.c = (uint16_t) strtoul(token, &err, 0);
382 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
383 } else if (!strcmp(key_token, "c_neg")) {
384 vector->mask |= TEST_BBDEV_VF_C_NEG;
385 turbo_dec->tb_params.c_neg = (uint16_t) strtoul(token, &err, 0);
386 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
387 } else if (!strcmp(key_token, "cab")) {
388 vector->mask |= TEST_BBDEV_VF_CAB;
389 turbo_dec->tb_params.cab = (uint8_t) strtoul(token, &err, 0);
390 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
391 } else if (!strcmp(key_token, "rv_index")) {
392 vector->mask |= TEST_BBDEV_VF_RV_INDEX;
393 turbo_dec->rv_index = (uint8_t) strtoul(token, &err, 0);
394 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
395 } else if (!strcmp(key_token, "iter_max")) {
396 vector->mask |= TEST_BBDEV_VF_ITER_MAX;
397 turbo_dec->iter_max = (uint8_t) strtoul(token, &err, 0);
398 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
399 } else if (!strcmp(key_token, "iter_min")) {
400 vector->mask |= TEST_BBDEV_VF_ITER_MIN;
401 turbo_dec->iter_min = (uint8_t) strtoul(token, &err, 0);
402 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
403 } else if (!strcmp(key_token, "expected_iter_count")) {
404 vector->mask |= TEST_BBDEV_VF_EXPECTED_ITER_COUNT;
405 turbo_dec->iter_count = (uint8_t) strtoul(token, &err, 0);
406 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
407 } else if (!strcmp(key_token, "ext_scale")) {
408 vector->mask |= TEST_BBDEV_VF_EXT_SCALE;
409 turbo_dec->ext_scale = (uint8_t) strtoul(token, &err, 0);
410 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
411 } else if (!strcmp(key_token, "num_maps")) {
412 vector->mask |= TEST_BBDEV_VF_NUM_MAPS;
413 turbo_dec->num_maps = (uint8_t) strtoul(token, &err, 0);
414 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
415 } else if (!strcmp(key_token, "code_block_mode")) {
416 vector->mask |= TEST_BBDEV_VF_CODE_BLOCK_MODE;
417 turbo_dec->code_block_mode = (uint8_t) strtoul(token, &err, 0);
418 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
419 } else if (!strcmp(key_token, "op_flags")) {
420 vector->mask |= TEST_BBDEV_VF_OP_FLAGS;
421 ret = parse_turbo_flags(token, &op_flags,
424 turbo_dec->op_flags = op_flags;
425 } else if (!strcmp(key_token, "expected_status")) {
426 vector->mask |= TEST_BBDEV_VF_EXPECTED_STATUS;
427 ret = parse_expected_status(token, &status, vector->op_type);
429 vector->expected_status = status;
431 printf("Not valid dec key: '%s'\n", key_token);
436 printf("Failed with convert '%s\t%s'\n", key_token, token);
443 /* parses turbo encoder parameters and assigns to global variable */
445 parse_encoder_params(const char *key_token, char *token,
446 struct test_bbdev_vector *vector)
448 int ret = 0, status = 0;
449 uint32_t op_flags = 0;
453 struct rte_bbdev_op_turbo_enc *turbo_enc = &vector->turbo_enc;
455 if (starts_with(key_token, op_data_prefixes[DATA_INPUT]))
456 ret = parse_data_entry(key_token, token, vector,
457 DATA_INPUT, op_data_prefixes[DATA_INPUT]);
458 else if (starts_with(key_token, "output"))
459 ret = parse_data_entry(key_token, token, vector,
460 DATA_HARD_OUTPUT, "output");
461 else if (!strcmp(key_token, "e")) {
462 vector->mask |= TEST_BBDEV_VF_E;
463 turbo_enc->cb_params.e = (uint32_t) strtoul(token, &err, 0);
464 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
465 } else if (!strcmp(key_token, "ea")) {
466 vector->mask |= TEST_BBDEV_VF_EA;
467 turbo_enc->tb_params.ea = (uint32_t) strtoul(token, &err, 0);
468 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
469 } else if (!strcmp(key_token, "eb")) {
470 vector->mask |= TEST_BBDEV_VF_EB;
471 turbo_enc->tb_params.eb = (uint32_t) strtoul(token, &err, 0);
472 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
473 } else if (!strcmp(key_token, "k")) {
474 vector->mask |= TEST_BBDEV_VF_K;
475 turbo_enc->cb_params.k = (uint16_t) strtoul(token, &err, 0);
476 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
477 } else if (!strcmp(key_token, "k_neg")) {
478 vector->mask |= TEST_BBDEV_VF_K_NEG;
479 turbo_enc->tb_params.k_neg = (uint16_t) strtoul(token, &err, 0);
480 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
481 } else if (!strcmp(key_token, "k_pos")) {
482 vector->mask |= TEST_BBDEV_VF_K_POS;
483 turbo_enc->tb_params.k_pos = (uint16_t) strtoul(token, &err, 0);
484 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
485 } else if (!strcmp(key_token, "c_neg")) {
486 vector->mask |= TEST_BBDEV_VF_C_NEG;
487 turbo_enc->tb_params.c_neg = (uint8_t) strtoul(token, &err, 0);
488 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
489 } else if (!strcmp(key_token, "c")) {
490 vector->mask |= TEST_BBDEV_VF_C;
491 turbo_enc->tb_params.c = (uint8_t) strtoul(token, &err, 0);
492 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
493 } else if (!strcmp(key_token, "cab")) {
494 vector->mask |= TEST_BBDEV_VF_CAB;
495 turbo_enc->tb_params.cab = (uint8_t) strtoul(token, &err, 0);
496 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
497 } else if (!strcmp(key_token, "rv_index")) {
498 vector->mask |= TEST_BBDEV_VF_RV_INDEX;
499 turbo_enc->rv_index = (uint8_t) strtoul(token, &err, 0);
500 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
501 } else if (!strcmp(key_token, "ncb")) {
502 vector->mask |= TEST_BBDEV_VF_NCB;
503 turbo_enc->cb_params.ncb = (uint16_t) strtoul(token, &err, 0);
504 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
505 } else if (!strcmp(key_token, "ncb_neg")) {
506 vector->mask |= TEST_BBDEV_VF_NCB_NEG;
507 turbo_enc->tb_params.ncb_neg =
508 (uint16_t) strtoul(token, &err, 0);
509 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
510 } else if (!strcmp(key_token, "ncb_pos")) {
511 vector->mask |= TEST_BBDEV_VF_NCB_POS;
512 turbo_enc->tb_params.ncb_pos =
513 (uint16_t) strtoul(token, &err, 0);
514 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
515 } else if (!strcmp(key_token, "r")) {
516 vector->mask |= TEST_BBDEV_VF_R;
517 turbo_enc->tb_params.r = (uint8_t) strtoul(token, &err, 0);
518 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
519 } else if (!strcmp(key_token, "code_block_mode")) {
520 vector->mask |= TEST_BBDEV_VF_CODE_BLOCK_MODE;
521 turbo_enc->code_block_mode = (uint8_t) strtoul(token, &err, 0);
522 ret = ((err == NULL) || (*err != '\0')) ? -1 : 0;
523 } else if (!strcmp(key_token, "op_flags")) {
524 vector->mask |= TEST_BBDEV_VF_OP_FLAGS;
525 ret = parse_turbo_flags(token, &op_flags,
528 turbo_enc->op_flags = op_flags;
529 } else if (!strcmp(key_token, "expected_status")) {
530 vector->mask |= TEST_BBDEV_VF_EXPECTED_STATUS;
531 ret = parse_expected_status(token, &status, vector->op_type);
533 vector->expected_status = status;
535 printf("Not valid enc key: '%s'\n", key_token);
540 printf("Failed with convert '%s\t%s'\n", key_token, token);
547 /* checks the type of key and assigns data */
549 parse_entry(char *entry, struct test_bbdev_vector *vector)
552 char *token, *key_token;
553 enum rte_bbdev_op_type op_type = RTE_BBDEV_OP_NONE;
556 printf("Expected entry value\n");
561 token = strtok(entry, ENTRY_DELIMITER);
563 /* get values for key */
564 token = strtok(NULL, ENTRY_DELIMITER);
566 if (key_token == NULL || token == NULL) {
567 printf("Expected 'key = values' but was '%.40s'..\n", entry);
570 trim_space(key_token);
572 /* first key_token has to specify type of operation */
573 if (vector->op_type == RTE_BBDEV_OP_NONE) {
574 if (!strcmp(key_token, "op_type")) {
575 ret = op_turbo_type_strtol(token, &op_type);
577 vector->op_type = op_type;
578 return (!ret) ? 0 : -1;
580 printf("First key_token (%s) does not specify op_type\n",
586 if (vector->op_type == RTE_BBDEV_OP_TURBO_DEC) {
587 if (parse_decoder_params(key_token, token, vector) == -1)
589 } else if (vector->op_type == RTE_BBDEV_OP_TURBO_ENC) {
590 if (parse_encoder_params(key_token, token, vector) == -1)
598 check_decoder_segments(struct test_bbdev_vector *vector)
601 struct rte_bbdev_op_turbo_dec *turbo_dec = &vector->turbo_dec;
603 if (vector->entries[DATA_INPUT].nb_segments == 0)
606 for (i = 0; i < vector->entries[DATA_INPUT].nb_segments; i++)
607 if (vector->entries[DATA_INPUT].segments[i].addr == NULL)
610 if (vector->entries[DATA_HARD_OUTPUT].nb_segments == 0)
613 for (i = 0; i < vector->entries[DATA_HARD_OUTPUT].nb_segments;
615 if (vector->entries[DATA_HARD_OUTPUT].segments[i].addr == NULL)
618 if ((turbo_dec->op_flags & RTE_BBDEV_TURBO_SOFT_OUTPUT) &&
619 (vector->entries[DATA_SOFT_OUTPUT].nb_segments == 0))
622 for (i = 0; i < vector->entries[DATA_SOFT_OUTPUT].nb_segments;
624 if (vector->entries[DATA_SOFT_OUTPUT].segments[i].addr == NULL)
631 check_decoder_llr_spec(struct test_bbdev_vector *vector)
633 struct rte_bbdev_op_turbo_dec *turbo_dec = &vector->turbo_dec;
635 /* Check input LLR sign formalism specification */
636 if ((turbo_dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN) &&
637 (turbo_dec->op_flags &
638 RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN)) {
640 "Both positive and negative LLR input flags were set!\n");
643 if (!(turbo_dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN) &&
644 !(turbo_dec->op_flags &
645 RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN)) {
647 "WARNING: input LLR sign formalism was not specified and will be set to negative LLR for '1' bit\n");
648 turbo_dec->op_flags |= RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN;
651 if (!(turbo_dec->op_flags & RTE_BBDEV_TURBO_SOFT_OUTPUT))
654 /* Check output LLR sign formalism specification */
655 if ((turbo_dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT) &&
656 (turbo_dec->op_flags &
657 RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT)) {
659 "Both positive and negative LLR output flags were set!\n");
662 if (!(turbo_dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT) &&
663 !(turbo_dec->op_flags &
664 RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT)) {
666 "WARNING: soft output LLR sign formalism was not specified and will be set to negative LLR for '1' bit\n");
667 turbo_dec->op_flags |=
668 RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT;
674 /* checks decoder parameters */
676 check_decoder(struct test_bbdev_vector *vector)
678 struct rte_bbdev_op_turbo_dec *turbo_dec = &vector->turbo_dec;
679 const int mask = vector->mask;
681 if (check_decoder_segments(vector) < 0)
684 if (check_decoder_llr_spec(vector) < 0)
687 /* Check which params were set */
688 if (!(mask & TEST_BBDEV_VF_CODE_BLOCK_MODE)) {
690 "WARNING: code_block_mode was not specified in vector file and will be set to 1 (0 - TB Mode, 1 - CB mode)\n");
691 turbo_dec->code_block_mode = 1;
693 if (turbo_dec->code_block_mode == 0) {
694 if (!(mask & TEST_BBDEV_VF_EA))
696 "WARNING: ea was not specified in vector file and will be set to 0\n");
697 if (!(mask & TEST_BBDEV_VF_EB))
699 "WARNING: eb was not specified in vector file and will be set to 0\n");
700 if (!(mask & TEST_BBDEV_VF_K_NEG))
702 "WARNING: k_neg was not specified in vector file and will be set to 0\n");
703 if (!(mask & TEST_BBDEV_VF_K_POS))
705 "WARNING: k_pos was not specified in vector file and will be set to 0\n");
706 if (!(mask & TEST_BBDEV_VF_C_NEG))
708 "WARNING: c_neg was not specified in vector file and will be set to 0\n");
709 if (!(mask & TEST_BBDEV_VF_C)) {
711 "WARNING: c was not specified in vector file and will be set to 1\n");
712 turbo_dec->tb_params.c = 1;
714 if (!(mask & TEST_BBDEV_VF_CAB))
716 "WARNING: cab was not specified in vector file and will be set to 0\n");
718 if (!(mask & TEST_BBDEV_VF_E))
720 "WARNING: e was not specified in vector file and will be set to 0\n");
721 if (!(mask & TEST_BBDEV_VF_K))
723 "WARNING: k was not specified in vector file and will be set to 0\n");
725 if (!(mask & TEST_BBDEV_VF_RV_INDEX))
727 "WARNING: rv_index was not specified in vector file and will be set to 0\n");
728 if (!(mask & TEST_BBDEV_VF_ITER_MIN))
730 "WARNING: iter_min was not specified in vector file and will be set to 0\n");
731 if (!(mask & TEST_BBDEV_VF_ITER_MAX))
733 "WARNING: iter_max was not specified in vector file and will be set to 0\n");
734 if (!(mask & TEST_BBDEV_VF_EXPECTED_ITER_COUNT))
736 "WARNING: expected_iter_count was not specified in vector file and iter_count will not be validated\n");
737 if (!(mask & TEST_BBDEV_VF_EXT_SCALE))
739 "WARNING: ext_scale was not specified in vector file and will be set to 0\n");
740 if (!(mask & TEST_BBDEV_VF_OP_FLAGS)) {
742 "WARNING: op_flags was not specified in vector file and capabilities will not be validated\n");
743 turbo_dec->num_maps = 0;
744 } else if (!(turbo_dec->op_flags & RTE_BBDEV_TURBO_MAP_DEC) &&
745 mask & TEST_BBDEV_VF_NUM_MAPS) {
747 "WARNING: RTE_BBDEV_TURBO_MAP_DEC was not set in vector file and num_maps will be set to 0\n");
748 turbo_dec->num_maps = 0;
750 if (!(mask & TEST_BBDEV_VF_EXPECTED_STATUS))
752 "WARNING: expected_status was not specified in vector file and will be set to 0\n");
756 /* checks encoder parameters */
758 check_encoder(struct test_bbdev_vector *vector)
761 const int mask = vector->mask;
763 if (vector->entries[DATA_INPUT].nb_segments == 0)
766 for (i = 0; i < vector->entries[DATA_INPUT].nb_segments; i++)
767 if (vector->entries[DATA_INPUT].segments[i].addr == NULL)
770 if (vector->entries[DATA_HARD_OUTPUT].nb_segments == 0)
773 for (i = 0; i < vector->entries[DATA_HARD_OUTPUT].nb_segments; i++)
774 if (vector->entries[DATA_HARD_OUTPUT].segments[i].addr == NULL)
777 if (!(mask & TEST_BBDEV_VF_CODE_BLOCK_MODE)) {
779 "WARNING: code_block_mode was not specified in vector file and will be set to 1\n");
780 vector->turbo_enc.code_block_mode = 1;
782 if (vector->turbo_enc.code_block_mode == 0) {
783 if (!(mask & TEST_BBDEV_VF_EA) && (vector->turbo_enc.op_flags &
784 RTE_BBDEV_TURBO_RATE_MATCH))
786 "WARNING: ea was not specified in vector file and will be set to 0\n");
787 if (!(mask & TEST_BBDEV_VF_EB) && (vector->turbo_enc.op_flags &
788 RTE_BBDEV_TURBO_RATE_MATCH))
790 "WARNING: eb was not specified in vector file and will be set to 0\n");
791 if (!(mask & TEST_BBDEV_VF_K_NEG))
793 "WARNING: k_neg was not specified in vector file and will be set to 0\n");
794 if (!(mask & TEST_BBDEV_VF_K_POS))
796 "WARNING: k_pos was not specified in vector file and will be set to 0\n");
797 if (!(mask & TEST_BBDEV_VF_C_NEG))
799 "WARNING: c_neg was not specified in vector file and will be set to 0\n");
800 if (!(mask & TEST_BBDEV_VF_C)) {
802 "WARNING: c was not specified in vector file and will be set to 1\n");
803 vector->turbo_enc.tb_params.c = 1;
805 if (!(mask & TEST_BBDEV_VF_CAB) && (vector->turbo_enc.op_flags &
806 RTE_BBDEV_TURBO_RATE_MATCH))
808 "WARNING: cab was not specified in vector file and will be set to 0\n");
809 if (!(mask & TEST_BBDEV_VF_NCB_NEG))
811 "WARNING: ncb_neg was not specified in vector file and will be set to 0\n");
812 if (!(mask & TEST_BBDEV_VF_NCB_POS))
814 "WARNING: ncb_pos was not specified in vector file and will be set to 0\n");
815 if (!(mask & TEST_BBDEV_VF_R))
817 "WARNING: r was not specified in vector file and will be set to 0\n");
819 if (!(mask & TEST_BBDEV_VF_E) && (vector->turbo_enc.op_flags &
820 RTE_BBDEV_TURBO_RATE_MATCH))
822 "WARNING: e was not specified in vector file and will be set to 0\n");
823 if (!(mask & TEST_BBDEV_VF_K))
825 "WARNING: k was not specified in vector file and will be set to 0\n");
826 if (!(mask & TEST_BBDEV_VF_NCB))
828 "WARNING: ncb was not specified in vector file and will be set to 0\n");
830 if (!(mask & TEST_BBDEV_VF_RV_INDEX))
832 "WARNING: rv_index was not specified in vector file and will be set to 0\n");
833 if (!(mask & TEST_BBDEV_VF_OP_FLAGS))
835 "WARNING: op_flags was not specified in vector file and capabilities will not be validated\n");
836 if (!(mask & TEST_BBDEV_VF_EXPECTED_STATUS))
838 "WARNING: expected_status was not specified in vector file and will be set to 0\n");
844 bbdev_check_vector(struct test_bbdev_vector *vector)
846 if (vector->op_type == RTE_BBDEV_OP_TURBO_DEC) {
847 if (check_decoder(vector) == -1)
849 } else if (vector->op_type == RTE_BBDEV_OP_TURBO_ENC) {
850 if (check_encoder(vector) == -1)
852 } else if (vector->op_type != RTE_BBDEV_OP_NONE) {
853 printf("Vector was not filled\n");
861 test_bbdev_vector_read(const char *filename,
862 struct test_bbdev_vector *vector)
871 fp = fopen(filename, "r");
873 printf("File %s does not exist\n", filename);
877 while (getline(&line, &len, fp) != -1) {
879 /* ignore comments and new lines */
880 if (line[0] == '#' || line[0] == '/' || line[0] == '\n'
886 /* buffer for multiline */
887 entry = realloc(entry, strlen(line) + 1);
889 printf("Fail to realloc %zu bytes\n", strlen(line) + 1);
896 /* check if entry ends with , or = */
897 if (entry[strlen(entry) - 1] == ','
898 || entry[strlen(entry) - 1] == '=') {
899 while (getline(&line, &len, fp) != -1) {
902 /* extend entry about length of new line */
903 char *entry_extended = realloc(entry,
907 if (entry_extended == NULL) {
908 printf("Fail to allocate %zu bytes\n",
915 entry = entry_extended;
916 /* entry has been allocated accordingly */
917 strcpy(&entry[strlen(entry)], line);
919 if (entry[strlen(entry) - 1] != ',')
923 ret = parse_entry(entry, vector);
925 printf("An error occurred while parsing!\n");
929 ret = bbdev_check_vector(vector);
931 printf("An error occurred while checking!\n");