1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2017 Intel Corporation
5 #include <rte_bus_pci.h>
6 #include <rte_common.h>
8 #include <rte_malloc.h>
10 #include <rte_cryptodev_pmd.h>
12 #include "qat_crypto.h"
15 uint8_t cryptodev_qat_driver_id;
17 static const struct rte_cryptodev_capabilities qat_gen1_capabilities[] = {
18 QAT_BASE_GEN1_SYM_CAPABILITIES,
19 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
22 static const struct rte_cryptodev_capabilities qat_gen2_capabilities[] = {
23 QAT_BASE_GEN1_SYM_CAPABILITIES,
24 QAT_EXTRA_GEN2_SYM_CAPABILITIES,
25 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
28 static struct rte_cryptodev_ops crypto_qat_ops = {
30 /* Device related operations */
31 .dev_configure = qat_dev_config,
32 .dev_start = qat_dev_start,
33 .dev_stop = qat_dev_stop,
34 .dev_close = qat_dev_close,
35 .dev_infos_get = qat_dev_info_get,
37 .stats_get = qat_crypto_sym_stats_get,
38 .stats_reset = qat_crypto_sym_stats_reset,
39 .queue_pair_setup = qat_crypto_sym_qp_setup,
40 .queue_pair_release = qat_crypto_sym_qp_release,
41 .queue_pair_start = NULL,
42 .queue_pair_stop = NULL,
43 .queue_pair_count = NULL,
45 /* Crypto related operations */
46 .session_get_size = qat_crypto_sym_get_session_private_size,
47 .session_configure = qat_crypto_sym_configure_session,
48 .session_clear = qat_crypto_sym_clear_session
52 * The set of PCI devices this driver supports
55 static const struct rte_pci_id pci_id_qat_map[] = {
57 RTE_PCI_DEVICE(0x8086, 0x0443),
60 RTE_PCI_DEVICE(0x8086, 0x37c9),
63 RTE_PCI_DEVICE(0x8086, 0x19e3),
66 RTE_PCI_DEVICE(0x8086, 0x6f55),
72 crypto_qat_create(const char *name, struct rte_pci_device *pci_dev,
73 struct rte_cryptodev_pmd_init_params *init_params)
75 struct rte_cryptodev *cryptodev;
76 struct qat_pmd_private *internals;
78 PMD_INIT_FUNC_TRACE();
80 cryptodev = rte_cryptodev_pmd_create(name, &pci_dev->device,
82 if (cryptodev == NULL)
85 cryptodev->driver_id = cryptodev_qat_driver_id;
86 cryptodev->dev_ops = &crypto_qat_ops;
88 cryptodev->enqueue_burst = qat_pmd_enqueue_op_burst;
89 cryptodev->dequeue_burst = qat_pmd_dequeue_op_burst;
91 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
92 RTE_CRYPTODEV_FF_HW_ACCELERATED |
93 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
94 RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER;
96 internals = cryptodev->data->dev_private;
97 internals->max_nb_sessions = init_params->max_nb_sessions;
98 switch (pci_dev->id.device_id) {
100 internals->qat_dev_gen = QAT_GEN1;
101 internals->qat_dev_capabilities = qat_gen1_capabilities;
106 internals->qat_dev_gen = QAT_GEN2;
107 internals->qat_dev_capabilities = qat_gen2_capabilities;
111 "Invalid dev_id, can't determine capabilities");
116 * For secondary processes, we don't initialise any further as primary
117 * has already done this work. Only check we don't need a different
120 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
121 PMD_DRV_LOG(DEBUG, "Device already initialised by primary process");
128 static int crypto_qat_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
129 struct rte_pci_device *pci_dev)
131 struct rte_cryptodev_pmd_init_params init_params = {
133 .socket_id = rte_socket_id(),
134 .private_data_size = sizeof(struct qat_pmd_private),
135 .max_nb_sessions = RTE_QAT_PMD_MAX_NB_SESSIONS
137 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
139 PMD_DRV_LOG(DEBUG, "Found QAT device at %02x:%02x.%x",
142 pci_dev->addr.function);
144 rte_pci_device_name(&pci_dev->addr, name, sizeof(name));
146 return crypto_qat_create(name, pci_dev, &init_params);
149 static int crypto_qat_pci_remove(struct rte_pci_device *pci_dev)
151 struct rte_cryptodev *cryptodev;
152 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
157 rte_pci_device_name(&pci_dev->addr, cryptodev_name,
158 sizeof(cryptodev_name));
160 cryptodev = rte_cryptodev_pmd_get_named_dev(cryptodev_name);
161 if (cryptodev == NULL)
164 /* free crypto device */
165 return rte_cryptodev_pmd_destroy(cryptodev);
168 static struct rte_pci_driver rte_qat_pmd = {
169 .id_table = pci_id_qat_map,
170 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
171 .probe = crypto_qat_pci_probe,
172 .remove = crypto_qat_pci_remove
175 static struct cryptodev_driver qat_crypto_drv;
177 RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_QAT_SYM_PMD, rte_qat_pmd);
178 RTE_PMD_REGISTER_PCI_TABLE(CRYPTODEV_NAME_QAT_SYM_PMD, pci_id_qat_map);
179 RTE_PMD_REGISTER_CRYPTO_DRIVER(qat_crypto_drv, rte_qat_pmd,
180 cryptodev_qat_driver_id);