1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2018 Intel Corporation
5 #include <rte_bus_pci.h>
6 #include <rte_common.h>
8 #include <rte_malloc.h>
10 #include <rte_cryptodev_pmd.h>
13 #include "qat_sym_session.h"
16 uint8_t cryptodev_qat_driver_id;
18 static const struct rte_cryptodev_capabilities qat_gen1_sym_capabilities[] = {
19 QAT_BASE_GEN1_SYM_CAPABILITIES,
20 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
23 static const struct rte_cryptodev_capabilities qat_gen2_sym_capabilities[] = {
24 QAT_BASE_GEN1_SYM_CAPABILITIES,
25 QAT_EXTRA_GEN2_SYM_CAPABILITIES,
26 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
29 static struct rte_cryptodev_ops crypto_qat_ops = {
31 /* Device related operations */
32 .dev_configure = qat_sym_dev_config,
33 .dev_start = qat_sym_dev_start,
34 .dev_stop = qat_sym_dev_stop,
35 .dev_close = qat_sym_dev_close,
36 .dev_infos_get = qat_sym_dev_info_get,
38 .stats_get = qat_sym_stats_get,
39 .stats_reset = qat_sym_stats_reset,
40 .queue_pair_setup = qat_sym_qp_setup,
41 .queue_pair_release = qat_sym_qp_release,
42 .queue_pair_start = NULL,
43 .queue_pair_stop = NULL,
44 .queue_pair_count = NULL,
46 /* Crypto related operations */
47 .session_get_size = qat_sym_session_get_private_size,
48 .session_configure = qat_sym_session_configure,
49 .session_clear = qat_sym_session_clear
53 * The set of PCI devices this driver supports
56 static const struct rte_pci_id pci_id_qat_map[] = {
58 RTE_PCI_DEVICE(0x8086, 0x0443),
61 RTE_PCI_DEVICE(0x8086, 0x37c9),
64 RTE_PCI_DEVICE(0x8086, 0x19e3),
67 RTE_PCI_DEVICE(0x8086, 0x6f55),
75 qat_sym_dev_create(struct qat_pci_device *qat_pci_dev)
77 struct rte_cryptodev_pmd_init_params init_params = {
79 .socket_id = qat_pci_dev->pci_dev->device.numa_node,
80 .private_data_size = sizeof(struct qat_sym_dev_private),
81 .max_nb_sessions = RTE_QAT_PMD_MAX_NB_SESSIONS
83 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
84 struct rte_cryptodev *cryptodev;
85 struct qat_sym_dev_private *internals;
87 snprintf(name, RTE_CRYPTODEV_NAME_MAX_LEN, "%s_%s",
88 qat_pci_dev->name, "sym");
89 PMD_DRV_LOG(DEBUG, "Creating QAT SYM device %s", name);
91 cryptodev = rte_cryptodev_pmd_create(name,
92 &qat_pci_dev->pci_dev->device, &init_params);
94 if (cryptodev == NULL)
97 cryptodev->driver_id = cryptodev_qat_driver_id;
98 cryptodev->dev_ops = &crypto_qat_ops;
100 cryptodev->enqueue_burst = qat_sym_pmd_enqueue_op_burst;
101 cryptodev->dequeue_burst = qat_sym_pmd_dequeue_op_burst;
103 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
104 RTE_CRYPTODEV_FF_HW_ACCELERATED |
105 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
106 RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER;
108 internals = cryptodev->data->dev_private;
109 internals->qat_dev = qat_pci_dev;
110 qat_pci_dev->sym_dev = internals;
112 internals->sym_dev_id = cryptodev->data->dev_id;
113 switch (qat_pci_dev->qat_dev_gen) {
115 internals->qat_dev_capabilities = qat_gen1_sym_capabilities;
118 internals->qat_dev_capabilities = qat_gen2_sym_capabilities;
121 internals->qat_dev_capabilities = qat_gen2_sym_capabilities;
123 "QAT gen %d capabilities unknown, default to GEN2",
124 qat_pci_dev->qat_dev_gen);
128 PMD_DRV_LOG(DEBUG, "Created QAT SYM device %s as cryptodev instance %d",
129 name, internals->sym_dev_id);
134 qat_sym_dev_destroy(struct qat_pci_device *qat_pci_dev)
136 struct rte_cryptodev *cryptodev;
138 if (qat_pci_dev == NULL)
140 if (qat_pci_dev->sym_dev == NULL)
143 /* free crypto device */
144 cryptodev = rte_cryptodev_pmd_get_dev(qat_pci_dev->sym_dev->sym_dev_id);
145 rte_cryptodev_pmd_destroy(cryptodev);
146 qat_pci_dev->sym_dev = NULL;
152 qat_comp_dev_create(struct qat_pci_device *qat_pci_dev __rte_unused)
158 qat_comp_dev_destroy(struct qat_pci_device *qat_pci_dev __rte_unused)
164 qat_asym_dev_create(struct qat_pci_device *qat_pci_dev __rte_unused)
170 qat_asym_dev_destroy(struct qat_pci_device *qat_pci_dev __rte_unused)
176 qat_pci_dev_destroy(struct qat_pci_device *qat_pci_dev,
177 struct rte_pci_device *pci_dev)
179 qat_sym_dev_destroy(qat_pci_dev);
180 qat_comp_dev_destroy(qat_pci_dev);
181 qat_asym_dev_destroy(qat_pci_dev);
182 return qat_pci_device_release(pci_dev);
185 static int qat_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
186 struct rte_pci_device *pci_dev)
189 struct qat_pci_device *qat_pci_dev;
191 PMD_DRV_LOG(DEBUG, "Found QAT device at %02x:%02x.%x",
194 pci_dev->addr.function);
196 qat_pci_dev = qat_pci_device_allocate(pci_dev);
197 if (qat_pci_dev == NULL)
200 ret = qat_sym_dev_create(qat_pci_dev);
204 ret = qat_comp_dev_create(qat_pci_dev);
208 ret = qat_asym_dev_create(qat_pci_dev);
215 qat_pci_dev_destroy(qat_pci_dev, pci_dev);
220 static int qat_pci_remove(struct rte_pci_device *pci_dev)
222 struct qat_pci_device *qat_pci_dev;
227 qat_pci_dev = qat_get_qat_dev_from_pci_dev(pci_dev);
228 if (qat_pci_dev == NULL)
231 return qat_pci_dev_destroy(qat_pci_dev, pci_dev);
236 /* An rte_driver is needed in the registration of both the device and the driver
238 * The actual qat pci's rte_driver can't be used as its name represents
239 * the whole pci device with all services. Think of this as a holder for a name
240 * for the crypto part of the pci device.
242 static const char qat_sym_drv_name[] = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
243 static struct rte_driver cryptodev_qat_sym_driver = {
244 .name = qat_sym_drv_name,
245 .alias = qat_sym_drv_name
247 static struct cryptodev_driver qat_crypto_drv;
248 RTE_PMD_REGISTER_CRYPTO_DRIVER(qat_crypto_drv, cryptodev_qat_sym_driver,
249 cryptodev_qat_driver_id);
251 static struct rte_pci_driver rte_qat_pmd = {
252 .id_table = pci_id_qat_map,
253 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
254 .probe = qat_pci_probe,
255 .remove = qat_pci_remove
257 RTE_PMD_REGISTER_PCI(QAT_PCI_NAME, rte_qat_pmd);
258 RTE_PMD_REGISTER_PCI_TABLE(QAT_PCI_NAME, pci_id_qat_map);