DPDK  18.02.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 
33 };
34 
52 };
53 
63 };
64 
75 struct rte_crypto_op {
76  uint8_t type;
78  uint8_t status;
85  uint8_t sess_type;
88  uint8_t reserved[5];
96  __extension__
97  union {
100  };
101 };
102 
109 static inline void
111 {
112  op->type = type;
115 
116  switch (type) {
119  break;
121  default:
122  break;
123  }
124 }
125 
132  uint16_t priv_size;
134 };
135 
136 
145 static inline uint16_t
147 {
148  struct rte_crypto_op_pool_private *priv =
150 
151  return priv->priv_size;
152 }
153 
154 
174 extern struct rte_mempool *
175 rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type,
176  unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
177  int socket_id);
178 
190 static inline int
192  enum rte_crypto_op_type type,
193  struct rte_crypto_op **ops, uint16_t nb_ops)
194 {
195  struct rte_crypto_op_pool_private *priv;
196 
197  priv = (struct rte_crypto_op_pool_private *) rte_mempool_get_priv(mempool);
198  if (unlikely(priv->type != type &&
200  return -EINVAL;
201 
202  if (rte_mempool_get_bulk(mempool, (void **)ops, nb_ops) == 0)
203  return nb_ops;
204 
205  return 0;
206 }
207 
218 static inline struct rte_crypto_op *
220 {
221  struct rte_crypto_op *op = NULL;
222  int retval;
223 
224  retval = __rte_crypto_op_raw_bulk_alloc(mempool, type, &op, 1);
225  if (unlikely(retval != 1))
226  return NULL;
227 
229 
230  return op;
231 }
232 
233 
248 static inline unsigned
251  struct rte_crypto_op **ops, uint16_t nb_ops)
252 {
253  int i;
254 
256  != nb_ops))
257  return 0;
258 
259  for (i = 0; i < nb_ops; i++)
260  __rte_crypto_op_reset(ops[i], type);
261 
262  return nb_ops;
263 }
264 
265 
266 
278 static inline void *
280 {
281  uint32_t priv_size;
282 
283  if (likely(op->mempool != NULL)) {
285 
286  if (likely(priv_size >= size))
287  return (void *)((uint8_t *)(op + 1) +
288  sizeof(struct rte_crypto_sym_op));
289  }
290 
291  return NULL;
292 }
293 
301 static inline void
303 {
304  if (op != NULL && op->mempool != NULL)
305  rte_mempool_put(op->mempool, op);
306 }
307 
319 static inline struct rte_crypto_op *
321 {
322  if (unlikely(m == NULL))
323  return NULL;
324 
325  /*
326  * check that the mbuf's private data size is sufficient to contain a
327  * crypto operation
328  */
329  if (unlikely(m->priv_size < (sizeof(struct rte_crypto_op) +
330  sizeof(struct rte_crypto_sym_op))))
331  return NULL;
332 
333  /* private data starts immediately after the mbuf header in the mbuf. */
334  struct rte_crypto_op *op = (struct rte_crypto_op *)(m + 1);
335 
337 
338  op->mempool = NULL;
339  op->sym->m_src = m;
340 
341  return op;
342 }
343 
353 static inline struct rte_crypto_sym_xform *
354 rte_crypto_op_sym_xforms_alloc(struct rte_crypto_op *op, uint8_t nb_xforms)
355 {
356  void *priv_data;
357  uint32_t size;
358 
360  return NULL;
361 
362  size = sizeof(struct rte_crypto_sym_xform) * nb_xforms;
363 
364  priv_data = __rte_crypto_op_get_priv_data(op, size);
365  if (priv_data == NULL)
366  return NULL;
367 
368  return __rte_crypto_sym_op_sym_xforms_alloc(op->sym, priv_data,
369  nb_xforms);
370 }
371 
372 
379 static inline int
381  struct rte_cryptodev_sym_session *sess)
382 {
384  return -1;
385 
387 
389 }
390 
391 #ifdef __cplusplus
392 }
393 #endif
394 
395 #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:110
enum rte_crypto_op_type type
Definition: rte_crypto.h:130
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)
#define likely(x)
static void * __rte_crypto_op_get_priv_data(struct rte_crypto_op *op, uint32_t size)
Definition: rte_crypto.h:279
uint8_t status
Definition: rte_crypto.h:78
uint8_t type
Definition: rte_crypto.h:76
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:191
rte_iova_t phys_addr
Definition: rte_crypto.h:93
static void __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
struct rte_mbuf * m_src
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:249
uint32_t cache_size
Definition: rte_mempool.h:212
static int rte_crypto_op_attach_sym_session(struct rte_crypto_op *op, struct rte_cryptodev_sym_session *sess)
Definition: rte_crypto.h:380
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:354
#define unlikely(x)
uint16_t priv_size
Definition: rte_mbuf.h:564
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:146
rte_crypto_op_type
Definition: rte_crypto.h:28
static void rte_crypto_op_free(struct rte_crypto_op *op)
Definition: rte_crypto.h:302
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:1335
uint8_t reserved[5]
Definition: rte_crypto.h:88
static struct rte_crypto_op * rte_crypto_sym_op_alloc_from_mbuf_priv_data(struct rte_mbuf *m)
Definition: rte_crypto.h:320
uint64_t rte_iova_t
Definition: rte_memory.h:78
rte_crypto_op_sess_type
Definition: rte_crypto.h:59
static struct rte_crypto_op * rte_crypto_op_alloc(struct rte_mempool *mempool, enum rte_crypto_op_type type)
Definition: rte_crypto.h:219
static __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1204
uint8_t sess_type
Definition: rte_crypto.h:85
static void * rte_mempool_get_priv(struct rte_mempool *mp)
Definition: rte_mempool.h:1481
char name[RTE_MEMZONE_NAMESIZE]
Definition: rte_mempool.h:201
rte_crypto_op_status
Definition: rte_crypto.h:36
struct rte_mempool * mempool
Definition: rte_crypto.h:90
struct rte_crypto_sym_op sym[0]
Definition: rte_crypto.h:98