app/testpmd: fix uninitialized members when setting PFC
[dpdk.git] / app / test-crypto-perf / cperf_options_parsing.c
index ad43e84..f43c5be 100644 (file)
@@ -1,33 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2016-2017 Intel Corporation
  */
 
 #include <getopt.h>
@@ -57,6 +29,7 @@ usage(char *progname)
                " --total-ops N: set the number of total operations performed\n"
                " --burst-sz N: set the number of packets per burst\n"
                " --buffer-sz N: set the size of a single packet\n"
+               " --imix N: set the distribution of packet sizes\n"
                " --segment-sz N: set the size of the segment to use\n"
                " --desc-nb N: set number of descriptors for each crypto device\n"
                " --devtype TYPE: set crypto device type to use\n"
@@ -243,6 +216,8 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
        char *token;
        uint32_t number;
        uint8_t count = 0;
+       uint32_t temp_min;
+       uint32_t temp_max;
 
        char *copy_arg = strdup(arg);
 
@@ -261,8 +236,8 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
                        goto err_list;
 
                list[count++] = number;
-               *min = number;
-               *max = number;
+               temp_min = number;
+               temp_max = number;
        } else
                goto err_list;
 
@@ -283,14 +258,19 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max)
 
                list[count++] = number;
 
-               if (number < *min)
-                       *min = number;
-               if (number > *max)
-                       *max = number;
+               if (number < temp_min)
+                       temp_min = number;
+               if (number > temp_max)
+                       temp_max = number;
 
                token = strtok(NULL, ",");
        }
 
+       if (min)
+               *min = temp_min;
+       if (max)
+               *max = temp_max;
+
        free(copy_arg);
        return count;
 
@@ -386,6 +366,29 @@ parse_segment_sz(struct cperf_options *opts, const char *arg)
        return 0;
 }
 
+static int
+parse_imix(struct cperf_options *opts, const char *arg)
+{
+       int ret;
+
+       ret = parse_list(arg, opts->imix_distribution_list,
+                               NULL, NULL);
+       if (ret < 0) {
+               RTE_LOG(ERR, USER1, "failed to parse imix distribution\n");
+               return -1;
+       }
+
+       opts->imix_distribution_count = ret;
+
+       if (opts->imix_distribution_count <= 1) {
+               RTE_LOG(ERR, USER1, "imix distribution should have "
+                               "at least two entries\n");
+               return -1;
+       }
+
+       return 0;
+}
+
 static int
 parse_desc_nb(struct cperf_options *opts, const char *arg)
 {
@@ -439,6 +442,10 @@ parse_op_type(struct cperf_options *opts, const char *arg)
                {
                        cperf_op_type_strs[CPERF_AEAD],
                        CPERF_AEAD
+               },
+               {
+                       cperf_op_type_strs[CPERF_PDCP],
+                       CPERF_PDCP
                }
        };
 
@@ -613,6 +620,63 @@ parse_digest_sz(struct cperf_options *opts, const char *arg)
        return parse_uint16_t(&opts->digest_sz, arg);
 }
 
+#ifdef RTE_LIBRTE_SECURITY
+static int
+parse_pdcp_sn_sz(struct cperf_options *opts, const char *arg)
+{
+       uint32_t val = 0;
+       int ret = parse_uint32_t(&val, arg);
+
+       if (ret < 0)
+               return ret;
+
+       if (val != RTE_SECURITY_PDCP_SN_SIZE_5 &&
+                       val != RTE_SECURITY_PDCP_SN_SIZE_7 &&
+                       val != RTE_SECURITY_PDCP_SN_SIZE_12 &&
+                       val != RTE_SECURITY_PDCP_SN_SIZE_15 &&
+                       val != RTE_SECURITY_PDCP_SN_SIZE_18) {
+               printf("\nInvalid pdcp SN size: %u\n", val);
+               return -ERANGE;
+       }
+       opts->pdcp_sn_sz = val;
+
+       return 0;
+}
+
+const char *cperf_pdcp_domain_strs[] = {
+       [RTE_SECURITY_PDCP_MODE_CONTROL] = "control",
+       [RTE_SECURITY_PDCP_MODE_DATA] = "data"
+};
+
+static int
+parse_pdcp_domain(struct cperf_options *opts, const char *arg)
+{
+       struct name_id_map pdcp_domain_namemap[] = {
+               {
+                       cperf_pdcp_domain_strs
+                       [RTE_SECURITY_PDCP_MODE_CONTROL],
+                       RTE_SECURITY_PDCP_MODE_CONTROL },
+               {
+                       cperf_pdcp_domain_strs
+                       [RTE_SECURITY_PDCP_MODE_DATA],
+                       RTE_SECURITY_PDCP_MODE_DATA
+               }
+       };
+
+       int id = get_str_key_id_mapping(pdcp_domain_namemap,
+                       RTE_DIM(pdcp_domain_namemap), arg);
+       if (id < 0) {
+               RTE_LOG(ERR, USER1, "invalid pdcp domain specified"
+                               "\n");
+               return -1;
+       }
+
+       opts->pdcp_domain = (enum rte_security_pdcp_domain)id;
+
+       return 0;
+}
+#endif
+
 static int
 parse_auth_iv_sz(struct cperf_options *opts, const char *arg)
 {
@@ -722,6 +786,7 @@ static struct option lgopts[] = {
        { CPERF_SEGMENT_SIZE, required_argument, 0, 0 },
        { CPERF_DESC_NB, required_argument, 0, 0 },
 
+       { CPERF_IMIX, required_argument, 0, 0 },
        { CPERF_DEVTYPE, required_argument, 0, 0 },
        { CPERF_OPTYPE, required_argument, 0, 0 },
 
@@ -752,6 +817,10 @@ static struct option lgopts[] = {
 
        { CPERF_DIGEST_SZ, required_argument, 0, 0 },
 
+#ifdef RTE_LIBRTE_SECURITY
+       { CPERF_PDCP_SN_SZ, required_argument, 0, 0 },
+       { CPERF_PDCP_DOMAIN, required_argument, 0, 0 },
+#endif
        { CPERF_CSV, no_argument, 0, 0},
 
        { CPERF_PMDCC_DELAY_MS, required_argument, 0, 0 },
@@ -786,6 +855,7 @@ cperf_options_default(struct cperf_options *opts)
         */
        opts->segment_sz = 0;
 
+       opts->imix_distribution_count = 0;
        strncpy(opts->device_type, "crypto_aesni_mb",
                        sizeof(opts->device_type));
        opts->nb_qps = 1;
@@ -817,6 +887,10 @@ cperf_options_default(struct cperf_options *opts)
        opts->digest_sz = 12;
 
        opts->pmdcc_delay = 0;
+#ifdef RTE_LIBRTE_SECURITY
+       opts->pdcp_sn_sz = 12;
+       opts->pdcp_domain = RTE_SECURITY_PDCP_MODE_CONTROL;
+#endif
 }
 
 static int
@@ -835,6 +909,7 @@ cperf_opts_parse_long(int opt_idx, struct cperf_options *opts)
                { CPERF_OPTYPE,         parse_op_type },
                { CPERF_SESSIONLESS,    parse_sessionless },
                { CPERF_OUT_OF_PLACE,   parse_out_of_place },
+               { CPERF_IMIX,           parse_imix },
                { CPERF_TEST_FILE,      parse_test_file },
                { CPERF_TEST_NAME,      parse_test_name },
                { CPERF_CIPHER_ALGO,    parse_cipher_algo },
@@ -851,6 +926,10 @@ cperf_opts_parse_long(int opt_idx, struct cperf_options *opts)
                { CPERF_AEAD_IV_SZ,     parse_aead_iv_sz },
                { CPERF_AEAD_AAD_SZ,    parse_aead_aad_sz },
                { CPERF_DIGEST_SZ,      parse_digest_sz },
+#ifdef RTE_LIBRTE_SECURITY
+               { CPERF_PDCP_SN_SZ,     parse_pdcp_sn_sz },
+               { CPERF_PDCP_DOMAIN,    parse_pdcp_domain },
+#endif
                { CPERF_CSV,            parse_csv_friendly},
                { CPERF_PMDCC_DELAY_MS, parse_pmd_cyclecount_delay_ms},
        };
@@ -958,6 +1037,13 @@ cperf_options_check(struct cperf_options *options)
        if (options->op_type == CPERF_CIPHER_ONLY)
                options->digest_sz = 0;
 
+       if (options->out_of_place &&
+                       options->segment_sz <= options->max_buffer_size) {
+               RTE_LOG(ERR, USER1, "Out of place mode can only work "
+                                       "with non segmented buffers\n");
+               return -EINVAL;
+       }
+
        /*
         * If segment size is not set, assume only one segment,
         * big enough to contain the largest buffer and the digest
@@ -973,6 +1059,14 @@ cperf_options_check(struct cperf_options *options)
                return -EINVAL;
        }
 
+       if ((options->imix_distribution_count != 0) &&
+                       (options->imix_distribution_count !=
+                               options->buffer_size_count)) {
+               RTE_LOG(ERR, USER1, "IMIX distribution must have the same "
+                               "number of buffer sizes\n");
+               return -EINVAL;
+       }
+
        if (options->test == CPERF_TEST_TYPE_VERIFY &&
                        options->test_file == NULL) {
                RTE_LOG(ERR, USER1, "Define path to the file with test"
@@ -1025,6 +1119,13 @@ cperf_options_check(struct cperf_options *options)
                return -EINVAL;
        }
 
+       if (options->test == CPERF_TEST_TYPE_VERIFY &&
+                       options->imix_distribution_count > 0) {
+               RTE_LOG(ERR, USER1, "IMIX is not allowed when "
+                               "using the verify test.\n");
+               return -EINVAL;
+       }
+
        if (options->op_type == CPERF_CIPHER_THEN_AUTH) {
                if (options->cipher_op != RTE_CRYPTO_CIPHER_OP_ENCRYPT &&
                                options->auth_op !=