bus/fslmc: add devices in sorted order
authorShreyansh Jain <shreyansh.jain@nxp.com>
Sat, 16 Sep 2017 10:52:41 +0000 (16:22 +0530)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 6 Oct 2017 01:26:58 +0000 (03:26 +0200)
Before this patch, the devices discovered from VFIO layer were
being added in the device list in the order received from directory
scan. This causes an issue in case devices are reordered.

This patch makes all the devices inserted in the device list in
sorted order according to their name.

Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
drivers/bus/fslmc/fslmc_bus.c

index d50c303..0a8229f 100644 (file)
@@ -65,6 +65,49 @@ cleanup_fslmc_device_list(void)
        }
 }
 
+static int
+compare_dpaa2_devname(struct rte_dpaa2_device *dev1,
+                     struct rte_dpaa2_device *dev2)
+{
+       int comp;
+
+       if (dev1->dev_type > dev2->dev_type) {
+               comp = 1;
+       } else if (dev1->dev_type < dev2->dev_type) {
+               comp = -1;
+       } else {
+               /* Check the ID as types match */
+               if (dev1->object_id > dev2->object_id)
+                       comp = 1;
+               else if (dev1->object_id < dev2->object_id)
+                       comp = -1;
+               else
+                       comp = 0; /* Duplicate device name */
+       }
+
+       return comp;
+}
+
+static void
+insert_in_device_list(struct rte_dpaa2_device *newdev)
+{
+       int comp, inserted = 0;
+       struct rte_dpaa2_device *dev = NULL;
+       struct rte_dpaa2_device *tdev = NULL;
+
+       TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, tdev) {
+               comp = compare_dpaa2_devname(newdev, dev);
+               if (comp < 0) {
+                       TAILQ_INSERT_BEFORE(dev, newdev, next);
+                       inserted = 1;
+                       break;
+               }
+       }
+
+       if (!inserted)
+               TAILQ_INSERT_TAIL(&rte_fslmc_bus.device_list, newdev, next);
+}
+
 static int
 scan_one_fslmc_device(char *dev_name)
 {
@@ -135,7 +178,7 @@ scan_one_fslmc_device(char *dev_name)
        }
 
        /* Add device in the fslmc device list */
-       TAILQ_INSERT_TAIL(&rte_fslmc_bus.device_list, dev, next);
+       insert_in_device_list(dev);
 
        /* Don't need the duplicated device filesystem entry anymore */
        if (dup_dev_name)