From patchwork Sat Feb 8 07:27:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hanxiao Li X-Patchwork-Id: 151176 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 58FDA461C6; Sat, 8 Feb 2025 08:41:10 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 02D4740663; Sat, 8 Feb 2025 08:40:25 +0100 (CET) Received: from mxct.zte.com.cn (mxct.zte.com.cn [183.62.165.209]) by mails.dpdk.org (Postfix) with ESMTP id 8BE69402E9 for ; Sat, 8 Feb 2025 08:40:18 +0100 (CET) Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4YqjRd49Qrz4xfxJ for ; Sat, 8 Feb 2025 15:40:13 +0800 (CST) Received: from szxlzmapp04.zte.com.cn ([10.5.231.166]) by mse-fl1.zte.com.cn with SMTP id 5187dxn8040154 for ; Sat, 8 Feb 2025 15:39:59 +0800 (+08) (envelope-from li.hanxiao@zte.com.cn) Received: from localhost.localdomain (unknown [192.168.6.15]) by smtp (Zmail) with SMTP; Sat, 8 Feb 2025 15:40:01 +0800 X-Zmail-TransId: 3e8167a70a51004-03851 From: Hanxiao Li To: dev@dpdk.org Cc: Hanxiao Li Subject: [PATCH v26 02/13] common/zsda: add zsdadev driver Date: Sat, 8 Feb 2025 15:27:18 +0800 Message-ID: <20250208072732.4008334-3-li.hanxiao@zte.com.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250208072732.4008334-1-li.hanxiao@zte.com.cn> References: <20250122093325.3099070-2-li.hanxiao@zte.com.cn> <20250208072732.4008334-1-li.hanxiao@zte.com.cn> MIME-Version: 1.0 X-MAIL: mse-fl1.zte.com.cn 5187dxn8040154 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 67A70A5D.000/4YqjRd49Qrz4xfxJ X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add basic zsdadev init and register PCI probe functions Signed-off-by: Hanxiao Li --- MAINTAINERS | 3 + drivers/common/zsda/meson.build | 13 ++ drivers/common/zsda/zsda_device.c | 187 +++++++++++++++++++++++++++ drivers/common/zsda/zsda_device.h | 54 ++++++++ drivers/common/zsda/zsda_qp_common.h | 28 ++++ drivers/meson.build | 1 + 6 files changed, 286 insertions(+) create mode 100644 drivers/common/zsda/meson.build create mode 100644 drivers/common/zsda/zsda_device.c create mode 100644 drivers/common/zsda/zsda_device.h create mode 100644 drivers/common/zsda/zsda_qp_common.h -- 2.27.0 diff --git a/MAINTAINERS b/MAINTAINERS index b86cdd266b..86864bc5f1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1312,6 +1312,9 @@ F: drivers/compress/zlib/ F: doc/guides/compressdevs/zlib.rst F: doc/guides/compressdevs/features/zlib.ini +ZTE Storage Data Accelerator(ZSDA) +M: Hanxiao Li +F: drivers/common/zsda/ DMAdev Drivers -------------- diff --git a/drivers/common/zsda/meson.build b/drivers/common/zsda/meson.build new file mode 100644 index 0000000000..68bc549c27 --- /dev/null +++ b/drivers/common/zsda/meson.build @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 ZTE Corporation + +if is_windows + build = false + reason = 'not supported on Windows' + subdir_done() +endif + +deps += ['bus_pci', 'mbuf'] +sources += files( + 'zsda_device.c', + ) diff --git a/drivers/common/zsda/zsda_device.c b/drivers/common/zsda/zsda_device.c new file mode 100644 index 0000000000..a7a3ff5440 --- /dev/null +++ b/drivers/common/zsda/zsda_device.c @@ -0,0 +1,187 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 ZTE Corporation + */ + +#include "zsda_device.h" + +/* per-process array of device data */ +struct zsda_device_info zsda_devs[RTE_PMD_ZSDA_MAX_PCI_DEVICES]; +static int zsda_nb_pci_devices; + +/* + * The set of PCI devices this driver supports + */ +static const struct rte_pci_id pci_id_zsda_map[] = { + { + RTE_PCI_DEVICE(0x1cf2, 0x8050), + }, + { + RTE_PCI_DEVICE(0x1cf2, 0x8051), + }, + {.device_id = 0}, +}; + +static struct zsda_pci_device * +zsda_pci_dev_by_name_get(const char *name) +{ + unsigned int i; + + if (name == NULL) + return NULL; + + for (i = 0; i < RTE_PMD_ZSDA_MAX_PCI_DEVICES; i++) { + if (zsda_devs[i].mz && + (strcmp(((struct zsda_pci_device *)zsda_devs[i].mz->addr) + ->name, + name) == 0)) + return (struct zsda_pci_device *)zsda_devs[i].mz->addr; + } + + return NULL; +} + +static uint8_t +zsda_pci_dev_free_id_get(void) +{ + uint32_t dev_id; + + for (dev_id = 0; dev_id < RTE_PMD_ZSDA_MAX_PCI_DEVICES; dev_id++) + if (zsda_devs[dev_id].mz == NULL) + break; + + return dev_id & (ZSDA_MAX_DEV - 1); +} + +static struct zsda_pci_device * +zsda_pci_dev_get(const struct rte_pci_device *pci_dev) +{ + char name[ZSDA_DEV_NAME_MAX_LEN]; + + rte_pci_device_name(&pci_dev->addr, name, sizeof(name)); + + return zsda_pci_dev_by_name_get(name); +} + +static struct zsda_pci_device * +zsda_pci_device_allocate(struct rte_pci_device *pci_dev) +{ + struct zsda_pci_device *zsda_pci_dev; + uint8_t zsda_dev_id; + char name[ZSDA_DEV_NAME_MAX_LEN]; + unsigned int socket_id = rte_socket_id(); + + rte_pci_device_name(&pci_dev->addr, name, sizeof(name)); + snprintf(name + strlen(name), (ZSDA_DEV_NAME_MAX_LEN - strlen(name)), + "_zsda"); + if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + const struct rte_memzone *mz = rte_memzone_lookup(name); + + if (mz == NULL) + return NULL; + zsda_pci_dev = mz->addr; + zsda_devs[zsda_pci_dev->zsda_dev_id].mz = mz; + zsda_devs[zsda_pci_dev->zsda_dev_id].pci_dev = pci_dev; + zsda_nb_pci_devices++; + return zsda_pci_dev; + } + + if (zsda_pci_dev_by_name_get(name) != NULL) + return NULL; + + zsda_dev_id = zsda_pci_dev_free_id_get(); + + if (zsda_dev_id == (RTE_PMD_ZSDA_MAX_PCI_DEVICES - 1)) + return NULL; + + zsda_devs[zsda_dev_id].mz = + rte_memzone_reserve(name, sizeof(struct zsda_pci_device), + (int)(socket_id & 0xfff), 0); + + if (zsda_devs[zsda_dev_id].mz == NULL) + return NULL; + + zsda_pci_dev = zsda_devs[zsda_dev_id].mz->addr; + memset(zsda_pci_dev, 0, sizeof(*zsda_pci_dev)); + memcpy(zsda_pci_dev->name, name, ZSDA_DEV_NAME_MAX_LEN); + zsda_pci_dev->zsda_dev_id = zsda_dev_id; + zsda_pci_dev->pci_dev = pci_dev; + zsda_devs[zsda_dev_id].pci_dev = pci_dev; + + zsda_nb_pci_devices++; + + return zsda_pci_dev; +} + +static int +zsda_pci_device_release(const struct rte_pci_device *pci_dev) +{ + struct zsda_pci_device *zsda_pci_dev; + struct zsda_device_info *inst; + char name[ZSDA_DEV_NAME_MAX_LEN]; + + if (pci_dev == NULL) + return -EINVAL; + + rte_pci_device_name(&pci_dev->addr, name, sizeof(name)); + + snprintf(name + strlen(name), + ZSDA_DEV_NAME_MAX_LEN - (strlen(name) - 1), "_zsda"); + zsda_pci_dev = zsda_pci_dev_by_name_get(name); + if (zsda_pci_dev != NULL) { + inst = &zsda_devs[zsda_pci_dev->zsda_dev_id]; + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) + rte_memzone_free(inst->mz); + + memset(inst, 0, sizeof(struct zsda_device_info)); + zsda_nb_pci_devices--; + } + return 0; +} + +static int +zsda_pci_dev_destroy(struct zsda_pci_device *zsda_pci_dev __rte_unused, + const struct rte_pci_device *pci_dev) +{ + return zsda_pci_device_release(pci_dev); +} + +static int +zsda_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev) +{ + int ret = 0; + struct zsda_pci_device *zsda_pci_dev; + + zsda_pci_dev = zsda_pci_device_allocate(pci_dev); + if (zsda_pci_dev == NULL) + return -ENODEV; + + return ret; +} + +static int +zsda_pci_remove(struct rte_pci_device *pci_dev) +{ + struct zsda_pci_device *zsda_pci_dev; + + if (pci_dev == NULL) + return -EINVAL; + + zsda_pci_dev = zsda_pci_dev_get(pci_dev); + if (zsda_pci_dev == NULL) + return 0; + + return zsda_pci_dev_destroy(zsda_pci_dev, pci_dev); +} + +static struct rte_pci_driver rte_zsda_pmd = { + .id_table = pci_id_zsda_map, + .drv_flags = RTE_PCI_DRV_NEED_MAPPING, + .probe = zsda_pci_probe, + .remove = zsda_pci_remove }; + +RTE_PMD_REGISTER_PCI(ZSDA_PCI_NAME, rte_zsda_pmd); +RTE_PMD_REGISTER_PCI_TABLE(ZSDA_PCI_NAME, pci_id_zsda_map); +RTE_PMD_REGISTER_KMOD_DEP(ZSDA_PCI_NAME, + "* igb_uio | uio_pci_generic | vfio-pci"); diff --git a/drivers/common/zsda/zsda_device.h b/drivers/common/zsda/zsda_device.h new file mode 100644 index 0000000000..67f8cc09e4 --- /dev/null +++ b/drivers/common/zsda/zsda_device.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 ZTE Corporation + */ + +#ifndef _ZSDA_DEVICE_H_ +#define _ZSDA_DEVICE_H_ + +#include "zsda_qp_common.h" + +#define MAX_QPS_ON_FUNCTION 128 +#define ZSDA_DEV_NAME_MAX_LEN 64 + +struct zsda_device_info { + const struct rte_memzone *mz; + /**< mz to store the: struct zsda_pci_device , so it can be + * shared across processes + */ + struct rte_device comp_rte_dev; + /**< This represents the compression subset of this pci device. + * Register with this rather than with the one in + * pci_dev so that its driver can have a compression-specific name + */ + struct rte_pci_device *pci_dev; +}; + +extern struct zsda_device_info zsda_devs[]; + +struct zsda_qp_hw_data { + bool used; + + uint8_t tx_ring_num; + uint8_t rx_ring_num; + uint16_t tx_msg_size; + uint16_t rx_msg_size; +}; + +struct zsda_qp_hw { + struct zsda_qp_hw_data data[MAX_QPS_ON_FUNCTION]; +}; + +struct zsda_pci_device { + /* Data used by all services */ + char name[ZSDA_DEV_NAME_MAX_LEN]; + /**< Name of zsda pci device */ + uint8_t zsda_dev_id; + /**< Id of device instance for this zsda pci device */ + + struct rte_pci_device *pci_dev; + + struct zsda_qp_hw zsda_hw_qps[ZSDA_MAX_SERVICES]; + uint16_t zsda_qp_hw_num[ZSDA_MAX_SERVICES]; +}; + +#endif /* _ZSDA_DEVICE_H_ */ diff --git a/drivers/common/zsda/zsda_qp_common.h b/drivers/common/zsda/zsda_qp_common.h new file mode 100644 index 0000000000..7635ecc9c1 --- /dev/null +++ b/drivers/common/zsda/zsda_qp_common.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2024 ZTE Corporation + */ + +#ifndef _ZSDA_QP_COMMON_H_ +#define _ZSDA_QP_COMMON_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include "bus_pci_driver.h" + +#define ZSDA_MAX_DEV RTE_PMD_ZSDA_MAX_PCI_DEVICES + +#define ZSDA_SUCCESS 0 +#define ZSDA_FAILED (-1) + +enum zsda_service_type { + ZSDA_SERVICE_INVALID, +}; +#define ZSDA_MAX_SERVICES (0) + +#endif /* _ZSDA_QP_COMMON_H_ */ diff --git a/drivers/meson.build b/drivers/meson.build index 495e21b54a..63ffa1f416 100644 --- a/drivers/meson.build +++ b/drivers/meson.build @@ -17,6 +17,7 @@ subdirs = [ 'common/nitrox', # depends on bus. 'common/qat', # depends on bus. 'common/sfc_efx', # depends on bus. + 'common/zsda', # depends on bus. 'mempool', # depends on common and bus. 'dma', # depends on common and bus. 'net', # depends on common, bus, mempool