4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <rte_malloc.h>
35 #include "rte_cryptodev_vdev.h"
36 #include "rte_cryptodev_pmd.h"
39 * Parse name from argument
42 rte_cryptodev_vdev_parse_name_arg(const char *key __rte_unused,
43 const char *value, void *extra_args)
45 struct rte_crypto_vdev_init_params *params = extra_args;
47 if (strlen(value) >= RTE_CRYPTODEV_NAME_MAX_LEN - 1) {
48 CDEV_LOG_ERR("Invalid name %s, should be less than "
50 RTE_CRYPTODEV_NAME_MAX_LEN - 1);
54 strncpy(params->name, value, RTE_CRYPTODEV_NAME_MAX_LEN);
60 * Parse integer from argument
63 rte_cryptodev_vdev_parse_integer_arg(const char *key __rte_unused,
64 const char *value, void *extra_args)
70 CDEV_LOG_ERR("Argument has to be positive.");
77 struct rte_cryptodev *
78 rte_cryptodev_vdev_pmd_init(const char *name, size_t dev_private_size,
79 int socket_id, struct rte_vdev_device *vdev)
81 struct rte_cryptodev *cryptodev;
83 /* allocate device structure */
84 cryptodev = rte_cryptodev_pmd_allocate(name, socket_id);
85 if (cryptodev == NULL)
88 /* allocate private device structure */
89 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
90 cryptodev->data->dev_private =
91 rte_zmalloc_socket("cryptodev device private",
96 if (cryptodev->data->dev_private == NULL)
97 rte_panic("Cannot allocate memzone for private device"
101 cryptodev->device = &vdev->device;
103 /* initialise user call-back tail queue */
104 TAILQ_INIT(&(cryptodev->link_intr_cbs));
110 rte_cryptodev_vdev_parse_init_params(struct rte_crypto_vdev_init_params *params,
111 const char *input_args)
113 struct rte_kvargs *kvlist = NULL;
120 kvlist = rte_kvargs_parse(input_args,
121 cryptodev_vdev_valid_params);
125 ret = rte_kvargs_process(kvlist,
126 RTE_CRYPTODEV_VDEV_MAX_NB_QP_ARG,
127 &rte_cryptodev_vdev_parse_integer_arg,
128 ¶ms->max_nb_queue_pairs);
132 ret = rte_kvargs_process(kvlist,
133 RTE_CRYPTODEV_VDEV_MAX_NB_SESS_ARG,
134 &rte_cryptodev_vdev_parse_integer_arg,
135 ¶ms->max_nb_sessions);
139 ret = rte_kvargs_process(kvlist, RTE_CRYPTODEV_VDEV_SOCKET_ID,
140 &rte_cryptodev_vdev_parse_integer_arg,
145 ret = rte_kvargs_process(kvlist, RTE_CRYPTODEV_VDEV_NAME,
146 &rte_cryptodev_vdev_parse_name_arg,
153 rte_kvargs_free(kvlist);