xref: /dpdk/drivers/crypto/null/null_crypto_pmd_ops.c (revision b3bbd9e5f265937164ed8c9c61d12f7543a745ea)
194b0ad8eSDeclan Doherty /*-
294b0ad8eSDeclan Doherty  *   BSD LICENSE
394b0ad8eSDeclan Doherty  *
4acf86169SPablo de Lara  *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
594b0ad8eSDeclan Doherty  *
694b0ad8eSDeclan Doherty  *   Redistribution and use in source and binary forms, with or without
794b0ad8eSDeclan Doherty  *   modification, are permitted provided that the following conditions
894b0ad8eSDeclan Doherty  *   are met:
994b0ad8eSDeclan Doherty  *
1094b0ad8eSDeclan Doherty  *     * Redistributions of source code must retain the above copyright
1194b0ad8eSDeclan Doherty  *       notice, this list of conditions and the following disclaimer.
1294b0ad8eSDeclan Doherty  *     * Redistributions in binary form must reproduce the above copyright
1394b0ad8eSDeclan Doherty  *       notice, this list of conditions and the following disclaimer in
1494b0ad8eSDeclan Doherty  *       the documentation and/or other materials provided with the
1594b0ad8eSDeclan Doherty  *       distribution.
1694b0ad8eSDeclan Doherty  *     * Neither the name of Intel Corporation nor the names of its
1794b0ad8eSDeclan Doherty  *       contributors may be used to endorse or promote products derived
1894b0ad8eSDeclan Doherty  *       from this software without specific prior written permission.
1994b0ad8eSDeclan Doherty  *
2094b0ad8eSDeclan Doherty  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2194b0ad8eSDeclan Doherty  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2294b0ad8eSDeclan Doherty  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2394b0ad8eSDeclan Doherty  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2494b0ad8eSDeclan Doherty  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2594b0ad8eSDeclan Doherty  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2694b0ad8eSDeclan Doherty  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2794b0ad8eSDeclan Doherty  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2894b0ad8eSDeclan Doherty  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2994b0ad8eSDeclan Doherty  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3094b0ad8eSDeclan Doherty  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3194b0ad8eSDeclan Doherty  */
3294b0ad8eSDeclan Doherty 
3394b0ad8eSDeclan Doherty #include <string.h>
3494b0ad8eSDeclan Doherty 
3594b0ad8eSDeclan Doherty #include <rte_common.h>
3694b0ad8eSDeclan Doherty #include <rte_malloc.h>
3794b0ad8eSDeclan Doherty #include <rte_cryptodev_pmd.h>
3894b0ad8eSDeclan Doherty 
3994b0ad8eSDeclan Doherty #include "null_crypto_pmd_private.h"
4094b0ad8eSDeclan Doherty 
4126c2e4adSDeclan Doherty static const struct rte_cryptodev_capabilities null_crypto_pmd_capabilities[] = {
4226c2e4adSDeclan Doherty 	{	/* NULL (AUTH) */
4326c2e4adSDeclan Doherty 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
44ff150afdSFiona Trahe 		{.sym = {
4526c2e4adSDeclan Doherty 			.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
46ff150afdSFiona Trahe 			{.auth = {
4726c2e4adSDeclan Doherty 				.algo = RTE_CRYPTO_AUTH_NULL,
4826c2e4adSDeclan Doherty 				.block_size = 1,
4926c2e4adSDeclan Doherty 				.key_size = {
5026c2e4adSDeclan Doherty 					.min = 0,
5126c2e4adSDeclan Doherty 					.max = 0,
5226c2e4adSDeclan Doherty 					.increment = 0
5326c2e4adSDeclan Doherty 				},
5426c2e4adSDeclan Doherty 				.digest_size = {
5526c2e4adSDeclan Doherty 					.min = 0,
5626c2e4adSDeclan Doherty 					.max = 0,
5726c2e4adSDeclan Doherty 					.increment = 0
5826c2e4adSDeclan Doherty 				},
59acf86169SPablo de Lara 				.aad_size = { 0 },
60acf86169SPablo de Lara 				.iv_size = { 0 }
61ff150afdSFiona Trahe 			}, },
62ff150afdSFiona Trahe 		}, },
6326c2e4adSDeclan Doherty 	},
6426c2e4adSDeclan Doherty 	{	/* NULL (CIPHER) */
6526c2e4adSDeclan Doherty 		.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
66ff150afdSFiona Trahe 		{.sym = {
6726c2e4adSDeclan Doherty 			.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
68ff150afdSFiona Trahe 			{.cipher = {
6926c2e4adSDeclan Doherty 				.algo = RTE_CRYPTO_CIPHER_NULL,
7026c2e4adSDeclan Doherty 				.block_size = 1,
7126c2e4adSDeclan Doherty 				.key_size = {
7226c2e4adSDeclan Doherty 					.min = 0,
7326c2e4adSDeclan Doherty 					.max = 0,
746bc43003SDeepak Kumar Jain 					.increment = 0
7526c2e4adSDeclan Doherty 				},
760fbd75a9SPablo de Lara 				.iv_size = { 0 }
77ff150afdSFiona Trahe 			}, },
78ff150afdSFiona Trahe 		}, }
7926c2e4adSDeclan Doherty 	},
8026c2e4adSDeclan Doherty 	RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
8126c2e4adSDeclan Doherty };
8226c2e4adSDeclan Doherty 
8394b0ad8eSDeclan Doherty /** Configure device */
8494b0ad8eSDeclan Doherty static int
8560e686c2SFan Zhang null_crypto_pmd_config(__rte_unused struct rte_cryptodev *dev,
8660e686c2SFan Zhang 		__rte_unused struct rte_cryptodev_config *config)
8794b0ad8eSDeclan Doherty {
8894b0ad8eSDeclan Doherty 	return 0;
8994b0ad8eSDeclan Doherty }
9094b0ad8eSDeclan Doherty 
9194b0ad8eSDeclan Doherty /** Start device */
9294b0ad8eSDeclan Doherty static int
9394b0ad8eSDeclan Doherty null_crypto_pmd_start(__rte_unused struct rte_cryptodev *dev)
9494b0ad8eSDeclan Doherty {
9594b0ad8eSDeclan Doherty 	return 0;
9694b0ad8eSDeclan Doherty }
9794b0ad8eSDeclan Doherty 
9894b0ad8eSDeclan Doherty /** Stop device */
9994b0ad8eSDeclan Doherty static void
10094b0ad8eSDeclan Doherty null_crypto_pmd_stop(__rte_unused struct rte_cryptodev *dev)
10194b0ad8eSDeclan Doherty {
10294b0ad8eSDeclan Doherty }
10394b0ad8eSDeclan Doherty 
10494b0ad8eSDeclan Doherty /** Close device */
10594b0ad8eSDeclan Doherty static int
10694b0ad8eSDeclan Doherty null_crypto_pmd_close(__rte_unused struct rte_cryptodev *dev)
10794b0ad8eSDeclan Doherty {
10894b0ad8eSDeclan Doherty 	return 0;
10994b0ad8eSDeclan Doherty }
11094b0ad8eSDeclan Doherty 
11194b0ad8eSDeclan Doherty /** Get device statistics */
11294b0ad8eSDeclan Doherty static void
11394b0ad8eSDeclan Doherty null_crypto_pmd_stats_get(struct rte_cryptodev *dev,
11494b0ad8eSDeclan Doherty 		struct rte_cryptodev_stats *stats)
11594b0ad8eSDeclan Doherty {
11694b0ad8eSDeclan Doherty 	int qp_id;
11794b0ad8eSDeclan Doherty 
11894b0ad8eSDeclan Doherty 	for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
11994b0ad8eSDeclan Doherty 		struct null_crypto_qp *qp = dev->data->queue_pairs[qp_id];
12094b0ad8eSDeclan Doherty 
12194b0ad8eSDeclan Doherty 		stats->enqueued_count += qp->qp_stats.enqueued_count;
12294b0ad8eSDeclan Doherty 		stats->dequeued_count += qp->qp_stats.dequeued_count;
12394b0ad8eSDeclan Doherty 
12494b0ad8eSDeclan Doherty 		stats->enqueue_err_count += qp->qp_stats.enqueue_err_count;
12594b0ad8eSDeclan Doherty 		stats->dequeue_err_count += qp->qp_stats.dequeue_err_count;
12694b0ad8eSDeclan Doherty 	}
12794b0ad8eSDeclan Doherty }
12894b0ad8eSDeclan Doherty 
12994b0ad8eSDeclan Doherty /** Reset device statistics */
13094b0ad8eSDeclan Doherty static void
13194b0ad8eSDeclan Doherty null_crypto_pmd_stats_reset(struct rte_cryptodev *dev)
13294b0ad8eSDeclan Doherty {
13394b0ad8eSDeclan Doherty 	int qp_id;
13494b0ad8eSDeclan Doherty 
13594b0ad8eSDeclan Doherty 	for (qp_id = 0; qp_id < dev->data->nb_queue_pairs; qp_id++) {
13694b0ad8eSDeclan Doherty 		struct null_crypto_qp *qp = dev->data->queue_pairs[qp_id];
13794b0ad8eSDeclan Doherty 
13894b0ad8eSDeclan Doherty 		memset(&qp->qp_stats, 0, sizeof(qp->qp_stats));
13994b0ad8eSDeclan Doherty 	}
14094b0ad8eSDeclan Doherty }
14194b0ad8eSDeclan Doherty 
14294b0ad8eSDeclan Doherty 
14394b0ad8eSDeclan Doherty /** Get device info */
14494b0ad8eSDeclan Doherty static void
14594b0ad8eSDeclan Doherty null_crypto_pmd_info_get(struct rte_cryptodev *dev,
14694b0ad8eSDeclan Doherty 		struct rte_cryptodev_info *dev_info)
14794b0ad8eSDeclan Doherty {
14894b0ad8eSDeclan Doherty 	struct null_crypto_private *internals = dev->data->dev_private;
14994b0ad8eSDeclan Doherty 
15094b0ad8eSDeclan Doherty 	if (dev_info != NULL) {
1517a364faeSSlawomir Mrozowicz 		dev_info->driver_id = dev->driver_id;
15294b0ad8eSDeclan Doherty 		dev_info->max_nb_queue_pairs = internals->max_nb_qpairs;
15394b0ad8eSDeclan Doherty 		dev_info->sym.max_nb_sessions = internals->max_nb_sessions;
15426c2e4adSDeclan Doherty 		dev_info->feature_flags = dev->feature_flags;
15526c2e4adSDeclan Doherty 		dev_info->capabilities = null_crypto_pmd_capabilities;
15694b0ad8eSDeclan Doherty 	}
15794b0ad8eSDeclan Doherty }
15894b0ad8eSDeclan Doherty 
15994b0ad8eSDeclan Doherty /** Release queue pair */
16094b0ad8eSDeclan Doherty static int
16194b0ad8eSDeclan Doherty null_crypto_pmd_qp_release(struct rte_cryptodev *dev, uint16_t qp_id)
16294b0ad8eSDeclan Doherty {
16394b0ad8eSDeclan Doherty 	if (dev->data->queue_pairs[qp_id] != NULL) {
16494b0ad8eSDeclan Doherty 		rte_free(dev->data->queue_pairs[qp_id]);
16594b0ad8eSDeclan Doherty 		dev->data->queue_pairs[qp_id] = NULL;
16694b0ad8eSDeclan Doherty 	}
16794b0ad8eSDeclan Doherty 	return 0;
16894b0ad8eSDeclan Doherty }
16994b0ad8eSDeclan Doherty 
17094b0ad8eSDeclan Doherty /** set a unique name for the queue pair based on it's name, dev_id and qp_id */
17194b0ad8eSDeclan Doherty static int
17294b0ad8eSDeclan Doherty null_crypto_pmd_qp_set_unique_name(struct rte_cryptodev *dev,
17394b0ad8eSDeclan Doherty 		struct null_crypto_qp *qp)
17494b0ad8eSDeclan Doherty {
17594b0ad8eSDeclan Doherty 	unsigned n = snprintf(qp->name, sizeof(qp->name),
17694b0ad8eSDeclan Doherty 			"null_crypto_pmd_%u_qp_%u",
17794b0ad8eSDeclan Doherty 			dev->data->dev_id, qp->id);
17894b0ad8eSDeclan Doherty 
17994b0ad8eSDeclan Doherty 	if (n > sizeof(qp->name))
18094b0ad8eSDeclan Doherty 		return -1;
18194b0ad8eSDeclan Doherty 
18294b0ad8eSDeclan Doherty 	return 0;
18394b0ad8eSDeclan Doherty }
18494b0ad8eSDeclan Doherty 
18594b0ad8eSDeclan Doherty /** Create a ring to place process packets on */
18694b0ad8eSDeclan Doherty static struct rte_ring *
18794b0ad8eSDeclan Doherty null_crypto_pmd_qp_create_processed_pkts_ring(struct null_crypto_qp *qp,
18894b0ad8eSDeclan Doherty 		unsigned ring_size, int socket_id)
18994b0ad8eSDeclan Doherty {
19094b0ad8eSDeclan Doherty 	struct rte_ring *r;
19194b0ad8eSDeclan Doherty 
19294b0ad8eSDeclan Doherty 	r = rte_ring_lookup(qp->name);
19394b0ad8eSDeclan Doherty 	if (r) {
194b11c78a2SBruce Richardson 		if (rte_ring_get_size(r) >= ring_size) {
19594b0ad8eSDeclan Doherty 			NULL_CRYPTO_LOG_INFO(
19694b0ad8eSDeclan Doherty 				"Reusing existing ring %s for processed packets",
19794b0ad8eSDeclan Doherty 				qp->name);
19894b0ad8eSDeclan Doherty 			return r;
19994b0ad8eSDeclan Doherty 		}
20094b0ad8eSDeclan Doherty 
20194b0ad8eSDeclan Doherty 		NULL_CRYPTO_LOG_INFO(
20294b0ad8eSDeclan Doherty 			"Unable to reuse existing ring %s for processed packets",
20394b0ad8eSDeclan Doherty 			 qp->name);
20494b0ad8eSDeclan Doherty 		return NULL;
20594b0ad8eSDeclan Doherty 	}
20694b0ad8eSDeclan Doherty 
20794b0ad8eSDeclan Doherty 	return rte_ring_create(qp->name, ring_size, socket_id,
20894b0ad8eSDeclan Doherty 			RING_F_SP_ENQ | RING_F_SC_DEQ);
20994b0ad8eSDeclan Doherty }
21094b0ad8eSDeclan Doherty 
21194b0ad8eSDeclan Doherty /** Setup a queue pair */
21294b0ad8eSDeclan Doherty static int
21394b0ad8eSDeclan Doherty null_crypto_pmd_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id,
21494b0ad8eSDeclan Doherty 		const struct rte_cryptodev_qp_conf *qp_conf,
21594b0ad8eSDeclan Doherty 		 int socket_id)
21694b0ad8eSDeclan Doherty {
21794b0ad8eSDeclan Doherty 	struct null_crypto_private *internals = dev->data->dev_private;
21894b0ad8eSDeclan Doherty 	struct null_crypto_qp *qp;
21994b0ad8eSDeclan Doherty 	int retval;
22094b0ad8eSDeclan Doherty 
22194b0ad8eSDeclan Doherty 	if (qp_id >= internals->max_nb_qpairs) {
22294b0ad8eSDeclan Doherty 		NULL_CRYPTO_LOG_ERR("Invalid qp_id %u, greater than maximum "
22394b0ad8eSDeclan Doherty 				"number of queue pairs supported (%u).",
22494b0ad8eSDeclan Doherty 				qp_id, internals->max_nb_qpairs);
22594b0ad8eSDeclan Doherty 		return (-EINVAL);
22694b0ad8eSDeclan Doherty 	}
22794b0ad8eSDeclan Doherty 
22894b0ad8eSDeclan Doherty 	/* Free memory prior to re-allocation if needed. */
22994b0ad8eSDeclan Doherty 	if (dev->data->queue_pairs[qp_id] != NULL)
23094b0ad8eSDeclan Doherty 		null_crypto_pmd_qp_release(dev, qp_id);
23194b0ad8eSDeclan Doherty 
23294b0ad8eSDeclan Doherty 	/* Allocate the queue pair data structure. */
23394b0ad8eSDeclan Doherty 	qp = rte_zmalloc_socket("Null Crypto PMD Queue Pair", sizeof(*qp),
23494b0ad8eSDeclan Doherty 					RTE_CACHE_LINE_SIZE, socket_id);
23594b0ad8eSDeclan Doherty 	if (qp == NULL) {
23694b0ad8eSDeclan Doherty 		NULL_CRYPTO_LOG_ERR("Failed to allocate queue pair memory");
23794b0ad8eSDeclan Doherty 		return (-ENOMEM);
23894b0ad8eSDeclan Doherty 	}
23994b0ad8eSDeclan Doherty 
24094b0ad8eSDeclan Doherty 	qp->id = qp_id;
24194b0ad8eSDeclan Doherty 	dev->data->queue_pairs[qp_id] = qp;
24294b0ad8eSDeclan Doherty 
24394b0ad8eSDeclan Doherty 	retval = null_crypto_pmd_qp_set_unique_name(dev, qp);
24494b0ad8eSDeclan Doherty 	if (retval) {
24594b0ad8eSDeclan Doherty 		NULL_CRYPTO_LOG_ERR("Failed to create unique name for null "
24694b0ad8eSDeclan Doherty 				"crypto device");
24794b0ad8eSDeclan Doherty 		goto qp_setup_cleanup;
24894b0ad8eSDeclan Doherty 	}
24994b0ad8eSDeclan Doherty 
25094b0ad8eSDeclan Doherty 	qp->processed_pkts = null_crypto_pmd_qp_create_processed_pkts_ring(qp,
25194b0ad8eSDeclan Doherty 			qp_conf->nb_descriptors, socket_id);
25294b0ad8eSDeclan Doherty 	if (qp->processed_pkts == NULL) {
25394b0ad8eSDeclan Doherty 		NULL_CRYPTO_LOG_ERR("Failed to create unique name for null "
25494b0ad8eSDeclan Doherty 				"crypto device");
25594b0ad8eSDeclan Doherty 		goto qp_setup_cleanup;
25694b0ad8eSDeclan Doherty 	}
25794b0ad8eSDeclan Doherty 
25894b0ad8eSDeclan Doherty 	qp->sess_mp = dev->data->session_pool;
25994b0ad8eSDeclan Doherty 
26094b0ad8eSDeclan Doherty 	memset(&qp->qp_stats, 0, sizeof(qp->qp_stats));
26194b0ad8eSDeclan Doherty 
26294b0ad8eSDeclan Doherty 	return 0;
26394b0ad8eSDeclan Doherty 
26494b0ad8eSDeclan Doherty qp_setup_cleanup:
26594b0ad8eSDeclan Doherty 	if (qp)
26694b0ad8eSDeclan Doherty 		rte_free(qp);
26794b0ad8eSDeclan Doherty 
26894b0ad8eSDeclan Doherty 	return -1;
26994b0ad8eSDeclan Doherty }
27094b0ad8eSDeclan Doherty 
27194b0ad8eSDeclan Doherty /** Start queue pair */
27294b0ad8eSDeclan Doherty static int
27394b0ad8eSDeclan Doherty null_crypto_pmd_qp_start(__rte_unused struct rte_cryptodev *dev,
27494b0ad8eSDeclan Doherty 		__rte_unused uint16_t queue_pair_id)
27594b0ad8eSDeclan Doherty {
27694b0ad8eSDeclan Doherty 	return -ENOTSUP;
27794b0ad8eSDeclan Doherty }
27894b0ad8eSDeclan Doherty 
27994b0ad8eSDeclan Doherty /** Stop queue pair */
28094b0ad8eSDeclan Doherty static int
28194b0ad8eSDeclan Doherty null_crypto_pmd_qp_stop(__rte_unused struct rte_cryptodev *dev,
28294b0ad8eSDeclan Doherty 		__rte_unused uint16_t queue_pair_id)
28394b0ad8eSDeclan Doherty {
28494b0ad8eSDeclan Doherty 	return -ENOTSUP;
28594b0ad8eSDeclan Doherty }
28694b0ad8eSDeclan Doherty 
28794b0ad8eSDeclan Doherty /** Return the number of allocated queue pairs */
28894b0ad8eSDeclan Doherty static uint32_t
28994b0ad8eSDeclan Doherty null_crypto_pmd_qp_count(struct rte_cryptodev *dev)
29094b0ad8eSDeclan Doherty {
29194b0ad8eSDeclan Doherty 	return dev->data->nb_queue_pairs;
29294b0ad8eSDeclan Doherty }
29394b0ad8eSDeclan Doherty 
29494b0ad8eSDeclan Doherty /** Returns the size of the NULL crypto session structure */
29594b0ad8eSDeclan Doherty static unsigned
29694b0ad8eSDeclan Doherty null_crypto_pmd_session_get_size(struct rte_cryptodev *dev __rte_unused)
29794b0ad8eSDeclan Doherty {
29894b0ad8eSDeclan Doherty 	return sizeof(struct null_crypto_session);
29994b0ad8eSDeclan Doherty }
30094b0ad8eSDeclan Doherty 
30194b0ad8eSDeclan Doherty /** Configure a null crypto session from a crypto xform chain */
302*b3bbd9e5SSlawomir Mrozowicz static int
30394b0ad8eSDeclan Doherty null_crypto_pmd_session_configure(struct rte_cryptodev *dev __rte_unused,
304*b3bbd9e5SSlawomir Mrozowicz 		struct rte_crypto_sym_xform *xform,
305*b3bbd9e5SSlawomir Mrozowicz 		struct rte_cryptodev_sym_session *sess,
306*b3bbd9e5SSlawomir Mrozowicz 		struct rte_mempool *mp)
30794b0ad8eSDeclan Doherty {
308*b3bbd9e5SSlawomir Mrozowicz 	void *sess_private_data;
30994b0ad8eSDeclan Doherty 
31094b0ad8eSDeclan Doherty 	if (unlikely(sess == NULL)) {
31194b0ad8eSDeclan Doherty 		NULL_CRYPTO_LOG_ERR("invalid session struct");
312*b3bbd9e5SSlawomir Mrozowicz 		return -1;
31394b0ad8eSDeclan Doherty 	}
31494b0ad8eSDeclan Doherty 
315*b3bbd9e5SSlawomir Mrozowicz 	if (rte_mempool_get(mp, &sess_private_data)) {
316*b3bbd9e5SSlawomir Mrozowicz 		CDEV_LOG_ERR(
317*b3bbd9e5SSlawomir Mrozowicz 			"Couldn't get object from session mempool");
318*b3bbd9e5SSlawomir Mrozowicz 		return -1;
319*b3bbd9e5SSlawomir Mrozowicz 	}
320*b3bbd9e5SSlawomir Mrozowicz 
321*b3bbd9e5SSlawomir Mrozowicz 	if (null_crypto_set_session_parameters(sess_private_data, xform) != 0) {
322*b3bbd9e5SSlawomir Mrozowicz 		NULL_CRYPTO_LOG_ERR("failed configure session parameters");
323*b3bbd9e5SSlawomir Mrozowicz 
324*b3bbd9e5SSlawomir Mrozowicz 		/* Return session to mempool */
325*b3bbd9e5SSlawomir Mrozowicz 		rte_mempool_put(mp, sess_private_data);
326*b3bbd9e5SSlawomir Mrozowicz 		return -1;
327*b3bbd9e5SSlawomir Mrozowicz 	}
328*b3bbd9e5SSlawomir Mrozowicz 
329*b3bbd9e5SSlawomir Mrozowicz 	set_session_private_data(sess, dev->driver_id,
330*b3bbd9e5SSlawomir Mrozowicz 		sess_private_data);
331*b3bbd9e5SSlawomir Mrozowicz 
332*b3bbd9e5SSlawomir Mrozowicz 	return 0;
33394b0ad8eSDeclan Doherty }
33494b0ad8eSDeclan Doherty 
33594b0ad8eSDeclan Doherty /** Clear the memory of session so it doesn't leave key material behind */
33694b0ad8eSDeclan Doherty static void
337*b3bbd9e5SSlawomir Mrozowicz null_crypto_pmd_session_clear(struct rte_cryptodev *dev,
338*b3bbd9e5SSlawomir Mrozowicz 		struct rte_cryptodev_sym_session *sess)
33994b0ad8eSDeclan Doherty {
340*b3bbd9e5SSlawomir Mrozowicz 	uint8_t index = dev->driver_id;
341*b3bbd9e5SSlawomir Mrozowicz 	void *sess_priv = get_session_private_data(sess, index);
342*b3bbd9e5SSlawomir Mrozowicz 
343*b3bbd9e5SSlawomir Mrozowicz 	/* Zero out the whole structure */
344*b3bbd9e5SSlawomir Mrozowicz 	if (sess_priv) {
345*b3bbd9e5SSlawomir Mrozowicz 		memset(sess_priv, 0, sizeof(struct null_crypto_session));
346*b3bbd9e5SSlawomir Mrozowicz 		struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
347*b3bbd9e5SSlawomir Mrozowicz 		set_session_private_data(sess, index, NULL);
348*b3bbd9e5SSlawomir Mrozowicz 		rte_mempool_put(sess_mp, sess_priv);
349*b3bbd9e5SSlawomir Mrozowicz 	}
35094b0ad8eSDeclan Doherty }
35194b0ad8eSDeclan Doherty 
35294b0ad8eSDeclan Doherty struct rte_cryptodev_ops pmd_ops = {
35394b0ad8eSDeclan Doherty 		.dev_configure		= null_crypto_pmd_config,
35494b0ad8eSDeclan Doherty 		.dev_start		= null_crypto_pmd_start,
35594b0ad8eSDeclan Doherty 		.dev_stop		= null_crypto_pmd_stop,
35694b0ad8eSDeclan Doherty 		.dev_close		= null_crypto_pmd_close,
35794b0ad8eSDeclan Doherty 
35894b0ad8eSDeclan Doherty 		.stats_get		= null_crypto_pmd_stats_get,
35994b0ad8eSDeclan Doherty 		.stats_reset		= null_crypto_pmd_stats_reset,
36094b0ad8eSDeclan Doherty 
36194b0ad8eSDeclan Doherty 		.dev_infos_get		= null_crypto_pmd_info_get,
36294b0ad8eSDeclan Doherty 
36394b0ad8eSDeclan Doherty 		.queue_pair_setup	= null_crypto_pmd_qp_setup,
36494b0ad8eSDeclan Doherty 		.queue_pair_release	= null_crypto_pmd_qp_release,
36594b0ad8eSDeclan Doherty 		.queue_pair_start	= null_crypto_pmd_qp_start,
36694b0ad8eSDeclan Doherty 		.queue_pair_stop	= null_crypto_pmd_qp_stop,
36794b0ad8eSDeclan Doherty 		.queue_pair_count	= null_crypto_pmd_qp_count,
36894b0ad8eSDeclan Doherty 
36994b0ad8eSDeclan Doherty 		.session_get_size	= null_crypto_pmd_session_get_size,
37094b0ad8eSDeclan Doherty 		.session_configure	= null_crypto_pmd_session_configure,
37194b0ad8eSDeclan Doherty 		.session_clear		= null_crypto_pmd_session_clear
37294b0ad8eSDeclan Doherty };
37394b0ad8eSDeclan Doherty 
37494b0ad8eSDeclan Doherty struct rte_cryptodev_ops *null_crypto_pmd_ops = &pmd_ops;
375