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