From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id DA0723777 for ; Thu, 29 Dec 2016 08:30:11 +0100 (CET) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP; 28 Dec 2016 23:30:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,425,1477983600"; d="scan'208";a="44228332" Received: from dpdk06.sh.intel.com ([10.239.129.195]) by orsmga004.jf.intel.com with ESMTP; 28 Dec 2016 23:30:10 -0800 From: Jianfeng Tan To: dev@dpdk.org Cc: yuanhan.liu@linux.intel.com, stephen@networkplumber.org, Jianfeng Tan Date: Thu, 29 Dec 2016 07:30:39 +0000 Message-Id: <1482996643-113253-6-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482996643-113253-1-git-send-email-jianfeng.tan@intel.com> References: <1480810702-114815-1-git-send-email-jianfeng.tan@intel.com> <1482996643-113253-1-git-send-email-jianfeng.tan@intel.com> Subject: [dpdk-dev] [PATCH v2 5/9] net/virtio: setup rxq interrupts X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Dec 2016 07:30:12 -0000 This patch mainly allocates structure to store queue/irq mapping, and configure queue/irq mapping down through PCI ops. It also creates eventfds for each Rx queue and tell the kernel about the eventfd/intr binding. Mostly importantly, different from previous NICs (usually implements these logic in dev_start()), virtio's interrupt settings should be configured down to QEMU before sending DRIVER_OK notification. Note: We only support 1:1 queue/irq mapping so far, which means, each rx queue has one exclusive interrupt (corresponding to irqfd in the qemu/kvm) to get notified when packets are available on that queue. Signed-off-by: Jianfeng Tan --- drivers/net/virtio/virtio_ethdev.c | 89 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 3f8b90c..082346b 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -1206,6 +1206,76 @@ rx_func_get(struct rte_eth_dev *eth_dev) eth_dev->rx_pkt_burst = &virtio_recv_pkts; } +/* Only support 1:1 queue/interrupt mapping so far. + * TODO: under below cases, lsc and rxq interrupt share one interrupt. + * a) binded to uio, igb_uio, vfio (type1); + * b) device only has one vec, see _vectors_ option in -device virtio-net-pci. + * TODO: support n:1 queue/interrupt mapping. + */ +static int +virtio_queues_bind_intr(struct rte_eth_dev *dev) +{ + uint32_t i; + struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle; + struct virtio_hw *hw = dev->data->dev_private; + + PMD_INIT_LOG(INFO, "queue/interrupt binding\n"); + for (i = 0; i < dev->data->nb_rx_queues; ++i) { + intr_handle->intr_vec[i] = i + 1; + if (vtpci_irq_queue(hw->vqs[i * VTNET_CQ], i + 1) == + VIRTIO_MSI_NO_VECTOR) { + PMD_DRV_LOG(ERR, "failed to set queue vector"); + return -EBUSY; + } + } + + return 0; +} + +static int +virtio_configure_intr(struct rte_eth_dev *dev) +{ + uint32_t intr_vector; + struct rte_intr_handle *intr_handle = &dev->pci_dev->intr_handle; + + /* check if rxq interrupt is enabled */ + if (!rte_intr_cap_multiple(intr_handle)) { + PMD_INIT_LOG(ERR, "Multiple intr vector not supported"); + return -ENOTSUP; + } + + intr_vector = dev->data->nb_rx_queues; + if (rte_intr_efd_enable(intr_handle, intr_vector)) { + PMD_INIT_LOG(ERR, "Fail to create eventfd"); + return -1; + } + + if (!intr_handle->intr_vec) { + intr_handle->intr_vec = + rte_zmalloc("intr_vec", intr_vector * sizeof(int), 0); + if (!intr_handle->intr_vec) { + PMD_INIT_LOG(ERR, "Failed to allocate %d rxq vectors", + intr_vector); + return -ENOMEM; + } + } + + if (virtio_queues_bind_intr(dev) < 0) { + PMD_INIT_LOG(ERR, "Failed to bind queue/interrupt"); + return -1; + } + + /* DO NOT try remove this! This function will enable msix, or QEMU + * will encounter SIGSEGV. + */ + if (rte_intr_enable(intr_handle) < 0) { + PMD_DRV_LOG(ERR, "interrupt enable failed"); + return -1; + } + + return 0; +} + /* reset device and renegotiate features if needed */ static int virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features) @@ -1299,6 +1369,17 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features) ret = virtio_alloc_queues(eth_dev); if (ret < 0) return ret; + + /* Make sure rxq interrupt is configured before sending DRIVER_OK, + * so that QEMU can properly set those irq into kvm. + */ + if (eth_dev->data->dev_conf.intr_conf.rxq) { + if (virtio_configure_intr(eth_dev) < 0) { + PMD_INIT_LOG(ERR, "failed to configure interrupt"); + return -1; + } + } + vtpci_reinit_complete(hw); if (pci_dev) @@ -1503,7 +1584,15 @@ virtio_dev_start(struct rte_eth_dev *dev) PMD_DRV_LOG(ERR, "link status not supported by host"); return -ENOTSUP; } + } + /* Enable uio/vfio intr/eventfd mapping: althrough we already did that + * in device configure, but it could be unmapped when device is + * stopped. + */ + if (dev->data->dev_conf.intr_conf.lsc || + dev->data->dev_conf.intr_conf.rxq) { + rte_intr_disable(&dev->pci_dev->intr_handle); if (rte_intr_enable(&dev->pci_dev->intr_handle) < 0) { PMD_DRV_LOG(ERR, "interrupt enable failed"); return -EIO; -- 2.7.4