4 * Copyright(c) 2016-2017 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.
33 #include <rte_common.h>
34 #include <rte_config.h>
35 #include <rte_cryptodev_pmd.h>
36 #include <rte_cryptodev_vdev.h>
38 #include <rte_malloc.h>
40 #include "null_crypto_pmd_private.h"
42 static uint8_t cryptodev_driver_id;
44 /** verify and set session parameters */
46 null_crypto_set_session_parameters(
47 struct null_crypto_session *sess __rte_unused,
48 const struct rte_crypto_sym_xform *xform)
52 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
53 xform->next == NULL) {
54 /* Authentication Only */
55 if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL)
57 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
58 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
59 /* Authentication then Cipher */
60 if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL &&
61 xform->next->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
63 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
64 xform->next == NULL) {
66 if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
68 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
69 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
70 /* Cipher then Authentication */
71 if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL &&
72 xform->next->auth.algo == RTE_CRYPTO_AUTH_NULL)
79 /** Process crypto operation for mbuf */
81 process_op(const struct null_crypto_qp *qp, struct rte_crypto_op *op,
82 struct null_crypto_session *sess __rte_unused)
84 /* set status as successful by default */
85 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
88 * if crypto session and operation are valid just enqueue the packet
89 * in the processed ring
91 return rte_ring_enqueue(qp->processed_pkts, (void *)op);
94 static struct null_crypto_session *
95 get_session(struct null_crypto_qp *qp, struct rte_crypto_op *op)
97 struct null_crypto_session *sess;
98 struct rte_crypto_sym_op *sym_op = op->sym;
100 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
101 if (unlikely(sym_op->session == NULL ||
102 sym_op->session->driver_id !=
103 cryptodev_driver_id))
106 sess = (struct null_crypto_session *)sym_op->session->_private;
108 struct rte_cryptodev_session *c_sess = NULL;
110 if (rte_mempool_get(qp->sess_mp, (void **)&c_sess))
113 sess = (struct null_crypto_session *)c_sess->_private;
115 if (null_crypto_set_session_parameters(sess, sym_op->xform) != 0)
124 null_crypto_pmd_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops,
127 struct null_crypto_session *sess;
128 struct null_crypto_qp *qp = queue_pair;
132 for (i = 0; i < nb_ops; i++) {
133 sess = get_session(qp, ops[i]);
134 if (unlikely(sess == NULL))
137 retval = process_op(qp, ops[i], sess);
138 if (unlikely(retval < 0))
142 qp->qp_stats.enqueued_count += i;
147 ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
149 qp->qp_stats.enqueue_err_count++;
155 null_crypto_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
158 struct null_crypto_qp *qp = queue_pair;
160 unsigned nb_dequeued;
162 nb_dequeued = rte_ring_dequeue_burst(qp->processed_pkts,
163 (void **)ops, nb_ops, NULL);
164 qp->qp_stats.dequeued_count += nb_dequeued;
169 static int cryptodev_null_remove(const char *name);
171 /** Create crypto device */
173 cryptodev_null_create(const char *name,
174 struct rte_vdev_device *vdev,
175 struct rte_crypto_vdev_init_params *init_params)
177 struct rte_cryptodev *dev;
178 struct null_crypto_private *internals;
180 if (init_params->name[0] == '\0')
181 snprintf(init_params->name, sizeof(init_params->name),
184 dev = rte_cryptodev_vdev_pmd_init(init_params->name,
185 sizeof(struct null_crypto_private),
186 init_params->socket_id,
189 NULL_CRYPTO_LOG_ERR("failed to create cryptodev vdev");
193 dev->driver_id = cryptodev_driver_id;
194 dev->dev_ops = null_crypto_pmd_ops;
196 /* register rx/tx burst functions for data path */
197 dev->dequeue_burst = null_crypto_pmd_dequeue_burst;
198 dev->enqueue_burst = null_crypto_pmd_enqueue_burst;
200 dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
201 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
202 RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER;
204 internals = dev->data->dev_private;
206 internals->max_nb_qpairs = init_params->max_nb_queue_pairs;
207 internals->max_nb_sessions = init_params->max_nb_sessions;
212 NULL_CRYPTO_LOG_ERR("driver %s: cryptodev_null_create failed",
214 cryptodev_null_remove(init_params->name);
219 /** Initialise null crypto device */
221 cryptodev_null_probe(struct rte_vdev_device *dev)
223 struct rte_crypto_vdev_init_params init_params = {
224 RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
225 RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_SESSIONS,
231 name = rte_vdev_device_name(dev);
235 RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n",
236 name, init_params.socket_id);
237 if (init_params.name[0] != '\0')
238 RTE_LOG(INFO, PMD, " User defined name = %s\n",
240 RTE_LOG(INFO, PMD, " Max number of queue pairs = %d\n",
241 init_params.max_nb_queue_pairs);
242 RTE_LOG(INFO, PMD, " Max number of sessions = %d\n",
243 init_params.max_nb_sessions);
245 return cryptodev_null_create(name, dev, &init_params);
248 /** Uninitialise null crypto device */
250 cryptodev_null_remove(const char *name)
255 RTE_LOG(INFO, PMD, "Closing null crypto device %s on numa socket %u\n",
256 name, rte_socket_id());
262 cryptodev_null_remove_dev(struct rte_vdev_device *dev)
264 return cryptodev_null_remove(rte_vdev_device_name(dev));
267 static struct rte_vdev_driver cryptodev_null_pmd_drv = {
268 .probe = cryptodev_null_probe,
269 .remove = cryptodev_null_remove_dev,
272 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_NULL_PMD, cryptodev_null_pmd_drv);
273 RTE_PMD_REGISTER_ALIAS(CRYPTODEV_NAME_NULL_PMD, cryptodev_null_pmd);
274 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_NULL_PMD,
275 "max_nb_queue_pairs=<int> "
276 "max_nb_sessions=<int> "
278 RTE_PMD_REGISTER_CRYPTO_DRIVER(cryptodev_null_pmd_drv, cryptodev_driver_id);