eal: query multi-vector interrupt capability
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_interrupts.c
index a4b9506..95beb4c 100644 (file)
@@ -45,6 +45,7 @@
 #include <sys/signalfd.h>
 #include <sys/ioctl.h>
 #include <sys/eventfd.h>
+#include <assert.h>
 
 #include <rte_common.h>
 #include <rte_interrupts.h>
@@ -301,8 +302,10 @@ vfio_enable_msix(struct rte_intr_handle *intr_handle) {
        irq_set->index = VFIO_PCI_MSIX_IRQ_INDEX;
        irq_set->start = 0;
        fd_ptr = (int *) &irq_set->data;
-       memcpy(fd_ptr, intr_handle->efds, sizeof(intr_handle->efds));
-       fd_ptr[intr_handle->max_intr - 1] = intr_handle->fd;
+       /* INTR vector offset 0 reserve for non-efds mapping */
+       fd_ptr[RTE_INTR_VEC_ZERO_OFFSET] = intr_handle->fd;
+       memcpy(&fd_ptr[RTE_INTR_VEC_RXTX_OFFSET], intr_handle->efds,
+               sizeof(*intr_handle->efds) * intr_handle->nb_efd);
 
        ret = ioctl(intr_handle->vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
 
@@ -1083,10 +1086,14 @@ rte_intr_rx_ctl(struct rte_intr_handle *intr_handle, int epfd,
        struct rte_epoll_event *rev;
        struct rte_epoll_data *epdata;
        int epfd_op;
+       unsigned int efd_idx;
        int rc = 0;
 
+       efd_idx = (vec >= RTE_INTR_VEC_RXTX_OFFSET) ?
+               (vec - RTE_INTR_VEC_RXTX_OFFSET) : vec;
+
        if (!intr_handle || intr_handle->nb_efd == 0 ||
-           vec >= intr_handle->nb_efd) {
+           efd_idx >= intr_handle->nb_efd) {
                RTE_LOG(ERR, EAL, "Wrong intr vector number.\n");
                return -EPERM;
        }
@@ -1094,7 +1101,7 @@ rte_intr_rx_ctl(struct rte_intr_handle *intr_handle, int epfd,
        switch (op) {
        case RTE_INTR_EVENT_ADD:
                epfd_op = EPOLL_CTL_ADD;
-               rev = &intr_handle->elist[vec];
+               rev = &intr_handle->elist[efd_idx];
                if (rev->status != RTE_EPOLL_INVALID) {
                        RTE_LOG(INFO, EAL, "Event already been added.\n");
                        return -EEXIST;
@@ -1106,7 +1113,8 @@ rte_intr_rx_ctl(struct rte_intr_handle *intr_handle, int epfd,
                epdata->data   = data;
                epdata->cb_fun = (rte_intr_event_cb_t)eal_intr_proc_rxtx_intr;
                epdata->cb_arg = (void *)intr_handle;
-               rc = rte_epoll_ctl(epfd, epfd_op, intr_handle->efds[vec], rev);
+               rc = rte_epoll_ctl(epfd, epfd_op,
+                                  intr_handle->efds[efd_idx], rev);
                if (!rc)
                        RTE_LOG(DEBUG, EAL,
                                "efd %d associated with vec %d added on epfd %d"
@@ -1116,7 +1124,7 @@ rte_intr_rx_ctl(struct rte_intr_handle *intr_handle, int epfd,
                break;
        case RTE_INTR_EVENT_DEL:
                epfd_op = EPOLL_CTL_DEL;
-               rev = &intr_handle->elist[vec];
+               rev = &intr_handle->elist[efd_idx];
                if (rev->status == RTE_EPOLL_INVALID) {
                        RTE_LOG(INFO, EAL, "Event does not exist.\n");
                        return -EPERM;
@@ -1141,6 +1149,8 @@ rte_intr_efd_enable(struct rte_intr_handle *intr_handle, uint32_t nb_efd)
        int fd;
        uint32_t n = RTE_MIN(nb_efd, (uint32_t)RTE_MAX_RXTX_INTR_VEC_ID);
 
+       assert(nb_efd != 0);
+
        if (intr_handle->type == RTE_INTR_HANDLE_VFIO_MSIX) {
                for (i = 0; i < n; i++) {
                        fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
@@ -1197,5 +1207,17 @@ rte_intr_dp_is_en(struct rte_intr_handle *intr_handle)
 int
 rte_intr_allow_others(struct rte_intr_handle *intr_handle)
 {
-       return !!(intr_handle->max_intr - intr_handle->nb_efd);
+       if (!rte_intr_dp_is_en(intr_handle))
+               return 1;
+       else
+               return !!(intr_handle->max_intr - intr_handle->nb_efd);
+}
+
+int
+rte_intr_cap_multiple(struct rte_intr_handle *intr_handle)
+{
+       if (intr_handle->type == RTE_INTR_HANDLE_VFIO_MSIX)
+               return 1;
+
+       return 0;
 }