DPDK  17.05.2
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;
144  default:
145  break;
146  }
147 
148  op->opaque_data = NULL;
149 }
150 
157  uint16_t priv_size;
159 };
160 
161 
170 static inline uint16_t
172 {
173  struct rte_crypto_op_pool_private *priv =
175 
176  return priv->priv_size;
177 }
178 
179 
199 extern struct rte_mempool *
200 rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type,
201  unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
202  int socket_id);
203 
215 static inline int
217  enum rte_crypto_op_type type,
218  struct rte_crypto_op **ops, uint16_t nb_ops)
219 {
220  struct rte_crypto_op_pool_private *priv;
221 
222  priv = (struct rte_crypto_op_pool_private *) rte_mempool_get_priv(mempool);
223  if (unlikely(priv->type != type &&
225  return -EINVAL;
226 
227  if (rte_mempool_get_bulk(mempool, (void **)ops, nb_ops) == 0)
228  return nb_ops;
229 
230  return 0;
231 }
232 
243 static inline struct rte_crypto_op *
245 {
246  struct rte_crypto_op *op = NULL;
247  int retval;
248 
249  retval = __rte_crypto_op_raw_bulk_alloc(mempool, type, &op, 1);
250  if (unlikely(retval != 1))
251  return NULL;
252 
253  __rte_crypto_op_reset(op, type);
254 
255  return op;
256 }
257 
258 
272 static inline unsigned
275  struct rte_crypto_op **ops, uint16_t nb_ops)
276 {
277  int i;
278 
279  if (unlikely(__rte_crypto_op_raw_bulk_alloc(mempool, type, ops, nb_ops)
280  != nb_ops))
281  return 0;
282 
283  for (i = 0; i < nb_ops; i++)
284  __rte_crypto_op_reset(ops[i], type);
285 
286  return nb_ops;
287 }
288 
289 
290 
302 static inline void *
304 {
305  uint32_t priv_size;
306 
307  if (likely(op->mempool != NULL)) {
309 
310  if (likely(priv_size >= size))
311  return (void *)((uint8_t *)(op + 1) +
312  sizeof(struct rte_crypto_sym_op));
313  }
314 
315  return NULL;
316 }
317 
325 static inline void
327 {
328  if (op != NULL && op->mempool != NULL)
329  rte_mempool_put(op->mempool, op);
330 }
331 
343 static inline struct rte_crypto_op *
345 {
346  if (unlikely(m == NULL))
347  return NULL;
348 
349  /*
350  * check that the mbuf's private data size is sufficient to contain a
351  * crypto operation
352  */
353  if (unlikely(m->priv_size < (sizeof(struct rte_crypto_op) +
354  sizeof(struct rte_crypto_sym_op))))
355  return NULL;
356 
357  /* private data starts immediately after the mbuf header in the mbuf. */
358  struct rte_crypto_op *op = (struct rte_crypto_op *)(m + 1);
359 
361 
362  op->mempool = NULL;
363  op->sym->m_src = m;
364 
365  return op;
366 }
367 
377 static inline struct rte_crypto_sym_xform *
378 rte_crypto_op_sym_xforms_alloc(struct rte_crypto_op *op, uint8_t nb_xforms)
379 {
380  void *priv_data;
381  uint32_t size;
382 
384  return NULL;
385 
386  size = sizeof(struct rte_crypto_sym_xform) * nb_xforms;
387 
388  priv_data = __rte_crypto_op_get_priv_data(op, size);
389  if (priv_data == NULL)
390  return NULL;
391 
392  return __rte_crypto_sym_op_sym_xforms_alloc(op->sym, priv_data,
393  nb_xforms);
394 }
395 
396 
403 static inline int
405  struct rte_cryptodev_sym_session *sess)
406 {
408  return -1;
409 
411 }
412 
413 #ifdef __cplusplus
414 }
415 #endif
416 
417 #endif /* _RTE_CRYPTO_H_ */