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
16 extern "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)
71 
83 struct rte_crypto_op {
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 
143 static 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 
182 static inline uint16_t
184 {
185  struct rte_crypto_op_pool_private *priv =
187 
188  return priv->priv_size;
189 }
190 
191 
211 extern struct rte_mempool *
212 rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type,
213  unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
214  int socket_id);
215 
227 static 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 
255 static inline struct rte_crypto_op *
257 {
258  struct rte_crypto_op *op = NULL;
259  int retval;
260 
261  retval = __rte_crypto_op_raw_bulk_alloc(mempool, type, &op, 1);
262  if (unlikely(retval != 1))
263  return NULL;
264 
266 
267  return op;
268 }
269 
270 
285 static 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++)
297  __rte_crypto_op_reset(ops[i], type);
298 
299  return nb_ops;
300 }
301 
302 
303 
315 static 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 
343 static inline void
345 {
346  if (op != NULL && op->mempool != NULL)
347  rte_mempool_put(op->mempool, op);
348 }
349 
361 static 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 
395 static inline struct rte_crypto_sym_xform *
396 rte_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 
421 static inline int
423  struct rte_cryptodev_sym_session *sess)
424 {
426  return -1;
427 
429 
431 }
432 
439 static 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_ */
static void __rte_crypto_op_reset(struct rte_crypto_op *op, enum rte_crypto_op_type type)
Definition: rte_crypto.h:144
enum rte_crypto_op_type type
Definition: rte_crypto.h:167
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 int rte_crypto_op_attach_asym_session(struct rte_crypto_op *op, struct rte_cryptodev_asym_session *sess)
Definition: rte_crypto.h:440
#define likely(x)
static void * __rte_crypto_op_get_priv_data(struct rte_crypto_op *op, uint32_t size)
Definition: rte_crypto.h:316
uint8_t status
Definition: rte_crypto.h:91
uint8_t type
Definition: rte_crypto.h:89
uint64_t rte_iova_t
Definition: rte_common.h:420
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
rte_iova_t phys_addr
Definition: rte_crypto.h:123
static void __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
struct rte_mbuf * m_src
uint8_t aux_flags
Definition: rte_crypto.h:101
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
uint32_t cache_size
Definition: rte_mempool.h:224
char name[RTE_MEMPOOL_NAMESIZE]
Definition: rte_mempool.h:213
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 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
#define unlikely(x)
uint16_t priv_size
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 uint16_t __rte_crypto_op_get_priv_data_size(struct rte_mempool *mempool)
Definition: rte_crypto.h:183
rte_crypto_op_type
Definition: rte_crypto.h:29
static void rte_crypto_op_free(struct rte_crypto_op *op)
Definition: rte_crypto.h:344
static int __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, struct rte_cryptodev_sym_session *sess)
static __rte_always_inline int rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
Definition: rte_mempool.h:1575
uint16_t private_data_offset
Definition: rte_crypto.h:110
static struct rte_crypto_op * rte_crypto_sym_op_alloc_from_mbuf_priv_data(struct rte_mbuf *m)
Definition: rte_crypto.h:362
struct rte_crypto_asym_op asym[0]
Definition: rte_crypto.h:131
rte_crypto_op_sess_type
Definition: rte_crypto.h:62
struct rte_cryptodev_asym_session * session
uint8_t reserved[2]
Definition: rte_crypto.h:106
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 __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1439
uint8_t sess_type
Definition: rte_crypto.h:99
static void * rte_mempool_get_priv(struct rte_mempool *mp)
Definition: rte_mempool.h:1757
rte_crypto_op_status
Definition: rte_crypto.h:39
struct rte_mempool * mempool
Definition: rte_crypto.h:120
struct rte_crypto_sym_op sym[0]
Definition: rte_crypto.h:128