bus/fslmc: fix the failure loop condition
[dpdk.git] / drivers / bus / fslmc / portal / dpaa2_hw_dpio.c
index a1a58b9..4c4e918 100644 (file)
 #include <fslmc_vfio.h>
 #include "dpaa2_hw_pvt.h"
 #include "dpaa2_hw_dpio.h"
+#include <mc/fsl_dpmng.h>
 
 #define NUM_HOST_CPUS RTE_MAX_LCORE
 
 struct dpaa2_io_portal_t dpaa2_io_portal[RTE_MAX_LCORE];
 RTE_DEFINE_PER_LCORE(struct dpaa2_io_portal_t, _dpaa2_io);
 
-TAILQ_HEAD(dpio_device_list, dpaa2_dpio_dev);
-static struct dpio_device_list *dpio_dev_list; /*!< DPIO device list */
+struct swp_active_dqs rte_global_active_dqs_list[NUM_MAX_SWP];
+
+TAILQ_HEAD(dpio_dev_list, dpaa2_dpio_dev);
+static struct dpio_dev_list dpio_dev_list
+       = TAILQ_HEAD_INITIALIZER(dpio_dev_list); /*!< DPIO device list */
 static uint32_t io_space_count;
 
 /*Stashing Macros default for LS208x*/
@@ -147,8 +151,6 @@ configure_dpio_qbman_swp(struct dpaa2_dpio_dev *dpio_dev)
        }
 
        PMD_INIT_LOG(DEBUG, "Qbman Portal ID %d", attr.qbman_portal_id);
-       PMD_INIT_LOG(DEBUG, "Portal CE adr 0x%lX", attr.qbman_portal_ce_offset);
-       PMD_INIT_LOG(DEBUG, "Portal CI adr 0x%lX", attr.qbman_portal_ci_offset);
 
        /* Configure & setup SW portal */
        p_des.block = NULL;
@@ -166,8 +168,6 @@ configure_dpio_qbman_swp(struct dpaa2_dpio_dev *dpio_dev)
                return -1;
        }
 
-       PMD_INIT_LOG(DEBUG, "QBMan SW Portal 0x%p\n", dpio_dev->sw_portal);
-
        return 0;
 }
 
@@ -176,6 +176,22 @@ dpaa2_configure_stashing(struct dpaa2_dpio_dev *dpio_dev)
 {
        int sdest;
        int cpu_id, ret;
+       static int first_time;
+
+       /* find the SoC type for the first time */
+       if (!first_time) {
+               struct mc_soc_version mc_plat_info = {0};
+
+               if (mc_get_soc_version(dpio_dev->dpio,
+                                      CMD_PRI_LOW, &mc_plat_info)) {
+                       PMD_INIT_LOG(ERR, "\tmc_get_soc_version failed\n");
+               } else if ((mc_plat_info.svr & 0xffff0000) == SVR_LS1080A) {
+                       dpaa2_core_cluster_base = 0x02;
+                       dpaa2_cluster_sz = 4;
+                       PMD_INIT_LOG(DEBUG, "\tLS108x (A53) Platform Detected");
+               }
+               first_time = 1;
+       }
 
        /* Set the Stashing Destination */
        cpu_id = rte_lcore_id();
@@ -188,8 +204,6 @@ dpaa2_configure_stashing(struct dpaa2_dpio_dev *dpio_dev)
        }
        /* Set the STASH Destination depending on Current CPU ID.
         * Valid values of SDEST are 4,5,6,7. Where,
-        * CPU 0-1 will have SDEST 4
-        * CPU 2-3 will have SDEST 5.....and so on.
         */
 
        sdest = dpaa2_core_cluster_sdest(cpu_id);
@@ -212,7 +226,7 @@ static inline struct dpaa2_dpio_dev *dpaa2_get_qbman_swp(void)
        int ret;
 
        /* Get DPIO dev handle from list using index */
-       TAILQ_FOREACH(dpio_dev, dpio_dev_list, next) {
+       TAILQ_FOREACH(dpio_dev, &dpio_dev_list, next) {
                if (dpio_dev && rte_atomic16_test_and_set(&dpio_dev->ref_count))
                        break;
        }
@@ -334,24 +348,13 @@ dpaa2_create_dpio_device(struct fslmc_vfio_device *vdev,
                return -1;
        }
 
-       if (!dpio_dev_list) {
-               dpio_dev_list = malloc(sizeof(struct dpio_device_list));
-               if (!dpio_dev_list) {
-                       PMD_INIT_LOG(ERR, "Memory alloc failed in DPIO list\n");
-                       return -1;
-               }
-
-               /* Initialize the DPIO List */
-               TAILQ_INIT(dpio_dev_list);
-       }
-
-       dpio_dev = malloc(sizeof(struct dpaa2_dpio_dev));
+       dpio_dev = rte_malloc(NULL, sizeof(struct dpaa2_dpio_dev),
+                             RTE_CACHE_LINE_SIZE);
        if (!dpio_dev) {
                PMD_INIT_LOG(ERR, "Memory allocation failed for DPIO Device\n");
                return -1;
        }
 
-       PMD_DRV_LOG(INFO, "\t Aloocated DPIO [%p]", dpio_dev);
        dpio_dev->dpio = NULL;
        dpio_dev->hw_id = object_id;
        dpio_dev->vfio_fd = vdev->fd;
@@ -362,12 +365,10 @@ dpaa2_create_dpio_device(struct fslmc_vfio_device *vdev,
        reg_info.index = 0;
        if (ioctl(dpio_dev->vfio_fd, VFIO_DEVICE_GET_REGION_INFO, &reg_info)) {
                PMD_INIT_LOG(ERR, "vfio: error getting region info\n");
-               free(dpio_dev);
+               rte_free(dpio_dev);
                return -1;
        }
 
-       PMD_DRV_LOG(DEBUG, "\t  Region Offset = %llx", reg_info.offset);
-       PMD_DRV_LOG(DEBUG, "\t  Region Size = %llx", reg_info.size);
        dpio_dev->ce_size = reg_info.size;
        dpio_dev->qbman_portal_ce_paddr = (uint64_t)mmap(NULL, reg_info.size,
                                PROT_WRITE | PROT_READ, MAP_SHARED,
@@ -379,19 +380,17 @@ dpaa2_create_dpio_device(struct fslmc_vfio_device *vdev,
        if (vfio_dmamap_mem_region(dpio_dev->qbman_portal_ce_paddr,
                                   reg_info.offset, reg_info.size)) {
                PMD_INIT_LOG(ERR, "DMAMAP for Portal CE area failed.\n");
-               free(dpio_dev);
+               rte_free(dpio_dev);
                return -1;
        }
 
        reg_info.index = 1;
        if (ioctl(dpio_dev->vfio_fd, VFIO_DEVICE_GET_REGION_INFO, &reg_info)) {
                PMD_INIT_LOG(ERR, "vfio: error getting region info\n");
-               free(dpio_dev);
+               rte_free(dpio_dev);
                return -1;
        }
 
-       PMD_DRV_LOG(DEBUG, "\t  Region Offset = %llx", reg_info.offset);
-       PMD_DRV_LOG(DEBUG, "\t  Region Size = %llx", reg_info.size);
        dpio_dev->ci_size = reg_info.size;
        dpio_dev->qbman_portal_ci_paddr = (uint64_t)mmap(NULL, reg_info.size,
                                PROT_WRITE | PROT_READ, MAP_SHARED,
@@ -401,13 +400,14 @@ dpaa2_create_dpio_device(struct fslmc_vfio_device *vdev,
                PMD_INIT_LOG(ERR,
                             "Fail to configure the dpio qbman portal for %d\n",
                             dpio_dev->hw_id);
-               free(dpio_dev);
+               rte_free(dpio_dev);
                return -1;
        }
 
        io_space_count++;
        dpio_dev->index = io_space_count;
-       TAILQ_INSERT_HEAD(dpio_dev_list, dpio_dev, next);
+       TAILQ_INSERT_TAIL(&dpio_dev_list, dpio_dev, next);
+       PMD_INIT_LOG(DEBUG, "DPAA2: Added [dpio-%d]", object_id);
 
        return 0;
 }
@@ -437,8 +437,7 @@ dpaa2_alloc_dq_storage(struct queue_storage_info_t *q_storage)
        }
        return 0;
 fail:
-       i -= 1;
-       while (i >= 0)
+       while (--i >= 0)
                rte_free(q_storage->dq_storage[i]);
 
        return -1;