crypto/dpaa2_sec: add per dev mempool to store FLE
[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_CIPHER_HASH,  /*!< Authenticated Encryption with
141                                  * associated data
142                                  */
143         DPAA2_SEC_HASH_CIPHER,  /*!< Encryption with Authenticated
144                                  * associated data
145                                  */
146         DPAA2_SEC_IPSEC, /*!< IPSEC protocol operations*/
147         DPAA2_SEC_PDCP,  /*!< PDCP protocol operations*/
148         DPAA2_SEC_PKC,   /*!< Public Key Cryptographic Operations */
149         DPAA2_SEC_MAX
150 };
151
152 struct dpaa2_sec_cipher_ctxt {
153         struct {
154                 uint8_t *data;
155                 uint16_t length;
156         } iv;   /**< Initialisation vector parameters */
157         uint8_t *init_counter;  /*!< Set initial counter for CTR mode */
158 };
159
160 struct dpaa2_sec_auth_ctxt {
161         uint8_t trunc_len;              /*!< Length for output ICV, should
162                                          * be 0 if no truncation required
163                                          */
164 };
165
166 struct dpaa2_sec_aead_ctxt {
167         struct {
168                 uint8_t *data;
169                 uint16_t length;
170         } iv;   /**< Initialisation vector parameters */
171         uint16_t auth_only_len; /*!< Length of data for Auth only */
172         uint8_t auth_cipher_text;       /**< Authenticate/cipher ordering */
173         uint8_t trunc_len;              /*!< Length for output ICV, should
174                                          * be 0 if no truncation required
175                                          */
176 };
177
178 typedef struct dpaa2_sec_session_entry {
179         void *ctxt;
180         uint8_t ctxt_type;
181         uint8_t dir;         /*!< Operation Direction */
182         enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
183         enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
184         struct {
185                 uint8_t *data;  /**< pointer to key data */
186                 size_t length;  /**< key length in bytes */
187         } cipher_key;
188         struct {
189                 uint8_t *data;  /**< pointer to key data */
190                 size_t length;  /**< key length in bytes */
191         } auth_key;
192         struct {
193                 uint16_t length; /**< IV length in bytes */
194                 uint16_t offset; /**< IV offset in bytes */
195         } iv;
196         uint16_t digest_length;
197         uint8_t status;
198         union {
199                 struct dpaa2_sec_cipher_ctxt cipher_ctxt;
200                 struct dpaa2_sec_auth_ctxt auth_ctxt;
201                 struct dpaa2_sec_aead_ctxt aead_ctxt;
202         } ext_params;
203 } dpaa2_sec_session;
204
205 static const struct rte_cryptodev_capabilities dpaa2_sec_capabilities[] = {
206         {       /* MD5 HMAC */
207                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
208                 {.sym = {
209                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
210                         {.auth = {
211                                 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
212                                 .block_size = 64,
213                                 .key_size = {
214                                         .min = 64,
215                                         .max = 64,
216                                         .increment = 0
217                                 },
218                                 .digest_size = {
219                                         .min = 16,
220                                         .max = 16,
221                                         .increment = 0
222                                 },
223                                 .aad_size = { 0 },
224                                 .iv_size = { 0 }
225                         }, }
226                 }, }
227         },
228         {       /* SHA1 HMAC */
229                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
230                 {.sym = {
231                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
232                         {.auth = {
233                                 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
234                                 .block_size = 64,
235                                 .key_size = {
236                                         .min = 64,
237                                         .max = 64,
238                                         .increment = 0
239                                 },
240                                 .digest_size = {
241                                         .min = 20,
242                                         .max = 20,
243                                         .increment = 0
244                                 },
245                                 .aad_size = { 0 },
246                                 .iv_size = { 0 }
247                         }, }
248                 }, }
249         },
250         {       /* SHA224 HMAC */
251                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
252                 {.sym = {
253                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
254                         {.auth = {
255                                 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
256                                 .block_size = 64,
257                                 .key_size = {
258                                         .min = 64,
259                                         .max = 64,
260                                         .increment = 0
261                                 },
262                                 .digest_size = {
263                                         .min = 28,
264                                         .max = 28,
265                                         .increment = 0
266                                 },
267                                 .aad_size = { 0 },
268                                 .iv_size = { 0 }
269                         }, }
270                 }, }
271         },
272         {       /* SHA256 HMAC */
273                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
274                 {.sym = {
275                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
276                         {.auth = {
277                                 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
278                                 .block_size = 64,
279                                 .key_size = {
280                                         .min = 64,
281                                         .max = 64,
282                                         .increment = 0
283                                 },
284                                 .digest_size = {
285                                                 .min = 32,
286                                                 .max = 32,
287                                                 .increment = 0
288                                 },
289                                 .aad_size = { 0 },
290                                 .iv_size = { 0 }
291                                 }, }
292                         }, }
293                 },
294         {       /* SHA384 HMAC */
295                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
296                 {.sym = {
297                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
298                         {.auth = {
299                                 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
300                                 .block_size = 128,
301                                 .key_size = {
302                                         .min = 128,
303                                         .max = 128,
304                                         .increment = 0
305                                 },
306                                 .digest_size = {
307                                         .min = 48,
308                                         .max = 48,
309                                         .increment = 0
310                                 },
311                                 .aad_size = { 0 },
312                                 .iv_size = { 0 }
313                         }, }
314                 }, }
315         },
316         {       /* SHA512 HMAC */
317                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
318                 {.sym = {
319                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
320                         {.auth = {
321                                 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
322                                 .block_size = 128,
323                                 .key_size = {
324                                         .min = 128,
325                                         .max = 128,
326                                         .increment = 0
327                                 },
328                                 .digest_size = {
329                                         .min = 64,
330                                         .max = 64,
331                                         .increment = 0
332                                 },
333                                 .aad_size = { 0 },
334                                 .iv_size = { 0 }
335                         }, }
336                 }, }
337         },
338         {       /* AES CBC */
339                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
340                 {.sym = {
341                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
342                         {.cipher = {
343                                 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
344                                 .block_size = 16,
345                                 .key_size = {
346                                         .min = 16,
347                                         .max = 32,
348                                         .increment = 8
349                                 },
350                                 .iv_size = {
351                                         .min = 16,
352                                         .max = 16,
353                                         .increment = 0
354                                 }
355                         }, }
356                 }, }
357         },
358         {       /* 3DES CBC */
359                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
360                 {.sym = {
361                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
362                         {.cipher = {
363                                 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
364                                 .block_size = 8,
365                                 .key_size = {
366                                         .min = 16,
367                                         .max = 24,
368                                         .increment = 8
369                                 },
370                                 .iv_size = {
371                                         .min = 8,
372                                         .max = 8,
373                                         .increment = 0
374                                 }
375                         }, }
376                 }, }
377         },
378
379         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
380 };
381 #endif /* _RTE_DPAA2_SEC_PMD_PRIVATE_H_ */