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>
37 #include <rte_malloc.h>
39 #include "null_crypto_pmd_private.h"
41 static uint8_t cryptodev_driver_id;
43 /** verify and set session parameters */
45 null_crypto_set_session_parameters(
46 struct null_crypto_session *sess __rte_unused,
47 const struct rte_crypto_sym_xform *xform)
51 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
52 xform->next == NULL) {
53 /* Authentication Only */
54 if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL)
56 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
57 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
58 /* Authentication then Cipher */
59 if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL &&
60 xform->next->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
62 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
63 xform->next == NULL) {
65 if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
67 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
68 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
69 /* Cipher then Authentication */
70 if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL &&
71 xform->next->auth.algo == RTE_CRYPTO_AUTH_NULL)
78 /** Process crypto operation for mbuf */
80 process_op(const struct null_crypto_qp *qp, struct rte_crypto_op *op,
81 struct null_crypto_session *sess __rte_unused)
83 /* set status as successful by default */
84 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
86 /* Free session if a session-less crypto op. */
87 if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
88 memset(op->sym->session, 0,
89 sizeof(struct null_crypto_session));
90 rte_cryptodev_sym_session_free(op->sym->session);
91 op->sym->session = NULL;
95 * if crypto session and operation are valid just enqueue the packet
96 * in the processed ring
98 return rte_ring_enqueue(qp->processed_pkts, (void *)op);
101 static struct null_crypto_session *
102 get_session(struct null_crypto_qp *qp, struct rte_crypto_op *op)
104 struct null_crypto_session *sess = NULL;
105 struct rte_crypto_sym_op *sym_op = op->sym;
107 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
108 if (likely(sym_op->session != NULL))
109 sess = (struct null_crypto_session *)
110 get_session_private_data(
111 sym_op->session, cryptodev_driver_id);
114 void *_sess_private_data = NULL;
116 if (rte_mempool_get(qp->sess_mp, (void **)&_sess))
119 if (rte_mempool_get(qp->sess_mp, (void **)&_sess_private_data))
122 sess = (struct null_crypto_session *)_sess_private_data;
124 if (unlikely(null_crypto_set_session_parameters(sess,
125 sym_op->xform) != 0)) {
126 rte_mempool_put(qp->sess_mp, _sess);
127 rte_mempool_put(qp->sess_mp, _sess_private_data);
130 sym_op->session = (struct rte_cryptodev_sym_session *)_sess;
131 set_session_private_data(sym_op->session, cryptodev_driver_id,
140 null_crypto_pmd_enqueue_burst(void *queue_pair, struct rte_crypto_op **ops,
143 struct null_crypto_session *sess;
144 struct null_crypto_qp *qp = queue_pair;
148 for (i = 0; i < nb_ops; i++) {
149 sess = get_session(qp, ops[i]);
150 if (unlikely(sess == NULL))
153 retval = process_op(qp, ops[i], sess);
154 if (unlikely(retval < 0))
158 qp->qp_stats.enqueued_count += i;
163 ops[i]->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
165 qp->qp_stats.enqueue_err_count++;
171 null_crypto_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
174 struct null_crypto_qp *qp = queue_pair;
176 unsigned nb_dequeued;
178 nb_dequeued = rte_ring_dequeue_burst(qp->processed_pkts,
179 (void **)ops, nb_ops, NULL);
180 qp->qp_stats.dequeued_count += nb_dequeued;
185 /** Create crypto device */
187 cryptodev_null_create(const char *name,
188 struct rte_vdev_device *vdev,
189 struct rte_cryptodev_pmd_init_params *init_params)
191 struct rte_cryptodev *dev;
192 struct null_crypto_private *internals;
194 dev = rte_cryptodev_pmd_create(name, &vdev->device, init_params);
196 NULL_CRYPTO_LOG_ERR("failed to create cryptodev vdev");
200 dev->driver_id = cryptodev_driver_id;
201 dev->dev_ops = null_crypto_pmd_ops;
203 /* register rx/tx burst functions for data path */
204 dev->dequeue_burst = null_crypto_pmd_dequeue_burst;
205 dev->enqueue_burst = null_crypto_pmd_enqueue_burst;
207 dev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
208 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
209 RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER;
211 internals = dev->data->dev_private;
213 internals->max_nb_qpairs = init_params->max_nb_queue_pairs;
214 internals->max_nb_sessions = init_params->max_nb_sessions;
219 /** Initialise null crypto device */
221 cryptodev_null_probe(struct rte_vdev_device *dev)
223 struct rte_cryptodev_pmd_init_params init_params = {
225 sizeof(struct null_crypto_private),
227 RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS,
228 RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_SESSIONS
230 const char *name, *args;
233 name = rte_vdev_device_name(dev);
237 args = rte_vdev_device_args(dev);
239 retval = rte_cryptodev_pmd_parse_input_args(&init_params, args);
242 "Failed to parse initialisation arguments[%s]\n", args);
246 return cryptodev_null_create(name, dev, &init_params);
250 cryptodev_null_remove_dev(struct rte_vdev_device *vdev)
252 struct rte_cryptodev *cryptodev;
255 name = rte_vdev_device_name(vdev);
259 cryptodev = rte_cryptodev_pmd_get_named_dev(name);
260 if (cryptodev == NULL)
263 return rte_cryptodev_pmd_destroy(cryptodev);
266 static struct rte_vdev_driver cryptodev_null_pmd_drv = {
267 .probe = cryptodev_null_probe,
268 .remove = cryptodev_null_remove_dev,
271 static struct cryptodev_driver null_crypto_drv;
273 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_NULL_PMD, cryptodev_null_pmd_drv);
274 RTE_PMD_REGISTER_ALIAS(CRYPTODEV_NAME_NULL_PMD, cryptodev_null_pmd);
275 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_NULL_PMD,
276 "max_nb_queue_pairs=<int> "
277 "max_nb_sessions=<int> "
279 RTE_PMD_REGISTER_CRYPTO_DRIVER(null_crypto_drv, cryptodev_null_pmd_drv,
280 cryptodev_driver_id);