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"
12 #include "cnxk_security_ar.h"
14 #define CPT_CAPS_ADD(cnxk_caps, cur_pos, hw_caps, name) \
16 if ((hw_caps[CPT_ENG_TYPE_SE].name) || \
17 (hw_caps[CPT_ENG_TYPE_IE].name) || \
18 (hw_caps[CPT_ENG_TYPE_AE].name)) \
19 cpt_caps_add(cnxk_caps, cur_pos, caps_##name, \
20 RTE_DIM(caps_##name)); \
23 #define SEC_CAPS_ADD(cnxk_caps, cur_pos, hw_caps, name) \
25 if ((hw_caps[CPT_ENG_TYPE_SE].name) || \
26 (hw_caps[CPT_ENG_TYPE_IE].name) || \
27 (hw_caps[CPT_ENG_TYPE_AE].name)) \
28 sec_caps_add(cnxk_caps, cur_pos, sec_caps_##name, \
29 RTE_DIM(sec_caps_##name)); \
32 static const struct rte_cryptodev_capabilities caps_mul[] = {
34 .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
37 .xform_type = RTE_CRYPTO_ASYM_XFORM_RSA,
38 .op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) |
39 (1 << RTE_CRYPTO_ASYM_OP_VERIFY) |
40 (1 << RTE_CRYPTO_ASYM_OP_ENCRYPT) |
41 (1 << RTE_CRYPTO_ASYM_OP_DECRYPT)),
51 .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
54 .xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX,
65 .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
68 .xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA,
69 .op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) |
70 (1 << RTE_CRYPTO_ASYM_OP_VERIFY)),
76 .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
79 .xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM,
87 static const struct rte_cryptodev_capabilities caps_sha1_sha2[] = {
89 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
91 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
93 .algo = RTE_CRYPTO_AUTH_SHA1,
109 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
111 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
113 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
129 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
131 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
133 .algo = RTE_CRYPTO_AUTH_SHA224,
149 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
151 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
153 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
169 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
171 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
173 .algo = RTE_CRYPTO_AUTH_SHA256,
189 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
191 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
193 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
209 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
211 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
213 .algo = RTE_CRYPTO_AUTH_SHA384,
229 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
231 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
233 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
249 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
251 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
253 .algo = RTE_CRYPTO_AUTH_SHA512,
269 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
271 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
273 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
289 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
291 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
293 .algo = RTE_CRYPTO_AUTH_MD5,
309 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
311 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
313 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
330 static const struct rte_cryptodev_capabilities caps_chacha20[] = {
331 { /* Chacha20-Poly1305 */
332 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
334 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
336 .algo = RTE_CRYPTO_AEAD_CHACHA20_POLY1305,
363 static const struct rte_cryptodev_capabilities caps_zuc_snow3g[] = {
364 { /* SNOW 3G (UEA2) */
365 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
367 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
369 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
385 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
387 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
389 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
404 { /* SNOW 3G (UIA2) */
405 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
407 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
409 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
430 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
432 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
434 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
456 static const struct rte_cryptodev_capabilities caps_aes[] = {
457 { /* AES GMAC (AUTH) */
458 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
460 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
462 .algo = RTE_CRYPTO_AUTH_AES_GMAC,
483 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
485 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
487 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
503 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
505 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
507 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
523 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
525 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
527 .algo = RTE_CRYPTO_CIPHER_AES_XTS,
543 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
545 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
547 .algo = RTE_CRYPTO_AEAD_AES_GCM,
573 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
575 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
577 .algo = RTE_CRYPTO_AUTH_AES_CMAC,
594 static const struct rte_cryptodev_capabilities caps_kasumi[] = {
596 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
598 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
600 .algo = RTE_CRYPTO_CIPHER_KASUMI_F8,
616 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
618 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
620 .algo = RTE_CRYPTO_AUTH_KASUMI_F9,
637 static const struct rte_cryptodev_capabilities caps_des[] = {
639 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
641 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
643 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
659 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
661 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
663 .algo = RTE_CRYPTO_CIPHER_3DES_ECB,
679 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
681 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
683 .algo = RTE_CRYPTO_CIPHER_DES_CBC,
700 static const struct rte_cryptodev_capabilities caps_null[] = {
702 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
704 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
706 .algo = RTE_CRYPTO_AUTH_NULL,
721 { /* NULL (CIPHER) */
722 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
724 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
726 .algo = RTE_CRYPTO_CIPHER_NULL,
743 static const struct rte_cryptodev_capabilities caps_end[] = {
744 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
747 static const struct rte_cryptodev_capabilities sec_caps_aes[] = {
749 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
751 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
753 .algo = RTE_CRYPTO_AEAD_AES_GCM,
779 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
781 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
783 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
799 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
801 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
803 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
819 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
821 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
823 .algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC,
840 static const struct rte_cryptodev_capabilities sec_caps_sha1_sha2[] = {
842 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
844 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
846 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
862 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
864 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
866 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
882 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
884 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
886 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
902 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
904 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
906 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
923 static const struct rte_cryptodev_capabilities sec_caps_null[] = {
924 { /* NULL (CIPHER) */
925 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
927 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
929 .algo = RTE_CRYPTO_CIPHER_NULL,
946 static const struct rte_security_capability sec_caps_templ[] = {
947 { /* IPsec Lookaside Protocol ESP Tunnel Ingress */
948 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
949 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
951 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
952 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
953 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
956 .crypto_capabilities = NULL,
958 { /* IPsec Lookaside Protocol ESP Tunnel Egress */
959 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
960 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
962 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
963 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
964 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
967 .crypto_capabilities = NULL,
969 { /* IPsec Lookaside Protocol ESP Transport Ingress */
970 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
971 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
973 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
974 .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
975 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
978 .crypto_capabilities = NULL,
980 { /* IPsec Lookaside Protocol ESP Transport Egress */
981 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
982 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
984 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
985 .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
986 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
989 .crypto_capabilities = NULL,
992 .action = RTE_SECURITY_ACTION_TYPE_NONE
997 cpt_caps_add(struct rte_cryptodev_capabilities cnxk_caps[], int *cur_pos,
998 const struct rte_cryptodev_capabilities *caps, int nb_caps)
1000 if (*cur_pos + nb_caps > CNXK_CPT_MAX_CAPS)
1003 memcpy(&cnxk_caps[*cur_pos], caps, nb_caps * sizeof(caps[0]));
1004 *cur_pos += nb_caps;
1008 cn10k_crypto_caps_update(struct rte_cryptodev_capabilities cnxk_caps[])
1011 struct rte_cryptodev_capabilities *caps;
1014 while ((caps = &cnxk_caps[i++])->op != RTE_CRYPTO_OP_TYPE_UNDEFINED) {
1015 if ((caps->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC) &&
1016 (caps->sym.xform_type == RTE_CRYPTO_SYM_XFORM_CIPHER) &&
1017 (caps->sym.cipher.algo == RTE_CRYPTO_CIPHER_ZUC_EEA3)) {
1019 caps->sym.cipher.key_size.max = 32;
1020 caps->sym.cipher.key_size.increment = 16;
1021 caps->sym.cipher.iv_size.max = 25;
1022 caps->sym.cipher.iv_size.increment = 1;
1025 if ((caps->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC) &&
1026 (caps->sym.xform_type == RTE_CRYPTO_SYM_XFORM_AUTH) &&
1027 (caps->sym.auth.algo == RTE_CRYPTO_AUTH_ZUC_EIA3)) {
1029 caps->sym.auth.key_size.max = 32;
1030 caps->sym.auth.key_size.increment = 16;
1031 caps->sym.auth.digest_size.max = 16;
1032 caps->sym.auth.digest_size.increment = 4;
1033 caps->sym.auth.iv_size.max = 25;
1034 caps->sym.auth.iv_size.increment = 1;
1040 crypto_caps_populate(struct rte_cryptodev_capabilities cnxk_caps[],
1041 union cpt_eng_caps *hw_caps)
1045 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, mul);
1046 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, sha1_sha2);
1047 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, chacha20);
1048 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, zuc_snow3g);
1049 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, aes);
1050 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, kasumi);
1051 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, des);
1053 cpt_caps_add(cnxk_caps, &cur_pos, caps_null, RTE_DIM(caps_null));
1054 cpt_caps_add(cnxk_caps, &cur_pos, caps_end, RTE_DIM(caps_end));
1056 if (roc_model_is_cn10k())
1057 cn10k_crypto_caps_update(cnxk_caps);
1060 const struct rte_cryptodev_capabilities *
1061 cnxk_crypto_capabilities_get(struct cnxk_cpt_vf *vf)
1063 return vf->crypto_caps;
1067 sec_caps_add(struct rte_cryptodev_capabilities cnxk_caps[], int *cur_pos,
1068 const struct rte_cryptodev_capabilities *caps, int nb_caps)
1070 if (*cur_pos + nb_caps > CNXK_SEC_CRYPTO_MAX_CAPS) {
1071 rte_panic("Could not add sec crypto caps");
1075 memcpy(&cnxk_caps[*cur_pos], caps, nb_caps * sizeof(caps[0]));
1076 *cur_pos += nb_caps;
1080 cn10k_sec_crypto_caps_update(struct rte_cryptodev_capabilities cnxk_caps[],
1083 const struct rte_cryptodev_capabilities *cap;
1086 if ((CNXK_SEC_CRYPTO_MAX_CAPS - *cur_pos) < 1) {
1087 rte_panic("Could not add sec crypto caps");
1092 for (i = 0; i < RTE_DIM(caps_null); i++) {
1093 cap = &caps_null[i];
1094 if (cap->sym.xform_type == RTE_CRYPTO_SYM_XFORM_AUTH &&
1095 cap->sym.auth.algo == RTE_CRYPTO_AUTH_NULL) {
1096 cnxk_caps[*cur_pos] = caps_null[i];
1103 cn9k_sec_crypto_caps_update(struct rte_cryptodev_capabilities cnxk_caps[])
1106 struct rte_cryptodev_capabilities *caps;
1109 while ((caps = &cnxk_caps[i++])->op != RTE_CRYPTO_OP_TYPE_UNDEFINED) {
1110 if ((caps->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC) &&
1111 (caps->sym.xform_type == RTE_CRYPTO_SYM_XFORM_AUTH) &&
1112 (caps->sym.auth.algo == RTE_CRYPTO_AUTH_SHA256_HMAC)) {
1113 caps->sym.auth.key_size.min = 32;
1114 caps->sym.auth.key_size.max = 64;
1115 caps->sym.auth.key_size.increment = 1;
1123 sec_crypto_caps_populate(struct rte_cryptodev_capabilities cnxk_caps[],
1124 union cpt_eng_caps *hw_caps)
1128 SEC_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, aes);
1129 SEC_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, sha1_sha2);
1131 if (roc_model_is_cn10k())
1132 cn10k_sec_crypto_caps_update(cnxk_caps, &cur_pos);
1134 cn9k_sec_crypto_caps_update(cnxk_caps);
1136 sec_caps_add(cnxk_caps, &cur_pos, sec_caps_null,
1137 RTE_DIM(sec_caps_null));
1138 sec_caps_add(cnxk_caps, &cur_pos, caps_end, RTE_DIM(caps_end));
1142 cnxk_sec_caps_update(struct rte_security_capability *sec_cap)
1144 sec_cap->ipsec.options.udp_encap = 1;
1145 sec_cap->ipsec.options.copy_df = 1;
1146 sec_cap->ipsec.options.copy_dscp = 1;
1150 cn10k_sec_caps_update(struct rte_security_capability *sec_cap)
1152 if (sec_cap->ipsec.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
1153 #ifdef LA_IPSEC_DEBUG
1154 sec_cap->ipsec.options.iv_gen_disable = 1;
1157 sec_cap->ipsec.options.udp_ports_verify = 1;
1158 if (sec_cap->ipsec.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL)
1159 sec_cap->ipsec.options.tunnel_hdr_verify =
1160 RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
1162 sec_cap->ipsec.options.ip_csum_enable = 1;
1163 sec_cap->ipsec.options.l4_csum_enable = 1;
1164 sec_cap->ipsec.options.stats = 1;
1165 sec_cap->ipsec.options.esn = 1;
1166 sec_cap->ipsec.replay_win_sz_max = ROC_AR_WIN_SIZE_MAX;
1170 cn9k_sec_caps_update(struct rte_security_capability *sec_cap)
1172 if (sec_cap->ipsec.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
1173 #ifdef LA_IPSEC_DEBUG
1174 sec_cap->ipsec.options.iv_gen_disable = 1;
1177 sec_cap->ipsec.replay_win_sz_max = CNXK_ON_AR_WIN_SIZE_MAX;
1181 cnxk_cpt_caps_populate(struct cnxk_cpt_vf *vf)
1185 crypto_caps_populate(vf->crypto_caps, vf->cpt.hw_caps);
1186 sec_crypto_caps_populate(vf->sec_crypto_caps, vf->cpt.hw_caps);
1188 PLT_STATIC_ASSERT(RTE_DIM(sec_caps_templ) <= RTE_DIM(vf->sec_caps));
1189 memcpy(vf->sec_caps, sec_caps_templ, sizeof(sec_caps_templ));
1191 for (i = 0; i < RTE_DIM(sec_caps_templ) - 1; i++) {
1192 vf->sec_caps[i].crypto_capabilities = vf->sec_crypto_caps;
1194 cnxk_sec_caps_update(&vf->sec_caps[i]);
1196 if (roc_model_is_cn10k())
1197 cn10k_sec_caps_update(&vf->sec_caps[i]);
1199 if (roc_model_is_cn9k())
1200 cn9k_sec_caps_update(&vf->sec_caps[i]);
1205 const struct rte_security_capability *
1206 cnxk_crypto_sec_capabilities_get(void *device)
1208 struct rte_cryptodev *dev = device;
1209 struct cnxk_cpt_vf *vf;
1211 vf = dev->data->dev_private;
1212 return vf->sec_caps;