bus/dpaa: fix port order shuffling
authorShreyansh Jain <shreyansh.jain@nxp.com>
Tue, 23 Jan 2018 12:27:04 +0000 (17:57 +0530)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 31 Jan 2018 12:44:48 +0000 (13:44 +0100)
While scanning for devices, the order in which devices appear is
different as compared to MAC sequence.
This can cause confusion for users and automated scripts.
This patch create a sorted list of devices.

Fixes: 919eeaccb2ba ("bus/dpaa: introduce NXP DPAA bus driver skeleton")
Cc: stable@dpdk.org
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
drivers/bus/dpaa/dpaa_bus.c

index 41ee640..9baeac8 100644 (file)
@@ -58,10 +58,58 @@ unsigned int dpaa_svr_family;
 RTE_DEFINE_PER_LCORE(bool, _dpaa_io);
 RTE_DEFINE_PER_LCORE(struct dpaa_portal_dqrr, held_bufs);
 
+static int
+compare_dpaa_devices(struct rte_dpaa_device *dev1,
+                    struct rte_dpaa_device *dev2)
+{
+       int comp = 0;
+
+       /* Segragating ETH from SEC devices */
+       if (dev1->device_type > dev2->device_type)
+               comp = 1;
+       else if (dev1->device_type < dev2->device_type)
+               comp = -1;
+       else
+               comp = 0;
+
+       if ((comp != 0) || (dev1->device_type != FSL_DPAA_ETH))
+               return comp;
+
+       if (dev1->id.fman_id > dev2->id.fman_id) {
+               comp = 1;
+       } else if (dev1->id.fman_id < dev2->id.fman_id) {
+               comp = -1;
+       } else {
+               /* FMAN ids match, check for mac_id */
+               if (dev1->id.mac_id > dev2->id.mac_id)
+                       comp = 1;
+               else if (dev1->id.mac_id < dev2->id.mac_id)
+                       comp = -1;
+               else
+                       comp = 0;
+       }
+
+       return comp;
+}
+
 static inline void
-dpaa_add_to_device_list(struct rte_dpaa_device *dev)
+dpaa_add_to_device_list(struct rte_dpaa_device *newdev)
 {
-       TAILQ_INSERT_TAIL(&rte_dpaa_bus.device_list, dev, next);
+       int comp, inserted = 0;
+       struct rte_dpaa_device *dev = NULL;
+       struct rte_dpaa_device *tdev = NULL;
+
+       TAILQ_FOREACH_SAFE(dev, &rte_dpaa_bus.device_list, next, tdev) {
+               comp = compare_dpaa_devices(newdev, dev);
+               if (comp < 0) {
+                       TAILQ_INSERT_BEFORE(dev, newdev, next);
+                       inserted = 1;
+                       break;
+               }
+       }
+
+       if (!inserted)
+               TAILQ_INSERT_TAIL(&rte_dpaa_bus.device_list, newdev, next);
 }
 
 /*