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