Add crypto driver skeleton for zsda devices.

Signed-off-by: Hanxiao Li <li.hanx...@zte.com.cn>
---
 MAINTAINERS                           |   6 ++
 doc/guides/cryptodevs/index.rst       |   1 +
 doc/guides/cryptodevs/zsda.rst        |  26 ++++++
 drivers/common/zsda/meson.build       |  12 ++-
 drivers/common/zsda/zsda_device.c     |  14 +++-
 drivers/common/zsda/zsda_device.h     |  10 +++
 drivers/common/zsda/zsda_qp.c         |   9 ++
 drivers/common/zsda/zsda_qp_common.h  |   5 +-
 drivers/crypto/zsda/zsda_crypto_pmd.c | 115 ++++++++++++++++++++++++++
 drivers/crypto/zsda/zsda_crypto_pmd.h |  49 +++++++++++
 10 files changed, 244 insertions(+), 3 deletions(-)
 create mode 100644 doc/guides/cryptodevs/zsda.rst
 create mode 100644 drivers/crypto/zsda/zsda_crypto_pmd.c
 create mode 100644 drivers/crypto/zsda/zsda_crypto_pmd.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 167cc74a15..3e16789250 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1270,6 +1270,12 @@ F: drivers/crypto/virtio/
 F: doc/guides/cryptodevs/virtio.rst
 F: doc/guides/cryptodevs/features/virtio.ini
 
+ZTE Storage Data Accelerator (ZSDA)
+M: Hanxiao Li <li.hanx...@zte.com.cn>
+F: drivers/crypto/zsda/
+F: doc/guides/cryptodevs/zsda.rst
+F: doc/guides/cryptodevs/features/zsda.ini
+
 
 Compression Drivers
 -------------------
diff --git a/doc/guides/cryptodevs/index.rst b/doc/guides/cryptodevs/index.rst
index 1e57a9fe86..be2620f185 100644
--- a/doc/guides/cryptodevs/index.rst
+++ b/doc/guides/cryptodevs/index.rst
@@ -34,3 +34,4 @@ Crypto Device Drivers
     uadk
     virtio
     zuc
+    zsda
diff --git a/doc/guides/cryptodevs/zsda.rst b/doc/guides/cryptodevs/zsda.rst
new file mode 100644
index 0000000000..0a7aeb2d50
--- /dev/null
+++ b/doc/guides/cryptodevs/zsda.rst
@@ -0,0 +1,26 @@
+..  SPDX-License-Identifier: BSD-3-Clause
+    Copyright(c) 2025 ZTE Corporation.
+
+ZTE Storage Data Accelerator (ZSDA) Poll Mode Driver
+====================================================
+
+The ZSDA crypto PMD provides poll mode Cipher and Hash driver
+support for the following hardware accelerator devices:
+
+* ``ZTE Processing accelerators 1cf2``
+
+
+Features
+--------
+
+
+Limitations
+-----------
+
+
+Installation
+------------
+
+
+Testing
+-------
diff --git a/drivers/common/zsda/meson.build b/drivers/common/zsda/meson.build
index be4fbaedb3..e897c3a931 100644
--- a/drivers/common/zsda/meson.build
+++ b/drivers/common/zsda/meson.build
@@ -7,7 +7,7 @@ if is_windows
     subdir_done()
 endif
 
-deps += ['bus_pci', 'mbuf', 'compressdev']
+deps += ['bus_pci', 'compressdev', 'cryptodev']
 sources += files(
         'zsda_device.c',
         'zsda_logs.c',
@@ -24,3 +24,13 @@ if zsda_compress
         sources += files(join_paths(zsda_compress_relpath, f))
     endforeach
 endif
+
+zsda_crypto = true
+zsda_crypto_path = 'crypto/zsda'
+zsda_crypto_relpath = '../../' + zsda_crypto_path
+includes += include_directories(zsda_crypto_relpath)
+if zsda_crypto
+    foreach f: ['zsda_crypto_pmd.c']
+        sources += files(join_paths(zsda_crypto_relpath, f))
+    endforeach
+endif
diff --git a/drivers/common/zsda/zsda_device.c 
b/drivers/common/zsda/zsda_device.c
index 8a89dc7fc9..0d1e772fe4 100644
--- a/drivers/common/zsda/zsda_device.c
+++ b/drivers/common/zsda/zsda_device.c
@@ -152,6 +152,7 @@ zsda_pci_dev_destroy(struct zsda_pci_device *zsda_pci_dev,
 {
 
        zsda_comp_dev_destroy(zsda_pci_dev);
+       zsda_crypto_dev_destroy(zsda_pci_dev);
 
        return zsda_pci_device_release(pci_dev);
 }
@@ -177,9 +178,20 @@ zsda_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 
        ret = zsda_comp_dev_create(zsda_pci_dev);
        if (ret)
-               ZSDA_LOG(ERR, "Failed! dev create.");
+               ZSDA_LOG(ERR, "Failed! comp_dev create.");
+
+       ret = zsda_crypto_dev_create(zsda_pci_dev);
+       if (ret) {
+               ZSDA_LOG(ERR, "Failed! crypto_dev create.");
+               goto exit;
+       }
 
        return ret;
+
+exit:
+       zsda_comp_dev_destroy(zsda_pci_dev);
+
+       return ZSDA_FAILED;
 }
 
 static int
diff --git a/drivers/common/zsda/zsda_device.h 
b/drivers/common/zsda/zsda_device.h
index dd0fa35ba6..036e157b8d 100644
--- a/drivers/common/zsda/zsda_device.h
+++ b/drivers/common/zsda/zsda_device.h
@@ -7,6 +7,7 @@
 
 #include "zsda_qp_common.h"
 #include "zsda_comp_pmd.h"
+#include "zsda_crypto_pmd.h"
 
 #define MAX_QPS_ON_FUNCTION                    128
 #define ZSDA_DEV_NAME_MAX_LEN          64
@@ -21,6 +22,11 @@ struct zsda_device_info {
         * Register with this rather than with the one in
         * pci_dev so that its driver can have a compression-specific name
         */
+       struct rte_device crypto_rte_dev;
+       /**< This represents the crypto subset of this pci device.
+        * Register with this rather than with the one in
+        * pci_dev so that its driver can have a crypto-specific name
+        */
        struct rte_pci_device *pci_dev;
 };
 
@@ -52,6 +58,10 @@ struct zsda_pci_device {
        struct zsda_comp_dev_private *comp_dev;
        /**< link back to compressdev private data */
 
+       /* Data relating to crypto service */
+       struct zsda_crypto_dev_private *crypto_dev_priv;
+       /**< link back to cryptodev private data */
+
        struct zsda_qp_hw zsda_hw_qps[ZSDA_MAX_SERVICES];
        uint16_t zsda_qp_hw_num[ZSDA_MAX_SERVICES];
 };
diff --git a/drivers/common/zsda/zsda_qp.c b/drivers/common/zsda/zsda_qp.c
index 0ef7cac585..a5f00d8ab6 100644
--- a/drivers/common/zsda/zsda_qp.c
+++ b/drivers/common/zsda/zsda_qp.c
@@ -15,6 +15,9 @@ static uint8_t zsda_num_used_qps;
 static struct ring_size zsda_qp_hw_ring_size[ZSDA_MAX_SERVICES] = {
        [ZSDA_SERVICE_COMPRESSION] = {32, 16},
        [ZSDA_SERVICE_DECOMPRESSION] = {32, 16},
+       [ZSDA_SERVICE_CRYPRO_ENCRY] = {128, 16},
+       [ZSDA_SERVICE_CRYPTO_DECRY] = {128, 16},
+       [ZSDA_SERVICE_HASH_ENCODE] = {32, 16},
 };
 
 static const uint8_t crc8_table[256] = {
@@ -480,6 +483,12 @@ zsda_nb_qps_get(const struct zsda_pci_device *zsda_pci_dev)
                zsda_num_qps_get(zsda_pci_dev, ZSDA_SERVICE_COMPRESSION);
        zsda_nb_qps.decomp =
                zsda_num_qps_get(zsda_pci_dev, ZSDA_SERVICE_DECOMPRESSION);
+       zsda_nb_qps.encrypt =
+               zsda_num_qps_get(zsda_pci_dev, ZSDA_SERVICE_CRYPRO_ENCRY);
+       zsda_nb_qps.decrypt =
+               zsda_num_qps_get(zsda_pci_dev, ZSDA_SERVICE_CRYPTO_DECRY);
+       zsda_nb_qps.hash =
+               zsda_num_qps_get(zsda_pci_dev, ZSDA_SERVICE_HASH_ENCODE);
 }
 
 int
diff --git a/drivers/common/zsda/zsda_qp_common.h 
b/drivers/common/zsda/zsda_qp_common.h
index 941278c6d2..911b3a07a3 100644
--- a/drivers/common/zsda/zsda_qp_common.h
+++ b/drivers/common/zsda/zsda_qp_common.h
@@ -24,9 +24,12 @@
 enum zsda_service_type {
        ZSDA_SERVICE_COMPRESSION = 0,
        ZSDA_SERVICE_DECOMPRESSION = 1,
+       ZSDA_SERVICE_CRYPRO_ENCRY = 2,
+       ZSDA_SERVICE_CRYPTO_DECRY = 3,
+       ZSDA_SERVICE_HASH_ENCODE = 6,
        ZSDA_SERVICE_INVALID,
 };
-#define ZSDA_MAX_SERVICES (2)
+#define ZSDA_MAX_SERVICES (ZSDA_SERVICE_INVALID)
 
 #define ZSDA_CSR_READ32(addr)        rte_read32((addr))
 #define ZSDA_CSR_WRITE32(addr, value) rte_write32((value), (addr))
diff --git a/drivers/crypto/zsda/zsda_crypto_pmd.c 
b/drivers/crypto/zsda/zsda_crypto_pmd.c
new file mode 100644
index 0000000000..99acfa3418
--- /dev/null
+++ b/drivers/crypto/zsda/zsda_crypto_pmd.c
@@ -0,0 +1,115 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2025 ZTE Corporation
+ */
+
+#include <rte_cryptodev.h>
+
+#include "zsda_crypto_pmd.h"
+
+uint8_t zsda_crypto_driver_id;
+
+static struct rte_cryptodev_ops crypto_zsda_ops = {
+       .dev_configure = NULL,
+       .dev_start = NULL,
+       .dev_stop = NULL,
+       .dev_close = NULL,
+       .dev_infos_get = NULL,
+
+       .stats_get = NULL,
+       .stats_reset = NULL,
+       .queue_pair_setup = NULL,
+       .queue_pair_release = NULL,
+
+       .sym_session_get_size = NULL,
+       .sym_session_configure = NULL,
+       .sym_session_clear = NULL,
+};
+
+static const char zsda_crypto_drv_name[] = RTE_STR(CRYPTODEV_NAME_ZSDA_PMD);
+static const struct rte_driver cryptodev_zsda_crypto_driver = {
+       .name = zsda_crypto_drv_name,
+       .alias = zsda_crypto_drv_name
+};
+
+int
+zsda_crypto_dev_create(struct zsda_pci_device *zsda_pci_dev)
+{
+       struct zsda_device_info *dev_info =
+               &zsda_devs[zsda_pci_dev->zsda_dev_id];
+
+       struct rte_cryptodev_pmd_init_params init_params = {
+               .name = "",
+               .socket_id = (int)rte_socket_id(),
+               .private_data_size = sizeof(struct zsda_crypto_dev_private)
+       };
+
+       char name[RTE_CRYPTODEV_NAME_MAX_LEN];
+       struct rte_cryptodev *cryptodev;
+       struct zsda_crypto_dev_private *crypto_dev_priv;
+
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return ZSDA_SUCCESS;
+
+       snprintf(name, RTE_CRYPTODEV_NAME_MAX_LEN, "%s_%s", zsda_pci_dev->name,
+                "crypto");
+       ZSDA_LOG(DEBUG, "Creating ZSDA crypto device %s", name);
+
+       dev_info->crypto_rte_dev.driver = &cryptodev_zsda_crypto_driver;
+       dev_info->crypto_rte_dev.numa_node = 
dev_info->pci_dev->device.numa_node;
+
+       cryptodev = rte_cryptodev_pmd_create(name, &(dev_info->crypto_rte_dev),
+                                            &init_params);
+
+       if (cryptodev == NULL) {
+               ZSDA_LOG(ERR, "Failed! rte_cryptodev_pmd_create");
+               goto error;
+       }
+
+       dev_info->crypto_rte_dev.name = cryptodev->data->name;
+       cryptodev->driver_id = zsda_crypto_driver_id;
+
+       cryptodev->dev_ops = &crypto_zsda_ops;
+
+       cryptodev->enqueue_burst = NULL;
+       cryptodev->dequeue_burst = NULL;
+       cryptodev->feature_flags = 0;
+
+       crypto_dev_priv = cryptodev->data->dev_private;
+       crypto_dev_priv->zsda_pci_dev = zsda_pci_dev;
+       crypto_dev_priv->cryptodev = cryptodev;
+
+       zsda_pci_dev->crypto_dev_priv = crypto_dev_priv;
+
+       return ZSDA_SUCCESS;
+
+error:
+
+       rte_cryptodev_pmd_destroy(cryptodev);
+       memset(&dev_info->crypto_rte_dev, 0, sizeof(dev_info->crypto_rte_dev));
+
+       return -EFAULT;
+}
+
+void
+zsda_crypto_dev_destroy(struct zsda_pci_device *zsda_pci_dev)
+{
+       struct zsda_crypto_dev_private *crypto_dev_priv;
+
+       if (zsda_pci_dev == NULL)
+               return;
+
+       crypto_dev_priv = zsda_pci_dev->crypto_dev_priv;
+       if (crypto_dev_priv == NULL)
+               return;
+
+       if (rte_eal_process_type() == RTE_PROC_PRIMARY)
+               rte_memzone_free(crypto_dev_priv->capa_mz);
+
+       rte_cryptodev_pmd_destroy(crypto_dev_priv->cryptodev);
+       zsda_devs[zsda_pci_dev->zsda_dev_id].crypto_rte_dev.name = NULL;
+       zsda_pci_dev->crypto_dev_priv = NULL;
+}
+
+static struct cryptodev_driver zsda_crypto_drv;
+RTE_PMD_REGISTER_CRYPTO_DRIVER(zsda_crypto_drv, cryptodev_zsda_crypto_driver,
+                              zsda_crypto_driver_id);
diff --git a/drivers/crypto/zsda/zsda_crypto_pmd.h 
b/drivers/crypto/zsda/zsda_crypto_pmd.h
new file mode 100644
index 0000000000..1b17735d40
--- /dev/null
+++ b/drivers/crypto/zsda/zsda_crypto_pmd.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2025 ZTE Corporation
+ */
+
+#ifndef _ZSDA_CRYPTO_PMD_H_
+#define _ZSDA_CRYPTO_PMD_H_
+
+#include "cryptodev_pmd.h"
+
+#include "zsda_qp.h"
+
+/** ZSDA Crypto PMD driver name */
+#define CRYPTODEV_NAME_ZSDA_PMD crypto_zsda
+#define ZSDA_CIPHER_KEY_MAX_LEN 64
+
+#define ZSDA_OPC_EC_AES_XTS_256        0x0  /* Encry AES-XTS-256 */
+#define ZSDA_OPC_EC_AES_XTS_512        0x01 /* Encry AES-XTS-512 */
+#define ZSDA_OPC_EC_SM4_XTS_256        0x02 /* Encry SM4-XTS-256 */
+#define ZSDA_OPC_DC_AES_XTS_256        0x08 /* Decry AES-XTS-256 */
+#define ZSDA_OPC_DC_AES_XTS_512        0x09 /* Decry AES-XTS-512 */
+#define ZSDA_OPC_DC_SM4_XTS_256        0x0A /* Decry SM4-XTS-256 */
+#define ZSDA_OPC_HASH_SHA1     0x20 /* Hash-SHA1 */
+#define ZSDA_OPC_HASH_SHA2_224 0x21 /* Hash-SHA2-224 */
+#define ZSDA_OPC_HASH_SHA2_256 0x22 /* Hash-SHA2-256 */
+#define ZSDA_OPC_HASH_SHA2_384 0x23 /* Hash-SHA2-384 */
+#define ZSDA_OPC_HASH_SHA2_512 0x24 /* Hash-SHA2-512 */
+#define ZSDA_OPC_HASH_SM3      0x25 /* Hash-SM3 */
+
+
+/** private data structure for a ZSDA device.
+ * This ZSDA device is a device offering only symmetric crypto service,
+ * there can be one of these on each zsda_pci_device (VF).
+ */
+struct zsda_crypto_dev_private {
+       struct zsda_pci_device *zsda_pci_dev;
+       /* The zsda pci device hosting the service */
+       struct rte_cryptodev *cryptodev;
+       /* The pointer to this crypto device structure */
+       const struct rte_cryptodev_capabilities *zsda_crypto_capabilities;
+       /* ZSDA device crypto capabilities */
+       const struct rte_memzone *capa_mz;
+       /* Shared memzone for storing capabilities */
+};
+
+int zsda_crypto_dev_create(struct zsda_pci_device *zsda_pci_dev);
+
+void zsda_crypto_dev_destroy(struct zsda_pci_device *zsda_pci_dev);
+
+#endif /* _ZSDA_CRYPTO_PMD_H_ */
-- 
2.27.0

Reply via email to