af3f2550b20419bcb23c704072d4e07f2726f943
[deb_dpdk.git] / drivers / crypto / dpaa_sec / dpaa_sec.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright 2016 NXP.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of NXP nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _DPAA_SEC_H_
34 #define _DPAA_SEC_H_
35
36 #define NUM_POOL_CHANNELS       4
37 #define DPAA_SEC_BURST          32
38 #define DPAA_SEC_ALG_UNSUPPORT  (-1)
39 #define TDES_CBC_IV_LEN         8
40 #define AES_CBC_IV_LEN          16
41 #define AES_CTR_IV_LEN          16
42 #define AES_GCM_IV_LEN          12
43
44 /* Minimum job descriptor consists of a oneword job descriptor HEADER and
45  * a pointer to the shared descriptor.
46  */
47 #define MIN_JOB_DESC_SIZE       (CAAM_CMD_SZ + CAAM_PTR_SZ)
48 /* CTX_POOL_NUM_BUFS is set as per the ipsec-secgw application */
49 #define CTX_POOL_NUM_BUFS       32000
50 #define CTX_POOL_BUF_SIZE       sizeof(struct dpaa_sec_op_ctx)
51 #define CTX_POOL_CACHE_SIZE     512
52
53 #define DIR_ENC                 1
54 #define DIR_DEC                 0
55
56 enum dpaa_sec_op_type {
57         DPAA_SEC_NONE,  /*!< No Cipher operations*/
58         DPAA_SEC_CIPHER,/*!< CIPHER operations */
59         DPAA_SEC_AUTH,  /*!< Authentication Operations */
60         DPAA_SEC_AEAD,  /*!< Authenticated Encryption with associated data */
61         DPAA_SEC_IPSEC, /*!< IPSEC protocol operations*/
62         DPAA_SEC_PDCP,  /*!< PDCP protocol operations*/
63         DPAA_SEC_PKC,   /*!< Public Key Cryptographic Operations */
64         DPAA_SEC_MAX
65 };
66
67 typedef struct dpaa_sec_session_entry {
68         uint8_t dir;         /*!< Operation Direction */
69         enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
70         enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
71         enum rte_crypto_aead_algorithm aead_alg; /*!< Authentication Algorithm*/
72         union {
73                 struct {
74                         uint8_t *data;  /**< pointer to key data */
75                         size_t length;  /**< key length in bytes */
76                 } aead_key;
77                 struct {
78                         struct {
79                                 uint8_t *data;  /**< pointer to key data */
80                                 size_t length;  /**< key length in bytes */
81                         } cipher_key;
82                         struct {
83                                 uint8_t *data;  /**< pointer to key data */
84                                 size_t length;  /**< key length in bytes */
85                         } auth_key;
86                 };
87         };
88         struct {
89                 uint16_t length;
90                 uint16_t offset;
91         } iv;   /**< Initialisation vector parameters */
92         uint16_t auth_only_len; /*!< Length of data for Auth only */
93         uint32_t digest_length;
94         struct dpaa_sec_qp *qp;
95         struct rte_mempool *ctx_pool; /* session mempool for dpaa_sec_op_ctx */
96 } dpaa_sec_session;
97
98 #define DPAA_SEC_MAX_DESC_SIZE  64
99 /* code or cmd block to caam */
100 struct sec_cdb {
101         struct {
102                 union {
103                         uint32_t word;
104                         struct {
105 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
106                                 uint16_t rsvd63_48;
107                                 unsigned int rsvd47_39:9;
108                                 unsigned int idlen:7;
109 #else
110                                 unsigned int idlen:7;
111                                 unsigned int rsvd47_39:9;
112                                 uint16_t rsvd63_48;
113 #endif
114                         } field;
115                 } __packed hi;
116
117                 union {
118                         uint32_t word;
119                         struct {
120 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
121                                 unsigned int rsvd31_30:2;
122                                 unsigned int fsgt:1;
123                                 unsigned int lng:1;
124                                 unsigned int offset:2;
125                                 unsigned int abs:1;
126                                 unsigned int add_buf:1;
127                                 uint8_t pool_id;
128                                 uint16_t pool_buffer_size;
129 #else
130                                 uint16_t pool_buffer_size;
131                                 uint8_t pool_id;
132                                 unsigned int add_buf:1;
133                                 unsigned int abs:1;
134                                 unsigned int offset:2;
135                                 unsigned int lng:1;
136                                 unsigned int fsgt:1;
137                                 unsigned int rsvd31_30:2;
138 #endif
139                         } field;
140                 } __packed lo;
141         } __packed sh_hdr;
142
143         uint32_t sh_desc[DPAA_SEC_MAX_DESC_SIZE];
144 };
145
146 struct dpaa_sec_qp {
147         struct dpaa_sec_dev_private *internals;
148         struct sec_cdb cdb;             /* cmd block associated with qp */
149         dpaa_sec_session *ses;          /* session associated with qp */
150         struct qman_fq inq;
151         struct qman_fq outq;
152         int rx_pkts;
153         int rx_errs;
154         int tx_pkts;
155         int tx_errs;
156 };
157
158 #define RTE_MAX_NB_SEC_QPS RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS
159 /* internal sec queue interface */
160 struct dpaa_sec_dev_private {
161         void *sec_hw;
162         struct rte_mempool *ctx_pool; /* per dev mempool for dpaa_sec_op_ctx */
163         struct dpaa_sec_qp qps[RTE_MAX_NB_SEC_QPS]; /* i/o queue for sec */
164         unsigned int max_nb_queue_pairs;
165         unsigned int max_nb_sessions;
166 };
167
168 #define MAX_SG_ENTRIES          16
169 #define SG_CACHELINE_0          0
170 #define SG_CACHELINE_1          4
171 #define SG_CACHELINE_2          8
172 #define SG_CACHELINE_3          12
173 struct dpaa_sec_job {
174         /* sg[0] output, sg[1] input, others are possible sub frames */
175         struct qm_sg_entry sg[MAX_SG_ENTRIES];
176 };
177
178 #define DPAA_MAX_NB_MAX_DIGEST  32
179 struct dpaa_sec_op_ctx {
180         struct dpaa_sec_job job;
181         struct rte_crypto_op *op;
182         struct rte_mempool *ctx_pool; /* mempool pointer for dpaa_sec_op_ctx */
183         uint32_t fd_status;
184         uint8_t digest[DPAA_MAX_NB_MAX_DIGEST];
185 };
186
187 static const struct rte_cryptodev_capabilities dpaa_sec_capabilities[] = {
188         {       /* MD5 HMAC */
189                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
190                 {.sym = {
191                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
192                         {.auth = {
193                                 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
194                                 .block_size = 64,
195                                 .key_size = {
196                                         .min = 1,
197                                         .max = 64,
198                                         .increment = 1
199                                 },
200                                 .digest_size = {
201                                         .min = 16,
202                                         .max = 16,
203                                         .increment = 0
204                                 },
205                         }, }
206                 }, }
207         },
208         {       /* SHA1 HMAC */
209                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
210                 {.sym = {
211                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
212                         {.auth = {
213                                 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
214                                 .block_size = 64,
215                                 .key_size = {
216                                         .min = 1,
217                                         .max = 64,
218                                         .increment = 1
219                                 },
220                                 .digest_size = {
221                                         .min = 20,
222                                         .max = 20,
223                                         .increment = 0
224                                 },
225                         }, }
226                 }, }
227         },
228         {       /* SHA224 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_SHA224_HMAC,
234                                 .block_size = 64,
235                                 .key_size = {
236                                         .min = 1,
237                                         .max = 64,
238                                         .increment = 1
239                                 },
240                                 .digest_size = {
241                                         .min = 28,
242                                         .max = 28,
243                                         .increment = 0
244                                 },
245                         }, }
246                 }, }
247         },
248         {       /* SHA256 HMAC */
249                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
250                 {.sym = {
251                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
252                         {.auth = {
253                                 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
254                                 .block_size = 64,
255                                 .key_size = {
256                                         .min = 1,
257                                         .max = 64,
258                                         .increment = 1
259                                 },
260                                 .digest_size = {
261                                         .min = 32,
262                                         .max = 32,
263                                         .increment = 0
264                                 },
265                         }, }
266                 }, }
267         },
268         {       /* SHA384 HMAC */
269                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
270                 {.sym = {
271                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
272                         {.auth = {
273                                 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
274                                 .block_size = 128,
275                                 .key_size = {
276                                         .min = 1,
277                                         .max = 128,
278                                         .increment = 1
279                                 },
280                                 .digest_size = {
281                                         .min = 48,
282                                         .max = 48,
283                                         .increment = 0
284                                 },
285                         }, }
286                 }, }
287         },
288         {       /* SHA512 HMAC */
289                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
290                 {.sym = {
291                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
292                         {.auth = {
293                                 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
294                                 .block_size = 128,
295                                 .key_size = {
296                                         .min = 1,
297                                         .max = 128,
298                                         .increment = 1
299                                 },
300                                 .digest_size = {
301                                         .min = 64,
302                                         .max = 64,
303                                         .increment = 0
304                                 },
305                         }, }
306                 }, }
307         },
308         {       /* AES GCM */
309                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
310                 {.sym = {
311                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
312                         {.auth = {
313                                 .algo = RTE_CRYPTO_AEAD_AES_GCM,
314                                 .block_size = 16,
315                                 .key_size = {
316                                         .min = 16,
317                                         .max = 32,
318                                         .increment = 8
319                                 },
320                                 .digest_size = {
321                                         .min = 8,
322                                         .max = 16,
323                                         .increment = 4
324                                 },
325                                 .aad_size = {
326                                         .min = 0,
327                                         .max = 240,
328                                         .increment = 1
329                                 },
330                                 .iv_size = {
331                                         .min = 12,
332                                         .max = 12,
333                                         .increment = 0
334                                 },
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         {       /* AES CTR */
359                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
360                 {.sym = {
361                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
362                         {.cipher = {
363                                 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
364                                 .block_size = 16,
365                                 .key_size = {
366                                         .min = 16,
367                                         .max = 32,
368                                         .increment = 8
369                                 },
370                                 .iv_size = {
371                                         .min = 16,
372                                         .max = 16,
373                                         .increment = 0
374                                 }
375                         }, }
376                 }, }
377         },
378         {       /* 3DES CBC */
379                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
380                 {.sym = {
381                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
382                         {.cipher = {
383                                 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
384                                 .block_size = 8,
385                                 .key_size = {
386                                         .min = 16,
387                                         .max = 24,
388                                         .increment = 8
389                                 },
390                                 .iv_size = {
391                                         .min = 8,
392                                         .max = 8,
393                                         .increment = 0
394                                 }
395                         }, }
396                 }, }
397         },
398
399         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
400 };
401
402 #endif /* _DPAA_SEC_H_ */