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_pci.h"
37 #include "rte_cryptodev_pmd.h"
40 * Parse name from argument
43 rte_cryptodev_vdev_parse_name_arg(const char *key __rte_unused,
44 const char *value, void *extra_args)
46 struct rte_crypto_vdev_init_params *params = extra_args;
48 if (strlen(value) >= RTE_CRYPTODEV_NAME_MAX_LEN - 1) {
49 CDEV_LOG_ERR("Invalid name %s, should be less than "
51 RTE_CRYPTODEV_NAME_MAX_LEN - 1);
55 strncpy(params->name, value, RTE_CRYPTODEV_NAME_MAX_LEN);
61 * Parse integer from argument
64 rte_cryptodev_vdev_parse_integer_arg(const char *key __rte_unused,
65 const char *value, void *extra_args)
71 CDEV_LOG_ERR("Argument has to be positive.");
78 struct rte_cryptodev *
79 rte_cryptodev_vdev_pmd_init(const char *name, size_t dev_private_size,
80 int socket_id, struct rte_vdev_device *vdev)
82 struct rte_cryptodev *cryptodev;
84 /* allocate device structure */
85 cryptodev = rte_cryptodev_pmd_allocate(name, socket_id);
86 if (cryptodev == NULL)
89 /* allocate private device structure */
90 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
91 cryptodev->data->dev_private =
92 rte_zmalloc_socket("cryptodev device private",
97 if (cryptodev->data->dev_private == NULL)
98 rte_panic("Cannot allocate memzone for private device"
102 cryptodev->device = &vdev->device;
104 /* initialise user call-back tail queue */
105 TAILQ_INIT(&(cryptodev->link_intr_cbs));
111 rte_cryptodev_vdev_parse_init_params(struct rte_crypto_vdev_init_params *params,
112 const char *input_args)
114 struct rte_kvargs *kvlist = NULL;
121 kvlist = rte_kvargs_parse(input_args,
122 cryptodev_vdev_valid_params);
126 ret = rte_kvargs_process(kvlist,
127 RTE_CRYPTODEV_VDEV_MAX_NB_QP_ARG,
128 &rte_cryptodev_vdev_parse_integer_arg,
129 ¶ms->max_nb_queue_pairs);
133 ret = rte_kvargs_process(kvlist,
134 RTE_CRYPTODEV_VDEV_MAX_NB_SESS_ARG,
135 &rte_cryptodev_vdev_parse_integer_arg,
136 ¶ms->max_nb_sessions);
140 ret = rte_kvargs_process(kvlist, RTE_CRYPTODEV_VDEV_SOCKET_ID,
141 &rte_cryptodev_vdev_parse_integer_arg,
146 ret = rte_kvargs_process(kvlist, RTE_CRYPTODEV_VDEV_NAME,
147 &rte_cryptodev_vdev_parse_name_arg,
154 rte_kvargs_free(kvlist);
159 rte_cryptodev_pci_generic_probe(struct rte_pci_device *pci_dev,
160 size_t private_data_size,
161 cryptodev_pci_init_t dev_init)
163 struct rte_cryptodev *cryptodev;
165 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
169 rte_pci_device_name(&pci_dev->addr, cryptodev_name,
170 sizeof(cryptodev_name));
172 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
173 if (cryptodev == NULL)
176 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
177 cryptodev->data->dev_private =
179 "cryptodev private structure",
184 if (cryptodev->data->dev_private == NULL)
185 rte_panic("Cannot allocate memzone for private "
189 cryptodev->device = &pci_dev->device;
191 /* init user callbacks */
192 TAILQ_INIT(&(cryptodev->link_intr_cbs));
194 /* Invoke PMD device initialization function */
195 RTE_FUNC_PTR_OR_ERR_RET(*dev_init, -EINVAL);
196 retval = dev_init(cryptodev);
200 CDEV_LOG_ERR("driver %s: crypto_dev_init(vendor_id=0x%x device_id=0x%x)"
201 " failed", pci_dev->device.driver->name,
202 (unsigned int) pci_dev->id.vendor_id,
203 (unsigned int) pci_dev->id.device_id);
205 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
206 rte_free(cryptodev->data->dev_private);
208 /* free crypto device */
209 rte_cryptodev_pmd_release_device(cryptodev);
215 rte_cryptodev_pci_generic_remove(struct rte_pci_device *pci_dev,
216 cryptodev_pci_uninit_t dev_uninit)
218 struct rte_cryptodev *cryptodev;
219 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
225 rte_pci_device_name(&pci_dev->addr, cryptodev_name,
226 sizeof(cryptodev_name));
228 cryptodev = rte_cryptodev_pmd_get_named_dev(cryptodev_name);
229 if (cryptodev == NULL)
232 /* Invoke PMD device uninit function */
234 ret = dev_uninit(cryptodev);
239 /* free crypto device */
240 rte_cryptodev_pmd_release_device(cryptodev);
242 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
243 rte_free(cryptodev->data->dev_private);
245 cryptodev->device = NULL;
246 cryptodev->data = NULL;