DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v3 03/19] net/xsc: add PCI device probe and remove
@ 2024-09-18  6:09 WanRenyong
  2024-09-18  7:28 ` David Marchand
  0 siblings, 1 reply; 3+ messages in thread
From: WanRenyong @ 2024-09-18  6:09 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit, WanRenyong

Support the following Yunsilicon NICs to be probed:

- metaScale-200
- metaScale-200S
- metaScale-50
- metaScale-100Q

Signed-off-by: WanRenyong <wanry@yunsilicon.com>
Signed-off-by: Na Na <nana@yunsilicon.com>
---
 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 <ethdev_pci.h>
+
 #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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-09-18  7:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-18  6:09 [PATCH v3 03/19] net/xsc: add PCI device probe and remove WanRenyong
2024-09-18  7:28 ` David Marchand
2024-09-18  7:50   ` WanRenyong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).