1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Advanced Micro Devices, Inc. All rights reserved.
5 #include <rte_bus_pci.h>
6 #include <rte_bus_vdev.h>
7 #include <rte_common.h>
8 #include <rte_config.h>
9 #include <rte_cryptodev.h>
10 #include <rte_cryptodev_pmd.h>
13 #include <rte_malloc.h>
15 #include "ccp_crypto.h"
17 #include "ccp_pmd_private.h"
20 * Global static parameter used to find if CCP device is already initialized.
22 static unsigned int ccp_pmd_init_done;
23 uint8_t ccp_cryptodev_driver_id;
25 static struct ccp_session *
26 get_ccp_session(struct ccp_qp *qp, struct rte_crypto_op *op)
28 struct ccp_session *sess = NULL;
30 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
31 if (unlikely(op->sym->session == NULL))
34 sess = (struct ccp_session *)
35 get_session_private_data(
37 ccp_cryptodev_driver_id);
38 } else if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
40 void *_sess_private_data = NULL;
42 if (rte_mempool_get(qp->sess_mp, &_sess))
44 if (rte_mempool_get(qp->sess_mp, (void **)&_sess_private_data))
47 sess = (struct ccp_session *)_sess_private_data;
49 if (unlikely(ccp_set_session_parameters(sess,
50 op->sym->xform) != 0)) {
51 rte_mempool_put(qp->sess_mp, _sess);
52 rte_mempool_put(qp->sess_mp, _sess_private_data);
55 op->sym->session = (struct rte_cryptodev_sym_session *)_sess;
56 set_session_private_data(op->sym->session,
57 ccp_cryptodev_driver_id,
65 ccp_pmd_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops,
68 struct ccp_session *sess = NULL;
69 struct ccp_qp *qp = queue_pair;
70 struct ccp_queue *cmd_q;
71 struct rte_cryptodev *dev = qp->dev;
72 uint16_t i, enq_cnt = 0, slots_req = 0;
77 if (unlikely(rte_ring_full(qp->processed_pkts) != 0))
80 for (i = 0; i < nb_ops; i++) {
81 sess = get_ccp_session(qp, ops[i]);
82 if (unlikely(sess == NULL) && (i == 0)) {
83 qp->qp_stats.enqueue_err_count++;
85 } else if (sess == NULL) {
89 slots_req += ccp_compute_slot_count(sess);
92 cmd_q = ccp_allot_queue(dev, slots_req);
93 if (unlikely(cmd_q == NULL))
96 enq_cnt = process_ops_to_enqueue(qp, ops, cmd_q, nb_ops, slots_req);
97 qp->qp_stats.enqueued_count += enq_cnt;
102 ccp_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
105 struct ccp_qp *qp = queue_pair;
106 uint16_t nb_dequeued = 0, i;
108 nb_dequeued = process_ops_to_dequeue(qp, ops, nb_ops);
110 /* Free session if a session-less crypto op */
111 for (i = 0; i < nb_dequeued; i++)
112 if (unlikely(ops[i]->sess_type ==
113 RTE_CRYPTO_OP_SESSIONLESS)) {
114 rte_mempool_put(qp->sess_mp,
115 ops[i]->sym->session);
116 ops[i]->sym->session = NULL;
118 qp->qp_stats.dequeued_count += nb_dequeued;
124 * The set of PCI devices this driver supports
126 static struct rte_pci_id ccp_pci_id[] = {
128 RTE_PCI_DEVICE(0x1022, 0x1456), /* AMD CCP-5a */
131 RTE_PCI_DEVICE(0x1022, 0x1468), /* AMD CCP-5b */
136 /** Remove ccp pmd */
138 cryptodev_ccp_remove(struct rte_vdev_device *dev)
142 ccp_pmd_init_done = 0;
143 name = rte_vdev_device_name(dev);
147 RTE_LOG(INFO, PMD, "Closing ccp device %s on numa socket %u\n",
148 name, rte_socket_id());
153 /** Create crypto device */
155 cryptodev_ccp_create(const char *name,
156 struct rte_vdev_device *vdev,
157 struct rte_cryptodev_pmd_init_params *init_params)
159 struct rte_cryptodev *dev;
160 struct ccp_private *internals;
161 uint8_t cryptodev_cnt = 0;
163 if (init_params->name[0] == '\0')
164 snprintf(init_params->name, sizeof(init_params->name),
167 dev = rte_cryptodev_pmd_create(init_params->name,
171 CCP_LOG_ERR("failed to create cryptodev vdev");
175 cryptodev_cnt = ccp_probe_devices(ccp_pci_id);
177 if (cryptodev_cnt == 0) {
178 CCP_LOG_ERR("failed to detect CCP crypto device");
182 printf("CCP : Crypto device count = %d\n", cryptodev_cnt);
183 dev->driver_id = ccp_cryptodev_driver_id;
185 /* register rx/tx burst functions for data path */
186 dev->dev_ops = ccp_pmd_ops;
187 dev->enqueue_burst = ccp_pmd_enqueue_burst;
188 dev->dequeue_burst = ccp_pmd_dequeue_burst;
190 dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
191 RTE_CRYPTODEV_FF_HW_ACCELERATED |
192 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING;
194 internals = dev->data->dev_private;
196 internals->max_nb_qpairs = init_params->max_nb_queue_pairs;
197 internals->max_nb_sessions = init_params->max_nb_sessions;
198 internals->crypto_num_dev = cryptodev_cnt;
203 CCP_LOG_ERR("driver %s: %s() failed",
204 init_params->name, __func__);
205 cryptodev_ccp_remove(vdev);
212 cryptodev_ccp_probe(struct rte_vdev_device *vdev)
216 struct rte_cryptodev_pmd_init_params init_params = {
218 sizeof(struct ccp_private),
220 CCP_PMD_MAX_QUEUE_PAIRS,
221 RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_SESSIONS
223 const char *input_args;
225 if (ccp_pmd_init_done) {
226 RTE_LOG(INFO, PMD, "CCP PMD already initialized\n");
229 name = rte_vdev_device_name(vdev);
233 input_args = rte_vdev_device_args(vdev);
234 rte_cryptodev_pmd_parse_input_args(&init_params, input_args);
235 init_params.max_nb_queue_pairs = CCP_PMD_MAX_QUEUE_PAIRS;
237 RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
238 init_params.socket_id);
239 RTE_LOG(INFO, PMD, "Max number of queue pairs = %d\n",
240 init_params.max_nb_queue_pairs);
241 RTE_LOG(INFO, PMD, "Max number of sessions = %d\n",
242 init_params.max_nb_sessions);
244 rc = cryptodev_ccp_create(name, vdev, &init_params);
247 ccp_pmd_init_done = 1;
251 static struct rte_vdev_driver cryptodev_ccp_pmd_drv = {
252 .probe = cryptodev_ccp_probe,
253 .remove = cryptodev_ccp_remove
256 static struct cryptodev_driver ccp_crypto_drv;
258 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_CCP_PMD, cryptodev_ccp_pmd_drv);
259 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_CCP_PMD,
260 "max_nb_queue_pairs=<int> max_nb_sessions=<int> socket_id=<int>");
261 RTE_PMD_REGISTER_CRYPTO_DRIVER(ccp_crypto_drv, cryptodev_ccp_pmd_drv.driver,
262 ccp_cryptodev_driver_id);