diff mbox series

[34/38] net/sfc: include controller and port in representor name

Message ID 20210827065717.1838258-35-andrew.rybchenko@oktetlabs.ru (mailing list archive)
State Superseded
Delegated to: Ferruh Yigit
Headers show
Series net/sfc: support port representors | expand

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

Andrew Rybchenko Aug. 27, 2021, 6:57 a.m. UTC
From: Viacheslav Galaktionov <viacheslav.galaktionov@oktetlabs.ru>

Make representor names unique on multi-host configurations.

Signed-off-by: Viacheslav Galaktionov <viacheslav.galaktionov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
---
 drivers/net/sfc/sfc_repr.c   | 28 ++++++++++++++++++++++++++--
 drivers/net/sfc/sfc_switch.c | 28 ++++++++++++++++++++++++++++
 drivers/net/sfc/sfc_switch.h |  4 ++++
 3 files changed, 58 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/sfc/sfc_repr.c b/drivers/net/sfc/sfc_repr.c
index a42e70c92c..d50efe6562 100644
--- a/drivers/net/sfc/sfc_repr.c
+++ b/drivers/net/sfc/sfc_repr.c
@@ -1050,11 +1050,35 @@  sfc_repr_create(struct rte_eth_dev *parent,
 {
 	struct sfc_repr_init_data repr_data;
 	char name[RTE_ETH_NAME_MAX_LEN];
+	int controller;
 	int ret;
+	int rc;
 	struct rte_eth_dev *dev;
 
-	if (snprintf(name, sizeof(name), "net_%s_representor_%u",
-		     parent->device->name, entity->vf) >= (int)sizeof(name)) {
+	controller = -1;
+	rc = sfc_mae_switch_domain_get_controller(switch_domain_id,
+						  entity->intf, &controller);
+	if (rc != 0) {
+		SFC_GENERIC_LOG(ERR, "%s() failed to get DPDK controller for %d",
+				__func__, entity->intf);
+		return -rc;
+	}
+
+	switch (entity->type) {
+	case RTE_ETH_REPRESENTOR_VF:
+		ret = snprintf(name, sizeof(name), "net_%s_representor_c%upf%uvf%u",
+			       parent->device->name, controller, entity->pf,
+			       entity->vf);
+		break;
+	case RTE_ETH_REPRESENTOR_PF:
+		ret = snprintf(name, sizeof(name), "net_%s_representor_c%upf%u",
+			       parent->device->name, controller, entity->pf);
+		break;
+	default:
+		return -ENOTSUP;
+	}
+
+	if (ret >= (int)sizeof(name)) {
 		SFC_GENERIC_LOG(ERR, "%s() failed name too long", __func__);
 		return -ENAMETOOLONG;
 	}
diff --git a/drivers/net/sfc/sfc_switch.c b/drivers/net/sfc/sfc_switch.c
index 7a0b332f33..225d07fa15 100644
--- a/drivers/net/sfc/sfc_switch.c
+++ b/drivers/net/sfc/sfc_switch.c
@@ -279,6 +279,34 @@  sfc_mae_switch_domain_map_controllers(uint16_t switch_domain_id,
 	return 0;
 }
 
+int
+sfc_mae_switch_domain_get_controller(uint16_t switch_domain_id,
+				     efx_pcie_interface_t intf,
+				     int *controller)
+{
+	const efx_pcie_interface_t *controllers;
+	size_t nb_controllers;
+	size_t i;
+	int rc;
+
+	rc = sfc_mae_switch_domain_controllers(switch_domain_id, &controllers,
+					       &nb_controllers);
+	if (rc != 0)
+		return rc;
+
+	if (controllers == NULL)
+		return ENOENT;
+
+	for (i = 0; i < nb_controllers; i++) {
+		if (controllers[i] == intf) {
+			*controller = i;
+			return 0;
+		}
+	}
+
+	return ENOENT;
+}
+
 /* This function expects to be called only when the lock is held */
 static struct sfc_mae_switch_port *
 sfc_mae_find_switch_port_by_entity(const struct sfc_mae_switch_domain *domain,
diff --git a/drivers/net/sfc/sfc_switch.h b/drivers/net/sfc/sfc_switch.h
index a072507375..294baae9a2 100644
--- a/drivers/net/sfc/sfc_switch.h
+++ b/drivers/net/sfc/sfc_switch.h
@@ -63,6 +63,10 @@  int sfc_mae_switch_domain_map_controllers(uint16_t switch_domain_id,
 					  efx_pcie_interface_t *controllers,
 					  size_t nb_controllers);
 
+int sfc_mae_switch_domain_get_controller(uint16_t switch_domain_id,
+				   efx_pcie_interface_t intf,
+				   int *controller);
+
 int sfc_mae_assign_switch_port(uint16_t switch_domain_id,
 			       const struct sfc_mae_switch_port_request *req,
 			       uint16_t *switch_port_id);