DPDK 21.11.0
rte_crypto.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2017 Intel Corporation
3 */
4
5#ifndef _RTE_CRYPTO_H_
6#define _RTE_CRYPTO_H_
7
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19
20#include <rte_mbuf.h>
21#include <rte_memory.h>
22#include <rte_mempool.h>
23#include <rte_common.h>
24
25#include "rte_crypto_sym.h"
26#include "rte_crypto_asym.h"
27
36};
37
55};
56
66};
67
68/* Auxiliary flags related to IPsec offload with RTE_SECURITY */
69
70#define RTE_CRYPTO_OP_AUX_FLAGS_IPSEC_SOFT_EXPIRY (1 << 0)
84 __extension__
85 union {
86 uint64_t raw;
87 __extension__
88 struct {
89 uint8_t type;
91 uint8_t status;
99 uint8_t sess_type;
101 uint8_t aux_flags;
106 uint8_t reserved[2];
118 };
119 };
126 __extension__
127 union {
134 };
135};
136
143static inline void
145{
146 op->type = type;
149
150 switch (type) {
153 break;
155 memset(op->asym, 0, sizeof(struct rte_crypto_asym_op));
156 break;
158 default:
159 break;
160 }
161}
162
169 uint16_t priv_size;
171};
172
173
182static inline uint16_t
184{
185 struct rte_crypto_op_pool_private *priv =
187
188 return priv->priv_size;
189}
190
191
211extern struct rte_mempool *
213 unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
214 int socket_id);
215
227static inline int
229 enum rte_crypto_op_type type,
230 struct rte_crypto_op **ops, uint16_t nb_ops)
231{
232 struct rte_crypto_op_pool_private *priv;
233
234 priv = (struct rte_crypto_op_pool_private *) rte_mempool_get_priv(mempool);
235 if (unlikely(priv->type != type &&
237 return -EINVAL;
238
239 if (rte_mempool_get_bulk(mempool, (void **)ops, nb_ops) == 0)
240 return nb_ops;
241
242 return 0;
243}
244
255static inline struct rte_crypto_op *
257{
258 struct rte_crypto_op *op = NULL;
259 int retval;
260
262 if (unlikely(retval != 1))
263 return NULL;
264
266
267 return op;
268}
269
270
285static inline unsigned
288 struct rte_crypto_op **ops, uint16_t nb_ops)
289{
290 int i;
291
293 != nb_ops))
294 return 0;
295
296 for (i = 0; i < nb_ops; i++)
298
299 return nb_ops;
300}
301
302
303
315static inline void *
317{
318 uint32_t priv_size;
319
320 if (likely(op->mempool != NULL)) {
322
323 if (likely(priv_size >= size)) {
325 return (void *)((uint8_t *)(op + 1) +
326 sizeof(struct rte_crypto_sym_op));
328 return (void *)((uint8_t *)(op + 1) +
329 sizeof(struct rte_crypto_asym_op));
330 }
331 }
332
333 return NULL;
334}
335
343static inline void
345{
346 if (op != NULL && op->mempool != NULL)
347 rte_mempool_put(op->mempool, op);
348}
349
361static inline struct rte_crypto_op *
363{
364 if (unlikely(m == NULL))
365 return NULL;
366
367 /*
368 * check that the mbuf's private data size is sufficient to contain a
369 * crypto operation
370 */
371 if (unlikely(m->priv_size < (sizeof(struct rte_crypto_op) +
372 sizeof(struct rte_crypto_sym_op))))
373 return NULL;
374
375 /* private data starts immediately after the mbuf header in the mbuf. */
376 struct rte_crypto_op *op = (struct rte_crypto_op *)(m + 1);
377
379
380 op->mempool = NULL;
381 op->sym->m_src = m;
382
383 return op;
384}
385
395static inline struct rte_crypto_sym_xform *
396rte_crypto_op_sym_xforms_alloc(struct rte_crypto_op *op, uint8_t nb_xforms)
397{
398 void *priv_data;
399 uint32_t size;
400
402 return NULL;
403
404 size = sizeof(struct rte_crypto_sym_xform) * nb_xforms;
405
406 priv_data = __rte_crypto_op_get_priv_data(op, size);
407 if (priv_data == NULL)
408 return NULL;
409
410 return __rte_crypto_sym_op_sym_xforms_alloc(op->sym, priv_data,
411 nb_xforms);
412}
413
414
421static inline int
423 struct rte_cryptodev_sym_session *sess)
424{
426 return -1;
427
429
431}
432
439static inline int
441 struct rte_cryptodev_asym_session *sess)
442{
444 return -1;
445
447 op->asym->session = sess;
448 return 0;
449}
450
451#ifdef __cplusplus
452}
453#endif
454
455#endif /* _RTE_CRYPTO_H_ */
#define likely(x)
#define unlikely(x)
uint64_t rte_iova_t
Definition: rte_common.h:420
static uint16_t __rte_crypto_op_get_priv_data_size(struct rte_mempool *mempool)
Definition: rte_crypto.h:183
static unsigned rte_crypto_op_bulk_alloc(struct rte_mempool *mempool, enum rte_crypto_op_type type, struct rte_crypto_op **ops, uint16_t nb_ops)
Definition: rte_crypto.h:286
static struct rte_crypto_op * rte_crypto_op_alloc(struct rte_mempool *mempool, enum rte_crypto_op_type type)
Definition: rte_crypto.h:256
static int __rte_crypto_op_raw_bulk_alloc(struct rte_mempool *mempool, enum rte_crypto_op_type type, struct rte_crypto_op **ops, uint16_t nb_ops)
Definition: rte_crypto.h:228
static int rte_crypto_op_attach_asym_session(struct rte_crypto_op *op, struct rte_cryptodev_asym_session *sess)
Definition: rte_crypto.h:440
rte_crypto_op_sess_type
Definition: rte_crypto.h:62
@ RTE_CRYPTO_OP_SESSIONLESS
Definition: rte_crypto.h:64
@ RTE_CRYPTO_OP_SECURITY_SESSION
Definition: rte_crypto.h:65
@ RTE_CRYPTO_OP_WITH_SESSION
Definition: rte_crypto.h:63
struct rte_mempool * rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type, unsigned nb_elts, unsigned cache_size, uint16_t priv_size, int socket_id)
static struct rte_crypto_sym_xform * rte_crypto_op_sym_xforms_alloc(struct rte_crypto_op *op, uint8_t nb_xforms)
Definition: rte_crypto.h:396
static void rte_crypto_op_free(struct rte_crypto_op *op)
Definition: rte_crypto.h:344
static void * __rte_crypto_op_get_priv_data(struct rte_crypto_op *op, uint32_t size)
Definition: rte_crypto.h:316
rte_crypto_op_type
Definition: rte_crypto.h:29
@ RTE_CRYPTO_OP_TYPE_ASYMMETRIC
Definition: rte_crypto.h:34
@ RTE_CRYPTO_OP_TYPE_SYMMETRIC
Definition: rte_crypto.h:32
@ RTE_CRYPTO_OP_TYPE_UNDEFINED
Definition: rte_crypto.h:30
static struct rte_crypto_op * rte_crypto_sym_op_alloc_from_mbuf_priv_data(struct rte_mbuf *m)
Definition: rte_crypto.h:362
static void __rte_crypto_op_reset(struct rte_crypto_op *op, enum rte_crypto_op_type type)
Definition: rte_crypto.h:144
rte_crypto_op_status
Definition: rte_crypto.h:39
@ RTE_CRYPTO_OP_STATUS_AUTH_FAILED
Definition: rte_crypto.h:44
@ RTE_CRYPTO_OP_STATUS_INVALID_SESSION
Definition: rte_crypto.h:46
@ RTE_CRYPTO_OP_STATUS_SUCCESS
Definition: rte_crypto.h:40
@ RTE_CRYPTO_OP_STATUS_ERROR
Definition: rte_crypto.h:53
@ RTE_CRYPTO_OP_STATUS_NOT_PROCESSED
Definition: rte_crypto.h:42
@ RTE_CRYPTO_OP_STATUS_INVALID_ARGS
Definition: rte_crypto.h:51
static int rte_crypto_op_attach_sym_session(struct rte_crypto_op *op, struct rte_cryptodev_sym_session *sess)
Definition: rte_crypto.h:422
static void __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
static int __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, struct rte_cryptodev_sym_session *sess)
static struct rte_crypto_sym_xform * __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op, void *priv_data, uint8_t nb_xforms)
static __rte_always_inline int rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
Definition: rte_mempool.h:1575
static __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1439
static void * rte_mempool_get_priv(struct rte_mempool *mp)
Definition: rte_mempool.h:1757
struct rte_cryptodev_asym_session * session
enum rte_crypto_op_type type
Definition: rte_crypto.h:167
struct rte_mempool * mempool
Definition: rte_crypto.h:120
uint8_t type
Definition: rte_crypto.h:89
struct rte_crypto_sym_op sym[0]
Definition: rte_crypto.h:128
uint16_t private_data_offset
Definition: rte_crypto.h:110
uint8_t reserved[2]
Definition: rte_crypto.h:106
uint8_t aux_flags
Definition: rte_crypto.h:101
uint8_t sess_type
Definition: rte_crypto.h:99
struct rte_crypto_asym_op asym[0]
Definition: rte_crypto.h:131
rte_iova_t phys_addr
Definition: rte_crypto.h:123
uint8_t status
Definition: rte_crypto.h:91
struct rte_mbuf * m_src
uint16_t priv_size
char name[RTE_MEMPOOL_NAMESIZE]
Definition: rte_mempool.h:213
uint32_t cache_size
Definition: rte_mempool.h:224