bus/dpaa: check portal presence in the caller function
[dpdk.git] / drivers / bus / dpaa / dpaa_bus.c
index 41ee640..1946bbe 100644 (file)
@@ -55,13 +55,61 @@ pthread_key_t dpaa_portal_key;
 
 unsigned int dpaa_svr_family;
 
-RTE_DEFINE_PER_LCORE(bool, _dpaa_io);
+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);
 }
 
 /*
@@ -177,9 +225,7 @@ dpaa_clean_device_list(void)
        }
 }
 
-/** XXX move this function into a separate file */
-static int
-_dpaa_portal_init(void *arg)
+int rte_dpaa_portal_init(void *arg)
 {
        cpu_set_t cpuset;
        pthread_t id;
@@ -250,25 +296,13 @@ _dpaa_portal_init(void *arg)
                return ret;
        }
 
-       RTE_PER_LCORE(_dpaa_io) = true;
+       RTE_PER_LCORE(dpaa_io) = true;
 
        DPAA_BUS_LOG(DEBUG, "QMAN thread initialized");
 
        return 0;
 }
 
-/*
- * rte_dpaa_portal_init - Wrapper over _dpaa_portal_init with thread level check
- * XXX Complete this
- */
-int rte_dpaa_portal_init(void *arg)
-{
-       if (unlikely(!RTE_PER_LCORE(_dpaa_io)))
-               return _dpaa_portal_init(arg);
-
-       return 0;
-}
-
 int
 rte_dpaa_portal_fq_init(void *arg, struct qman_fq *fq)
 {
@@ -276,8 +310,8 @@ rte_dpaa_portal_fq_init(void *arg, struct qman_fq *fq)
        u32 sdqcr;
        struct qman_portal *qp;
 
-       if (unlikely(!RTE_PER_LCORE(_dpaa_io)))
-               _dpaa_portal_init(arg);
+       if (unlikely(!RTE_PER_LCORE(dpaa_io)))
+               rte_dpaa_portal_init(arg);
 
        /* Initialise qman specific portals */
        qp = fsl_qman_portal_create();
@@ -315,7 +349,7 @@ dpaa_portal_finish(void *arg)
        rte_free(dpaa_io_portal);
        dpaa_io_portal = NULL;
 
-       RTE_PER_LCORE(_dpaa_io) = false;
+       RTE_PER_LCORE(dpaa_io) = false;
 }
 
 #define DPAA_DEV_PATH1 "/sys/devices/platform/soc/soc:fsl,dpaa"