4 * Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <rte_common.h>
36 #include <rte_malloc.h>
37 #include <rte_cryptodev_pmd.h>
39 #include "rte_aesni_mb_pmd_private.h"
42 static const struct rte_cryptodev_capabilities aesni_mb_pmd_capabilities[] = {
44 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
46 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
48 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
65 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
67 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
69 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
86 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
88 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
90 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
107 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
109 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
111 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
128 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
130 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
132 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
149 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
151 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
153 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
169 { /* AES XCBC HMAC */
170 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
172 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
174 .algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC,
191 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
193 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
195 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
211 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
213 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
215 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
230 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
234 /** Configure device */
236 aesni_mb_pmd_config(__rte_unused struct rte_cryptodev *dev,
237 __rte_unused struct rte_cryptodev_config *config)
244 aesni_mb_pmd_start(__rte_unused struct rte_cryptodev *dev)
251 aesni_mb_pmd_stop(__rte_unused struct rte_cryptodev *dev)
257 aesni_mb_pmd_close(__rte_unused struct rte_cryptodev *dev)
263 /** Get device statistics */
265 aesni_mb_pmd_stats_get(struct rte_cryptodev *dev,
266 struct rte_cryptodev_stats *stats)
270 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
271 struct aesni_mb_qp *qp = dev->data->queue_pairs[qp_id];
273 stats->enqueued_count += qp->stats.enqueued_count;
274 stats->dequeued_count += qp->stats.dequeued_count;
276 stats->enqueue_err_count += qp->stats.enqueue_err_count;
277 stats->dequeue_err_count += qp->stats.dequeue_err_count;
281 /** Reset device statistics */
283 aesni_mb_pmd_stats_reset(struct rte_cryptodev *dev)
287 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
288 struct aesni_mb_qp *qp = dev->data->queue_pairs[qp_id];
290 memset(&qp->stats, 0, sizeof(qp->stats));
295 /** Get device info */
297 aesni_mb_pmd_info_get(struct rte_cryptodev *dev,
298 struct rte_cryptodev_info *dev_info)
300 struct aesni_mb_private *internals = dev->data->dev_private;
302 if (dev_info != NULL) {
303 dev_info->dev_type = dev->dev_type;
304 dev_info->feature_flags = dev->feature_flags;
305 dev_info->capabilities = aesni_mb_pmd_capabilities;
306 dev_info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
307 dev_info->sym.max_nb_sessions = internals->max_nb_sessions;
311 /** Release queue pair */
313 aesni_mb_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id)
315 struct aesni_mb_qp *qp = dev->data->queue_pairs[qp_id];
316 struct rte_ring *r = NULL;
319 r = rte_ring_lookup(qp->name);
323 dev->data->queue_pairs[qp_id] = NULL;
328 /** set a unique name for the queue pair based on it's name, dev_id and qp_id */
330 aesni_mb_pmd_qp_set_unique_name(struct rte_cryptodev *dev,
331 struct aesni_mb_qp *qp)
333 unsigned n = snprintf(qp->name, sizeof(qp->name),
334 "aesni_mb_pmd_%u_qp_%u",
335 dev->data->dev_id, qp->id);
337 if (n > sizeof(qp->name))
343 /** Create a ring to place processed operations on */
344 static struct rte_ring *
345 aesni_mb_pmd_qp_create_processed_ops_ring(struct aesni_mb_qp *qp,
346 unsigned ring_size, int socket_id)
350 r = rte_ring_lookup(qp->name);
352 if (rte_ring_get_size(r) >= ring_size) {
353 MB_LOG_INFO("Reusing existing ring %s for processed ops",
358 MB_LOG_ERR("Unable to reuse existing ring %s for processed ops",
363 return rte_ring_create(qp->name, ring_size, socket_id,
364 RING_F_SP_ENQ | RING_F_SC_DEQ);
367 /** Setup a queue pair */
369 aesni_mb_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
370 const struct rte_cryptodev_qp_conf *qp_conf,
373 struct aesni_mb_qp *qp = NULL;
374 struct aesni_mb_private *internals = dev->data->dev_private;
376 /* Free memory prior to re-allocation if needed. */
377 if (dev->data->queue_pairs[qp_id] != NULL)
378 aesni_mb_pmd_qp_release(dev, qp_id);
380 /* Allocate the queue pair data structure. */
381 qp = rte_zmalloc_socket("AES-NI PMD Queue Pair", sizeof(*qp),
382 RTE_CACHE_LINE_SIZE, socket_id);
387 dev->data->queue_pairs[qp_id] = qp;
389 if (aesni_mb_pmd_qp_set_unique_name(dev, qp))
390 goto qp_setup_cleanup;
392 qp->ops = &job_ops[internals->vector_mode];
394 qp->processed_ops = aesni_mb_pmd_qp_create_processed_ops_ring(qp,
395 qp_conf->nb_descriptors, socket_id);
396 if (qp->processed_ops == NULL)
397 goto qp_setup_cleanup;
399 qp->sess_mp = dev->data->session_pool;
401 memset(&qp->stats, 0, sizeof(qp->stats));
403 /* Initialise multi-buffer manager */
404 (*qp->ops->job.init_mgr)(&qp->mb_mgr);
415 /** Start queue pair */
417 aesni_mb_pmd_qp_start(__rte_unused struct rte_cryptodev *dev,
418 __rte_unused uint16_t queue_pair_id)
423 /** Stop queue pair */
425 aesni_mb_pmd_qp_stop(__rte_unused struct rte_cryptodev *dev,
426 __rte_unused uint16_t queue_pair_id)
431 /** Return the number of allocated queue pairs */
433 aesni_mb_pmd_qp_count(struct rte_cryptodev *dev)
435 return dev->data->nb_queue_pairs;
438 /** Returns the size of the aesni multi-buffer session structure */
440 aesni_mb_pmd_session_get_size(struct rte_cryptodev *dev __rte_unused)
442 return sizeof(struct aesni_mb_session);
445 /** Configure a aesni multi-buffer session from a crypto xform chain */
447 aesni_mb_pmd_session_configure(struct rte_cryptodev *dev,
448 struct rte_crypto_sym_xform *xform, void *sess)
450 struct aesni_mb_private *internals = dev->data->dev_private;
452 if (unlikely(sess == NULL)) {
453 MB_LOG_ERR("invalid session struct");
457 if (aesni_mb_set_session_parameters(&job_ops[internals->vector_mode],
459 MB_LOG_ERR("failed configure session parameters");
466 /** Clear the memory of session so it doesn't leave key material behind */
468 aesni_mb_pmd_session_clear(struct rte_cryptodev *dev __rte_unused, void *sess)
471 * Current just resetting the whole data structure, need to investigate
472 * whether a more selective reset of key would be more performant
475 memset(sess, 0, sizeof(struct aesni_mb_session));
478 struct rte_cryptodev_ops aesni_mb_pmd_ops = {
479 .dev_configure = aesni_mb_pmd_config,
480 .dev_start = aesni_mb_pmd_start,
481 .dev_stop = aesni_mb_pmd_stop,
482 .dev_close = aesni_mb_pmd_close,
484 .stats_get = aesni_mb_pmd_stats_get,
485 .stats_reset = aesni_mb_pmd_stats_reset,
487 .dev_infos_get = aesni_mb_pmd_info_get,
489 .queue_pair_setup = aesni_mb_pmd_qp_setup,
490 .queue_pair_release = aesni_mb_pmd_qp_release,
491 .queue_pair_start = aesni_mb_pmd_qp_start,
492 .queue_pair_stop = aesni_mb_pmd_qp_stop,
493 .queue_pair_count = aesni_mb_pmd_qp_count,
495 .session_get_size = aesni_mb_pmd_session_get_size,
496 .session_configure = aesni_mb_pmd_session_configure,
497 .session_clear = aesni_mb_pmd_session_clear
500 struct rte_cryptodev_ops *rte_aesni_mb_pmd_ops = &aesni_mb_pmd_ops;