crypto/qat: rename functions which depend on cryptodev
[dpdk.git] / drivers / crypto / qat / rte_qat_cryptodev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2018 Intel Corporation
3  */
4
5 #include <rte_bus_pci.h>
6 #include <rte_common.h>
7 #include <rte_dev.h>
8 #include <rte_malloc.h>
9 #include <rte_pci.h>
10 #include <rte_cryptodev_pmd.h>
11
12 #include "qat_sym.h"
13 #include "qat_sym_session.h"
14 #include "qat_logs.h"
15
16 uint8_t cryptodev_qat_driver_id;
17
18 static const struct rte_cryptodev_capabilities qat_gen1_sym_capabilities[] = {
19         QAT_BASE_GEN1_SYM_CAPABILITIES,
20         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
21 };
22
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()
27 };
28
29 static struct rte_cryptodev_ops crypto_qat_ops = {
30
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,
37
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,
45
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
50 };
51
52 /*
53  * The set of PCI devices this driver supports
54  */
55
56 static const struct rte_pci_id pci_id_qat_map[] = {
57                 {
58                         RTE_PCI_DEVICE(0x8086, 0x0443),
59                 },
60                 {
61                         RTE_PCI_DEVICE(0x8086, 0x37c9),
62                 },
63                 {
64                         RTE_PCI_DEVICE(0x8086, 0x19e3),
65                 },
66                 {
67                         RTE_PCI_DEVICE(0x8086, 0x6f55),
68                 },
69                 {.device_id = 0},
70 };
71
72
73
74 static int
75 qat_sym_dev_create(struct qat_pci_device *qat_pci_dev)
76 {
77         struct rte_cryptodev_pmd_init_params init_params = {
78                         .name = "",
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
82         };
83         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
84         struct rte_cryptodev *cryptodev;
85         struct qat_sym_dev_private *internals;
86
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);
90
91         cryptodev = rte_cryptodev_pmd_create(name,
92                         &qat_pci_dev->pci_dev->device, &init_params);
93
94         if (cryptodev == NULL)
95                 return -ENODEV;
96
97         cryptodev->driver_id = cryptodev_qat_driver_id;
98         cryptodev->dev_ops = &crypto_qat_ops;
99
100         cryptodev->enqueue_burst = qat_sym_pmd_enqueue_op_burst;
101         cryptodev->dequeue_burst = qat_sym_pmd_dequeue_op_burst;
102
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;
107
108         internals = cryptodev->data->dev_private;
109         internals->qat_dev = qat_pci_dev;
110         qat_pci_dev->sym_dev = internals;
111
112         internals->sym_dev_id = cryptodev->data->dev_id;
113         switch (qat_pci_dev->qat_dev_gen) {
114         case QAT_GEN1:
115                 internals->qat_dev_capabilities = qat_gen1_sym_capabilities;
116                 break;
117         case QAT_GEN2:
118                 internals->qat_dev_capabilities = qat_gen2_sym_capabilities;
119                 break;
120         default:
121                 internals->qat_dev_capabilities = qat_gen2_sym_capabilities;
122                 PMD_DRV_LOG(DEBUG,
123                         "QAT gen %d capabilities unknown, default to GEN2",
124                                         qat_pci_dev->qat_dev_gen);
125                 break;
126         }
127
128         PMD_DRV_LOG(DEBUG, "Created QAT SYM device %s as cryptodev instance %d",
129                         name, internals->sym_dev_id);
130         return 0;
131 }
132
133 static int
134 qat_sym_dev_destroy(struct qat_pci_device *qat_pci_dev)
135 {
136         struct rte_cryptodev *cryptodev;
137
138         if (qat_pci_dev == NULL)
139                 return -ENODEV;
140         if (qat_pci_dev->sym_dev == NULL)
141                 return 0;
142
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;
147
148         return 0;
149 }
150
151 static int
152 qat_comp_dev_create(struct qat_pci_device *qat_pci_dev __rte_unused)
153 {
154         return 0;
155 }
156
157 static int
158 qat_comp_dev_destroy(struct qat_pci_device *qat_pci_dev __rte_unused)
159 {
160         return 0;
161 }
162
163 static int
164 qat_asym_dev_create(struct qat_pci_device *qat_pci_dev __rte_unused)
165 {
166         return 0;
167 }
168
169 static int
170 qat_asym_dev_destroy(struct qat_pci_device *qat_pci_dev __rte_unused)
171 {
172         return 0;
173 }
174
175 static int
176 qat_pci_dev_destroy(struct qat_pci_device *qat_pci_dev,
177                 struct rte_pci_device *pci_dev)
178 {
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);
183 }
184
185 static int qat_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
186                 struct rte_pci_device *pci_dev)
187 {
188         int ret = 0;
189         struct qat_pci_device *qat_pci_dev;
190
191         PMD_DRV_LOG(DEBUG, "Found QAT device at %02x:%02x.%x",
192                         pci_dev->addr.bus,
193                         pci_dev->addr.devid,
194                         pci_dev->addr.function);
195
196         qat_pci_dev = qat_pci_device_allocate(pci_dev);
197         if (qat_pci_dev == NULL)
198                 return -ENODEV;
199
200         ret = qat_sym_dev_create(qat_pci_dev);
201         if (ret != 0)
202                 goto error_out;
203
204         ret = qat_comp_dev_create(qat_pci_dev);
205         if (ret != 0)
206                 goto error_out;
207
208         ret = qat_asym_dev_create(qat_pci_dev);
209         if (ret != 0)
210                 goto error_out;
211
212         return 0;
213
214 error_out:
215         qat_pci_dev_destroy(qat_pci_dev, pci_dev);
216         return ret;
217
218 }
219
220 static int qat_pci_remove(struct rte_pci_device *pci_dev)
221 {
222         struct qat_pci_device *qat_pci_dev;
223
224         if (pci_dev == NULL)
225                 return -EINVAL;
226
227         qat_pci_dev = qat_get_qat_dev_from_pci_dev(pci_dev);
228         if (qat_pci_dev == NULL)
229                 return 0;
230
231         return qat_pci_dev_destroy(qat_pci_dev, pci_dev);
232
233 }
234
235
236 /* An rte_driver is needed in the registration of both the device and the driver
237  * with cryptodev.
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.
241  */
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
246 };
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);
250
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
256 };
257 RTE_PMD_REGISTER_PCI(QAT_PCI_NAME, rte_qat_pmd);
258 RTE_PMD_REGISTER_PCI_TABLE(QAT_PCI_NAME, pci_id_qat_map);