1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
5 #include <cryptodev_pmd.h>
6 #include <rte_security.h>
10 #include "cnxk_cryptodev.h"
11 #include "cnxk_cryptodev_capabilities.h"
13 #define CPT_CAPS_ADD(cnxk_caps, cur_pos, hw_caps, name) \
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)); \
22 #define SEC_CAPS_ADD(cnxk_caps, cur_pos, hw_caps, name) \
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)); \
31 static const struct rte_cryptodev_capabilities caps_mul[] = {
33 .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
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)),
50 .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
53 .xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX,
64 .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
67 .xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA,
68 .op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) |
69 (1 << RTE_CRYPTO_ASYM_OP_VERIFY)),
75 .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
78 .xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM,
86 static const struct rte_cryptodev_capabilities caps_sha1_sha2[] = {
88 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
90 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
92 .algo = RTE_CRYPTO_AUTH_SHA1,
108 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
110 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
112 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
128 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
130 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
132 .algo = RTE_CRYPTO_AUTH_SHA224,
148 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
150 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
152 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
168 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
170 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
172 .algo = RTE_CRYPTO_AUTH_SHA256,
188 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
190 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
192 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
208 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
210 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
212 .algo = RTE_CRYPTO_AUTH_SHA384,
228 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
230 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
232 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
248 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
250 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
252 .algo = RTE_CRYPTO_AUTH_SHA512,
268 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
270 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
272 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
288 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
290 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
292 .algo = RTE_CRYPTO_AUTH_MD5,
308 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
310 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
312 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
329 static const struct rte_cryptodev_capabilities caps_chacha20[] = {
330 { /* Chacha20-Poly1305 */
331 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
333 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
335 .algo = RTE_CRYPTO_AEAD_CHACHA20_POLY1305,
362 static const struct rte_cryptodev_capabilities caps_zuc_snow3g[] = {
363 { /* SNOW 3G (UEA2) */
364 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
366 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
368 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
384 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
386 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
388 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
403 { /* SNOW 3G (UIA2) */
404 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
406 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
408 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
429 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
431 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
433 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
455 static const struct rte_cryptodev_capabilities caps_aes[] = {
456 { /* AES GMAC (AUTH) */
457 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
459 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
461 .algo = RTE_CRYPTO_AUTH_AES_GMAC,
482 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
484 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
486 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
502 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
504 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
506 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
522 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
524 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
526 .algo = RTE_CRYPTO_CIPHER_AES_XTS,
542 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
544 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
546 .algo = RTE_CRYPTO_AEAD_AES_GCM,
573 static const struct rte_cryptodev_capabilities caps_kasumi[] = {
575 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
577 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
579 .algo = RTE_CRYPTO_CIPHER_KASUMI_F8,
595 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
597 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
599 .algo = RTE_CRYPTO_AUTH_KASUMI_F9,
616 static const struct rte_cryptodev_capabilities caps_des[] = {
618 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
620 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
622 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
638 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
640 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
642 .algo = RTE_CRYPTO_CIPHER_3DES_ECB,
658 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
660 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
662 .algo = RTE_CRYPTO_CIPHER_DES_CBC,
679 static const struct rte_cryptodev_capabilities caps_null[] = {
681 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
683 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
685 .algo = RTE_CRYPTO_AUTH_NULL,
700 { /* NULL (CIPHER) */
701 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
703 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
705 .algo = RTE_CRYPTO_CIPHER_NULL,
722 static const struct rte_cryptodev_capabilities caps_end[] = {
723 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
726 static const struct rte_cryptodev_capabilities sec_caps_aes[] = {
728 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
730 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
732 .algo = RTE_CRYPTO_AEAD_AES_GCM,
758 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
760 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
762 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
779 static const struct rte_cryptodev_capabilities sec_caps_sha1_sha2[] = {
781 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
783 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
785 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
801 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
803 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
805 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
822 static const struct rte_security_capability sec_caps_templ[] = {
823 { /* IPsec Lookaside Protocol ESP Tunnel Ingress */
824 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
825 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
827 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
828 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
829 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
832 .crypto_capabilities = NULL,
834 { /* IPsec Lookaside Protocol ESP Tunnel Egress */
835 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
836 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
838 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
839 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
840 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
843 .crypto_capabilities = NULL,
845 { /* IPsec Lookaside Protocol ESP Transport Ingress */
846 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
847 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
849 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
850 .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
851 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
854 .crypto_capabilities = NULL,
856 { /* IPsec Lookaside Protocol ESP Transport Egress */
857 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
858 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
860 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
861 .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
862 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
865 .crypto_capabilities = NULL,
868 .action = RTE_SECURITY_ACTION_TYPE_NONE
873 cpt_caps_add(struct rte_cryptodev_capabilities cnxk_caps[], int *cur_pos,
874 const struct rte_cryptodev_capabilities *caps, int nb_caps)
876 if (*cur_pos + nb_caps > CNXK_CPT_MAX_CAPS)
879 memcpy(&cnxk_caps[*cur_pos], caps, nb_caps * sizeof(caps[0]));
884 cn10k_crypto_caps_update(struct rte_cryptodev_capabilities cnxk_caps[])
887 struct rte_cryptodev_capabilities *caps;
890 while ((caps = &cnxk_caps[i++])->op != RTE_CRYPTO_OP_TYPE_UNDEFINED) {
891 if ((caps->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC) &&
892 (caps->sym.xform_type == RTE_CRYPTO_SYM_XFORM_CIPHER) &&
893 (caps->sym.cipher.algo == RTE_CRYPTO_CIPHER_ZUC_EEA3)) {
895 caps->sym.cipher.key_size.max = 32;
896 caps->sym.cipher.key_size.increment = 16;
897 caps->sym.cipher.iv_size.max = 25;
898 caps->sym.cipher.iv_size.increment = 1;
901 if ((caps->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC) &&
902 (caps->sym.xform_type == RTE_CRYPTO_SYM_XFORM_AUTH) &&
903 (caps->sym.auth.algo == RTE_CRYPTO_AUTH_ZUC_EIA3)) {
905 caps->sym.auth.key_size.max = 32;
906 caps->sym.auth.key_size.increment = 16;
907 caps->sym.auth.digest_size.max = 16;
908 caps->sym.auth.digest_size.increment = 4;
909 caps->sym.auth.iv_size.max = 25;
910 caps->sym.auth.iv_size.increment = 1;
916 crypto_caps_populate(struct rte_cryptodev_capabilities cnxk_caps[],
917 union cpt_eng_caps *hw_caps)
921 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, mul);
922 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, sha1_sha2);
923 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, chacha20);
924 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, zuc_snow3g);
925 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, aes);
926 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, kasumi);
927 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, des);
929 cpt_caps_add(cnxk_caps, &cur_pos, caps_null, RTE_DIM(caps_null));
930 cpt_caps_add(cnxk_caps, &cur_pos, caps_end, RTE_DIM(caps_end));
932 if (roc_model_is_cn10k())
933 cn10k_crypto_caps_update(cnxk_caps);
936 const struct rte_cryptodev_capabilities *
937 cnxk_crypto_capabilities_get(struct cnxk_cpt_vf *vf)
939 return vf->crypto_caps;
943 sec_caps_add(struct rte_cryptodev_capabilities cnxk_caps[], int *cur_pos,
944 const struct rte_cryptodev_capabilities *caps, int nb_caps)
946 if (*cur_pos + nb_caps > CNXK_SEC_CRYPTO_MAX_CAPS) {
947 rte_panic("Could not add sec crypto caps");
951 memcpy(&cnxk_caps[*cur_pos], caps, nb_caps * sizeof(caps[0]));
956 cn10k_sec_crypto_caps_update(struct rte_cryptodev_capabilities cnxk_caps[],
959 const struct rte_cryptodev_capabilities *cap;
962 if ((CNXK_SEC_CRYPTO_MAX_CAPS - *cur_pos) < 1) {
963 rte_panic("Could not add sec crypto caps");
968 for (i = 0; i < RTE_DIM(caps_null); i++) {
970 if (cap->sym.xform_type == RTE_CRYPTO_SYM_XFORM_AUTH &&
971 cap->sym.auth.algo == RTE_CRYPTO_AUTH_NULL) {
972 cnxk_caps[*cur_pos] = caps_null[i];
979 cn9k_sec_crypto_caps_update(struct rte_cryptodev_capabilities cnxk_caps[])
982 struct rte_cryptodev_capabilities *caps;
985 while ((caps = &cnxk_caps[i++])->op != RTE_CRYPTO_OP_TYPE_UNDEFINED) {
986 if ((caps->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC) &&
987 (caps->sym.xform_type == RTE_CRYPTO_SYM_XFORM_AUTH) &&
988 (caps->sym.auth.algo == RTE_CRYPTO_AUTH_SHA256_HMAC)) {
989 caps->sym.auth.key_size.min = 32;
990 caps->sym.auth.key_size.max = 64;
991 caps->sym.auth.key_size.increment = 1;
999 sec_crypto_caps_populate(struct rte_cryptodev_capabilities cnxk_caps[],
1000 union cpt_eng_caps *hw_caps)
1004 SEC_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, aes);
1005 SEC_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, sha1_sha2);
1007 if (roc_model_is_cn10k())
1008 cn10k_sec_crypto_caps_update(cnxk_caps, &cur_pos);
1010 cn9k_sec_crypto_caps_update(cnxk_caps);
1012 sec_caps_add(cnxk_caps, &cur_pos, caps_end, RTE_DIM(caps_end));
1016 cnxk_sec_caps_update(struct rte_security_capability *sec_cap)
1018 sec_cap->ipsec.options.udp_encap = 1;
1022 cn10k_sec_caps_update(struct rte_security_capability *sec_cap)
1024 if (sec_cap->ipsec.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
1025 #ifdef LA_IPSEC_DEBUG
1026 sec_cap->ipsec.options.iv_gen_disable = 1;
1029 sec_cap->ipsec.options.udp_ports_verify = 1;
1030 if (sec_cap->ipsec.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL)
1031 sec_cap->ipsec.options.tunnel_hdr_verify =
1032 RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
1034 sec_cap->ipsec.options.ip_csum_enable = 1;
1035 sec_cap->ipsec.options.l4_csum_enable = 1;
1039 cn9k_sec_caps_update(struct rte_security_capability *sec_cap)
1041 if (sec_cap->ipsec.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
1042 sec_cap->ipsec.options.iv_gen_disable = 1;
1047 cnxk_cpt_caps_populate(struct cnxk_cpt_vf *vf)
1051 crypto_caps_populate(vf->crypto_caps, vf->cpt.hw_caps);
1052 sec_crypto_caps_populate(vf->sec_crypto_caps, vf->cpt.hw_caps);
1054 PLT_STATIC_ASSERT(RTE_DIM(sec_caps_templ) <= RTE_DIM(vf->sec_caps));
1055 memcpy(vf->sec_caps, sec_caps_templ, sizeof(sec_caps_templ));
1057 for (i = 0; i < RTE_DIM(sec_caps_templ) - 1; i++) {
1058 vf->sec_caps[i].crypto_capabilities = vf->sec_crypto_caps;
1060 cnxk_sec_caps_update(&vf->sec_caps[i]);
1062 if (roc_model_is_cn10k())
1063 cn10k_sec_caps_update(&vf->sec_caps[i]);
1065 if (roc_model_is_cn9k())
1066 cn9k_sec_caps_update(&vf->sec_caps[i]);
1071 const struct rte_security_capability *
1072 cnxk_crypto_sec_capabilities_get(void *device)
1074 struct rte_cryptodev *dev = device;
1075 struct cnxk_cpt_vf *vf;
1077 vf = dev->data->dev_private;
1078 return vf->sec_caps;