xref: /dpdk/app/test-crypto-perf/cperf_options_parsing.c (revision b82742f99f4d67de6a0024f9f090e8dece3a8e4b)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2017 Intel Corporation
3  */
4 
5 #include <getopt.h>
6 #include <stdlib.h>
7 #include <unistd.h>
8 
9 #include <rte_cryptodev.h>
10 #include <rte_malloc.h>
11 #include <rte_ether.h>
12 
13 #include "cperf_options.h"
14 #include "cperf_test_vectors.h"
15 
16 #define AES_BLOCK_SIZE 16
17 #define DES_BLOCK_SIZE 8
18 
19 struct name_id_map {
20 	const char *name;
21 	uint32_t id;
22 };
23 
24 static void
25 usage(char *progname)
26 {
27 	printf("%s [EAL options] --\n"
28 		" --silent: disable options dump\n"
29 		" --ptest throughput / latency / verify / pmd-cyclecount :"
30 		" set test type\n"
31 		" --pool_sz N: set the number of crypto ops/mbufs allocated\n"
32 		" --total-ops N: set the number of total operations performed\n"
33 		" --burst-sz N: set the number of packets per burst\n"
34 		" --buffer-sz N: set the size of a single packet\n"
35 		" --imix N: set the distribution of packet sizes\n"
36 		" --segment-sz N: set the size of the segment to use\n"
37 		" --desc-nb N: set number of descriptors for each crypto device\n"
38 		" --devtype TYPE: set crypto device type to use\n"
39 		" --optype cipher-only / auth-only / cipher-then-auth / auth-then-cipher /\n"
40 		"        aead / pdcp / docsis / ipsec / modex / sm2 / tls-record : set operation type\n"
41 		" --sessionless: enable session-less crypto operations\n"
42 		" --out-of-place: enable out-of-place crypto operations\n"
43 		" --test-file NAME: set the test vector file path\n"
44 		" --test-name NAME: set specific test name section in test file\n"
45 		" --cipher-algo ALGO: set cipher algorithm\n"
46 		" --cipher-op encrypt / decrypt: set the cipher operation\n"
47 		" --cipher-key-sz N: set the cipher key size\n"
48 		" --cipher-iv-sz N: set the cipher IV size\n"
49 		" --auth-algo ALGO: set auth algorithm\n"
50 		" --auth-op generate / verify: set the auth operation\n"
51 		" --auth-key-sz N: set the auth key size\n"
52 		" --auth-iv-sz N: set the auth IV size\n"
53 		" --aead-algo ALGO: set AEAD algorithm\n"
54 		" --aead-op encrypt / decrypt: set the AEAD operation\n"
55 		" --aead-key-sz N: set the AEAD key size\n"
56 		" --aead-iv-sz N: set the AEAD IV size\n"
57 		" --aead-aad-sz N: set the AEAD AAD size\n"
58 		" --digest-sz N: set the digest size\n"
59 		" --pmd-cyclecount-delay-ms N: set delay between enqueue\n"
60 		"           and dequeue in pmd-cyclecount benchmarking mode\n"
61 		" --csv-friendly: enable test result output CSV friendly\n"
62 		" --modex-len N: modex length, supported lengths are "
63 		"60, 128, 255, 448. Default: 128\n"
64 		" --asym-op encrypt / decrypt / sign / verify : set asym operation type\n"
65 #ifdef RTE_LIB_SECURITY
66 		" --pdcp-sn-sz N: set PDCP SN size N <5/7/12/15/18>\n"
67 		" --pdcp-domain DOMAIN: set PDCP domain <control/user>\n"
68 		" --pdcp-ses-hfn-en: enable session based fixed HFN\n"
69 		" --enable-sdap: enable sdap\n"
70 		" --docsis-hdr-sz: set DOCSIS header size\n"
71 		" --tls-version VER: set TLS VERSION <TLS1.2/TLS1.3/DTLS1.2>\n"
72 #endif
73 		" -h: prints this help\n",
74 		progname);
75 }
76 
77 static int
78 get_str_key_id_mapping(struct name_id_map *map, unsigned int map_len,
79 		const char *str_key)
80 {
81 	unsigned int i;
82 
83 	for (i = 0; i < map_len; i++) {
84 
85 		if (strcmp(str_key, map[i].name) == 0)
86 			return map[i].id;
87 	}
88 
89 	return -1;
90 }
91 
92 static int
93 parse_cperf_test_type(struct cperf_options *opts, const char *arg)
94 {
95 	struct name_id_map cperftest_namemap[] = {
96 		{
97 			cperf_test_type_strs[CPERF_TEST_TYPE_THROUGHPUT],
98 			CPERF_TEST_TYPE_THROUGHPUT
99 		},
100 		{
101 			cperf_test_type_strs[CPERF_TEST_TYPE_VERIFY],
102 			CPERF_TEST_TYPE_VERIFY
103 		},
104 		{
105 			cperf_test_type_strs[CPERF_TEST_TYPE_LATENCY],
106 			CPERF_TEST_TYPE_LATENCY
107 		},
108 		{
109 			cperf_test_type_strs[CPERF_TEST_TYPE_PMDCC],
110 			CPERF_TEST_TYPE_PMDCC
111 		}
112 	};
113 
114 	int id = get_str_key_id_mapping(
115 			(struct name_id_map *)cperftest_namemap,
116 			RTE_DIM(cperftest_namemap), arg);
117 	if (id < 0) {
118 		RTE_LOG(ERR, USER1, "failed to parse test type");
119 		return -1;
120 	}
121 
122 	opts->test = (enum cperf_perf_test_type)id;
123 
124 	return 0;
125 }
126 
127 static int
128 parse_uint32_t(uint32_t *value, const char *arg)
129 {
130 	char *end = NULL;
131 	unsigned long n = strtoul(arg, &end, 10);
132 
133 	if ((optarg[0] == '\0') || (end == NULL) || (*end != '\0'))
134 		return -1;
135 
136 	if (n > UINT32_MAX)
137 		return -ERANGE;
138 
139 	*value = (uint32_t) n;
140 
141 	return 0;
142 }
143 
144 static int
145 parse_uint16_t(uint16_t *value, const char *arg)
146 {
147 	uint32_t val = 0;
148 	int ret = parse_uint32_t(&val, arg);
149 
150 	if (ret < 0)
151 		return ret;
152 
153 	if (val > UINT16_MAX)
154 		return -ERANGE;
155 
156 	*value = (uint16_t) val;
157 
158 	return 0;
159 }
160 
161 static int
162 parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc)
163 {
164 	char *token;
165 	uint32_t number;
166 
167 	char *copy_arg = strdup(arg);
168 
169 	if (copy_arg == NULL)
170 		return -1;
171 
172 	errno = 0;
173 	token = strtok(copy_arg, ":");
174 
175 	/* Parse minimum value */
176 	if (token != NULL) {
177 		number = strtoul(token, NULL, 10);
178 
179 		if (errno == EINVAL || errno == ERANGE ||
180 				number == 0)
181 			goto err_range;
182 
183 		*min = number;
184 	} else
185 		goto err_range;
186 
187 	token = strtok(NULL, ":");
188 
189 	/* Parse increment value */
190 	if (token != NULL) {
191 		number = strtoul(token, NULL, 10);
192 
193 		if (errno == EINVAL || errno == ERANGE ||
194 				number == 0)
195 			goto err_range;
196 
197 		*inc = number;
198 	} else
199 		goto err_range;
200 
201 	token = strtok(NULL, ":");
202 
203 	/* Parse maximum value */
204 	if (token != NULL) {
205 		number = strtoul(token, NULL, 10);
206 
207 		if (errno == EINVAL || errno == ERANGE ||
208 				number == 0 ||
209 				number < *min)
210 			goto err_range;
211 
212 		*max = number;
213 	} else
214 		goto err_range;
215 
216 	if (strtok(NULL, ":") != NULL)
217 		goto err_range;
218 
219 	free(copy_arg);
220 	return 0;
221 
222 err_range:
223 	free(copy_arg);
224 	return -1;
225 }
226 
227 static int
228 parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
229 {
230 	char *token;
231 	uint32_t number;
232 	uint8_t count = 0;
233 	uint32_t temp_min;
234 	uint32_t temp_max;
235 
236 	char *copy_arg = strdup(arg);
237 
238 	if (copy_arg == NULL)
239 		return -1;
240 
241 	errno = 0;
242 	token = strtok(copy_arg, ",");
243 
244 	/* Parse first value */
245 	if (token != NULL) {
246 		number = strtoul(token, NULL, 10);
247 
248 		if (errno == EINVAL || errno == ERANGE ||
249 				number == 0)
250 			goto err_list;
251 
252 		list[count++] = number;
253 		temp_min = number;
254 		temp_max = number;
255 	} else
256 		goto err_list;
257 
258 	token = strtok(NULL, ",");
259 
260 	while (token != NULL) {
261 		if (count == MAX_LIST) {
262 			RTE_LOG(WARNING, USER1, "Using only the first %u sizes\n",
263 					MAX_LIST);
264 			break;
265 		}
266 
267 		number = strtoul(token, NULL, 10);
268 
269 		if (errno == EINVAL || errno == ERANGE ||
270 				number == 0)
271 			goto err_list;
272 
273 		list[count++] = number;
274 
275 		if (number < temp_min)
276 			temp_min = number;
277 		if (number > temp_max)
278 			temp_max = number;
279 
280 		token = strtok(NULL, ",");
281 	}
282 
283 	if (min)
284 		*min = temp_min;
285 	if (max)
286 		*max = temp_max;
287 
288 	free(copy_arg);
289 	return count;
290 
291 err_list:
292 	free(copy_arg);
293 	return -1;
294 }
295 
296 static int
297 parse_total_ops(struct cperf_options *opts, const char *arg)
298 {
299 	int ret = parse_uint32_t(&opts->total_ops, arg);
300 
301 	if (ret)
302 		RTE_LOG(ERR, USER1, "failed to parse total operations count\n");
303 
304 	if (opts->total_ops == 0) {
305 		RTE_LOG(ERR, USER1,
306 				"invalid total operations count number specified\n");
307 		return -1;
308 	}
309 
310 	return ret;
311 }
312 
313 static int
314 parse_pool_sz(struct cperf_options *opts, const char *arg)
315 {
316 	int ret =  parse_uint32_t(&opts->pool_sz, arg);
317 
318 	if (ret)
319 		RTE_LOG(ERR, USER1, "failed to parse pool size");
320 	return ret;
321 }
322 
323 static int
324 parse_modex_len(struct cperf_options *opts, const char *arg)
325 {
326 	int ret =  parse_uint16_t(&opts->modex_len, arg);
327 
328 	if (ret)
329 		RTE_LOG(ERR, USER1, "failed to parse modex len");
330 	return ret;
331 }
332 
333 static int
334 parse_burst_sz(struct cperf_options *opts, const char *arg)
335 {
336 	int ret;
337 
338 	/* Try parsing the argument as a range, if it fails, parse it as a list */
339 	if (parse_range(arg, &opts->min_burst_size, &opts->max_burst_size,
340 			&opts->inc_burst_size) < 0) {
341 		ret = parse_list(arg, opts->burst_size_list,
342 					&opts->min_burst_size,
343 					&opts->max_burst_size);
344 		if (ret < 0) {
345 			RTE_LOG(ERR, USER1, "failed to parse burst size/s\n");
346 			return -1;
347 		}
348 		opts->burst_size_count = ret;
349 	}
350 
351 	return 0;
352 }
353 
354 static int
355 parse_buffer_sz(struct cperf_options *opts, const char *arg)
356 {
357 	int ret;
358 
359 	/* Try parsing the argument as a range, if it fails, parse it as a list */
360 	if (parse_range(arg, &opts->min_buffer_size, &opts->max_buffer_size,
361 			&opts->inc_buffer_size) < 0) {
362 		ret = parse_list(arg, opts->buffer_size_list,
363 					&opts->min_buffer_size,
364 					&opts->max_buffer_size);
365 		if (ret < 0) {
366 			RTE_LOG(ERR, USER1, "failed to parse buffer size/s\n");
367 			return -1;
368 		}
369 		opts->buffer_size_count = ret;
370 	}
371 
372 	return 0;
373 }
374 
375 static int
376 parse_segment_sz(struct cperf_options *opts, const char *arg)
377 {
378 	int ret = parse_uint32_t(&opts->segment_sz, arg);
379 
380 	if (ret) {
381 		RTE_LOG(ERR, USER1, "failed to parse segment size\n");
382 		return -1;
383 	}
384 
385 	if (opts->segment_sz == 0) {
386 		RTE_LOG(ERR, USER1, "Segment size has to be bigger than 0\n");
387 		return -1;
388 	}
389 
390 	return 0;
391 }
392 
393 static int
394 parse_imix(struct cperf_options *opts, const char *arg)
395 {
396 	int ret;
397 
398 	ret = parse_list(arg, opts->imix_distribution_list,
399 				NULL, NULL);
400 	if (ret < 0) {
401 		RTE_LOG(ERR, USER1, "failed to parse imix distribution\n");
402 		return -1;
403 	}
404 
405 	opts->imix_distribution_count = ret;
406 
407 	if (opts->imix_distribution_count <= 1) {
408 		RTE_LOG(ERR, USER1, "imix distribution should have "
409 				"at least two entries\n");
410 		return -1;
411 	}
412 
413 	return 0;
414 }
415 
416 static int
417 parse_desc_nb(struct cperf_options *opts, const char *arg)
418 {
419 	int ret = parse_uint32_t(&opts->nb_descriptors, arg);
420 
421 	if (ret) {
422 		RTE_LOG(ERR, USER1, "failed to parse descriptors number\n");
423 		return -1;
424 	}
425 
426 	if (opts->nb_descriptors == 0) {
427 		RTE_LOG(ERR, USER1, "invalid descriptors number specified\n");
428 		return -1;
429 	}
430 
431 	return 0;
432 }
433 
434 static int
435 parse_device_type(struct cperf_options *opts, const char *arg)
436 {
437 	if (strlen(arg) > (sizeof(opts->device_type) - 1))
438 		return -1;
439 
440 	strncpy(opts->device_type, arg, sizeof(opts->device_type) - 1);
441 	*(opts->device_type + sizeof(opts->device_type) - 1) = '\0';
442 
443 	return 0;
444 }
445 
446 static int
447 parse_op_type(struct cperf_options *opts, const char *arg)
448 {
449 	struct name_id_map optype_namemap[] = {
450 		{
451 			cperf_op_type_strs[CPERF_CIPHER_ONLY],
452 			CPERF_CIPHER_ONLY
453 		},
454 		{
455 			cperf_op_type_strs[CPERF_AUTH_ONLY],
456 			CPERF_AUTH_ONLY
457 		},
458 		{
459 			cperf_op_type_strs[CPERF_CIPHER_THEN_AUTH],
460 			CPERF_CIPHER_THEN_AUTH
461 		},
462 		{
463 			cperf_op_type_strs[CPERF_AUTH_THEN_CIPHER],
464 			CPERF_AUTH_THEN_CIPHER
465 		},
466 		{
467 			cperf_op_type_strs[CPERF_AEAD],
468 			CPERF_AEAD
469 		},
470 		{
471 			cperf_op_type_strs[CPERF_PDCP],
472 			CPERF_PDCP
473 		},
474 		{
475 			cperf_op_type_strs[CPERF_DOCSIS],
476 			CPERF_DOCSIS
477 		},
478 		{
479 			cperf_op_type_strs[CPERF_IPSEC],
480 			CPERF_IPSEC
481 		},
482 		{
483 			cperf_op_type_strs[CPERF_ASYM_MODEX],
484 			CPERF_ASYM_MODEX
485 		},
486 		{
487 			cperf_op_type_strs[CPERF_ASYM_SM2],
488 			CPERF_ASYM_SM2
489 		},
490 		{
491 			cperf_op_type_strs[CPERF_TLS],
492 			CPERF_TLS
493 		},
494 	};
495 
496 	int id = get_str_key_id_mapping(optype_namemap,
497 			RTE_DIM(optype_namemap), arg);
498 	if (id < 0) {
499 		RTE_LOG(ERR, USER1, "invalid opt type specified\n");
500 		return -1;
501 	}
502 
503 	opts->op_type = (enum cperf_op_type)id;
504 
505 	return 0;
506 }
507 
508 static int
509 parse_sessionless(struct cperf_options *opts,
510 		const char *arg __rte_unused)
511 {
512 	opts->sessionless = 1;
513 	return 0;
514 }
515 
516 static int
517 parse_out_of_place(struct cperf_options *opts,
518 		const char *arg __rte_unused)
519 {
520 	opts->out_of_place = 1;
521 	return 0;
522 }
523 
524 static int
525 parse_test_file(struct cperf_options *opts,
526 		const char *arg)
527 {
528 	opts->test_file = strdup(arg);
529 	if (opts->test_file == NULL) {
530 		RTE_LOG(ERR, USER1, "Dup vector file failed!\n");
531 		return -1;
532 	}
533 	if (access(opts->test_file, F_OK) != -1)
534 		return 0;
535 	RTE_LOG(ERR, USER1, "Test vector file doesn't exist\n");
536 	free(opts->test_file);
537 
538 	return -1;
539 }
540 
541 static int
542 parse_test_name(struct cperf_options *opts,
543 		const char *arg)
544 {
545 	char *test_name = (char *) rte_zmalloc(NULL,
546 		sizeof(char) * (strlen(arg) + 3), 0);
547 	if (test_name == NULL) {
548 		RTE_LOG(ERR, USER1, "Failed to rte zmalloc with size: %zu\n",
549 			strlen(arg) + 3);
550 		return -1;
551 	}
552 
553 	snprintf(test_name, strlen(arg) + 3, "[%s]", arg);
554 	opts->test_name = test_name;
555 
556 	return 0;
557 }
558 
559 static int
560 parse_silent(struct cperf_options *opts,
561 		const char *arg __rte_unused)
562 {
563 	opts->silent = 1;
564 
565 	return 0;
566 }
567 
568 static int
569 parse_enable_sdap(struct cperf_options *opts,
570 		const char *arg __rte_unused)
571 {
572 	opts->pdcp_sdap = 1;
573 
574 	return 0;
575 }
576 
577 static int
578 parse_cipher_algo(struct cperf_options *opts, const char *arg)
579 {
580 
581 	enum rte_crypto_cipher_algorithm cipher_algo;
582 
583 	if (rte_cryptodev_get_cipher_algo_enum(&cipher_algo, arg) < 0) {
584 		RTE_LOG(ERR, USER1, "Invalid cipher algorithm specified\n");
585 		return -1;
586 	}
587 
588 	opts->cipher_algo = cipher_algo;
589 
590 	return 0;
591 }
592 
593 static int
594 parse_cipher_op(struct cperf_options *opts, const char *arg)
595 {
596 	struct name_id_map cipher_op_namemap[] = {
597 		{
598 			rte_crypto_cipher_operation_strings
599 			[RTE_CRYPTO_CIPHER_OP_ENCRYPT],
600 			RTE_CRYPTO_CIPHER_OP_ENCRYPT },
601 		{
602 			rte_crypto_cipher_operation_strings
603 			[RTE_CRYPTO_CIPHER_OP_DECRYPT],
604 			RTE_CRYPTO_CIPHER_OP_DECRYPT
605 		}
606 	};
607 
608 	int id = get_str_key_id_mapping(cipher_op_namemap,
609 			RTE_DIM(cipher_op_namemap), arg);
610 	if (id < 0) {
611 		RTE_LOG(ERR, USER1, "Invalid cipher operation specified\n");
612 		return -1;
613 	}
614 
615 	opts->cipher_op = (enum rte_crypto_cipher_operation)id;
616 
617 	return 0;
618 }
619 
620 static int
621 parse_cipher_key_sz(struct cperf_options *opts, const char *arg)
622 {
623 	return parse_uint16_t(&opts->cipher_key_sz, arg);
624 }
625 
626 static int
627 parse_cipher_iv_sz(struct cperf_options *opts, const char *arg)
628 {
629 	return parse_uint16_t(&opts->cipher_iv_sz, arg);
630 }
631 
632 static int
633 parse_auth_algo(struct cperf_options *opts, const char *arg)
634 {
635 	enum rte_crypto_auth_algorithm auth_algo;
636 
637 	if (rte_cryptodev_get_auth_algo_enum(&auth_algo, arg) < 0) {
638 		RTE_LOG(ERR, USER1, "Invalid authentication algorithm specified\n");
639 		return -1;
640 	}
641 
642 	opts->auth_algo = auth_algo;
643 
644 	return 0;
645 }
646 
647 static int
648 parse_auth_op(struct cperf_options *opts, const char *arg)
649 {
650 	struct name_id_map auth_op_namemap[] = {
651 		{
652 			rte_crypto_auth_operation_strings
653 			[RTE_CRYPTO_AUTH_OP_GENERATE],
654 			RTE_CRYPTO_AUTH_OP_GENERATE },
655 		{
656 			rte_crypto_auth_operation_strings
657 			[RTE_CRYPTO_AUTH_OP_VERIFY],
658 			RTE_CRYPTO_AUTH_OP_VERIFY
659 		}
660 	};
661 
662 	int id = get_str_key_id_mapping(auth_op_namemap,
663 			RTE_DIM(auth_op_namemap), arg);
664 	if (id < 0) {
665 		RTE_LOG(ERR, USER1, "invalid authentication operation specified"
666 				"\n");
667 		return -1;
668 	}
669 
670 	opts->auth_op = (enum rte_crypto_auth_operation)id;
671 
672 	return 0;
673 }
674 
675 static int
676 parse_auth_key_sz(struct cperf_options *opts, const char *arg)
677 {
678 	return parse_uint16_t(&opts->auth_key_sz, arg);
679 }
680 
681 static int
682 parse_digest_sz(struct cperf_options *opts, const char *arg)
683 {
684 	return parse_uint16_t(&opts->digest_sz, arg);
685 }
686 
687 #ifdef RTE_LIB_SECURITY
688 static int
689 parse_pdcp_sn_sz(struct cperf_options *opts, const char *arg)
690 {
691 	uint32_t val = 0;
692 	int ret = parse_uint32_t(&val, arg);
693 
694 	if (ret < 0)
695 		return ret;
696 
697 	if (val != RTE_SECURITY_PDCP_SN_SIZE_5 &&
698 			val != RTE_SECURITY_PDCP_SN_SIZE_7 &&
699 			val != RTE_SECURITY_PDCP_SN_SIZE_12 &&
700 			val != RTE_SECURITY_PDCP_SN_SIZE_15 &&
701 			val != RTE_SECURITY_PDCP_SN_SIZE_18) {
702 		printf("\nInvalid pdcp SN size: %u\n", val);
703 		return -ERANGE;
704 	}
705 	opts->pdcp_sn_sz = val;
706 
707 	return 0;
708 }
709 
710 const char *cperf_pdcp_domain_strs[] = {
711 	[RTE_SECURITY_PDCP_MODE_CONTROL] = "control",
712 	[RTE_SECURITY_PDCP_MODE_DATA] = "data",
713 	[RTE_SECURITY_PDCP_MODE_SHORT_MAC] = "short_mac"
714 };
715 
716 static int
717 parse_pdcp_domain(struct cperf_options *opts, const char *arg)
718 {
719 	struct name_id_map pdcp_domain_namemap[] = {
720 		{
721 			cperf_pdcp_domain_strs
722 			[RTE_SECURITY_PDCP_MODE_CONTROL],
723 			RTE_SECURITY_PDCP_MODE_CONTROL },
724 		{
725 			cperf_pdcp_domain_strs
726 			[RTE_SECURITY_PDCP_MODE_DATA],
727 			RTE_SECURITY_PDCP_MODE_DATA
728 		},
729 		{
730 			cperf_pdcp_domain_strs
731 			[RTE_SECURITY_PDCP_MODE_SHORT_MAC],
732 			RTE_SECURITY_PDCP_MODE_SHORT_MAC
733 		}
734 	};
735 
736 	int id = get_str_key_id_mapping(pdcp_domain_namemap,
737 			RTE_DIM(pdcp_domain_namemap), arg);
738 	if (id < 0) {
739 		RTE_LOG(ERR, USER1, "invalid pdcp domain specified"
740 				"\n");
741 		return -1;
742 	}
743 
744 	opts->pdcp_domain = (enum rte_security_pdcp_domain)id;
745 
746 	return 0;
747 }
748 
749 const char *cperf_tls_version_strs[] = {
750 	[RTE_SECURITY_VERSION_TLS_1_2] = "TLS1.2",
751 	[RTE_SECURITY_VERSION_TLS_1_3] = "TLS1.3",
752 	[RTE_SECURITY_VERSION_DTLS_1_2] = "DTLS1.2"
753 };
754 
755 static int
756 parse_tls_version(struct cperf_options *opts, const char *arg)
757 {
758 	struct name_id_map tls_version_namemap[] = {
759 		{
760 			cperf_tls_version_strs
761 			[RTE_SECURITY_VERSION_TLS_1_2],
762 			RTE_SECURITY_VERSION_TLS_1_2
763 		},
764 		{
765 			cperf_tls_version_strs
766 			[RTE_SECURITY_VERSION_TLS_1_3],
767 			RTE_SECURITY_VERSION_TLS_1_3
768 		},
769 		{
770 			cperf_tls_version_strs
771 			[RTE_SECURITY_VERSION_DTLS_1_2],
772 			RTE_SECURITY_VERSION_DTLS_1_2
773 		},
774 	};
775 
776 	int id = get_str_key_id_mapping(tls_version_namemap,
777 			RTE_DIM(tls_version_namemap), arg);
778 	if (id < 0) {
779 		RTE_LOG(ERR, USER1, "invalid TLS version specified\n");
780 		return -1;
781 	}
782 
783 	opts->tls_version = (enum rte_security_tls_version)id;
784 
785 	return 0;
786 }
787 
788 static int
789 parse_pdcp_ses_hfn_en(struct cperf_options *opts, const char *arg __rte_unused)
790 {
791 	opts->pdcp_ses_hfn_en = 1;
792 	return 0;
793 }
794 
795 static int
796 parse_docsis_hdr_sz(struct cperf_options *opts, const char *arg)
797 {
798 	return parse_uint16_t(&opts->docsis_hdr_sz, arg);
799 }
800 #endif
801 
802 static int
803 parse_auth_iv_sz(struct cperf_options *opts, const char *arg)
804 {
805 	return parse_uint16_t(&opts->auth_iv_sz, arg);
806 }
807 
808 static int
809 parse_aead_algo(struct cperf_options *opts, const char *arg)
810 {
811 	enum rte_crypto_aead_algorithm aead_algo;
812 
813 	if (rte_cryptodev_get_aead_algo_enum(&aead_algo, arg) < 0) {
814 		RTE_LOG(ERR, USER1, "Invalid AEAD algorithm specified\n");
815 		return -1;
816 	}
817 
818 	opts->aead_algo = aead_algo;
819 
820 	return 0;
821 }
822 
823 static int
824 parse_aead_op(struct cperf_options *opts, const char *arg)
825 {
826 	struct name_id_map aead_op_namemap[] = {
827 		{
828 			rte_crypto_aead_operation_strings
829 			[RTE_CRYPTO_AEAD_OP_ENCRYPT],
830 			RTE_CRYPTO_AEAD_OP_ENCRYPT },
831 		{
832 			rte_crypto_aead_operation_strings
833 			[RTE_CRYPTO_AEAD_OP_DECRYPT],
834 			RTE_CRYPTO_AEAD_OP_DECRYPT
835 		}
836 	};
837 
838 	int id = get_str_key_id_mapping(aead_op_namemap,
839 			RTE_DIM(aead_op_namemap), arg);
840 	if (id < 0) {
841 		RTE_LOG(ERR, USER1, "invalid AEAD operation specified"
842 				"\n");
843 		return -1;
844 	}
845 
846 	opts->aead_op = (enum rte_crypto_aead_operation)id;
847 
848 	return 0;
849 }
850 
851 static int
852 parse_aead_key_sz(struct cperf_options *opts, const char *arg)
853 {
854 	return parse_uint16_t(&opts->aead_key_sz, arg);
855 }
856 
857 static int
858 parse_aead_iv_sz(struct cperf_options *opts, const char *arg)
859 {
860 	return parse_uint16_t(&opts->aead_iv_sz, arg);
861 }
862 
863 static int
864 parse_aead_aad_sz(struct cperf_options *opts, const char *arg)
865 {
866 	return parse_uint16_t(&opts->aead_aad_sz, arg);
867 }
868 
869 static int
870 parse_asym_op(struct cperf_options *opts, const char *arg)
871 {
872 	struct name_id_map asym_op_namemap[] = {
873 		{
874 			rte_crypto_asym_op_strings
875 			[RTE_CRYPTO_ASYM_OP_ENCRYPT],
876 			RTE_CRYPTO_ASYM_OP_ENCRYPT
877 		},
878 		{
879 			rte_crypto_asym_op_strings
880 			[RTE_CRYPTO_ASYM_OP_DECRYPT],
881 			RTE_CRYPTO_ASYM_OP_DECRYPT
882 		},
883 		{
884 			rte_crypto_asym_op_strings
885 			[RTE_CRYPTO_ASYM_OP_SIGN],
886 			RTE_CRYPTO_ASYM_OP_SIGN
887 		},
888 		{
889 			rte_crypto_asym_op_strings
890 			[RTE_CRYPTO_ASYM_OP_VERIFY],
891 			RTE_CRYPTO_ASYM_OP_VERIFY
892 		}
893 	};
894 
895 	int id = get_str_key_id_mapping(asym_op_namemap,
896 			RTE_DIM(asym_op_namemap), arg);
897 	if (id < 0) {
898 		RTE_LOG(ERR, USER1, "invalid ASYM operation specified\n");
899 		return -1;
900 	}
901 
902 	opts->asym_op_type = (enum rte_crypto_asym_op_type)id;
903 
904 	return 0;
905 }
906 
907 
908 static int
909 parse_csv_friendly(struct cperf_options *opts, const char *arg __rte_unused)
910 {
911 	opts->csv = 1;
912 	opts->silent = 1;
913 	return 0;
914 }
915 
916 static int
917 parse_pmd_cyclecount_delay_ms(struct cperf_options *opts,
918 			const char *arg)
919 {
920 	int ret = parse_uint32_t(&opts->pmdcc_delay, arg);
921 
922 	if (ret) {
923 		RTE_LOG(ERR, USER1, "failed to parse pmd-cyclecount delay\n");
924 		return -1;
925 	}
926 
927 	return 0;
928 }
929 
930 typedef int (*option_parser_t)(struct cperf_options *opts,
931 		const char *arg);
932 
933 struct long_opt_parser {
934 	const char *lgopt_name;
935 	option_parser_t parser_fn;
936 
937 };
938 
939 static struct option lgopts[] = {
940 
941 	{ CPERF_PTEST_TYPE, required_argument, 0, 0 },
942 	{ CPERF_MODEX_LEN, required_argument, 0, 0 },
943 
944 	{ CPERF_POOL_SIZE, required_argument, 0, 0 },
945 	{ CPERF_TOTAL_OPS, required_argument, 0, 0 },
946 	{ CPERF_BURST_SIZE, required_argument, 0, 0 },
947 	{ CPERF_BUFFER_SIZE, required_argument, 0, 0 },
948 	{ CPERF_SEGMENT_SIZE, required_argument, 0, 0 },
949 	{ CPERF_DESC_NB, required_argument, 0, 0 },
950 
951 	{ CPERF_IMIX, required_argument, 0, 0 },
952 	{ CPERF_DEVTYPE, required_argument, 0, 0 },
953 	{ CPERF_OPTYPE, required_argument, 0, 0 },
954 
955 	{ CPERF_SILENT, no_argument, 0, 0 },
956 	{ CPERF_SESSIONLESS, no_argument, 0, 0 },
957 	{ CPERF_OUT_OF_PLACE, no_argument, 0, 0 },
958 	{ CPERF_TEST_FILE, required_argument, 0, 0 },
959 	{ CPERF_TEST_NAME, required_argument, 0, 0 },
960 
961 	{ CPERF_CIPHER_ALGO, required_argument, 0, 0 },
962 	{ CPERF_CIPHER_OP, required_argument, 0, 0 },
963 
964 	{ CPERF_CIPHER_KEY_SZ, required_argument, 0, 0 },
965 	{ CPERF_CIPHER_IV_SZ, required_argument, 0, 0 },
966 
967 	{ CPERF_AUTH_ALGO, required_argument, 0, 0 },
968 	{ CPERF_AUTH_OP, required_argument, 0, 0 },
969 
970 	{ CPERF_AUTH_KEY_SZ, required_argument, 0, 0 },
971 	{ CPERF_AUTH_IV_SZ, required_argument, 0, 0 },
972 
973 	{ CPERF_AEAD_ALGO, required_argument, 0, 0 },
974 	{ CPERF_AEAD_OP, required_argument, 0, 0 },
975 
976 	{ CPERF_AEAD_KEY_SZ, required_argument, 0, 0 },
977 	{ CPERF_AEAD_AAD_SZ, required_argument, 0, 0 },
978 	{ CPERF_AEAD_IV_SZ, required_argument, 0, 0 },
979 
980 	{ CPERF_DIGEST_SZ, required_argument, 0, 0 },
981 
982 	{ CPERF_ASYM_OP, required_argument, 0, 0 },
983 
984 #ifdef RTE_LIB_SECURITY
985 	{ CPERF_PDCP_SN_SZ, required_argument, 0, 0 },
986 	{ CPERF_PDCP_DOMAIN, required_argument, 0, 0 },
987 	{ CPERF_PDCP_SES_HFN_EN, no_argument, 0, 0 },
988 	{ CPERF_ENABLE_SDAP, no_argument, 0, 0 },
989 	{ CPERF_DOCSIS_HDR_SZ, required_argument, 0, 0 },
990 	{ CPERF_TLS_VERSION, required_argument, 0, 0 },
991 #endif
992 	{ CPERF_CSV, no_argument, 0, 0},
993 
994 	{ CPERF_PMDCC_DELAY_MS, required_argument, 0, 0 },
995 
996 	{ NULL, 0, 0, 0 }
997 };
998 
999 void
1000 cperf_options_default(struct cperf_options *opts)
1001 {
1002 	opts->test = CPERF_TEST_TYPE_THROUGHPUT;
1003 
1004 	opts->pool_sz = 8192;
1005 	opts->total_ops = 10000000;
1006 	opts->nb_descriptors = 2048;
1007 
1008 	opts->buffer_size_list[0] = 64;
1009 	opts->buffer_size_count = 1;
1010 	opts->max_buffer_size = 64;
1011 	opts->min_buffer_size = 64;
1012 	opts->inc_buffer_size = 0;
1013 
1014 	opts->burst_size_list[0] = 32;
1015 	opts->burst_size_count = 1;
1016 	opts->max_burst_size = 32;
1017 	opts->min_burst_size = 32;
1018 	opts->inc_burst_size = 0;
1019 
1020 	/*
1021 	 * Will be parsed from command line or set to
1022 	 * maximum buffer size + digest, later
1023 	 */
1024 	opts->segment_sz = 0;
1025 
1026 	opts->imix_distribution_count = 0;
1027 	strncpy(opts->device_type, "crypto_aesni_mb",
1028 			sizeof(opts->device_type));
1029 	opts->nb_qps = 1;
1030 
1031 	opts->op_type = CPERF_CIPHER_THEN_AUTH;
1032 
1033 	opts->silent = 0;
1034 	opts->test_file = NULL;
1035 	opts->test_name = NULL;
1036 	opts->sessionless = 0;
1037 	opts->out_of_place = 0;
1038 	opts->csv = 0;
1039 
1040 	opts->cipher_algo = RTE_CRYPTO_CIPHER_AES_CBC;
1041 	opts->cipher_op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1042 	opts->cipher_key_sz = 16;
1043 	opts->cipher_iv_sz = 16;
1044 
1045 	opts->auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1046 	opts->auth_op = RTE_CRYPTO_AUTH_OP_GENERATE;
1047 
1048 	opts->auth_key_sz = 64;
1049 	opts->auth_iv_sz = 0;
1050 
1051 	opts->aead_key_sz = 0;
1052 	opts->aead_iv_sz = 0;
1053 	opts->aead_aad_sz = 0;
1054 
1055 	opts->digest_sz = 12;
1056 
1057 	opts->pmdcc_delay = 0;
1058 #ifdef RTE_LIB_SECURITY
1059 	opts->pdcp_sn_sz = 12;
1060 	opts->pdcp_domain = RTE_SECURITY_PDCP_MODE_CONTROL;
1061 	opts->pdcp_ses_hfn_en = 0;
1062 	opts->pdcp_sdap = 0;
1063 	opts->docsis_hdr_sz = 17;
1064 #endif
1065 	opts->modex_data = (struct cperf_modex_test_data *)&modex_perf_data[0];
1066 
1067 	opts->sm2_data = &sm2_perf_data;
1068 	opts->asym_op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1069 }
1070 
1071 static int
1072 cperf_opts_parse_long(int opt_idx, struct cperf_options *opts)
1073 {
1074 	struct long_opt_parser parsermap[] = {
1075 		{ CPERF_PTEST_TYPE,	parse_cperf_test_type },
1076 		{ CPERF_MODEX_LEN,	parse_modex_len },
1077 		{ CPERF_SILENT,		parse_silent },
1078 		{ CPERF_POOL_SIZE,	parse_pool_sz },
1079 		{ CPERF_TOTAL_OPS,	parse_total_ops },
1080 		{ CPERF_BURST_SIZE,	parse_burst_sz },
1081 		{ CPERF_BUFFER_SIZE,	parse_buffer_sz },
1082 		{ CPERF_SEGMENT_SIZE,	parse_segment_sz },
1083 		{ CPERF_DESC_NB,	parse_desc_nb },
1084 		{ CPERF_DEVTYPE,	parse_device_type },
1085 		{ CPERF_OPTYPE,		parse_op_type },
1086 		{ CPERF_SESSIONLESS,	parse_sessionless },
1087 		{ CPERF_OUT_OF_PLACE,	parse_out_of_place },
1088 		{ CPERF_IMIX,		parse_imix },
1089 		{ CPERF_TEST_FILE,	parse_test_file },
1090 		{ CPERF_TEST_NAME,	parse_test_name },
1091 		{ CPERF_CIPHER_ALGO,	parse_cipher_algo },
1092 		{ CPERF_CIPHER_OP,	parse_cipher_op },
1093 		{ CPERF_CIPHER_KEY_SZ,	parse_cipher_key_sz },
1094 		{ CPERF_CIPHER_IV_SZ,	parse_cipher_iv_sz },
1095 		{ CPERF_AUTH_ALGO,	parse_auth_algo },
1096 		{ CPERF_AUTH_OP,	parse_auth_op },
1097 		{ CPERF_AUTH_KEY_SZ,	parse_auth_key_sz },
1098 		{ CPERF_AUTH_IV_SZ,	parse_auth_iv_sz },
1099 		{ CPERF_AEAD_ALGO,	parse_aead_algo },
1100 		{ CPERF_AEAD_OP,	parse_aead_op },
1101 		{ CPERF_AEAD_KEY_SZ,	parse_aead_key_sz },
1102 		{ CPERF_AEAD_IV_SZ,	parse_aead_iv_sz },
1103 		{ CPERF_AEAD_AAD_SZ,	parse_aead_aad_sz },
1104 		{ CPERF_DIGEST_SZ,	parse_digest_sz },
1105 		{ CPERF_ASYM_OP,	parse_asym_op },
1106 #ifdef RTE_LIB_SECURITY
1107 		{ CPERF_PDCP_SN_SZ,	parse_pdcp_sn_sz },
1108 		{ CPERF_PDCP_DOMAIN,	parse_pdcp_domain },
1109 		{ CPERF_PDCP_SES_HFN_EN,	parse_pdcp_ses_hfn_en },
1110 		{ CPERF_ENABLE_SDAP,	parse_enable_sdap },
1111 		{ CPERF_DOCSIS_HDR_SZ,	parse_docsis_hdr_sz },
1112 		{ CPERF_TLS_VERSION,	parse_tls_version },
1113 #endif
1114 		{ CPERF_CSV,		parse_csv_friendly},
1115 		{ CPERF_PMDCC_DELAY_MS,	parse_pmd_cyclecount_delay_ms},
1116 	};
1117 	unsigned int i;
1118 
1119 	for (i = 0; i < RTE_DIM(parsermap); i++) {
1120 		if (strncmp(lgopts[opt_idx].name, parsermap[i].lgopt_name,
1121 				strlen(lgopts[opt_idx].name)) == 0)
1122 			return parsermap[i].parser_fn(opts, optarg);
1123 	}
1124 
1125 	return -EINVAL;
1126 }
1127 
1128 int
1129 cperf_options_parse(struct cperf_options *options, int argc, char **argv)
1130 {
1131 	int opt, retval, opt_idx;
1132 
1133 	while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
1134 		switch (opt) {
1135 		case 'h':
1136 			usage(argv[0]);
1137 			exit(EXIT_SUCCESS);
1138 			break;
1139 		/* long options */
1140 		case 0:
1141 			retval = cperf_opts_parse_long(opt_idx, options);
1142 			if (retval != 0)
1143 				return retval;
1144 
1145 			break;
1146 
1147 		default:
1148 			usage(argv[0]);
1149 			return -EINVAL;
1150 		}
1151 	}
1152 
1153 	return 0;
1154 }
1155 
1156 static int
1157 check_cipher_buffer_length(struct cperf_options *options)
1158 {
1159 	uint32_t buffer_size, buffer_size_idx = 0;
1160 
1161 	if (options->cipher_algo == RTE_CRYPTO_CIPHER_AES_CBC ||
1162 			options->cipher_algo == RTE_CRYPTO_CIPHER_AES_ECB) {
1163 		if (options->inc_buffer_size != 0)
1164 			buffer_size = options->min_buffer_size;
1165 		else
1166 			buffer_size = options->buffer_size_list[0];
1167 
1168 		if ((options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE) &&
1169 				(options->op_type == CPERF_AUTH_THEN_CIPHER))
1170 			buffer_size += options->digest_sz;
1171 
1172 		while (buffer_size <= options->max_buffer_size) {
1173 			if ((buffer_size % AES_BLOCK_SIZE) != 0) {
1174 				RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
1175 					"not suitable for the algorithm selected\n");
1176 				return -EINVAL;
1177 			}
1178 
1179 			if (options->inc_buffer_size != 0)
1180 				buffer_size += options->inc_buffer_size;
1181 			else {
1182 				if (++buffer_size_idx == options->buffer_size_count)
1183 					break;
1184 				buffer_size = options->buffer_size_list[buffer_size_idx];
1185 			}
1186 
1187 		}
1188 	}
1189 
1190 	if (options->cipher_algo == RTE_CRYPTO_CIPHER_DES_CBC ||
1191 			options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_CBC ||
1192 			options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_ECB) {
1193 		if (options->inc_buffer_size != 0)
1194 			buffer_size = options->min_buffer_size;
1195 		else
1196 			buffer_size = options->buffer_size_list[0];
1197 
1198 		if ((options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE) &&
1199 				(options->op_type == CPERF_AUTH_THEN_CIPHER))
1200 			buffer_size += options->digest_sz;
1201 
1202 		while (buffer_size <= options->max_buffer_size) {
1203 			if ((buffer_size % DES_BLOCK_SIZE) != 0) {
1204 				RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
1205 					"not suitable for the algorithm selected\n");
1206 				return -EINVAL;
1207 			}
1208 
1209 			if (options->inc_buffer_size != 0)
1210 				buffer_size += options->inc_buffer_size;
1211 			else {
1212 				if (++buffer_size_idx == options->buffer_size_count)
1213 					break;
1214 				buffer_size = options->buffer_size_list[buffer_size_idx];
1215 			}
1216 
1217 		}
1218 	}
1219 
1220 	return 0;
1221 }
1222 
1223 #ifdef RTE_LIB_SECURITY
1224 static int
1225 check_docsis_buffer_length(struct cperf_options *options)
1226 {
1227 	uint32_t buffer_size, buffer_size_idx = 0;
1228 
1229 	if (options->inc_buffer_size != 0)
1230 		buffer_size = options->min_buffer_size;
1231 	else
1232 		buffer_size = options->buffer_size_list[0];
1233 
1234 	while (buffer_size <= options->max_buffer_size) {
1235 		if (buffer_size < (uint32_t)(options->docsis_hdr_sz +
1236 				RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN)) {
1237 			RTE_LOG(ERR, USER1, "Some of the buffer sizes are not "
1238 				"valid for DOCSIS\n");
1239 			return -EINVAL;
1240 		}
1241 
1242 		if (options->inc_buffer_size != 0)
1243 			buffer_size += options->inc_buffer_size;
1244 		else {
1245 			if (++buffer_size_idx == options->buffer_size_count)
1246 				break;
1247 			buffer_size =
1248 				options->buffer_size_list[buffer_size_idx];
1249 		}
1250 	}
1251 
1252 	return 0;
1253 }
1254 #endif
1255 
1256 static bool
1257 is_valid_chained_op(struct cperf_options *options)
1258 {
1259 	if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
1260 			options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE)
1261 		return true;
1262 
1263 	if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT &&
1264 			options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY)
1265 		return true;
1266 
1267 	return false;
1268 }
1269 
1270 int
1271 cperf_options_check(struct cperf_options *options)
1272 {
1273 	int i;
1274 
1275 	if (options->op_type == CPERF_CIPHER_ONLY ||
1276 			options->op_type == CPERF_DOCSIS)
1277 		options->digest_sz = 0;
1278 
1279 	if (options->out_of_place &&
1280 			options->segment_sz <= options->max_buffer_size) {
1281 		RTE_LOG(ERR, USER1, "Out of place mode can only work "
1282 					"with non segmented buffers\n");
1283 		return -EINVAL;
1284 	}
1285 
1286 	/*
1287 	 * If segment size is not set, assume only one segment,
1288 	 * big enough to contain the largest buffer and the digest
1289 	 */
1290 	if (options->segment_sz == 0) {
1291 		options->segment_sz = options->max_buffer_size +
1292 				options->digest_sz;
1293 		/* In IPsec and TLS operation, packet length will be increased
1294 		 * by some bytes depend upon the algorithm, so increasing
1295 		 * the segment size by headroom to cover most of
1296 		 * the scenarios.
1297 		 */
1298 		if (options->op_type == CPERF_IPSEC || options->op_type == CPERF_TLS)
1299 			options->segment_sz += RTE_PKTMBUF_HEADROOM;
1300 	}
1301 
1302 	if (options->segment_sz < options->digest_sz) {
1303 		RTE_LOG(ERR, USER1,
1304 				"Segment size should be at least "
1305 				"the size of the digest\n");
1306 		return -EINVAL;
1307 	}
1308 
1309 	if ((options->imix_distribution_count != 0) &&
1310 			(options->imix_distribution_count !=
1311 				options->buffer_size_count)) {
1312 		RTE_LOG(ERR, USER1, "IMIX distribution must have the same "
1313 				"number of buffer sizes\n");
1314 		return -EINVAL;
1315 	}
1316 
1317 	if (options->test == CPERF_TEST_TYPE_VERIFY &&
1318 			options->test_file == NULL) {
1319 		RTE_LOG(ERR, USER1, "Define path to the file with test"
1320 				" vectors.\n");
1321 		return -EINVAL;
1322 	}
1323 
1324 	if (options->test == CPERF_TEST_TYPE_VERIFY &&
1325 			options->op_type != CPERF_CIPHER_ONLY &&
1326 			options->test_name == NULL) {
1327 		RTE_LOG(ERR, USER1, "Define test name to get the correct digest"
1328 				" from the test vectors.\n");
1329 		return -EINVAL;
1330 	}
1331 
1332 	if (options->test_name != NULL && options->test_file == NULL) {
1333 		RTE_LOG(ERR, USER1, "Define path to the file with test"
1334 				" vectors.\n");
1335 		return -EINVAL;
1336 	}
1337 
1338 	if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY &&
1339 			options->test_file == NULL) {
1340 		RTE_LOG(ERR, USER1, "Define path to the file with test"
1341 				" vectors.\n");
1342 		return -EINVAL;
1343 	}
1344 
1345 	if (options->test == CPERF_TEST_TYPE_VERIFY &&
1346 			(options->inc_buffer_size != 0 ||
1347 			options->buffer_size_count > 1)) {
1348 		RTE_LOG(ERR, USER1, "Only one buffer size is allowed when "
1349 				"using the verify test.\n");
1350 		return -EINVAL;
1351 	}
1352 
1353 	if (options->test == CPERF_TEST_TYPE_VERIFY &&
1354 			(options->inc_burst_size != 0 ||
1355 			options->burst_size_count > 1)) {
1356 		RTE_LOG(ERR, USER1, "Only one burst size is allowed when "
1357 				"using the verify test.\n");
1358 		return -EINVAL;
1359 	}
1360 
1361 	if (options->test == CPERF_TEST_TYPE_PMDCC &&
1362 			options->pool_sz < options->nb_descriptors) {
1363 		RTE_LOG(ERR, USER1, "For pmd cyclecount benchmarks, pool size "
1364 				"must be equal or greater than the number of "
1365 				"cryptodev descriptors.\n");
1366 		return -EINVAL;
1367 	}
1368 
1369 	if (options->test == CPERF_TEST_TYPE_VERIFY &&
1370 			options->imix_distribution_count > 0) {
1371 		RTE_LOG(ERR, USER1, "IMIX is not allowed when "
1372 				"using the verify test.\n");
1373 		return -EINVAL;
1374 	}
1375 
1376 	if (options->op_type == CPERF_CIPHER_THEN_AUTH ||
1377 			options->op_type == CPERF_AUTH_THEN_CIPHER) {
1378 		if (!is_valid_chained_op(options)) {
1379 			RTE_LOG(ERR, USER1, "Invalid chained operation.\n");
1380 			return -EINVAL;
1381 		}
1382 	}
1383 
1384 	if (options->op_type == CPERF_CIPHER_THEN_AUTH) {
1385 		if (options->cipher_op != RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
1386 				options->auth_op !=
1387 				RTE_CRYPTO_AUTH_OP_GENERATE) {
1388 			RTE_LOG(ERR, USER1, "Option cipher then auth must use"
1389 					" options: encrypt and generate.\n");
1390 			return -EINVAL;
1391 		}
1392 	}
1393 
1394 	if (options->op_type == CPERF_CIPHER_ONLY ||
1395 			options->op_type == CPERF_CIPHER_THEN_AUTH ||
1396 			options->op_type == CPERF_AUTH_THEN_CIPHER) {
1397 		if (check_cipher_buffer_length(options) < 0)
1398 			return -EINVAL;
1399 	}
1400 
1401 	if (options->modex_len) {
1402 		if (options->op_type != CPERF_ASYM_MODEX) {
1403 			RTE_LOG(ERR, USER1, "Option modex len should be used only with "
1404 					" optype: modex.\n");
1405 			return -EINVAL;
1406 		}
1407 
1408 		for (i = 0; i < (int)RTE_DIM(modex_perf_data); i++) {
1409 			if (modex_perf_data[i].modulus.len ==
1410 			    options->modex_len) {
1411 				options->modex_data =
1412 					(struct cperf_modex_test_data
1413 						 *)&modex_perf_data[i];
1414 				break;
1415 			}
1416 		}
1417 		if (i == (int)RTE_DIM(modex_perf_data)) {
1418 			RTE_LOG(ERR, USER1,
1419 				"Option modex len: %d is not supported\n",
1420 				options->modex_len);
1421 			return -EINVAL;
1422 		}
1423 	}
1424 
1425 #ifdef RTE_LIB_SECURITY
1426 	if (options->op_type == CPERF_DOCSIS) {
1427 		if (check_docsis_buffer_length(options) < 0)
1428 			return -EINVAL;
1429 	}
1430 
1431 	if (options->op_type == CPERF_IPSEC || options->op_type == CPERF_TLS) {
1432 		if (options->aead_algo) {
1433 			if (options->aead_op == RTE_CRYPTO_AEAD_OP_ENCRYPT)
1434 				options->is_outbound = 1;
1435 			else
1436 				options->is_outbound = 0;
1437 		} else {
1438 			if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
1439 			    options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE)
1440 				options->is_outbound = 1;
1441 			else
1442 				options->is_outbound = 0;
1443 		}
1444 	}
1445 #endif
1446 
1447 	return 0;
1448 }
1449 
1450 void
1451 cperf_options_dump(struct cperf_options *opts)
1452 {
1453 	uint8_t size_idx;
1454 
1455 	printf("# Crypto Performance Application Options:\n");
1456 	printf("#\n");
1457 	printf("# cperf test: %s\n", cperf_test_type_strs[opts->test]);
1458 	printf("#\n");
1459 	printf("# cperf operation type: %s\n", cperf_op_type_strs[opts->op_type]);
1460 	printf("#\n");
1461 	printf("# size of crypto op / mbuf pool: %u\n", opts->pool_sz);
1462 	printf("# total number of ops: %u\n", opts->total_ops);
1463 	if (opts->inc_buffer_size != 0) {
1464 		printf("# buffer size:\n");
1465 		printf("#\t min: %u\n", opts->min_buffer_size);
1466 		printf("#\t max: %u\n", opts->max_buffer_size);
1467 		printf("#\t inc: %u\n", opts->inc_buffer_size);
1468 	} else {
1469 		printf("# buffer sizes: ");
1470 		for (size_idx = 0; size_idx < opts->buffer_size_count; size_idx++)
1471 			printf("%u ", opts->buffer_size_list[size_idx]);
1472 		printf("\n");
1473 	}
1474 	if (opts->inc_burst_size != 0) {
1475 		printf("# burst size:\n");
1476 		printf("#\t min: %u\n", opts->min_burst_size);
1477 		printf("#\t max: %u\n", opts->max_burst_size);
1478 		printf("#\t inc: %u\n", opts->inc_burst_size);
1479 	} else {
1480 		printf("# burst sizes: ");
1481 		for (size_idx = 0; size_idx < opts->burst_size_count; size_idx++)
1482 			printf("%u ", opts->burst_size_list[size_idx]);
1483 		printf("\n");
1484 	}
1485 	printf("\n# segment size: %u\n", opts->segment_sz);
1486 	printf("#\n");
1487 	printf("# cryptodev type: %s\n", opts->device_type);
1488 	printf("#\n");
1489 	printf("# number of queue pairs per device: %u\n", opts->nb_qps);
1490 	printf("# crypto operation: %s\n", cperf_op_type_strs[opts->op_type]);
1491 	if (opts->op_type == CPERF_ASYM_SM2)
1492 		printf("# asym operation type: %s\n",
1493 				rte_crypto_asym_op_strings[opts->asym_op_type]);
1494 	printf("# sessionless: %s\n", opts->sessionless ? "yes" : "no");
1495 	printf("# out of place: %s\n", opts->out_of_place ? "yes" : "no");
1496 	if (opts->test == CPERF_TEST_TYPE_PMDCC)
1497 		printf("# inter-burst delay: %u ms\n", opts->pmdcc_delay);
1498 
1499 	printf("#\n");
1500 
1501 	if (opts->op_type == CPERF_AUTH_ONLY ||
1502 			opts->op_type == CPERF_CIPHER_THEN_AUTH ||
1503 			opts->op_type == CPERF_AUTH_THEN_CIPHER) {
1504 		printf("# auth algorithm: %s\n",
1505 			rte_cryptodev_get_auth_algo_string(opts->auth_algo));
1506 		printf("# auth operation: %s\n",
1507 			rte_crypto_auth_operation_strings[opts->auth_op]);
1508 		printf("# auth key size: %u\n", opts->auth_key_sz);
1509 		printf("# auth iv size: %u\n", opts->auth_iv_sz);
1510 		printf("# auth digest size: %u\n", opts->digest_sz);
1511 		printf("#\n");
1512 	}
1513 
1514 	if (opts->op_type == CPERF_CIPHER_ONLY ||
1515 			opts->op_type == CPERF_CIPHER_THEN_AUTH ||
1516 			opts->op_type == CPERF_AUTH_THEN_CIPHER) {
1517 		printf("# cipher algorithm: %s\n",
1518 			rte_cryptodev_get_cipher_algo_string(opts->cipher_algo));
1519 		printf("# cipher operation: %s\n",
1520 			rte_crypto_cipher_operation_strings[opts->cipher_op]);
1521 		printf("# cipher key size: %u\n", opts->cipher_key_sz);
1522 		printf("# cipher iv size: %u\n", opts->cipher_iv_sz);
1523 		printf("#\n");
1524 	}
1525 
1526 	if (opts->op_type == CPERF_AEAD) {
1527 		printf("# aead algorithm: %s\n",
1528 			rte_cryptodev_get_aead_algo_string(opts->aead_algo));
1529 		printf("# aead operation: %s\n",
1530 			rte_crypto_aead_operation_strings[opts->aead_op]);
1531 		printf("# aead key size: %u\n", opts->aead_key_sz);
1532 		printf("# aead iv size: %u\n", opts->aead_iv_sz);
1533 		printf("# aead digest size: %u\n", opts->digest_sz);
1534 		printf("# aead aad size: %u\n", opts->aead_aad_sz);
1535 		printf("#\n");
1536 	}
1537 
1538 #ifdef RTE_LIB_SECURITY
1539 	if (opts->op_type == CPERF_DOCSIS) {
1540 		printf("# docsis header size: %u\n", opts->docsis_hdr_sz);
1541 		printf("#\n");
1542 	}
1543 #endif
1544 }
1545