From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 1F53CB7A9 for ; Fri, 20 Feb 2015 17:59:21 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP; 20 Feb 2015 08:51:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,615,1418112000"; d="scan'208";a="654893536" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 20 Feb 2015 08:59:20 -0800 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t1KGxIjB031945; Fri, 20 Feb 2015 16:59:18 GMT Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id t1KGxHAb027469; Fri, 20 Feb 2015 16:59:17 GMT Received: (from bricha3@localhost) by sivswdev01.ir.intel.com with id t1KGxHHW027465; Fri, 20 Feb 2015 16:59:17 GMT From: Bruce Richardson To: dev@dpdk.org Date: Fri, 20 Feb 2015 16:59:16 +0000 Message-Id: <1424451557-27419-3-git-send-email-bruce.richardson@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1424451557-27419-1-git-send-email-bruce.richardson@intel.com> References: <1424365731-32228-1-git-send-email-danny.zhou@intel.com> <1424451557-27419-1-git-send-email-bruce.richardson@intel.com> Subject: [dpdk-dev] [PATCH v3 2/3] eal: add interrupt enable/disable routines for uio_pci_generic X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Feb 2015 16:59:22 -0000 From: Zhou Danny enable/disable interrupt by manipulating a control bit of command register on NIC's PCIe configuration space. Signed-off-by: Danny Zhou Tested-by: Qun Wan Signed-off-by: Bruce Richardson --- 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: -- 2.1.0