4 * Copyright(c) 2015-2017 Intel Corporation. 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 Intel Corporation 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.
34 #include <rte_bus_pci.h>
35 #include <rte_common.h>
37 #include <rte_malloc.h>
39 #include <rte_cryptodev_pmd.h>
41 #include "qat_crypto.h"
44 uint8_t cryptodev_qat_driver_id;
46 static const struct rte_cryptodev_capabilities qat_gen1_capabilities[] = {
47 QAT_BASE_GEN1_SYM_CAPABILITIES,
48 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
51 static const struct rte_cryptodev_capabilities qat_gen2_capabilities[] = {
52 QAT_BASE_GEN1_SYM_CAPABILITIES,
53 QAT_EXTRA_GEN2_SYM_CAPABILITIES,
54 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
57 static struct rte_cryptodev_ops crypto_qat_ops = {
59 /* Device related operations */
60 .dev_configure = qat_dev_config,
61 .dev_start = qat_dev_start,
62 .dev_stop = qat_dev_stop,
63 .dev_close = qat_dev_close,
64 .dev_infos_get = qat_dev_info_get,
66 .stats_get = qat_crypto_sym_stats_get,
67 .stats_reset = qat_crypto_sym_stats_reset,
68 .queue_pair_setup = qat_crypto_sym_qp_setup,
69 .queue_pair_release = qat_crypto_sym_qp_release,
70 .queue_pair_start = NULL,
71 .queue_pair_stop = NULL,
72 .queue_pair_count = NULL,
74 /* Crypto related operations */
75 .session_get_size = qat_crypto_sym_get_session_private_size,
76 .session_configure = qat_crypto_sym_configure_session,
77 .session_clear = qat_crypto_sym_clear_session
81 * The set of PCI devices this driver supports
84 static const struct rte_pci_id pci_id_qat_map[] = {
86 RTE_PCI_DEVICE(0x8086, 0x0443),
89 RTE_PCI_DEVICE(0x8086, 0x37c9),
92 RTE_PCI_DEVICE(0x8086, 0x19e3),
95 RTE_PCI_DEVICE(0x8086, 0x6f55),
101 crypto_qat_create(const char *name, struct rte_pci_device *pci_dev,
102 struct rte_cryptodev_pmd_init_params *init_params)
104 struct rte_cryptodev *cryptodev;
105 struct qat_pmd_private *internals;
107 PMD_INIT_FUNC_TRACE();
109 cryptodev = rte_cryptodev_pmd_create(name, &pci_dev->device,
111 if (cryptodev == NULL)
114 cryptodev->driver_id = cryptodev_qat_driver_id;
115 cryptodev->dev_ops = &crypto_qat_ops;
117 cryptodev->enqueue_burst = qat_pmd_enqueue_op_burst;
118 cryptodev->dequeue_burst = qat_pmd_dequeue_op_burst;
120 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
121 RTE_CRYPTODEV_FF_HW_ACCELERATED |
122 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
123 RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER;
125 internals = cryptodev->data->dev_private;
126 internals->max_nb_sessions = init_params->max_nb_sessions;
127 switch (pci_dev->id.device_id) {
129 internals->qat_dev_gen = QAT_GEN1;
130 internals->qat_dev_capabilities = qat_gen1_capabilities;
135 internals->qat_dev_gen = QAT_GEN2;
136 internals->qat_dev_capabilities = qat_gen2_capabilities;
140 "Invalid dev_id, can't determine capabilities");
145 * For secondary processes, we don't initialise any further as primary
146 * has already done this work. Only check we don't need a different
149 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
150 PMD_DRV_LOG(DEBUG, "Device already initialised by primary process");
157 static int crypto_qat_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
158 struct rte_pci_device *pci_dev)
160 struct rte_cryptodev_pmd_init_params init_params = {
162 .socket_id = rte_socket_id(),
163 .private_data_size = sizeof(struct qat_pmd_private),
164 .max_nb_sessions = RTE_QAT_PMD_MAX_NB_SESSIONS
166 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
168 PMD_DRV_LOG(DEBUG, "Found QAT device at %02x:%02x.%x",
171 pci_dev->addr.function);
173 rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
175 return crypto_qat_create(name, pci_dev, &init_params);
178 static int crypto_qat_pci_remove(struct rte_pci_device *pci_dev)
180 struct rte_cryptodev *cryptodev;
181 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
186 rte_pci_device_name(&pci_dev->addr, cryptodev_name,
187 sizeof(cryptodev_name));
189 cryptodev = rte_cryptodev_pmd_get_named_dev(cryptodev_name);
190 if (cryptodev == NULL)
193 /* free crypto device */
194 return rte_cryptodev_pmd_destroy(cryptodev);
197 static struct rte_pci_driver rte_qat_pmd = {
198 .id_table = pci_id_qat_map,
199 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
200 .probe = crypto_qat_pci_probe,
201 .remove = crypto_qat_pci_remove
204 static struct cryptodev_driver qat_crypto_drv;
206 RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_QAT_SYM_PMD, rte_qat_pmd);
207 RTE_PMD_REGISTER_PCI_TABLE(CRYPTODEV_NAME_QAT_SYM_PMD, pci_id_qat_map);
208 RTE_PMD_REGISTER_CRYPTO_DRIVER(qat_crypto_drv, rte_qat_pmd,
209 cryptodev_qat_driver_id);