1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2018 Intel Corporation
7 #include <rte_common.h>
8 #include <rte_malloc.h>
9 #include <rte_cryptodev_pmd.h>
11 #include "kasumi_pmd_private.h"
13 static const struct rte_cryptodev_capabilities kasumi_pmd_capabilities[] = {
15 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
17 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
19 .algo = RTE_CRYPTO_AUTH_KASUMI_F9,
36 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
38 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
40 .algo = RTE_CRYPTO_CIPHER_KASUMI_F8,
55 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
58 /** Configure device */
60 kasumi_pmd_config(__rte_unused struct rte_cryptodev *dev,
61 __rte_unused struct rte_cryptodev_config *config)
68 kasumi_pmd_start(__rte_unused struct rte_cryptodev *dev)
75 kasumi_pmd_stop(__rte_unused struct rte_cryptodev *dev)
81 kasumi_pmd_close(__rte_unused struct rte_cryptodev *dev)
87 /** Get device statistics */
89 kasumi_pmd_stats_get(struct rte_cryptodev *dev,
90 struct rte_cryptodev_stats *stats)
94 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
95 struct kasumi_qp *qp = dev->data->queue_pairs[qp_id];
97 stats->enqueued_count += qp->qp_stats.enqueued_count;
98 stats->dequeued_count += qp->qp_stats.dequeued_count;
100 stats->enqueue_err_count += qp->qp_stats.enqueue_err_count;
101 stats->dequeue_err_count += qp->qp_stats.dequeue_err_count;
105 /** Reset device statistics */
107 kasumi_pmd_stats_reset(struct rte_cryptodev *dev)
111 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
112 struct kasumi_qp *qp = dev->data->queue_pairs[qp_id];
114 memset(&qp->qp_stats, 0, sizeof(qp->qp_stats));
119 /** Get device info */
121 kasumi_pmd_info_get(struct rte_cryptodev *dev,
122 struct rte_cryptodev_info *dev_info)
124 struct kasumi_private *internals = dev->data->dev_private;
126 if (dev_info != NULL) {
127 dev_info->driver_id = dev->driver_id;
128 dev_info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
129 /* No limit of number of sessions */
130 dev_info->sym.max_nb_sessions = 0;
131 dev_info->feature_flags = dev->feature_flags;
132 dev_info->capabilities = kasumi_pmd_capabilities;
136 /** Release queue pair */
138 kasumi_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id)
140 struct kasumi_qp *qp = dev->data->queue_pairs[qp_id];
143 rte_ring_free(qp->processed_ops);
145 dev->data->queue_pairs[qp_id] = NULL;
150 /** set a unique name for the queue pair based on its name, dev_id and qp_id */
152 kasumi_pmd_qp_set_unique_name(struct rte_cryptodev *dev,
153 struct kasumi_qp *qp)
155 unsigned n = snprintf(qp->name, sizeof(qp->name),
156 "kasumi_pmd_%u_qp_%u",
157 dev->data->dev_id, qp->id);
159 if (n >= sizeof(qp->name))
165 /** Create a ring to place processed ops on */
166 static struct rte_ring *
167 kasumi_pmd_qp_create_processed_ops_ring(struct kasumi_qp *qp,
168 unsigned ring_size, int socket_id)
172 r = rte_ring_lookup(qp->name);
174 if (rte_ring_get_size(r) == ring_size) {
175 KASUMI_LOG(INFO, "Reusing existing ring %s"
176 " for processed packets",
181 KASUMI_LOG(ERR, "Unable to reuse existing ring %s"
182 " for processed packets",
187 return rte_ring_create(qp->name, ring_size, socket_id,
188 RING_F_SP_ENQ | RING_F_SC_DEQ);
191 /** Setup a queue pair */
193 kasumi_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
194 const struct rte_cryptodev_qp_conf *qp_conf,
197 struct kasumi_qp *qp = NULL;
198 struct kasumi_private *internals = dev->data->dev_private;
200 /* Free memory prior to re-allocation if needed. */
201 if (dev->data->queue_pairs[qp_id] != NULL)
202 kasumi_pmd_qp_release(dev, qp_id);
204 /* Allocate the queue pair data structure. */
205 qp = rte_zmalloc_socket("KASUMI PMD Queue Pair", sizeof(*qp),
206 RTE_CACHE_LINE_SIZE, socket_id);
211 dev->data->queue_pairs[qp_id] = qp;
213 if (kasumi_pmd_qp_set_unique_name(dev, qp))
214 goto qp_setup_cleanup;
216 qp->processed_ops = kasumi_pmd_qp_create_processed_ops_ring(qp,
217 qp_conf->nb_descriptors, socket_id);
218 if (qp->processed_ops == NULL)
219 goto qp_setup_cleanup;
221 qp->mgr = internals->mgr;
222 qp->sess_mp = qp_conf->mp_session;
223 qp->sess_mp_priv = qp_conf->mp_session_private;
225 memset(&qp->qp_stats, 0, sizeof(qp->qp_stats));
235 /** Returns the size of the KASUMI session structure */
237 kasumi_pmd_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
239 return sizeof(struct kasumi_session);
242 /** Configure a KASUMI session from a crypto xform chain */
244 kasumi_pmd_sym_session_configure(struct rte_cryptodev *dev,
245 struct rte_crypto_sym_xform *xform,
246 struct rte_cryptodev_sym_session *sess,
247 struct rte_mempool *mempool)
249 void *sess_private_data;
251 struct kasumi_private *internals = dev->data->dev_private;
253 if (unlikely(sess == NULL)) {
254 KASUMI_LOG(ERR, "invalid session struct");
258 if (rte_mempool_get(mempool, &sess_private_data)) {
260 "Couldn't get object from session mempool");
264 ret = kasumi_set_session_parameters(internals->mgr,
265 sess_private_data, xform);
267 KASUMI_LOG(ERR, "failed configure session parameters");
269 /* Return session to mempool */
270 rte_mempool_put(mempool, sess_private_data);
274 set_sym_session_private_data(sess, dev->driver_id,
280 /** Clear the memory of session so it doesn't leave key material behind */
282 kasumi_pmd_sym_session_clear(struct rte_cryptodev *dev,
283 struct rte_cryptodev_sym_session *sess)
285 uint8_t index = dev->driver_id;
286 void *sess_priv = get_sym_session_private_data(sess, index);
288 /* Zero out the whole structure */
290 memset(sess_priv, 0, sizeof(struct kasumi_session));
291 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
292 set_sym_session_private_data(sess, index, NULL);
293 rte_mempool_put(sess_mp, sess_priv);
297 struct rte_cryptodev_ops kasumi_pmd_ops = {
298 .dev_configure = kasumi_pmd_config,
299 .dev_start = kasumi_pmd_start,
300 .dev_stop = kasumi_pmd_stop,
301 .dev_close = kasumi_pmd_close,
303 .stats_get = kasumi_pmd_stats_get,
304 .stats_reset = kasumi_pmd_stats_reset,
306 .dev_infos_get = kasumi_pmd_info_get,
308 .queue_pair_setup = kasumi_pmd_qp_setup,
309 .queue_pair_release = kasumi_pmd_qp_release,
311 .sym_session_get_size = kasumi_pmd_sym_session_get_size,
312 .sym_session_configure = kasumi_pmd_sym_session_configure,
313 .sym_session_clear = kasumi_pmd_sym_session_clear
316 struct rte_cryptodev_ops *rte_kasumi_pmd_ops = &kasumi_pmd_ops;