4 * Copyright(c) 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_openssl_pmd_private.h"
42 static const struct rte_cryptodev_capabilities openssl_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_MD5,
86 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
88 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
90 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
107 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
109 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
111 .algo = RTE_CRYPTO_AUTH_SHA1,
128 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
130 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
132 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
149 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
151 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
153 .algo = RTE_CRYPTO_AUTH_SHA224,
170 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
172 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
174 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
191 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
193 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
195 .algo = RTE_CRYPTO_AUTH_SHA256,
212 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
214 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
216 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
233 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
235 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
237 .algo = RTE_CRYPTO_AUTH_SHA384,
254 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
256 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
258 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
275 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
277 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
279 .algo = RTE_CRYPTO_AUTH_SHA512,
296 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
298 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
300 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
316 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
318 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
320 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
335 { /* AES GCM (AUTH) */
336 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
338 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
340 .algo = RTE_CRYPTO_AUTH_AES_GCM,
360 { /* AES GCM (CIPHER) */
361 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
363 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
365 .algo = RTE_CRYPTO_CIPHER_AES_GCM,
380 { /* AES GMAC (AUTH) */
381 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
383 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
385 .algo = RTE_CRYPTO_AUTH_AES_GMAC,
406 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
408 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
410 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
426 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
428 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
430 .algo = RTE_CRYPTO_CIPHER_3DES_CTR,
446 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
450 /** Configure device */
452 openssl_pmd_config(__rte_unused struct rte_cryptodev *dev)
459 openssl_pmd_start(__rte_unused struct rte_cryptodev *dev)
466 openssl_pmd_stop(__rte_unused struct rte_cryptodev *dev)
472 openssl_pmd_close(__rte_unused struct rte_cryptodev *dev)
478 /** Get device statistics */
480 openssl_pmd_stats_get(struct rte_cryptodev *dev,
481 struct rte_cryptodev_stats *stats)
485 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
486 struct openssl_qp *qp = dev->data->queue_pairs[qp_id];
488 stats->enqueued_count += qp->stats.enqueued_count;
489 stats->dequeued_count += qp->stats.dequeued_count;
491 stats->enqueue_err_count += qp->stats.enqueue_err_count;
492 stats->dequeue_err_count += qp->stats.dequeue_err_count;
496 /** Reset device statistics */
498 openssl_pmd_stats_reset(struct rte_cryptodev *dev)
502 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
503 struct openssl_qp *qp = dev->data->queue_pairs[qp_id];
505 memset(&qp->stats, 0, sizeof(qp->stats));
510 /** Get device info */
512 openssl_pmd_info_get(struct rte_cryptodev *dev,
513 struct rte_cryptodev_info *dev_info)
515 struct openssl_private *internals = dev->data->dev_private;
517 if (dev_info != NULL) {
518 dev_info->dev_type = dev->dev_type;
519 dev_info->feature_flags = dev->feature_flags;
520 dev_info->capabilities = openssl_pmd_capabilities;
521 dev_info->max_nb_queue_pairs = internals->max_nb_qpairs;
522 dev_info->sym.max_nb_sessions = internals->max_nb_sessions;
526 /** Release queue pair */
528 openssl_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id)
530 if (dev->data->queue_pairs[qp_id] != NULL) {
531 rte_free(dev->data->queue_pairs[qp_id]);
532 dev->data->queue_pairs[qp_id] = NULL;
537 /** set a unique name for the queue pair based on it's name, dev_id and qp_id */
539 openssl_pmd_qp_set_unique_name(struct rte_cryptodev *dev,
540 struct openssl_qp *qp)
542 unsigned int n = snprintf(qp->name, sizeof(qp->name),
543 "openssl_pmd_%u_qp_%u",
544 dev->data->dev_id, qp->id);
546 if (n > sizeof(qp->name))
553 /** Create a ring to place processed operations on */
554 static struct rte_ring *
555 openssl_pmd_qp_create_processed_ops_ring(struct openssl_qp *qp,
556 unsigned int ring_size, int socket_id)
560 r = rte_ring_lookup(qp->name);
562 if (r->prod.size >= ring_size) {
564 "Reusing existing ring %s for processed ops",
570 "Unable to reuse existing ring %s for processed ops",
575 return rte_ring_create(qp->name, ring_size, socket_id,
576 RING_F_SP_ENQ | RING_F_SC_DEQ);
580 /** Setup a queue pair */
582 openssl_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
583 const struct rte_cryptodev_qp_conf *qp_conf,
586 struct openssl_qp *qp = NULL;
588 /* Free memory prior to re-allocation if needed. */
589 if (dev->data->queue_pairs[qp_id] != NULL)
590 openssl_pmd_qp_release(dev, qp_id);
592 /* Allocate the queue pair data structure. */
593 qp = rte_zmalloc_socket("OPENSSL PMD Queue Pair", sizeof(*qp),
594 RTE_CACHE_LINE_SIZE, socket_id);
599 dev->data->queue_pairs[qp_id] = qp;
601 if (openssl_pmd_qp_set_unique_name(dev, qp))
602 goto qp_setup_cleanup;
604 qp->processed_ops = openssl_pmd_qp_create_processed_ops_ring(qp,
605 qp_conf->nb_descriptors, socket_id);
606 if (qp->processed_ops == NULL)
607 goto qp_setup_cleanup;
609 qp->sess_mp = dev->data->session_pool;
611 memset(&qp->stats, 0, sizeof(qp->stats));
622 /** Start queue pair */
624 openssl_pmd_qp_start(__rte_unused struct rte_cryptodev *dev,
625 __rte_unused uint16_t queue_pair_id)
630 /** Stop queue pair */
632 openssl_pmd_qp_stop(__rte_unused struct rte_cryptodev *dev,
633 __rte_unused uint16_t queue_pair_id)
638 /** Return the number of allocated queue pairs */
640 openssl_pmd_qp_count(struct rte_cryptodev *dev)
642 return dev->data->nb_queue_pairs;
645 /** Returns the size of the session structure */
647 openssl_pmd_session_get_size(struct rte_cryptodev *dev __rte_unused)
649 return sizeof(struct openssl_session);
652 /** Configure the session from a crypto xform chain */
654 openssl_pmd_session_configure(struct rte_cryptodev *dev __rte_unused,
655 struct rte_crypto_sym_xform *xform, void *sess)
657 if (unlikely(sess == NULL)) {
658 OPENSSL_LOG_ERR("invalid session struct");
662 if (openssl_set_session_parameters(
664 OPENSSL_LOG_ERR("failed configure session parameters");
672 /** Clear the memory of session so it doesn't leave key material behind */
674 openssl_pmd_session_clear(struct rte_cryptodev *dev __rte_unused, void *sess)
677 * Current just resetting the whole data structure, need to investigate
678 * whether a more selective reset of key would be more performant
681 openssl_reset_session(sess);
682 memset(sess, 0, sizeof(struct openssl_session));
686 struct rte_cryptodev_ops openssl_pmd_ops = {
687 .dev_configure = openssl_pmd_config,
688 .dev_start = openssl_pmd_start,
689 .dev_stop = openssl_pmd_stop,
690 .dev_close = openssl_pmd_close,
692 .stats_get = openssl_pmd_stats_get,
693 .stats_reset = openssl_pmd_stats_reset,
695 .dev_infos_get = openssl_pmd_info_get,
697 .queue_pair_setup = openssl_pmd_qp_setup,
698 .queue_pair_release = openssl_pmd_qp_release,
699 .queue_pair_start = openssl_pmd_qp_start,
700 .queue_pair_stop = openssl_pmd_qp_stop,
701 .queue_pair_count = openssl_pmd_qp_count,
703 .session_get_size = openssl_pmd_session_get_size,
704 .session_configure = openssl_pmd_session_configure,
705 .session_clear = openssl_pmd_session_clear
708 struct rte_cryptodev_ops *rte_openssl_pmd_ops = &openssl_pmd_ops;