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 12A9C4595A; Wed, 11 Sep 2024 04:08:49 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D9C7742F17; Wed, 11 Sep 2024 04:08:14 +0200 (CEST) Received: from lf-1-20.ptr.blmpb.com (lf-1-20.ptr.blmpb.com [103.149.242.20]) by mails.dpdk.org (Postfix) with ESMTP id 9F71940E1D for ; Wed, 11 Sep 2024 04:08:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1726020476; 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=DQ8k62etkOqgBRFbKmRPi+VVgRMD6/YJyu0n27GGRDz6VT1jwBrEutSYwFFb+T5Dv7+xmw vsRBe46PCs3mG0Dk4g4UPm8i4d/hrWOeuY69w3WwGkGwpKwgQoNspWZBAfzv8FOn0zTEWi IC+8NjS9NnP/OxCwxgkB/ifcQM27ofXjgGdOx76eYgsOKx+BlI9j3Ffcry1fEHDWpigdTO iXEOcA1xs/pTXSsZWNXd+5TqDj6rUtl4+9yhPeWsJgnYO5xRFmLazyEn2oqQTL2LtIeKfw 4IONPj78uZkCAGple1s/5VxOMT0PSMm9xpiZlZL5NRPH/wp4WQjw6nhkKq+KtQ== To: Received: from ubuntu-liun.yunsilicon.com ([58.34.192.114]) by smtp.feishu.cn with ESMTPS; Wed, 11 Sep 2024 10:07:55 +0800 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Mailer: git-send-email 2.25.1 Cc: , , "WanRenyong" , "Na Na" Subject: [PATCH v2 03/19] net/xsc: add PCI device probe and remove X-Original-From: WanRenyong Mime-Version: 1.0 X-Lms-Return-Path: From: "WanRenyong" Date: Wed, 11 Sep 2024 10:07:24 +0800 Message-Id: <20240911020740.3950704-4-wanry@yunsilicon.com> 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