DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 08/19] net/xsc: create eth devices for representor ports
@ 2024-09-06 12:13 WanRenyong
  0 siblings, 0 replies; only message in thread
From: WanRenyong @ 2024-09-06 12:13 UTC (permalink / raw)
  To: dev; +Cc: ferruh.yigit, nana, WanRenyong

Each representor port is a rte ethernet device.

Signed-off-by: WanRenyong <wanry@yunsilicon.com>
---
 drivers/net/xsc/xsc_ethdev.c | 87 ++++++++++++++++++++++++++++++++++++
 drivers/net/xsc/xsc_ethdev.h |  1 +
 2 files changed, 88 insertions(+)

diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 6a33cbb2cd..d6efc3c9a0 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -9,6 +9,83 @@
 #include "xsc_dev.h"
 #include "xsc_ethdev.h"
 
+static int
+xsc_ethdev_init_one_representor(struct rte_eth_dev *eth_dev, void *init_params)
+{
+	struct xsc_repr_port *repr_port = (struct xsc_repr_port *)init_params;
+	struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+
+	priv->repr_port = repr_port;
+	repr_port->drv_data = eth_dev;
+
+	return 0;
+}
+
+static int
+xsc_ethdev_init_representors(struct rte_eth_dev *eth_dev)
+{
+	struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(eth_dev);
+	struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
+	struct rte_device *dev;
+	struct xsc_dev *xdev;
+	struct xsc_repr_port *repr_port;
+	char name[RTE_ETH_NAME_MAX_LEN];
+	int i;
+	int ret;
+
+	PMD_INIT_FUNC_TRACE();
+
+	dev = &priv->pci_dev->device;
+	if (dev->devargs != NULL) {
+		ret = rte_eth_devargs_parse(dev->devargs->args, &eth_da, 1);
+		if (ret < 0) {
+			PMD_DRV_LOG(ERR, "Failed to parse device arguments: %s",
+				    dev->devargs->args);
+			return -EINVAL;
+		}
+	}
+
+	xdev = priv->xdev;
+	ret = xsc_repr_ports_probe(xdev, eth_da.nb_representor_ports, RTE_MAX_ETHPORTS);
+	if (ret != 0) {
+		PMD_DRV_LOG(ERR, "Failed to probe %d xsc device representors",
+			    eth_da.nb_representor_ports);
+		return ret;
+	}
+
+	repr_port = &xdev->repr_ports[XSC_DEV_REPR_PORT];
+	ret = xsc_ethdev_init_one_representor(eth_dev, repr_port);
+	if (ret != 0) {
+		PMD_DRV_LOG(ERR, "Failed to init backing representor");
+		return ret;
+	}
+
+	for (i = 1; i < xdev->num_repr_ports; i++) {
+		repr_port = &xdev->repr_ports[i];
+		snprintf(name, sizeof(name), "%s_rep_%d",
+			 xdev->ibv_name, repr_port->info.repr_id);
+		ret = rte_eth_dev_create(&xdev->pci_dev->device,
+					 name,
+					 sizeof(struct xsc_ethdev_priv),
+					 NULL, NULL,
+					 xsc_ethdev_init_one_representor,
+					 repr_port);
+		if (ret != 0) {
+			PMD_DRV_LOG(ERR, "Failed to create representor: %d", i);
+			goto destroy_reprs;
+		}
+	}
+
+	return 0;
+
+destroy_reprs:
+	while ((i--) > 1) {
+		repr_port = &xdev->repr_ports[i];
+		rte_eth_dev_destroy((struct rte_eth_dev *)repr_port->drv_data, NULL);
+	}
+	return ret;
+}
+
 static int
 xsc_ethdev_init(struct rte_eth_dev *eth_dev)
 {
@@ -26,7 +103,17 @@ xsc_ethdev_init(struct rte_eth_dev *eth_dev)
 		return ret;
 	}
 
+	ret = xsc_ethdev_init_representors(eth_dev);
+	if (ret != 0) {
+		PMD_DRV_LOG(ERR, "Failed to initialize representors");
+		goto uninit_xsc_dev;
+	}
+
 	return 0;
+
+uninit_xsc_dev:
+	xsc_dev_uninit(priv->xdev);
+	return ret;
 }
 
 static int
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
index 22fc462e25..a05a63193c 100644
--- a/drivers/net/xsc/xsc_ethdev.h
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -9,6 +9,7 @@ struct xsc_ethdev_priv {
 	struct rte_eth_dev *eth_dev;
 	struct rte_pci_device *pci_dev;
 	struct xsc_dev *xdev;
+	struct xsc_repr_port *repr_port;
 };
 
 #define TO_XSC_ETHDEV_PRIV(dev) \
-- 
2.25.1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-09-06 12:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-06 12:13 [PATCH 08/19] net/xsc: create eth devices for representor ports 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).