net/failsafe: use ownership mechanism for slaves
authorMatan Azrad <matan@mellanox.com>
Mon, 22 Jan 2018 16:38:22 +0000 (16:38 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 31 Jan 2018 19:49:42 +0000 (20:49 +0100)
Fail-safe PMD sub devices management is based on ethdev port mechanism.
So, the sub-devices management structures are exposed to other DPDK
entities which may use them in parallel to fail-safe PMD.

Use the new port ownership mechanism to avoid multiple managments of
fail-safe PMD sub-devices.

Signed-off-by: Matan Azrad <matan@mellanox.com>
Acked-by: Gaetan Rivet <gaetan.rivet@6wind.com>
drivers/net/failsafe/failsafe.c
drivers/net/failsafe/failsafe_eal.c
drivers/net/failsafe/failsafe_private.h

index 921e656..02e6035 100644 (file)
@@ -196,6 +196,13 @@ fs_eth_dev_create(struct rte_vdev_device *vdev)
        ret = failsafe_args_parse(dev, params);
        if (ret)
                goto free_subs;
+       ret = rte_eth_dev_owner_new(&priv->my_owner.id);
+       if (ret) {
+               ERROR("Failed to get unique owner identifier");
+               goto free_args;
+       }
+       snprintf(priv->my_owner.name, sizeof(priv->my_owner.name),
+                FAILSAFE_OWNER_NAME);
        ret = failsafe_eal_init(dev);
        if (ret)
                goto free_args;
index 33a5adf..3994661 100644 (file)
@@ -106,6 +106,22 @@ fs_bus_init(struct rte_eth_dev *dev)
                        INFO("Taking control of a probed sub device"
                              " %d named %s", i, da->name);
                }
+               ret = rte_eth_dev_owner_set(pid, &PRIV(dev)->my_owner);
+               if (ret) {
+                       INFO("sub_device %d owner set failed (%s),"
+                            " will try again later", i, strerror(ret));
+                       continue;
+               } else if (strncmp(rte_eth_devices[pid].device->name, da->name,
+                          strlen(da->name)) != 0) {
+                       /*
+                        * The device probably was removed and its port id was
+                        * reallocated before ownership set.
+                        */
+                       rte_eth_dev_owner_unset(pid, PRIV(dev)->my_owner.id);
+                       INFO("sub_device %d was probably removed before taking"
+                            " ownership, will try again later", i);
+                       continue;
+               }
                ETH(sdev) = &rte_eth_devices[pid];
                SUB_ID(sdev) = i;
                sdev->fs_dev = dev;
index 5d328ff..e23512c 100644 (file)
@@ -43,6 +43,7 @@
 #include <rte_interrupts.h>
 
 #define FAILSAFE_DRIVER_NAME "Fail-safe PMD"
+#define FAILSAFE_OWNER_NAME "Fail-safe"
 
 #define PMD_FAILSAFE_MAC_KVARG "mac"
 #define PMD_FAILSAFE_HOTPLUG_POLL_KVARG "hotplug_poll"
@@ -167,6 +168,7 @@ struct fs_priv {
        uint32_t mac_addr_pool[FAILSAFE_MAX_ETHADDR];
        /* current capabilities */
        struct rte_eth_dev_info infos;
+       struct rte_eth_dev_owner my_owner; /* Unique owner. */
        struct rte_intr_handle intr_handle; /* Port interrupt handle. */
        /*
         * Fail-safe state machine.