From mboxrd@z Thu Jan 1 00:00:00 1970 From: Danny Zhou Subject: [PATCH v1 2/3] eal: add interrupt enable/disable routines for uio_pci_generic Date: Thu, 29 Jan 2015 17:28:18 +0800 Message-ID: <1422523699-17181-3-git-send-email-danny.zhou@intel.com> References: <1422523699-17181-1-git-send-email-danny.zhou@intel.com> To: dev-VfR2kkLFssw@public.gmane.org Return-path: In-Reply-To: <1422523699-17181-1-git-send-email-danny.zhou-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" enable/disable interrupt by manipulating enable/disable bit of command register on NIC's PCIe configuration space. Signed-off-by: Danny Zhou Tested-by: Qun Wan --- lib/librte_eal/linuxapp/eal/eal_interrupts.c | 68 +++++++++++++++++++++------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/lib/librte_eal/linuxapp/eal/eal_interrupts.c b/lib/librte_eal/linuxapp/eal/eal_interrupts.c index dc2668a..8c5b834 100644 --- a/lib/librte_eal/linuxapp/eal/eal_interrupts.c +++ b/lib/librte_eal/linuxapp/eal/eal_interrupts.c @@ -361,6 +361,54 @@ vfio_disable_msix(struct rte_intr_handle *intr_handle) { } #endif +static int +uio_intr_disable(struct rte_intr_handle *intr_handle) +{ + unsigned char command_high; + + /* use UIO config file descriptor for uio_pci_generic */ + if (pread(intr_handle->uio_cfg_fd, &command_high, 1, 5) != 1) { + RTE_LOG(ERR, EAL, + "Error reading interrupts status for fd %d\n", + intr_handle->uio_cfg_fd); + return -1; + } + /* disable interrupts */ + command_high |= 0x4; + if (pwrite(intr_handle->uio_cfg_fd, &command_high, 1, 5) != 1) { + RTE_LOG(ERR, EAL, + "Error disabling interrupts for fd %d\n", + intr_handle->uio_cfg_fd); + return -1; + } + + return 0; +} + +static int +uio_intr_enable(struct rte_intr_handle *intr_handle) +{ + unsigned char command_high; + + /* use UIO config file descriptor for uio_pci_generic */ + if (pread(intr_handle->uio_cfg_fd, &command_high, 1, 5) != 1) { + RTE_LOG(ERR, EAL, + "Error reading interrupts status for fd %d\n", + intr_handle->uio_cfg_fd); + return -1; + } + /* enable interrupts */ + command_high &= ~0x4; + if (pwrite(intr_handle->uio_cfg_fd, &command_high, 1, 5) != 1) { + RTE_LOG(ERR, EAL, + "Error enabling interrupts for fd %d\n", + intr_handle->uio_cfg_fd); + return -1; + } + + return 0; +} + int rte_intr_callback_register(struct rte_intr_handle *intr_handle, rte_intr_callback_fn cb, void *cb_arg) @@ -500,20 +548,14 @@ rte_intr_callback_unregister(struct rte_intr_handle *intr_handle, int rte_intr_enable(struct rte_intr_handle *intr_handle) { - const int value = 1; - - if (!intr_handle || intr_handle->fd < 0) + if (!intr_handle || intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0) return -1; switch (intr_handle->type){ /* write to the uio fd to enable the interrupt */ case RTE_INTR_HANDLE_UIO: - if (write(intr_handle->fd, &value, sizeof(value)) < 0) { - RTE_LOG(ERR, EAL, - "Error enabling interrupts for fd %d\n", - intr_handle->fd); + if (uio_intr_enable(intr_handle)) return -1; - } break; /* not used at this moment */ case RTE_INTR_HANDLE_ALARM: @@ -546,20 +588,14 @@ rte_intr_enable(struct rte_intr_handle *intr_handle) int rte_intr_disable(struct rte_intr_handle *intr_handle) { - const int value = 0; - - if (!intr_handle || intr_handle->fd < 0) + if (!intr_handle || intr_handle->fd < 0 || intr_handle->uio_cfg_fd < 0) return -1; switch (intr_handle->type){ /* write to the uio fd to disable the interrupt */ case RTE_INTR_HANDLE_UIO: - if (write(intr_handle->fd, &value, sizeof(value)) < 0){ - RTE_LOG(ERR, EAL, - "Error disabling interrupts for fd %d\n", - intr_handle->fd); + if (uio_intr_disable(intr_handle)) return -1; - } break; /* not used at this moment */ case RTE_INTR_HANDLE_ALARM: -- 1.8.1.4