59c3ee1e9e5d632eb79e623d0b890ccc134ff457
[deb_dpdk.git] / drivers / crypto / aesni_mb / aesni_mb_ops.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015 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 _AESNI_MB_OPS_H_
34 #define _AESNI_MB_OPS_H_
35
36 #ifndef LINUX
37 #define LINUX
38 #endif
39
40 #include <mb_mgr.h>
41 #include <aux_funcs.h>
42
43 enum aesni_mb_vector_mode {
44         RTE_AESNI_MB_NOT_SUPPORTED = 0,
45         RTE_AESNI_MB_SSE,
46         RTE_AESNI_MB_AVX,
47         RTE_AESNI_MB_AVX2,
48         RTE_AESNI_MB_AVX512
49 };
50
51 typedef void (*md5_one_block_t)(const void *data, void *digest);
52
53 typedef void (*sha1_one_block_t)(const void *data, void *digest);
54 typedef void (*sha224_one_block_t)(const void *data, void *digest);
55 typedef void (*sha256_one_block_t)(const void *data, void *digest);
56 typedef void (*sha384_one_block_t)(const void *data, void *digest);
57 typedef void (*sha512_one_block_t)(const void *data, void *digest);
58
59 typedef void (*aes_keyexp_128_t)
60                 (const void *key, void *enc_exp_keys, void *dec_exp_keys);
61 typedef void (*aes_keyexp_192_t)
62                 (const void *key, void *enc_exp_keys, void *dec_exp_keys);
63 typedef void (*aes_keyexp_256_t)
64                 (const void *key, void *enc_exp_keys, void *dec_exp_keys);
65
66 typedef void (*aes_xcbc_expand_key_t)
67                 (const void *key, void *exp_k1, void *k2, void *k3);
68
69 /** Multi-buffer library function pointer table */
70 struct aesni_mb_op_fns {
71         struct {
72                 init_mb_mgr_t init_mgr;
73                 /**< Initialise scheduler  */
74                 get_next_job_t get_next;
75                 /**< Get next free job structure */
76                 submit_job_t submit;
77                 /**< Submit job to scheduler */
78                 get_completed_job_t get_completed_job;
79                 /**< Get completed job */
80                 flush_job_t flush_job;
81                 /**< flush jobs from manager */
82         } job;
83         /**< multi buffer manager functions */
84
85         struct {
86                 struct {
87                         md5_one_block_t md5;
88                         /**< MD5 one block hash */
89                         sha1_one_block_t sha1;
90                         /**< SHA1 one block hash */
91                         sha224_one_block_t sha224;
92                         /**< SHA224 one block hash */
93                         sha256_one_block_t sha256;
94                         /**< SHA256 one block hash */
95                         sha384_one_block_t sha384;
96                         /**< SHA384 one block hash */
97                         sha512_one_block_t sha512;
98                         /**< SHA512 one block hash */
99                 } one_block;
100                 /**< one block hash functions */
101
102                 struct {
103                         aes_keyexp_128_t aes128;
104                         /**< AES128 key expansions */
105                         aes_keyexp_192_t aes192;
106                         /**< AES192 key expansions */
107                         aes_keyexp_256_t aes256;
108                         /**< AES256 key expansions */
109
110                         aes_xcbc_expand_key_t aes_xcbc;
111                         /**< AES XCBC key expansions */
112                 } keyexp;
113                 /**< Key expansion functions */
114         } aux;
115         /**< Auxiliary functions */
116 };
117
118
119 static const struct aesni_mb_op_fns job_ops[] = {
120                 [RTE_AESNI_MB_NOT_SUPPORTED] = {
121                         .job = {
122                                 NULL
123                         },
124                         .aux = {
125                                 .one_block = {
126                                         NULL
127                                 },
128                                 .keyexp = {
129                                         NULL
130                                 }
131                         }
132                 },
133                 [RTE_AESNI_MB_SSE] = {
134                         .job = {
135                                 init_mb_mgr_sse,
136                                 get_next_job_sse,
137                                 submit_job_sse,
138                                 get_completed_job_sse,
139                                 flush_job_sse
140                         },
141                         .aux = {
142                                 .one_block = {
143                                         md5_one_block_sse,
144                                         sha1_one_block_sse,
145                                         sha224_one_block_sse,
146                                         sha256_one_block_sse,
147                                         sha384_one_block_sse,
148                                         sha512_one_block_sse
149                                 },
150                                 .keyexp = {
151                                         aes_keyexp_128_sse,
152                                         aes_keyexp_192_sse,
153                                         aes_keyexp_256_sse,
154                                         aes_xcbc_expand_key_sse
155                                 }
156                         }
157                 },
158                 [RTE_AESNI_MB_AVX] = {
159                         .job = {
160                                 init_mb_mgr_avx,
161                                 get_next_job_avx,
162                                 submit_job_avx,
163                                 get_completed_job_avx,
164                                 flush_job_avx
165                         },
166                         .aux = {
167                                 .one_block = {
168                                         md5_one_block_avx,
169                                         sha1_one_block_avx,
170                                         sha224_one_block_avx,
171                                         sha256_one_block_avx,
172                                         sha384_one_block_avx,
173                                         sha512_one_block_avx
174                                 },
175                                 .keyexp = {
176                                         aes_keyexp_128_avx,
177                                         aes_keyexp_192_avx,
178                                         aes_keyexp_256_avx,
179                                         aes_xcbc_expand_key_avx
180                                 }
181                         }
182                 },
183                 [RTE_AESNI_MB_AVX2] = {
184                         .job = {
185                                 init_mb_mgr_avx2,
186                                 get_next_job_avx2,
187                                 submit_job_avx2,
188                                 get_completed_job_avx2,
189                                 flush_job_avx2
190                         },
191                         .aux = {
192                                 .one_block = {
193                                         md5_one_block_avx2,
194                                         sha1_one_block_avx2,
195                                         sha224_one_block_avx2,
196                                         sha256_one_block_avx2,
197                                         sha384_one_block_avx2,
198                                         sha512_one_block_avx2
199                                 },
200                                 .keyexp = {
201                                         aes_keyexp_128_avx2,
202                                         aes_keyexp_192_avx2,
203                                         aes_keyexp_256_avx2,
204                                         aes_xcbc_expand_key_avx2
205                                 }
206                         }
207                 },
208                 [RTE_AESNI_MB_AVX512] = {
209                         .job = {
210                                 init_mb_mgr_avx512,
211                                 get_next_job_avx512,
212                                 submit_job_avx512,
213                                 get_completed_job_avx512,
214                                 flush_job_avx512
215                         },
216                         .aux = {
217                                 .one_block = {
218                                         md5_one_block_avx512,
219                                         sha1_one_block_avx512,
220                                         sha224_one_block_avx512,
221                                         sha256_one_block_avx512,
222                                         sha384_one_block_avx512,
223                                         sha512_one_block_avx512
224                                 },
225                                 .keyexp = {
226                                         aes_keyexp_128_avx512,
227                                         aes_keyexp_192_avx512,
228                                         aes_keyexp_256_avx512,
229                                         aes_xcbc_expand_key_avx512
230                                 }
231                         }
232                 }
233 };
234
235
236 #endif /* _AESNI_MB_OPS_H_ */