1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
5 #include <rte_cryptodev_pmd.h>
10 #include "qat_asym_pmd.h"
11 #include "qat_sym_capabilities.h"
12 #include "qat_asym_capabilities.h"
14 uint8_t cryptodev_qat_asym_driver_id;
16 static const struct rte_cryptodev_capabilities qat_gen1_asym_capabilities[] = {
17 QAT_BASE_GEN1_ASYM_CAPABILITIES,
18 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
21 static int qat_asym_qp_release(struct rte_cryptodev *dev,
22 uint16_t queue_pair_id);
24 static int qat_asym_dev_config(__rte_unused struct rte_cryptodev *dev,
25 __rte_unused struct rte_cryptodev_config *config)
30 static int qat_asym_dev_start(__rte_unused struct rte_cryptodev *dev)
35 static void qat_asym_dev_stop(__rte_unused struct rte_cryptodev *dev)
40 static int qat_asym_dev_close(struct rte_cryptodev *dev)
44 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
45 ret = qat_asym_qp_release(dev, i);
53 static void qat_asym_dev_info_get(struct rte_cryptodev *dev,
54 struct rte_cryptodev_info *info)
56 struct qat_asym_dev_private *internals = dev->data->dev_private;
57 const struct qat_qp_hw_data *asym_hw_qps =
58 qat_gen_config[internals->qat_dev->qat_dev_gen]
59 .qp_hw_data[QAT_SERVICE_ASYMMETRIC];
62 info->max_nb_queue_pairs = qat_qps_per_service(asym_hw_qps,
63 QAT_SERVICE_ASYMMETRIC);
64 info->feature_flags = dev->feature_flags;
65 info->capabilities = internals->qat_dev_capabilities;
66 info->driver_id = cryptodev_qat_asym_driver_id;
67 /* No limit of number of sessions */
68 info->sym.max_nb_sessions = 0;
72 static void qat_asym_stats_get(struct rte_cryptodev *dev,
73 struct rte_cryptodev_stats *stats)
75 struct qat_common_stats qat_stats = {0};
76 struct qat_asym_dev_private *qat_priv;
78 if (stats == NULL || dev == NULL) {
79 QAT_LOG(ERR, "invalid ptr: stats %p, dev %p", stats, dev);
82 qat_priv = dev->data->dev_private;
84 qat_stats_get(qat_priv->qat_dev, &qat_stats, QAT_SERVICE_ASYMMETRIC);
85 stats->enqueued_count = qat_stats.enqueued_count;
86 stats->dequeued_count = qat_stats.dequeued_count;
87 stats->enqueue_err_count = qat_stats.enqueue_err_count;
88 stats->dequeue_err_count = qat_stats.dequeue_err_count;
91 static void qat_asym_stats_reset(struct rte_cryptodev *dev)
93 struct qat_asym_dev_private *qat_priv;
96 QAT_LOG(ERR, "invalid asymmetric cryptodev ptr %p", dev);
99 qat_priv = dev->data->dev_private;
101 qat_stats_reset(qat_priv->qat_dev, QAT_SERVICE_ASYMMETRIC);
104 static int qat_asym_qp_release(struct rte_cryptodev *dev,
105 uint16_t queue_pair_id)
107 struct qat_asym_dev_private *qat_private = dev->data->dev_private;
109 QAT_LOG(DEBUG, "Release asym qp %u on device %d",
110 queue_pair_id, dev->data->dev_id);
112 qat_private->qat_dev->qps_in_use[QAT_SERVICE_ASYMMETRIC][queue_pair_id]
115 return qat_qp_release((struct qat_qp **)
116 &(dev->data->queue_pairs[queue_pair_id]));
119 static int qat_asym_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
120 const struct rte_cryptodev_qp_conf *qp_conf,
123 struct qat_qp_config qat_qp_conf;
128 struct qat_qp **qp_addr =
129 (struct qat_qp **)&(dev->data->queue_pairs[qp_id]);
130 struct qat_asym_dev_private *qat_private = dev->data->dev_private;
131 const struct qat_qp_hw_data *asym_hw_qps =
132 qat_gen_config[qat_private->qat_dev->qat_dev_gen]
133 .qp_hw_data[QAT_SERVICE_ASYMMETRIC];
134 const struct qat_qp_hw_data *qp_hw_data = asym_hw_qps + qp_id;
136 /* If qp is already in use free ring memory and qp metadata. */
137 if (*qp_addr != NULL) {
138 ret = qat_asym_qp_release(dev, qp_id);
142 if (qp_id >= qat_qps_per_service(asym_hw_qps, QAT_SERVICE_ASYMMETRIC)) {
143 QAT_LOG(ERR, "qp_id %u invalid for this device", qp_id);
147 qat_qp_conf.hw = qp_hw_data;
148 qat_qp_conf.build_request = qat_asym_build_request;
149 qat_qp_conf.cookie_size = sizeof(struct qat_asym_op_cookie);
150 qat_qp_conf.nb_descriptors = qp_conf->nb_descriptors;
151 qat_qp_conf.socket_id = socket_id;
152 qat_qp_conf.service_str = "asym";
154 ret = qat_qp_setup(qat_private->qat_dev, qp_addr, qp_id, &qat_qp_conf);
158 /* store a link to the qp in the qat_pci_device */
159 qat_private->qat_dev->qps_in_use[QAT_SERVICE_ASYMMETRIC][qp_id]
162 qp = (struct qat_qp *)*qp_addr;
164 for (i = 0; i < qp->nb_descriptors; i++) {
167 struct qat_asym_op_cookie __rte_unused *cookie =
169 cookie->input_addr = rte_mempool_virt2iova(cookie) +
170 offsetof(struct qat_asym_op_cookie,
173 cookie->output_addr = rte_mempool_virt2iova(cookie) +
174 offsetof(struct qat_asym_op_cookie,
177 for (j = 0; j < 8; j++) {
178 cookie->input_params_ptrs[j] =
179 rte_mempool_virt2iova(cookie) +
180 offsetof(struct qat_asym_op_cookie,
182 cookie->output_params_ptrs[j] =
183 rte_mempool_virt2iova(cookie) +
184 offsetof(struct qat_asym_op_cookie,
192 struct rte_cryptodev_ops crypto_qat_ops = {
194 /* Device related operations */
195 .dev_configure = qat_asym_dev_config,
196 .dev_start = qat_asym_dev_start,
197 .dev_stop = qat_asym_dev_stop,
198 .dev_close = qat_asym_dev_close,
199 .dev_infos_get = qat_asym_dev_info_get,
201 .stats_get = qat_asym_stats_get,
202 .stats_reset = qat_asym_stats_reset,
203 .queue_pair_setup = qat_asym_qp_setup,
204 .queue_pair_release = qat_asym_qp_release,
205 .queue_pair_count = NULL,
207 /* Crypto related operations */
208 .asym_session_get_size = qat_asym_session_get_private_size,
209 .asym_session_configure = qat_asym_session_configure,
210 .asym_session_clear = qat_asym_session_clear
213 uint16_t qat_asym_pmd_enqueue_op_burst(void *qp, struct rte_crypto_op **ops,
216 return qat_enqueue_op_burst(qp, (void **)ops, nb_ops);
219 uint16_t qat_asym_pmd_dequeue_op_burst(void *qp, struct rte_crypto_op **ops,
222 return qat_dequeue_op_burst(qp, (void **)ops, nb_ops);
225 /* An rte_driver is needed in the registration of both the device and the driver
227 * The actual qat pci's rte_driver can't be used as its name represents
228 * the whole pci device with all services. Think of this as a holder for a name
229 * for the crypto part of the pci device.
231 static const char qat_asym_drv_name[] = RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD);
232 static const struct rte_driver cryptodev_qat_asym_driver = {
233 .name = qat_asym_drv_name,
234 .alias = qat_asym_drv_name
238 qat_asym_dev_create(struct qat_pci_device *qat_pci_dev)
240 struct rte_cryptodev_pmd_init_params init_params = {
242 .socket_id = qat_pci_dev->pci_dev->device.numa_node,
243 .private_data_size = sizeof(struct qat_asym_dev_private)
245 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
246 struct rte_cryptodev *cryptodev;
247 struct qat_asym_dev_private *internals;
249 snprintf(name, RTE_CRYPTODEV_NAME_MAX_LEN, "%s_%s",
250 qat_pci_dev->name, "asym");
251 QAT_LOG(DEBUG, "Creating QAT ASYM device %s\n", name);
253 /* Populate subset device to use in cryptodev device creation */
254 qat_pci_dev->asym_rte_dev.driver = &cryptodev_qat_asym_driver;
255 qat_pci_dev->asym_rte_dev.numa_node =
256 qat_pci_dev->pci_dev->device.numa_node;
257 qat_pci_dev->asym_rte_dev.devargs = NULL;
259 cryptodev = rte_cryptodev_pmd_create(name,
260 &(qat_pci_dev->asym_rte_dev), &init_params);
262 if (cryptodev == NULL)
265 qat_pci_dev->asym_rte_dev.name = cryptodev->data->name;
266 cryptodev->driver_id = cryptodev_qat_asym_driver_id;
267 cryptodev->dev_ops = &crypto_qat_ops;
269 cryptodev->enqueue_burst = qat_asym_pmd_enqueue_op_burst;
270 cryptodev->dequeue_burst = qat_asym_pmd_dequeue_op_burst;
272 cryptodev->feature_flags = RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO |
273 RTE_CRYPTODEV_FF_HW_ACCELERATED;
274 internals = cryptodev->data->dev_private;
275 internals->qat_dev = qat_pci_dev;
276 qat_pci_dev->asym_dev = internals;
278 internals->asym_dev_id = cryptodev->data->dev_id;
279 internals->qat_dev_capabilities = qat_gen1_asym_capabilities;
281 QAT_LOG(DEBUG, "Created QAT ASYM device %s as cryptodev instance %d",
282 cryptodev->data->name, internals->asym_dev_id);
287 qat_asym_dev_destroy(struct qat_pci_device *qat_pci_dev)
289 struct rte_cryptodev *cryptodev;
291 if (qat_pci_dev == NULL)
293 if (qat_pci_dev->asym_dev == NULL)
296 /* free crypto device */
297 cryptodev = rte_cryptodev_pmd_get_dev(
298 qat_pci_dev->asym_dev->asym_dev_id);
299 rte_cryptodev_pmd_destroy(cryptodev);
300 qat_pci_dev->asym_rte_dev.name = NULL;
301 qat_pci_dev->asym_dev = NULL;
306 static struct cryptodev_driver qat_crypto_drv;
307 RTE_PMD_REGISTER_CRYPTO_DRIVER(qat_crypto_drv,
308 cryptodev_qat_asym_driver,
309 cryptodev_qat_asym_driver_id);