drivers: remove direct access to interrupt handle
[dpdk.git] / drivers / bus / fslmc / portal / dpaa2_hw_dpio.c
index 1a9dd18..2210a0f 100644 (file)
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
-#include <sys/syscall.h>
 #include <sys/epoll.h>
-#include<sys/eventfd.h>
+#include <sys/eventfd.h>
+#include <sys/syscall.h>
 
 #include <rte_mbuf.h>
-#include <rte_ethdev_driver.h>
+#include <ethdev_driver.h>
 #include <rte_malloc.h>
 #include <rte_memcpy.h>
 #include <rte_string_fns.h>
@@ -169,14 +169,14 @@ dpaa2_affine_dpio_intr_to_respective_core(int32_t dpio_id, int cpu_id)
        fclose(file);
 }
 
-static int dpaa2_dpio_intr_init(struct dpaa2_dpio_dev *dpio_dev, int cpu_id)
+static int dpaa2_dpio_intr_init(struct dpaa2_dpio_dev *dpio_dev)
 {
        struct epoll_event epoll_ev;
        int eventfd, dpio_epoll_fd, ret;
        int threshold = 0x3, timeout = 0xFF;
 
        dpio_epoll_fd = epoll_create(1);
-       ret = rte_dpaa2_intr_enable(&dpio_dev->intr_handle, 0);
+       ret = rte_dpaa2_intr_enable(dpio_dev->intr_handle, 0);
        if (ret) {
                DPAA2_BUS_ERR("Interrupt registeration failed");
                return -1;
@@ -195,7 +195,7 @@ static int dpaa2_dpio_intr_init(struct dpaa2_dpio_dev *dpio_dev, int cpu_id)
        qbman_swp_dqrr_thrshld_write(dpio_dev->sw_portal, threshold);
        qbman_swp_intr_timeout_write(dpio_dev->sw_portal, timeout);
 
-       eventfd = dpio_dev->intr_handle.fd;
+       eventfd = rte_intr_fd_get(dpio_dev->intr_handle);
        epoll_ev.events = EPOLLIN | EPOLLPRI | EPOLLET;
        epoll_ev.data.fd = eventfd;
 
@@ -206,8 +206,6 @@ static int dpaa2_dpio_intr_init(struct dpaa2_dpio_dev *dpio_dev, int cpu_id)
        }
        dpio_dev->epoll_fd = dpio_epoll_fd;
 
-       dpaa2_affine_dpio_intr_to_respective_core(dpio_dev->hw_id, cpu_id);
-
        return 0;
 }
 
@@ -215,7 +213,7 @@ static void dpaa2_dpio_intr_deinit(struct dpaa2_dpio_dev *dpio_dev)
 {
        int ret;
 
-       ret = rte_dpaa2_intr_disable(&dpio_dev->intr_handle, 0);
+       ret = rte_dpaa2_intr_disable(dpio_dev->intr_handle, 0);
        if (ret)
                DPAA2_BUS_ERR("DPIO interrupt disable failed");
 
@@ -243,10 +241,11 @@ dpaa2_configure_stashing(struct dpaa2_dpio_dev *dpio_dev, int cpu_id)
        }
 
 #ifdef RTE_EVENT_DPAA2
-       if (dpaa2_dpio_intr_init(dpio_dev, cpu_id)) {
+       if (dpaa2_dpio_intr_init(dpio_dev)) {
                DPAA2_BUS_ERR("Interrupt registration failed for dpio");
                return -1;
        }
+       dpaa2_affine_dpio_intr_to_respective_core(dpio_dev->hw_id, cpu_id);
 #endif
 
        return 0;
@@ -278,8 +277,8 @@ static struct dpaa2_dpio_dev *dpaa2_get_qbman_swp(void)
                return NULL;
        }
 
-       DPAA2_BUS_DEBUG("New Portal %p (%d) affined thread - %lu",
-                       dpio_dev, dpio_dev->index, syscall(SYS_gettid));
+       DPAA2_BUS_DEBUG("New Portal %p (%d) affined thread - %u",
+                       dpio_dev, dpio_dev->index, rte_gettid());
 
        /* Set the Stashing Destination */
        cpu_id = dpaa2_get_core_id();
@@ -310,7 +309,7 @@ int
 dpaa2_affine_qbman_swp(void)
 {
        struct dpaa2_dpio_dev *dpio_dev;
-       uint64_t tid = syscall(SYS_gettid);
+       uint64_t tid = rte_gettid();
 
        /* Populate the dpaa2_io_portal structure */
        if (!RTE_PER_LCORE(_dpaa2_io).dpio_dev) {
@@ -332,7 +331,7 @@ int
 dpaa2_affine_qbman_ethrx_swp(void)
 {
        struct dpaa2_dpio_dev *dpio_dev;
-       uint64_t tid = syscall(SYS_gettid);
+       uint64_t tid = rte_gettid();
 
        /* Populate the dpaa2_io_portal structure */
        if (!RTE_PER_LCORE(_dpaa2_io).ethrx_dpio_dev) {
@@ -389,6 +388,14 @@ dpaa2_create_dpio_device(int vdev_fd,
        /* Using single portal  for all devices */
        dpio_dev->mc_portal = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
 
+       /* Allocate interrupt instance */
+       dpio_dev->intr_handle =
+               rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_SHARED);
+       if (!dpio_dev->intr_handle) {
+               DPAA2_BUS_ERR("Failed to allocate intr handle");
+               goto err;
+       }
+
        dpio_dev->dpio = rte_zmalloc(NULL, sizeof(struct fsl_mc_io),
                                     RTE_CACHE_LINE_SIZE);
        if (!dpio_dev->dpio) {
@@ -491,7 +498,7 @@ dpaa2_create_dpio_device(int vdev_fd,
        io_space_count++;
        dpio_dev->index = io_space_count;
 
-       if (rte_dpaa2_vfio_setup_intr(&dpio_dev->intr_handle, vdev_fd, 1)) {
+       if (rte_dpaa2_vfio_setup_intr(dpio_dev->intr_handle, vdev_fd, 1)) {
                DPAA2_BUS_ERR("Fail to setup interrupt for %d",
                              dpio_dev->hw_id);
                goto err;
@@ -539,6 +546,7 @@ err:
                rte_free(dpio_dev->dpio);
        }
 
+       rte_intr_instance_free(dpio_dev->intr_handle);
        rte_free(dpio_dev);
 
        /* For each element in the list, cleanup */
@@ -550,6 +558,7 @@ err:
                                dpio_dev->token);
                        rte_free(dpio_dev->dpio);
                }
+               rte_intr_instance_free(dpio_dev->intr_handle);
                rte_free(dpio_dev);
        }