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_pmd_private.h"
13 static const struct rte_cryptodev_capabilities
14 armv8_crypto_pmd_capabilities[] = {
16 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
18 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
20 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
37 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
39 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
41 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
58 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
60 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
62 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
78 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
82 /** Configure device */
84 armv8_crypto_pmd_config(__rte_unused struct rte_cryptodev *dev,
85 __rte_unused struct rte_cryptodev_config *config)
92 armv8_crypto_pmd_start(__rte_unused struct rte_cryptodev *dev)
99 armv8_crypto_pmd_stop(__rte_unused struct rte_cryptodev *dev)
105 armv8_crypto_pmd_close(__rte_unused struct rte_cryptodev *dev)
111 /** Get device statistics */
113 armv8_crypto_pmd_stats_get(struct rte_cryptodev *dev,
114 struct rte_cryptodev_stats *stats)
118 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
119 struct armv8_crypto_qp *qp = dev->data->queue_pairs[qp_id];
121 stats->enqueued_count += qp->stats.enqueued_count;
122 stats->dequeued_count += qp->stats.dequeued_count;
124 stats->enqueue_err_count += qp->stats.enqueue_err_count;
125 stats->dequeue_err_count += qp->stats.dequeue_err_count;
129 /** Reset device statistics */
131 armv8_crypto_pmd_stats_reset(struct rte_cryptodev *dev)
135 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
136 struct armv8_crypto_qp *qp = dev->data->queue_pairs[qp_id];
138 memset(&qp->stats, 0, sizeof(qp->stats));
143 /** Get device info */
145 armv8_crypto_pmd_info_get(struct rte_cryptodev *dev,
146 struct rte_cryptodev_info *dev_info)
148 struct armv8_crypto_private *internals = dev->data->dev_private;
150 if (dev_info != NULL) {
151 dev_info->driver_id = dev->driver_id;
152 dev_info->feature_flags = dev->feature_flags;
153 dev_info->capabilities = armv8_crypto_pmd_capabilities;
154 dev_info->max_nb_queue_pairs = internals->max_nb_qpairs;
155 /* No limit of number of sessions */
156 dev_info->sym.max_nb_sessions = 0;
160 /** Release queue pair */
162 armv8_crypto_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id)
165 if (dev->data->queue_pairs[qp_id] != NULL) {
166 rte_free(dev->data->queue_pairs[qp_id]);
167 dev->data->queue_pairs[qp_id] = NULL;
173 /** set a unique name for the queue pair based on it's name, dev_id and qp_id */
175 armv8_crypto_pmd_qp_set_unique_name(struct rte_cryptodev *dev,
176 struct armv8_crypto_qp *qp)
180 n = snprintf(qp->name, sizeof(qp->name), "armv8_crypto_pmd_%u_qp_%u",
181 dev->data->dev_id, qp->id);
183 if (n >= sizeof(qp->name))
190 /** Create a ring to place processed operations on */
191 static struct rte_ring *
192 armv8_crypto_pmd_qp_create_processed_ops_ring(struct armv8_crypto_qp *qp,
193 unsigned int ring_size, int socket_id)
197 r = rte_ring_lookup(qp->name);
199 if (rte_ring_get_size(r) >= ring_size) {
200 ARMV8_CRYPTO_LOG_INFO(
201 "Reusing existing ring %s for processed ops",
206 ARMV8_CRYPTO_LOG_ERR(
207 "Unable to reuse existing ring %s for processed ops",
212 return rte_ring_create(qp->name, ring_size, socket_id,
213 RING_F_SP_ENQ | RING_F_SC_DEQ);
217 /** Setup a queue pair */
219 armv8_crypto_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
220 const struct rte_cryptodev_qp_conf *qp_conf,
223 struct armv8_crypto_qp *qp = NULL;
225 /* Free memory prior to re-allocation if needed. */
226 if (dev->data->queue_pairs[qp_id] != NULL)
227 armv8_crypto_pmd_qp_release(dev, qp_id);
229 /* Allocate the queue pair data structure. */
230 qp = rte_zmalloc_socket("ARMv8 PMD Queue Pair", sizeof(*qp),
231 RTE_CACHE_LINE_SIZE, socket_id);
236 dev->data->queue_pairs[qp_id] = qp;
238 if (armv8_crypto_pmd_qp_set_unique_name(dev, qp) != 0)
239 goto qp_setup_cleanup;
241 qp->processed_ops = armv8_crypto_pmd_qp_create_processed_ops_ring(qp,
242 qp_conf->nb_descriptors, socket_id);
243 if (qp->processed_ops == NULL)
244 goto qp_setup_cleanup;
246 qp->sess_mp = qp_conf->mp_session;
247 qp->sess_mp_priv = qp_conf->mp_session_private;
249 memset(&qp->stats, 0, sizeof(qp->stats));
260 /** Returns the size of the session structure */
262 armv8_crypto_pmd_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
264 return sizeof(struct armv8_crypto_session);
267 /** Configure the session from a crypto xform chain */
269 armv8_crypto_pmd_sym_session_configure(struct rte_cryptodev *dev,
270 struct rte_crypto_sym_xform *xform,
271 struct rte_cryptodev_sym_session *sess,
272 struct rte_mempool *mempool)
274 void *sess_private_data;
277 if (unlikely(sess == NULL)) {
278 ARMV8_CRYPTO_LOG_ERR("invalid session struct");
282 if (rte_mempool_get(mempool, &sess_private_data)) {
284 "Couldn't get object from session mempool");
288 ret = armv8_crypto_set_session_parameters(sess_private_data, xform);
290 ARMV8_CRYPTO_LOG_ERR("failed configure session parameters");
292 /* Return session to mempool */
293 rte_mempool_put(mempool, sess_private_data);
297 set_sym_session_private_data(sess, dev->driver_id,
303 /** Clear the memory of session so it doesn't leave key material behind */
305 armv8_crypto_pmd_sym_session_clear(struct rte_cryptodev *dev,
306 struct rte_cryptodev_sym_session *sess)
308 uint8_t index = dev->driver_id;
309 void *sess_priv = get_sym_session_private_data(sess, index);
311 /* Zero out the whole structure */
313 memset(sess_priv, 0, sizeof(struct armv8_crypto_session));
314 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
315 set_sym_session_private_data(sess, index, NULL);
316 rte_mempool_put(sess_mp, sess_priv);
320 struct rte_cryptodev_ops armv8_crypto_pmd_ops = {
321 .dev_configure = armv8_crypto_pmd_config,
322 .dev_start = armv8_crypto_pmd_start,
323 .dev_stop = armv8_crypto_pmd_stop,
324 .dev_close = armv8_crypto_pmd_close,
326 .stats_get = armv8_crypto_pmd_stats_get,
327 .stats_reset = armv8_crypto_pmd_stats_reset,
329 .dev_infos_get = armv8_crypto_pmd_info_get,
331 .queue_pair_setup = armv8_crypto_pmd_qp_setup,
332 .queue_pair_release = armv8_crypto_pmd_qp_release,
334 .sym_session_get_size = armv8_crypto_pmd_sym_session_get_size,
335 .sym_session_configure = armv8_crypto_pmd_sym_session_configure,
336 .sym_session_clear = armv8_crypto_pmd_sym_session_clear
339 struct rte_cryptodev_ops *rte_armv8_crypto_pmd_ops = &armv8_crypto_pmd_ops;