e9b888186e22c0fa745e315b312d9af4c1c026ac
[dpdk.git] / drivers / crypto / dpaa2_sec / dpaa2_sec_priv.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4  *   Copyright 2016,2020-2021 NXP
5  *
6  */
7
8 #ifndef _DPAA2_SEC_PMD_PRIVATE_H_
9 #define _DPAA2_SEC_PMD_PRIVATE_H_
10
11 #ifdef RTE_LIB_SECURITY
12 #include <rte_security_driver.h>
13 #endif
14
15 #define CRYPTODEV_NAME_DPAA2_SEC_PMD    crypto_dpaa2_sec
16 /**< NXP DPAA2 - SEC PMD device name */
17
18 extern uint8_t cryptodev_driver_id;
19
20 /* FLE_POOL_NUM_BUFS is set as per the ipsec-secgw application */
21 #define FLE_POOL_NUM_BUFS       32000
22 #define FLE_POOL_BUF_SIZE       256
23 #define FLE_POOL_CACHE_SIZE     512
24 #define FLE_SG_MEM_SIZE(num)    (FLE_POOL_BUF_SIZE + ((num) * 32))
25 #define SEC_FLC_DHR_OUTBOUND    -114
26 #define SEC_FLC_DHR_INBOUND     0
27
28 #define MAX_QUEUES              64
29 #define MAX_DESC_SIZE           64
30 /** private data structure for each DPAA2_SEC device */
31 struct dpaa2_sec_dev_private {
32         void *mc_portal; /**< MC Portal for configuring this device */
33         void *hw; /**< Hardware handle for this device.Used by NADK framework */
34         struct rte_mempool *fle_pool; /* per device memory pool for FLE */
35         int32_t hw_id; /**< An unique ID of this device instance */
36         int32_t vfio_fd; /**< File descriptor received via VFIO */
37         uint16_t token; /**< Token required by DPxxx objects */
38         unsigned int max_nb_queue_pairs;
39         /**< Max number of queue pairs supported by device */
40 };
41
42 struct dpaa2_sec_qp {
43         struct dpaa2_queue rx_vq;
44         struct dpaa2_queue tx_vq;
45 };
46
47 enum shr_desc_type {
48         DESC_UPDATE,
49         DESC_FINAL,
50         DESC_INITFINAL,
51 };
52
53 #define DIR_ENC                 1
54 #define DIR_DEC                 0
55
56 #define DPAA2_IPv6_DEFAULT_VTC_FLOW     0x60000000
57
58 #define DPAA2_SET_FLC_EWS(flc)  (flc->word1_bits23_16 |= 0x1)
59 #define DPAA2_SET_FLC_RSC(flc)  (flc->word1_bits31_24 |= 0x1)
60 #define DPAA2_SET_FLC_REUSE_BS(flc) (flc->mode_bits |= 0x8000)
61 #define DPAA2_SET_FLC_REUSE_FF(flc) (flc->mode_bits |= 0x2000)
62
63 /* SEC Flow Context Descriptor */
64 struct sec_flow_context {
65         /* word 0 */
66         uint16_t word0_sdid;            /* 11-0  SDID */
67         uint16_t word0_res;             /* 31-12 reserved */
68
69         /* word 1 */
70         uint8_t word1_sdl;              /* 5-0 SDL */
71                                         /* 7-6 reserved */
72
73         uint8_t word1_bits_15_8;        /* 11-8 CRID */
74                                         /* 14-12 reserved */
75                                         /* 15 CRJD */
76
77         uint8_t word1_bits23_16;        /* 16  EWS */
78                                         /* 17 DAC */
79                                         /* 18,19,20 ? */
80                                         /* 23-21 reserved */
81
82         uint8_t word1_bits31_24;        /* 24 RSC */
83                                         /* 25 RBMT */
84                                         /* 31-26 reserved */
85
86         /* word 2  RFLC[31-0] */
87         uint32_t word2_rflc_31_0;
88
89         /* word 3  RFLC[63-32] */
90         uint32_t word3_rflc_63_32;
91
92         /* word 4 */
93         uint16_t word4_iicid;           /* 15-0  IICID */
94         uint16_t word4_oicid;           /* 31-16 OICID */
95
96         /* word 5 */
97         uint32_t word5_ofqid:24;                /* 23-0 OFQID */
98         uint32_t word5_31_24:8;
99                                         /* 24 OSC */
100                                         /* 25 OBMT */
101                                         /* 29-26 reserved */
102                                         /* 31-30 ICR */
103
104         /* word 6 */
105         uint32_t word6_oflc_31_0;
106
107         /* word 7 */
108         uint32_t word7_oflc_63_32;
109
110         /* Word 8-15 storage profiles */
111         uint16_t dl;                    /**<  DataLength(correction) */
112         uint16_t reserved;              /**< reserved */
113         uint16_t dhr;                   /**< DataHeadRoom(correction) */
114         uint16_t mode_bits;             /**< mode bits */
115         uint16_t bpv0;                  /**< buffer pool0 valid */
116         uint16_t bpid0;                 /**< Bypass Memory Translation */
117         uint16_t bpv1;                  /**< buffer pool1 valid */
118         uint16_t bpid1;                 /**< Bypass Memory Translation */
119         uint64_t word_12_15[2];         /**< word 12-15 are reserved */
120 };
121
122 struct sec_flc_desc {
123         struct sec_flow_context flc;
124         uint32_t desc[MAX_DESC_SIZE];
125 };
126
127 struct ctxt_priv {
128         struct rte_mempool *fle_pool; /* per device memory pool for FLE */
129         struct sec_flc_desc flc_desc[0];
130 };
131
132 enum dpaa2_sec_op_type {
133         DPAA2_SEC_NONE,  /*!< No Cipher operations*/
134         DPAA2_SEC_CIPHER,/*!< CIPHER operations */
135         DPAA2_SEC_AUTH,  /*!< Authentication Operations */
136         DPAA2_SEC_AEAD,  /*!< AEAD (AES-GCM/CCM) type operations */
137         DPAA2_SEC_CIPHER_HASH,  /*!< Authenticated Encryption with
138                                  * associated data
139                                  */
140         DPAA2_SEC_HASH_CIPHER,  /*!< Encryption with Authenticated
141                                  * associated data
142                                  */
143         DPAA2_SEC_IPSEC, /*!< IPSEC protocol operations*/
144         DPAA2_SEC_PDCP,  /*!< PDCP protocol operations*/
145         DPAA2_SEC_PKC,   /*!< Public Key Cryptographic Operations */
146         DPAA2_SEC_MAX
147 };
148
149 struct dpaa2_sec_aead_ctxt {
150         uint16_t auth_only_len; /*!< Length of data for Auth only */
151         uint8_t auth_cipher_text;       /**< Authenticate/cipher ordering */
152 };
153
154 #ifdef RTE_LIB_SECURITY
155 /*
156  * The structure is to be filled by user for PDCP Protocol
157  */
158 struct dpaa2_pdcp_ctxt {
159         enum rte_security_pdcp_domain domain; /*!< Data/Control mode*/
160         int8_t bearer;  /*!< PDCP bearer ID */
161         int8_t pkt_dir;/*!< PDCP Frame Direction 0:UL 1:DL*/
162         int8_t hfn_ovd;/*!< Overwrite HFN per packet*/
163         uint8_t sn_size;        /*!< Sequence number size, 5/7/12/15/18 */
164         uint32_t hfn_ovd_offset;/*!< offset from rte_crypto_op at which
165                                  * per packet hfn is stored
166                                  */
167         uint32_t hfn;   /*!< Hyper Frame Number */
168         uint32_t hfn_threshold; /*!< HFN Threashold for key renegotiation */
169 };
170 #endif
171
172 typedef int (*dpaa2_sec_build_fd_t)(
173         void *qp, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
174         uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
175         struct rte_crypto_va_iova_ptr *iv,
176         struct rte_crypto_va_iova_ptr *digest,
177         struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
178         void *user_data);
179
180 typedef int (*dpaa2_sec_build_raw_dp_fd_t)(uint8_t *drv_ctx,
181                        struct rte_crypto_sgl *sgl,
182                        struct rte_crypto_va_iova_ptr *iv,
183                        struct rte_crypto_va_iova_ptr *digest,
184                        struct rte_crypto_va_iova_ptr *auth_iv,
185                        union rte_crypto_sym_ofs ofs,
186                        void *userdata,
187                        struct qbman_fd *fd);
188
189 typedef struct dpaa2_sec_session_entry {
190         void *ctxt;
191         uint8_t ctxt_type;
192         uint8_t dir;         /*!< Operation Direction */
193         enum rte_crypto_cipher_algorithm cipher_alg; /*!< Cipher Algorithm*/
194         enum rte_crypto_auth_algorithm auth_alg; /*!< Authentication Algorithm*/
195         enum rte_crypto_aead_algorithm aead_alg; /*!< AEAD Algorithm*/
196         dpaa2_sec_build_fd_t build_fd;
197         dpaa2_sec_build_raw_dp_fd_t build_raw_dp_fd;
198         union {
199                 struct {
200                         uint8_t *data;  /**< pointer to key data */
201                         size_t length;  /**< key length in bytes */
202                 } aead_key;
203                 struct {
204                         struct {
205                                 uint8_t *data;  /**< pointer to key data */
206                                 size_t length;  /**< key length in bytes */
207                         } cipher_key;
208                         struct {
209                                 uint8_t *data;  /**< pointer to key data */
210                                 size_t length;  /**< key length in bytes */
211                         } auth_key;
212                 };
213         };
214         union {
215                 struct {
216                         struct {
217                                 uint16_t length; /**< IV length in bytes */
218                                 uint16_t offset; /**< IV offset in bytes */
219                         } iv;
220                         uint16_t digest_length;
221                         uint8_t status;
222                         union {
223                                 struct dpaa2_sec_aead_ctxt aead_ctxt;
224                         } ext_params;
225                 };
226 #ifdef RTE_LIB_SECURITY
227                 struct dpaa2_pdcp_ctxt pdcp;
228 #endif
229         };
230 } dpaa2_sec_session;
231
232 static const struct rte_cryptodev_capabilities dpaa2_sec_capabilities[] = {
233         /* Symmetric capabilities */
234         {       /* NULL (AUTH) */
235                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
236                 {.sym = {
237                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
238                         {.auth = {
239                                 .algo = RTE_CRYPTO_AUTH_NULL,
240                                 .block_size = 1,
241                                 .key_size = {
242                                         .min = 0,
243                                         .max = 0,
244                                         .increment = 0
245                                 },
246                                 .digest_size = {
247                                         .min = 0,
248                                         .max = 0,
249                                         .increment = 0
250                                 },
251                                 .iv_size = { 0 }
252                         }, },
253                 }, },
254         },
255         {       /* MD5 */
256                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
257                 {.sym = {
258                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
259                         {.auth = {
260                                 .algo = RTE_CRYPTO_AUTH_MD5,
261                                 .block_size = 64,
262                                 .key_size = {
263                                         .min = 0,
264                                         .max = 0,
265                                         .increment = 0
266                                 },
267                                 .digest_size = {
268                                         .min = 16,
269                                         .max = 16,
270                                         .increment = 0
271                                 },
272                                 .iv_size = { 0 }
273                         }, }
274                 }, }
275         },
276         {       /* MD5 HMAC */
277                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
278                 {.sym = {
279                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
280                         {.auth = {
281                                 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
282                                 .block_size = 64,
283                                 .key_size = {
284                                         .min = 1,
285                                         .max = 64,
286                                         .increment = 1
287                                 },
288                                 .digest_size = {
289                                         .min = 1,
290                                         .max = 16,
291                                         .increment = 1
292                                 },
293                                 .iv_size = { 0 }
294                         }, }
295                 }, }
296         },
297         {       /* SHA1 */
298                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
299                 {.sym = {
300                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
301                         {.auth = {
302                                 .algo = RTE_CRYPTO_AUTH_SHA1,
303                                 .block_size = 64,
304                                 .key_size = {
305                                         .min = 0,
306                                         .max = 0,
307                                         .increment = 0
308                                 },
309                                 .digest_size = {
310                                         .min = 20,
311                                         .max = 20,
312                                         .increment = 0
313                                 },
314                                 .iv_size = { 0 }
315                         }, }
316                 }, }
317         },
318         {       /* SHA1 HMAC */
319                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
320                 {.sym = {
321                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
322                         {.auth = {
323                                 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
324                                 .block_size = 64,
325                                 .key_size = {
326                                         .min = 1,
327                                         .max = 64,
328                                         .increment = 1
329                                 },
330                                 .digest_size = {
331                                         .min = 1,
332                                         .max = 20,
333                                         .increment = 1
334                                 },
335                                 .iv_size = { 0 }
336                         }, }
337                 }, }
338         },
339         {       /* SHA224 */
340                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
341                 {.sym = {
342                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
343                         {.auth = {
344                                 .algo = RTE_CRYPTO_AUTH_SHA224,
345                                 .block_size = 64,
346                                         .key_size = {
347                                         .min = 0,
348                                         .max = 0,
349                                         .increment = 0
350                                 },
351                                 .digest_size = {
352                                         .min = 28,
353                                         .max = 28,
354                                         .increment = 0
355                                 },
356                                 .iv_size = { 0 }
357                         }, }
358                 }, }
359         },
360         {       /* SHA224 HMAC */
361                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
362                 {.sym = {
363                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
364                         {.auth = {
365                                 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
366                                 .block_size = 64,
367                                 .key_size = {
368                                         .min = 1,
369                                         .max = 64,
370                                         .increment = 1
371                                 },
372                                 .digest_size = {
373                                         .min = 1,
374                                         .max = 28,
375                                         .increment = 1
376                                 },
377                                 .iv_size = { 0 }
378                         }, }
379                 }, }
380         },
381         {       /* SHA256 */
382                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
383                 {.sym = {
384                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
385                         {.auth = {
386                                 .algo = RTE_CRYPTO_AUTH_SHA256,
387                                 .block_size = 64,
388                                 .key_size = {
389                                         .min = 0,
390                                         .max = 0,
391                                         .increment = 0
392                                 },
393                                 .digest_size = {
394                                         .min = 32,
395                                         .max = 32,
396                                         .increment = 0
397                                 },
398                                 .iv_size = { 0 }
399                         }, }
400                 }, }
401         },
402         {       /* SHA256 HMAC */
403                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
404                 {.sym = {
405                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
406                         {.auth = {
407                                 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
408                                 .block_size = 64,
409                                 .key_size = {
410                                         .min = 1,
411                                         .max = 64,
412                                         .increment = 1
413                                 },
414                                 .digest_size = {
415                                         .min = 1,
416                                         .max = 32,
417                                         .increment = 1
418                                 },
419                                 .iv_size = { 0 }
420                         }, }
421                 }, }
422         },
423         {       /* SHA384 */
424                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
425                 {.sym = {
426                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
427                         {.auth = {
428                                 .algo = RTE_CRYPTO_AUTH_SHA384,
429                                 .block_size = 64,
430                                 .key_size = {
431                                         .min = 0,
432                                         .max = 0,
433                                         .increment = 0
434                                 },
435                                 .digest_size = {
436                                         .min = 48,
437                                         .max = 48,
438                                         .increment = 0
439                                         },
440                                 .iv_size = { 0 }
441                         }, }
442                 }, }
443         },
444         {       /* SHA384 HMAC */
445                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
446                 {.sym = {
447                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
448                         {.auth = {
449                                 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
450                                 .block_size = 128,
451                                 .key_size = {
452                                         .min = 1,
453                                         .max = 128,
454                                         .increment = 1
455                                 },
456                                 .digest_size = {
457                                         .min = 1,
458                                         .max = 48,
459                                         .increment = 1
460                                 },
461                                 .iv_size = { 0 }
462                         }, }
463                 }, }
464         },
465         {       /* SHA512 */
466                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
467                 {.sym = {
468                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
469                         {.auth = {
470                                 .algo = RTE_CRYPTO_AUTH_SHA512,
471                                 .block_size = 128,
472                                 .key_size = {
473                                         .min = 0,
474                                         .max = 0,
475                                         .increment = 0
476                                 },
477                                 .digest_size = {
478                                         .min = 64,
479                                         .max = 64,
480                                         .increment = 0
481                                 },
482                                 .iv_size = { 0 }
483                         }, }
484                 }, }
485         },
486         {       /* SHA512 HMAC */
487                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
488                 {.sym = {
489                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
490                         {.auth = {
491                                 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
492                                 .block_size = 128,
493                                 .key_size = {
494                                         .min = 1,
495                                         .max = 128,
496                                         .increment = 1
497                                 },
498                                 .digest_size = {
499                                         .min = 1,
500                                         .max = 64,
501                                         .increment = 1
502                                 },
503                                 .iv_size = { 0 }
504                         }, }
505                 }, }
506         },
507         {       /* AES GCM */
508                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
509                 {.sym = {
510                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
511                         {.aead = {
512                                 .algo = RTE_CRYPTO_AEAD_AES_GCM,
513                                 .block_size = 16,
514                                 .key_size = {
515                                         .min = 16,
516                                         .max = 32,
517                                         .increment = 8
518                                 },
519                                 .digest_size = {
520                                         .min = 8,
521                                         .max = 16,
522                                         .increment = 4
523                                 },
524                                 .aad_size = {
525                                         .min = 0,
526                                         .max = 240,
527                                         .increment = 1
528                                 },
529                                 .iv_size = {
530                                         .min = 12,
531                                         .max = 12,
532                                         .increment = 0
533                                 },
534                         }, }
535                 }, }
536         },
537         {       /* AES XCBC HMAC */
538                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
539                 {.sym = {
540                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
541                         {.auth = {
542                                 .algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC,
543                                 .block_size = 16,
544                                 .key_size = {
545                                         .min = 1,
546                                         .max = 16,
547                                         .increment = 1
548                                 },
549                                 .digest_size = {
550                                         .min = 12,
551                                         .max = 16,
552                                         .increment = 4
553                                 },
554                                 .aad_size = { 0 },
555                                 .iv_size = { 0 }
556                         }, }
557                 }, }
558         },
559         {       /* AES CMAC */
560                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
561                 {.sym = {
562                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
563                         {.auth = {
564                                 .algo = RTE_CRYPTO_AUTH_AES_CMAC,
565                                 .block_size = 16,
566                                 .key_size = {
567                                         .min = 1,
568                                         .max = 16,
569                                         .increment = 1
570                                 },
571                                 .digest_size = {
572                                         .min = 4,
573                                         .max = 16,
574                                         .increment = 4
575                                 },
576                                 .aad_size = { 0 }
577                         }, }
578                 }, }
579         },
580         {       /* AES CBC */
581                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
582                 {.sym = {
583                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
584                         {.cipher = {
585                                 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
586                                 .block_size = 16,
587                                 .key_size = {
588                                         .min = 16,
589                                         .max = 32,
590                                         .increment = 8
591                                 },
592                                 .iv_size = {
593                                         .min = 16,
594                                         .max = 16,
595                                         .increment = 0
596                                 }
597                         }, }
598                 }, }
599         },
600         {       /* AES CTR */
601                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
602                 {.sym = {
603                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
604                         {.cipher = {
605                                 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
606                                 .block_size = 16,
607                                 .key_size = {
608                                         .min = 16,
609                                         .max = 32,
610                                         .increment = 8
611                                 },
612                                 .iv_size = {
613                                         .min = 16,
614                                         .max = 16,
615                                         .increment = 0
616                                 },
617                         }, }
618                 }, }
619         },
620         {       /* DES CBC */
621                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
622                 {.sym = {
623                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
624                         {.cipher = {
625                                 .algo = RTE_CRYPTO_CIPHER_DES_CBC,
626                                 .block_size = 8,
627                                 .key_size = {
628                                         .min = 8,
629                                         .max = 8,
630                                         .increment = 0
631                                 },
632                                 .iv_size = {
633                                         .min = 8,
634                                         .max = 8,
635                                         .increment = 0
636                                 }
637                         }, }
638                 }, }
639         },
640         {       /* 3DES CBC */
641                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
642                 {.sym = {
643                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
644                         {.cipher = {
645                                 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
646                                 .block_size = 8,
647                                 .key_size = {
648                                         .min = 16,
649                                         .max = 24,
650                                         .increment = 8
651                                 },
652                                 .iv_size = {
653                                         .min = 8,
654                                         .max = 8,
655                                         .increment = 0
656                                 }
657                         }, }
658                 }, }
659         },
660         {       /* SNOW 3G (UIA2) */
661                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
662                 {.sym = {
663                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
664                         {.auth = {
665                                 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
666                                 .block_size = 16,
667                                 .key_size = {
668                                         .min = 16,
669                                         .max = 16,
670                                         .increment = 0
671                                 },
672                                 .digest_size = {
673                                         .min = 4,
674                                         .max = 4,
675                                         .increment = 0
676                                 },
677                                 .iv_size = {
678                                         .min = 16,
679                                         .max = 16,
680                                         .increment = 0
681                                 }
682                         }, }
683                 }, }
684         },
685         {       /* SNOW 3G (UEA2) */
686                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
687                 {.sym = {
688                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
689                         {.cipher = {
690                                 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
691                                 .block_size = 16,
692                                 .key_size = {
693                                         .min = 16,
694                                         .max = 16,
695                                         .increment = 0
696                                 },
697                                 .iv_size = {
698                                         .min = 16,
699                                         .max = 16,
700                                         .increment = 0
701                                 }
702                         }, }
703                 }, }
704         },
705         {       /* ZUC (EEA3) */
706                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
707                 {.sym = {
708                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
709                         {.cipher = {
710                                 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
711                                 .block_size = 16,
712                                 .key_size = {
713                                         .min = 16,
714                                         .max = 16,
715                                         .increment = 0
716                                 },
717                                 .iv_size = {
718                                         .min = 16,
719                                         .max = 16,
720                                         .increment = 0
721                                 }
722                         }, }
723                 }, }
724         },
725         {       /* ZUC (EIA3) */
726                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
727                 {.sym = {
728                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
729                         {.auth = {
730                                 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
731                                 .block_size = 16,
732                                 .key_size = {
733                                         .min = 16,
734                                         .max = 16,
735                                         .increment = 0
736                                 },
737                                 .digest_size = {
738                                         .min = 4,
739                                         .max = 4,
740                                         .increment = 0
741                                 },
742                                 .iv_size = {
743                                         .min = 16,
744                                         .max = 16,
745                                         .increment = 0
746                                 }
747                         }, }
748                 }, }
749         },
750         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
751 };
752
753 #ifdef RTE_LIB_SECURITY
754
755 static const struct rte_cryptodev_capabilities dpaa2_pdcp_capabilities[] = {
756         {       /* SNOW 3G (UIA2) */
757                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
758                 {.sym = {
759                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
760                         {.auth = {
761                                 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
762                                 .block_size = 16,
763                                 .key_size = {
764                                         .min = 16,
765                                         .max = 16,
766                                         .increment = 0
767                                 },
768                                 .digest_size = {
769                                         .min = 4,
770                                         .max = 4,
771                                         .increment = 0
772                                 },
773                                 .iv_size = {
774                                         .min = 16,
775                                         .max = 16,
776                                         .increment = 0
777                                 }
778                         }, }
779                 }, }
780         },
781         {       /* SNOW 3G (UEA2) */
782                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
783                 {.sym = {
784                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
785                         {.cipher = {
786                                 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
787                                 .block_size = 16,
788                                 .key_size = {
789                                         .min = 16,
790                                         .max = 16,
791                                         .increment = 0
792                                 },
793                                 .iv_size = {
794                                         .min = 16,
795                                         .max = 16,
796                                         .increment = 0
797                                 }
798                         }, }
799                 }, }
800         },
801         {       /* AES CTR */
802                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
803                 {.sym = {
804                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
805                         {.cipher = {
806                                 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
807                                 .block_size = 16,
808                                 .key_size = {
809                                         .min = 16,
810                                         .max = 32,
811                                         .increment = 8
812                                 },
813                                 .iv_size = {
814                                         .min = 16,
815                                         .max = 16,
816                                         .increment = 0
817                                 }
818                         }, }
819                 }, }
820         },
821         {       /* NULL (AUTH) */
822                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
823                 {.sym = {
824                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
825                         {.auth = {
826                                 .algo = RTE_CRYPTO_AUTH_NULL,
827                                 .block_size = 1,
828                                 .key_size = {
829                                         .min = 0,
830                                         .max = 0,
831                                         .increment = 0
832                                 },
833                                 .digest_size = {
834                                         .min = 0,
835                                         .max = 0,
836                                         .increment = 0
837                                 },
838                                 .iv_size = { 0 }
839                         }, },
840                 }, },
841         },
842         {       /* NULL (CIPHER) */
843                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
844                 {.sym = {
845                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
846                         {.cipher = {
847                                 .algo = RTE_CRYPTO_CIPHER_NULL,
848                                 .block_size = 1,
849                                 .key_size = {
850                                         .min = 0,
851                                         .max = 0,
852                                         .increment = 0
853                                 },
854                                 .iv_size = {
855                                         .min = 0,
856                                         .max = 0,
857                                         .increment = 0
858                                 }
859                         }, },
860                 }, }
861         },
862         {       /* ZUC (EEA3) */
863                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
864                 {.sym = {
865                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
866                         {.cipher = {
867                                 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
868                                 .block_size = 16,
869                                 .key_size = {
870                                         .min = 16,
871                                         .max = 16,
872                                         .increment = 0
873                                 },
874                                 .iv_size = {
875                                         .min = 16,
876                                         .max = 16,
877                                         .increment = 0
878                                 }
879                         }, }
880                 }, }
881         },
882         {       /* ZUC (EIA3) */
883                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
884                 {.sym = {
885                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
886                         {.auth = {
887                                 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
888                                 .block_size = 16,
889                                 .key_size = {
890                                         .min = 16,
891                                         .max = 16,
892                                         .increment = 0
893                                 },
894                                 .digest_size = {
895                                         .min = 4,
896                                         .max = 4,
897                                         .increment = 0
898                                 },
899                                 .iv_size = {
900                                         .min = 16,
901                                         .max = 16,
902                                         .increment = 0
903                                 }
904                         }, }
905                 }, }
906         },
907
908         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
909 };
910
911 static const struct rte_security_capability dpaa2_sec_security_cap[] = {
912         { /* IPsec Lookaside Protocol offload ESP Transport Egress */
913                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
914                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
915                 .ipsec = {
916                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
917                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
918                         .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
919                         .options = { 0 },
920                         .replay_win_sz_max = 128
921                 },
922                 .crypto_capabilities = dpaa2_sec_capabilities
923         },
924         { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
925                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
926                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
927                 .ipsec = {
928                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
929                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
930                         .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
931                         .options = { 0 },
932                         .replay_win_sz_max = 128
933                 },
934                 .crypto_capabilities = dpaa2_sec_capabilities
935         },
936         { /* PDCP Lookaside Protocol offload Data */
937                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
938                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
939                 .pdcp = {
940                         .domain = RTE_SECURITY_PDCP_MODE_DATA,
941                         .capa_flags = 0
942                 },
943                 .crypto_capabilities = dpaa2_pdcp_capabilities
944         },
945         { /* PDCP Lookaside Protocol offload Control */
946                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
947                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
948                 .pdcp = {
949                         .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
950                         .capa_flags = 0
951                 },
952                 .crypto_capabilities = dpaa2_pdcp_capabilities
953         },
954         { /* PDCP Lookaside Protocol offload Short MAC */
955                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
956                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
957                 .pdcp = {
958                         .domain = RTE_SECURITY_PDCP_MODE_SHORT_MAC,
959                         .capa_flags = 0
960                 },
961                 .crypto_capabilities = dpaa2_pdcp_capabilities
962         },
963         {
964                 .action = RTE_SECURITY_ACTION_TYPE_NONE
965         }
966 };
967 #endif
968 /**
969  * Checksum
970  *
971  * @param buffer calculate chksum for buffer
972  * @param len    buffer length
973  *
974  * @return checksum value in host cpu order
975  */
976 static inline uint16_t
977 calc_chksum(void *buffer, int len)
978 {
979         uint16_t *buf = (uint16_t *)buffer;
980         uint32_t sum = 0;
981         uint16_t result;
982
983         for (sum = 0; len > 1; len -= 2)
984                 sum += *buf++;
985
986         if (len == 1)
987                 sum += *(unsigned char *)buf;
988
989         sum = (sum >> 16) + (sum & 0xFFFF);
990         sum += (sum >> 16);
991         result = ~sum;
992
993         return  result;
994 }
995
996 int
997 dpaa2_sec_configure_raw_dp_ctx(struct rte_cryptodev *dev, uint16_t qp_id,
998         struct rte_crypto_raw_dp_ctx *raw_dp_ctx,
999         enum rte_crypto_op_sess_type sess_type,
1000         union rte_cryptodev_session_ctx session_ctx, uint8_t is_update);
1001
1002 int
1003 dpaa2_sec_get_dp_ctx_size(struct rte_cryptodev *dev);
1004
1005
1006 #endif /* _DPAA2_SEC_PMD_PRIVATE_H_ */