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 (access(opts->test_file, F_OK) != -1)
520 : : return 0;
521 : 0 : RTE_LOG(ERR, USER1, "Test vector file doesn't exist\n");
522 : 0 : free(opts->test_file);
523 : :
524 : 0 : return -1;
525 : : }
526 : :
527 : : static int
528 : 0 : parse_test_name(struct cperf_options *opts,
529 : : const char *arg)
530 : : {
531 : 0 : char *test_name = (char *) rte_zmalloc(NULL,
532 : 0 : sizeof(char) * (strlen(arg) + 3), 0);
533 : 0 : if (test_name == NULL) {
534 : 0 : RTE_LOG(ERR, USER1, "Failed to rte zmalloc with size: %zu\n",
535 : : strlen(arg) + 3);
536 : 0 : return -1;
537 : : }
538 : :
539 : 0 : snprintf(test_name, strlen(arg) + 3, "[%s]", arg);
540 : 0 : opts->test_name = test_name;
541 : :
542 : 0 : return 0;
543 : : }
544 : :
545 : : static int
546 : 0 : parse_silent(struct cperf_options *opts,
547 : : const char *arg __rte_unused)
548 : : {
549 : 0 : opts->silent = 1;
550 : :
551 : 0 : return 0;
552 : : }
553 : :
554 : : static int
555 : 0 : parse_enable_sdap(struct cperf_options *opts,
556 : : const char *arg __rte_unused)
557 : : {
558 : 0 : opts->pdcp_sdap = 1;
559 : :
560 : 0 : return 0;
561 : : }
562 : :
563 : : static int
564 : 0 : parse_cipher_algo(struct cperf_options *opts, const char *arg)
565 : : {
566 : :
567 : : enum rte_crypto_cipher_algorithm cipher_algo;
568 : :
569 : 0 : if (rte_cryptodev_get_cipher_algo_enum(&cipher_algo, arg) < 0) {
570 : 0 : RTE_LOG(ERR, USER1, "Invalid cipher algorithm specified\n");
571 : 0 : return -1;
572 : : }
573 : :
574 : 0 : opts->cipher_algo = cipher_algo;
575 : :
576 : 0 : return 0;
577 : : }
578 : :
579 : : static int
580 : 0 : parse_cipher_op(struct cperf_options *opts, const char *arg)
581 : : {
582 : 0 : struct name_id_map cipher_op_namemap[] = {
583 : : {
584 : : rte_crypto_cipher_operation_strings
585 : 0 : [RTE_CRYPTO_CIPHER_OP_ENCRYPT],
586 : : RTE_CRYPTO_CIPHER_OP_ENCRYPT },
587 : : {
588 : : rte_crypto_cipher_operation_strings
589 : 0 : [RTE_CRYPTO_CIPHER_OP_DECRYPT],
590 : : RTE_CRYPTO_CIPHER_OP_DECRYPT
591 : : }
592 : : };
593 : :
594 : 0 : int id = get_str_key_id_mapping(cipher_op_namemap,
595 : : RTE_DIM(cipher_op_namemap), arg);
596 : 0 : if (id < 0) {
597 : 0 : RTE_LOG(ERR, USER1, "Invalid cipher operation specified\n");
598 : 0 : return -1;
599 : : }
600 : :
601 : 0 : opts->cipher_op = (enum rte_crypto_cipher_operation)id;
602 : :
603 : 0 : return 0;
604 : : }
605 : :
606 : : static int
607 : 0 : parse_cipher_key_sz(struct cperf_options *opts, const char *arg)
608 : : {
609 : 0 : return parse_uint16_t(&opts->cipher_key_sz, arg);
610 : : }
611 : :
612 : : static int
613 : 0 : parse_cipher_iv_sz(struct cperf_options *opts, const char *arg)
614 : : {
615 : 0 : return parse_uint16_t(&opts->cipher_iv_sz, arg);
616 : : }
617 : :
618 : : static int
619 : 0 : parse_auth_algo(struct cperf_options *opts, const char *arg)
620 : : {
621 : : enum rte_crypto_auth_algorithm auth_algo;
622 : :
623 : 0 : if (rte_cryptodev_get_auth_algo_enum(&auth_algo, arg) < 0) {
624 : 0 : RTE_LOG(ERR, USER1, "Invalid authentication algorithm specified\n");
625 : 0 : return -1;
626 : : }
627 : :
628 : 0 : opts->auth_algo = auth_algo;
629 : :
630 : 0 : return 0;
631 : : }
632 : :
633 : : static int
634 : 0 : parse_auth_op(struct cperf_options *opts, const char *arg)
635 : : {
636 : 0 : struct name_id_map auth_op_namemap[] = {
637 : : {
638 : : rte_crypto_auth_operation_strings
639 : 0 : [RTE_CRYPTO_AUTH_OP_GENERATE],
640 : : RTE_CRYPTO_AUTH_OP_GENERATE },
641 : : {
642 : : rte_crypto_auth_operation_strings
643 : 0 : [RTE_CRYPTO_AUTH_OP_VERIFY],
644 : : RTE_CRYPTO_AUTH_OP_VERIFY
645 : : }
646 : : };
647 : :
648 : 0 : int id = get_str_key_id_mapping(auth_op_namemap,
649 : : RTE_DIM(auth_op_namemap), arg);
650 : 0 : if (id < 0) {
651 : 0 : RTE_LOG(ERR, USER1, "invalid authentication operation specified"
652 : : "\n");
653 : 0 : return -1;
654 : : }
655 : :
656 : 0 : opts->auth_op = (enum rte_crypto_auth_operation)id;
657 : :
658 : 0 : return 0;
659 : : }
660 : :
661 : : static int
662 : 0 : parse_auth_key_sz(struct cperf_options *opts, const char *arg)
663 : : {
664 : 0 : return parse_uint16_t(&opts->auth_key_sz, arg);
665 : : }
666 : :
667 : : static int
668 : 0 : parse_digest_sz(struct cperf_options *opts, const char *arg)
669 : : {
670 : 0 : return parse_uint16_t(&opts->digest_sz, arg);
671 : : }
672 : :
673 : : #ifdef RTE_LIB_SECURITY
674 : : static int
675 : 0 : parse_pdcp_sn_sz(struct cperf_options *opts, const char *arg)
676 : : {
677 : 0 : uint32_t val = 0;
678 : 0 : int ret = parse_uint32_t(&val, arg);
679 : :
680 : 0 : if (ret < 0)
681 : : return ret;
682 : :
683 : 0 : if (val != RTE_SECURITY_PDCP_SN_SIZE_5 &&
684 : : val != RTE_SECURITY_PDCP_SN_SIZE_7 &&
685 : : val != RTE_SECURITY_PDCP_SN_SIZE_12 &&
686 : : val != RTE_SECURITY_PDCP_SN_SIZE_15 &&
687 : : val != RTE_SECURITY_PDCP_SN_SIZE_18) {
688 : : printf("\nInvalid pdcp SN size: %u\n", val);
689 : 0 : return -ERANGE;
690 : : }
691 : 0 : opts->pdcp_sn_sz = val;
692 : :
693 : 0 : return 0;
694 : : }
695 : :
696 : : const char *cperf_pdcp_domain_strs[] = {
697 : : [RTE_SECURITY_PDCP_MODE_CONTROL] = "control",
698 : : [RTE_SECURITY_PDCP_MODE_DATA] = "data",
699 : : [RTE_SECURITY_PDCP_MODE_SHORT_MAC] = "short_mac"
700 : : };
701 : :
702 : : static int
703 : 0 : parse_pdcp_domain(struct cperf_options *opts, const char *arg)
704 : : {
705 : 0 : struct name_id_map pdcp_domain_namemap[] = {
706 : : {
707 : : cperf_pdcp_domain_strs
708 : 0 : [RTE_SECURITY_PDCP_MODE_CONTROL],
709 : : RTE_SECURITY_PDCP_MODE_CONTROL },
710 : : {
711 : : cperf_pdcp_domain_strs
712 : 0 : [RTE_SECURITY_PDCP_MODE_DATA],
713 : : RTE_SECURITY_PDCP_MODE_DATA
714 : : },
715 : : {
716 : : cperf_pdcp_domain_strs
717 : 0 : [RTE_SECURITY_PDCP_MODE_SHORT_MAC],
718 : : RTE_SECURITY_PDCP_MODE_SHORT_MAC
719 : : }
720 : : };
721 : :
722 : 0 : int id = get_str_key_id_mapping(pdcp_domain_namemap,
723 : : RTE_DIM(pdcp_domain_namemap), arg);
724 : 0 : if (id < 0) {
725 : 0 : RTE_LOG(ERR, USER1, "invalid pdcp domain specified"
726 : : "\n");
727 : 0 : return -1;
728 : : }
729 : :
730 : 0 : opts->pdcp_domain = (enum rte_security_pdcp_domain)id;
731 : :
732 : 0 : return 0;
733 : : }
734 : :
735 : : static int
736 : 0 : parse_pdcp_ses_hfn_en(struct cperf_options *opts, const char *arg __rte_unused)
737 : : {
738 : 0 : opts->pdcp_ses_hfn_en = 1;
739 : 0 : return 0;
740 : : }
741 : :
742 : : static int
743 : 0 : parse_docsis_hdr_sz(struct cperf_options *opts, const char *arg)
744 : : {
745 : 0 : return parse_uint16_t(&opts->docsis_hdr_sz, arg);
746 : : }
747 : : #endif
748 : :
749 : : static int
750 : 0 : parse_auth_iv_sz(struct cperf_options *opts, const char *arg)
751 : : {
752 : 0 : return parse_uint16_t(&opts->auth_iv_sz, arg);
753 : : }
754 : :
755 : : static int
756 : 0 : parse_aead_algo(struct cperf_options *opts, const char *arg)
757 : : {
758 : : enum rte_crypto_aead_algorithm aead_algo;
759 : :
760 : 0 : if (rte_cryptodev_get_aead_algo_enum(&aead_algo, arg) < 0) {
761 : 0 : RTE_LOG(ERR, USER1, "Invalid AEAD algorithm specified\n");
762 : 0 : return -1;
763 : : }
764 : :
765 : 0 : opts->aead_algo = aead_algo;
766 : :
767 : 0 : return 0;
768 : : }
769 : :
770 : : static int
771 : 0 : parse_aead_op(struct cperf_options *opts, const char *arg)
772 : : {
773 : 0 : struct name_id_map aead_op_namemap[] = {
774 : : {
775 : : rte_crypto_aead_operation_strings
776 : 0 : [RTE_CRYPTO_AEAD_OP_ENCRYPT],
777 : : RTE_CRYPTO_AEAD_OP_ENCRYPT },
778 : : {
779 : : rte_crypto_aead_operation_strings
780 : 0 : [RTE_CRYPTO_AEAD_OP_DECRYPT],
781 : : RTE_CRYPTO_AEAD_OP_DECRYPT
782 : : }
783 : : };
784 : :
785 : 0 : int id = get_str_key_id_mapping(aead_op_namemap,
786 : : RTE_DIM(aead_op_namemap), arg);
787 : 0 : if (id < 0) {
788 : 0 : RTE_LOG(ERR, USER1, "invalid AEAD operation specified"
789 : : "\n");
790 : 0 : return -1;
791 : : }
792 : :
793 : 0 : opts->aead_op = (enum rte_crypto_aead_operation)id;
794 : :
795 : 0 : return 0;
796 : : }
797 : :
798 : : static int
799 : 0 : parse_aead_key_sz(struct cperf_options *opts, const char *arg)
800 : : {
801 : 0 : return parse_uint16_t(&opts->aead_key_sz, arg);
802 : : }
803 : :
804 : : static int
805 : 0 : parse_aead_iv_sz(struct cperf_options *opts, const char *arg)
806 : : {
807 : 0 : return parse_uint16_t(&opts->aead_iv_sz, arg);
808 : : }
809 : :
810 : : static int
811 : 0 : parse_aead_aad_sz(struct cperf_options *opts, const char *arg)
812 : : {
813 : 0 : return parse_uint16_t(&opts->aead_aad_sz, arg);
814 : : }
815 : :
816 : : static int
817 : 0 : parse_csv_friendly(struct cperf_options *opts, const char *arg __rte_unused)
818 : : {
819 : 0 : opts->csv = 1;
820 : 0 : opts->silent = 1;
821 : 0 : return 0;
822 : : }
823 : :
824 : : static int
825 : 0 : parse_pmd_cyclecount_delay_ms(struct cperf_options *opts,
826 : : const char *arg)
827 : : {
828 : 0 : int ret = parse_uint32_t(&opts->pmdcc_delay, arg);
829 : :
830 : 0 : if (ret) {
831 : 0 : RTE_LOG(ERR, USER1, "failed to parse pmd-cyclecount delay\n");
832 : 0 : return -1;
833 : : }
834 : :
835 : : return 0;
836 : : }
837 : :
838 : : typedef int (*option_parser_t)(struct cperf_options *opts,
839 : : const char *arg);
840 : :
841 : : struct long_opt_parser {
842 : : const char *lgopt_name;
843 : : option_parser_t parser_fn;
844 : :
845 : : };
846 : :
847 : : static struct option lgopts[] = {
848 : :
849 : : { CPERF_PTEST_TYPE, required_argument, 0, 0 },
850 : : { CPERF_MODEX_LEN, required_argument, 0, 0 },
851 : :
852 : : { CPERF_POOL_SIZE, required_argument, 0, 0 },
853 : : { CPERF_TOTAL_OPS, required_argument, 0, 0 },
854 : : { CPERF_BURST_SIZE, required_argument, 0, 0 },
855 : : { CPERF_BUFFER_SIZE, required_argument, 0, 0 },
856 : : { CPERF_SEGMENT_SIZE, required_argument, 0, 0 },
857 : : { CPERF_DESC_NB, required_argument, 0, 0 },
858 : :
859 : : { CPERF_IMIX, required_argument, 0, 0 },
860 : : { CPERF_DEVTYPE, required_argument, 0, 0 },
861 : : { CPERF_OPTYPE, required_argument, 0, 0 },
862 : :
863 : : { CPERF_SILENT, no_argument, 0, 0 },
864 : : { CPERF_SESSIONLESS, no_argument, 0, 0 },
865 : : { CPERF_OUT_OF_PLACE, no_argument, 0, 0 },
866 : : { CPERF_TEST_FILE, required_argument, 0, 0 },
867 : : { CPERF_TEST_NAME, required_argument, 0, 0 },
868 : :
869 : : { CPERF_CIPHER_ALGO, required_argument, 0, 0 },
870 : : { CPERF_CIPHER_OP, required_argument, 0, 0 },
871 : :
872 : : { CPERF_CIPHER_KEY_SZ, required_argument, 0, 0 },
873 : : { CPERF_CIPHER_IV_SZ, required_argument, 0, 0 },
874 : :
875 : : { CPERF_AUTH_ALGO, required_argument, 0, 0 },
876 : : { CPERF_AUTH_OP, required_argument, 0, 0 },
877 : :
878 : : { CPERF_AUTH_KEY_SZ, required_argument, 0, 0 },
879 : : { CPERF_AUTH_IV_SZ, required_argument, 0, 0 },
880 : :
881 : : { CPERF_AEAD_ALGO, required_argument, 0, 0 },
882 : : { CPERF_AEAD_OP, required_argument, 0, 0 },
883 : :
884 : : { CPERF_AEAD_KEY_SZ, required_argument, 0, 0 },
885 : : { CPERF_AEAD_AAD_SZ, required_argument, 0, 0 },
886 : : { CPERF_AEAD_IV_SZ, required_argument, 0, 0 },
887 : :
888 : : { CPERF_DIGEST_SZ, required_argument, 0, 0 },
889 : :
890 : : #ifdef RTE_LIB_SECURITY
891 : : { CPERF_PDCP_SN_SZ, required_argument, 0, 0 },
892 : : { CPERF_PDCP_DOMAIN, required_argument, 0, 0 },
893 : : { CPERF_PDCP_SES_HFN_EN, no_argument, 0, 0 },
894 : : { CPERF_ENABLE_SDAP, no_argument, 0, 0 },
895 : : { CPERF_DOCSIS_HDR_SZ, required_argument, 0, 0 },
896 : : #endif
897 : : { CPERF_CSV, no_argument, 0, 0},
898 : :
899 : : { CPERF_PMDCC_DELAY_MS, required_argument, 0, 0 },
900 : :
901 : : { NULL, 0, 0, 0 }
902 : : };
903 : :
904 : : void
905 : 0 : cperf_options_default(struct cperf_options *opts)
906 : : {
907 : 0 : opts->test = CPERF_TEST_TYPE_THROUGHPUT;
908 : :
909 : 0 : opts->pool_sz = 8192;
910 : 0 : opts->total_ops = 10000000;
911 : 0 : opts->nb_descriptors = 2048;
912 : :
913 : 0 : opts->buffer_size_list[0] = 64;
914 : 0 : opts->buffer_size_count = 1;
915 : 0 : opts->max_buffer_size = 64;
916 : 0 : opts->min_buffer_size = 64;
917 : 0 : opts->inc_buffer_size = 0;
918 : :
919 : 0 : opts->burst_size_list[0] = 32;
920 : 0 : opts->burst_size_count = 1;
921 : 0 : opts->max_burst_size = 32;
922 : 0 : opts->min_burst_size = 32;
923 : 0 : opts->inc_burst_size = 0;
924 : :
925 : : /*
926 : : * Will be parsed from command line or set to
927 : : * maximum buffer size + digest, later
928 : : */
929 : 0 : opts->segment_sz = 0;
930 : :
931 : 0 : opts->imix_distribution_count = 0;
932 : 0 : strncpy(opts->device_type, "crypto_aesni_mb",
933 : : sizeof(opts->device_type));
934 : 0 : opts->nb_qps = 1;
935 : :
936 : 0 : opts->op_type = CPERF_CIPHER_THEN_AUTH;
937 : :
938 : 0 : opts->silent = 0;
939 : 0 : opts->test_file = NULL;
940 : 0 : opts->test_name = NULL;
941 : 0 : opts->sessionless = 0;
942 : 0 : opts->out_of_place = 0;
943 : 0 : opts->csv = 0;
944 : :
945 : 0 : opts->cipher_algo = RTE_CRYPTO_CIPHER_AES_CBC;
946 : 0 : opts->cipher_op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
947 : 0 : opts->cipher_key_sz = 16;
948 : 0 : opts->cipher_iv_sz = 16;
949 : :
950 : 0 : opts->auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
951 : 0 : opts->auth_op = RTE_CRYPTO_AUTH_OP_GENERATE;
952 : :
953 : 0 : opts->auth_key_sz = 64;
954 : 0 : opts->auth_iv_sz = 0;
955 : :
956 : 0 : opts->aead_key_sz = 0;
957 : 0 : opts->aead_iv_sz = 0;
958 : 0 : opts->aead_aad_sz = 0;
959 : :
960 : 0 : opts->digest_sz = 12;
961 : :
962 : 0 : opts->pmdcc_delay = 0;
963 : : #ifdef RTE_LIB_SECURITY
964 : 0 : opts->pdcp_sn_sz = 12;
965 : 0 : opts->pdcp_domain = RTE_SECURITY_PDCP_MODE_CONTROL;
966 : 0 : opts->pdcp_ses_hfn_en = 0;
967 : 0 : opts->pdcp_sdap = 0;
968 : 0 : opts->docsis_hdr_sz = 17;
969 : : #endif
970 : 0 : opts->modex_data = (struct cperf_modex_test_data *)&modex_perf_data[0];
971 : 0 : }
972 : :
973 : : static int
974 : 0 : cperf_opts_parse_long(int opt_idx, struct cperf_options *opts)
975 : : {
976 : 0 : struct long_opt_parser parsermap[] = {
977 : : { CPERF_PTEST_TYPE, parse_cperf_test_type },
978 : : { CPERF_MODEX_LEN, parse_modex_len },
979 : : { CPERF_SILENT, parse_silent },
980 : : { CPERF_POOL_SIZE, parse_pool_sz },
981 : : { CPERF_TOTAL_OPS, parse_total_ops },
982 : : { CPERF_BURST_SIZE, parse_burst_sz },
983 : : { CPERF_BUFFER_SIZE, parse_buffer_sz },
984 : : { CPERF_SEGMENT_SIZE, parse_segment_sz },
985 : : { CPERF_DESC_NB, parse_desc_nb },
986 : : { CPERF_DEVTYPE, parse_device_type },
987 : : { CPERF_OPTYPE, parse_op_type },
988 : : { CPERF_SESSIONLESS, parse_sessionless },
989 : : { CPERF_OUT_OF_PLACE, parse_out_of_place },
990 : : { CPERF_IMIX, parse_imix },
991 : : { CPERF_TEST_FILE, parse_test_file },
992 : : { CPERF_TEST_NAME, parse_test_name },
993 : : { CPERF_CIPHER_ALGO, parse_cipher_algo },
994 : : { CPERF_CIPHER_OP, parse_cipher_op },
995 : : { CPERF_CIPHER_KEY_SZ, parse_cipher_key_sz },
996 : : { CPERF_CIPHER_IV_SZ, parse_cipher_iv_sz },
997 : : { CPERF_AUTH_ALGO, parse_auth_algo },
998 : : { CPERF_AUTH_OP, parse_auth_op },
999 : : { CPERF_AUTH_KEY_SZ, parse_auth_key_sz },
1000 : : { CPERF_AUTH_IV_SZ, parse_auth_iv_sz },
1001 : : { CPERF_AEAD_ALGO, parse_aead_algo },
1002 : : { CPERF_AEAD_OP, parse_aead_op },
1003 : : { CPERF_AEAD_KEY_SZ, parse_aead_key_sz },
1004 : : { CPERF_AEAD_IV_SZ, parse_aead_iv_sz },
1005 : : { CPERF_AEAD_AAD_SZ, parse_aead_aad_sz },
1006 : : { CPERF_DIGEST_SZ, parse_digest_sz },
1007 : : #ifdef RTE_LIB_SECURITY
1008 : : { CPERF_PDCP_SN_SZ, parse_pdcp_sn_sz },
1009 : : { CPERF_PDCP_DOMAIN, parse_pdcp_domain },
1010 : : { CPERF_PDCP_SES_HFN_EN, parse_pdcp_ses_hfn_en },
1011 : : { CPERF_ENABLE_SDAP, parse_enable_sdap },
1012 : : { CPERF_DOCSIS_HDR_SZ, parse_docsis_hdr_sz },
1013 : : #endif
1014 : : { CPERF_CSV, parse_csv_friendly},
1015 : : { CPERF_PMDCC_DELAY_MS, parse_pmd_cyclecount_delay_ms},
1016 : : };
1017 : : unsigned int i;
1018 : :
1019 : 0 : for (i = 0; i < RTE_DIM(parsermap); i++) {
1020 : 0 : if (strncmp(lgopts[opt_idx].name, parsermap[i].lgopt_name,
1021 : : strlen(lgopts[opt_idx].name)) == 0)
1022 : 0 : return parsermap[i].parser_fn(opts, optarg);
1023 : : }
1024 : :
1025 : : return -EINVAL;
1026 : : }
1027 : :
1028 : : int
1029 : 0 : cperf_options_parse(struct cperf_options *options, int argc, char **argv)
1030 : : {
1031 : : int opt, retval, opt_idx;
1032 : :
1033 : 0 : while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) {
1034 : 0 : switch (opt) {
1035 : 0 : case 'h':
1036 : 0 : usage(argv[0]);
1037 : 0 : exit(EXIT_SUCCESS);
1038 : : break;
1039 : : /* long options */
1040 : 0 : case 0:
1041 : 0 : retval = cperf_opts_parse_long(opt_idx, options);
1042 : 0 : if (retval != 0)
1043 : 0 : return retval;
1044 : :
1045 : : break;
1046 : :
1047 : 0 : default:
1048 : 0 : usage(argv[0]);
1049 : 0 : return -EINVAL;
1050 : : }
1051 : : }
1052 : :
1053 : : return 0;
1054 : : }
1055 : :
1056 : : static int
1057 : 0 : check_cipher_buffer_length(struct cperf_options *options)
1058 : : {
1059 : : uint32_t buffer_size, buffer_size_idx = 0;
1060 : :
1061 : 0 : if (options->cipher_algo == RTE_CRYPTO_CIPHER_AES_CBC ||
1062 : : options->cipher_algo == RTE_CRYPTO_CIPHER_AES_ECB) {
1063 : 0 : if (options->inc_buffer_size != 0)
1064 : 0 : buffer_size = options->min_buffer_size;
1065 : : else
1066 : 0 : buffer_size = options->buffer_size_list[0];
1067 : :
1068 : 0 : if ((options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE) &&
1069 : 0 : (options->op_type == CPERF_AUTH_THEN_CIPHER))
1070 : 0 : buffer_size += options->digest_sz;
1071 : :
1072 : 0 : while (buffer_size <= options->max_buffer_size) {
1073 : 0 : if ((buffer_size % AES_BLOCK_SIZE) != 0) {
1074 : 0 : RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
1075 : : "not suitable for the algorithm selected\n");
1076 : 0 : return -EINVAL;
1077 : : }
1078 : :
1079 : 0 : if (options->inc_buffer_size != 0)
1080 : 0 : buffer_size += options->inc_buffer_size;
1081 : : else {
1082 : 0 : if (++buffer_size_idx == options->buffer_size_count)
1083 : : break;
1084 : 0 : buffer_size = options->buffer_size_list[buffer_size_idx];
1085 : : }
1086 : :
1087 : : }
1088 : : }
1089 : :
1090 : 0 : if (options->cipher_algo == RTE_CRYPTO_CIPHER_DES_CBC ||
1091 : 0 : options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_CBC ||
1092 : : options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_ECB) {
1093 : 0 : if (options->inc_buffer_size != 0)
1094 : 0 : buffer_size = options->min_buffer_size;
1095 : : else
1096 : 0 : buffer_size = options->buffer_size_list[0];
1097 : :
1098 : 0 : if ((options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE) &&
1099 : 0 : (options->op_type == CPERF_AUTH_THEN_CIPHER))
1100 : 0 : buffer_size += options->digest_sz;
1101 : :
1102 : 0 : while (buffer_size <= options->max_buffer_size) {
1103 : 0 : if ((buffer_size % DES_BLOCK_SIZE) != 0) {
1104 : 0 : RTE_LOG(ERR, USER1, "Some of the buffer sizes are "
1105 : : "not suitable for the algorithm selected\n");
1106 : 0 : return -EINVAL;
1107 : : }
1108 : :
1109 : 0 : if (options->inc_buffer_size != 0)
1110 : 0 : buffer_size += options->inc_buffer_size;
1111 : : else {
1112 : 0 : if (++buffer_size_idx == options->buffer_size_count)
1113 : : break;
1114 : 0 : buffer_size = options->buffer_size_list[buffer_size_idx];
1115 : : }
1116 : :
1117 : : }
1118 : : }
1119 : :
1120 : : return 0;
1121 : : }
1122 : :
1123 : : #ifdef RTE_LIB_SECURITY
1124 : : static int
1125 : 0 : check_docsis_buffer_length(struct cperf_options *options)
1126 : : {
1127 : : uint32_t buffer_size, buffer_size_idx = 0;
1128 : :
1129 : 0 : if (options->inc_buffer_size != 0)
1130 : 0 : buffer_size = options->min_buffer_size;
1131 : : else
1132 : 0 : buffer_size = options->buffer_size_list[0];
1133 : :
1134 : 0 : while (buffer_size <= options->max_buffer_size) {
1135 : 0 : if (buffer_size < (uint32_t)(options->docsis_hdr_sz +
1136 : 0 : RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN)) {
1137 : 0 : RTE_LOG(ERR, USER1, "Some of the buffer sizes are not "
1138 : : "valid for DOCSIS\n");
1139 : 0 : return -EINVAL;
1140 : : }
1141 : :
1142 : 0 : if (options->inc_buffer_size != 0)
1143 : 0 : buffer_size += options->inc_buffer_size;
1144 : : else {
1145 : 0 : if (++buffer_size_idx == options->buffer_size_count)
1146 : : break;
1147 : 0 : buffer_size =
1148 : : options->buffer_size_list[buffer_size_idx];
1149 : : }
1150 : : }
1151 : :
1152 : : return 0;
1153 : : }
1154 : : #endif
1155 : :
1156 : : static bool
1157 : : is_valid_chained_op(struct cperf_options *options)
1158 : : {
1159 : 0 : if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
1160 : : options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE)
1161 : : return true;
1162 : :
1163 : 0 : if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT &&
1164 : : options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY)
1165 : : return true;
1166 : :
1167 : : return false;
1168 : : }
1169 : :
1170 : : int
1171 : 0 : cperf_options_check(struct cperf_options *options)
1172 : : {
1173 : : int i;
1174 : :
1175 : 0 : if (options->op_type == CPERF_CIPHER_ONLY ||
1176 : : options->op_type == CPERF_DOCSIS)
1177 : 0 : options->digest_sz = 0;
1178 : :
1179 : 0 : if (options->out_of_place &&
1180 : 0 : options->segment_sz <= options->max_buffer_size) {
1181 : 0 : RTE_LOG(ERR, USER1, "Out of place mode can only work "
1182 : : "with non segmented buffers\n");
1183 : 0 : return -EINVAL;
1184 : : }
1185 : :
1186 : : /*
1187 : : * If segment size is not set, assume only one segment,
1188 : : * big enough to contain the largest buffer and the digest
1189 : : */
1190 : 0 : if (options->segment_sz == 0) {
1191 : 0 : options->segment_sz = options->max_buffer_size +
1192 : 0 : options->digest_sz;
1193 : : /* In IPsec operation, packet length will be increased
1194 : : * by some bytes depend upon the algorithm, so increasing
1195 : : * the segment size by headroom to cover most of
1196 : : * the scenarios.
1197 : : */
1198 : 0 : if (options->op_type == CPERF_IPSEC)
1199 : 0 : options->segment_sz += RTE_PKTMBUF_HEADROOM;
1200 : : }
1201 : :
1202 : 0 : if (options->segment_sz < options->digest_sz) {
1203 : 0 : RTE_LOG(ERR, USER1,
1204 : : "Segment size should be at least "
1205 : : "the size of the digest\n");
1206 : 0 : return -EINVAL;
1207 : : }
1208 : :
1209 : 0 : if ((options->imix_distribution_count != 0) &&
1210 : : (options->imix_distribution_count !=
1211 : 0 : options->buffer_size_count)) {
1212 : 0 : RTE_LOG(ERR, USER1, "IMIX distribution must have the same "
1213 : : "number of buffer sizes\n");
1214 : 0 : return -EINVAL;
1215 : : }
1216 : :
1217 : 0 : if (options->test == CPERF_TEST_TYPE_VERIFY &&
1218 : 0 : options->test_file == NULL) {
1219 : 0 : RTE_LOG(ERR, USER1, "Define path to the file with test"
1220 : : " vectors.\n");
1221 : 0 : return -EINVAL;
1222 : : }
1223 : :
1224 : 0 : if (options->test == CPERF_TEST_TYPE_VERIFY &&
1225 : 0 : options->op_type != CPERF_CIPHER_ONLY &&
1226 : 0 : options->test_name == NULL) {
1227 : 0 : RTE_LOG(ERR, USER1, "Define test name to get the correct digest"
1228 : : " from the test vectors.\n");
1229 : 0 : return -EINVAL;
1230 : : }
1231 : :
1232 : 0 : if (options->test_name != NULL && options->test_file == NULL) {
1233 : 0 : RTE_LOG(ERR, USER1, "Define path to the file with test"
1234 : : " vectors.\n");
1235 : 0 : return -EINVAL;
1236 : : }
1237 : :
1238 : 0 : if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY &&
1239 : 0 : options->test_file == NULL) {
1240 : 0 : RTE_LOG(ERR, USER1, "Define path to the file with test"
1241 : : " vectors.\n");
1242 : 0 : return -EINVAL;
1243 : : }
1244 : :
1245 : 0 : if (options->test == CPERF_TEST_TYPE_VERIFY &&
1246 : 0 : (options->inc_buffer_size != 0 ||
1247 : 0 : options->buffer_size_count > 1)) {
1248 : 0 : RTE_LOG(ERR, USER1, "Only one buffer size is allowed when "
1249 : : "using the verify test.\n");
1250 : 0 : return -EINVAL;
1251 : : }
1252 : :
1253 : 0 : if (options->test == CPERF_TEST_TYPE_VERIFY &&
1254 : 0 : (options->inc_burst_size != 0 ||
1255 : 0 : options->burst_size_count > 1)) {
1256 : 0 : RTE_LOG(ERR, USER1, "Only one burst size is allowed when "
1257 : : "using the verify test.\n");
1258 : 0 : return -EINVAL;
1259 : : }
1260 : :
1261 : 0 : if (options->test == CPERF_TEST_TYPE_PMDCC &&
1262 : 0 : options->pool_sz < options->nb_descriptors) {
1263 : 0 : RTE_LOG(ERR, USER1, "For pmd cyclecount benchmarks, pool size "
1264 : : "must be equal or greater than the number of "
1265 : : "cryptodev descriptors.\n");
1266 : 0 : return -EINVAL;
1267 : : }
1268 : :
1269 : 0 : if (options->test == CPERF_TEST_TYPE_VERIFY &&
1270 : : options->imix_distribution_count > 0) {
1271 : 0 : RTE_LOG(ERR, USER1, "IMIX is not allowed when "
1272 : : "using the verify test.\n");
1273 : 0 : return -EINVAL;
1274 : : }
1275 : :
1276 : 0 : if (options->op_type == CPERF_CIPHER_THEN_AUTH ||
1277 : : options->op_type == CPERF_AUTH_THEN_CIPHER) {
1278 : : if (!is_valid_chained_op(options)) {
1279 : 0 : RTE_LOG(ERR, USER1, "Invalid chained operation.\n");
1280 : 0 : return -EINVAL;
1281 : : }
1282 : : }
1283 : :
1284 : 0 : if (options->op_type == CPERF_CIPHER_THEN_AUTH) {
1285 : 0 : if (options->cipher_op != RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
1286 : : options->auth_op !=
1287 : : RTE_CRYPTO_AUTH_OP_GENERATE) {
1288 : 0 : RTE_LOG(ERR, USER1, "Option cipher then auth must use"
1289 : : " options: encrypt and generate.\n");
1290 : 0 : return -EINVAL;
1291 : : }
1292 : : }
1293 : :
1294 : 0 : if (options->op_type == CPERF_CIPHER_ONLY ||
1295 : 0 : options->op_type == CPERF_CIPHER_THEN_AUTH ||
1296 : : options->op_type == CPERF_AUTH_THEN_CIPHER) {
1297 : 0 : if (check_cipher_buffer_length(options) < 0)
1298 : : return -EINVAL;
1299 : : }
1300 : :
1301 : 0 : if (options->modex_len) {
1302 : 0 : if (options->op_type != CPERF_ASYM_MODEX) {
1303 : 0 : RTE_LOG(ERR, USER1, "Option modex len should be used only with "
1304 : : " optype: modex.\n");
1305 : 0 : return -EINVAL;
1306 : : }
1307 : :
1308 : 0 : for (i = 0; i < (int)RTE_DIM(modex_perf_data); i++) {
1309 : 0 : if (modex_perf_data[i].modulus.len ==
1310 : : options->modex_len) {
1311 : 0 : options->modex_data =
1312 : 0 : (struct cperf_modex_test_data
1313 : : *)&modex_perf_data[i];
1314 : 0 : break;
1315 : : }
1316 : : }
1317 : 0 : if (i == (int)RTE_DIM(modex_perf_data)) {
1318 : 0 : RTE_LOG(ERR, USER1,
1319 : : "Option modex len: %d is not supported\n",
1320 : : options->modex_len);
1321 : 0 : return -EINVAL;
1322 : : }
1323 : : }
1324 : :
1325 : : #ifdef RTE_LIB_SECURITY
1326 : 0 : if (options->op_type == CPERF_DOCSIS) {
1327 : 0 : if (check_docsis_buffer_length(options) < 0)
1328 : : return -EINVAL;
1329 : : }
1330 : :
1331 : 0 : if (options->op_type == CPERF_IPSEC) {
1332 : 0 : if (options->aead_algo) {
1333 : 0 : if (options->aead_op == RTE_CRYPTO_AEAD_OP_ENCRYPT)
1334 : 0 : options->is_outbound = 1;
1335 : : else
1336 : 0 : options->is_outbound = 0;
1337 : : } else {
1338 : 0 : if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
1339 : 0 : options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE)
1340 : 0 : options->is_outbound = 1;
1341 : : else
1342 : 0 : options->is_outbound = 0;
1343 : : }
1344 : : }
1345 : : #endif
1346 : :
1347 : : return 0;
1348 : : }
1349 : :
1350 : : void
1351 : 0 : cperf_options_dump(struct cperf_options *opts)
1352 : : {
1353 : : uint8_t size_idx;
1354 : :
1355 : : printf("# Crypto Performance Application Options:\n");
1356 : : printf("#\n");
1357 : 0 : printf("# cperf test: %s\n", cperf_test_type_strs[opts->test]);
1358 : : printf("#\n");
1359 : 0 : printf("# size of crypto op / mbuf pool: %u\n", opts->pool_sz);
1360 : 0 : printf("# total number of ops: %u\n", opts->total_ops);
1361 : 0 : if (opts->inc_buffer_size != 0) {
1362 : : printf("# buffer size:\n");
1363 : 0 : printf("#\t min: %u\n", opts->min_buffer_size);
1364 : 0 : printf("#\t max: %u\n", opts->max_buffer_size);
1365 : 0 : printf("#\t inc: %u\n", opts->inc_buffer_size);
1366 : : } else {
1367 : : printf("# buffer sizes: ");
1368 : 0 : for (size_idx = 0; size_idx < opts->buffer_size_count; size_idx++)
1369 : 0 : printf("%u ", opts->buffer_size_list[size_idx]);
1370 : : printf("\n");
1371 : : }
1372 : 0 : if (opts->inc_burst_size != 0) {
1373 : : printf("# burst size:\n");
1374 : 0 : printf("#\t min: %u\n", opts->min_burst_size);
1375 : 0 : printf("#\t max: %u\n", opts->max_burst_size);
1376 : 0 : printf("#\t inc: %u\n", opts->inc_burst_size);
1377 : : } else {
1378 : : printf("# burst sizes: ");
1379 : 0 : for (size_idx = 0; size_idx < opts->burst_size_count; size_idx++)
1380 : 0 : printf("%u ", opts->burst_size_list[size_idx]);
1381 : : printf("\n");
1382 : : }
1383 : 0 : printf("\n# segment size: %u\n", opts->segment_sz);
1384 : : printf("#\n");
1385 : 0 : printf("# cryptodev type: %s\n", opts->device_type);
1386 : : printf("#\n");
1387 : 0 : printf("# number of queue pairs per device: %u\n", opts->nb_qps);
1388 : 0 : printf("# crypto operation: %s\n", cperf_op_type_strs[opts->op_type]);
1389 : 0 : printf("# sessionless: %s\n", opts->sessionless ? "yes" : "no");
1390 : 0 : printf("# out of place: %s\n", opts->out_of_place ? "yes" : "no");
1391 : 0 : if (opts->test == CPERF_TEST_TYPE_PMDCC)
1392 : 0 : printf("# inter-burst delay: %u ms\n", opts->pmdcc_delay);
1393 : :
1394 : : printf("#\n");
1395 : :
1396 : 0 : if (opts->op_type == CPERF_AUTH_ONLY ||
1397 : 0 : opts->op_type == CPERF_CIPHER_THEN_AUTH ||
1398 : : opts->op_type == CPERF_AUTH_THEN_CIPHER) {
1399 : 0 : printf("# auth algorithm: %s\n",
1400 : : rte_cryptodev_get_auth_algo_string(opts->auth_algo));
1401 : 0 : printf("# auth operation: %s\n",
1402 : 0 : rte_crypto_auth_operation_strings[opts->auth_op]);
1403 : 0 : printf("# auth key size: %u\n", opts->auth_key_sz);
1404 : 0 : printf("# auth iv size: %u\n", opts->auth_iv_sz);
1405 : 0 : printf("# auth digest size: %u\n", opts->digest_sz);
1406 : : printf("#\n");
1407 : : }
1408 : :
1409 : 0 : if (opts->op_type == CPERF_CIPHER_ONLY ||
1410 : 0 : opts->op_type == CPERF_CIPHER_THEN_AUTH ||
1411 : : opts->op_type == CPERF_AUTH_THEN_CIPHER) {
1412 : 0 : printf("# cipher algorithm: %s\n",
1413 : : rte_cryptodev_get_cipher_algo_string(opts->cipher_algo));
1414 : 0 : printf("# cipher operation: %s\n",
1415 : 0 : rte_crypto_cipher_operation_strings[opts->cipher_op]);
1416 : 0 : printf("# cipher key size: %u\n", opts->cipher_key_sz);
1417 : 0 : printf("# cipher iv size: %u\n", opts->cipher_iv_sz);
1418 : : printf("#\n");
1419 : : }
1420 : :
1421 : 0 : if (opts->op_type == CPERF_AEAD) {
1422 : 0 : printf("# aead algorithm: %s\n",
1423 : : rte_cryptodev_get_aead_algo_string(opts->aead_algo));
1424 : 0 : printf("# aead operation: %s\n",
1425 : 0 : rte_crypto_aead_operation_strings[opts->aead_op]);
1426 : 0 : printf("# aead key size: %u\n", opts->aead_key_sz);
1427 : 0 : printf("# aead iv size: %u\n", opts->aead_iv_sz);
1428 : 0 : printf("# aead digest size: %u\n", opts->digest_sz);
1429 : 0 : printf("# aead aad size: %u\n", opts->aead_aad_sz);
1430 : : printf("#\n");
1431 : : }
1432 : :
1433 : : #ifdef RTE_LIB_SECURITY
1434 : 0 : if (opts->op_type == CPERF_DOCSIS) {
1435 : 0 : printf("# docsis header size: %u\n", opts->docsis_hdr_sz);
1436 : : printf("#\n");
1437 : : }
1438 : : #endif
1439 : 0 : }
|