From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f182.google.com (mail-pf0-f182.google.com [209.85.192.182]) by dpdk.org (Postfix) with ESMTP id CF7482C72 for ; Wed, 9 Mar 2016 09:33:49 +0100 (CET) Received: by mail-pf0-f182.google.com with SMTP id 124so34910956pfg.0 for ; Wed, 09 Mar 2016 00:33:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=w29C0A9pn74RERUR7ewS3ag5exKlqh6igTGt9+RRJcw=; b=AMhVA76fZwCI4oBLIqdSElwihLYInZQPbN0DKM2SuEJIKpwX1qX3ctm7fwCSnEi1nV 1B2q+pdw5eQn5e6XkOl3KCrvy+5QAoaVm0J6THYUoH3a3z/j3Cse8zADs/u7RtaCYymj T/nH100LJajnhbJy9uIgH0yU1DHkBKoRcvTjVtfM60qPuMtcgWO5lek6Cq2K5TMTs1FQ lm9C+QB/3gWB57PfvpRaNTxweyW47QezjpgI8ZD3ssktQyYlcLOh6eAVcKEIN6gV+GYM TLjwrbdFYzVULWnCmr6u4S5aWQxKrdBINQ76At98sRKFUY/EaZgAAs1NJjVcxLmEDVjb iuMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=w29C0A9pn74RERUR7ewS3ag5exKlqh6igTGt9+RRJcw=; b=iiC/WnKor5TXZOdNWhKcBzKs0FjVbASo9Vqyi4vURoD/Bn3Sd75ANMmlCiaHolTlA8 LbjrMpxmdoafjL3HVc1H5/uTrbXRJLTZruBvCjpL/zPTaWonFRj12YgD3XIbaelcHXfL r5mYaflWbjUiLfXFkxr5IQmqQDb/wbBHQmtk04bBjnZAZYB10vmQDXWYE6/G6uIrqOvC RTIH0bEeljAWDLJXHAwDQyrj/Vz4/d+rP8dWb+QTGWXWhx6/LDSJmNfysCIGkZ3XWb8z vKXxC/0SKtivsU73sjQCFZ5SVUqPIBwsVhzQiN3DTVZvGY+nJhJKs21zAPZjFcM3ZfHY ImmA== X-Gm-Message-State: AD7BkJJDh+k6BmaF2+gYbL1Uu62A9+d0FhUeCQxgigdr5vcZu5Lh1DzhPIEU2gq0AcKUyA== X-Received: by 10.98.79.203 with SMTP id f72mr49135719pfj.102.1457512429245; Wed, 09 Mar 2016 00:33:49 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id qh8sm10350238pac.40.2016.03.09.00.33.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Mar 2016 00:33:48 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org, jianfeng.tan@intel.com, huawei.xie@intel.com, yuanhan.liu@linux.intel.com Date: Wed, 9 Mar 2016 17:33:19 +0900 Message-Id: <1457512409-24403-3-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1457512409-24403-1-git-send-email-mukawa@igel.co.jp> References: <1457512409-24403-1-git-send-email-mukawa@igel.co.jp> In-Reply-To: <1456129075-14909-4-git-send-email-mukawa@igel.co.jp> References: <1456129075-14909-4-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v4 02/12] vhost: Add a function to check virtio device type 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: Wed, 09 Mar 2016 08:33:50 -0000 The patch adds below function to cleanup virtio code. - virtio_dev_check() Signed-off-by: Tetsuya Mukawa --- drivers/net/virtio/virtio_ethdev.c | 52 ++++++++++++++++++-------------------- drivers/net/virtio/virtio_ethdev.h | 32 +++++++++++++++++++++++ 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 429377b..bc631c7 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -371,7 +371,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, vq->mz = mz; vq->vq_ring_virt_mem = mz->addr; - if (dev->dev_type == RTE_ETH_DEV_PCI) { + if (virtio_dev_check(dev, RTE_ETH_DEV_PCI, NULL, 0)) { vq->vq_ring_mem = mz->phys_addr; /* Virtio PCI device VIRTIO_PCI_QUEUE_PF register is 32bit, @@ -429,7 +429,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, vq->virtio_net_hdr_vaddr = mz->addr; memset(vq->virtio_net_hdr_vaddr, 0, hdr_size); - if (dev->dev_type == RTE_ETH_DEV_PCI) + if (virtio_dev_check(dev, RTE_ETH_DEV_PCI, NULL, 0)) vq->virtio_net_hdr_mem = mz->phys_addr; #ifdef RTE_VIRTIO_VDEV else @@ -439,7 +439,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev, hw->vtpci_ops->setup_queue(hw, vq); - if (dev->dev_type == RTE_ETH_DEV_PCI) + if (virtio_dev_check(dev, RTE_ETH_DEV_PCI, NULL, 0)) vq->offset = offsetof(struct rte_mbuf, buf_physaddr); #ifdef RTE_VIRTIO_VDEV else @@ -490,15 +490,13 @@ static void virtio_dev_close(struct rte_eth_dev *dev) { struct virtio_hw *hw = dev->data->dev_private; - struct rte_pci_device *pci_dev = dev->pci_dev; PMD_INIT_LOG(DEBUG, "virtio_dev_close"); /* reset the NIC */ - if (dev->dev_type == RTE_ETH_DEV_PCI) { - if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC) - vtpci_irq_config(hw, VIRTIO_MSI_NO_VECTOR); - } + if (virtio_dev_check(dev, RTE_ETH_DEV_PCI, NULL, RTE_PCI_DRV_INTR_LSC)) + vtpci_irq_config(hw, VIRTIO_MSI_NO_VECTOR); + vtpci_reset(hw); hw->started = 0; virtio_dev_free_mbufs(dev); @@ -1001,7 +999,7 @@ virtio_interrupt_handler(__rte_unused struct rte_intr_handle *handle, isr = vtpci_isr(hw); PMD_DRV_LOG(INFO, "interrupt status = %#x", isr); - if (dev->dev_type == RTE_ETH_DEV_PCI) + if (virtio_dev_check(dev, RTE_ETH_DEV_PCI, NULL, 0)) if (rte_intr_enable(&dev->pci_dev->intr_handle) < 0) PMD_DRV_LOG(ERR, "interrupt enable failed"); @@ -1056,9 +1054,10 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev = eth_dev->pci_dev; - if (eth_dev->dev_type == RTE_ETH_DEV_PCI) + if (virtio_dev_check(eth_dev, RTE_ETH_DEV_PCI, NULL, 0)) { if (vtpci_init(pci_dev, hw) < 0) return -1; + } /* Reset the device although not necessary at startup */ vtpci_reset(hw); @@ -1072,7 +1071,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) return -1; /* If host does not support status then disable LSC */ - if (eth_dev->dev_type == RTE_ETH_DEV_PCI) { + if (virtio_dev_check(eth_dev, RTE_ETH_DEV_PCI, NULL, 0)) { if (!vtpci_with_feature(hw, VIRTIO_NET_F_STATUS)) pci_dev->driver->drv_flags &= ~RTE_PCI_DRV_INTR_LSC; @@ -1154,13 +1153,14 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) PMD_INIT_LOG(DEBUG, "hw->max_rx_queues=%d hw->max_tx_queues=%d", hw->max_rx_queues, hw->max_tx_queues); - if (eth_dev->dev_type == RTE_ETH_DEV_PCI) { + if (virtio_dev_check(eth_dev, RTE_ETH_DEV_PCI, NULL, 0)) { PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x", eth_dev->data->port_id, pci_dev->id.vendor_id, pci_dev->id.device_id); /* Setup interrupt callback */ - if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC) + if (virtio_dev_check(eth_dev, RTE_ETH_DEV_PCI, + NULL, RTE_PCI_DRV_INTR_LSC)) rte_intr_callback_register(&pci_dev->intr_handle, virtio_interrupt_handler, eth_dev); @@ -1197,11 +1197,11 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev) eth_dev->data->mac_addrs = NULL; /* reset interrupt callback */ - if (eth_dev->dev_type == RTE_ETH_DEV_PCI) - if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC) - rte_intr_callback_unregister(&pci_dev->intr_handle, - virtio_interrupt_handler, - eth_dev); + if (virtio_dev_check(eth_dev, RTE_ETH_DEV_PCI, NULL, RTE_PCI_DRV_INTR_LSC)) + rte_intr_callback_unregister(&pci_dev->intr_handle, + virtio_interrupt_handler, + eth_dev); + rte_eal_pci_unmap_device(pci_dev); PMD_INIT_LOG(DEBUG, "dev_uninit completed"); @@ -1248,7 +1248,6 @@ virtio_dev_configure(struct rte_eth_dev *dev) { const struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode; struct virtio_hw *hw = dev->data->dev_private; - struct rte_pci_device *pci_dev = dev->pci_dev; PMD_INIT_LOG(DEBUG, "configure"); @@ -1266,12 +1265,11 @@ virtio_dev_configure(struct rte_eth_dev *dev) return -ENOTSUP; } - if (dev->dev_type == RTE_ETH_DEV_PCI) { - if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC) - if (vtpci_irq_config(hw, 0) == VIRTIO_MSI_NO_VECTOR) { - PMD_DRV_LOG(ERR, "failed to set config vector"); - return -EBUSY; - } + if (virtio_dev_check(dev, RTE_ETH_DEV_PCI, NULL, RTE_PCI_DRV_INTR_LSC)) { + if (vtpci_irq_config(hw, 0) == VIRTIO_MSI_NO_VECTOR) { + PMD_DRV_LOG(ERR, "failed to set config vector"); + return -EBUSY; + } } return 0; @@ -1283,11 +1281,11 @@ virtio_dev_start(struct rte_eth_dev *dev) { uint16_t nb_queues, i; struct virtio_hw *hw = dev->data->dev_private; - struct rte_pci_device *pci_dev = dev->pci_dev; /* check if lsc interrupt feature is enabled */ if (dev->data->dev_conf.intr_conf.lsc) { - if (!(pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)) { + if (!virtio_dev_check(dev, RTE_ETH_DEV_PCI, + NULL, RTE_PCI_DRV_INTR_LSC)) { PMD_DRV_LOG(ERR, "link status not supported by host"); return -ENOTSUP; } diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h index fde77ca..223b56d 100644 --- a/drivers/net/virtio/virtio_ethdev.h +++ b/drivers/net/virtio/virtio_ethdev.h @@ -67,6 +67,38 @@ 1u << VIRTIO_NET_F_MRG_RXBUF | \ 1ULL << VIRTIO_F_VERSION_1) +static inline int +virtio_dev_check(struct rte_eth_dev *dev, enum rte_eth_dev_type type, + const char *name, uint64_t flags) +{ + int ret; + + if (dev == NULL) + return 0; + + if (type != 0) + ret = (dev->dev_type == type); + else + ret = 1; + + if (name != 0) + ret &= (strncmp(dev->data->name, name, strlen(name)) == 0); + else + ret &= 1; + + if (flags != 0) { + if (dev->dev_type == RTE_ETH_DEV_PCI) + ret &= (dev->pci_dev->driver->drv_flags & flags) ? 1 : 0; + else if (dev->dev_type == RTE_ETH_DEV_VIRTUAL) + ret &= (dev->data->dev_flags & flags) ? 1 : 0; + else + ret = 0; + } else + ret &= 1; + + return ret; +} + /* * CQ function prototype */ -- 2.1.4