DPDK  17.08.0
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 
90 };
91 
103  uint8_t type;
105  uint8_t status;
112  uint8_t sess_type;
115  uint8_t reserved[5];
124  union {
127  };
128 };
129 
136 static inline void
138 {
139  op->type = type;
142 
143  switch (type) {
146  break;
147  default:
148  break;
149  }
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 *
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 
274 static inline unsigned
276  enum rte_crypto_op_type type,
277  struct rte_crypto_op **ops, uint16_t nb_ops)
278 {
279  int i;
280 
281  if (unlikely(__rte_crypto_op_raw_bulk_alloc(mempool, type, ops, nb_ops)
282  != nb_ops))
283  return 0;
284 
285  for (i = 0; i < nb_ops; i++)
286  __rte_crypto_op_reset(ops[i], type);
287 
288  return nb_ops;
289 }
290 
291 
292 
304 static inline void *
306 {
307  uint32_t priv_size;
308 
309  if (likely(op->mempool != NULL)) {
311 
312  if (likely(priv_size >= size))
313  return (void *)((uint8_t *)(op + 1) +
314  sizeof(struct rte_crypto_sym_op));
315  }
316 
317  return NULL;
318 }
319 
327 static inline void
329 {
330  if (op != NULL && op->mempool != NULL)
331  rte_mempool_put(op->mempool, op);
332 }
333 
345 static inline struct rte_crypto_op *
347 {
348  if (unlikely(m == NULL))
349  return NULL;
350 
351  /*
352  * check that the mbuf's private data size is sufficient to contain a
353  * crypto operation
354  */
355  if (unlikely(m->priv_size < (sizeof(struct rte_crypto_op) +
356  sizeof(struct rte_crypto_sym_op))))
357  return NULL;
358 
359  /* private data starts immediately after the mbuf header in the mbuf. */
360  struct rte_crypto_op *op = (struct rte_crypto_op *)(m + 1);
361 
363 
364  op->mempool = NULL;
365  op->sym->m_src = m;
366 
367  return op;
368 }
369 
379 static inline struct rte_crypto_sym_xform *
380 rte_crypto_op_sym_xforms_alloc(struct rte_crypto_op *op, uint8_t nb_xforms)
381 {
382  void *priv_data;
383  uint32_t size;
384 
386  return NULL;
387 
388  size = sizeof(struct rte_crypto_sym_xform) * nb_xforms;
389 
390  priv_data = __rte_crypto_op_get_priv_data(op, size);
391  if (priv_data == NULL)
392  return NULL;
393 
394  return __rte_crypto_sym_op_sym_xforms_alloc(op->sym, priv_data,
395  nb_xforms);
396 }
397 
398 
405 static inline int
407  struct rte_cryptodev_sym_session *sess)
408 {
410  return -1;
411 
413 
415 }
416 
417 #ifdef __cplusplus
418 }
419 #endif
420 
421 #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:137
enum rte_crypto_op_type type
Definition: rte_crypto.h:156
static __rte_always_inline int rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned n)
Definition: rte_mempool.h:1285
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:305
uint8_t status
Definition: rte_crypto.h:105
uint8_t type
Definition: rte_crypto.h:103
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:275
uint32_t cache_size
Definition: rte_mempool.h:232
static int rte_crypto_op_attach_sym_session(struct rte_crypto_op *op, struct rte_cryptodev_sym_session *sess)
Definition: rte_crypto.h:406
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:380
#define unlikely(x)
uint16_t priv_size
Definition: rte_mbuf.h:539
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:328
static int __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, struct rte_cryptodev_sym_session *sess)
uint8_t reserved[5]
Definition: rte_crypto.h:115
#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:346
rte_crypto_op_sess_type
Definition: rte_crypto.h:87
uint64_t phys_addr_t
Definition: rte_memory.h:103
phys_addr_t phys_addr
Definition: rte_crypto.h:120
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 __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1148
uint8_t sess_type
Definition: rte_crypto.h:112
static void * rte_mempool_get_priv(struct rte_mempool *mp)
Definition: rte_mempool.h:1426
char name[RTE_MEMZONE_NAMESIZE]
Definition: rte_mempool.h:221
rte_crypto_op_status
Definition: rte_crypto.h:64
struct rte_mempool * mempool
Definition: rte_crypto.h:117
struct rte_crypto_sym_op sym[0]
Definition: rte_crypto.h:125