1f714a188SAmr Mokhtar /* SPDX-License-Identifier: BSD-3-Clause 2f714a188SAmr Mokhtar * Copyright(c) 2017 Intel Corporation 3f714a188SAmr Mokhtar */ 4f714a188SAmr Mokhtar 5f714a188SAmr Mokhtar #ifdef RTE_EXEC_ENV_BSDAPP 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", 21f714a188SAmr Mokhtar }; 22f714a188SAmr Mokhtar 23f714a188SAmr Mokhtar /* trim leading and trailing spaces */ 24f714a188SAmr Mokhtar static void 25f714a188SAmr Mokhtar trim_space(char *str) 26f714a188SAmr Mokhtar { 27f714a188SAmr Mokhtar char *start, *end; 28f714a188SAmr Mokhtar 29f714a188SAmr Mokhtar for (start = str; *start; start++) { 30f714a188SAmr Mokhtar if (!isspace((unsigned char) start[0])) 31f714a188SAmr Mokhtar break; 32f714a188SAmr Mokhtar } 33f714a188SAmr Mokhtar 34f714a188SAmr Mokhtar for (end = start + strlen(start); end > start + 1; end--) { 35f714a188SAmr Mokhtar if (!isspace((unsigned char) end[-1])) 36f714a188SAmr Mokhtar break; 37f714a188SAmr Mokhtar } 38f714a188SAmr Mokhtar 39f714a188SAmr Mokhtar *end = 0; 40f714a188SAmr Mokhtar 41f714a188SAmr Mokhtar /* Shift from "start" to the beginning of the string */ 42f714a188SAmr Mokhtar if (start > str) 43f714a188SAmr Mokhtar memmove(str, start, (end - start) + 1); 44f714a188SAmr Mokhtar } 45f714a188SAmr Mokhtar 46f714a188SAmr Mokhtar static bool 47f714a188SAmr Mokhtar starts_with(const char *str, const char *pre) 48f714a188SAmr Mokhtar { 49f714a188SAmr Mokhtar return strncmp(pre, str, strlen(pre)) == 0; 50f714a188SAmr Mokhtar } 51f714a188SAmr Mokhtar 52f714a188SAmr Mokhtar /* tokenization test values separated by a comma */ 53f714a188SAmr Mokhtar static int 54f714a188SAmr Mokhtar parse_values(char *tokens, uint32_t **data, uint32_t *data_length) 55f714a188SAmr Mokhtar { 56f714a188SAmr Mokhtar uint32_t n_tokens = 0; 57f714a188SAmr Mokhtar uint32_t data_size = 32; 58f714a188SAmr Mokhtar 59f714a188SAmr Mokhtar uint32_t *values, *values_resized; 60f714a188SAmr Mokhtar char *tok, *error = NULL; 61f714a188SAmr Mokhtar 62f714a188SAmr Mokhtar tok = strtok(tokens, VALUE_DELIMITER); 63f714a188SAmr Mokhtar if (tok == NULL) 64f714a188SAmr Mokhtar return -1; 65f714a188SAmr Mokhtar 66f714a188SAmr Mokhtar values = (uint32_t *) 67f714a188SAmr Mokhtar rte_zmalloc(NULL, sizeof(uint32_t) * data_size, 0); 68f714a188SAmr Mokhtar if (values == NULL) 69f714a188SAmr Mokhtar return -1; 70f714a188SAmr Mokhtar 71f714a188SAmr Mokhtar while (tok != NULL) { 72f714a188SAmr Mokhtar values_resized = NULL; 73f714a188SAmr Mokhtar 74f714a188SAmr Mokhtar if (n_tokens >= data_size) { 75f714a188SAmr Mokhtar data_size *= 2; 76f714a188SAmr Mokhtar 77f714a188SAmr Mokhtar values_resized = (uint32_t *) rte_realloc(values, 78f714a188SAmr Mokhtar sizeof(uint32_t) * data_size, 0); 79f714a188SAmr Mokhtar if (values_resized == NULL) { 80f714a188SAmr Mokhtar rte_free(values); 81f714a188SAmr Mokhtar return -1; 82f714a188SAmr Mokhtar } 83f714a188SAmr Mokhtar values = values_resized; 84f714a188SAmr Mokhtar } 85f714a188SAmr Mokhtar 86f714a188SAmr Mokhtar values[n_tokens] = (uint32_t) strtoul(tok, &error, 0); 87f714a188SAmr Mokhtar if ((error == NULL) || (*error != '\0')) { 88f714a188SAmr Mokhtar printf("Failed with convert '%s'\n", tok); 89f714a188SAmr Mokhtar rte_free(values); 90f714a188SAmr Mokhtar return -1; 91f714a188SAmr Mokhtar } 92f714a188SAmr Mokhtar 93f714a188SAmr Mokhtar *data_length = *data_length + (strlen(tok) - strlen("0x"))/2; 94f714a188SAmr Mokhtar 95f714a188SAmr Mokhtar tok = strtok(NULL, VALUE_DELIMITER); 96f714a188SAmr Mokhtar if (tok == NULL) 97f714a188SAmr Mokhtar break; 98f714a188SAmr Mokhtar 99f714a188SAmr Mokhtar n_tokens++; 100f714a188SAmr Mokhtar } 101f714a188SAmr Mokhtar 102f714a188SAmr Mokhtar values_resized = (uint32_t *) rte_realloc(values, 103f714a188SAmr Mokhtar sizeof(uint32_t) * (n_tokens + 1), 0); 104f714a188SAmr Mokhtar 105f714a188SAmr Mokhtar if (values_resized == NULL) { 106f714a188SAmr Mokhtar rte_free(values); 107f714a188SAmr Mokhtar return -1; 108f714a188SAmr Mokhtar } 109f714a188SAmr Mokhtar 110f714a188SAmr Mokhtar *data = values_resized; 111f714a188SAmr Mokhtar 112f714a188SAmr Mokhtar return 0; 113f714a188SAmr Mokhtar } 114f714a188SAmr Mokhtar 115f714a188SAmr Mokhtar /* convert turbo decoder flag from string to unsigned long int*/ 116f714a188SAmr Mokhtar static int 117f714a188SAmr Mokhtar op_decoder_flag_strtoul(char *token, uint32_t *op_flag_value) 118f714a188SAmr Mokhtar { 119f714a188SAmr Mokhtar if (!strcmp(token, "RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE")) 120f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE; 121f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_CRC_TYPE_24B")) 122f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_CRC_TYPE_24B; 123f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_EQUALIZER")) 124f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_EQUALIZER; 125f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_SOFT_OUT_SATURATE")) 126f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_SOFT_OUT_SATURATE; 127f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_HALF_ITERATION_EVEN")) 128f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_HALF_ITERATION_EVEN; 129f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_CONTINUE_CRC_MATCH")) 130f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_CONTINUE_CRC_MATCH; 131f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_SOFT_OUTPUT")) 132f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_SOFT_OUTPUT; 133f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_EARLY_TERMINATION")) 134f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_EARLY_TERMINATION; 135f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN")) 136f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN; 137f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN")) 138f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN; 139f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT")) 140f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT; 141f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT")) 142f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT; 143f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_MAP_DEC")) 144f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_MAP_DEC; 145f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_DEC_SCATTER_GATHER")) 146f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_DEC_SCATTER_GATHER; 147f714a188SAmr Mokhtar else { 148f714a188SAmr Mokhtar printf("The given value is not a turbo decoder flag\n"); 149f714a188SAmr Mokhtar return -1; 150f714a188SAmr Mokhtar } 151f714a188SAmr Mokhtar 152f714a188SAmr Mokhtar return 0; 153f714a188SAmr Mokhtar } 154f714a188SAmr Mokhtar 155f714a188SAmr Mokhtar /* convert turbo encoder flag from string to unsigned long int*/ 156f714a188SAmr Mokhtar static int 157f714a188SAmr Mokhtar op_encoder_flag_strtoul(char *token, uint32_t *op_flag_value) 158f714a188SAmr Mokhtar { 159f714a188SAmr Mokhtar if (!strcmp(token, "RTE_BBDEV_TURBO_RV_INDEX_BYPASS")) 160f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_RV_INDEX_BYPASS; 161f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_RATE_MATCH")) 162f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_RATE_MATCH; 163f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_CRC_24B_ATTACH")) 164f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_CRC_24B_ATTACH; 165f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_CRC_24A_ATTACH")) 166f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_CRC_24A_ATTACH; 167f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_TURBO_ENC_SCATTER_GATHER")) 168f714a188SAmr Mokhtar *op_flag_value = RTE_BBDEV_TURBO_ENC_SCATTER_GATHER; 169f714a188SAmr Mokhtar else { 170f714a188SAmr Mokhtar printf("The given value is not a turbo encoder flag\n"); 171f714a188SAmr Mokhtar return -1; 172f714a188SAmr Mokhtar } 173f714a188SAmr Mokhtar 174f714a188SAmr Mokhtar return 0; 175f714a188SAmr Mokhtar } 176f714a188SAmr Mokhtar 177f714a188SAmr Mokhtar /* tokenization turbo decoder/encoder flags values separated by a comma */ 178f714a188SAmr Mokhtar static int 179f714a188SAmr Mokhtar parse_turbo_flags(char *tokens, uint32_t *op_flags, 180f714a188SAmr Mokhtar enum rte_bbdev_op_type op_type) 181f714a188SAmr Mokhtar { 182f714a188SAmr Mokhtar char *tok = NULL; 183f714a188SAmr Mokhtar uint32_t op_flag_value = 0; 184f714a188SAmr Mokhtar 185f714a188SAmr Mokhtar tok = strtok(tokens, VALUE_DELIMITER); 186f714a188SAmr Mokhtar if (tok == NULL) 187f714a188SAmr Mokhtar return -1; 188f714a188SAmr Mokhtar 189f714a188SAmr Mokhtar while (tok != NULL) { 190f714a188SAmr Mokhtar trim_space(tok); 191f714a188SAmr Mokhtar if (op_type == RTE_BBDEV_OP_TURBO_DEC) { 192f714a188SAmr Mokhtar if (op_decoder_flag_strtoul(tok, &op_flag_value) == -1) 193f714a188SAmr Mokhtar return -1; 194f714a188SAmr Mokhtar } else if (op_type == RTE_BBDEV_OP_TURBO_ENC) { 195f714a188SAmr Mokhtar if (op_encoder_flag_strtoul(tok, &op_flag_value) == -1) 196f714a188SAmr Mokhtar return -1; 197f714a188SAmr Mokhtar } else { 198f714a188SAmr Mokhtar return -1; 199f714a188SAmr Mokhtar } 200f714a188SAmr Mokhtar 201f714a188SAmr Mokhtar *op_flags = *op_flags | op_flag_value; 202f714a188SAmr Mokhtar 203f714a188SAmr Mokhtar tok = strtok(NULL, VALUE_DELIMITER); 204f714a188SAmr Mokhtar if (tok == NULL) 205f714a188SAmr Mokhtar break; 206f714a188SAmr Mokhtar } 207f714a188SAmr Mokhtar 208f714a188SAmr Mokhtar return 0; 209f714a188SAmr Mokhtar } 210f714a188SAmr Mokhtar 211f714a188SAmr Mokhtar /* convert turbo encoder/decoder op_type from string to enum*/ 212f714a188SAmr Mokhtar static int 213f714a188SAmr Mokhtar op_turbo_type_strtol(char *token, enum rte_bbdev_op_type *op_type) 214f714a188SAmr Mokhtar { 215f714a188SAmr Mokhtar trim_space(token); 216f714a188SAmr Mokhtar if (!strcmp(token, "RTE_BBDEV_OP_TURBO_DEC")) 217f714a188SAmr Mokhtar *op_type = RTE_BBDEV_OP_TURBO_DEC; 218f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_OP_TURBO_ENC")) 219f714a188SAmr Mokhtar *op_type = RTE_BBDEV_OP_TURBO_ENC; 220f714a188SAmr Mokhtar else if (!strcmp(token, "RTE_BBDEV_OP_NONE")) 221f714a188SAmr Mokhtar *op_type = RTE_BBDEV_OP_NONE; 222f714a188SAmr Mokhtar else { 223f714a188SAmr Mokhtar printf("Not valid turbo op_type: '%s'\n", token); 224f714a188SAmr Mokhtar return -1; 225f714a188SAmr Mokhtar } 226f714a188SAmr Mokhtar 227f714a188SAmr Mokhtar return 0; 228f714a188SAmr Mokhtar } 229f714a188SAmr Mokhtar 230f714a188SAmr Mokhtar /* tokenization expected status values separated by a comma */ 231f714a188SAmr Mokhtar static int 232f714a188SAmr Mokhtar parse_expected_status(char *tokens, int *status, enum rte_bbdev_op_type op_type) 233f714a188SAmr Mokhtar { 234f714a188SAmr Mokhtar char *tok = NULL; 235f714a188SAmr Mokhtar bool status_ok = false; 236f714a188SAmr Mokhtar 237f714a188SAmr Mokhtar tok = strtok(tokens, VALUE_DELIMITER); 238f714a188SAmr Mokhtar if (tok == NULL) 239f714a188SAmr Mokhtar return -1; 240f714a188SAmr Mokhtar 241f714a188SAmr Mokhtar while (tok != NULL) { 242f714a188SAmr Mokhtar trim_space(tok); 243f714a188SAmr Mokhtar if (!strcmp(tok, "OK")) 244f714a188SAmr Mokhtar status_ok = true; 245f714a188SAmr Mokhtar else if (!strcmp(tok, "DMA")) 246f714a188SAmr Mokhtar *status = *status | (1 << RTE_BBDEV_DRV_ERROR); 247f714a188SAmr Mokhtar else if (!strcmp(tok, "FCW")) 248f714a188SAmr Mokhtar *status = *status | (1 << RTE_BBDEV_DATA_ERROR); 249f714a188SAmr Mokhtar else if (!strcmp(tok, "CRC")) { 250f714a188SAmr Mokhtar if (op_type == RTE_BBDEV_OP_TURBO_DEC) 251f714a188SAmr Mokhtar *status = *status | (1 << RTE_BBDEV_CRC_ERROR); 252f714a188SAmr Mokhtar else { 253f714a188SAmr Mokhtar printf( 254f714a188SAmr Mokhtar "CRC is only a valid value for turbo decoder\n"); 255f714a188SAmr Mokhtar return -1; 256f714a188SAmr Mokhtar } 257f714a188SAmr Mokhtar } else { 258f714a188SAmr Mokhtar printf("Not valid status: '%s'\n", tok); 259f714a188SAmr Mokhtar return -1; 260f714a188SAmr Mokhtar } 261f714a188SAmr Mokhtar 262f714a188SAmr Mokhtar tok = strtok(NULL, VALUE_DELIMITER); 263f714a188SAmr Mokhtar if (tok == NULL) 264f714a188SAmr Mokhtar break; 265f714a188SAmr Mokhtar } 266f714a188SAmr Mokhtar 267f714a188SAmr Mokhtar if (status_ok && *status != 0) { 268f714a188SAmr Mokhtar printf( 269f714a188SAmr Mokhtar "Not valid status values. Cannot be OK and ERROR at the same time.\n"); 270f714a188SAmr Mokhtar return -1; 271f714a188SAmr Mokhtar } 272f714a188SAmr Mokhtar 273f714a188SAmr Mokhtar return 0; 274f714a188SAmr Mokhtar } 275f714a188SAmr Mokhtar 276f714a188SAmr Mokhtar /* parse ops data entry (there can be more than 1 input entry, each will be 277f714a188SAmr Mokhtar * contained in a separate op_data_buf struct) 278f714a188SAmr Mokhtar */ 279f714a188SAmr Mokhtar static int 280f714a188SAmr Mokhtar parse_data_entry(const char *key_token, char *token, 281f714a188SAmr Mokhtar struct test_bbdev_vector *vector, enum op_data_type type, 282f714a188SAmr Mokhtar const char *prefix) 283f714a188SAmr Mokhtar { 284f714a188SAmr Mokhtar int ret; 285f714a188SAmr Mokhtar uint32_t data_length = 0; 286f714a188SAmr Mokhtar uint32_t *data = NULL; 287f714a188SAmr Mokhtar unsigned int id; 288f714a188SAmr Mokhtar struct op_data_buf *op_data; 289f714a188SAmr Mokhtar unsigned int *nb_ops; 290f714a188SAmr Mokhtar 291*21820350SAmr Mokhtar if (type >= DATA_NUM_TYPES) { 292f714a188SAmr Mokhtar printf("Unknown op type: %d!\n", type); 293f714a188SAmr Mokhtar return -1; 294f714a188SAmr Mokhtar } 295f714a188SAmr Mokhtar 296f714a188SAmr Mokhtar op_data = vector->entries[type].segments; 297f714a188SAmr Mokhtar nb_ops = &vector->entries[type].nb_segments; 298f714a188SAmr Mokhtar 299f714a188SAmr Mokhtar if (*nb_ops >= RTE_BBDEV_MAX_CODE_BLOCKS) { 300f714a188SAmr Mokhtar printf("Too many segments (code blocks defined): %u, max %d!\n", 301f714a188SAmr Mokhtar *nb_ops, RTE_BBDEV_MAX_CODE_BLOCKS); 302f714a188SAmr Mokhtar return -1; 303f714a188SAmr Mokhtar } 304f714a188SAmr Mokhtar 305f714a188SAmr Mokhtar if (sscanf(key_token + strlen(prefix), "%u", &id) != 1) { 306f714a188SAmr Mokhtar printf("Missing ID of %s\n", prefix); 307f714a188SAmr Mokhtar return -1; 308f714a188SAmr Mokhtar } 309f714a188SAmr Mokhtar if (id != *nb_ops) { 310f714a188SAmr Mokhtar printf( 311f714a188SAmr Mokhtar "Please order data entries sequentially, i.e. %s0, %s1, ...\n", 312f714a188SAmr Mokhtar prefix, prefix); 313f714a188SAmr Mokhtar return -1; 314f714a188SAmr Mokhtar } 315f714a188SAmr Mokhtar 316f714a188SAmr Mokhtar /* Clear new op data struct */ 317f714a188SAmr Mokhtar memset(op_data + *nb_ops, 0, sizeof(struct op_data_buf)); 318f714a188SAmr Mokhtar 319f714a188SAmr Mokhtar ret = parse_values(token, &data, &data_length); 320f714a188SAmr Mokhtar if (!ret) { 321f714a188SAmr Mokhtar op_data[*nb_ops].addr = data; 322f714a188SAmr Mokhtar op_data[*nb_ops].length = data_length; 323f714a188SAmr Mokhtar ++(*nb_ops); 324f714a188SAmr Mokhtar } 325f714a188SAmr Mokhtar 326f714a188SAmr Mokhtar return ret; 327f714a188SAmr Mokhtar } 328f714a188SAmr Mokhtar 329f714a188SAmr Mokhtar /* parses turbo decoder parameters and assigns to global variable */ 330f714a188SAmr Mokhtar static int 331f714a188SAmr Mokhtar parse_decoder_params(const char *key_token, char *token, 332f714a188SAmr Mokhtar struct test_bbdev_vector *vector) 333f714a188SAmr Mokhtar { 334f714a188SAmr Mokhtar int ret = 0, status = 0; 335f714a188SAmr Mokhtar uint32_t op_flags = 0; 336f714a188SAmr Mokhtar char *err = NULL; 337f714a188SAmr Mokhtar 338f714a188SAmr Mokhtar struct rte_bbdev_op_turbo_dec *turbo_dec = &vector->turbo_dec; 339f714a188SAmr Mokhtar 340f714a188SAmr Mokhtar /* compare keys */ 341f714a188SAmr Mokhtar if (starts_with(key_token, op_data_prefixes[DATA_INPUT])) 342f714a188SAmr Mokhtar ret = parse_data_entry(key_token, token, vector, 343f714a188SAmr Mokhtar DATA_INPUT, op_data_prefixes[DATA_INPUT]); 344f714a188SAmr Mokhtar 345f714a188SAmr Mokhtar else if (starts_with(key_token, op_data_prefixes[DATA_SOFT_OUTPUT])) 346f714a188SAmr Mokhtar ret = parse_data_entry(key_token, token, vector, 347f714a188SAmr Mokhtar DATA_SOFT_OUTPUT, 348f714a188SAmr Mokhtar op_data_prefixes[DATA_SOFT_OUTPUT]); 349f714a188SAmr Mokhtar 350f714a188SAmr Mokhtar else if (starts_with(key_token, op_data_prefixes[DATA_HARD_OUTPUT])) 351f714a188SAmr Mokhtar ret = parse_data_entry(key_token, token, vector, 352f714a188SAmr Mokhtar DATA_HARD_OUTPUT, 353f714a188SAmr Mokhtar op_data_prefixes[DATA_HARD_OUTPUT]); 354f714a188SAmr Mokhtar else if (!strcmp(key_token, "e")) { 355f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_E; 356f714a188SAmr Mokhtar turbo_dec->cb_params.e = (uint32_t) strtoul(token, &err, 0); 357f714a188SAmr Mokhtar } else if (!strcmp(key_token, "ea")) { 358f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_EA; 359f714a188SAmr Mokhtar turbo_dec->tb_params.ea = (uint32_t) strtoul(token, &err, 0); 360f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 361f714a188SAmr Mokhtar } else if (!strcmp(key_token, "eb")) { 362f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_EB; 363f714a188SAmr Mokhtar turbo_dec->tb_params.eb = (uint32_t) strtoul(token, &err, 0); 364f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 365f714a188SAmr Mokhtar } else if (!strcmp(key_token, "k")) { 366f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_K; 367f714a188SAmr Mokhtar turbo_dec->cb_params.k = (uint16_t) strtoul(token, &err, 0); 368f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 369f714a188SAmr Mokhtar } else if (!strcmp(key_token, "k_pos")) { 370f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_K_POS; 371f714a188SAmr Mokhtar turbo_dec->tb_params.k_pos = (uint16_t) strtoul(token, &err, 0); 372f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 373f714a188SAmr Mokhtar } else if (!strcmp(key_token, "k_neg")) { 374f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_K_NEG; 375f714a188SAmr Mokhtar turbo_dec->tb_params.k_neg = (uint16_t) strtoul(token, &err, 0); 376f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 377f714a188SAmr Mokhtar } else if (!strcmp(key_token, "c")) { 378f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_C; 379f714a188SAmr Mokhtar turbo_dec->tb_params.c = (uint16_t) strtoul(token, &err, 0); 380f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 381f714a188SAmr Mokhtar } else if (!strcmp(key_token, "c_neg")) { 382f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_C_NEG; 383f714a188SAmr Mokhtar turbo_dec->tb_params.c_neg = (uint16_t) strtoul(token, &err, 0); 384f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 385f714a188SAmr Mokhtar } else if (!strcmp(key_token, "cab")) { 386f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_CAB; 387f714a188SAmr Mokhtar turbo_dec->tb_params.cab = (uint8_t) strtoul(token, &err, 0); 388f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 389f714a188SAmr Mokhtar } else if (!strcmp(key_token, "rv_index")) { 390f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_RV_INDEX; 391f714a188SAmr Mokhtar turbo_dec->rv_index = (uint8_t) strtoul(token, &err, 0); 392f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 393f714a188SAmr Mokhtar } else if (!strcmp(key_token, "iter_max")) { 394f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_ITER_MAX; 395f714a188SAmr Mokhtar turbo_dec->iter_max = (uint8_t) strtoul(token, &err, 0); 396f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 397f714a188SAmr Mokhtar } else if (!strcmp(key_token, "iter_min")) { 398f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_ITER_MIN; 399f714a188SAmr Mokhtar turbo_dec->iter_min = (uint8_t) strtoul(token, &err, 0); 400f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 401f714a188SAmr Mokhtar } else if (!strcmp(key_token, "expected_iter_count")) { 402f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_EXPECTED_ITER_COUNT; 403f714a188SAmr Mokhtar turbo_dec->iter_count = (uint8_t) strtoul(token, &err, 0); 404f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 405f714a188SAmr Mokhtar } else if (!strcmp(key_token, "ext_scale")) { 406f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_EXT_SCALE; 407f714a188SAmr Mokhtar turbo_dec->ext_scale = (uint8_t) strtoul(token, &err, 0); 408f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 409f714a188SAmr Mokhtar } else if (!strcmp(key_token, "num_maps")) { 410f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_NUM_MAPS; 411f714a188SAmr Mokhtar turbo_dec->num_maps = (uint8_t) strtoul(token, &err, 0); 412f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 413f714a188SAmr Mokhtar } else if (!strcmp(key_token, "code_block_mode")) { 414f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_CODE_BLOCK_MODE; 415f714a188SAmr Mokhtar turbo_dec->code_block_mode = (uint8_t) strtoul(token, &err, 0); 416f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 417f714a188SAmr Mokhtar } else if (!strcmp(key_token, "op_flags")) { 418f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_OP_FLAGS; 419f714a188SAmr Mokhtar ret = parse_turbo_flags(token, &op_flags, 420f714a188SAmr Mokhtar vector->op_type); 421f714a188SAmr Mokhtar if (!ret) 422f714a188SAmr Mokhtar turbo_dec->op_flags = op_flags; 423f714a188SAmr Mokhtar } else if (!strcmp(key_token, "expected_status")) { 424f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_EXPECTED_STATUS; 425f714a188SAmr Mokhtar ret = parse_expected_status(token, &status, vector->op_type); 426f714a188SAmr Mokhtar if (!ret) 427f714a188SAmr Mokhtar vector->expected_status = status; 428f714a188SAmr Mokhtar } else { 429f714a188SAmr Mokhtar printf("Not valid dec key: '%s'\n", key_token); 430f714a188SAmr Mokhtar return -1; 431f714a188SAmr Mokhtar } 432f714a188SAmr Mokhtar 433f714a188SAmr Mokhtar if (ret != 0) { 434f714a188SAmr Mokhtar printf("Failed with convert '%s\t%s'\n", key_token, token); 435f714a188SAmr Mokhtar return -1; 436f714a188SAmr Mokhtar } 437f714a188SAmr Mokhtar 438f714a188SAmr Mokhtar return 0; 439f714a188SAmr Mokhtar } 440f714a188SAmr Mokhtar 441f714a188SAmr Mokhtar /* parses turbo encoder parameters and assigns to global variable */ 442f714a188SAmr Mokhtar static int 443f714a188SAmr Mokhtar parse_encoder_params(const char *key_token, char *token, 444f714a188SAmr Mokhtar struct test_bbdev_vector *vector) 445f714a188SAmr Mokhtar { 446f714a188SAmr Mokhtar int ret = 0, status = 0; 447f714a188SAmr Mokhtar uint32_t op_flags = 0; 448f714a188SAmr Mokhtar char *err = NULL; 449f714a188SAmr Mokhtar 450f714a188SAmr Mokhtar 451f714a188SAmr Mokhtar struct rte_bbdev_op_turbo_enc *turbo_enc = &vector->turbo_enc; 452f714a188SAmr Mokhtar 453f714a188SAmr Mokhtar if (starts_with(key_token, op_data_prefixes[DATA_INPUT])) 454f714a188SAmr Mokhtar ret = parse_data_entry(key_token, token, vector, 455f714a188SAmr Mokhtar DATA_INPUT, op_data_prefixes[DATA_INPUT]); 456f714a188SAmr Mokhtar else if (starts_with(key_token, "output")) 457f714a188SAmr Mokhtar ret = parse_data_entry(key_token, token, vector, 458f714a188SAmr Mokhtar DATA_HARD_OUTPUT, "output"); 459f714a188SAmr Mokhtar else if (!strcmp(key_token, "e")) { 460f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_E; 461f714a188SAmr Mokhtar turbo_enc->cb_params.e = (uint32_t) strtoul(token, &err, 0); 462f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 463f714a188SAmr Mokhtar } else if (!strcmp(key_token, "ea")) { 464f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_EA; 465f714a188SAmr Mokhtar turbo_enc->tb_params.ea = (uint32_t) strtoul(token, &err, 0); 466f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 467f714a188SAmr Mokhtar } else if (!strcmp(key_token, "eb")) { 468f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_EB; 469f714a188SAmr Mokhtar turbo_enc->tb_params.eb = (uint32_t) strtoul(token, &err, 0); 470f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 471f714a188SAmr Mokhtar } else if (!strcmp(key_token, "k")) { 472f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_K; 473f714a188SAmr Mokhtar turbo_enc->cb_params.k = (uint16_t) strtoul(token, &err, 0); 474f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 475f714a188SAmr Mokhtar } else if (!strcmp(key_token, "k_neg")) { 476f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_K_NEG; 477f714a188SAmr Mokhtar turbo_enc->tb_params.k_neg = (uint16_t) strtoul(token, &err, 0); 478f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 479f714a188SAmr Mokhtar } else if (!strcmp(key_token, "k_pos")) { 480f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_K_POS; 481f714a188SAmr Mokhtar turbo_enc->tb_params.k_pos = (uint16_t) strtoul(token, &err, 0); 482f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 483f714a188SAmr Mokhtar } else if (!strcmp(key_token, "c_neg")) { 484f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_C_NEG; 485f714a188SAmr Mokhtar turbo_enc->tb_params.c_neg = (uint8_t) strtoul(token, &err, 0); 486f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 487f714a188SAmr Mokhtar } else if (!strcmp(key_token, "c")) { 488f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_C; 489f714a188SAmr Mokhtar turbo_enc->tb_params.c = (uint8_t) strtoul(token, &err, 0); 490f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 491f714a188SAmr Mokhtar } else if (!strcmp(key_token, "cab")) { 492f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_CAB; 493f714a188SAmr Mokhtar turbo_enc->tb_params.cab = (uint8_t) strtoul(token, &err, 0); 494f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 495f714a188SAmr Mokhtar } else if (!strcmp(key_token, "rv_index")) { 496f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_RV_INDEX; 497f714a188SAmr Mokhtar turbo_enc->rv_index = (uint8_t) strtoul(token, &err, 0); 498f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 499f714a188SAmr Mokhtar } else if (!strcmp(key_token, "ncb")) { 500f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_NCB; 501f714a188SAmr Mokhtar turbo_enc->cb_params.ncb = (uint16_t) strtoul(token, &err, 0); 502f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 503f714a188SAmr Mokhtar } else if (!strcmp(key_token, "ncb_neg")) { 504f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_NCB_NEG; 505f714a188SAmr Mokhtar turbo_enc->tb_params.ncb_neg = 506f714a188SAmr Mokhtar (uint16_t) strtoul(token, &err, 0); 507f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 508f714a188SAmr Mokhtar } else if (!strcmp(key_token, "ncb_pos")) { 509f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_NCB_POS; 510f714a188SAmr Mokhtar turbo_enc->tb_params.ncb_pos = 511f714a188SAmr Mokhtar (uint16_t) strtoul(token, &err, 0); 512f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 513f714a188SAmr Mokhtar } else if (!strcmp(key_token, "r")) { 514f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_R; 515f714a188SAmr Mokhtar turbo_enc->tb_params.r = (uint8_t) strtoul(token, &err, 0); 516f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 517f714a188SAmr Mokhtar } else if (!strcmp(key_token, "code_block_mode")) { 518f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_CODE_BLOCK_MODE; 519f714a188SAmr Mokhtar turbo_enc->code_block_mode = (uint8_t) strtoul(token, &err, 0); 520f714a188SAmr Mokhtar ret = ((err == NULL) || (*err != '\0')) ? -1 : 0; 521f714a188SAmr Mokhtar } else if (!strcmp(key_token, "op_flags")) { 522f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_OP_FLAGS; 523f714a188SAmr Mokhtar ret = parse_turbo_flags(token, &op_flags, 524f714a188SAmr Mokhtar vector->op_type); 525f714a188SAmr Mokhtar if (!ret) 526f714a188SAmr Mokhtar turbo_enc->op_flags = op_flags; 527f714a188SAmr Mokhtar } else if (!strcmp(key_token, "expected_status")) { 528f714a188SAmr Mokhtar vector->mask |= TEST_BBDEV_VF_EXPECTED_STATUS; 529f714a188SAmr Mokhtar ret = parse_expected_status(token, &status, vector->op_type); 530f714a188SAmr Mokhtar if (!ret) 531f714a188SAmr Mokhtar vector->expected_status = status; 532f714a188SAmr Mokhtar } else { 533f714a188SAmr Mokhtar printf("Not valid enc key: '%s'\n", key_token); 534f714a188SAmr Mokhtar return -1; 535f714a188SAmr Mokhtar } 536f714a188SAmr Mokhtar 537f714a188SAmr Mokhtar if (ret != 0) { 538f714a188SAmr Mokhtar printf("Failed with convert '%s\t%s'\n", key_token, token); 539f714a188SAmr Mokhtar return -1; 540f714a188SAmr Mokhtar } 541f714a188SAmr Mokhtar 542f714a188SAmr Mokhtar return 0; 543f714a188SAmr Mokhtar } 544f714a188SAmr Mokhtar 545f714a188SAmr Mokhtar /* checks the type of key and assigns data */ 546f714a188SAmr Mokhtar static int 547f714a188SAmr Mokhtar parse_entry(char *entry, struct test_bbdev_vector *vector) 548f714a188SAmr Mokhtar { 549f714a188SAmr Mokhtar int ret = 0; 550f714a188SAmr Mokhtar char *token, *key_token; 551f714a188SAmr Mokhtar enum rte_bbdev_op_type op_type = RTE_BBDEV_OP_NONE; 552f714a188SAmr Mokhtar 553f714a188SAmr Mokhtar if (entry == NULL) { 554f714a188SAmr Mokhtar printf("Expected entry value\n"); 555f714a188SAmr Mokhtar return -1; 556f714a188SAmr Mokhtar } 557f714a188SAmr Mokhtar 558f714a188SAmr Mokhtar /* get key */ 559f714a188SAmr Mokhtar token = strtok(entry, ENTRY_DELIMITER); 560f714a188SAmr Mokhtar key_token = token; 561f714a188SAmr Mokhtar /* get values for key */ 562f714a188SAmr Mokhtar token = strtok(NULL, ENTRY_DELIMITER); 563f714a188SAmr Mokhtar 564f714a188SAmr Mokhtar if (key_token == NULL || token == NULL) { 565f714a188SAmr Mokhtar printf("Expected 'key = values' but was '%.40s'..\n", entry); 566f714a188SAmr Mokhtar return -1; 567f714a188SAmr Mokhtar } 568f714a188SAmr Mokhtar trim_space(key_token); 569f714a188SAmr Mokhtar 570f714a188SAmr Mokhtar /* first key_token has to specify type of operation */ 571f714a188SAmr Mokhtar if (vector->op_type == RTE_BBDEV_OP_NONE) { 572f714a188SAmr Mokhtar if (!strcmp(key_token, "op_type")) { 573f714a188SAmr Mokhtar ret = op_turbo_type_strtol(token, &op_type); 574f714a188SAmr Mokhtar if (!ret) 575f714a188SAmr Mokhtar vector->op_type = op_type; 576f714a188SAmr Mokhtar return (!ret) ? 0 : -1; 577f714a188SAmr Mokhtar } 578f714a188SAmr Mokhtar printf("First key_token (%s) does not specify op_type\n", 579f714a188SAmr Mokhtar key_token); 580f714a188SAmr Mokhtar return -1; 581f714a188SAmr Mokhtar } 582f714a188SAmr Mokhtar 583f714a188SAmr Mokhtar /* compare keys */ 584f714a188SAmr Mokhtar if (vector->op_type == RTE_BBDEV_OP_TURBO_DEC) { 585f714a188SAmr Mokhtar if (parse_decoder_params(key_token, token, vector) == -1) 586f714a188SAmr Mokhtar return -1; 587f714a188SAmr Mokhtar } else if (vector->op_type == RTE_BBDEV_OP_TURBO_ENC) { 588f714a188SAmr Mokhtar if (parse_encoder_params(key_token, token, vector) == -1) 589f714a188SAmr Mokhtar return -1; 590f714a188SAmr Mokhtar } 591f714a188SAmr Mokhtar 592f714a188SAmr Mokhtar return 0; 593f714a188SAmr Mokhtar } 594f714a188SAmr Mokhtar 595f714a188SAmr Mokhtar static int 596f714a188SAmr Mokhtar check_decoder_segments(struct test_bbdev_vector *vector) 597f714a188SAmr Mokhtar { 598f714a188SAmr Mokhtar unsigned char i; 599f714a188SAmr Mokhtar struct rte_bbdev_op_turbo_dec *turbo_dec = &vector->turbo_dec; 600f714a188SAmr Mokhtar 601f714a188SAmr Mokhtar if (vector->entries[DATA_INPUT].nb_segments == 0) 602f714a188SAmr Mokhtar return -1; 603f714a188SAmr Mokhtar 604f714a188SAmr Mokhtar for (i = 0; i < vector->entries[DATA_INPUT].nb_segments; i++) 605f714a188SAmr Mokhtar if (vector->entries[DATA_INPUT].segments[i].addr == NULL) 606f714a188SAmr Mokhtar return -1; 607f714a188SAmr Mokhtar 608f714a188SAmr Mokhtar if (vector->entries[DATA_HARD_OUTPUT].nb_segments == 0) 609f714a188SAmr Mokhtar return -1; 610f714a188SAmr Mokhtar 611f714a188SAmr Mokhtar for (i = 0; i < vector->entries[DATA_HARD_OUTPUT].nb_segments; 612f714a188SAmr Mokhtar i++) 613f714a188SAmr Mokhtar if (vector->entries[DATA_HARD_OUTPUT].segments[i].addr == NULL) 614f714a188SAmr Mokhtar return -1; 615f714a188SAmr Mokhtar 616f714a188SAmr Mokhtar if ((turbo_dec->op_flags & RTE_BBDEV_TURBO_SOFT_OUTPUT) && 617f714a188SAmr Mokhtar (vector->entries[DATA_SOFT_OUTPUT].nb_segments == 0)) 618f714a188SAmr Mokhtar return -1; 619f714a188SAmr Mokhtar 620f714a188SAmr Mokhtar for (i = 0; i < vector->entries[DATA_SOFT_OUTPUT].nb_segments; 621f714a188SAmr Mokhtar i++) 622f714a188SAmr Mokhtar if (vector->entries[DATA_SOFT_OUTPUT].segments[i].addr == NULL) 623f714a188SAmr Mokhtar return -1; 624f714a188SAmr Mokhtar 625f714a188SAmr Mokhtar return 0; 626f714a188SAmr Mokhtar } 627f714a188SAmr Mokhtar 628f714a188SAmr Mokhtar static int 629f714a188SAmr Mokhtar check_decoder_llr_spec(struct test_bbdev_vector *vector) 630f714a188SAmr Mokhtar { 631f714a188SAmr Mokhtar struct rte_bbdev_op_turbo_dec *turbo_dec = &vector->turbo_dec; 632f714a188SAmr Mokhtar 633f714a188SAmr Mokhtar /* Check input LLR sign formalism specification */ 634f714a188SAmr Mokhtar if ((turbo_dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN) && 635f714a188SAmr Mokhtar (turbo_dec->op_flags & 636f714a188SAmr Mokhtar RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN)) { 637f714a188SAmr Mokhtar printf( 638f714a188SAmr Mokhtar "Both positive and negative LLR input flags were set!\n"); 639f714a188SAmr Mokhtar return -1; 640f714a188SAmr Mokhtar } 641f714a188SAmr Mokhtar if (!(turbo_dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_IN) && 642f714a188SAmr Mokhtar !(turbo_dec->op_flags & 643f714a188SAmr Mokhtar RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN)) { 644f714a188SAmr Mokhtar printf( 645f714a188SAmr Mokhtar "WARNING: input LLR sign formalism was not specified and will be set to negative LLR for '1' bit\n"); 646f714a188SAmr Mokhtar turbo_dec->op_flags |= RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN; 647f714a188SAmr Mokhtar } 648f714a188SAmr Mokhtar 649f714a188SAmr Mokhtar if (!(turbo_dec->op_flags & RTE_BBDEV_TURBO_SOFT_OUTPUT)) 650f714a188SAmr Mokhtar return 0; 651f714a188SAmr Mokhtar 652f714a188SAmr Mokhtar /* Check output LLR sign formalism specification */ 653f714a188SAmr Mokhtar if ((turbo_dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT) && 654f714a188SAmr Mokhtar (turbo_dec->op_flags & 655f714a188SAmr Mokhtar RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT)) { 656f714a188SAmr Mokhtar printf( 657f714a188SAmr Mokhtar "Both positive and negative LLR output flags were set!\n"); 658f714a188SAmr Mokhtar return -1; 659f714a188SAmr Mokhtar } 660f714a188SAmr Mokhtar if (!(turbo_dec->op_flags & RTE_BBDEV_TURBO_POS_LLR_1_BIT_SOFT_OUT) && 661f714a188SAmr Mokhtar !(turbo_dec->op_flags & 662f714a188SAmr Mokhtar RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT)) { 663f714a188SAmr Mokhtar printf( 664f714a188SAmr Mokhtar "WARNING: soft output LLR sign formalism was not specified and will be set to negative LLR for '1' bit\n"); 665f714a188SAmr Mokhtar turbo_dec->op_flags |= 666f714a188SAmr Mokhtar RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT; 667f714a188SAmr Mokhtar } 668f714a188SAmr Mokhtar 669f714a188SAmr Mokhtar return 0; 670f714a188SAmr Mokhtar } 671f714a188SAmr Mokhtar 672f714a188SAmr Mokhtar /* checks decoder parameters */ 673f714a188SAmr Mokhtar static int 674f714a188SAmr Mokhtar check_decoder(struct test_bbdev_vector *vector) 675f714a188SAmr Mokhtar { 676f714a188SAmr Mokhtar struct rte_bbdev_op_turbo_dec *turbo_dec = &vector->turbo_dec; 677f714a188SAmr Mokhtar const int mask = vector->mask; 678f714a188SAmr Mokhtar 679f714a188SAmr Mokhtar if (check_decoder_segments(vector) < 0) 680f714a188SAmr Mokhtar return -1; 681f714a188SAmr Mokhtar 682f714a188SAmr Mokhtar if (check_decoder_llr_spec(vector) < 0) 683f714a188SAmr Mokhtar return -1; 684f714a188SAmr Mokhtar 685f714a188SAmr Mokhtar /* Check which params were set */ 686f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_CODE_BLOCK_MODE)) { 687f714a188SAmr Mokhtar printf( 688f714a188SAmr Mokhtar "WARNING: code_block_mode was not specified in vector file and will be set to 1 (0 - TB Mode, 1 - CB mode)\n"); 689f714a188SAmr Mokhtar turbo_dec->code_block_mode = 1; 690f714a188SAmr Mokhtar } 691f714a188SAmr Mokhtar if (turbo_dec->code_block_mode == 0) { 692f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_EA)) 693f714a188SAmr Mokhtar printf( 694f714a188SAmr Mokhtar "WARNING: ea was not specified in vector file and will be set to 0\n"); 695f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_EB)) 696f714a188SAmr Mokhtar printf( 697f714a188SAmr Mokhtar "WARNING: eb was not specified in vector file and will be set to 0\n"); 698f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_K_NEG)) 699f714a188SAmr Mokhtar printf( 700f714a188SAmr Mokhtar "WARNING: k_neg was not specified in vector file and will be set to 0\n"); 701f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_K_POS)) 702f714a188SAmr Mokhtar printf( 703f714a188SAmr Mokhtar "WARNING: k_pos was not specified in vector file and will be set to 0\n"); 704f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_C_NEG)) 705f714a188SAmr Mokhtar printf( 706f714a188SAmr Mokhtar "WARNING: c_neg was not specified in vector file and will be set to 0\n"); 707f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_C)) { 708f714a188SAmr Mokhtar printf( 709f714a188SAmr Mokhtar "WARNING: c was not specified in vector file and will be set to 1\n"); 710f714a188SAmr Mokhtar turbo_dec->tb_params.c = 1; 711f714a188SAmr Mokhtar } 712f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_CAB)) 713f714a188SAmr Mokhtar printf( 714f714a188SAmr Mokhtar "WARNING: cab was not specified in vector file and will be set to 0\n"); 715f714a188SAmr Mokhtar } else { 716f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_E)) 717f714a188SAmr Mokhtar printf( 718f714a188SAmr Mokhtar "WARNING: e was not specified in vector file and will be set to 0\n"); 719f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_K)) 720f714a188SAmr Mokhtar printf( 721f714a188SAmr Mokhtar "WARNING: k was not specified in vector file and will be set to 0\n"); 722f714a188SAmr Mokhtar } 723f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_RV_INDEX)) 724f714a188SAmr Mokhtar printf( 725f714a188SAmr Mokhtar "WARNING: rv_index was not specified in vector file and will be set to 0\n"); 726f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_ITER_MIN)) 727f714a188SAmr Mokhtar printf( 728f714a188SAmr Mokhtar "WARNING: iter_min was not specified in vector file and will be set to 0\n"); 729f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_ITER_MAX)) 730f714a188SAmr Mokhtar printf( 731f714a188SAmr Mokhtar "WARNING: iter_max was not specified in vector file and will be set to 0\n"); 732f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_EXPECTED_ITER_COUNT)) 733f714a188SAmr Mokhtar printf( 734f714a188SAmr Mokhtar "WARNING: expected_iter_count was not specified in vector file and iter_count will not be validated\n"); 735f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_EXT_SCALE)) 736f714a188SAmr Mokhtar printf( 737f714a188SAmr Mokhtar "WARNING: ext_scale was not specified in vector file and will be set to 0\n"); 738f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_OP_FLAGS)) { 739f714a188SAmr Mokhtar printf( 740f714a188SAmr Mokhtar "WARNING: op_flags was not specified in vector file and capabilities will not be validated\n"); 741f714a188SAmr Mokhtar turbo_dec->num_maps = 0; 742f714a188SAmr Mokhtar } else if (!(turbo_dec->op_flags & RTE_BBDEV_TURBO_MAP_DEC) && 743f714a188SAmr Mokhtar mask & TEST_BBDEV_VF_NUM_MAPS) { 744f714a188SAmr Mokhtar printf( 745f714a188SAmr Mokhtar "WARNING: RTE_BBDEV_TURBO_MAP_DEC was not set in vector file and num_maps will be set to 0\n"); 746f714a188SAmr Mokhtar turbo_dec->num_maps = 0; 747f714a188SAmr Mokhtar } 748f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_EXPECTED_STATUS)) 749f714a188SAmr Mokhtar printf( 750f714a188SAmr Mokhtar "WARNING: expected_status was not specified in vector file and will be set to 0\n"); 751f714a188SAmr Mokhtar return 0; 752f714a188SAmr Mokhtar } 753f714a188SAmr Mokhtar 754f714a188SAmr Mokhtar /* checks encoder parameters */ 755f714a188SAmr Mokhtar static int 756f714a188SAmr Mokhtar check_encoder(struct test_bbdev_vector *vector) 757f714a188SAmr Mokhtar { 758f714a188SAmr Mokhtar unsigned char i; 759f714a188SAmr Mokhtar const int mask = vector->mask; 760f714a188SAmr Mokhtar 761f714a188SAmr Mokhtar if (vector->entries[DATA_INPUT].nb_segments == 0) 762f714a188SAmr Mokhtar return -1; 763f714a188SAmr Mokhtar 764f714a188SAmr Mokhtar for (i = 0; i < vector->entries[DATA_INPUT].nb_segments; i++) 765f714a188SAmr Mokhtar if (vector->entries[DATA_INPUT].segments[i].addr == NULL) 766f714a188SAmr Mokhtar return -1; 767f714a188SAmr Mokhtar 768f714a188SAmr Mokhtar if (vector->entries[DATA_HARD_OUTPUT].nb_segments == 0) 769f714a188SAmr Mokhtar return -1; 770f714a188SAmr Mokhtar 771f714a188SAmr Mokhtar for (i = 0; i < vector->entries[DATA_HARD_OUTPUT].nb_segments; i++) 772f714a188SAmr Mokhtar if (vector->entries[DATA_HARD_OUTPUT].segments[i].addr == NULL) 773f714a188SAmr Mokhtar return -1; 774f714a188SAmr Mokhtar 775f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_CODE_BLOCK_MODE)) { 776f714a188SAmr Mokhtar printf( 777f714a188SAmr Mokhtar "WARNING: code_block_mode was not specified in vector file and will be set to 1\n"); 778f714a188SAmr Mokhtar vector->turbo_enc.code_block_mode = 1; 779f714a188SAmr Mokhtar } 780f714a188SAmr Mokhtar if (vector->turbo_enc.code_block_mode == 0) { 781f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_EA) && (vector->turbo_enc.op_flags & 782f714a188SAmr Mokhtar RTE_BBDEV_TURBO_RATE_MATCH)) 783f714a188SAmr Mokhtar printf( 784f714a188SAmr Mokhtar "WARNING: ea was not specified in vector file and will be set to 0\n"); 785f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_EB) && (vector->turbo_enc.op_flags & 786f714a188SAmr Mokhtar RTE_BBDEV_TURBO_RATE_MATCH)) 787f714a188SAmr Mokhtar printf( 788f714a188SAmr Mokhtar "WARNING: eb was not specified in vector file and will be set to 0\n"); 789f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_K_NEG)) 790f714a188SAmr Mokhtar printf( 791f714a188SAmr Mokhtar "WARNING: k_neg was not specified in vector file and will be set to 0\n"); 792f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_K_POS)) 793f714a188SAmr Mokhtar printf( 794f714a188SAmr Mokhtar "WARNING: k_pos was not specified in vector file and will be set to 0\n"); 795f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_C_NEG)) 796f714a188SAmr Mokhtar printf( 797f714a188SAmr Mokhtar "WARNING: c_neg was not specified in vector file and will be set to 0\n"); 798f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_C)) { 799f714a188SAmr Mokhtar printf( 800f714a188SAmr Mokhtar "WARNING: c was not specified in vector file and will be set to 1\n"); 801f714a188SAmr Mokhtar vector->turbo_enc.tb_params.c = 1; 802f714a188SAmr Mokhtar } 803f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_CAB) && (vector->turbo_enc.op_flags & 804f714a188SAmr Mokhtar RTE_BBDEV_TURBO_RATE_MATCH)) 805f714a188SAmr Mokhtar printf( 806f714a188SAmr Mokhtar "WARNING: cab was not specified in vector file and will be set to 0\n"); 807f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_NCB_NEG)) 808f714a188SAmr Mokhtar printf( 809f714a188SAmr Mokhtar "WARNING: ncb_neg was not specified in vector file and will be set to 0\n"); 810f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_NCB_POS)) 811f714a188SAmr Mokhtar printf( 812f714a188SAmr Mokhtar "WARNING: ncb_pos was not specified in vector file and will be set to 0\n"); 813f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_R)) 814f714a188SAmr Mokhtar printf( 815f714a188SAmr Mokhtar "WARNING: r was not specified in vector file and will be set to 0\n"); 816f714a188SAmr Mokhtar } else { 817f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_E) && (vector->turbo_enc.op_flags & 818f714a188SAmr Mokhtar RTE_BBDEV_TURBO_RATE_MATCH)) 819f714a188SAmr Mokhtar printf( 820f714a188SAmr Mokhtar "WARNING: e was not specified in vector file and will be set to 0\n"); 821f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_K)) 822f714a188SAmr Mokhtar printf( 823f714a188SAmr Mokhtar "WARNING: k was not specified in vector file and will be set to 0\n"); 824f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_NCB)) 825f714a188SAmr Mokhtar printf( 826f714a188SAmr Mokhtar "WARNING: ncb was not specified in vector file and will be set to 0\n"); 827f714a188SAmr Mokhtar } 828f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_RV_INDEX)) 829f714a188SAmr Mokhtar printf( 830f714a188SAmr Mokhtar "WARNING: rv_index was not specified in vector file and will be set to 0\n"); 831f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_OP_FLAGS)) 832f714a188SAmr Mokhtar printf( 833f714a188SAmr Mokhtar "WARNING: op_flags was not specified in vector file and capabilities will not be validated\n"); 834f714a188SAmr Mokhtar if (!(mask & TEST_BBDEV_VF_EXPECTED_STATUS)) 835f714a188SAmr Mokhtar printf( 836f714a188SAmr Mokhtar "WARNING: expected_status was not specified in vector file and will be set to 0\n"); 837f714a188SAmr Mokhtar 838f714a188SAmr Mokhtar return 0; 839f714a188SAmr Mokhtar } 840f714a188SAmr Mokhtar 841f714a188SAmr Mokhtar static int 842f714a188SAmr Mokhtar bbdev_check_vector(struct test_bbdev_vector *vector) 843f714a188SAmr Mokhtar { 844f714a188SAmr Mokhtar if (vector->op_type == RTE_BBDEV_OP_TURBO_DEC) { 845f714a188SAmr Mokhtar if (check_decoder(vector) == -1) 846f714a188SAmr Mokhtar return -1; 847f714a188SAmr Mokhtar } else if (vector->op_type == RTE_BBDEV_OP_TURBO_ENC) { 848f714a188SAmr Mokhtar if (check_encoder(vector) == -1) 849f714a188SAmr Mokhtar return -1; 850f714a188SAmr Mokhtar } else if (vector->op_type != RTE_BBDEV_OP_NONE) { 851f714a188SAmr Mokhtar printf("Vector was not filled\n"); 852f714a188SAmr Mokhtar return -1; 853f714a188SAmr Mokhtar } 854f714a188SAmr Mokhtar 855f714a188SAmr Mokhtar return 0; 856f714a188SAmr Mokhtar } 857f714a188SAmr Mokhtar 858f714a188SAmr Mokhtar int 859f714a188SAmr Mokhtar test_bbdev_vector_read(const char *filename, 860f714a188SAmr Mokhtar struct test_bbdev_vector *vector) 861f714a188SAmr Mokhtar { 862f714a188SAmr Mokhtar int ret = 0; 863f714a188SAmr Mokhtar size_t len = 0; 864f714a188SAmr Mokhtar 865f714a188SAmr Mokhtar FILE *fp = NULL; 866f714a188SAmr Mokhtar char *line = NULL; 867f714a188SAmr Mokhtar char *entry = NULL; 868f714a188SAmr Mokhtar 869f714a188SAmr Mokhtar fp = fopen(filename, "r"); 870f714a188SAmr Mokhtar if (fp == NULL) { 871f714a188SAmr Mokhtar printf("File %s does not exist\n", filename); 872f714a188SAmr Mokhtar return -1; 873f714a188SAmr Mokhtar } 874f714a188SAmr Mokhtar 875f714a188SAmr Mokhtar while (getline(&line, &len, fp) != -1) { 876f714a188SAmr Mokhtar 877f714a188SAmr Mokhtar /* ignore comments and new lines */ 878f714a188SAmr Mokhtar if (line[0] == '#' || line[0] == '/' || line[0] == '\n' 879f714a188SAmr Mokhtar || line[0] == '\r') 880f714a188SAmr Mokhtar continue; 881f714a188SAmr Mokhtar 882f714a188SAmr Mokhtar trim_space(line); 883f714a188SAmr Mokhtar 884f714a188SAmr Mokhtar /* buffer for multiline */ 885f714a188SAmr Mokhtar entry = realloc(entry, strlen(line) + 1); 886f714a188SAmr Mokhtar if (entry == NULL) { 887f714a188SAmr Mokhtar printf("Fail to realloc %zu bytes\n", strlen(line) + 1); 888f714a188SAmr Mokhtar ret = -ENOMEM; 889f714a188SAmr Mokhtar goto exit; 890f714a188SAmr Mokhtar } 891f714a188SAmr Mokhtar 892f714a188SAmr Mokhtar memset(entry, 0, strlen(line) + 1); 893f714a188SAmr Mokhtar strncpy(entry, line, strlen(line)); 894f714a188SAmr Mokhtar 895f714a188SAmr Mokhtar /* check if entry ends with , or = */ 896f714a188SAmr Mokhtar if (entry[strlen(entry) - 1] == ',' 897f714a188SAmr Mokhtar || entry[strlen(entry) - 1] == '=') { 898f714a188SAmr Mokhtar while (getline(&line, &len, fp) != -1) { 899f714a188SAmr Mokhtar trim_space(line); 900f714a188SAmr Mokhtar 901f714a188SAmr Mokhtar /* extend entry about length of new line */ 902f714a188SAmr Mokhtar char *entry_extended = realloc(entry, 903f714a188SAmr Mokhtar strlen(line) + 904f714a188SAmr Mokhtar strlen(entry) + 1); 905f714a188SAmr Mokhtar 906f714a188SAmr Mokhtar if (entry_extended == NULL) { 907f714a188SAmr Mokhtar printf("Fail to allocate %zu bytes\n", 908f714a188SAmr Mokhtar strlen(line) + 909f714a188SAmr Mokhtar strlen(entry) + 1); 910f714a188SAmr Mokhtar ret = -ENOMEM; 911f714a188SAmr Mokhtar goto exit; 912f714a188SAmr Mokhtar } 913f714a188SAmr Mokhtar 914f714a188SAmr Mokhtar entry = entry_extended; 915f714a188SAmr Mokhtar strncat(entry, line, strlen(line)); 916f714a188SAmr Mokhtar 917f714a188SAmr Mokhtar if (entry[strlen(entry) - 1] != ',') 918f714a188SAmr Mokhtar break; 919f714a188SAmr Mokhtar } 920f714a188SAmr Mokhtar } 921f714a188SAmr Mokhtar ret = parse_entry(entry, vector); 922f714a188SAmr Mokhtar if (ret != 0) { 923f714a188SAmr Mokhtar printf("An error occurred while parsing!\n"); 924f714a188SAmr Mokhtar goto exit; 925f714a188SAmr Mokhtar } 926f714a188SAmr Mokhtar } 927f714a188SAmr Mokhtar ret = bbdev_check_vector(vector); 928f714a188SAmr Mokhtar if (ret != 0) 929f714a188SAmr Mokhtar printf("An error occurred while checking!\n"); 930f714a188SAmr Mokhtar 931f714a188SAmr Mokhtar exit: 932f714a188SAmr Mokhtar fclose(fp); 933f714a188SAmr Mokhtar free(line); 934f714a188SAmr Mokhtar free(entry); 935f714a188SAmr Mokhtar 936f714a188SAmr Mokhtar return ret; 937f714a188SAmr Mokhtar } 938