[v2,2/8] net/rnp: add ethdev probe and remove

Message ID 20230802081106.2340406-3-caowenbo@mucse.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series *** Add Support New Pmd Driver *** |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

11 Aug. 2, 2023, 8:11 a.m. UTC
  Add basic PCIe ethdev probe and remove.

Signed-off-by: Wenbo Cao <caowenbo@mucse.com>
---
 drivers/net/rnp/rnp.h        | 13 ++++++
 drivers/net/rnp/rnp_ethdev.c | 83 ++++++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+)
 create mode 100644 drivers/net/rnp/rnp.h
  

Comments

Stephen Hemminger Aug. 2, 2023, 4:06 p.m. UTC | #1
On Wed,  2 Aug 2023 08:11:00 +0000
Wenbo Cao <caowenbo@mucse.com> wrote:

> +RTE_PMD_REGISTER_PCI(net_rnp, rte_rnp_pmd);
> +RTE_PMD_REGISTER_PCI_TABLE(net_rnp, pci_id_rnp_map);
> +RTE_PMD_REGISTER_KMOD_DEP(net_txgbe, "igb_uio | uio_pci_generic");

Will this driver work with VFIO? Vfio is preferred over igb_uio.
  
11 Aug. 3, 2023, 2 a.m. UTC | #2
Hello Stephen,

Thanks for your comment.
For vfio-pci mode we can support it, but when multiple rerun dpdk-app,
In rte_eal_init the logical of vfio will reset pcie.
The firmware will be core-dump for read pcie Configuration Space, when the
pcie is in reset state.
This bug is resolving and testing, so that this code just support igb_uio.
Until the test has been finished, I will add vfio-pci ability.
Do I need add this ability of vfio in this patch ?

Regards Wenbo

-----Original Message-----
From: Stephen Hemminger <stephen@networkplumber.org> 
Sent: 2023年8月3日 0:07
To: Wenbo Cao <caowenbo@mucse.com>
Cc: Anatoly Burakov <anatoly.burakov@intel.com>; dev@dpdk.org;
ferruh.yigit@intel.com; andrew.rybchenko@oktetlabs.ru
Subject: Re: [PATCH v2 2/8] net/rnp: add ethdev probe and remove

On Wed,  2 Aug 2023 08:11:00 +0000
Wenbo Cao <caowenbo@mucse.com> wrote:

> +RTE_PMD_REGISTER_PCI(net_rnp, rte_rnp_pmd); 
> +RTE_PMD_REGISTER_PCI_TABLE(net_rnp, pci_id_rnp_map); 
> +RTE_PMD_REGISTER_KMOD_DEP(net_txgbe, "igb_uio | uio_pci_generic");

Will this driver work with VFIO? Vfio is preferred over igb_uio.
  

Patch

diff --git a/drivers/net/rnp/rnp.h b/drivers/net/rnp/rnp.h
new file mode 100644
index 0000000000..76d281cc0a
--- /dev/null
+++ b/drivers/net/rnp/rnp.h
@@ -0,0 +1,13 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2023 Mucse IC Design Ltd.
+ */
+#ifndef __RNP_H__
+#define __RNP_H__
+
+#define PCI_VENDOR_ID_MUCSE	(0x8848)
+#define RNP_DEV_ID_N10G		(0x1000)
+
+struct rnp_eth_port {
+} __rte_cache_aligned;
+
+#endif /* __RNP_H__ */
diff --git a/drivers/net/rnp/rnp_ethdev.c b/drivers/net/rnp/rnp_ethdev.c
index 9ce3c0b497..5951c2b311 100644
--- a/drivers/net/rnp/rnp_ethdev.c
+++ b/drivers/net/rnp/rnp_ethdev.c
@@ -1,3 +1,86 @@ 
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(C) 2023 Mucse IC Design Ltd.
  */
+
+#include <ethdev_pci.h>
+#include <rte_io.h>
+#include <rte_malloc.h>
+
+#include "rnp.h"
+
+static int
+rnp_eth_dev_init(struct rte_eth_dev *eth_dev)
+{
+	RTE_SET_USED(eth_dev);
+
+	return -ENODEV;
+}
+
+static int
+rnp_eth_dev_uninit(struct rte_eth_dev *eth_dev)
+{
+	RTE_SET_USED(eth_dev);
+
+	return -ENODEV;
+}
+
+static int
+rnp_pci_remove(struct rte_pci_device *pci_dev)
+{
+	struct rte_eth_dev *eth_dev;
+	int rc;
+
+	eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
+
+	if (eth_dev) {
+		/* Cleanup eth dev */
+		rc = rte_eth_dev_pci_generic_remove(pci_dev,
+				rnp_eth_dev_uninit);
+		if (rc)
+			return rc;
+	}
+	/* Nothing to be done for secondary processes */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return 0;
+
+	return 0;
+}
+
+static int
+rnp_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
+{
+	int rc;
+
+	RTE_SET_USED(pci_drv);
+
+	rc = rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct rnp_eth_port),
+					   rnp_eth_dev_init);
+
+	/* On error on secondary, recheck if port exists in primary or
+	 * in mid of detach state.
+	 */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY && rc)
+		if (!rte_eth_dev_allocated(pci_dev->device.name))
+			return 0;
+	return rc;
+}
+
+static const struct rte_pci_id pci_id_rnp_map[] = {
+	{
+		RTE_PCI_DEVICE(PCI_VENDOR_ID_MUCSE, RNP_DEV_ID_N10G)
+	},
+	{
+		.vendor_id = 0,
+	},
+};
+
+static struct rte_pci_driver rte_rnp_pmd = {
+	.id_table = pci_id_rnp_map,
+	.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+	.probe = rnp_pci_probe,
+	.remove = rnp_pci_remove,
+};
+
+RTE_PMD_REGISTER_PCI(net_rnp, rte_rnp_pmd);
+RTE_PMD_REGISTER_PCI_TABLE(net_rnp, pci_id_rnp_map);
+RTE_PMD_REGISTER_KMOD_DEP(net_txgbe, "igb_uio | uio_pci_generic");