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