net/sfc: include controller and port in representor name
authorViacheslav Galaktionov <viacheslav.galaktionov@oktetlabs.ru>
Mon, 11 Oct 2021 14:48:53 +0000 (17:48 +0300)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 12 Oct 2021 16:44:11 +0000 (18:44 +0200)
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
drivers/net/sfc/sfc_switch.c
drivers/net/sfc/sfc_switch.h

index 04415d1..a9dab6f 100644 (file)
@@ -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;
        }
index 7a0b332..225d07f 100644 (file)
@@ -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,
index a072507..294baae 100644 (file)
@@ -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);