udp: fix csum computation when offload disabled
[vpp.git] / src / plugins / crypto_native / crypto_native.h
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2019 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17
18 #ifndef __crypto_native_h__
19 #define __crypto_native_h__
20
21 typedef void *(crypto_native_key_fn_t) (vnet_crypto_key_t * key);
22 typedef int (crypto_native_variant_probe_t) ();
23
24 typedef struct crypto_native_op_handler
25 {
26   struct crypto_native_op_handler *next;
27   vnet_crypto_op_id_t op_id;
28   vnet_crypto_ops_handler_t *fn;
29   vnet_crypto_chained_ops_handler_t *cfn;
30   crypto_native_variant_probe_t *probe;
31   int priority;
32 } crypto_native_op_handler_t;
33
34 typedef struct crypto_native_key_handler
35 {
36   struct crypto_native_key_handler *next;
37   vnet_crypto_alg_t alg_id;
38   crypto_native_key_fn_t *key_fn;
39   crypto_native_variant_probe_t *probe;
40   int priority;
41 } crypto_native_key_handler_t;
42
43 typedef struct
44 {
45   u32 crypto_engine_index;
46   crypto_native_key_fn_t *key_fn[VNET_CRYPTO_N_ALGS];
47   void **key_data;
48   crypto_native_op_handler_t *op_handlers;
49   crypto_native_key_handler_t *key_handlers;
50 } crypto_native_main_t;
51
52 extern crypto_native_main_t crypto_native_main;
53
54 #define CRYPTO_NATIVE_OP_HANDLER(x)                                           \
55   static crypto_native_op_handler_t __crypto_native_op_handler_##x;           \
56   static void __clib_constructor __crypto_native_op_handler_cb_##x (void)     \
57   {                                                                           \
58     crypto_native_main_t *cm = &crypto_native_main;                           \
59     int priority = __crypto_native_op_handler_##x.probe ();                   \
60     if (priority >= 0)                                                        \
61       {                                                                       \
62         __crypto_native_op_handler_##x.priority = priority;                   \
63         __crypto_native_op_handler_##x.next = cm->op_handlers;                \
64         cm->op_handlers = &__crypto_native_op_handler_##x;                    \
65       }                                                                       \
66   }                                                                           \
67   static crypto_native_op_handler_t __crypto_native_op_handler_##x
68
69 #define CRYPTO_NATIVE_KEY_HANDLER(x)                                          \
70   static crypto_native_key_handler_t __crypto_native_key_handler_##x;         \
71   static void __clib_constructor __crypto_native_key_handler_cb_##x (void)    \
72   {                                                                           \
73     crypto_native_main_t *cm = &crypto_native_main;                           \
74     int priority = __crypto_native_key_handler_##x.probe ();                  \
75     if (priority >= 0)                                                        \
76       {                                                                       \
77         __crypto_native_key_handler_##x.priority = priority;                  \
78         __crypto_native_key_handler_##x.next = cm->key_handlers;              \
79         cm->key_handlers = &__crypto_native_key_handler_##x;                  \
80       }                                                                       \
81   }                                                                           \
82   static crypto_native_key_handler_t __crypto_native_key_handler_##x
83 #endif /* __crypto_native_h__ */
84