f397b756e8086c68d2c0b889fe9ec89806419fd6
[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         {       /* MD5 */
235                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
236                 {.sym = {
237                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
238                         {.auth = {
239                                 .algo = RTE_CRYPTO_AUTH_MD5,
240                                 .block_size = 64,
241                                 .key_size = {
242                                         .min = 0,
243                                         .max = 0,
244                                         .increment = 0
245                                 },
246                                 .digest_size = {
247                                         .min = 16,
248                                         .max = 16,
249                                         .increment = 0
250                                 },
251                                 .iv_size = { 0 }
252                         }, }
253                 }, }
254         },
255         {       /* MD5 HMAC */
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_HMAC,
261                                 .block_size = 64,
262                                 .key_size = {
263                                         .min = 1,
264                                         .max = 64,
265                                         .increment = 1
266                                 },
267                                 .digest_size = {
268                                         .min = 1,
269                                         .max = 16,
270                                         .increment = 1
271                                 },
272                                 .iv_size = { 0 }
273                         }, }
274                 }, }
275         },
276         {       /* SHA1 */
277                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
278                 {.sym = {
279                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
280                         {.auth = {
281                                 .algo = RTE_CRYPTO_AUTH_SHA1,
282                                 .block_size = 64,
283                                 .key_size = {
284                                         .min = 0,
285                                         .max = 0,
286                                         .increment = 0
287                                 },
288                                 .digest_size = {
289                                         .min = 20,
290                                         .max = 20,
291                                         .increment = 0
292                                 },
293                                 .iv_size = { 0 }
294                         }, }
295                 }, }
296         },
297         {       /* SHA1 HMAC */
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_HMAC,
303                                 .block_size = 64,
304                                 .key_size = {
305                                         .min = 1,
306                                         .max = 64,
307                                         .increment = 1
308                                 },
309                                 .digest_size = {
310                                         .min = 1,
311                                         .max = 20,
312                                         .increment = 1
313                                 },
314                                 .iv_size = { 0 }
315                         }, }
316                 }, }
317         },
318         {       /* SHA224 */
319                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
320                 {.sym = {
321                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
322                         {.auth = {
323                                 .algo = RTE_CRYPTO_AUTH_SHA224,
324                                 .block_size = 64,
325                                         .key_size = {
326                                         .min = 0,
327                                         .max = 0,
328                                         .increment = 0
329                                 },
330                                 .digest_size = {
331                                         .min = 28,
332                                         .max = 28,
333                                         .increment = 0
334                                 },
335                                 .iv_size = { 0 }
336                         }, }
337                 }, }
338         },
339         {       /* SHA224 HMAC */
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_HMAC,
345                                 .block_size = 64,
346                                 .key_size = {
347                                         .min = 1,
348                                         .max = 64,
349                                         .increment = 1
350                                 },
351                                 .digest_size = {
352                                         .min = 1,
353                                         .max = 28,
354                                         .increment = 1
355                                 },
356                                 .iv_size = { 0 }
357                         }, }
358                 }, }
359         },
360         {       /* SHA256 */
361                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
362                 {.sym = {
363                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
364                         {.auth = {
365                                 .algo = RTE_CRYPTO_AUTH_SHA256,
366                                 .block_size = 64,
367                                 .key_size = {
368                                         .min = 0,
369                                         .max = 0,
370                                         .increment = 0
371                                 },
372                                 .digest_size = {
373                                         .min = 32,
374                                         .max = 32,
375                                         .increment = 0
376                                 },
377                                 .iv_size = { 0 }
378                         }, }
379                 }, }
380         },
381         {       /* SHA256 HMAC */
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_HMAC,
387                                 .block_size = 64,
388                                 .key_size = {
389                                         .min = 1,
390                                         .max = 64,
391                                         .increment = 1
392                                 },
393                                 .digest_size = {
394                                         .min = 1,
395                                         .max = 32,
396                                         .increment = 1
397                                 },
398                                 .iv_size = { 0 }
399                         }, }
400                 }, }
401         },
402         {       /* SHA384 */
403                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
404                 {.sym = {
405                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
406                         {.auth = {
407                                 .algo = RTE_CRYPTO_AUTH_SHA384,
408                                 .block_size = 64,
409                                 .key_size = {
410                                         .min = 0,
411                                         .max = 0,
412                                         .increment = 0
413                                 },
414                                 .digest_size = {
415                                         .min = 48,
416                                         .max = 48,
417                                         .increment = 0
418                                         },
419                                 .iv_size = { 0 }
420                         }, }
421                 }, }
422         },
423         {       /* SHA384 HMAC */
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_HMAC,
429                                 .block_size = 128,
430                                 .key_size = {
431                                         .min = 1,
432                                         .max = 128,
433                                         .increment = 1
434                                 },
435                                 .digest_size = {
436                                         .min = 1,
437                                         .max = 48,
438                                         .increment = 1
439                                 },
440                                 .iv_size = { 0 }
441                         }, }
442                 }, }
443         },
444         {       /* SHA512 */
445                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
446                 {.sym = {
447                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
448                         {.auth = {
449                                 .algo = RTE_CRYPTO_AUTH_SHA512,
450                                 .block_size = 128,
451                                 .key_size = {
452                                         .min = 0,
453                                         .max = 0,
454                                         .increment = 0
455                                 },
456                                 .digest_size = {
457                                         .min = 64,
458                                         .max = 64,
459                                         .increment = 0
460                                 },
461                                 .iv_size = { 0 }
462                         }, }
463                 }, }
464         },
465         {       /* SHA512 HMAC */
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_HMAC,
471                                 .block_size = 128,
472                                 .key_size = {
473                                         .min = 1,
474                                         .max = 128,
475                                         .increment = 1
476                                 },
477                                 .digest_size = {
478                                         .min = 1,
479                                         .max = 64,
480                                         .increment = 1
481                                 },
482                                 .iv_size = { 0 }
483                         }, }
484                 }, }
485         },
486         {       /* AES GCM */
487                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
488                 {.sym = {
489                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
490                         {.aead = {
491                                 .algo = RTE_CRYPTO_AEAD_AES_GCM,
492                                 .block_size = 16,
493                                 .key_size = {
494                                         .min = 16,
495                                         .max = 32,
496                                         .increment = 8
497                                 },
498                                 .digest_size = {
499                                         .min = 8,
500                                         .max = 16,
501                                         .increment = 4
502                                 },
503                                 .aad_size = {
504                                         .min = 0,
505                                         .max = 240,
506                                         .increment = 1
507                                 },
508                                 .iv_size = {
509                                         .min = 12,
510                                         .max = 12,
511                                         .increment = 0
512                                 },
513                         }, }
514                 }, }
515         },
516         {       /* AES XCBC HMAC */
517                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
518                 {.sym = {
519                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
520                         {.auth = {
521                                 .algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC,
522                                 .block_size = 16,
523                                 .key_size = {
524                                         .min = 1,
525                                         .max = 16,
526                                         .increment = 1
527                                 },
528                                 .digest_size = {
529                                         .min = 12,
530                                         .max = 16,
531                                         .increment = 4
532                                 },
533                                 .aad_size = { 0 },
534                                 .iv_size = { 0 }
535                         }, }
536                 }, }
537         },
538         {       /* AES CMAC */
539                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
540                 {.sym = {
541                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
542                         {.auth = {
543                                 .algo = RTE_CRYPTO_AUTH_AES_CMAC,
544                                 .block_size = 16,
545                                 .key_size = {
546                                         .min = 1,
547                                         .max = 16,
548                                         .increment = 1
549                                 },
550                                 .digest_size = {
551                                         .min = 4,
552                                         .max = 16,
553                                         .increment = 4
554                                 },
555                                 .aad_size = { 0 }
556                         }, }
557                 }, }
558         },
559         {       /* AES CBC */
560                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
561                 {.sym = {
562                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
563                         {.cipher = {
564                                 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
565                                 .block_size = 16,
566                                 .key_size = {
567                                         .min = 16,
568                                         .max = 32,
569                                         .increment = 8
570                                 },
571                                 .iv_size = {
572                                         .min = 16,
573                                         .max = 16,
574                                         .increment = 0
575                                 }
576                         }, }
577                 }, }
578         },
579         {       /* AES CTR */
580                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
581                 {.sym = {
582                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
583                         {.cipher = {
584                                 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
585                                 .block_size = 16,
586                                 .key_size = {
587                                         .min = 16,
588                                         .max = 32,
589                                         .increment = 8
590                                 },
591                                 .iv_size = {
592                                         .min = 16,
593                                         .max = 16,
594                                         .increment = 0
595                                 },
596                         }, }
597                 }, }
598         },
599         {       /* DES CBC */
600                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
601                 {.sym = {
602                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
603                         {.cipher = {
604                                 .algo = RTE_CRYPTO_CIPHER_DES_CBC,
605                                 .block_size = 8,
606                                 .key_size = {
607                                         .min = 8,
608                                         .max = 8,
609                                         .increment = 0
610                                 },
611                                 .iv_size = {
612                                         .min = 8,
613                                         .max = 8,
614                                         .increment = 0
615                                 }
616                         }, }
617                 }, }
618         },
619         {       /* 3DES CBC */
620                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
621                 {.sym = {
622                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
623                         {.cipher = {
624                                 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
625                                 .block_size = 8,
626                                 .key_size = {
627                                         .min = 16,
628                                         .max = 24,
629                                         .increment = 8
630                                 },
631                                 .iv_size = {
632                                         .min = 8,
633                                         .max = 8,
634                                         .increment = 0
635                                 }
636                         }, }
637                 }, }
638         },
639         {       /* SNOW 3G (UIA2) */
640                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
641                 {.sym = {
642                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
643                         {.auth = {
644                                 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
645                                 .block_size = 16,
646                                 .key_size = {
647                                         .min = 16,
648                                         .max = 16,
649                                         .increment = 0
650                                 },
651                                 .digest_size = {
652                                         .min = 4,
653                                         .max = 4,
654                                         .increment = 0
655                                 },
656                                 .iv_size = {
657                                         .min = 16,
658                                         .max = 16,
659                                         .increment = 0
660                                 }
661                         }, }
662                 }, }
663         },
664         {       /* SNOW 3G (UEA2) */
665                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
666                 {.sym = {
667                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
668                         {.cipher = {
669                                 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
670                                 .block_size = 16,
671                                 .key_size = {
672                                         .min = 16,
673                                         .max = 16,
674                                         .increment = 0
675                                 },
676                                 .iv_size = {
677                                         .min = 16,
678                                         .max = 16,
679                                         .increment = 0
680                                 }
681                         }, }
682                 }, }
683         },
684         {       /* ZUC (EEA3) */
685                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
686                 {.sym = {
687                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
688                         {.cipher = {
689                                 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
690                                 .block_size = 16,
691                                 .key_size = {
692                                         .min = 16,
693                                         .max = 16,
694                                         .increment = 0
695                                 },
696                                 .iv_size = {
697                                         .min = 16,
698                                         .max = 16,
699                                         .increment = 0
700                                 }
701                         }, }
702                 }, }
703         },
704         {       /* ZUC (EIA3) */
705                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
706                 {.sym = {
707                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
708                         {.auth = {
709                                 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
710                                 .block_size = 16,
711                                 .key_size = {
712                                         .min = 16,
713                                         .max = 16,
714                                         .increment = 0
715                                 },
716                                 .digest_size = {
717                                         .min = 4,
718                                         .max = 4,
719                                         .increment = 0
720                                 },
721                                 .iv_size = {
722                                         .min = 16,
723                                         .max = 16,
724                                         .increment = 0
725                                 }
726                         }, }
727                 }, }
728         },
729         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
730 };
731
732 #ifdef RTE_LIB_SECURITY
733
734 static const struct rte_cryptodev_capabilities dpaa2_pdcp_capabilities[] = {
735         {       /* SNOW 3G (UIA2) */
736                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
737                 {.sym = {
738                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
739                         {.auth = {
740                                 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
741                                 .block_size = 16,
742                                 .key_size = {
743                                         .min = 16,
744                                         .max = 16,
745                                         .increment = 0
746                                 },
747                                 .digest_size = {
748                                         .min = 4,
749                                         .max = 4,
750                                         .increment = 0
751                                 },
752                                 .iv_size = {
753                                         .min = 16,
754                                         .max = 16,
755                                         .increment = 0
756                                 }
757                         }, }
758                 }, }
759         },
760         {       /* SNOW 3G (UEA2) */
761                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
762                 {.sym = {
763                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
764                         {.cipher = {
765                                 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
766                                 .block_size = 16,
767                                 .key_size = {
768                                         .min = 16,
769                                         .max = 16,
770                                         .increment = 0
771                                 },
772                                 .iv_size = {
773                                         .min = 16,
774                                         .max = 16,
775                                         .increment = 0
776                                 }
777                         }, }
778                 }, }
779         },
780         {       /* AES CTR */
781                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
782                 {.sym = {
783                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
784                         {.cipher = {
785                                 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
786                                 .block_size = 16,
787                                 .key_size = {
788                                         .min = 16,
789                                         .max = 32,
790                                         .increment = 8
791                                 },
792                                 .iv_size = {
793                                         .min = 16,
794                                         .max = 16,
795                                         .increment = 0
796                                 }
797                         }, }
798                 }, }
799         },
800         {       /* NULL (AUTH) */
801                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
802                 {.sym = {
803                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
804                         {.auth = {
805                                 .algo = RTE_CRYPTO_AUTH_NULL,
806                                 .block_size = 1,
807                                 .key_size = {
808                                         .min = 0,
809                                         .max = 0,
810                                         .increment = 0
811                                 },
812                                 .digest_size = {
813                                         .min = 0,
814                                         .max = 0,
815                                         .increment = 0
816                                 },
817                                 .iv_size = { 0 }
818                         }, },
819                 }, },
820         },
821         {       /* NULL (CIPHER) */
822                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
823                 {.sym = {
824                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
825                         {.cipher = {
826                                 .algo = RTE_CRYPTO_CIPHER_NULL,
827                                 .block_size = 1,
828                                 .key_size = {
829                                         .min = 0,
830                                         .max = 0,
831                                         .increment = 0
832                                 },
833                                 .iv_size = {
834                                         .min = 0,
835                                         .max = 0,
836                                         .increment = 0
837                                 }
838                         }, },
839                 }, }
840         },
841         {       /* ZUC (EEA3) */
842                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
843                 {.sym = {
844                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
845                         {.cipher = {
846                                 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
847                                 .block_size = 16,
848                                 .key_size = {
849                                         .min = 16,
850                                         .max = 16,
851                                         .increment = 0
852                                 },
853                                 .iv_size = {
854                                         .min = 16,
855                                         .max = 16,
856                                         .increment = 0
857                                 }
858                         }, }
859                 }, }
860         },
861         {       /* ZUC (EIA3) */
862                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
863                 {.sym = {
864                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
865                         {.auth = {
866                                 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
867                                 .block_size = 16,
868                                 .key_size = {
869                                         .min = 16,
870                                         .max = 16,
871                                         .increment = 0
872                                 },
873                                 .digest_size = {
874                                         .min = 4,
875                                         .max = 4,
876                                         .increment = 0
877                                 },
878                                 .iv_size = {
879                                         .min = 16,
880                                         .max = 16,
881                                         .increment = 0
882                                 }
883                         }, }
884                 }, }
885         },
886
887         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
888 };
889
890 static const struct rte_security_capability dpaa2_sec_security_cap[] = {
891         { /* IPsec Lookaside Protocol offload ESP Transport Egress */
892                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
893                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
894                 .ipsec = {
895                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
896                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
897                         .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
898                         .options = { 0 },
899                         .replay_win_sz_max = 128
900                 },
901                 .crypto_capabilities = dpaa2_sec_capabilities
902         },
903         { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
904                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
905                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
906                 .ipsec = {
907                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
908                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
909                         .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
910                         .options = { 0 },
911                         .replay_win_sz_max = 128
912                 },
913                 .crypto_capabilities = dpaa2_sec_capabilities
914         },
915         { /* PDCP Lookaside Protocol offload Data */
916                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
917                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
918                 .pdcp = {
919                         .domain = RTE_SECURITY_PDCP_MODE_DATA,
920                         .capa_flags = 0
921                 },
922                 .crypto_capabilities = dpaa2_pdcp_capabilities
923         },
924         { /* PDCP Lookaside Protocol offload Control */
925                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
926                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
927                 .pdcp = {
928                         .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
929                         .capa_flags = 0
930                 },
931                 .crypto_capabilities = dpaa2_pdcp_capabilities
932         },
933         { /* PDCP Lookaside Protocol offload Short MAC */
934                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
935                 .protocol = RTE_SECURITY_PROTOCOL_PDCP,
936                 .pdcp = {
937                         .domain = RTE_SECURITY_PDCP_MODE_SHORT_MAC,
938                         .capa_flags = 0
939                 },
940                 .crypto_capabilities = dpaa2_pdcp_capabilities
941         },
942         {
943                 .action = RTE_SECURITY_ACTION_TYPE_NONE
944         }
945 };
946 #endif
947 /**
948  * Checksum
949  *
950  * @param buffer calculate chksum for buffer
951  * @param len    buffer length
952  *
953  * @return checksum value in host cpu order
954  */
955 static inline uint16_t
956 calc_chksum(void *buffer, int len)
957 {
958         uint16_t *buf = (uint16_t *)buffer;
959         uint32_t sum = 0;
960         uint16_t result;
961
962         for (sum = 0; len > 1; len -= 2)
963                 sum += *buf++;
964
965         if (len == 1)
966                 sum += *(unsigned char *)buf;
967
968         sum = (sum >> 16) + (sum & 0xFFFF);
969         sum += (sum >> 16);
970         result = ~sum;
971
972         return  result;
973 }
974
975 int
976 dpaa2_sec_configure_raw_dp_ctx(struct rte_cryptodev *dev, uint16_t qp_id,
977         struct rte_crypto_raw_dp_ctx *raw_dp_ctx,
978         enum rte_crypto_op_sess_type sess_type,
979         union rte_cryptodev_session_ctx session_ctx, uint8_t is_update);
980
981 int
982 dpaa2_sec_get_dp_ctx_size(struct rte_cryptodev *dev);
983
984
985 #endif /* _DPAA2_SEC_PMD_PRIVATE_H_ */