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 : strlcpy(opts->device_type, arg, sizeof(opts->device_type));
486 : :
487 : 0 : return 0;
488 : : }
489 : :
490 : : static int
491 : 0 : parse_op_type(struct cperf_options *opts, const char *arg)
492 : : {
493 : 0 : struct name_id_map optype_namemap[] = {
494 : : {
495 : 0 : cperf_op_type_strs[CPERF_CIPHER_ONLY],
496 : : CPERF_CIPHER_ONLY
497 : : },
498 : : {
499 : 0 : cperf_op_type_strs[CPERF_AUTH_ONLY],
500 : : CPERF_AUTH_ONLY
501 : : },
502 : : {
503 : 0 : cperf_op_type_strs[CPERF_CIPHER_THEN_AUTH],
504 : : CPERF_CIPHER_THEN_AUTH
505 : : },
506 : : {
507 : 0 : cperf_op_type_strs[CPERF_AUTH_THEN_CIPHER],
508 : : CPERF_AUTH_THEN_CIPHER
509 : : },
510 : : {
511 : 0 : cperf_op_type_strs[CPERF_AEAD],
512 : : CPERF_AEAD
513 : : },
514 : : {
515 : 0 : cperf_op_type_strs[CPERF_PDCP],
516 : : CPERF_PDCP
517 : : },
518 : : {
519 : 0 : cperf_op_type_strs[CPERF_DOCSIS],
520 : : CPERF_DOCSIS
521 : : },
522 : : {
523 : 0 : cperf_op_type_strs[CPERF_IPSEC],
524 : : CPERF_IPSEC
525 : : },
526 : : {
527 : 0 : cperf_op_type_strs[CPERF_ASYM_MODEX],
528 : : CPERF_ASYM_MODEX
529 : : },
530 : : {
531 : 0 : cperf_op_type_strs[CPERF_ASYM_RSA],
532 : : CPERF_ASYM_RSA
533 : : },
534 : : {
535 : 0 : cperf_op_type_strs[CPERF_ASYM_SECP192R1],
536 : : CPERF_ASYM_SECP192R1
537 : : },
538 : : {
539 : 0 : cperf_op_type_strs[CPERF_ASYM_SECP224R1],
540 : : CPERF_ASYM_SECP224R1
541 : : },
542 : : {
543 : 0 : cperf_op_type_strs[CPERF_ASYM_SECP256R1],
544 : : CPERF_ASYM_SECP256R1
545 : : },
546 : : {
547 : 0 : cperf_op_type_strs[CPERF_ASYM_SECP384R1],
548 : : CPERF_ASYM_SECP384R1
549 : : },
550 : : {
551 : 0 : cperf_op_type_strs[CPERF_ASYM_SECP521R1],
552 : : CPERF_ASYM_SECP521R1
553 : : },
554 : : {
555 : 0 : cperf_op_type_strs[CPERF_ASYM_ED25519],
556 : : CPERF_ASYM_ED25519
557 : : },
558 : : {
559 : 0 : cperf_op_type_strs[CPERF_ASYM_SM2],
560 : : CPERF_ASYM_SM2
561 : : },
562 : : {
563 : 0 : cperf_op_type_strs[CPERF_ASYM_MLDSA44],
564 : : CPERF_ASYM_MLDSA44
565 : : },
566 : : {
567 : 0 : cperf_op_type_strs[CPERF_ASYM_MLKEM512],
568 : : CPERF_ASYM_MLKEM512
569 : : },
570 : : {
571 : 0 : cperf_op_type_strs[CPERF_TLS],
572 : : CPERF_TLS
573 : : },
574 : : };
575 : :
576 : 0 : int id = get_str_key_id_mapping(optype_namemap,
577 : : RTE_DIM(optype_namemap), arg);
578 : 0 : if (id < 0) {
579 : 0 : RTE_LOG(ERR, USER1, "invalid opt type specified\n");
580 : 0 : return -1;
581 : : }
582 : :
583 : 0 : opts->op_type = (enum cperf_op_type)id;
584 : :
585 : 0 : return 0;
586 : : }
587 : :
588 : : static int
589 : 0 : parse_sessionless(struct cperf_options *opts,
590 : : const char *arg __rte_unused)
591 : : {
592 : 0 : opts->sessionless = 1;
593 : 0 : return 0;
594 : : }
595 : :
596 : : static int
597 : 0 : parse_shared_session(struct cperf_options *opts,
598 : : const char *arg __rte_unused)
599 : : {
600 : 0 : opts->shared_session = 1;
601 : 0 : return 0;
602 : : }
603 : :
604 : : static int
605 : 0 : parse_out_of_place(struct cperf_options *opts,
606 : : const char *arg __rte_unused)
607 : : {
608 : 0 : opts->out_of_place = 1;
609 : 0 : return 0;
610 : : }
611 : :
612 : : static int
613 : 0 : parse_test_file(struct cperf_options *opts,
614 : : const char *arg)
615 : : {
616 : 0 : opts->test_file = strdup(arg);
617 : 0 : if (opts->test_file == NULL) {
618 : 0 : RTE_LOG(ERR, USER1, "Dup vector file failed!\n");
619 : 0 : return -1;
620 : : }
621 : 0 : if (access(opts->test_file, F_OK) != -1)
622 : : return 0;
623 : 0 : RTE_LOG(ERR, USER1, "Test vector file doesn't exist\n");
624 : 0 : free(opts->test_file);
625 : :
626 : 0 : return -1;
627 : : }
628 : :
629 : : static int
630 : 0 : parse_test_name(struct cperf_options *opts,
631 : : const char *arg)
632 : : {
633 : 0 : char *test_name = (char *) rte_zmalloc(NULL,
634 : 0 : sizeof(char) * (strlen(arg) + 3), 0);
635 : 0 : if (test_name == NULL) {
636 : 0 : RTE_LOG(ERR, USER1, "Failed to rte zmalloc with size: %zu\n",
637 : : strlen(arg) + 3);
638 : 0 : return -1;
639 : : }
640 : :
641 : 0 : snprintf(test_name, strlen(arg) + 3, "[%s]", arg);
642 : 0 : opts->test_name = test_name;
643 : :
644 : 0 : return 0;
645 : : }
646 : :
647 : : static int
648 : 0 : parse_silent(struct cperf_options *opts,
649 : : const char *arg __rte_unused)
650 : : {
651 : 0 : opts->silent = 1;
652 : :
653 : 0 : return 0;
654 : : }
655 : :
656 : : static int
657 : 0 : parse_enable_sdap(struct cperf_options *opts,
658 : : const char *arg __rte_unused)
659 : : {
660 : 0 : opts->pdcp_sdap = 1;
661 : :
662 : 0 : return 0;
663 : : }
664 : :
665 : : static int
666 : 0 : parse_cipher_algo(struct cperf_options *opts, const char *arg)
667 : : {
668 : :
669 : : enum rte_crypto_cipher_algorithm cipher_algo;
670 : :
671 : 0 : if (rte_cryptodev_get_cipher_algo_enum(&cipher_algo, arg) < 0) {
672 : 0 : RTE_LOG(ERR, USER1, "Invalid cipher algorithm specified\n");
673 : 0 : return -1;
674 : : }
675 : :
676 : 0 : opts->cipher_algo = cipher_algo;
677 : :
678 : 0 : return 0;
679 : : }
680 : :
681 : : static int
682 : 0 : parse_cipher_op(struct cperf_options *opts, const char *arg)
683 : : {
684 : 0 : struct name_id_map cipher_op_namemap[] = {
685 : : {
686 : : rte_crypto_cipher_operation_strings
687 : 0 : [RTE_CRYPTO_CIPHER_OP_ENCRYPT],
688 : : RTE_CRYPTO_CIPHER_OP_ENCRYPT },
689 : : {
690 : : rte_crypto_cipher_operation_strings
691 : 0 : [RTE_CRYPTO_CIPHER_OP_DECRYPT],
692 : : RTE_CRYPTO_CIPHER_OP_DECRYPT
693 : : }
694 : : };
695 : :
696 : 0 : int id = get_str_key_id_mapping(cipher_op_namemap,
697 : : RTE_DIM(cipher_op_namemap), arg);
698 : 0 : if (id < 0) {
699 : 0 : RTE_LOG(ERR, USER1, "Invalid cipher operation specified\n");
700 : 0 : return -1;
701 : : }
702 : :
703 : 0 : opts->cipher_op = (enum rte_crypto_cipher_operation)id;
704 : :
705 : 0 : return 0;
706 : : }
707 : :
708 : : static int
709 : 0 : parse_cipher_key_sz(struct cperf_options *opts, const char *arg)
710 : : {
711 : 0 : return parse_uint16_t(&opts->cipher_key_sz, arg);
712 : : }
713 : :
714 : : static int
715 : 0 : parse_cipher_iv_sz(struct cperf_options *opts, const char *arg)
716 : : {
717 : 0 : return parse_uint16_t(&opts->cipher_iv_sz, arg);
718 : : }
719 : :
720 : : static int
721 : 0 : parse_auth_algo(struct cperf_options *opts, const char *arg)
722 : : {
723 : : enum rte_crypto_auth_algorithm auth_algo;
724 : :
725 : 0 : if (rte_cryptodev_get_auth_algo_enum(&auth_algo, arg) < 0) {
726 : 0 : RTE_LOG(ERR, USER1, "Invalid authentication algorithm specified\n");
727 : 0 : return -1;
728 : : }
729 : :
730 : 0 : opts->auth_algo = auth_algo;
731 : :
732 : 0 : return 0;
733 : : }
734 : :
735 : : static int
736 : 0 : parse_auth_op(struct cperf_options *opts, const char *arg)
737 : : {
738 : 0 : struct name_id_map auth_op_namemap[] = {
739 : : {
740 : : rte_crypto_auth_operation_strings
741 : 0 : [RTE_CRYPTO_AUTH_OP_GENERATE],
742 : : RTE_CRYPTO_AUTH_OP_GENERATE },
743 : : {
744 : : rte_crypto_auth_operation_strings
745 : 0 : [RTE_CRYPTO_AUTH_OP_VERIFY],
746 : : RTE_CRYPTO_AUTH_OP_VERIFY
747 : : }
748 : : };
749 : :
750 : 0 : int id = get_str_key_id_mapping(auth_op_namemap,
751 : : RTE_DIM(auth_op_namemap), arg);
752 : 0 : if (id < 0) {
753 : 0 : RTE_LOG(ERR, USER1, "invalid authentication operation specified"
754 : : "\n");
755 : 0 : return -1;
756 : : }
757 : :
758 : 0 : opts->auth_op = (enum rte_crypto_auth_operation)id;
759 : :
760 : 0 : return 0;
761 : : }
762 : :
763 : : static int
764 : 0 : parse_auth_key_sz(struct cperf_options *opts, const char *arg)
765 : : {
766 : 0 : return parse_uint16_t(&opts->auth_key_sz, arg);
767 : : }
768 : :
769 : : static int
770 : 0 : parse_digest_sz(struct cperf_options *opts, const char *arg)
771 : : {
772 : 0 : return parse_uint16_t(&opts->digest_sz, arg);
773 : : }
774 : :
775 : : #ifdef RTE_LIB_SECURITY
776 : : static int
777 : 0 : parse_pdcp_sn_sz(struct cperf_options *opts, const char *arg)
778 : : {
779 : 0 : uint32_t val = 0;
780 : 0 : int ret = parse_uint32_t(&val, arg);
781 : :
782 : 0 : if (ret < 0)
783 : : return ret;
784 : :
785 : 0 : if (val != RTE_SECURITY_PDCP_SN_SIZE_5 &&
786 : : val != RTE_SECURITY_PDCP_SN_SIZE_7 &&
787 : : val != RTE_SECURITY_PDCP_SN_SIZE_12 &&
788 : : val != RTE_SECURITY_PDCP_SN_SIZE_15 &&
789 : : val != RTE_SECURITY_PDCP_SN_SIZE_18) {
790 : : printf("\nInvalid pdcp SN size: %u\n", val);
791 : 0 : return -ERANGE;
792 : : }
793 : 0 : opts->pdcp_sn_sz = val;
794 : :
795 : 0 : return 0;
796 : : }
797 : :
798 : : const char *cperf_pdcp_domain_strs[] = {
799 : : [RTE_SECURITY_PDCP_MODE_CONTROL] = "control",
800 : : [RTE_SECURITY_PDCP_MODE_DATA] = "data",
801 : : [RTE_SECURITY_PDCP_MODE_SHORT_MAC] = "short_mac"
802 : : };
803 : :
804 : : static int
805 : 0 : parse_pdcp_domain(struct cperf_options *opts, const char *arg)
806 : : {
807 : 0 : struct name_id_map pdcp_domain_namemap[] = {
808 : : {
809 : : cperf_pdcp_domain_strs
810 : 0 : [RTE_SECURITY_PDCP_MODE_CONTROL],
811 : : RTE_SECURITY_PDCP_MODE_CONTROL },
812 : : {
813 : : cperf_pdcp_domain_strs
814 : 0 : [RTE_SECURITY_PDCP_MODE_DATA],
815 : : RTE_SECURITY_PDCP_MODE_DATA
816 : : },
817 : : {
818 : : cperf_pdcp_domain_strs
819 : 0 : [RTE_SECURITY_PDCP_MODE_SHORT_MAC],
820 : : RTE_SECURITY_PDCP_MODE_SHORT_MAC
821 : : }
822 : : };
823 : :
824 : 0 : int id = get_str_key_id_mapping(pdcp_domain_namemap,
825 : : RTE_DIM(pdcp_domain_namemap), arg);
826 : 0 : if (id < 0) {
827 : 0 : RTE_LOG(ERR, USER1, "invalid pdcp domain specified"
828 : : "\n");
829 : 0 : return -1;
830 : : }
831 : :
832 : 0 : opts->pdcp_domain = (enum rte_security_pdcp_domain)id;
833 : :
834 : 0 : return 0;
835 : : }
836 : :
837 : : const char *cperf_tls_version_strs[] = {
838 : : [RTE_SECURITY_VERSION_TLS_1_2] = "TLS1.2",
839 : : [RTE_SECURITY_VERSION_TLS_1_3] = "TLS1.3",
840 : : [RTE_SECURITY_VERSION_DTLS_1_2] = "DTLS1.2"
841 : : };
842 : :
843 : : static int
844 : 0 : parse_tls_version(struct cperf_options *opts, const char *arg)
845 : : {
846 : 0 : struct name_id_map tls_version_namemap[] = {
847 : : {
848 : : cperf_tls_version_strs
849 : 0 : [RTE_SECURITY_VERSION_TLS_1_2],
850 : : RTE_SECURITY_VERSION_TLS_1_2
851 : : },
852 : : {
853 : : cperf_tls_version_strs
854 : 0 : [RTE_SECURITY_VERSION_TLS_1_3],
855 : : RTE_SECURITY_VERSION_TLS_1_3
856 : : },
857 : : {
858 : : cperf_tls_version_strs
859 : 0 : [RTE_SECURITY_VERSION_DTLS_1_2],
860 : : RTE_SECURITY_VERSION_DTLS_1_2
861 : : },
862 : : };
863 : :
864 : 0 : int id = get_str_key_id_mapping(tls_version_namemap,
865 : : RTE_DIM(tls_version_namemap), arg);
866 : 0 : if (id < 0) {
867 : 0 : RTE_LOG(ERR, USER1, "invalid TLS version specified\n");
868 : 0 : return -1;
869 : : }
870 : :
871 : 0 : opts->tls_version = (enum rte_security_tls_version)id;
872 : :
873 : 0 : return 0;
874 : : }
875 : :
876 : : static int
877 : 0 : parse_pdcp_ses_hfn_en(struct cperf_options *opts, const char *arg __rte_unused)
878 : : {
879 : 0 : opts->pdcp_ses_hfn_en = 1;
880 : 0 : return 0;
881 : : }
882 : :
883 : : static int
884 : 0 : parse_docsis_hdr_sz(struct cperf_options *opts, const char *arg)
885 : : {
886 : 0 : return parse_uint16_t(&opts->docsis_hdr_sz, arg);
887 : : }
888 : : #endif
889 : :
890 : : static int
891 : 0 : parse_auth_iv_sz(struct cperf_options *opts, const char *arg)
892 : : {
893 : 0 : return parse_uint16_t(&opts->auth_iv_sz, arg);
894 : : }
895 : :
896 : : static int
897 : 0 : parse_aead_algo(struct cperf_options *opts, const char *arg)
898 : : {
899 : : enum rte_crypto_aead_algorithm aead_algo;
900 : :
901 : 0 : if (rte_cryptodev_get_aead_algo_enum(&aead_algo, arg) < 0) {
902 : 0 : RTE_LOG(ERR, USER1, "Invalid AEAD algorithm specified\n");
903 : 0 : return -1;
904 : : }
905 : :
906 : 0 : opts->aead_algo = aead_algo;
907 : :
908 : 0 : return 0;
909 : : }
910 : :
911 : : static int
912 : 0 : parse_aead_op(struct cperf_options *opts, const char *arg)
913 : : {
914 : 0 : struct name_id_map aead_op_namemap[] = {
915 : : {
916 : : rte_crypto_aead_operation_strings
917 : 0 : [RTE_CRYPTO_AEAD_OP_ENCRYPT],
918 : : RTE_CRYPTO_AEAD_OP_ENCRYPT },
919 : : {
920 : : rte_crypto_aead_operation_strings
921 : 0 : [RTE_CRYPTO_AEAD_OP_DECRYPT],
922 : : RTE_CRYPTO_AEAD_OP_DECRYPT
923 : : }
924 : : };
925 : :
926 : 0 : int id = get_str_key_id_mapping(aead_op_namemap,
927 : : RTE_DIM(aead_op_namemap), arg);
928 : 0 : if (id < 0) {
929 : 0 : RTE_LOG(ERR, USER1, "invalid AEAD operation specified"
930 : : "\n");
931 : 0 : return -1;
932 : : }
933 : :
934 : 0 : opts->aead_op = (enum rte_crypto_aead_operation)id;
935 : :
936 : 0 : return 0;
937 : : }
938 : :
939 : : static int
940 : 0 : parse_aead_key_sz(struct cperf_options *opts, const char *arg)
941 : : {
942 : 0 : return parse_uint16_t(&opts->aead_key_sz, arg);
943 : : }
944 : :
945 : : static int
946 : 0 : parse_aead_iv_sz(struct cperf_options *opts, const char *arg)
947 : : {
948 : 0 : return parse_uint16_t(&opts->aead_iv_sz, arg);
949 : : }
950 : :
951 : : static int
952 : 0 : parse_aead_aad_sz(struct cperf_options *opts, const char *arg)
953 : : {
954 : 0 : return parse_uint16_t(&opts->aead_aad_sz, arg);
955 : : }
956 : :
957 : : static int
958 : 0 : parse_asym_op(struct cperf_options *opts, const char *arg)
959 : : {
960 : 0 : struct name_id_map asym_op_namemap[] = {
961 : : {
962 : : rte_crypto_asym_op_strings
963 : 0 : [RTE_CRYPTO_ASYM_OP_ENCRYPT],
964 : : RTE_CRYPTO_ASYM_OP_ENCRYPT
965 : : },
966 : : {
967 : : rte_crypto_asym_op_strings
968 : 0 : [RTE_CRYPTO_ASYM_OP_DECRYPT],
969 : : RTE_CRYPTO_ASYM_OP_DECRYPT
970 : : },
971 : : {
972 : : rte_crypto_asym_op_strings
973 : 0 : [RTE_CRYPTO_ASYM_OP_SIGN],
974 : : RTE_CRYPTO_ASYM_OP_SIGN
975 : : },
976 : : {
977 : : rte_crypto_asym_op_strings
978 : 0 : [RTE_CRYPTO_ASYM_OP_VERIFY],
979 : : RTE_CRYPTO_ASYM_OP_VERIFY
980 : : }
981 : : };
982 : :
983 : 0 : int id = get_str_key_id_mapping(asym_op_namemap,
984 : : RTE_DIM(asym_op_namemap), arg);
985 : 0 : if (id < 0) {
986 : 0 : RTE_LOG(ERR, USER1, "invalid ASYM operation specified\n");
987 : 0 : return -1;
988 : : }
989 : :
990 : 0 : opts->asym_op_type = (enum rte_crypto_asym_op_type)id;
991 : :
992 : 0 : return 0;
993 : : }
994 : :
995 : :
996 : : static int
997 : 0 : parse_csv_friendly(struct cperf_options *opts, const char *arg __rte_unused)
998 : : {
999 : 0 : opts->csv = 1;
1000 : 0 : opts->silent = 1;
1001 : 0 : return 0;
1002 : : }
1003 : :
1004 : : static int
1005 : 0 : parse_pmd_cyclecount_delay_ms(struct cperf_options *opts,
1006 : : const char *arg)
1007 : : {
1008 : 0 : int ret = parse_uint32_t(&opts->pmdcc_delay, arg);
1009 : :
1010 : 0 : if (ret) {
1011 : 0 : RTE_LOG(ERR, USER1, "failed to parse pmd-cyclecount delay\n");
1012 : 0 : return -1;
1013 : : }
1014 : :
1015 : : return 0;
1016 : : }
1017 : :
1018 : : static int
1019 : 0 : parse_low_prio_qp_mask(struct cperf_options *opts, const char *arg)
1020 : : {
1021 : 0 : char *end = NULL;
1022 : : unsigned long n;
1023 : :
1024 : : /* parse hexadecimal string */
1025 : 0 : n = strtoul(arg, &end, 16);
1026 : 0 : if ((optarg[0] == '\0') || (end == NULL) || (*end != '\0'))
1027 : : return -1;
1028 : :
1029 : 0 : opts->low_prio_qp_mask = n;
1030 : :
1031 : 0 : return 0;
1032 : : }
1033 : :
1034 : : typedef int (*option_parser_t)(struct cperf_options *opts,
1035 : : const char *arg);
1036 : :
1037 : : struct long_opt_parser {
1038 : : const char *lgopt_name;
1039 : : option_parser_t parser_fn;
1040 : :
1041 : : };
1042 : :
1043 : : static struct option lgopts[] = {
1044 : :
1045 : : { CPERF_PTEST_TYPE, required_argument, 0, 0 },
1046 : : { CPERF_MODEX_LEN, required_argument, 0, 0 },
1047 : : { CPERF_RSA_PRIV_KEYTYPE, required_argument, 0, 0 },
1048 : : { CPERF_RSA_MODLEN, required_argument, 0, 0 },
1049 : :
1050 : : { CPERF_POOL_SIZE, required_argument, 0, 0 },
1051 : : { CPERF_TOTAL_OPS, required_argument, 0, 0 },
1052 : : { CPERF_BURST_SIZE, required_argument, 0, 0 },
1053 : : { CPERF_BUFFER_SIZE, required_argument, 0, 0 },
1054 : : { CPERF_SEGMENT_SIZE, required_argument, 0, 0 },
1055 : : { CPERF_DESC_NB, required_argument, 0, 0 },
1056 : :
1057 : : { CPERF_LOW_PRIO_QP_MASK, required_argument, 0, 0 },
1058 : :
1059 : : { CPERF_IMIX, required_argument, 0, 0 },
1060 : : { CPERF_DEVTYPE, required_argument, 0, 0 },
1061 : : { CPERF_OPTYPE, required_argument, 0, 0 },
1062 : :
1063 : : { CPERF_SILENT, no_argument, 0, 0 },
1064 : : { CPERF_SESSIONLESS, no_argument, 0, 0 },
1065 : : { CPERF_SHARED_SESSION, no_argument, 0, 0 },
1066 : : { CPERF_OUT_OF_PLACE, no_argument, 0, 0 },
1067 : : { CPERF_TEST_FILE, required_argument, 0, 0 },
1068 : : { CPERF_TEST_NAME, required_argument, 0, 0 },
1069 : :
1070 : : { CPERF_CIPHER_ALGO, required_argument, 0, 0 },
1071 : : { CPERF_CIPHER_OP, required_argument, 0, 0 },
1072 : :
1073 : : { CPERF_CIPHER_KEY_SZ, required_argument, 0, 0 },
1074 : : { CPERF_CIPHER_IV_SZ, required_argument, 0, 0 },
1075 : :
1076 : : { CPERF_AUTH_ALGO, required_argument, 0, 0 },
1077 : : { CPERF_AUTH_OP, required_argument, 0, 0 },
1078 : :
1079 : : { CPERF_AUTH_KEY_SZ, required_argument, 0, 0 },
1080 : : { CPERF_AUTH_IV_SZ, required_argument, 0, 0 },
1081 : :
1082 : : { CPERF_AEAD_ALGO, required_argument, 0, 0 },
1083 : : { CPERF_AEAD_OP, required_argument, 0, 0 },
1084 : :
1085 : : { CPERF_AEAD_KEY_SZ, required_argument, 0, 0 },
1086 : : { CPERF_AEAD_AAD_SZ, required_argument, 0, 0 },
1087 : : { CPERF_AEAD_IV_SZ, required_argument, 0, 0 },
1088 : :
1089 : : { CPERF_DIGEST_SZ, required_argument, 0, 0 },
1090 : :
1091 : : { CPERF_ASYM_OP, required_argument, 0, 0 },
1092 : :
1093 : : #ifdef RTE_LIB_SECURITY
1094 : : { CPERF_PDCP_SN_SZ, required_argument, 0, 0 },
1095 : : { CPERF_PDCP_DOMAIN, required_argument, 0, 0 },
1096 : : { CPERF_PDCP_SES_HFN_EN, no_argument, 0, 0 },
1097 : : { CPERF_ENABLE_SDAP, no_argument, 0, 0 },
1098 : : { CPERF_DOCSIS_HDR_SZ, required_argument, 0, 0 },
1099 : : { CPERF_TLS_VERSION, required_argument, 0, 0 },
1100 : : #endif
1101 : : { CPERF_CSV, no_argument, 0, 0},
1102 : :
1103 : : { CPERF_PMDCC_DELAY_MS, required_argument, 0, 0 },
1104 : :
1105 : : { NULL, 0, 0, 0 }
1106 : : };
1107 : :
1108 : : void
1109 : 0 : cperf_options_default(struct cperf_options *opts)
1110 : : {
1111 : 0 : opts->test = CPERF_TEST_TYPE_THROUGHPUT;
1112 : :
1113 : 0 : opts->pool_sz = 8192;
1114 : 0 : opts->total_ops = 10000000;
1115 : 0 : opts->nb_descriptors = 2048;
1116 : :
1117 : 0 : opts->buffer_size_list[0] = 64;
1118 : 0 : opts->buffer_size_count = 1;
1119 : 0 : opts->max_buffer_size = 64;
1120 : 0 : opts->min_buffer_size = 64;
1121 : 0 : opts->inc_buffer_size = 0;
1122 : :
1123 : 0 : opts->burst_size_list[0] = 32;
1124 : 0 : opts->burst_size_count = 1;
1125 : 0 : opts->max_burst_size = 32;
1126 : 0 : opts->min_burst_size = 32;
1127 : 0 : opts->inc_burst_size = 0;
1128 : :
1129 : : /*
1130 : : * Will be parsed from command line or set to
1131 : : * maximum buffer size + digest, later
1132 : : */
1133 : 0 : opts->segment_sz = 0;
1134 : :
1135 : 0 : opts->imix_distribution_count = 0;
1136 : 0 : strlcpy(opts->device_type, "crypto_aesni_mb",
1137 : : sizeof(opts->device_type));
1138 : 0 : opts->nb_qps = 1;
1139 : :
1140 : 0 : opts->op_type = CPERF_CIPHER_THEN_AUTH;
1141 : :
1142 : 0 : opts->silent = 0;
1143 : 0 : opts->test_file = NULL;
1144 : 0 : opts->test_name = NULL;
1145 : 0 : opts->sessionless = 0;
1146 : 0 : opts->out_of_place = 0;
1147 : 0 : opts->csv = 0;
1148 : :
1149 : 0 : opts->cipher_algo = RTE_CRYPTO_CIPHER_AES_CBC;
1150 : 0 : opts->cipher_op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1151 : 0 : opts->cipher_key_sz = 16;
1152 : 0 : opts->cipher_iv_sz = 16;
1153 : :
1154 : 0 : opts->auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1155 : 0 : opts->auth_op = RTE_CRYPTO_AUTH_OP_GENERATE;
1156 : :
1157 : 0 : opts->auth_key_sz = 64;
1158 : 0 : opts->auth_iv_sz = 0;
1159 : :
1160 : 0 : opts->aead_key_sz = 0;
1161 : 0 : opts->aead_iv_sz = 0;
1162 : 0 : opts->aead_aad_sz = 0;
1163 : :
1164 : 0 : opts->digest_sz = 12;
1165 : :
1166 : 0 : opts->pmdcc_delay = 0;
1167 : : #ifdef RTE_LIB_SECURITY
1168 : 0 : opts->pdcp_sn_sz = 12;
1169 : 0 : opts->pdcp_domain = RTE_SECURITY_PDCP_MODE_CONTROL;
1170 : 0 : opts->pdcp_ses_hfn_en = 0;
1171 : 0 : opts->pdcp_sdap = 0;
1172 : 0 : opts->docsis_hdr_sz = 17;
1173 : : #endif
1174 : 0 : opts->modex_data = (struct cperf_modex_test_data *)&modex_perf_data[0];
1175 : 0 : opts->rsa_data = &rsa_pub_perf_data[0];
1176 : 0 : opts->rsa_keytype = UINT8_MAX;
1177 : :
1178 : 0 : opts->secp192r1_data = &secp192r1_perf_data;
1179 : 0 : opts->secp224r1_data = &secp224r1_perf_data;
1180 : 0 : opts->secp256r1_data = &secp256r1_perf_data;
1181 : 0 : opts->secp384r1_data = &secp384r1_perf_data;
1182 : 0 : opts->secp521r1_data = &secp521r1_perf_data;
1183 : 0 : opts->eddsa_data = &ed25519_perf_data;
1184 : 0 : opts->sm2_data = &sm2_perf_data;
1185 : 0 : opts->mlkem_data = &mlkem_encap_perf_data[0];
1186 : 0 : opts->mldsa_data = &mldsa_sign_perf_data[0];
1187 : 0 : opts->asym_op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
1188 : 0 : }
1189 : :
1190 : : static int
1191 : 0 : cperf_opts_parse_long(int opt_idx, struct cperf_options *opts)
1192 : : {
1193 : 0 : struct long_opt_parser parsermap[] = {
1194 : : { CPERF_PTEST_TYPE, parse_cperf_test_type },
1195 : : { CPERF_MODEX_LEN, parse_modex_len },
1196 : : { CPERF_RSA_PRIV_KEYTYPE, parse_rsa_priv_keytype },
1197 : : { CPERF_RSA_MODLEN, parse_rsa_modlen },
1198 : : { CPERF_SILENT, parse_silent },
1199 : : { CPERF_POOL_SIZE, parse_pool_sz },
1200 : : { CPERF_TOTAL_OPS, parse_total_ops },
1201 : : { CPERF_BURST_SIZE, parse_burst_sz },
1202 : : { CPERF_BUFFER_SIZE, parse_buffer_sz },
1203 : : { CPERF_SEGMENT_SIZE, parse_segment_sz },
1204 : : { CPERF_DESC_NB, parse_desc_nb },
1205 : : { CPERF_LOW_PRIO_QP_MASK, parse_low_prio_qp_mask },
1206 : : { CPERF_DEVTYPE, parse_device_type },
1207 : : { CPERF_OPTYPE, parse_op_type },
1208 : : { CPERF_SESSIONLESS, parse_sessionless },
1209 : : { CPERF_SHARED_SESSION, parse_shared_session },
1210 : : { CPERF_OUT_OF_PLACE, parse_out_of_place },
1211 : : { CPERF_IMIX, parse_imix },
1212 : : { CPERF_TEST_FILE, parse_test_file },
1213 : : { CPERF_TEST_NAME, parse_test_name },
1214 : : { CPERF_CIPHER_ALGO, parse_cipher_algo },
1215 : : { CPERF_CIPHER_OP, parse_cipher_op },
1216 : : { CPERF_CIPHER_KEY_SZ, parse_cipher_key_sz },
1217 : : { CPERF_CIPHER_IV_SZ, parse_cipher_iv_sz },
1218 : : { CPERF_AUTH_ALGO, parse_auth_algo },
1219 : : { CPERF_AUTH_OP, parse_auth_op },
1220 : : { CPERF_AUTH_KEY_SZ, parse_auth_key_sz },
1221 : : { CPERF_AUTH_IV_SZ, parse_auth_iv_sz },
1222 : : { CPERF_AEAD_ALGO, parse_aead_algo },
1223 : : { CPERF_AEAD_OP, parse_aead_op },
1224 : : { CPERF_AEAD_KEY_SZ, parse_aead_key_sz },
1225 : : { CPERF_AEAD_IV_SZ, parse_aead_iv_sz },
1226 : : { CPERF_AEAD_AAD_SZ, parse_aead_aad_sz },
1227 : : { CPERF_DIGEST_SZ, parse_digest_sz },
1228 : : { CPERF_ASYM_OP, parse_asym_op },
1229 : : #ifdef RTE_LIB_SECURITY
1230 : : { CPERF_PDCP_SN_SZ, parse_pdcp_sn_sz },
1231 : : { CPERF_PDCP_DOMAIN, parse_pdcp_domain },
1232 : : { CPERF_PDCP_SES_HFN_EN, parse_pdcp_ses_hfn_en },
1233 : : { CPERF_ENABLE_SDAP, parse_enable_sdap },
1234 : : { CPERF_DOCSIS_HDR_SZ, parse_docsis_hdr_sz },
1235 : : { CPERF_TLS_VERSION, parse_tls_version },
1236 : : #endif
1237 : : { CPERF_CSV, parse_csv_friendly},
1238 : : { CPERF_PMDCC_DELAY_MS, parse_pmd_cyclecount_delay_ms},
1239 : : };
1240 : : unsigned int i;
1241 : :
1242 : 0 : for (i = 0; i < RTE_DIM(parsermap); i++) {
1243 : 0 : if (strncmp(lgopts[opt_idx].name, parsermap[i].lgopt_name,
1244 : : strlen(lgopts[opt_idx].name)) == 0)
1245 : 0 : return parsermap[i].parser_fn(opts, optarg);
1246 : : }
1247 : :
1248 : : return -EINVAL;
1249 : : }
1250 : :
1251 : : int
1252 : 0 : cperf_options_parse(struct cperf_options *options, int argc, char **argv)
1253 : : {
1254 : : int opt, retval, opt_idx;
1255 : :
1256 : 0 : while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
1257 : 0 : switch (opt) {
1258 : 0 : case 'h':
1259 : 0 : usage(argv[0]);
1260 : 0 : exit(EXIT_SUCCESS);
1261 : : break;
1262 : : /* long options */
1263 : 0 : case 0:
1264 : 0 : retval = cperf_opts_parse_long(opt_idx, options);
1265 : 0 : if (retval != 0)
1266 : 0 : return retval;
1267 : :
1268 : : break;
1269 : :
1270 : 0 : default:
1271 : 0 : usage(argv[0]);
1272 : 0 : return -EINVAL;
1273 : : }
1274 : : }
1275 : :
1276 : : return 0;
1277 : : }
1278 : :
1279 : : static int
1280 : 0 : check_cipher_buffer_length(struct cperf_options *options)
1281 : : {
1282 : : uint32_t buffer_size, buffer_size_idx = 0;
1283 : :
1284 : 0 : if (options->cipher_algo == RTE_CRYPTO_CIPHER_AES_CBC ||
1285 : : options->cipher_algo == RTE_CRYPTO_CIPHER_AES_ECB) {
1286 : 0 : if (options->inc_buffer_size != 0)
1287 : 0 : buffer_size = options->min_buffer_size;
1288 : : else
1289 : 0 : buffer_size = options->buffer_size_list[0];
1290 : :
1291 : 0 : if ((options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE) &&
1292 : 0 : (options->op_type == CPERF_AUTH_THEN_CIPHER))
1293 : 0 : buffer_size += options->digest_sz;
1294 : :
1295 : 0 : while (buffer_size <= options->max_buffer_size) {
1296 : 0 : if ((buffer_size % AES_BLOCK_SIZE) != 0) {
1297 : 0 : RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
1298 : : "not suitable for the algorithm selected\n");
1299 : 0 : return -EINVAL;
1300 : : }
1301 : :
1302 : 0 : if (options->inc_buffer_size != 0)
1303 : 0 : buffer_size += options->inc_buffer_size;
1304 : : else {
1305 : 0 : if (++buffer_size_idx == options->buffer_size_count)
1306 : : break;
1307 : 0 : buffer_size = options->buffer_size_list[buffer_size_idx];
1308 : : }
1309 : :
1310 : : }
1311 : : }
1312 : :
1313 : 0 : if (options->cipher_algo == RTE_CRYPTO_CIPHER_DES_CBC ||
1314 : 0 : options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_CBC ||
1315 : : options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_ECB) {
1316 : 0 : if (options->inc_buffer_size != 0)
1317 : 0 : buffer_size = options->min_buffer_size;
1318 : : else
1319 : 0 : buffer_size = options->buffer_size_list[0];
1320 : :
1321 : 0 : if ((options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE) &&
1322 : 0 : (options->op_type == CPERF_AUTH_THEN_CIPHER))
1323 : 0 : buffer_size += options->digest_sz;
1324 : :
1325 : 0 : while (buffer_size <= options->max_buffer_size) {
1326 : 0 : if ((buffer_size % DES_BLOCK_SIZE) != 0) {
1327 : 0 : RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
1328 : : "not suitable for the algorithm selected\n");
1329 : 0 : return -EINVAL;
1330 : : }
1331 : :
1332 : 0 : if (options->inc_buffer_size != 0)
1333 : 0 : buffer_size += options->inc_buffer_size;
1334 : : else {
1335 : 0 : if (++buffer_size_idx == options->buffer_size_count)
1336 : : break;
1337 : 0 : buffer_size = options->buffer_size_list[buffer_size_idx];
1338 : : }
1339 : :
1340 : : }
1341 : : }
1342 : :
1343 : : return 0;
1344 : : }
1345 : :
1346 : : #ifdef RTE_LIB_SECURITY
1347 : : static int
1348 : 0 : check_docsis_buffer_length(struct cperf_options *options)
1349 : : {
1350 : : uint32_t buffer_size, buffer_size_idx = 0;
1351 : :
1352 : 0 : if (options->inc_buffer_size != 0)
1353 : 0 : buffer_size = options->min_buffer_size;
1354 : : else
1355 : 0 : buffer_size = options->buffer_size_list[0];
1356 : :
1357 : 0 : while (buffer_size <= options->max_buffer_size) {
1358 : 0 : if (buffer_size < (uint32_t)(options->docsis_hdr_sz +
1359 : 0 : RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN)) {
1360 : 0 : RTE_LOG(ERR, USER1, "Some of the buffer sizes are not "
1361 : : "valid for DOCSIS\n");
1362 : 0 : return -EINVAL;
1363 : : }
1364 : :
1365 : 0 : if (options->inc_buffer_size != 0)
1366 : 0 : buffer_size += options->inc_buffer_size;
1367 : : else {
1368 : 0 : if (++buffer_size_idx == options->buffer_size_count)
1369 : : break;
1370 : 0 : buffer_size =
1371 : : options->buffer_size_list[buffer_size_idx];
1372 : : }
1373 : : }
1374 : :
1375 : : return 0;
1376 : : }
1377 : : #endif
1378 : :
1379 : : static bool
1380 : : is_valid_chained_op(struct cperf_options *options)
1381 : : {
1382 : 0 : if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
1383 : : options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE)
1384 : : return true;
1385 : :
1386 : 0 : if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT &&
1387 : : options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY)
1388 : : return true;
1389 : :
1390 : : return false;
1391 : : }
1392 : :
1393 : : static int
1394 : 0 : cperf_rsa_options_check(struct cperf_options *options)
1395 : : {
1396 : 0 : if (options->rsa_keytype != UINT8_MAX) {
1397 : 0 : switch (options->rsa_keytype) {
1398 : 0 : case RTE_RSA_KEY_TYPE_QT:
1399 : 0 : if (options->asym_op_type != RTE_CRYPTO_ASYM_OP_SIGN &&
1400 : : options->asym_op_type != RTE_CRYPTO_ASYM_OP_DECRYPT) {
1401 : 0 : RTE_LOG(ERR, USER1, "QT private key to be used in sign and decrypt op\n");
1402 : 0 : return -EINVAL;
1403 : : }
1404 : 0 : options->rsa_data = &rsa_qt_perf_data[0];
1405 : 0 : break;
1406 : 0 : case RTE_RSA_KEY_TYPE_EXP:
1407 : 0 : if (options->asym_op_type != RTE_CRYPTO_ASYM_OP_ENCRYPT &&
1408 : : options->asym_op_type != RTE_CRYPTO_ASYM_OP_VERIFY) {
1409 : 0 : RTE_LOG(ERR, USER1, "Exponent private key to be used in encrypt and verify op\n");
1410 : 0 : return -EINVAL;
1411 : : }
1412 : 0 : options->rsa_data = &rsa_exp_perf_data[0];
1413 : 0 : break;
1414 : 0 : default:
1415 : 0 : RTE_LOG(ERR, USER1, "Invalid RSA key type specified\n");
1416 : 0 : return -EINVAL;
1417 : : }
1418 : : } else {
1419 : 0 : if (options->asym_op_type != RTE_CRYPTO_ASYM_OP_ENCRYPT) {
1420 : 0 : RTE_LOG(ERR, USER1, "Public key to be used in encrypt op\n");
1421 : 0 : return -EINVAL;
1422 : : }
1423 : : }
1424 : : return 0;
1425 : : }
1426 : :
1427 : : int
1428 : 0 : cperf_options_check(struct cperf_options *options)
1429 : : {
1430 : : uint16_t modlen;
1431 : : int i;
1432 : :
1433 : 0 : if (options->op_type == CPERF_CIPHER_ONLY ||
1434 : : options->op_type == CPERF_DOCSIS)
1435 : 0 : options->digest_sz = 0;
1436 : :
1437 : 0 : if (options->out_of_place &&
1438 : 0 : options->segment_sz <= options->max_buffer_size) {
1439 : 0 : RTE_LOG(ERR, USER1, "Out of place mode can only work "
1440 : : "with non segmented buffers\n");
1441 : 0 : return -EINVAL;
1442 : : }
1443 : :
1444 : : /*
1445 : : * If segment size is not set, assume only one segment,
1446 : : * big enough to contain the largest buffer and the digest
1447 : : */
1448 : 0 : if (options->segment_sz == 0) {
1449 : 0 : options->segment_sz = options->max_buffer_size +
1450 : 0 : options->digest_sz;
1451 : : /* In IPsec and TLS operation, packet length will be increased
1452 : : * by some bytes depend upon the algorithm, so increasing
1453 : : * the segment size by headroom to cover most of
1454 : : * the scenarios.
1455 : : */
1456 : 0 : if (options->op_type == CPERF_IPSEC || options->op_type == CPERF_TLS)
1457 : 0 : options->segment_sz += RTE_PKTMBUF_HEADROOM;
1458 : : }
1459 : :
1460 : 0 : if (options->segment_sz < options->digest_sz) {
1461 : 0 : RTE_LOG(ERR, USER1,
1462 : : "Segment size should be at least "
1463 : : "the size of the digest\n");
1464 : 0 : return -EINVAL;
1465 : : }
1466 : :
1467 : 0 : if ((options->imix_distribution_count != 0) &&
1468 : : (options->imix_distribution_count !=
1469 : 0 : options->buffer_size_count)) {
1470 : 0 : RTE_LOG(ERR, USER1, "IMIX distribution must have the same "
1471 : : "number of buffer sizes\n");
1472 : 0 : return -EINVAL;
1473 : : }
1474 : :
1475 : 0 : if (options->test == CPERF_TEST_TYPE_VERIFY &&
1476 : 0 : options->test_file == NULL) {
1477 : 0 : RTE_LOG(ERR, USER1, "Define path to the file with test"
1478 : : " vectors.\n");
1479 : 0 : return -EINVAL;
1480 : : }
1481 : :
1482 : 0 : if (options->test == CPERF_TEST_TYPE_VERIFY &&
1483 : 0 : options->op_type != CPERF_CIPHER_ONLY &&
1484 : 0 : options->test_name == NULL) {
1485 : 0 : RTE_LOG(ERR, USER1, "Define test name to get the correct digest"
1486 : : " from the test vectors.\n");
1487 : 0 : return -EINVAL;
1488 : : }
1489 : :
1490 : 0 : if (options->test_name != NULL && options->test_file == NULL) {
1491 : 0 : RTE_LOG(ERR, USER1, "Define path to the file with test"
1492 : : " vectors.\n");
1493 : 0 : return -EINVAL;
1494 : : }
1495 : :
1496 : 0 : if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY &&
1497 : 0 : options->test_file == NULL) {
1498 : 0 : RTE_LOG(ERR, USER1, "Define path to the file with test"
1499 : : " vectors.\n");
1500 : 0 : return -EINVAL;
1501 : : }
1502 : :
1503 : 0 : if (options->test == CPERF_TEST_TYPE_VERIFY &&
1504 : 0 : (options->inc_buffer_size != 0 ||
1505 : 0 : options->buffer_size_count > 1)) {
1506 : 0 : RTE_LOG(ERR, USER1, "Only one buffer size is allowed when "
1507 : : "using the verify test.\n");
1508 : 0 : return -EINVAL;
1509 : : }
1510 : :
1511 : 0 : if (options->test == CPERF_TEST_TYPE_VERIFY &&
1512 : 0 : (options->inc_burst_size != 0 ||
1513 : 0 : options->burst_size_count > 1)) {
1514 : 0 : RTE_LOG(ERR, USER1, "Only one burst size is allowed when "
1515 : : "using the verify test.\n");
1516 : 0 : return -EINVAL;
1517 : : }
1518 : :
1519 : 0 : if (options->test == CPERF_TEST_TYPE_PMDCC &&
1520 : 0 : options->pool_sz < options->nb_descriptors) {
1521 : 0 : RTE_LOG(ERR, USER1, "For pmd cyclecount benchmarks, pool size "
1522 : : "must be equal or greater than the number of "
1523 : : "cryptodev descriptors.\n");
1524 : 0 : return -EINVAL;
1525 : : }
1526 : :
1527 : 0 : if (options->test == CPERF_TEST_TYPE_VERIFY &&
1528 : : options->imix_distribution_count > 0) {
1529 : 0 : RTE_LOG(ERR, USER1, "IMIX is not allowed when "
1530 : : "using the verify test.\n");
1531 : 0 : return -EINVAL;
1532 : : }
1533 : :
1534 : 0 : if (options->op_type == CPERF_CIPHER_THEN_AUTH ||
1535 : : options->op_type == CPERF_AUTH_THEN_CIPHER) {
1536 : : if (!is_valid_chained_op(options)) {
1537 : 0 : RTE_LOG(ERR, USER1, "Invalid chained operation.\n");
1538 : 0 : return -EINVAL;
1539 : : }
1540 : : }
1541 : :
1542 : 0 : if (options->op_type == CPERF_CIPHER_THEN_AUTH) {
1543 : 0 : if (options->cipher_op != RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
1544 : : options->auth_op !=
1545 : : RTE_CRYPTO_AUTH_OP_GENERATE) {
1546 : 0 : RTE_LOG(ERR, USER1, "Option cipher then auth must use"
1547 : : " options: encrypt and generate.\n");
1548 : 0 : return -EINVAL;
1549 : : }
1550 : : }
1551 : :
1552 : 0 : if ((options->test == CPERF_TEST_TYPE_THROUGHPUT ||
1553 : 0 : options->test == CPERF_TEST_TYPE_LATENCY) &&
1554 : 0 : (options->aead_op == RTE_CRYPTO_AEAD_OP_DECRYPT ||
1555 : 0 : options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) &&
1556 : : !options->out_of_place) {
1557 : 0 : RTE_LOG(ERR, USER1, "Only out-of-place is allowed in throughput and"
1558 : : " latency decryption.\n");
1559 : 0 : return -EINVAL;
1560 : : }
1561 : :
1562 : 0 : if ((options->test == CPERF_TEST_TYPE_THROUGHPUT ||
1563 : 0 : options->test == CPERF_TEST_TYPE_LATENCY) &&
1564 : 0 : (options->aead_op == RTE_CRYPTO_AEAD_OP_DECRYPT ||
1565 : 0 : options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) &&
1566 : 0 : options->test_name == NULL &&
1567 : 0 : options->test_file == NULL) {
1568 : 0 : RTE_LOG(ERR, USER1, "Define path to the file with test"
1569 : : " vectors.\n");
1570 : 0 : RTE_LOG(ERR, USER1, "Define test name to get the correct digest"
1571 : : " from the test vectors.\n");
1572 : 0 : return -EINVAL;
1573 : : }
1574 : :
1575 : 0 : if (options->op_type == CPERF_CIPHER_ONLY ||
1576 : 0 : options->op_type == CPERF_CIPHER_THEN_AUTH ||
1577 : : options->op_type == CPERF_AUTH_THEN_CIPHER) {
1578 : 0 : if (check_cipher_buffer_length(options) < 0)
1579 : : return -EINVAL;
1580 : : }
1581 : :
1582 : 0 : if (options->modex_len) {
1583 : 0 : if (options->op_type != CPERF_ASYM_MODEX) {
1584 : 0 : RTE_LOG(ERR, USER1, "Option modex len should be used only with "
1585 : : " optype: modex.\n");
1586 : 0 : return -EINVAL;
1587 : : }
1588 : :
1589 : 0 : for (i = 0; i < (int)RTE_DIM(modex_perf_data); i++) {
1590 : 0 : if (modex_perf_data[i].modulus.len ==
1591 : : options->modex_len) {
1592 : 0 : options->modex_data =
1593 : 0 : (struct cperf_modex_test_data
1594 : : *)&modex_perf_data[i];
1595 : 0 : break;
1596 : : }
1597 : : }
1598 : 0 : if (i == (int)RTE_DIM(modex_perf_data)) {
1599 : 0 : RTE_LOG(ERR, USER1,
1600 : : "Option modex len: %d is not supported\n",
1601 : : options->modex_len);
1602 : 0 : return -EINVAL;
1603 : : }
1604 : : }
1605 : :
1606 : :
1607 : 0 : if (options->op_type == CPERF_ASYM_RSA) {
1608 : 0 : if (cperf_rsa_options_check(options) < 0) {
1609 : 0 : RTE_LOG(ERR, USER1, "Invalid RSA options\n");
1610 : 0 : return -EINVAL;
1611 : : }
1612 : :
1613 : 0 : if (options->rsa_modlen) {
1614 : 0 : if (options->rsa_keytype == RTE_RSA_KEY_TYPE_QT) {
1615 : 0 : for (i = 0; i < (int)RTE_DIM(rsa_qt_perf_data); i++) {
1616 : 0 : modlen = rsa_qt_perf_data[i].n.length * 8;
1617 : 0 : if (options->rsa_modlen == modlen) {
1618 : 0 : options->rsa_data =
1619 : 0 : (struct cperf_rsa_test_data *)
1620 : : &rsa_qt_perf_data[i];
1621 : 0 : break;
1622 : : }
1623 : : }
1624 : :
1625 : 0 : if (i == (int)RTE_DIM(rsa_qt_perf_data)) {
1626 : 0 : RTE_LOG(ERR, USER1,
1627 : : "Option rsa_modlen: %d is not supported for QT private key\n",
1628 : : options->rsa_modlen);
1629 : 0 : return -EINVAL;
1630 : : }
1631 : 0 : } else if (options->rsa_keytype == RTE_RSA_KEY_TYPE_EXP) {
1632 : 0 : for (i = 0; i < (int)RTE_DIM(rsa_exp_perf_data); i++) {
1633 : 0 : modlen = rsa_exp_perf_data[i].n.length * 8;
1634 : 0 : if (options->rsa_modlen == modlen) {
1635 : 0 : options->rsa_data =
1636 : 0 : (struct cperf_rsa_test_data *)
1637 : : &rsa_exp_perf_data[i];
1638 : 0 : break;
1639 : : }
1640 : : }
1641 : :
1642 : 0 : if (i == (int)RTE_DIM(rsa_exp_perf_data)) {
1643 : 0 : RTE_LOG(ERR, USER1,
1644 : : "Option rsa_modlen: %d is not supported for exponent private key\n",
1645 : : options->rsa_modlen);
1646 : 0 : return -EINVAL;
1647 : : }
1648 : : } else {
1649 : 0 : for (i = 0; i < (int)RTE_DIM(rsa_pub_perf_data); i++) {
1650 : 0 : modlen = rsa_pub_perf_data[i].n.length * 8;
1651 : 0 : if (options->rsa_modlen == modlen) {
1652 : 0 : options->rsa_data =
1653 : 0 : (struct cperf_rsa_test_data *)
1654 : : &rsa_pub_perf_data[i];
1655 : 0 : break;
1656 : : }
1657 : : }
1658 : :
1659 : 0 : if (i == (int)RTE_DIM(rsa_pub_perf_data)) {
1660 : 0 : RTE_LOG(ERR, USER1,
1661 : : "Option rsa_modlen: %d is not supported for public key\n",
1662 : : options->rsa_modlen);
1663 : 0 : return -EINVAL;
1664 : : }
1665 : : }
1666 : : }
1667 : : }
1668 : :
1669 : 0 : if (options->op_type == CPERF_ASYM_SECP192R1 ||
1670 : : options->op_type == CPERF_ASYM_SECP224R1 ||
1671 : : options->op_type == CPERF_ASYM_SECP256R1 ||
1672 : 0 : options->op_type == CPERF_ASYM_SECP384R1 ||
1673 : : options->op_type == CPERF_ASYM_SECP521R1) {
1674 : :
1675 : 0 : if (options->asym_op_type != RTE_CRYPTO_ASYM_OP_SIGN &&
1676 : : options->asym_op_type != RTE_CRYPTO_ASYM_OP_VERIFY) {
1677 : 0 : RTE_LOG(ERR, USER1, "ECDSA operations only support sign and verify\n");
1678 : 0 : return -EINVAL;
1679 : : }
1680 : : }
1681 : :
1682 : 0 : if (options->op_type == CPERF_ASYM_MLKEM512) {
1683 : 0 : if (options->asym_op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT)
1684 : 0 : options->mlkem_data = &mlkem_encap_perf_data[0];
1685 : 0 : else if (options->asym_op_type == RTE_CRYPTO_ASYM_OP_DECRYPT)
1686 : 0 : options->mlkem_data = &mlkem_decap_perf_data[0];
1687 : : else {
1688 : 0 : RTE_LOG(ERR, USER1,
1689 : : "ML-KEM operations only support encrypt (encapsulate) and decrypt (decapsulate)\n");
1690 : 0 : return -EINVAL;
1691 : : }
1692 : : }
1693 : :
1694 : : #ifdef RTE_LIB_SECURITY
1695 : 0 : if (options->op_type == CPERF_DOCSIS) {
1696 : 0 : if (check_docsis_buffer_length(options) < 0)
1697 : : return -EINVAL;
1698 : : }
1699 : :
1700 : 0 : if (options->op_type == CPERF_IPSEC || options->op_type == CPERF_TLS) {
1701 : 0 : if (options->aead_algo) {
1702 : 0 : if (options->aead_op == RTE_CRYPTO_AEAD_OP_ENCRYPT)
1703 : 0 : options->is_outbound = 1;
1704 : : else
1705 : 0 : options->is_outbound = 0;
1706 : : } else {
1707 : 0 : if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
1708 : 0 : options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE)
1709 : 0 : options->is_outbound = 1;
1710 : : else
1711 : 0 : options->is_outbound = 0;
1712 : : }
1713 : : }
1714 : : #endif
1715 : :
1716 : 0 : if (options->op_type == CPERF_ASYM_MLDSA44) {
1717 : 0 : if (options->asym_op_type == RTE_CRYPTO_ASYM_OP_SIGN)
1718 : 0 : options->mldsa_data = &mldsa_sign_perf_data[0];
1719 : 0 : else if (options->asym_op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
1720 : 0 : options->mldsa_data = &mldsa_verify_perf_data[0];
1721 : : else {
1722 : 0 : RTE_LOG(ERR, USER1, "ML-DSA only supports sign and verify operations\n");
1723 : 0 : return -EINVAL;
1724 : : }
1725 : : }
1726 : :
1727 : : return 0;
1728 : : }
1729 : :
1730 : : void
1731 : 0 : cperf_options_dump(struct cperf_options *opts)
1732 : : {
1733 : : uint8_t size_idx;
1734 : :
1735 : : printf("# Crypto Performance Application Options:\n");
1736 : : printf("#\n");
1737 : 0 : printf("# cperf test: %s\n", cperf_test_type_strs[opts->test]);
1738 : : printf("#\n");
1739 : 0 : printf("# cperf operation type: %s\n", cperf_op_type_strs[opts->op_type]);
1740 : : printf("#\n");
1741 : 0 : printf("# size of crypto op / mbuf pool: %u\n", opts->pool_sz);
1742 : 0 : printf("# total number of ops: %u\n", opts->total_ops);
1743 : 0 : if (opts->inc_buffer_size != 0) {
1744 : : printf("# buffer size:\n");
1745 : 0 : printf("#\t min: %u\n", opts->min_buffer_size);
1746 : 0 : printf("#\t max: %u\n", opts->max_buffer_size);
1747 : 0 : printf("#\t inc: %u\n", opts->inc_buffer_size);
1748 : : } else {
1749 : : printf("# buffer sizes: ");
1750 : 0 : for (size_idx = 0; size_idx < opts->buffer_size_count; size_idx++)
1751 : 0 : printf("%u ", opts->buffer_size_list[size_idx]);
1752 : : printf("\n");
1753 : : }
1754 : 0 : if (opts->inc_burst_size != 0) {
1755 : : printf("# burst size:\n");
1756 : 0 : printf("#\t min: %u\n", opts->min_burst_size);
1757 : 0 : printf("#\t max: %u\n", opts->max_burst_size);
1758 : 0 : printf("#\t inc: %u\n", opts->inc_burst_size);
1759 : : } else {
1760 : : printf("# burst sizes: ");
1761 : 0 : for (size_idx = 0; size_idx < opts->burst_size_count; size_idx++)
1762 : 0 : printf("%u ", opts->burst_size_list[size_idx]);
1763 : : printf("\n");
1764 : : }
1765 : 0 : printf("\n# segment size: %u\n", opts->segment_sz);
1766 : : printf("#\n");
1767 : 0 : printf("# cryptodev type: %s\n", opts->device_type);
1768 : : printf("#\n");
1769 : 0 : printf("# number of queue pairs per device: %u\n", opts->nb_qps);
1770 : 0 : printf("# crypto operation: %s\n", cperf_op_type_strs[opts->op_type]);
1771 : 0 : if (cperf_is_asym_test(opts)) {
1772 : 0 : if (opts->op_type != CPERF_ASYM_MODEX)
1773 : 0 : printf("# asym operation type: %s\n",
1774 : 0 : rte_crypto_asym_op_strings[opts->asym_op_type]);
1775 : 0 : if (opts->op_type == CPERF_ASYM_RSA)
1776 : 0 : printf("# rsa test name: %s\n", opts->rsa_data->name);
1777 : 0 : if (opts->op_type == CPERF_ASYM_MLDSA44)
1778 : 0 : printf("# mldsa test name: %s\n", opts->mldsa_data->name);
1779 : 0 : if (opts->op_type == CPERF_ASYM_MLKEM512)
1780 : 0 : printf("# mlkem test name: %s\n", opts->mlkem_data->name);
1781 : : }
1782 : 0 : printf("# sessionless: %s\n", opts->sessionless ? "yes" : "no");
1783 : 0 : printf("# shared session: %s\n", opts->shared_session ? "yes" : "no");
1784 : 0 : printf("# out of place: %s\n", opts->out_of_place ? "yes" : "no");
1785 : 0 : if (opts->test == CPERF_TEST_TYPE_PMDCC)
1786 : 0 : printf("# inter-burst delay: %u ms\n", opts->pmdcc_delay);
1787 : :
1788 : : printf("#\n");
1789 : :
1790 : 0 : if (opts->op_type == CPERF_AUTH_ONLY ||
1791 : 0 : opts->op_type == CPERF_CIPHER_THEN_AUTH ||
1792 : : opts->op_type == CPERF_AUTH_THEN_CIPHER) {
1793 : 0 : printf("# auth algorithm: %s\n",
1794 : : rte_cryptodev_get_auth_algo_string(opts->auth_algo));
1795 : 0 : printf("# auth operation: %s\n",
1796 : 0 : rte_crypto_auth_operation_strings[opts->auth_op]);
1797 : 0 : printf("# auth key size: %u\n", opts->auth_key_sz);
1798 : 0 : printf("# auth iv size: %u\n", opts->auth_iv_sz);
1799 : 0 : printf("# auth digest size: %u\n", opts->digest_sz);
1800 : : printf("#\n");
1801 : : }
1802 : :
1803 : 0 : if (opts->op_type == CPERF_CIPHER_ONLY ||
1804 : 0 : opts->op_type == CPERF_CIPHER_THEN_AUTH ||
1805 : : opts->op_type == CPERF_AUTH_THEN_CIPHER) {
1806 : 0 : printf("# cipher algorithm: %s\n",
1807 : : rte_cryptodev_get_cipher_algo_string(opts->cipher_algo));
1808 : 0 : printf("# cipher operation: %s\n",
1809 : 0 : rte_crypto_cipher_operation_strings[opts->cipher_op]);
1810 : 0 : printf("# cipher key size: %u\n", opts->cipher_key_sz);
1811 : 0 : printf("# cipher iv size: %u\n", opts->cipher_iv_sz);
1812 : : printf("#\n");
1813 : : }
1814 : :
1815 : 0 : if (opts->op_type == CPERF_AEAD) {
1816 : 0 : printf("# aead algorithm: %s\n",
1817 : : rte_cryptodev_get_aead_algo_string(opts->aead_algo));
1818 : 0 : printf("# aead operation: %s\n",
1819 : 0 : rte_crypto_aead_operation_strings[opts->aead_op]);
1820 : 0 : printf("# aead key size: %u\n", opts->aead_key_sz);
1821 : 0 : printf("# aead iv size: %u\n", opts->aead_iv_sz);
1822 : 0 : printf("# aead digest size: %u\n", opts->digest_sz);
1823 : 0 : printf("# aead aad size: %u\n", opts->aead_aad_sz);
1824 : : printf("#\n");
1825 : : }
1826 : :
1827 : : #ifdef RTE_LIB_SECURITY
1828 : 0 : if (opts->op_type == CPERF_DOCSIS) {
1829 : 0 : printf("# docsis header size: %u\n", opts->docsis_hdr_sz);
1830 : : printf("#\n");
1831 : : }
1832 : : #endif
1833 : 0 : }
|