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,
445 { /* DES DOCSIS BPI */
446 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
448 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
450 .algo = RTE_CRYPTO_CIPHER_DES_DOCSISBPI,
466 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
470 /** Configure device */
472 openssl_pmd_config(__rte_unused struct rte_cryptodev *dev,
473 __rte_unused struct rte_cryptodev_config *config)
480 openssl_pmd_start(__rte_unused struct rte_cryptodev *dev)
487 openssl_pmd_stop(__rte_unused struct rte_cryptodev *dev)
493 openssl_pmd_close(__rte_unused struct rte_cryptodev *dev)
499 /** Get device statistics */
501 openssl_pmd_stats_get(struct rte_cryptodev *dev,
502 struct rte_cryptodev_stats *stats)
506 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
507 struct openssl_qp *qp = dev->data->queue_pairs[qp_id];
509 stats->enqueued_count += qp->stats.enqueued_count;
510 stats->dequeued_count += qp->stats.dequeued_count;
512 stats->enqueue_err_count += qp->stats.enqueue_err_count;
513 stats->dequeue_err_count += qp->stats.dequeue_err_count;
517 /** Reset device statistics */
519 openssl_pmd_stats_reset(struct rte_cryptodev *dev)
523 for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
524 struct openssl_qp *qp = dev->data->queue_pairs[qp_id];
526 memset(&qp->stats, 0, sizeof(qp->stats));
531 /** Get device info */
533 openssl_pmd_info_get(struct rte_cryptodev *dev,
534 struct rte_cryptodev_info *dev_info)
536 struct openssl_private *internals = dev->data->dev_private;
538 if (dev_info != NULL) {
539 dev_info->dev_type = dev->dev_type;
540 dev_info->feature_flags = dev->feature_flags;
541 dev_info->capabilities = openssl_pmd_capabilities;
542 dev_info->max_nb_queue_pairs = internals->max_nb_qpairs;
543 dev_info->sym.max_nb_sessions = internals->max_nb_sessions;
547 /** Release queue pair */
549 openssl_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id)
551 if (dev->data->queue_pairs[qp_id] != NULL) {
552 rte_free(dev->data->queue_pairs[qp_id]);
553 dev->data->queue_pairs[qp_id] = NULL;
558 /** set a unique name for the queue pair based on it's name, dev_id and qp_id */
560 openssl_pmd_qp_set_unique_name(struct rte_cryptodev *dev,
561 struct openssl_qp *qp)
563 unsigned int n = snprintf(qp->name, sizeof(qp->name),
564 "openssl_pmd_%u_qp_%u",
565 dev->data->dev_id, qp->id);
567 if (n > sizeof(qp->name))
574 /** Create a ring to place processed operations on */
575 static struct rte_ring *
576 openssl_pmd_qp_create_processed_ops_ring(struct openssl_qp *qp,
577 unsigned int ring_size, int socket_id)
581 r = rte_ring_lookup(qp->name);
583 if (rte_ring_get_size(r) >= ring_size) {
585 "Reusing existing ring %s for processed ops",
591 "Unable to reuse existing ring %s for processed ops",
596 return rte_ring_create(qp->name, ring_size, socket_id,
597 RING_F_SP_ENQ | RING_F_SC_DEQ);
601 /** Setup a queue pair */
603 openssl_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
604 const struct rte_cryptodev_qp_conf *qp_conf,
607 struct openssl_qp *qp = NULL;
609 /* Free memory prior to re-allocation if needed. */
610 if (dev->data->queue_pairs[qp_id] != NULL)
611 openssl_pmd_qp_release(dev, qp_id);
613 /* Allocate the queue pair data structure. */
614 qp = rte_zmalloc_socket("OPENSSL PMD Queue Pair", sizeof(*qp),
615 RTE_CACHE_LINE_SIZE, socket_id);
620 dev->data->queue_pairs[qp_id] = qp;
622 if (openssl_pmd_qp_set_unique_name(dev, qp))
623 goto qp_setup_cleanup;
625 qp->processed_ops = openssl_pmd_qp_create_processed_ops_ring(qp,
626 qp_conf->nb_descriptors, socket_id);
627 if (qp->processed_ops == NULL)
628 goto qp_setup_cleanup;
630 qp->sess_mp = dev->data->session_pool;
632 memset(&qp->stats, 0, sizeof(qp->stats));
643 /** Start queue pair */
645 openssl_pmd_qp_start(__rte_unused struct rte_cryptodev *dev,
646 __rte_unused uint16_t queue_pair_id)
651 /** Stop queue pair */
653 openssl_pmd_qp_stop(__rte_unused struct rte_cryptodev *dev,
654 __rte_unused uint16_t queue_pair_id)
659 /** Return the number of allocated queue pairs */
661 openssl_pmd_qp_count(struct rte_cryptodev *dev)
663 return dev->data->nb_queue_pairs;
666 /** Returns the size of the session structure */
668 openssl_pmd_session_get_size(struct rte_cryptodev *dev __rte_unused)
670 return sizeof(struct openssl_session);
673 /** Configure the session from a crypto xform chain */
675 openssl_pmd_session_configure(struct rte_cryptodev *dev __rte_unused,
676 struct rte_crypto_sym_xform *xform, void *sess)
678 if (unlikely(sess == NULL)) {
679 OPENSSL_LOG_ERR("invalid session struct");
683 if (openssl_set_session_parameters(
685 OPENSSL_LOG_ERR("failed configure session parameters");
693 /** Clear the memory of session so it doesn't leave key material behind */
695 openssl_pmd_session_clear(struct rte_cryptodev *dev __rte_unused, void *sess)
698 * Current just resetting the whole data structure, need to investigate
699 * whether a more selective reset of key would be more performant
702 openssl_reset_session(sess);
703 memset(sess, 0, sizeof(struct openssl_session));
707 struct rte_cryptodev_ops openssl_pmd_ops = {
708 .dev_configure = openssl_pmd_config,
709 .dev_start = openssl_pmd_start,
710 .dev_stop = openssl_pmd_stop,
711 .dev_close = openssl_pmd_close,
713 .stats_get = openssl_pmd_stats_get,
714 .stats_reset = openssl_pmd_stats_reset,
716 .dev_infos_get = openssl_pmd_info_get,
718 .queue_pair_setup = openssl_pmd_qp_setup,
719 .queue_pair_release = openssl_pmd_qp_release,
720 .queue_pair_start = openssl_pmd_qp_start,
721 .queue_pair_stop = openssl_pmd_qp_stop,
722 .queue_pair_count = openssl_pmd_qp_count,
724 .session_get_size = openssl_pmd_session_get_size,
725 .session_configure = openssl_pmd_session_configure,
726 .session_clear = openssl_pmd_session_clear
729 struct rte_cryptodev_ops *rte_openssl_pmd_ops = &openssl_pmd_ops;