1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Cavium, Inc
7 #include <rte_common.h>
8 #include <rte_malloc.h>
9 #include <rte_cryptodev_pmd.h>
11 #include "armv8_crypto_defs.h"
13 #include "rte_armv8_pmd_private.h"
15 static const struct rte_cryptodev_capabilities
16 armv8_crypto_pmd_capabilities[] = {
18 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
20 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
22 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
39 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
41 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
43 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
60 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
62 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
64 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
80 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
84 /** Configure device */
86 armv8_crypto_pmd_config(__rte_unused struct rte_cryptodev *dev,
87 __rte_unused struct rte_cryptodev_config *config)
94 armv8_crypto_pmd_start(__rte_unused struct rte_cryptodev *dev)
101 armv8_crypto_pmd_stop(__rte_unused struct rte_cryptodev *dev)
107 armv8_crypto_pmd_close(__rte_unused struct rte_cryptodev *dev)
113 /** Get device statistics */
115 armv8_crypto_pmd_stats_get(struct rte_cryptodev *dev,
116 struct rte_cryptodev_stats *stats)
120 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
121 struct armv8_crypto_qp *qp = dev->data->queue_pairs[qp_id];
123 stats->enqueued_count += qp->stats.enqueued_count;
124 stats->dequeued_count += qp->stats.dequeued_count;
126 stats->enqueue_err_count += qp->stats.enqueue_err_count;
127 stats->dequeue_err_count += qp->stats.dequeue_err_count;
131 /** Reset device statistics */
133 armv8_crypto_pmd_stats_reset(struct rte_cryptodev *dev)
137 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
138 struct armv8_crypto_qp *qp = dev->data->queue_pairs[qp_id];
140 memset(&qp->stats, 0, sizeof(qp->stats));
145 /** Get device info */
147 armv8_crypto_pmd_info_get(struct rte_cryptodev *dev,
148 struct rte_cryptodev_info *dev_info)
150 struct armv8_crypto_private *internals = dev->data->dev_private;
152 if (dev_info != NULL) {
153 dev_info->driver_id = dev->driver_id;
154 dev_info->feature_flags = dev->feature_flags;
155 dev_info->capabilities = armv8_crypto_pmd_capabilities;
156 dev_info->max_nb_queue_pairs = internals->max_nb_qpairs;
157 dev_info->sym.max_nb_sessions = internals->max_nb_sessions;
161 /** Release queue pair */
163 armv8_crypto_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id)
166 if (dev->data->queue_pairs[qp_id] != NULL) {
167 rte_free(dev->data->queue_pairs[qp_id]);
168 dev->data->queue_pairs[qp_id] = NULL;
174 /** set a unique name for the queue pair based on it's name, dev_id and qp_id */
176 armv8_crypto_pmd_qp_set_unique_name(struct rte_cryptodev *dev,
177 struct armv8_crypto_qp *qp)
181 n = snprintf(qp->name, sizeof(qp->name), "armv8_crypto_pmd_%u_qp_%u",
182 dev->data->dev_id, qp->id);
184 if (n >= sizeof(qp->name))
191 /** Create a ring to place processed operations on */
192 static struct rte_ring *
193 armv8_crypto_pmd_qp_create_processed_ops_ring(struct armv8_crypto_qp *qp,
194 unsigned int ring_size, int socket_id)
198 r = rte_ring_lookup(qp->name);
200 if (rte_ring_get_size(r) >= ring_size) {
201 ARMV8_CRYPTO_LOG_INFO(
202 "Reusing existing ring %s for processed ops",
207 ARMV8_CRYPTO_LOG_ERR(
208 "Unable to reuse existing ring %s for processed ops",
213 return rte_ring_create(qp->name, ring_size, socket_id,
214 RING_F_SP_ENQ | RING_F_SC_DEQ);
218 /** Setup a queue pair */
220 armv8_crypto_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
221 const struct rte_cryptodev_qp_conf *qp_conf,
222 int socket_id, struct rte_mempool *session_pool)
224 struct armv8_crypto_qp *qp = NULL;
226 /* Free memory prior to re-allocation if needed. */
227 if (dev->data->queue_pairs[qp_id] != NULL)
228 armv8_crypto_pmd_qp_release(dev, qp_id);
230 /* Allocate the queue pair data structure. */
231 qp = rte_zmalloc_socket("ARMv8 PMD Queue Pair", sizeof(*qp),
232 RTE_CACHE_LINE_SIZE, socket_id);
237 dev->data->queue_pairs[qp_id] = qp;
239 if (armv8_crypto_pmd_qp_set_unique_name(dev, qp) != 0)
240 goto qp_setup_cleanup;
242 qp->processed_ops = armv8_crypto_pmd_qp_create_processed_ops_ring(qp,
243 qp_conf->nb_descriptors, socket_id);
244 if (qp->processed_ops == NULL)
245 goto qp_setup_cleanup;
247 qp->sess_mp = session_pool;
249 memset(&qp->stats, 0, sizeof(qp->stats));
260 /** Start queue pair */
262 armv8_crypto_pmd_qp_start(__rte_unused struct rte_cryptodev *dev,
263 __rte_unused uint16_t queue_pair_id)
268 /** Stop queue pair */
270 armv8_crypto_pmd_qp_stop(__rte_unused struct rte_cryptodev *dev,
271 __rte_unused uint16_t queue_pair_id)
276 /** Return the number of allocated queue pairs */
278 armv8_crypto_pmd_qp_count(struct rte_cryptodev *dev)
280 return dev->data->nb_queue_pairs;
283 /** Returns the size of the session structure */
285 armv8_crypto_pmd_session_get_size(struct rte_cryptodev *dev __rte_unused)
287 return sizeof(struct armv8_crypto_session);
290 /** Configure the session from a crypto xform chain */
292 armv8_crypto_pmd_session_configure(struct rte_cryptodev *dev,
293 struct rte_crypto_sym_xform *xform,
294 struct rte_cryptodev_sym_session *sess,
295 struct rte_mempool *mempool)
297 void *sess_private_data;
300 if (unlikely(sess == NULL)) {
301 ARMV8_CRYPTO_LOG_ERR("invalid session struct");
305 if (rte_mempool_get(mempool, &sess_private_data)) {
307 "Couldn't get object from session mempool");
311 ret = armv8_crypto_set_session_parameters(sess_private_data, xform);
313 ARMV8_CRYPTO_LOG_ERR("failed configure session parameters");
315 /* Return session to mempool */
316 rte_mempool_put(mempool, sess_private_data);
320 set_session_private_data(sess, dev->driver_id,
326 /** Clear the memory of session so it doesn't leave key material behind */
328 armv8_crypto_pmd_session_clear(struct rte_cryptodev *dev,
329 struct rte_cryptodev_sym_session *sess)
331 uint8_t index = dev->driver_id;
332 void *sess_priv = get_session_private_data(sess, index);
334 /* Zero out the whole structure */
336 memset(sess_priv, 0, sizeof(struct armv8_crypto_session));
337 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
338 set_session_private_data(sess, index, NULL);
339 rte_mempool_put(sess_mp, sess_priv);
343 struct rte_cryptodev_ops armv8_crypto_pmd_ops = {
344 .dev_configure = armv8_crypto_pmd_config,
345 .dev_start = armv8_crypto_pmd_start,
346 .dev_stop = armv8_crypto_pmd_stop,
347 .dev_close = armv8_crypto_pmd_close,
349 .stats_get = armv8_crypto_pmd_stats_get,
350 .stats_reset = armv8_crypto_pmd_stats_reset,
352 .dev_infos_get = armv8_crypto_pmd_info_get,
354 .queue_pair_setup = armv8_crypto_pmd_qp_setup,
355 .queue_pair_release = armv8_crypto_pmd_qp_release,
356 .queue_pair_start = armv8_crypto_pmd_qp_start,
357 .queue_pair_stop = armv8_crypto_pmd_qp_stop,
358 .queue_pair_count = armv8_crypto_pmd_qp_count,
360 .session_get_size = armv8_crypto_pmd_session_get_size,
361 .session_configure = armv8_crypto_pmd_session_configure,
362 .session_clear = armv8_crypto_pmd_session_clear
365 struct rte_cryptodev_ops *rte_armv8_crypto_pmd_ops = &armv8_crypto_pmd_ops;