crypto/dpaa_sec: optimize virtual address conversion
[dpdk.git] / drivers / crypto / dpaa_sec / dpaa_sec.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright 2016 NXP
4  *
5  */
6
7 #ifndef _DPAA_SEC_H_
8 #define _DPAA_SEC_H_
9
10 #define NUM_POOL_CHANNELS       4
11 #define DPAA_SEC_BURST          32
12 #define DPAA_SEC_ALG_UNSUPPORT  (-1)
13 #define TDES_CBC_IV_LEN         8
14 #define AES_CBC_IV_LEN          16
15 #define AES_CTR_IV_LEN          16
16 #define AES_GCM_IV_LEN          12
17
18 /* Minimum job descriptor consists of a oneword job descriptor HEADER and
19  * a pointer to the shared descriptor.
20  */
21 #define MIN_JOB_DESC_SIZE       (CAAM_CMD_SZ + CAAM_PTR_SZ)
22 /* CTX_POOL_NUM_BUFS is set as per the ipsec-secgw application */
23 #define CTX_POOL_NUM_BUFS       32000
24 #define CTX_POOL_BUF_SIZE       sizeof(struct dpaa_sec_op_ctx)
25 #define CTX_POOL_CACHE_SIZE     512
26
27 #define DIR_ENC                 1
28 #define DIR_DEC                 0
29
30 enum dpaa_sec_op_type {
31         DPAA_SEC_NONE,  /*!< No Cipher operations*/
32         DPAA_SEC_CIPHER,/*!< CIPHER operations */
33         DPAA_SEC_AUTH,  /*!< Authentication Operations */
34         DPAA_SEC_AEAD,  /*!< Authenticated Encryption with associated data */
35         DPAA_SEC_IPSEC, /*!< IPSEC protocol operations*/
36         DPAA_SEC_PDCP,  /*!< PDCP protocol operations*/
37         DPAA_SEC_PKC,   /*!< Public Key Cryptographic Operations */
38         DPAA_SEC_MAX
39 };
40
41 typedef struct dpaa_sec_session_entry {
42         uint8_t dir;         /*!< Operation Direction */
43         enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
44         enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
45         enum rte_crypto_aead_algorithm aead_alg; /*!< Authentication Algorithm*/
46         union {
47                 struct {
48                         uint8_t *data;  /**< pointer to key data */
49                         size_t length;  /**< key length in bytes */
50                 } aead_key;
51                 struct {
52                         struct {
53                                 uint8_t *data;  /**< pointer to key data */
54                                 size_t length;  /**< key length in bytes */
55                         } cipher_key;
56                         struct {
57                                 uint8_t *data;  /**< pointer to key data */
58                                 size_t length;  /**< key length in bytes */
59                         } auth_key;
60                 };
61         };
62         struct {
63                 uint16_t length;
64                 uint16_t offset;
65         } iv;   /**< Initialisation vector parameters */
66         uint16_t auth_only_len; /*!< Length of data for Auth only */
67         uint32_t digest_length;
68         struct dpaa_sec_qp *qp;
69         struct rte_mempool *ctx_pool; /* session mempool for dpaa_sec_op_ctx */
70 } dpaa_sec_session;
71
72 #define DPAA_SEC_MAX_DESC_SIZE  64
73 /* code or cmd block to caam */
74 struct sec_cdb {
75         struct {
76                 union {
77                         uint32_t word;
78                         struct {
79 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
80                                 uint16_t rsvd63_48;
81                                 unsigned int rsvd47_39:9;
82                                 unsigned int idlen:7;
83 #else
84                                 unsigned int idlen:7;
85                                 unsigned int rsvd47_39:9;
86                                 uint16_t rsvd63_48;
87 #endif
88                         } field;
89                 } __packed hi;
90
91                 union {
92                         uint32_t word;
93                         struct {
94 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
95                                 unsigned int rsvd31_30:2;
96                                 unsigned int fsgt:1;
97                                 unsigned int lng:1;
98                                 unsigned int offset:2;
99                                 unsigned int abs:1;
100                                 unsigned int add_buf:1;
101                                 uint8_t pool_id;
102                                 uint16_t pool_buffer_size;
103 #else
104                                 uint16_t pool_buffer_size;
105                                 uint8_t pool_id;
106                                 unsigned int add_buf:1;
107                                 unsigned int abs:1;
108                                 unsigned int offset:2;
109                                 unsigned int lng:1;
110                                 unsigned int fsgt:1;
111                                 unsigned int rsvd31_30:2;
112 #endif
113                         } field;
114                 } __packed lo;
115         } __packed sh_hdr;
116
117         uint32_t sh_desc[DPAA_SEC_MAX_DESC_SIZE];
118 };
119
120 struct dpaa_sec_qp {
121         struct dpaa_sec_dev_private *internals;
122         struct sec_cdb cdb;             /* cmd block associated with qp */
123         dpaa_sec_session *ses;          /* session associated with qp */
124         struct qman_fq inq;
125         struct qman_fq outq;
126         int rx_pkts;
127         int rx_errs;
128         int tx_pkts;
129         int tx_errs;
130 };
131
132 #define RTE_MAX_NB_SEC_QPS RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS
133 /* internal sec queue interface */
134 struct dpaa_sec_dev_private {
135         void *sec_hw;
136         struct rte_mempool *ctx_pool; /* per dev mempool for dpaa_sec_op_ctx */
137         struct dpaa_sec_qp qps[RTE_MAX_NB_SEC_QPS]; /* i/o queue for sec */
138         unsigned int max_nb_queue_pairs;
139         unsigned int max_nb_sessions;
140 };
141
142 #define MAX_SG_ENTRIES          16
143 #define SG_CACHELINE_0          0
144 #define SG_CACHELINE_1          4
145 #define SG_CACHELINE_2          8
146 #define SG_CACHELINE_3          12
147 struct dpaa_sec_job {
148         /* sg[0] output, sg[1] input, others are possible sub frames */
149         struct qm_sg_entry sg[MAX_SG_ENTRIES];
150 };
151
152 #define DPAA_MAX_NB_MAX_DIGEST  32
153 struct dpaa_sec_op_ctx {
154         struct dpaa_sec_job job;
155         struct rte_crypto_op *op;
156         struct rte_mempool *ctx_pool; /* mempool pointer for dpaa_sec_op_ctx */
157         uint32_t fd_status;
158         int64_t vtop_offset;
159         uint8_t digest[DPAA_MAX_NB_MAX_DIGEST];
160 };
161
162 static const struct rte_cryptodev_capabilities dpaa_sec_capabilities[] = {
163         {       /* MD5 HMAC */
164                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
165                 {.sym = {
166                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
167                         {.auth = {
168                                 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
169                                 .block_size = 64,
170                                 .key_size = {
171                                         .min = 1,
172                                         .max = 64,
173                                         .increment = 1
174                                 },
175                                 .digest_size = {
176                                         .min = 16,
177                                         .max = 16,
178                                         .increment = 0
179                                 },
180                         }, }
181                 }, }
182         },
183         {       /* SHA1 HMAC */
184                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
185                 {.sym = {
186                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
187                         {.auth = {
188                                 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
189                                 .block_size = 64,
190                                 .key_size = {
191                                         .min = 1,
192                                         .max = 64,
193                                         .increment = 1
194                                 },
195                                 .digest_size = {
196                                         .min = 20,
197                                         .max = 20,
198                                         .increment = 0
199                                 },
200                         }, }
201                 }, }
202         },
203         {       /* SHA224 HMAC */
204                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
205                 {.sym = {
206                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
207                         {.auth = {
208                                 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
209                                 .block_size = 64,
210                                 .key_size = {
211                                         .min = 1,
212                                         .max = 64,
213                                         .increment = 1
214                                 },
215                                 .digest_size = {
216                                         .min = 28,
217                                         .max = 28,
218                                         .increment = 0
219                                 },
220                         }, }
221                 }, }
222         },
223         {       /* SHA256 HMAC */
224                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
225                 {.sym = {
226                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
227                         {.auth = {
228                                 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
229                                 .block_size = 64,
230                                 .key_size = {
231                                         .min = 1,
232                                         .max = 64,
233                                         .increment = 1
234                                 },
235                                 .digest_size = {
236                                         .min = 32,
237                                         .max = 32,
238                                         .increment = 0
239                                 },
240                         }, }
241                 }, }
242         },
243         {       /* SHA384 HMAC */
244                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
245                 {.sym = {
246                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
247                         {.auth = {
248                                 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
249                                 .block_size = 128,
250                                 .key_size = {
251                                         .min = 1,
252                                         .max = 128,
253                                         .increment = 1
254                                 },
255                                 .digest_size = {
256                                         .min = 48,
257                                         .max = 48,
258                                         .increment = 0
259                                 },
260                         }, }
261                 }, }
262         },
263         {       /* SHA512 HMAC */
264                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
265                 {.sym = {
266                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
267                         {.auth = {
268                                 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
269                                 .block_size = 128,
270                                 .key_size = {
271                                         .min = 1,
272                                         .max = 128,
273                                         .increment = 1
274                                 },
275                                 .digest_size = {
276                                         .min = 64,
277                                         .max = 64,
278                                         .increment = 0
279                                 },
280                         }, }
281                 }, }
282         },
283         {       /* AES GCM */
284                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
285                 {.sym = {
286                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
287                         {.auth = {
288                                 .algo = RTE_CRYPTO_AEAD_AES_GCM,
289                                 .block_size = 16,
290                                 .key_size = {
291                                         .min = 16,
292                                         .max = 32,
293                                         .increment = 8
294                                 },
295                                 .digest_size = {
296                                         .min = 8,
297                                         .max = 16,
298                                         .increment = 4
299                                 },
300                                 .aad_size = {
301                                         .min = 0,
302                                         .max = 240,
303                                         .increment = 1
304                                 },
305                                 .iv_size = {
306                                         .min = 12,
307                                         .max = 12,
308                                         .increment = 0
309                                 },
310                         }, }
311                 }, }
312         },
313         {       /* AES CBC */
314                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
315                 {.sym = {
316                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
317                         {.cipher = {
318                                 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
319                                 .block_size = 16,
320                                 .key_size = {
321                                         .min = 16,
322                                         .max = 32,
323                                         .increment = 8
324                                 },
325                                 .iv_size = {
326                                         .min = 16,
327                                         .max = 16,
328                                         .increment = 0
329                                 }
330                         }, }
331                 }, }
332         },
333         {       /* AES CTR */
334                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
335                 {.sym = {
336                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
337                         {.cipher = {
338                                 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
339                                 .block_size = 16,
340                                 .key_size = {
341                                         .min = 16,
342                                         .max = 32,
343                                         .increment = 8
344                                 },
345                                 .iv_size = {
346                                         .min = 16,
347                                         .max = 16,
348                                         .increment = 0
349                                 }
350                         }, }
351                 }, }
352         },
353         {       /* 3DES CBC */
354                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
355                 {.sym = {
356                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
357                         {.cipher = {
358                                 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
359                                 .block_size = 8,
360                                 .key_size = {
361                                         .min = 16,
362                                         .max = 24,
363                                         .increment = 8
364                                 },
365                                 .iv_size = {
366                                         .min = 8,
367                                         .max = 8,
368                                         .increment = 0
369                                 }
370                         }, }
371                 }, }
372         },
373
374         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
375 };
376
377 #endif /* _DPAA_SEC_H_ */