DPDK  16.04.0
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 
52 #include "rte_crypto_sym.h"
53 
60 };
61 
81 };
82 
93 struct rte_crypto_op {
111  void *opaque_data;
114  union {
117  };
119 
126 static inline void
128 {
129  op->type = type;
131 
132  switch (type) {
137  op->sym = (struct rte_crypto_sym_op *)(op + 1);
138  op->type = type;
139 
141  break;
142  default:
143  break;
144  }
145 
146  op->opaque_data = NULL;
147 }
148 
155  uint16_t priv_size;
157 };
158 
159 
168 static inline uint16_t
170 {
171  struct rte_crypto_op_pool_private *priv =
173 
174  return priv->priv_size;
175 }
176 
177 
197 extern struct rte_mempool *
198 rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type,
199  unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
200  int socket_id);
201 
213 static inline int
215  enum rte_crypto_op_type type,
216  struct rte_crypto_op **ops, uint16_t nb_ops)
217 {
218  struct rte_crypto_op_pool_private *priv;
219 
220  priv = (struct rte_crypto_op_pool_private *) rte_mempool_get_priv(mempool);
221  if (unlikely(priv->type != type &&
223  return -EINVAL;
224 
225  if (rte_mempool_get_bulk(mempool, (void **)ops, nb_ops) == 0)
226  return nb_ops;
227 
228  return 0;
229 }
230 
241 static inline struct rte_crypto_op *
243 {
244  struct rte_crypto_op *op = NULL;
245  int retval;
246 
247  retval = __rte_crypto_op_raw_bulk_alloc(mempool, type, &op, 1);
248  if (unlikely(retval != 1))
249  return NULL;
250 
251  __rte_crypto_op_reset(op, type);
252 
253  return op;
254 }
255 
256 
270 static inline unsigned
273  struct rte_crypto_op **ops, uint16_t nb_ops)
274 {
275  int i;
276 
277  if (unlikely(__rte_crypto_op_raw_bulk_alloc(mempool, type, ops, nb_ops)
278  != nb_ops))
279  return 0;
280 
281  for (i = 0; i < nb_ops; i++)
282  __rte_crypto_op_reset(ops[i], type);
283 
284  return nb_ops;
285 }
286 
287 
288 
300 static inline void *
302 {
303  uint32_t priv_size;
304 
305  if (likely(op->mempool != NULL)) {
307 
308  if (likely(priv_size >= size))
309  return (void *)((uint8_t *)(op + 1) +
310  sizeof(struct rte_crypto_sym_op));
311  }
312 
313  return NULL;
314 }
315 
323 static inline void
325 {
326  if (op != NULL && op->mempool != NULL)
327  rte_mempool_put(op->mempool, op);
328 }
329 
341 static inline struct rte_crypto_op *
343 {
344  if (unlikely(m == NULL))
345  return NULL;
346 
347  /*
348  * check that the mbuf's private data size is sufficient to contain a
349  * crypto operation
350  */
351  if (unlikely(m->priv_size < (sizeof(struct rte_crypto_op) +
352  sizeof(struct rte_crypto_sym_op))))
353  return NULL;
354 
355  /* private data starts immediately after the mbuf header in the mbuf. */
356  struct rte_crypto_op *op = (struct rte_crypto_op *)(m + 1);
357 
359 
360  op->mempool = NULL;
361  op->sym->m_src = m;
362 
363  return op;
364 }
365 
375 static inline struct rte_crypto_sym_xform *
376 rte_crypto_op_sym_xforms_alloc(struct rte_crypto_op *op, uint8_t nb_xforms)
377 {
378  void *priv_data;
379  uint32_t size;
380 
382  return NULL;
383 
384  size = sizeof(struct rte_crypto_sym_xform) * nb_xforms;
385 
386  priv_data = __rte_crypto_op_get_priv_data(op, size);
387  if (priv_data == NULL)
388  return NULL;
389 
390  return __rte_crypto_sym_op_sym_xforms_alloc(op->sym, priv_data,
391  nb_xforms);
392 }
393 
394 
401 static inline int
403  struct rte_cryptodev_sym_session *sess)
404 {
406  return -1;
407 
409 }
410 
411 #ifdef __cplusplus
412 }
413 #endif
414 
415 #endif /* _RTE_CRYPTO_H_ */