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;
108 rte_cryptodev_vdev_parse_init_params(struct rte_crypto_vdev_init_params *params,
109 const char *input_args)
111 struct rte_kvargs *kvlist = NULL;
118 kvlist = rte_kvargs_parse(input_args,
119 cryptodev_vdev_valid_params);
123 ret = rte_kvargs_process(kvlist,
124 RTE_CRYPTODEV_VDEV_MAX_NB_QP_ARG,
125 &rte_cryptodev_vdev_parse_integer_arg,
126 ¶ms->max_nb_queue_pairs);
130 ret = rte_kvargs_process(kvlist,
131 RTE_CRYPTODEV_VDEV_MAX_NB_SESS_ARG,
132 &rte_cryptodev_vdev_parse_integer_arg,
133 ¶ms->max_nb_sessions);
137 ret = rte_kvargs_process(kvlist, RTE_CRYPTODEV_VDEV_SOCKET_ID,
138 &rte_cryptodev_vdev_parse_integer_arg,
143 ret = rte_kvargs_process(kvlist, RTE_CRYPTODEV_VDEV_NAME,
144 &rte_cryptodev_vdev_parse_name_arg,
151 rte_kvargs_free(kvlist);
156 rte_cryptodev_pci_generic_probe(struct rte_pci_device *pci_dev,
157 size_t private_data_size,
158 cryptodev_pci_init_t dev_init)
160 struct rte_cryptodev *cryptodev;
162 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
166 rte_pci_device_name(&pci_dev->addr, cryptodev_name,
167 sizeof(cryptodev_name));
169 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
170 if (cryptodev == NULL)
173 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
174 cryptodev->data->dev_private =
176 "cryptodev private structure",
181 if (cryptodev->data->dev_private == NULL)
182 rte_panic("Cannot allocate memzone for private "
186 cryptodev->device = &pci_dev->device;
188 /* Invoke PMD device initialization function */
189 RTE_FUNC_PTR_OR_ERR_RET(*dev_init, -EINVAL);
190 retval = dev_init(cryptodev);
194 CDEV_LOG_ERR("driver %s: crypto_dev_init(vendor_id=0x%x device_id=0x%x)"
195 " failed", pci_dev->device.driver->name,
196 (unsigned int) pci_dev->id.vendor_id,
197 (unsigned int) pci_dev->id.device_id);
199 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
200 rte_free(cryptodev->data->dev_private);
202 /* free crypto device */
203 rte_cryptodev_pmd_release_device(cryptodev);
209 rte_cryptodev_pci_generic_remove(struct rte_pci_device *pci_dev,
210 cryptodev_pci_uninit_t dev_uninit)
212 struct rte_cryptodev *cryptodev;
213 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
219 rte_pci_device_name(&pci_dev->addr, cryptodev_name,
220 sizeof(cryptodev_name));
222 cryptodev = rte_cryptodev_pmd_get_named_dev(cryptodev_name);
223 if (cryptodev == NULL)
226 /* Invoke PMD device uninit function */
228 ret = dev_uninit(cryptodev);
233 /* free crypto device */
234 rte_cryptodev_pmd_release_device(cryptodev);
236 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
237 rte_free(cryptodev->data->dev_private);
239 cryptodev->device = NULL;
240 cryptodev->data = NULL;