DPDK  16.11.11
rte_crypto.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2016 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 
82 };
83 
94 struct rte_crypto_op {
112  void *opaque_data;
116  union {
119  };
121 
128 static inline void
130 {
131  op->type = type;
133 
134  switch (type) {
139  op->sym = (struct rte_crypto_sym_op *)(op + 1);
140  op->type = type;
141 
143  break;
145  default:
146  break;
147  }
148 
149  op->opaque_data = NULL;
150 }
151 
158  uint16_t priv_size;
160 };
161 
162 
171 static inline uint16_t
173 {
174  struct rte_crypto_op_pool_private *priv =
176 
177  return priv->priv_size;
178 }
179 
180 
200 extern struct rte_mempool *
201 rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type,
202  unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
203  int socket_id);
204 
216 static inline int
218  enum rte_crypto_op_type type,
219  struct rte_crypto_op **ops, uint16_t nb_ops)
220 {
221  struct rte_crypto_op_pool_private *priv;
222 
223  priv = (struct rte_crypto_op_pool_private *) rte_mempool_get_priv(mempool);
224  if (unlikely(priv->type != type &&
226  return -EINVAL;
227 
228  if (rte_mempool_get_bulk(mempool, (void **)ops, nb_ops) == 0)
229  return nb_ops;
230 
231  return 0;
232 }
233 
244 static inline struct rte_crypto_op *
246 {
247  struct rte_crypto_op *op = NULL;
248  int retval;
249 
250  retval = __rte_crypto_op_raw_bulk_alloc(mempool, type, &op, 1);
251  if (unlikely(retval != 1))
252  return NULL;
253 
254  __rte_crypto_op_reset(op, type);
255 
256  return op;
257 }
258 
259 
273 static inline unsigned
276  struct rte_crypto_op **ops, uint16_t nb_ops)
277 {
278  int i;
279 
280  if (unlikely(__rte_crypto_op_raw_bulk_alloc(mempool, type, ops, nb_ops)
281  != nb_ops))
282  return 0;
283 
284  for (i = 0; i < nb_ops; i++)
285  __rte_crypto_op_reset(ops[i], type);
286 
287  return nb_ops;
288 }
289 
290 
291 
303 static inline void *
305 {
306  uint32_t priv_size;
307 
308  if (likely(op->mempool != NULL)) {
310 
311  if (likely(priv_size >= size))
312  return (void *)((uint8_t *)(op + 1) +
313  sizeof(struct rte_crypto_sym_op));
314  }
315 
316  return NULL;
317 }
318 
326 static inline void
328 {
329  if (op != NULL && op->mempool != NULL)
330  rte_mempool_put(op->mempool, op);
331 }
332 
344 static inline struct rte_crypto_op *
346 {
347  if (unlikely(m == NULL))
348  return NULL;
349 
350  /*
351  * check that the mbuf's private data size is sufficient to contain a
352  * crypto operation
353  */
354  if (unlikely(m->priv_size < (sizeof(struct rte_crypto_op) +
355  sizeof(struct rte_crypto_sym_op))))
356  return NULL;
357 
358  /* private data starts immediately after the mbuf header in the mbuf. */
359  struct rte_crypto_op *op = (struct rte_crypto_op *)(m + 1);
360 
362 
363  op->mempool = NULL;
364  op->sym->m_src = m;
365 
366  return op;
367 }
368 
378 static inline struct rte_crypto_sym_xform *
379 rte_crypto_op_sym_xforms_alloc(struct rte_crypto_op *op, uint8_t nb_xforms)
380 {
381  void *priv_data;
382  uint32_t size;
383 
385  return NULL;
386 
387  size = sizeof(struct rte_crypto_sym_xform) * nb_xforms;
388 
389  priv_data = __rte_crypto_op_get_priv_data(op, size);
390  if (priv_data == NULL)
391  return NULL;
392 
393  return __rte_crypto_sym_op_sym_xforms_alloc(op->sym, priv_data,
394  nb_xforms);
395 }
396 
397 
404 static inline int
406  struct rte_cryptodev_sym_session *sess)
407 {
409  return -1;
410 
412 }
413 
414 #ifdef __cplusplus
415 }
416 #endif
417 
418 #endif /* _RTE_CRYPTO_H_ */
struct rte_crypto_sym_op * sym
Definition: rte_crypto.h:117
static void __rte_crypto_op_reset(struct rte_crypto_op *op, enum rte_crypto_op_type type)
Definition: rte_crypto.h:129
enum rte_crypto_op_type type
Definition: rte_crypto.h:156
void * opaque_data
Definition: rte_crypto.h:112
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:304
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:217
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:274
uint32_t cache_size
Definition: rte_mempool.h:230
static int rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned n)
Definition: rte_mempool.h:1417
static int rte_crypto_op_attach_sym_session(struct rte_crypto_op *op, struct rte_cryptodev_sym_session *sess)
Definition: rte_crypto.h:405
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:379
#define unlikely(x)
uint16_t priv_size
Definition: rte_mbuf.h:482
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:172
rte_crypto_op_type
Definition: rte_crypto.h:56
static void rte_crypto_op_free(struct rte_crypto_op *op)
Definition: rte_crypto.h:327
static int __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, struct rte_cryptodev_sym_session *sess)
#define RTE_STD_C11
Definition: rte_common.h:64
static struct rte_crypto_op * rte_crypto_sym_op_alloc_from_mbuf_priv_data(struct rte_mbuf *m)
Definition: rte_crypto.h:345
enum rte_crypto_op_status status
Definition: rte_crypto.h:98
uint64_t phys_addr_t
Definition: rte_memory.h:103
#define __rte_cache_aligned
Definition: rte_memory.h:96
phys_addr_t phys_addr
Definition: rte_crypto.h:109
static struct rte_crypto_op * rte_crypto_op_alloc(struct rte_mempool *mempool, enum rte_crypto_op_type type)
Definition: rte_crypto.h:245
static void * rte_mempool_get_priv(struct rte_mempool *mp)
Definition: rte_mempool.h:1649
char name[RTE_MEMZONE_NAMESIZE]
Definition: rte_mempool.h:219
static void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1223
enum rte_crypto_op_type type
Definition: rte_crypto.h:95
rte_crypto_op_status
Definition: rte_crypto.h:64
struct rte_mempool * mempool
Definition: rte_crypto.h:106