bus/dpaa: check portal presence in the caller function
[dpdk.git] / drivers / bus / dpaa / dpaa_bus.c
index 78d60be..1946bbe 100644 (file)
 #include <rte_eal.h>
 #include <rte_alarm.h>
 #include <rte_ether.h>
-#include <rte_ethdev.h>
+#include <rte_ethdev_driver.h>
 #include <rte_malloc.h>
 #include <rte_ring.h>
 #include <rte_bus.h>
+#include <rte_mbuf_pool_ops.h>
 
 #include <rte_dpaa_bus.h>
 #include <rte_dpaa_logs.h>
@@ -44,6 +45,7 @@
 int dpaa_logtype_bus;
 int dpaa_logtype_mempool;
 int dpaa_logtype_pmd;
+int dpaa_logtype_eventdev;
 
 struct rte_dpaa_bus rte_dpaa_bus;
 struct netcfg_info *dpaa_netcfg;
@@ -53,19 +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 inline void
-dpaa_add_to_device_list(struct rte_dpaa_device *dev)
+static int
+compare_dpaa_devices(struct rte_dpaa_device *dev1,
+                    struct rte_dpaa_device *dev2)
 {
-       TAILQ_INSERT_TAIL(&rte_dpaa_bus.device_list, dev, next);
+       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_remove_from_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);
 }
 
 /*
@@ -181,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;
@@ -254,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)
 {
@@ -280,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();
@@ -319,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"
@@ -468,6 +498,7 @@ rte_dpaa_bus_probe(void)
                        break;
                }
        }
+       rte_mbuf_set_platform_mempool_ops(DPAA_MEMPOOL_OPS_NAME);
 
        svr_file = fopen(DPAA_SOC_ID_FILE, "r");
        if (svr_file) {
@@ -536,4 +567,8 @@ dpaa_init_log(void)
        dpaa_logtype_pmd = rte_log_register("pmd.dpaa");
        if (dpaa_logtype_pmd >= 0)
                rte_log_set_level(dpaa_logtype_pmd, RTE_LOG_NOTICE);
+
+       dpaa_logtype_eventdev = rte_log_register("eventdev.dpaa");
+       if (dpaa_logtype_eventdev >= 0)
+               rte_log_set_level(dpaa_logtype_eventdev, RTE_LOG_NOTICE);
 }