4 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
5 * Copyright (c) 2016 NXP. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Freescale Semiconductor, Inc nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <rte_cryptodev.h>
39 #include <rte_malloc.h>
40 #include <rte_memcpy.h>
41 #include <rte_string_fns.h>
42 #include <rte_cycles.h>
43 #include <rte_kvargs.h>
45 #include <rte_cryptodev_pmd.h>
46 #include <rte_common.h>
47 #include <rte_fslmc.h>
48 #include <fslmc_vfio.h>
49 #include <dpaa2_hw_pvt.h>
50 #include <dpaa2_hw_dpio.h>
52 #include "dpaa2_sec_priv.h"
53 #include "dpaa2_sec_logs.h"
55 #define FSL_VENDOR_ID 0x1957
56 #define FSL_DEVICE_ID 0x410
57 #define FSL_SUBSYSTEM_SEC 1
58 #define FSL_MC_DPSECI_DEVID 3
61 dpaa2_sec_uninit(const struct rte_cryptodev_driver *crypto_drv __rte_unused,
62 struct rte_cryptodev *dev)
64 PMD_INIT_LOG(INFO, "Closing DPAA2_SEC device %s on numa socket %u\n",
65 dev->data->name, rte_socket_id());
71 dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
73 struct dpaa2_sec_dev_private *internals;
74 struct rte_device *dev = cryptodev->device;
75 struct rte_dpaa2_device *dpaa2_dev;
77 PMD_INIT_FUNC_TRACE();
78 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
79 if (dpaa2_dev == NULL) {
80 PMD_INIT_LOG(ERR, "dpaa2_device not found\n");
84 cryptodev->dev_type = RTE_CRYPTODEV_DPAA2_SEC_PMD;
86 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
87 RTE_CRYPTODEV_FF_HW_ACCELERATED |
88 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING;
90 internals = cryptodev->data->dev_private;
91 internals->max_nb_sessions = RTE_DPAA2_SEC_PMD_MAX_NB_SESSIONS;
94 * For secondary processes, we don't initialise any further as primary
95 * has already done this work. Only check we don't need a different
98 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
99 PMD_INIT_LOG(DEBUG, "Device already init by primary process");
103 PMD_INIT_LOG(DEBUG, "driver %s: created\n", cryptodev->data->name);
108 cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv,
109 struct rte_dpaa2_device *dpaa2_dev)
111 struct rte_cryptodev *cryptodev;
112 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
116 sprintf(cryptodev_name, "dpsec-%d", dpaa2_dev->object_id);
118 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
119 if (cryptodev == NULL)
122 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
123 cryptodev->data->dev_private = rte_zmalloc_socket(
124 "cryptodev private structure",
125 sizeof(struct dpaa2_sec_dev_private),
129 if (cryptodev->data->dev_private == NULL)
130 rte_panic("Cannot allocate memzone for private "
134 dpaa2_dev->cryptodev = cryptodev;
135 cryptodev->device = &dpaa2_dev->device;
136 cryptodev->driver = (struct rte_cryptodev_driver *)dpaa2_drv;
138 /* init user callbacks */
139 TAILQ_INIT(&(cryptodev->link_intr_cbs));
141 /* Invoke PMD device initialization function */
142 retval = dpaa2_sec_dev_init(cryptodev);
146 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
147 rte_free(cryptodev->data->dev_private);
149 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
155 cryptodev_dpaa2_sec_remove(struct rte_dpaa2_device *dpaa2_dev)
157 struct rte_cryptodev *cryptodev;
160 cryptodev = dpaa2_dev->cryptodev;
161 if (cryptodev == NULL)
164 ret = dpaa2_sec_uninit(NULL, cryptodev);
168 /* free crypto device */
169 rte_cryptodev_pmd_release_device(cryptodev);
171 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
172 rte_free(cryptodev->data->dev_private);
174 cryptodev->device = NULL;
175 cryptodev->driver = NULL;
176 cryptodev->data = NULL;
181 static struct rte_dpaa2_driver rte_dpaa2_sec_driver = {
182 .drv_type = DPAA2_MC_DPSECI_DEVID,
184 .name = "DPAA2 SEC PMD"
186 .probe = cryptodev_dpaa2_sec_probe,
187 .remove = cryptodev_dpaa2_sec_remove,
190 RTE_PMD_REGISTER_DPAA2(dpaa2_sec_pmd, rte_dpaa2_sec_driver);