1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2017 Intel Corporation
5 #include <rte_common.h>
6 #include <rte_cryptodev_pmd.h>
7 #include <rte_bus_vdev.h>
8 #include <rte_malloc.h>
10 #include "null_crypto_pmd_private.h"
12 static uint8_t cryptodev_driver_id
;
14 /** verify and set session parameters */
16 null_crypto_set_session_parameters(
17 struct null_crypto_session
*sess __rte_unused
,
18 const struct rte_crypto_sym_xform
*xform
)
22 } else if (xform
->type
== RTE_CRYPTO_SYM_XFORM_AUTH
&&
23 xform
->next
== NULL
) {
24 /* Authentication Only */
25 if (xform
->auth
.algo
== RTE_CRYPTO_AUTH_NULL
)
27 } else if (xform
->type
== RTE_CRYPTO_SYM_XFORM_AUTH
&&
28 xform
->next
->type
== RTE_CRYPTO_SYM_XFORM_CIPHER
) {
29 /* Authentication then Cipher */
30 if (xform
->auth
.algo
== RTE_CRYPTO_AUTH_NULL
&&
31 xform
->next
->cipher
.algo
== RTE_CRYPTO_CIPHER_NULL
)
33 } else if (xform
->type
== RTE_CRYPTO_SYM_XFORM_CIPHER
&&
34 xform
->next
== NULL
) {
36 if (xform
->cipher
.algo
== RTE_CRYPTO_CIPHER_NULL
)
38 } else if (xform
->type
== RTE_CRYPTO_SYM_XFORM_CIPHER
&&
39 xform
->next
->type
== RTE_CRYPTO_SYM_XFORM_AUTH
) {
40 /* Cipher then Authentication */
41 if (xform
->cipher
.algo
== RTE_CRYPTO_CIPHER_NULL
&&
42 xform
->next
->auth
.algo
== RTE_CRYPTO_AUTH_NULL
)
49 /** Process crypto operation for mbuf */
51 process_op(const struct null_crypto_qp
*qp
, struct rte_crypto_op
*op
,
52 struct null_crypto_session
*sess __rte_unused
)
54 /* set status as successful by default */
55 op
->status
= RTE_CRYPTO_OP_STATUS_SUCCESS
;
57 /* Free session if a session-less crypto op. */
58 if (op
->sess_type
== RTE_CRYPTO_OP_SESSIONLESS
) {
59 memset(op
->sym
->session
, 0,
60 sizeof(struct null_crypto_session
));
61 rte_cryptodev_sym_session_free(op
->sym
->session
);
62 op
->sym
->session
= NULL
;
66 * if crypto session and operation are valid just enqueue the packet
67 * in the processed ring
69 return rte_ring_enqueue(qp
->processed_pkts
, (void *)op
);
72 static struct null_crypto_session
*
73 get_session(struct null_crypto_qp
*qp
, struct rte_crypto_op
*op
)
75 struct null_crypto_session
*sess
= NULL
;
76 struct rte_crypto_sym_op
*sym_op
= op
->sym
;
78 if (op
->sess_type
== RTE_CRYPTO_OP_WITH_SESSION
) {
79 if (likely(sym_op
->session
!= NULL
))
80 sess
= (struct null_crypto_session
*)
81 get_sym_session_private_data(
82 sym_op
->session
, cryptodev_driver_id
);
85 void *_sess_private_data
= NULL
;
87 if (rte_mempool_get(qp
->sess_mp
, (void **)&_sess
))
90 if (rte_mempool_get(qp
->sess_mp
, (void **)&_sess_private_data
))
93 sess
= (struct null_crypto_session
*)_sess_private_data
;
95 if (unlikely(null_crypto_set_session_parameters(sess
,
96 sym_op
->xform
) != 0)) {
97 rte_mempool_put(qp
->sess_mp
, _sess
);
98 rte_mempool_put(qp
->sess_mp
, _sess_private_data
);
101 sym_op
->session
= (struct rte_cryptodev_sym_session
*)_sess
;
102 set_sym_session_private_data(op
->sym
->session
,
103 cryptodev_driver_id
, _sess_private_data
);
111 null_crypto_pmd_enqueue_burst(void *queue_pair
, struct rte_crypto_op
**ops
,
114 struct null_crypto_session
*sess
;
115 struct null_crypto_qp
*qp
= queue_pair
;
119 for (i
= 0; i
< nb_ops
; i
++) {
120 sess
= get_session(qp
, ops
[i
]);
121 if (unlikely(sess
== NULL
))
124 retval
= process_op(qp
, ops
[i
], sess
);
125 if (unlikely(retval
< 0))
129 qp
->qp_stats
.enqueued_count
+= i
;
134 ops
[i
]->status
= RTE_CRYPTO_OP_STATUS_INVALID_ARGS
;
136 qp
->qp_stats
.enqueue_err_count
++;
142 null_crypto_pmd_dequeue_burst(void *queue_pair
, struct rte_crypto_op
**ops
,
145 struct null_crypto_qp
*qp
= queue_pair
;
147 unsigned nb_dequeued
;
149 nb_dequeued
= rte_ring_dequeue_burst(qp
->processed_pkts
,
150 (void **)ops
, nb_ops
, NULL
);
151 qp
->qp_stats
.dequeued_count
+= nb_dequeued
;
156 /** Create crypto device */
158 cryptodev_null_create(const char *name
,
159 struct rte_vdev_device
*vdev
,
160 struct rte_cryptodev_pmd_init_params
*init_params
)
162 struct rte_cryptodev
*dev
;
163 struct null_crypto_private
*internals
;
164 dev
= rte_cryptodev_pmd_create(name
, &vdev
->device
, init_params
);
166 NULL_LOG(ERR
, "failed to create cryptodev vdev");
170 dev
->driver_id
= cryptodev_driver_id
;
171 dev
->dev_ops
= null_crypto_pmd_ops
;
173 /* register rx/tx burst functions for data path */
174 dev
->dequeue_burst
= null_crypto_pmd_dequeue_burst
;
175 dev
->enqueue_burst
= null_crypto_pmd_enqueue_burst
;
177 dev
->feature_flags
= RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO
|
178 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING
|
179 RTE_CRYPTODEV_FF_IN_PLACE_SGL
;
181 internals
= dev
->data
->dev_private
;
183 internals
->max_nb_qpairs
= init_params
->max_nb_queue_pairs
;
188 /** Initialise null crypto device */
190 cryptodev_null_probe(struct rte_vdev_device
*dev
)
192 struct rte_cryptodev_pmd_init_params init_params
= {
194 sizeof(struct null_crypto_private
),
196 RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS
198 const char *name
, *args
;
201 name
= rte_vdev_device_name(dev
);
205 args
= rte_vdev_device_args(dev
);
207 retval
= rte_cryptodev_pmd_parse_input_args(&init_params
, args
);
210 "Failed to parse initialisation arguments[%s]",
215 return cryptodev_null_create(name
, dev
, &init_params
);
219 cryptodev_null_remove_dev(struct rte_vdev_device
*vdev
)
221 struct rte_cryptodev
*cryptodev
;
224 name
= rte_vdev_device_name(vdev
);
228 cryptodev
= rte_cryptodev_pmd_get_named_dev(name
);
229 if (cryptodev
== NULL
)
232 return rte_cryptodev_pmd_destroy(cryptodev
);
235 static struct rte_vdev_driver cryptodev_null_pmd_drv
= {
236 .probe
= cryptodev_null_probe
,
237 .remove
= cryptodev_null_remove_dev
,
240 static struct cryptodev_driver null_crypto_drv
;
242 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_NULL_PMD
, cryptodev_null_pmd_drv
);
243 RTE_PMD_REGISTER_ALIAS(CRYPTODEV_NAME_NULL_PMD
, cryptodev_null_pmd
);
244 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_NULL_PMD
,
245 "max_nb_queue_pairs=<int> "
247 RTE_PMD_REGISTER_CRYPTO_DRIVER(null_crypto_drv
, cryptodev_null_pmd_drv
.driver
,
248 cryptodev_driver_id
);
250 RTE_INIT(null_init_log
)
252 null_logtype_driver
= rte_log_register("pmd.crypto.null");