From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7BB25459C3; Wed, 18 Sep 2024 08:10:11 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 38A0942E50; Wed, 18 Sep 2024 08:09:54 +0200 (CEST) Received: from lf-2-59.ptr.blmpb.com (lf-2-59.ptr.blmpb.com [101.36.218.59]) by mails.dpdk.org (Postfix) with ESMTP id F175B42DE4 for ; Wed, 18 Sep 2024 08:09:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726639784; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=LuNNyN0MW3rg2Mxwh2wpsDJ5w8rcYYPxI7ecnwPirIk=; b=eOaZRlrTtJxlRwIKdTvWYa2rBSZW9Z3IDFPxUXtfOK1ledF/z9pXnqaMbEfadDvdszEHGU OgR+8PZvn+Eh1dtHHBRsOvwzElaRqWka327mmEkd+5MbHsXfLTsL4WdAoqMktoItH4irNB uomaHkcVig0py/m1AeH2OwV7Q1pnF4NTBguWkv6vfFGPLhyoHtjDyTWVlhfI033nZ4NLfZ rGVYTlDr/fLBMO+aCqSAv1ceFg/tW/FfTuu6/6rSuCtlwp8vzfhB9K3c/CIjiqtAMTrIY7 gnlZBWXmh2VO+3jXl7We8Jvue/Bq0ThOy1b0133/efrD6FFfOrIilAbq+3yOuQ== X-Mailer: git-send-email 2.25.1 To: From: "WanRenyong" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Date: Wed, 18 Sep 2024 14:09:20 +0800 Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 18 Sep 2024 14:09:42 +0800 Cc: , "WanRenyong" Message-Id: <20240918060936.1231758-4-wanry@yunsilicon.com> Content-Type: text/plain; charset=UTF-8 Subject: [PATCH v3 03/19] net/xsc: add PCI device probe and remove X-Lms-Return-Path: X-Original-From: WanRenyong 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 Support the following Yunsilicon NICs to be probed: - metaScale-200 - metaScale-200S - metaScale-50 - metaScale-100Q Signed-off-by: WanRenyong Signed-off-by: Na Na --- drivers/net/xsc/xsc_defs.h | 12 ++++++ drivers/net/xsc/xsc_ethdev.c | 74 ++++++++++++++++++++++++++++++++++++ drivers/net/xsc/xsc_ethdev.h | 16 ++++++++ 3 files changed, 102 insertions(+) create mode 100644 drivers/net/xsc/xsc_defs.h create mode 100644 drivers/net/xsc/xsc_ethdev.h diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h new file mode 100644 index 0000000000..b4ede6eca6 --- /dev/null +++ b/drivers/net/xsc/xsc_defs.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ + +#ifndef XSC_DEFS_H_ +#define XSC_DEFS_H_ + +#define XSC_PCI_VENDOR_ID 0x1f67 +#define XSC_PCI_DEV_ID_MS 0x1111 + +#endif /* XSC_DEFS_H_ */ + diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c index 58ceaa3940..8f4d539848 100644 --- a/drivers/net/xsc/xsc_ethdev.c +++ b/drivers/net/xsc/xsc_ethdev.c @@ -2,7 +2,81 @@ * Copyright 2024 Yunsilicon Technology Co., Ltd. */ +#include + #include "xsc_log.h" +#include "xsc_defs.h" +#include "xsc_ethdev.h" + +static int +xsc_ethdev_init(struct rte_eth_dev *eth_dev) +{ + struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev); + + PMD_INIT_FUNC_TRACE(); + + priv->eth_dev = eth_dev; + priv->pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev); + + return 0; +} + +static int +xsc_ethdev_uninit(struct rte_eth_dev *eth_dev) +{ + RTE_SET_USED(eth_dev); + PMD_INIT_FUNC_TRACE(); + + return 0; +} + +static int +xsc_ethdev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, + struct rte_pci_device *pci_dev) +{ + int ret; + + PMD_INIT_FUNC_TRACE(); + + ret = rte_eth_dev_pci_generic_probe(pci_dev, + sizeof(struct xsc_ethdev_priv), + xsc_ethdev_init); + if (ret) { + PMD_DRV_LOG(ERR, "Failed to probe ethdev: %s", pci_dev->name); + return ret; + } + + return 0; +} + +static int +xsc_ethdev_pci_remove(struct rte_pci_device *pci_dev) +{ + int ret; + + PMD_INIT_FUNC_TRACE(); + + ret = rte_eth_dev_pci_generic_remove(pci_dev, xsc_ethdev_uninit); + if (ret) { + PMD_DRV_LOG(ERR, "Could not remove ethdev: %s", pci_dev->name); + return ret; + } + + return 0; +} + +static const struct rte_pci_id xsc_ethdev_pci_id_map[] = { + { RTE_PCI_DEVICE(XSC_PCI_VENDOR_ID, XSC_PCI_DEV_ID_MS) }, +}; + +static struct rte_pci_driver xsc_ethdev_pci_driver = { + .id_table = xsc_ethdev_pci_id_map, + .probe = xsc_ethdev_pci_probe, + .remove = xsc_ethdev_pci_remove, +}; + +RTE_PMD_REGISTER_PCI(net_xsc, xsc_ethdev_pci_driver); +RTE_PMD_REGISTER_PCI_TABLE(net_xsc, xsc_ethdev_pci_id_map); RTE_LOG_REGISTER_SUFFIX(xsc_logtype_init, init, NOTICE); RTE_LOG_REGISTER_SUFFIX(xsc_logtype_driver, driver, NOTICE); diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h new file mode 100644 index 0000000000..75aa34dc63 --- /dev/null +++ b/drivers/net/xsc/xsc_ethdev.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2024 Yunsilicon Technology Co., Ltd. + */ + +#ifndef _XSC_ETHDEV_H_ +#define _XSC_ETHDEV_H_ + +struct xsc_ethdev_priv { + struct rte_eth_dev *eth_dev; + struct rte_pci_device *pci_dev; +}; + +#define TO_XSC_ETHDEV_PRIV(dev) \ + ((struct xsc_ethdev_priv *)(dev)->data->dev_private) + +#endif /* _XSC_ETHDEV_H_ */ -- 2.25.1