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