New upstream version 17.08
[deb_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 2016 NXP.
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 CRYPTODEV_NAME_DPAA2_SEC_PMD    crypto_dpaa2_sec
38 /**< NXP DPAA2 - SEC PMD device name */
39
40 #define MAX_QUEUES              64
41 #define MAX_DESC_SIZE           64
42 /** private data structure for each DPAA2_SEC device */
43 struct dpaa2_sec_dev_private {
44         void *mc_portal; /**< MC Portal for configuring this device */
45         void *hw; /**< Hardware handle for this device.Used by NADK framework */
46         struct rte_mempool *fle_pool; /* per device memory pool for FLE */
47         int32_t hw_id; /**< An unique ID of this device instance */
48         int32_t vfio_fd; /**< File descriptor received via VFIO */
49         uint16_t token; /**< Token required by DPxxx objects */
50         unsigned int max_nb_queue_pairs;
51         /**< Max number of queue pairs supported by device */
52         unsigned int max_nb_sessions;
53         /**< Max number of sessions supported by device */
54 };
55
56 struct dpaa2_sec_qp {
57         struct dpaa2_queue rx_vq;
58         struct dpaa2_queue tx_vq;
59 };
60
61 enum shr_desc_type {
62         DESC_UPDATE,
63         DESC_FINAL,
64         DESC_INITFINAL,
65 };
66
67 #define DIR_ENC                 1
68 #define DIR_DEC                 0
69
70 /* SEC Flow Context Descriptor */
71 struct sec_flow_context {
72         /* word 0 */
73         uint16_t word0_sdid;            /* 11-0  SDID */
74         uint16_t word0_res;             /* 31-12 reserved */
75
76         /* word 1 */
77         uint8_t word1_sdl;              /* 5-0 SDL */
78                                         /* 7-6 reserved */
79
80         uint8_t word1_bits_15_8;        /* 11-8 CRID */
81                                         /* 14-12 reserved */
82                                         /* 15 CRJD */
83
84         uint8_t word1_bits23_16;        /* 16  EWS */
85                                         /* 17 DAC */
86                                         /* 18,19,20 ? */
87                                         /* 23-21 reserved */
88
89         uint8_t word1_bits31_24;        /* 24 RSC */
90                                         /* 25 RBMT */
91                                         /* 31-26 reserved */
92
93         /* word 2  RFLC[31-0] */
94         uint32_t word2_rflc_31_0;
95
96         /* word 3  RFLC[63-32] */
97         uint32_t word3_rflc_63_32;
98
99         /* word 4 */
100         uint16_t word4_iicid;           /* 15-0  IICID */
101         uint16_t word4_oicid;           /* 31-16 OICID */
102
103         /* word 5 */
104         uint32_t word5_ofqid:24;                /* 23-0 OFQID */
105         uint32_t word5_31_24:8;
106                                         /* 24 OSC */
107                                         /* 25 OBMT */
108                                         /* 29-26 reserved */
109                                         /* 31-30 ICR */
110
111         /* word 6 */
112         uint32_t word6_oflc_31_0;
113
114         /* word 7 */
115         uint32_t word7_oflc_63_32;
116
117         /* Word 8-15 storage profiles */
118         uint16_t dl;                    /**<  DataLength(correction) */
119         uint16_t reserved;              /**< reserved */
120         uint16_t dhr;                   /**< DataHeadRoom(correction) */
121         uint16_t mode_bits;             /**< mode bits */
122         uint16_t bpv0;                  /**< buffer pool0 valid */
123         uint16_t bpid0;                 /**< Bypass Memory Translation */
124         uint16_t bpv1;                  /**< buffer pool1 valid */
125         uint16_t bpid1;                 /**< Bypass Memory Translation */
126         uint64_t word_12_15[2];         /**< word 12-15 are reserved */
127 };
128
129 struct sec_flc_desc {
130         struct sec_flow_context flc;
131         uint32_t desc[MAX_DESC_SIZE];
132 };
133
134 struct ctxt_priv {
135         struct rte_mempool *fle_pool; /* per device memory pool for FLE */
136         struct sec_flc_desc flc_desc[0];
137 };
138
139 enum dpaa2_sec_op_type {
140         DPAA2_SEC_NONE,  /*!< No Cipher operations*/
141         DPAA2_SEC_CIPHER,/*!< CIPHER operations */
142         DPAA2_SEC_AUTH,  /*!< Authentication Operations */
143         DPAA2_SEC_AEAD,  /*!< AEAD (AES-GCM/CCM) type operations */
144         DPAA2_SEC_CIPHER_HASH,  /*!< Authenticated Encryption with
145                                  * associated data
146                                  */
147         DPAA2_SEC_HASH_CIPHER,  /*!< Encryption with Authenticated
148                                  * associated data
149                                  */
150         DPAA2_SEC_IPSEC, /*!< IPSEC protocol operations*/
151         DPAA2_SEC_PDCP,  /*!< PDCP protocol operations*/
152         DPAA2_SEC_PKC,   /*!< Public Key Cryptographic Operations */
153         DPAA2_SEC_MAX
154 };
155
156 struct dpaa2_sec_aead_ctxt {
157         uint16_t auth_only_len; /*!< Length of data for Auth only */
158         uint8_t auth_cipher_text;       /**< Authenticate/cipher ordering */
159 };
160
161 typedef struct dpaa2_sec_session_entry {
162         void *ctxt;
163         uint8_t ctxt_type;
164         uint8_t dir;         /*!< Operation Direction */
165         enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
166         enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
167         union {
168                 struct {
169                         uint8_t *data;  /**< pointer to key data */
170                         size_t length;  /**< key length in bytes */
171                 } aead_key;
172                 struct {
173                         struct {
174                                 uint8_t *data;  /**< pointer to key data */
175                                 size_t length;  /**< key length in bytes */
176                         } cipher_key;
177                         struct {
178                                 uint8_t *data;  /**< pointer to key data */
179                                 size_t length;  /**< key length in bytes */
180                         } auth_key;
181                 };
182         };
183         struct {
184                 uint16_t length; /**< IV length in bytes */
185                 uint16_t offset; /**< IV offset in bytes */
186         } iv;
187         uint16_t digest_length;
188         uint8_t status;
189         union {
190                 struct dpaa2_sec_aead_ctxt aead_ctxt;
191         } ext_params;
192 } dpaa2_sec_session;
193
194 static const struct rte_cryptodev_capabilities dpaa2_sec_capabilities[] = {
195         {       /* MD5 HMAC */
196                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
197                 {.sym = {
198                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
199                         {.auth = {
200                                 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
201                                 .block_size = 64,
202                                 .key_size = {
203                                         .min = 1,
204                                         .max = 64,
205                                         .increment = 1
206                                 },
207                                 .digest_size = {
208                                         .min = 16,
209                                         .max = 16,
210                                         .increment = 0
211                                 },
212                                 .iv_size = { 0 }
213                         }, }
214                 }, }
215         },
216         {       /* SHA1 HMAC */
217                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
218                 {.sym = {
219                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
220                         {.auth = {
221                                 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
222                                 .block_size = 64,
223                                 .key_size = {
224                                         .min = 1,
225                                         .max = 64,
226                                         .increment = 1
227                                 },
228                                 .digest_size = {
229                                         .min = 20,
230                                         .max = 20,
231                                         .increment = 0
232                                 },
233                                 .iv_size = { 0 }
234                         }, }
235                 }, }
236         },
237         {       /* SHA224 HMAC */
238                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
239                 {.sym = {
240                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
241                         {.auth = {
242                                 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
243                                 .block_size = 64,
244                                 .key_size = {
245                                         .min = 1,
246                                         .max = 64,
247                                         .increment = 1
248                                 },
249                                 .digest_size = {
250                                         .min = 28,
251                                         .max = 28,
252                                         .increment = 0
253                                 },
254                                 .iv_size = { 0 }
255                         }, }
256                 }, }
257         },
258         {       /* SHA256 HMAC */
259                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
260                 {.sym = {
261                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
262                         {.auth = {
263                                 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
264                                 .block_size = 64,
265                                 .key_size = {
266                                         .min = 1,
267                                         .max = 64,
268                                         .increment = 1
269                                 },
270                                 .digest_size = {
271                                                 .min = 32,
272                                                 .max = 32,
273                                                 .increment = 0
274                                 },
275                                 .iv_size = { 0 }
276                                 }, }
277                         }, }
278                 },
279         {       /* SHA384 HMAC */
280                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
281                 {.sym = {
282                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
283                         {.auth = {
284                                 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
285                                 .block_size = 128,
286                                 .key_size = {
287                                         .min = 1,
288                                         .max = 128,
289                                         .increment = 1
290                                 },
291                                 .digest_size = {
292                                         .min = 48,
293                                         .max = 48,
294                                         .increment = 0
295                                 },
296                                 .iv_size = { 0 }
297                         }, }
298                 }, }
299         },
300         {       /* SHA512 HMAC */
301                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
302                 {.sym = {
303                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
304                         {.auth = {
305                                 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
306                                 .block_size = 128,
307                                 .key_size = {
308                                         .min = 1,
309                                         .max = 128,
310                                         .increment = 1
311                                 },
312                                 .digest_size = {
313                                         .min = 64,
314                                         .max = 64,
315                                         .increment = 0
316                                 },
317                                 .iv_size = { 0 }
318                         }, }
319                 }, }
320         },
321         {       /* AES GCM */
322                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
323                 {.sym = {
324                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
325                         {.aead = {
326                                 .algo = RTE_CRYPTO_AEAD_AES_GCM,
327                                 .block_size = 16,
328                                 .key_size = {
329                                         .min = 16,
330                                         .max = 32,
331                                         .increment = 8
332                                 },
333                                 .digest_size = {
334                                         .min = 8,
335                                         .max = 16,
336                                         .increment = 4
337                                 },
338                                 .aad_size = {
339                                         .min = 0,
340                                         .max = 240,
341                                         .increment = 1
342                                 },
343                                 .iv_size = {
344                                         .min = 12,
345                                         .max = 12,
346                                         .increment = 0
347                                 },
348                         }, }
349                 }, }
350         },
351         {       /* AES CBC */
352                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
353                 {.sym = {
354                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
355                         {.cipher = {
356                                 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
357                                 .block_size = 16,
358                                 .key_size = {
359                                         .min = 16,
360                                         .max = 32,
361                                         .increment = 8
362                                 },
363                                 .iv_size = {
364                                         .min = 16,
365                                         .max = 16,
366                                         .increment = 0
367                                 }
368                         }, }
369                 }, }
370         },
371         {       /* AES CTR */
372                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
373                 {.sym = {
374                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
375                         {.cipher = {
376                                 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
377                                 .block_size = 16,
378                                 .key_size = {
379                                         .min = 16,
380                                         .max = 32,
381                                         .increment = 8
382                                 },
383                                 .iv_size = {
384                                         .min = 16,
385                                         .max = 16,
386                                         .increment = 0
387                                 },
388                         }, }
389                 }, }
390         },
391         {       /* 3DES CBC */
392                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
393                 {.sym = {
394                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
395                         {.cipher = {
396                                 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
397                                 .block_size = 8,
398                                 .key_size = {
399                                         .min = 16,
400                                         .max = 24,
401                                         .increment = 8
402                                 },
403                                 .iv_size = {
404                                         .min = 8,
405                                         .max = 8,
406                                         .increment = 0
407                                 }
408                         }, }
409                 }, }
410         },
411
412         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
413 };
414 #endif /* _RTE_DPAA2_SEC_PMD_PRIVATE_H_ */