crypto/cnxk: add copy and set DF
[dpdk.git] / drivers / crypto / cnxk / cnxk_cryptodev_capabilities.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #include <cryptodev_pmd.h>
6 #include <rte_security.h>
7
8 #include "roc_api.h"
9
10 #include "cnxk_cryptodev.h"
11 #include "cnxk_cryptodev_capabilities.h"
12
13 #define CPT_CAPS_ADD(cnxk_caps, cur_pos, hw_caps, name)                        \
14         do {                                                                   \
15                 if ((hw_caps[CPT_ENG_TYPE_SE].name) ||                         \
16                     (hw_caps[CPT_ENG_TYPE_IE].name) ||                         \
17                     (hw_caps[CPT_ENG_TYPE_AE].name))                           \
18                         cpt_caps_add(cnxk_caps, cur_pos, caps_##name,          \
19                                      RTE_DIM(caps_##name));                    \
20         } while (0)
21
22 #define SEC_CAPS_ADD(cnxk_caps, cur_pos, hw_caps, name)                        \
23         do {                                                                   \
24                 if ((hw_caps[CPT_ENG_TYPE_SE].name) ||                         \
25                     (hw_caps[CPT_ENG_TYPE_IE].name) ||                         \
26                     (hw_caps[CPT_ENG_TYPE_AE].name))                           \
27                         sec_caps_add(cnxk_caps, cur_pos, sec_caps_##name,      \
28                                      RTE_DIM(sec_caps_##name));                \
29         } while (0)
30
31 static const struct rte_cryptodev_capabilities caps_mul[] = {
32         {       /* RSA */
33                 .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
34                 {.asym = {
35                         .xform_capa = {
36                                 .xform_type = RTE_CRYPTO_ASYM_XFORM_RSA,
37                                 .op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) |
38                                         (1 << RTE_CRYPTO_ASYM_OP_VERIFY) |
39                                         (1 << RTE_CRYPTO_ASYM_OP_ENCRYPT) |
40                                         (1 << RTE_CRYPTO_ASYM_OP_DECRYPT)),
41                                 {.modlen = {
42                                         .min = 17,
43                                         .max = 1024,
44                                         .increment = 1
45                                 }, }
46                         }
47                 }, }
48         },
49         {       /* MOD_EXP */
50                 .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
51                 {.asym = {
52                         .xform_capa = {
53                                 .xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX,
54                                 .op_types = 0,
55                                 {.modlen = {
56                                         .min = 17,
57                                         .max = 1024,
58                                         .increment = 1
59                                 }, }
60                         }
61                 }, }
62         },
63         {       /* ECDSA */
64                 .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
65                 {.asym = {
66                         .xform_capa = {
67                                 .xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA,
68                                 .op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) |
69                                         (1 << RTE_CRYPTO_ASYM_OP_VERIFY)),
70                                 }
71                         },
72                 }
73         },
74         {       /* ECPM */
75                 .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
76                 {.asym = {
77                         .xform_capa = {
78                                 .xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM,
79                                 .op_types = 0
80                                 }
81                         },
82                 }
83         },
84 };
85
86 static const struct rte_cryptodev_capabilities caps_sha1_sha2[] = {
87         {       /* SHA1 */
88                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
89                 {.sym = {
90                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
91                         {.auth = {
92                                 .algo = RTE_CRYPTO_AUTH_SHA1,
93                                 .block_size = 64,
94                                 .key_size = {
95                                         .min = 0,
96                                         .max = 0,
97                                         .increment = 0
98                                 },
99                                 .digest_size = {
100                                         .min = 20,
101                                         .max = 20,
102                                         .increment = 0
103                                 },
104                         }, }
105                 }, }
106         },
107         {       /* SHA1 HMAC */
108                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
109                 {.sym = {
110                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
111                         {.auth = {
112                                 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
113                                 .block_size = 64,
114                                 .key_size = {
115                                         .min = 1,
116                                         .max = 1024,
117                                         .increment = 1
118                                 },
119                                 .digest_size = {
120                                         .min = 12,
121                                         .max = 20,
122                                         .increment = 8
123                                 },
124                         }, }
125                 }, }
126         },
127         {       /* SHA224 */
128                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
129                 {.sym = {
130                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
131                         {.auth = {
132                                 .algo = RTE_CRYPTO_AUTH_SHA224,
133                                 .block_size = 64,
134                                         .key_size = {
135                                         .min = 0,
136                                         .max = 0,
137                                         .increment = 0
138                                 },
139                                 .digest_size = {
140                                         .min = 28,
141                                         .max = 28,
142                                         .increment = 0
143                                 },
144                         }, }
145                 }, }
146         },
147         {       /* SHA224 HMAC */
148                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
149                 {.sym = {
150                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
151                         {.auth = {
152                                 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
153                                 .block_size = 64,
154                                         .key_size = {
155                                         .min = 1,
156                                         .max = 1024,
157                                         .increment = 1
158                                 },
159                                 .digest_size = {
160                                         .min = 28,
161                                         .max = 28,
162                                         .increment = 0
163                                 },
164                         }, }
165                 }, }
166         },
167         {       /* SHA256 */
168                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
169                 {.sym = {
170                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
171                         {.auth = {
172                                 .algo = RTE_CRYPTO_AUTH_SHA256,
173                                 .block_size = 64,
174                                 .key_size = {
175                                         .min = 0,
176                                         .max = 0,
177                                         .increment = 0
178                                 },
179                                 .digest_size = {
180                                         .min = 32,
181                                         .max = 32,
182                                         .increment = 0
183                                 },
184                         }, }
185                 }, }
186         },
187         {       /* SHA256 HMAC */
188                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
189                 {.sym = {
190                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
191                         {.auth = {
192                                 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
193                                 .block_size = 64,
194                                 .key_size = {
195                                         .min = 1,
196                                         .max = 1024,
197                                         .increment = 1
198                                 },
199                                 .digest_size = {
200                                         .min = 16,
201                                         .max = 32,
202                                         .increment = 16
203                                 },
204                         }, }
205                 }, }
206         },
207         {       /* SHA384 */
208                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
209                 {.sym = {
210                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
211                         {.auth = {
212                                 .algo = RTE_CRYPTO_AUTH_SHA384,
213                                 .block_size = 64,
214                                 .key_size = {
215                                         .min = 0,
216                                         .max = 0,
217                                         .increment = 0
218                                 },
219                                 .digest_size = {
220                                         .min = 48,
221                                         .max = 48,
222                                         .increment = 0
223                                         },
224                         }, }
225                 }, }
226         },
227         {       /* SHA384 HMAC */
228                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
229                 {.sym = {
230                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
231                         {.auth = {
232                                 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
233                                 .block_size = 64,
234                                 .key_size = {
235                                         .min = 1,
236                                         .max = 1024,
237                                         .increment = 1
238                                 },
239                                 .digest_size = {
240                                         .min = 24,
241                                         .max = 48,
242                                         .increment = 24
243                                         },
244                         }, }
245                 }, }
246         },
247         {       /* SHA512 */
248                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
249                 {.sym = {
250                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
251                         {.auth = {
252                                 .algo = RTE_CRYPTO_AUTH_SHA512,
253                                 .block_size = 128,
254                                 .key_size = {
255                                         .min = 0,
256                                         .max = 0,
257                                         .increment = 0
258                                 },
259                                 .digest_size = {
260                                         .min = 64,
261                                         .max = 64,
262                                         .increment = 0
263                                 },
264                         }, }
265                 }, }
266         },
267         {       /* SHA512 HMAC */
268                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
269                 {.sym = {
270                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
271                         {.auth = {
272                                 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
273                                 .block_size = 128,
274                                 .key_size = {
275                                         .min = 1,
276                                         .max = 1024,
277                                         .increment = 1
278                                 },
279                                 .digest_size = {
280                                         .min = 32,
281                                         .max = 64,
282                                         .increment = 32
283                                 },
284                         }, }
285                 }, }
286         },
287         {       /* MD5 */
288                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
289                 {.sym = {
290                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
291                         {.auth = {
292                                 .algo = RTE_CRYPTO_AUTH_MD5,
293                                 .block_size = 64,
294                                 .key_size = {
295                                         .min = 0,
296                                         .max = 0,
297                                         .increment = 0
298                                 },
299                                 .digest_size = {
300                                         .min = 16,
301                                         .max = 16,
302                                         .increment = 0
303                                 },
304                         }, }
305                 }, }
306         },
307         {       /* MD5 HMAC */
308                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
309                 {.sym = {
310                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
311                         {.auth = {
312                                 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
313                                 .block_size = 64,
314                                 .key_size = {
315                                         .min = 8,
316                                         .max = 64,
317                                         .increment = 8
318                                 },
319                                 .digest_size = {
320                                         .min = 12,
321                                         .max = 16,
322                                         .increment = 4
323                                 },
324                         }, }
325                 }, }
326         },
327 };
328
329 static const struct rte_cryptodev_capabilities caps_chacha20[] = {
330         {       /* Chacha20-Poly1305 */
331                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
332                 {.sym = {
333                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
334                         {.aead = {
335                                 .algo = RTE_CRYPTO_AEAD_CHACHA20_POLY1305,
336                                 .block_size = 64,
337                                 .key_size = {
338                                         .min = 32,
339                                         .max = 32,
340                                         .increment = 0
341                                 },
342                                 .digest_size = {
343                                         .min = 16,
344                                         .max = 16,
345                                         .increment = 0
346                                 },
347                                 .aad_size = {
348                                         .min = 0,
349                                         .max = 1024,
350                                         .increment = 1
351                                 },
352                                 .iv_size = {
353                                         .min = 12,
354                                         .max = 12,
355                                         .increment = 0
356                                 },
357                         }, }
358                 }, }
359         }
360 };
361
362 static const struct rte_cryptodev_capabilities caps_zuc_snow3g[] = {
363         {       /* SNOW 3G (UEA2) */
364                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
365                 {.sym = {
366                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
367                         {.cipher = {
368                                 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
369                                 .block_size = 16,
370                                 .key_size = {
371                                         .min = 16,
372                                         .max = 16,
373                                         .increment = 0
374                                 },
375                                 .iv_size = {
376                                         .min = 16,
377                                         .max = 16,
378                                         .increment = 0
379                                 }
380                         }, }
381                 }, }
382         },
383         {       /* ZUC (EEA3) */
384                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
385                 {.sym = {
386                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
387                         {.cipher = {
388                                 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
389                                 .block_size = 16,
390                                 .key_size = {
391                                         .min = 16,
392                                         .max = 16,
393                                         .increment = 0
394                                 },
395                                 .iv_size = {
396                                         .min = 16,
397                                         .max = 16,
398                                         .increment = 0
399                                 }
400                         }, }
401                 }, }
402         },
403         {       /* SNOW 3G (UIA2) */
404                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
405                 {.sym = {
406                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
407                         {.auth = {
408                                 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
409                                 .block_size = 16,
410                                 .key_size = {
411                                         .min = 16,
412                                         .max = 16,
413                                         .increment = 0
414                                 },
415                                 .digest_size = {
416                                         .min = 4,
417                                         .max = 4,
418                                         .increment = 0
419                                 },
420                                 .iv_size = {
421                                         .min = 16,
422                                         .max = 16,
423                                         .increment = 0
424                                 }
425                         }, }
426                 }, }
427         },
428         {       /* ZUC (EIA3) */
429                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
430                 {.sym = {
431                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
432                         {.auth = {
433                                 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
434                                 .block_size = 16,
435                                 .key_size = {
436                                         .min = 16,
437                                         .max = 16,
438                                         .increment = 0
439                                 },
440                                 .digest_size = {
441                                         .min = 4,
442                                         .max = 4,
443                                         .increment = 0
444                                 },
445                                 .iv_size = {
446                                         .min = 16,
447                                         .max = 16,
448                                         .increment = 0
449                                 }
450                         }, }
451                 }, }
452         },
453 };
454
455 static const struct rte_cryptodev_capabilities caps_aes[] = {
456         {       /* AES GMAC (AUTH) */
457                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
458                 {.sym = {
459                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
460                         {.auth = {
461                                 .algo = RTE_CRYPTO_AUTH_AES_GMAC,
462                                 .block_size = 16,
463                                 .key_size = {
464                                         .min = 16,
465                                         .max = 32,
466                                         .increment = 8
467                                 },
468                                 .digest_size = {
469                                         .min = 8,
470                                         .max = 16,
471                                         .increment = 4
472                                 },
473                                 .iv_size = {
474                                         .min = 12,
475                                         .max = 12,
476                                         .increment = 0
477                                 }
478                         }, }
479                 }, }
480         },
481         {       /* AES CBC */
482                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
483                 {.sym = {
484                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
485                         {.cipher = {
486                                 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
487                                 .block_size = 16,
488                                 .key_size = {
489                                         .min = 16,
490                                         .max = 32,
491                                         .increment = 8
492                                 },
493                                 .iv_size = {
494                                         .min = 16,
495                                         .max = 16,
496                                         .increment = 0
497                                 }
498                         }, }
499                 }, }
500         },
501         {       /* AES CTR */
502                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
503                 {.sym = {
504                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
505                         {.cipher = {
506                                 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
507                                 .block_size = 16,
508                                 .key_size = {
509                                         .min = 16,
510                                         .max = 32,
511                                         .increment = 8
512                                 },
513                                 .iv_size = {
514                                         .min = 12,
515                                         .max = 16,
516                                         .increment = 4
517                                 }
518                         }, }
519                 }, }
520         },
521         {       /* AES XTS */
522                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
523                 {.sym = {
524                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
525                         {.cipher = {
526                                 .algo = RTE_CRYPTO_CIPHER_AES_XTS,
527                                 .block_size = 16,
528                                 .key_size = {
529                                         .min = 32,
530                                         .max = 64,
531                                         .increment = 32
532                                 },
533                                 .iv_size = {
534                                         .min = 16,
535                                         .max = 16,
536                                         .increment = 0
537                                 }
538                         }, }
539                 }, }
540         },
541         {       /* AES GCM */
542                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
543                 {.sym = {
544                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
545                         {.aead = {
546                                 .algo = RTE_CRYPTO_AEAD_AES_GCM,
547                                 .block_size = 16,
548                                 .key_size = {
549                                         .min = 16,
550                                         .max = 32,
551                                         .increment = 8
552                                 },
553                                 .digest_size = {
554                                         .min = 4,
555                                         .max = 16,
556                                         .increment = 1
557                                 },
558                                 .aad_size = {
559                                         .min = 0,
560                                         .max = 1024,
561                                         .increment = 1
562                                 },
563                                 .iv_size = {
564                                         .min = 12,
565                                         .max = 12,
566                                         .increment = 0
567                                 }
568                         }, }
569                 }, }
570         },
571 };
572
573 static const struct rte_cryptodev_capabilities caps_kasumi[] = {
574         {       /* KASUMI (F8) */
575                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
576                 {.sym = {
577                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
578                         {.cipher = {
579                                 .algo = RTE_CRYPTO_CIPHER_KASUMI_F8,
580                                 .block_size = 8,
581                                 .key_size = {
582                                         .min = 16,
583                                         .max = 16,
584                                         .increment = 0
585                                 },
586                                 .iv_size = {
587                                         .min = 8,
588                                         .max = 8,
589                                         .increment = 0
590                                 }
591                         }, }
592                 }, }
593         },
594         {       /* KASUMI (F9) */
595                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
596                 {.sym = {
597                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
598                         {.auth = {
599                                 .algo = RTE_CRYPTO_AUTH_KASUMI_F9,
600                                 .block_size = 8,
601                                 .key_size = {
602                                         .min = 16,
603                                         .max = 16,
604                                         .increment = 0
605                                 },
606                                 .digest_size = {
607                                         .min = 4,
608                                         .max = 4,
609                                         .increment = 0
610                                 },
611                         }, }
612                 }, }
613         },
614 };
615
616 static const struct rte_cryptodev_capabilities caps_des[] = {
617         {       /* 3DES CBC */
618                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
619                 {.sym = {
620                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
621                         {.cipher = {
622                                 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
623                                 .block_size = 8,
624                                 .key_size = {
625                                         .min = 24,
626                                         .max = 24,
627                                         .increment = 0
628                                 },
629                                 .iv_size = {
630                                         .min = 8,
631                                         .max = 16,
632                                         .increment = 8
633                                 }
634                         }, }
635                 }, }
636         },
637         {       /* 3DES ECB */
638                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
639                 {.sym = {
640                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
641                         {.cipher = {
642                                 .algo = RTE_CRYPTO_CIPHER_3DES_ECB,
643                                 .block_size = 8,
644                                 .key_size = {
645                                         .min = 24,
646                                         .max = 24,
647                                         .increment = 0
648                                 },
649                                 .iv_size = {
650                                         .min = 0,
651                                         .max = 0,
652                                         .increment = 0
653                                 }
654                         }, }
655                 }, }
656         },
657         {       /* DES CBC */
658                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
659                 {.sym = {
660                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
661                         {.cipher = {
662                                 .algo = RTE_CRYPTO_CIPHER_DES_CBC,
663                                 .block_size = 8,
664                                 .key_size = {
665                                         .min = 8,
666                                         .max = 8,
667                                         .increment = 0
668                                 },
669                                 .iv_size = {
670                                         .min = 8,
671                                         .max = 8,
672                                         .increment = 0
673                                 }
674                         }, }
675                 }, }
676         },
677 };
678
679 static const struct rte_cryptodev_capabilities caps_null[] = {
680         {       /* NULL (AUTH) */
681                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
682                 {.sym = {
683                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
684                         {.auth = {
685                                 .algo = RTE_CRYPTO_AUTH_NULL,
686                                 .block_size = 1,
687                                 .key_size = {
688                                         .min = 0,
689                                         .max = 0,
690                                         .increment = 0
691                                 },
692                                 .digest_size = {
693                                         .min = 0,
694                                         .max = 0,
695                                         .increment = 0
696                                 },
697                         }, },
698                 }, },
699         },
700         {       /* NULL (CIPHER) */
701                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
702                 {.sym = {
703                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
704                         {.cipher = {
705                                 .algo = RTE_CRYPTO_CIPHER_NULL,
706                                 .block_size = 1,
707                                 .key_size = {
708                                         .min = 0,
709                                         .max = 0,
710                                         .increment = 0
711                                 },
712                                 .iv_size = {
713                                         .min = 0,
714                                         .max = 0,
715                                         .increment = 0
716                                 }
717                         }, },
718                 }, }
719         },
720 };
721
722 static const struct rte_cryptodev_capabilities caps_end[] = {
723         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
724 };
725
726 static const struct rte_cryptodev_capabilities sec_caps_aes[] = {
727         {       /* AES GCM */
728                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
729                 {.sym = {
730                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
731                         {.aead = {
732                                 .algo = RTE_CRYPTO_AEAD_AES_GCM,
733                                 .block_size = 16,
734                                 .key_size = {
735                                         .min = 16,
736                                         .max = 32,
737                                         .increment = 8
738                                 },
739                                 .digest_size = {
740                                         .min = 16,
741                                         .max = 16,
742                                         .increment = 0
743                                 },
744                                 .aad_size = {
745                                         .min = 8,
746                                         .max = 12,
747                                         .increment = 4
748                                 },
749                                 .iv_size = {
750                                         .min = 12,
751                                         .max = 12,
752                                         .increment = 0
753                                 }
754                         }, }
755                 }, }
756         },
757         {       /* AES CTR */
758                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
759                 {.sym = {
760                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
761                         {.cipher = {
762                                 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
763                                 .block_size = 16,
764                                 .key_size = {
765                                         .min = 16,
766                                         .max = 32,
767                                         .increment = 8
768                                 },
769                                 .iv_size = {
770                                         .min = 12,
771                                         .max = 16,
772                                         .increment = 4
773                                 }
774                         }, }
775                 }, }
776         },
777         {       /* AES CBC */
778                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
779                 {.sym = {
780                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
781                         {.cipher = {
782                                 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
783                                 .block_size = 16,
784                                 .key_size = {
785                                         .min = 16,
786                                         .max = 32,
787                                         .increment = 8
788                                 },
789                                 .iv_size = {
790                                         .min = 16,
791                                         .max = 16,
792                                         .increment = 0
793                                 }
794                         }, }
795                 }, }
796         },
797         {       /* AES-XCBC */
798                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
799                 { .sym = {
800                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
801                         {.auth = {
802                                 .algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC,
803                                 .block_size = 16,
804                                 .key_size = {
805                                         .min = 16,
806                                         .max = 16,
807                                         .increment = 0
808                                 },
809                                 .digest_size = {
810                                         .min = 12,
811                                         .max = 12,
812                                         .increment = 0,
813                                 },
814                         }, }
815                 }, }
816         },
817 };
818
819 static const struct rte_cryptodev_capabilities sec_caps_sha1_sha2[] = {
820         {       /* SHA1 HMAC */
821                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
822                 {.sym = {
823                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
824                         {.auth = {
825                                 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
826                                 .block_size = 64,
827                                 .key_size = {
828                                         .min = 20,
829                                         .max = 64,
830                                         .increment = 1
831                                 },
832                                 .digest_size = {
833                                         .min = 12,
834                                         .max = 12,
835                                         .increment = 0
836                                 },
837                         }, }
838                 }, }
839         },
840         {       /* SHA256 HMAC */
841                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
842                 {.sym = {
843                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
844                         {.auth = {
845                                 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
846                                 .block_size = 64,
847                                 .key_size = {
848                                         .min = 1,
849                                         .max = 1024,
850                                         .increment = 1
851                                 },
852                                 .digest_size = {
853                                         .min = 16,
854                                         .max = 16,
855                                         .increment = 0
856                                 },
857                         }, }
858                 }, }
859         },
860         {       /* SHA384 HMAC */
861                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
862                 {.sym = {
863                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
864                         {.auth = {
865                                 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
866                                 .block_size = 64,
867                                 .key_size = {
868                                         .min = 48,
869                                         .max = 48,
870                                         .increment = 0
871                                 },
872                                 .digest_size = {
873                                         .min = 24,
874                                         .max = 24,
875                                         .increment = 0
876                                         },
877                         }, }
878                 }, }
879         },
880         {       /* SHA512 HMAC */
881                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
882                 {.sym = {
883                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
884                         {.auth = {
885                                 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
886                                 .block_size = 128,
887                                 .key_size = {
888                                         .min = 64,
889                                         .max = 64,
890                                         .increment = 0
891                                 },
892                                 .digest_size = {
893                                         .min = 32,
894                                         .max = 32,
895                                         .increment = 0
896                                 },
897                         }, }
898                 }, }
899         },
900 };
901
902 static const struct rte_cryptodev_capabilities sec_caps_null[] = {
903         {       /* NULL (CIPHER) */
904                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
905                 {.sym = {
906                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
907                         {.cipher = {
908                                 .algo = RTE_CRYPTO_CIPHER_NULL,
909                                 .block_size = 1,
910                                 .key_size = {
911                                         .min = 0,
912                                         .max = 0,
913                                         .increment = 0
914                                 },
915                                 .iv_size = {
916                                         .min = 0,
917                                         .max = 0,
918                                         .increment = 0
919                                 }
920                         }, },
921                 }, }
922         },
923 };
924
925 static const struct rte_security_capability sec_caps_templ[] = {
926         {       /* IPsec Lookaside Protocol ESP Tunnel Ingress */
927                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
928                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
929                 .ipsec = {
930                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
931                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
932                         .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
933                         .options = { 0 },
934                 },
935                 .crypto_capabilities = NULL,
936         },
937         {       /* IPsec Lookaside Protocol ESP Tunnel Egress */
938                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
939                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
940                 .ipsec = {
941                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
942                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
943                         .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
944                         .options = { 0 },
945                 },
946                 .crypto_capabilities = NULL,
947         },
948         {       /* IPsec Lookaside Protocol ESP Transport Ingress */
949                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
950                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
951                 .ipsec = {
952                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
953                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
954                         .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
955                         .options = { 0 },
956                 },
957                 .crypto_capabilities = NULL,
958         },
959         {       /* IPsec Lookaside Protocol ESP Transport Egress */
960                 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
961                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
962                 .ipsec = {
963                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
964                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
965                         .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
966                         .options = { 0 },
967                 },
968                 .crypto_capabilities = NULL,
969         },
970         {
971                 .action = RTE_SECURITY_ACTION_TYPE_NONE
972         }
973 };
974
975 static void
976 cpt_caps_add(struct rte_cryptodev_capabilities cnxk_caps[], int *cur_pos,
977              const struct rte_cryptodev_capabilities *caps, int nb_caps)
978 {
979         if (*cur_pos + nb_caps > CNXK_CPT_MAX_CAPS)
980                 return;
981
982         memcpy(&cnxk_caps[*cur_pos], caps, nb_caps * sizeof(caps[0]));
983         *cur_pos += nb_caps;
984 }
985
986 static void
987 cn10k_crypto_caps_update(struct rte_cryptodev_capabilities cnxk_caps[])
988 {
989
990         struct rte_cryptodev_capabilities *caps;
991         int i = 0;
992
993         while ((caps = &cnxk_caps[i++])->op != RTE_CRYPTO_OP_TYPE_UNDEFINED) {
994                 if ((caps->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC) &&
995                     (caps->sym.xform_type == RTE_CRYPTO_SYM_XFORM_CIPHER) &&
996                     (caps->sym.cipher.algo == RTE_CRYPTO_CIPHER_ZUC_EEA3)) {
997
998                         caps->sym.cipher.key_size.max = 32;
999                         caps->sym.cipher.key_size.increment = 16;
1000                         caps->sym.cipher.iv_size.max = 25;
1001                         caps->sym.cipher.iv_size.increment = 1;
1002                 }
1003
1004                 if ((caps->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC) &&
1005                     (caps->sym.xform_type == RTE_CRYPTO_SYM_XFORM_AUTH) &&
1006                     (caps->sym.auth.algo == RTE_CRYPTO_AUTH_ZUC_EIA3)) {
1007
1008                         caps->sym.auth.key_size.max = 32;
1009                         caps->sym.auth.key_size.increment = 16;
1010                         caps->sym.auth.digest_size.max = 16;
1011                         caps->sym.auth.digest_size.increment = 4;
1012                         caps->sym.auth.iv_size.max = 25;
1013                         caps->sym.auth.iv_size.increment = 1;
1014                 }
1015         }
1016 }
1017
1018 static void
1019 crypto_caps_populate(struct rte_cryptodev_capabilities cnxk_caps[],
1020                      union cpt_eng_caps *hw_caps)
1021 {
1022         int cur_pos = 0;
1023
1024         CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, mul);
1025         CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, sha1_sha2);
1026         CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, chacha20);
1027         CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, zuc_snow3g);
1028         CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, aes);
1029         CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, kasumi);
1030         CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, des);
1031
1032         cpt_caps_add(cnxk_caps, &cur_pos, caps_null, RTE_DIM(caps_null));
1033         cpt_caps_add(cnxk_caps, &cur_pos, caps_end, RTE_DIM(caps_end));
1034
1035         if (roc_model_is_cn10k())
1036                 cn10k_crypto_caps_update(cnxk_caps);
1037 }
1038
1039 const struct rte_cryptodev_capabilities *
1040 cnxk_crypto_capabilities_get(struct cnxk_cpt_vf *vf)
1041 {
1042         return vf->crypto_caps;
1043 }
1044
1045 static void
1046 sec_caps_add(struct rte_cryptodev_capabilities cnxk_caps[], int *cur_pos,
1047              const struct rte_cryptodev_capabilities *caps, int nb_caps)
1048 {
1049         if (*cur_pos + nb_caps > CNXK_SEC_CRYPTO_MAX_CAPS) {
1050                 rte_panic("Could not add sec crypto caps");
1051                 return;
1052         }
1053
1054         memcpy(&cnxk_caps[*cur_pos], caps, nb_caps * sizeof(caps[0]));
1055         *cur_pos += nb_caps;
1056 }
1057
1058 static void
1059 cn10k_sec_crypto_caps_update(struct rte_cryptodev_capabilities cnxk_caps[],
1060                              int *cur_pos)
1061 {
1062         const struct rte_cryptodev_capabilities *cap;
1063         unsigned int i;
1064
1065         if ((CNXK_SEC_CRYPTO_MAX_CAPS - *cur_pos) < 1) {
1066                 rte_panic("Could not add sec crypto caps");
1067                 return;
1068         }
1069
1070         /* NULL auth */
1071         for (i = 0; i < RTE_DIM(caps_null); i++) {
1072                 cap = &caps_null[i];
1073                 if (cap->sym.xform_type == RTE_CRYPTO_SYM_XFORM_AUTH &&
1074                     cap->sym.auth.algo == RTE_CRYPTO_AUTH_NULL) {
1075                         cnxk_caps[*cur_pos] = caps_null[i];
1076                         *cur_pos += 1;
1077                 }
1078         }
1079 }
1080
1081 static void
1082 cn9k_sec_crypto_caps_update(struct rte_cryptodev_capabilities cnxk_caps[])
1083 {
1084
1085         struct rte_cryptodev_capabilities *caps;
1086         int i = 0;
1087
1088         while ((caps = &cnxk_caps[i++])->op != RTE_CRYPTO_OP_TYPE_UNDEFINED) {
1089                 if ((caps->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC) &&
1090                     (caps->sym.xform_type == RTE_CRYPTO_SYM_XFORM_AUTH) &&
1091                     (caps->sym.auth.algo == RTE_CRYPTO_AUTH_SHA256_HMAC)) {
1092                         caps->sym.auth.key_size.min = 32;
1093                         caps->sym.auth.key_size.max = 64;
1094                         caps->sym.auth.key_size.increment = 1;
1095
1096                         break;
1097                 }
1098         }
1099 }
1100
1101 static void
1102 sec_crypto_caps_populate(struct rte_cryptodev_capabilities cnxk_caps[],
1103                          union cpt_eng_caps *hw_caps)
1104 {
1105         int cur_pos = 0;
1106
1107         SEC_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, aes);
1108         SEC_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, sha1_sha2);
1109
1110         if (roc_model_is_cn10k())
1111                 cn10k_sec_crypto_caps_update(cnxk_caps, &cur_pos);
1112         else
1113                 cn9k_sec_crypto_caps_update(cnxk_caps);
1114
1115         sec_caps_add(cnxk_caps, &cur_pos, sec_caps_null,
1116                      RTE_DIM(sec_caps_null));
1117         sec_caps_add(cnxk_caps, &cur_pos, caps_end, RTE_DIM(caps_end));
1118 }
1119
1120 static void
1121 cnxk_sec_caps_update(struct rte_security_capability *sec_cap)
1122 {
1123         sec_cap->ipsec.options.udp_encap = 1;
1124         sec_cap->ipsec.options.copy_df = 1;
1125 }
1126
1127 static void
1128 cn10k_sec_caps_update(struct rte_security_capability *sec_cap)
1129 {
1130         if (sec_cap->ipsec.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
1131 #ifdef LA_IPSEC_DEBUG
1132                 sec_cap->ipsec.options.iv_gen_disable = 1;
1133 #endif
1134         } else {
1135                 sec_cap->ipsec.options.udp_ports_verify = 1;
1136                 if (sec_cap->ipsec.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL)
1137                         sec_cap->ipsec.options.tunnel_hdr_verify =
1138                                 RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
1139         }
1140         sec_cap->ipsec.options.ip_csum_enable = 1;
1141         sec_cap->ipsec.options.l4_csum_enable = 1;
1142         sec_cap->ipsec.options.stats = 1;
1143 }
1144
1145 static void
1146 cn9k_sec_caps_update(struct rte_security_capability *sec_cap)
1147 {
1148         if (sec_cap->ipsec.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
1149                 sec_cap->ipsec.options.iv_gen_disable = 1;
1150         }
1151 }
1152
1153 void
1154 cnxk_cpt_caps_populate(struct cnxk_cpt_vf *vf)
1155 {
1156         unsigned long i;
1157
1158         crypto_caps_populate(vf->crypto_caps, vf->cpt.hw_caps);
1159         sec_crypto_caps_populate(vf->sec_crypto_caps, vf->cpt.hw_caps);
1160
1161         PLT_STATIC_ASSERT(RTE_DIM(sec_caps_templ) <= RTE_DIM(vf->sec_caps));
1162         memcpy(vf->sec_caps, sec_caps_templ, sizeof(sec_caps_templ));
1163
1164         for (i = 0; i < RTE_DIM(sec_caps_templ) - 1; i++) {
1165                 vf->sec_caps[i].crypto_capabilities = vf->sec_crypto_caps;
1166
1167                 cnxk_sec_caps_update(&vf->sec_caps[i]);
1168
1169                 if (roc_model_is_cn10k())
1170                         cn10k_sec_caps_update(&vf->sec_caps[i]);
1171
1172                 if (roc_model_is_cn9k())
1173                         cn9k_sec_caps_update(&vf->sec_caps[i]);
1174
1175         }
1176 }
1177
1178 const struct rte_security_capability *
1179 cnxk_crypto_sec_capabilities_get(void *device)
1180 {
1181         struct rte_cryptodev *dev = device;
1182         struct cnxk_cpt_vf *vf;
1183
1184         vf = dev->data->dev_private;
1185         return vf->sec_caps;
1186 }