DPDK
16.04.0
Main Page
Related Pages
Data Structures
Files
Examples
File List
Globals
lib
librte_cryptodev
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
55
enum
rte_crypto_op_type
{
56
RTE_CRYPTO_OP_TYPE_UNDEFINED
,
58
RTE_CRYPTO_OP_TYPE_SYMMETRIC
,
60
};
61
63
enum
rte_crypto_op_status
{
64
RTE_CRYPTO_OP_STATUS_SUCCESS
,
66
RTE_CRYPTO_OP_STATUS_NOT_PROCESSED
,
68
RTE_CRYPTO_OP_STATUS_ENQUEUED
,
70
RTE_CRYPTO_OP_STATUS_AUTH_FAILED
,
72
RTE_CRYPTO_OP_STATUS_INVALID_SESSION
,
77
RTE_CRYPTO_OP_STATUS_INVALID_ARGS
,
79
RTE_CRYPTO_OP_STATUS_ERROR
,
81
};
82
93
struct
rte_crypto_op
{
94
enum
rte_crypto_op_type
type
;
97
enum
rte_crypto_op_status
status
;
105
struct
rte_mempool
*
mempool
;
108
phys_addr_t
phys_addr
;
111
void
*
opaque_data
;
114
union
{
115
struct
rte_crypto_sym_op
*
sym
;
117
};
118
}
__rte_cache_aligned
;
119
126
static
inline
void
127
__rte_crypto_op_reset
(
struct
rte_crypto_op
*op,
enum
rte_crypto_op_type
type)
128
{
129
op->
type
= type;
130
op->
status
=
RTE_CRYPTO_OP_STATUS_NOT_PROCESSED
;
131
132
switch
(type) {
133
case
RTE_CRYPTO_OP_TYPE_SYMMETRIC
:
137
op->
sym
= (
struct
rte_crypto_sym_op
*)(op + 1);
138
op->
type
= type;
139
140
__rte_crypto_sym_op_reset
(op->
sym
);
141
break
;
142
default
:
143
break
;
144
}
145
146
op->
opaque_data
= NULL;
147
}
148
152
struct
rte_crypto_op_pool_private
{
153
enum
rte_crypto_op_type
type
;
155
uint16_t
priv_size
;
157
};
158
159
168
static
inline
uint16_t
169
__rte_crypto_op_get_priv_data_size
(
struct
rte_mempool
*mempool)
170
{
171
struct
rte_crypto_op_pool_private
*priv =
172
(
struct
rte_crypto_op_pool_private
*)
rte_mempool_get_priv
(mempool);
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
214
__rte_crypto_op_raw_bulk_alloc
(
struct
rte_mempool
*mempool,
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 &&
222
priv->
type
!=
RTE_CRYPTO_OP_TYPE_UNDEFINED
))
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
*
242
rte_crypto_op_alloc
(
struct
rte_mempool
*
mempool
,
enum
rte_crypto_op_type
type
)
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
271
rte_crypto_op_bulk_alloc
(
struct
rte_mempool
*
mempool
,
272
enum
rte_crypto_op_type
type
,
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
*
301
__rte_crypto_op_get_priv_data
(
struct
rte_crypto_op
*op, uint32_t size)
302
{
303
uint32_t priv_size;
304
305
if
(
likely
(op->
mempool
!= NULL)) {
306
priv_size =
__rte_crypto_op_get_priv_data_size
(op->
mempool
);
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
324
rte_crypto_op_free
(
struct
rte_crypto_op
*op)
325
{
326
if
(op != NULL && op->
mempool
!= NULL)
327
rte_mempool_put
(op->
mempool
, op);
328
}
329
341
static
inline
struct
rte_crypto_op
*
342
rte_crypto_sym_op_alloc_from_mbuf_priv_data
(
struct
rte_mbuf
*m)
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
358
__rte_crypto_op_reset
(op,
RTE_CRYPTO_OP_TYPE_SYMMETRIC
);
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
381
if
(
unlikely
(op->
type
!=
RTE_CRYPTO_OP_TYPE_SYMMETRIC
))
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
402
rte_crypto_op_attach_sym_session
(
struct
rte_crypto_op
*op,
403
struct
rte_cryptodev_sym_session
*sess)
404
{
405
if
(
unlikely
(op->
type
!=
RTE_CRYPTO_OP_TYPE_SYMMETRIC
))
406
return
-1;
407
408
return
__rte_crypto_sym_op_attach_sym_session
(op->
sym
, sess);
409
}
410
411
#ifdef __cplusplus
412
}
413
#endif
414
415
#endif
/* _RTE_CRYPTO_H_ */
Generated by
1.8.1.2