1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
5 #include <rte_string_fns.h>
6 #include <rte_malloc.h>
8 #include "rte_cryptodev_pmd.h"
11 * Parse name from argument
14 rte_cryptodev_pmd_parse_name_arg(const char *key __rte_unused,
15 const char *value, void *extra_args)
17 struct rte_cryptodev_pmd_init_params *params = extra_args;
20 n = strlcpy(params->name, value, RTE_CRYPTODEV_NAME_MAX_LEN);
21 if (n >= RTE_CRYPTODEV_NAME_MAX_LEN)
28 * Parse unsigned integer from argument
31 rte_cryptodev_pmd_parse_uint_arg(const char *key __rte_unused,
32 const char *value, void *extra_args)
38 i = strtol(value, &end, 10);
39 if (*end != 0 || errno != 0 || i < 0)
42 *((uint32_t *)extra_args) = i;
47 rte_cryptodev_pmd_parse_input_args(
48 struct rte_cryptodev_pmd_init_params *params,
51 struct rte_kvargs *kvlist = NULL;
58 kvlist = rte_kvargs_parse(args, cryptodev_pmd_valid_params);
62 ret = rte_kvargs_process(kvlist,
63 RTE_CRYPTODEV_PMD_MAX_NB_QP_ARG,
64 &rte_cryptodev_pmd_parse_uint_arg,
65 ¶ms->max_nb_queue_pairs);
69 ret = rte_kvargs_process(kvlist,
70 RTE_CRYPTODEV_PMD_SOCKET_ID_ARG,
71 &rte_cryptodev_pmd_parse_uint_arg,
76 ret = rte_kvargs_process(kvlist,
77 RTE_CRYPTODEV_PMD_NAME_ARG,
78 &rte_cryptodev_pmd_parse_name_arg,
85 rte_kvargs_free(kvlist);
89 struct rte_cryptodev *
90 rte_cryptodev_pmd_create(const char *name,
91 struct rte_device *device,
92 struct rte_cryptodev_pmd_init_params *params)
94 struct rte_cryptodev *cryptodev;
96 if (params->name[0] != '\0') {
97 CDEV_LOG_INFO("User specified device name = %s\n", params->name);
101 CDEV_LOG_INFO("Creating cryptodev %s\n", name);
103 CDEV_LOG_INFO("Initialisation parameters - name: %s,"
104 "socket id: %d, max queue pairs: %u",
105 name, params->socket_id, params->max_nb_queue_pairs);
107 /* allocate device structure */
108 cryptodev = rte_cryptodev_pmd_allocate(name, params->socket_id);
109 if (cryptodev == NULL) {
110 CDEV_LOG_ERR("Failed to allocate crypto device for %s", name);
114 /* allocate private device structure */
115 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
116 cryptodev->data->dev_private =
117 rte_zmalloc_socket("cryptodev device private",
118 params->private_data_size,
122 if (cryptodev->data->dev_private == NULL) {
123 CDEV_LOG_ERR("Cannot allocate memory for cryptodev %s"
124 " private data", name);
126 rte_cryptodev_pmd_release_device(cryptodev);
131 cryptodev->device = device;
133 /* initialise user call-back tail queue */
134 TAILQ_INIT(&(cryptodev->link_intr_cbs));
140 rte_cryptodev_pmd_destroy(struct rte_cryptodev *cryptodev)
144 CDEV_LOG_INFO("Closing crypto device %s", cryptodev->device->name);
146 /* free crypto device */
147 retval = rte_cryptodev_pmd_release_device(cryptodev);
151 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
152 rte_free(cryptodev->data->dev_private);
155 cryptodev->device = NULL;
156 cryptodev->data = NULL;