1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
5 #include <rte_cryptodev.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,
802 static const struct rte_security_capability sec_caps_templ[] = {
803 { /* IPsec Lookaside Protocol ESP Tunnel Ingress */
804 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
805 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
807 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
808 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
809 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
812 .crypto_capabilities = NULL,
814 { /* IPsec Lookaside Protocol ESP Tunnel Egress */
815 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
816 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
818 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
819 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
820 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
823 .crypto_capabilities = NULL,
825 { /* IPsec Lookaside Protocol ESP Transport Ingress */
826 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
827 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
829 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
830 .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
831 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
834 .crypto_capabilities = NULL,
836 { /* IPsec Lookaside Protocol ESP Transport Egress */
837 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
838 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
840 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
841 .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
842 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
845 .crypto_capabilities = NULL,
848 .action = RTE_SECURITY_ACTION_TYPE_NONE
853 cpt_caps_add(struct rte_cryptodev_capabilities cnxk_caps[], int *cur_pos,
854 const struct rte_cryptodev_capabilities *caps, int nb_caps)
856 if (*cur_pos + nb_caps > CNXK_CPT_MAX_CAPS)
859 memcpy(&cnxk_caps[*cur_pos], caps, nb_caps * sizeof(caps[0]));
864 crypto_caps_populate(struct rte_cryptodev_capabilities cnxk_caps[],
865 union cpt_eng_caps *hw_caps)
869 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, mul);
870 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, sha1_sha2);
871 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, chacha20);
872 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, zuc_snow3g);
873 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, aes);
874 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, kasumi);
875 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, des);
877 cpt_caps_add(cnxk_caps, &cur_pos, caps_null, RTE_DIM(caps_null));
878 cpt_caps_add(cnxk_caps, &cur_pos, caps_end, RTE_DIM(caps_end));
881 const struct rte_cryptodev_capabilities *
882 cnxk_crypto_capabilities_get(struct cnxk_cpt_vf *vf)
884 return vf->crypto_caps;
888 sec_caps_add(struct rte_cryptodev_capabilities cnxk_caps[], int *cur_pos,
889 const struct rte_cryptodev_capabilities *caps, int nb_caps)
891 if (*cur_pos + nb_caps > CNXK_SEC_CRYPTO_MAX_CAPS)
894 memcpy(&cnxk_caps[*cur_pos], caps, nb_caps * sizeof(caps[0]));
899 sec_crypto_caps_populate(struct rte_cryptodev_capabilities cnxk_caps[],
900 union cpt_eng_caps *hw_caps)
904 SEC_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, aes);
905 SEC_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, sha1_sha2);
907 sec_caps_add(cnxk_caps, &cur_pos, caps_end, RTE_DIM(caps_end));
911 cnxk_sec_caps_update(struct rte_security_capability *sec_cap)
913 sec_cap->ipsec.options.udp_encap = 1;
917 cn10k_sec_caps_update(struct rte_security_capability *sec_cap)
919 if (sec_cap->ipsec.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
920 #ifdef LA_IPSEC_DEBUG
921 sec_cap->ipsec.options.iv_gen_disable = 1;
924 sec_cap->ipsec.options.udp_ports_verify = 1;
925 if (sec_cap->ipsec.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL)
926 sec_cap->ipsec.options.tunnel_hdr_verify =
927 RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
932 cn9k_sec_caps_update(struct rte_security_capability *sec_cap)
934 if (sec_cap->ipsec.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
935 sec_cap->ipsec.options.iv_gen_disable = 1;
940 cnxk_cpt_caps_populate(struct cnxk_cpt_vf *vf)
944 crypto_caps_populate(vf->crypto_caps, vf->cpt.hw_caps);
945 sec_crypto_caps_populate(vf->sec_crypto_caps, vf->cpt.hw_caps);
947 PLT_STATIC_ASSERT(RTE_DIM(sec_caps_templ) <= RTE_DIM(vf->sec_caps));
948 memcpy(vf->sec_caps, sec_caps_templ, sizeof(sec_caps_templ));
950 for (i = 0; i < RTE_DIM(sec_caps_templ) - 1; i++) {
951 vf->sec_caps[i].crypto_capabilities = vf->sec_crypto_caps;
953 cnxk_sec_caps_update(&vf->sec_caps[i]);
955 if (roc_model_is_cn10k())
956 cn10k_sec_caps_update(&vf->sec_caps[i]);
958 if (roc_model_is_cn9k())
959 cn9k_sec_caps_update(&vf->sec_caps[i]);
964 const struct rte_security_capability *
965 cnxk_crypto_sec_capabilities_get(void *device)
967 struct rte_cryptodev *dev = device;
968 struct cnxk_cpt_vf *vf;
970 vf = dev->data->dev_private;