eda2eec985227dd466976927a1e9806ec274c83a
[dpdk.git] / drivers / crypto / dpaa2_sec / dpaa2_sec_priv.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
5  *   Copyright (c) 2016 NXP. All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of  Freescale Semiconductor, Inc nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _RTE_DPAA2_SEC_PMD_PRIVATE_H_
35 #define _RTE_DPAA2_SEC_PMD_PRIVATE_H_
36
37 #define MAX_QUEUES              64
38 #define MAX_DESC_SIZE           64
39 /** private data structure for each DPAA2_SEC device */
40 struct dpaa2_sec_dev_private {
41         void *mc_portal; /**< MC Portal for configuring this device */
42         void *hw; /**< Hardware handle for this device.Used by NADK framework */
43         int32_t hw_id; /**< An unique ID of this device instance */
44         int32_t vfio_fd; /**< File descriptor received via VFIO */
45         uint16_t token; /**< Token required by DPxxx objects */
46         unsigned int max_nb_queue_pairs;
47         /**< Max number of queue pairs supported by device */
48         unsigned int max_nb_sessions;
49         /**< Max number of sessions supported by device */
50 };
51
52 struct dpaa2_sec_qp {
53         struct dpaa2_queue rx_vq;
54         struct dpaa2_queue tx_vq;
55 };
56
57 enum shr_desc_type {
58         DESC_UPDATE,
59         DESC_FINAL,
60         DESC_INITFINAL,
61 };
62
63 #define DIR_ENC                 1
64 #define DIR_DEC                 0
65
66 /* SEC Flow Context Descriptor */
67 struct sec_flow_context {
68         /* word 0 */
69         uint16_t word0_sdid;            /* 11-0  SDID */
70         uint16_t word0_res;             /* 31-12 reserved */
71
72         /* word 1 */
73         uint8_t word1_sdl;              /* 5-0 SDL */
74                                         /* 7-6 reserved */
75
76         uint8_t word1_bits_15_8;        /* 11-8 CRID */
77                                         /* 14-12 reserved */
78                                         /* 15 CRJD */
79
80         uint8_t word1_bits23_16;        /* 16  EWS */
81                                         /* 17 DAC */
82                                         /* 18,19,20 ? */
83                                         /* 23-21 reserved */
84
85         uint8_t word1_bits31_24;        /* 24 RSC */
86                                         /* 25 RBMT */
87                                         /* 31-26 reserved */
88
89         /* word 2  RFLC[31-0] */
90         uint32_t word2_rflc_31_0;
91
92         /* word 3  RFLC[63-32] */
93         uint32_t word3_rflc_63_32;
94
95         /* word 4 */
96         uint16_t word4_iicid;           /* 15-0  IICID */
97         uint16_t word4_oicid;           /* 31-16 OICID */
98
99         /* word 5 */
100         uint32_t word5_ofqid:24;                /* 23-0 OFQID */
101         uint32_t word5_31_24:8;
102                                         /* 24 OSC */
103                                         /* 25 OBMT */
104                                         /* 29-26 reserved */
105                                         /* 31-30 ICR */
106
107         /* word 6 */
108         uint32_t word6_oflc_31_0;
109
110         /* word 7 */
111         uint32_t word7_oflc_63_32;
112
113         /* Word 8-15 storage profiles */
114         uint16_t dl;                    /**<  DataLength(correction) */
115         uint16_t reserved;              /**< reserved */
116         uint16_t dhr;                   /**< DataHeadRoom(correction) */
117         uint16_t mode_bits;             /**< mode bits */
118         uint16_t bpv0;                  /**< buffer pool0 valid */
119         uint16_t bpid0;                 /**< Bypass Memory Translation */
120         uint16_t bpv1;                  /**< buffer pool1 valid */
121         uint16_t bpid1;                 /**< Bypass Memory Translation */
122         uint64_t word_12_15[2];         /**< word 12-15 are reserved */
123 };
124
125 struct sec_flc_desc {
126         struct sec_flow_context flc;
127         uint32_t desc[MAX_DESC_SIZE];
128 };
129
130 struct ctxt_priv {
131         struct sec_flc_desc flc_desc[0];
132 };
133
134 enum dpaa2_sec_op_type {
135         DPAA2_SEC_NONE,  /*!< No Cipher operations*/
136         DPAA2_SEC_CIPHER,/*!< CIPHER operations */
137         DPAA2_SEC_AUTH,  /*!< Authentication Operations */
138         DPAA2_SEC_CIPHER_HASH,  /*!< Authenticated Encryption with
139                                  * associated data
140                                  */
141         DPAA2_SEC_HASH_CIPHER,  /*!< Encryption with Authenticated
142                                  * associated data
143                                  */
144         DPAA2_SEC_IPSEC, /*!< IPSEC protocol operations*/
145         DPAA2_SEC_PDCP,  /*!< PDCP protocol operations*/
146         DPAA2_SEC_PKC,   /*!< Public Key Cryptographic Operations */
147         DPAA2_SEC_MAX
148 };
149
150 struct dpaa2_sec_cipher_ctxt {
151         struct {
152                 uint8_t *data;
153                 uint16_t length;
154         } iv;   /**< Initialisation vector parameters */
155         uint8_t *init_counter;  /*!< Set initial counter for CTR mode */
156 };
157
158 struct dpaa2_sec_auth_ctxt {
159         uint8_t trunc_len;              /*!< Length for output ICV, should
160                                          * be 0 if no truncation required
161                                          */
162 };
163
164 struct dpaa2_sec_aead_ctxt {
165         struct {
166                 uint8_t *data;
167                 uint16_t length;
168         } iv;   /**< Initialisation vector parameters */
169         uint16_t auth_only_len; /*!< Length of data for Auth only */
170         uint8_t auth_cipher_text;       /**< Authenticate/cipher ordering */
171         uint8_t trunc_len;              /*!< Length for output ICV, should
172                                          * be 0 if no truncation required
173                                          */
174 };
175
176 typedef struct dpaa2_sec_session_entry {
177         void *ctxt;
178         uint8_t ctxt_type;
179         uint8_t dir;         /*!< Operation Direction */
180         enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
181         enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
182         struct {
183                 uint8_t *data;  /**< pointer to key data */
184                 size_t length;  /**< key length in bytes */
185         } cipher_key;
186         struct {
187                 uint8_t *data;  /**< pointer to key data */
188                 size_t length;  /**< key length in bytes */
189         } auth_key;
190         struct {
191                 uint16_t length; /**< IV length in bytes */
192                 uint16_t offset; /**< IV offset in bytes */
193         } iv;
194         uint16_t digest_length;
195         uint8_t status;
196         union {
197                 struct dpaa2_sec_cipher_ctxt cipher_ctxt;
198                 struct dpaa2_sec_auth_ctxt auth_ctxt;
199                 struct dpaa2_sec_aead_ctxt aead_ctxt;
200         } ext_params;
201 } dpaa2_sec_session;
202
203 static const struct rte_cryptodev_capabilities dpaa2_sec_capabilities[] = {
204         {       /* MD5 HMAC */
205                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
206                 {.sym = {
207                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
208                         {.auth = {
209                                 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
210                                 .block_size = 64,
211                                 .key_size = {
212                                         .min = 64,
213                                         .max = 64,
214                                         .increment = 0
215                                 },
216                                 .digest_size = {
217                                         .min = 16,
218                                         .max = 16,
219                                         .increment = 0
220                                 },
221                                 .aad_size = { 0 },
222                                 .iv_size = { 0 }
223                         }, }
224                 }, }
225         },
226         {       /* SHA1 HMAC */
227                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
228                 {.sym = {
229                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
230                         {.auth = {
231                                 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
232                                 .block_size = 64,
233                                 .key_size = {
234                                         .min = 64,
235                                         .max = 64,
236                                         .increment = 0
237                                 },
238                                 .digest_size = {
239                                         .min = 20,
240                                         .max = 20,
241                                         .increment = 0
242                                 },
243                                 .aad_size = { 0 },
244                                 .iv_size = { 0 }
245                         }, }
246                 }, }
247         },
248         {       /* SHA224 HMAC */
249                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
250                 {.sym = {
251                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
252                         {.auth = {
253                                 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
254                                 .block_size = 64,
255                                 .key_size = {
256                                         .min = 64,
257                                         .max = 64,
258                                         .increment = 0
259                                 },
260                                 .digest_size = {
261                                         .min = 28,
262                                         .max = 28,
263                                         .increment = 0
264                                 },
265                                 .aad_size = { 0 },
266                                 .iv_size = { 0 }
267                         }, }
268                 }, }
269         },
270         {       /* SHA256 HMAC */
271                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
272                 {.sym = {
273                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
274                         {.auth = {
275                                 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
276                                 .block_size = 64,
277                                 .key_size = {
278                                         .min = 64,
279                                         .max = 64,
280                                         .increment = 0
281                                 },
282                                 .digest_size = {
283                                                 .min = 32,
284                                                 .max = 32,
285                                                 .increment = 0
286                                 },
287                                 .aad_size = { 0 },
288                                 .iv_size = { 0 }
289                                 }, }
290                         }, }
291                 },
292         {       /* SHA384 HMAC */
293                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
294                 {.sym = {
295                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
296                         {.auth = {
297                                 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
298                                 .block_size = 128,
299                                 .key_size = {
300                                         .min = 128,
301                                         .max = 128,
302                                         .increment = 0
303                                 },
304                                 .digest_size = {
305                                         .min = 48,
306                                         .max = 48,
307                                         .increment = 0
308                                 },
309                                 .aad_size = { 0 },
310                                 .iv_size = { 0 }
311                         }, }
312                 }, }
313         },
314         {       /* SHA512 HMAC */
315                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
316                 {.sym = {
317                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
318                         {.auth = {
319                                 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
320                                 .block_size = 128,
321                                 .key_size = {
322                                         .min = 128,
323                                         .max = 128,
324                                         .increment = 0
325                                 },
326                                 .digest_size = {
327                                         .min = 64,
328                                         .max = 64,
329                                         .increment = 0
330                                 },
331                                 .aad_size = { 0 },
332                                 .iv_size = { 0 }
333                         }, }
334                 }, }
335         },
336         {       /* AES CBC */
337                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
338                 {.sym = {
339                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
340                         {.cipher = {
341                                 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
342                                 .block_size = 16,
343                                 .key_size = {
344                                         .min = 16,
345                                         .max = 32,
346                                         .increment = 8
347                                 },
348                                 .iv_size = {
349                                         .min = 16,
350                                         .max = 16,
351                                         .increment = 0
352                                 }
353                         }, }
354                 }, }
355         },
356         {       /* 3DES CBC */
357                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
358                 {.sym = {
359                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
360                         {.cipher = {
361                                 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
362                                 .block_size = 8,
363                                 .key_size = {
364                                         .min = 16,
365                                         .max = 24,
366                                         .increment = 8
367                                 },
368                                 .iv_size = {
369                                         .min = 8,
370                                         .max = 8,
371                                         .increment = 0
372                                 }
373                         }, }
374                 }, }
375         },
376
377         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
378 };
379 #endif /* _RTE_DPAA2_SEC_PMD_PRIVATE_H_ */