From c75d560db32b04b29472dc9d91e63ab39e8945b8 Mon Sep 17 00:00:00 2001 From: Viacheslav Galaktionov Date: Mon, 11 Oct 2021 17:48:53 +0300 Subject: [PATCH] net/sfc: include controller and port in representor name Make representor names unique on multi-host configurations. Signed-off-by: Viacheslav Galaktionov Signed-off-by: Andrew Rybchenko Reviewed-by: Andy Moreton --- 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 --git a/drivers/net/sfc/sfc_repr.c b/drivers/net/sfc/sfc_repr.c index 04415d1b79..a9dab6f28c 100644 --- a/drivers/net/sfc/sfc_repr.c +++ b/drivers/net/sfc/sfc_repr.c @@ -1028,11 +1028,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);