From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hemant Agrawal Subject: [PATCH v3 27/27] bus/fslmc: add devices in sorted order Date: Sat, 16 Sep 2017 16:22:41 +0530 Message-ID: <1505559161-29222-28-git-send-email-hemant.agrawal@nxp.com> References: <1504860327-18451-1-git-send-email-hemant.agrawal@nxp.com> <1505559161-29222-1-git-send-email-hemant.agrawal@nxp.com> Mime-Version: 1.0 Content-Type: text/plain Cc: , To: Return-path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0083.outbound.protection.outlook.com [104.47.34.83]) by dpdk.org (Postfix) with ESMTP id 6D52B1B1A9 for ; Sat, 16 Sep 2017 12:54:01 +0200 (CEST) In-Reply-To: <1505559161-29222-1-git-send-email-hemant.agrawal@nxp.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Shreyansh Jain 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 --- drivers/bus/fslmc/fslmc_bus.c | 45 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index d50c303..0a8229f 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -66,6 +66,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) { char *dup_dev_name, *t_ptr; @@ -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) -- 2.7.4