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_sha1_sha2[] = {
33 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
35 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
37 .algo = RTE_CRYPTO_AUTH_SHA1,
53 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
55 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
57 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
73 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
75 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
77 .algo = RTE_CRYPTO_AUTH_SHA224,
93 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
95 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
97 .algo = RTE_CRYPTO_AUTH_SHA224_HMAC,
113 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
115 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
117 .algo = RTE_CRYPTO_AUTH_SHA256,
133 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
135 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
137 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
153 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
155 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
157 .algo = RTE_CRYPTO_AUTH_SHA384,
173 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
175 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
177 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
193 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
195 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
197 .algo = RTE_CRYPTO_AUTH_SHA512,
213 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
215 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
217 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
233 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
235 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
237 .algo = RTE_CRYPTO_AUTH_MD5,
253 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
255 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
257 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
274 static const struct rte_cryptodev_capabilities caps_chacha20[] = {
275 { /* Chacha20-Poly1305 */
276 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
278 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
280 .algo = RTE_CRYPTO_AEAD_CHACHA20_POLY1305,
307 static const struct rte_cryptodev_capabilities caps_zuc_snow3g[] = {
308 { /* SNOW 3G (UEA2) */
309 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
311 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
313 .algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
329 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
331 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
333 .algo = RTE_CRYPTO_CIPHER_ZUC_EEA3,
348 { /* SNOW 3G (UIA2) */
349 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
351 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
353 .algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2,
374 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
376 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
378 .algo = RTE_CRYPTO_AUTH_ZUC_EIA3,
400 static const struct rte_cryptodev_capabilities caps_aes[] = {
401 { /* AES GMAC (AUTH) */
402 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
404 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
406 .algo = RTE_CRYPTO_AUTH_AES_GMAC,
427 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
429 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
431 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
447 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
449 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
451 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
467 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
469 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
471 .algo = RTE_CRYPTO_CIPHER_AES_XTS,
487 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
489 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
491 .algo = RTE_CRYPTO_AEAD_AES_GCM,
518 static const struct rte_cryptodev_capabilities caps_kasumi[] = {
520 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
522 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
524 .algo = RTE_CRYPTO_CIPHER_KASUMI_F8,
540 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
542 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
544 .algo = RTE_CRYPTO_AUTH_KASUMI_F9,
561 static const struct rte_cryptodev_capabilities caps_des[] = {
563 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
565 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
567 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
583 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
585 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
587 .algo = RTE_CRYPTO_CIPHER_3DES_ECB,
603 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
605 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
607 .algo = RTE_CRYPTO_CIPHER_DES_CBC,
624 static const struct rte_cryptodev_capabilities caps_null[] = {
626 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
628 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
630 .algo = RTE_CRYPTO_AUTH_NULL,
645 { /* NULL (CIPHER) */
646 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
648 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
650 .algo = RTE_CRYPTO_CIPHER_NULL,
667 static const struct rte_cryptodev_capabilities caps_end[] = {
668 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
671 static const struct rte_cryptodev_capabilities sec_caps_aes[] = {
673 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
675 .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
677 .algo = RTE_CRYPTO_AEAD_AES_GCM,
704 static const struct rte_security_capability sec_caps_templ[] = {
705 { /* IPsec Lookaside Protocol ESP Tunnel Ingress */
706 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
707 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
709 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
710 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
711 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
714 .crypto_capabilities = NULL,
715 .ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
717 { /* IPsec Lookaside Protocol ESP Tunnel Egress */
718 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
719 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
721 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
722 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
723 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
726 .crypto_capabilities = NULL,
727 .ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
730 .action = RTE_SECURITY_ACTION_TYPE_NONE
735 cpt_caps_add(struct rte_cryptodev_capabilities cnxk_caps[], int *cur_pos,
736 const struct rte_cryptodev_capabilities *caps, int nb_caps)
738 if (*cur_pos + nb_caps > CNXK_CPT_MAX_CAPS)
741 memcpy(&cnxk_caps[*cur_pos], caps, nb_caps * sizeof(caps[0]));
746 crypto_caps_populate(struct rte_cryptodev_capabilities cnxk_caps[],
747 union cpt_eng_caps *hw_caps)
751 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, sha1_sha2);
752 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, chacha20);
753 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, zuc_snow3g);
754 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, aes);
755 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, kasumi);
756 CPT_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, des);
758 cpt_caps_add(cnxk_caps, &cur_pos, caps_null, RTE_DIM(caps_null));
759 cpt_caps_add(cnxk_caps, &cur_pos, caps_end, RTE_DIM(caps_end));
762 const struct rte_cryptodev_capabilities *
763 cnxk_crypto_capabilities_get(struct cnxk_cpt_vf *vf)
765 return vf->crypto_caps;
769 sec_caps_add(struct rte_cryptodev_capabilities cnxk_caps[], int *cur_pos,
770 const struct rte_cryptodev_capabilities *caps, int nb_caps)
772 if (*cur_pos + nb_caps > CNXK_SEC_CRYPTO_MAX_CAPS)
775 memcpy(&cnxk_caps[*cur_pos], caps, nb_caps * sizeof(caps[0]));
780 sec_crypto_caps_populate(struct rte_cryptodev_capabilities cnxk_caps[],
781 union cpt_eng_caps *hw_caps)
785 SEC_CAPS_ADD(cnxk_caps, &cur_pos, hw_caps, aes);
787 sec_caps_add(cnxk_caps, &cur_pos, caps_end, RTE_DIM(caps_end));
791 cnxk_cpt_caps_populate(struct cnxk_cpt_vf *vf)
795 crypto_caps_populate(vf->crypto_caps, vf->cpt.hw_caps);
796 sec_crypto_caps_populate(vf->sec_crypto_caps, vf->cpt.hw_caps);
798 PLT_STATIC_ASSERT(RTE_DIM(sec_caps_templ) <= RTE_DIM(vf->sec_caps));
799 memcpy(vf->sec_caps, sec_caps_templ, sizeof(sec_caps_templ));
801 for (i = 0; i < RTE_DIM(sec_caps_templ) - 1; i++)
802 vf->sec_caps[i].crypto_capabilities = vf->sec_crypto_caps;
805 const struct rte_security_capability *
806 cnxk_crypto_sec_capabilities_get(void *device)
808 struct rte_cryptodev *dev = device;
809 struct cnxk_cpt_vf *vf;
811 vf = dev->data->dev_private;