DPDK  18.02.2
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 
228  __rte_crypto_op_reset(op, type);
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 
255  if (unlikely(__rte_crypto_op_raw_bulk_alloc(mempool, type, ops, nb_ops)
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_ */