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