DPDK  17.11.10
rte_crypto.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Intel Corporation nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef _RTE_CRYPTO_H_
34 #define _RTE_CRYPTO_H_
35 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 
48 #include <rte_mbuf.h>
49 #include <rte_memory.h>
50 #include <rte_mempool.h>
51 #include <rte_common.h>
52 
53 #include "rte_crypto_sym.h"
54 
61 };
62 
80 };
81 
91 };
92 
104  uint8_t type;
106  uint8_t status;
113  uint8_t sess_type;
116  uint8_t reserved[5];
124  __extension__
125  union {
128  };
129 };
130 
137 static inline void
139 {
140  op->type = type;
143 
144  switch (type) {
147  break;
149  default:
150  break;
151  }
152 }
153 
160  uint16_t priv_size;
162 };
163 
164 
173 static inline uint16_t
175 {
176  struct rte_crypto_op_pool_private *priv =
178 
179  return priv->priv_size;
180 }
181 
182 
202 extern struct rte_mempool *
203 rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type,
204  unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
205  int socket_id);
206 
218 static inline int
220  enum rte_crypto_op_type type,
221  struct rte_crypto_op **ops, uint16_t nb_ops)
222 {
223  struct rte_crypto_op_pool_private *priv;
224 
225  priv = (struct rte_crypto_op_pool_private *) rte_mempool_get_priv(mempool);
226  if (unlikely(priv->type != type &&
228  return -EINVAL;
229 
230  if (rte_mempool_get_bulk(mempool, (void **)ops, nb_ops) == 0)
231  return nb_ops;
232 
233  return 0;
234 }
235 
246 static inline struct rte_crypto_op *
248 {
249  struct rte_crypto_op *op = NULL;
250  int retval;
251 
252  retval = __rte_crypto_op_raw_bulk_alloc(mempool, type, &op, 1);
253  if (unlikely(retval != 1))
254  return NULL;
255 
256  __rte_crypto_op_reset(op, type);
257 
258  return op;
259 }
260 
261 
276 static inline unsigned
279  struct rte_crypto_op **ops, uint16_t nb_ops)
280 {
281  int i;
282 
283  if (unlikely(__rte_crypto_op_raw_bulk_alloc(mempool, type, ops, nb_ops)
284  != nb_ops))
285  return 0;
286 
287  for (i = 0; i < nb_ops; i++)
288  __rte_crypto_op_reset(ops[i], type);
289 
290  return nb_ops;
291 }
292 
293 
294 
306 static inline void *
308 {
309  uint32_t priv_size;
310 
311  if (likely(op->mempool != NULL)) {
313 
314  if (likely(priv_size >= size))
315  return (void *)((uint8_t *)(op + 1) +
316  sizeof(struct rte_crypto_sym_op));
317  }
318 
319  return NULL;
320 }
321 
329 static inline void
331 {
332  if (op != NULL && op->mempool != NULL)
333  rte_mempool_put(op->mempool, op);
334 }
335 
347 static inline struct rte_crypto_op *
349 {
350  if (unlikely(m == NULL))
351  return NULL;
352 
353  /*
354  * check that the mbuf's private data size is sufficient to contain a
355  * crypto operation
356  */
357  if (unlikely(m->priv_size < (sizeof(struct rte_crypto_op) +
358  sizeof(struct rte_crypto_sym_op))))
359  return NULL;
360 
361  /* private data starts immediately after the mbuf header in the mbuf. */
362  struct rte_crypto_op *op = (struct rte_crypto_op *)(m + 1);
363 
365 
366  op->mempool = NULL;
367  op->sym->m_src = m;
368 
369  return op;
370 }
371 
381 static inline struct rte_crypto_sym_xform *
382 rte_crypto_op_sym_xforms_alloc(struct rte_crypto_op *op, uint8_t nb_xforms)
383 {
384  void *priv_data;
385  uint32_t size;
386 
388  return NULL;
389 
390  size = sizeof(struct rte_crypto_sym_xform) * nb_xforms;
391 
392  priv_data = __rte_crypto_op_get_priv_data(op, size);
393  if (priv_data == NULL)
394  return NULL;
395 
396  return __rte_crypto_sym_op_sym_xforms_alloc(op->sym, priv_data,
397  nb_xforms);
398 }
399 
400 
407 static inline int
409  struct rte_cryptodev_sym_session *sess)
410 {
412  return -1;
413 
415 
417 }
418 
419 #ifdef __cplusplus
420 }
421 #endif
422 
423 #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:138
enum rte_crypto_op_type type
Definition: rte_crypto.h:158
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:307
uint8_t status
Definition: rte_crypto.h:106
uint8_t type
Definition: rte_crypto.h:104
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:219
rte_iova_t phys_addr
Definition: rte_crypto.h:121
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:277
uint32_t cache_size
Definition: rte_mempool.h:241
static int rte_crypto_op_attach_sym_session(struct rte_crypto_op *op, struct rte_cryptodev_sym_session *sess)
Definition: rte_crypto.h:408
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:382
#define unlikely(x)
uint16_t priv_size
Definition: rte_mbuf.h:575
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:174
rte_crypto_op_type
Definition: rte_crypto.h:56
static void rte_crypto_op_free(struct rte_crypto_op *op)
Definition: rte_crypto.h:330
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:1364
uint8_t reserved[5]
Definition: rte_crypto.h:116
static struct rte_crypto_op * rte_crypto_sym_op_alloc_from_mbuf_priv_data(struct rte_mbuf *m)
Definition: rte_crypto.h:348
uint64_t rte_iova_t
Definition: rte_memory.h:107
rte_crypto_op_sess_type
Definition: rte_crypto.h:87
static struct rte_crypto_op * rte_crypto_op_alloc(struct rte_mempool *mempool, enum rte_crypto_op_type type)
Definition: rte_crypto.h:247
static __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1233
uint8_t sess_type
Definition: rte_crypto.h:113
static void * rte_mempool_get_priv(struct rte_mempool *mp)
Definition: rte_mempool.h:1510
char name[RTE_MEMZONE_NAMESIZE]
Definition: rte_mempool.h:230
rte_crypto_op_status
Definition: rte_crypto.h:64
struct rte_mempool * mempool
Definition: rte_crypto.h:118
struct rte_crypto_sym_op sym[0]
Definition: rte_crypto.h:126