From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <jblunck@gmail.com>
Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66])
 by dpdk.org (Postfix) with ESMTP id 2EAB5FAFE
 for <dev@dpdk.org>; Tue, 20 Dec 2016 12:12:23 +0100 (CET)
Received: by mail-wm0-f66.google.com with SMTP id m203so23620657wma.3
 for <dev@dpdk.org>; Tue, 20 Dec 2016 03:12:23 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=sender:from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=27C1aYr9nIq0w2zRR3dHopzvOKOmG1t7h6Zy0kvJ+eM=;
 b=i4TlkW82ym26HvnQv+wcLWvHMwPLmRZ0Qm/Ls9RGls2xI6SgOpn8Cwhli3TcYgQoLR
 YYVN+hu22Nxabq0xtbaGrqODkTbR8s7P5/BrF63/Wamce1/6t0zVdLbxTXPsTfKL/VxD
 8AjCzV2rHHX/HOaQPUxekzHhS4u0611mrnc2f6qR5gYrVujZj0MxCT2Gqood3SH+JG/t
 Z+XVXXUtyTQYlrNyXnQM23YTKkU4Sy+vM1AgensABLRz+KJJl/niEsNORwGQDhgcxFeY
 p+E5vXCLdTE5Oau/Otn6gztxrTex1ddR7IkuSLq5fQ8ipyKNG8Bo3nGEfuCHw/fniKya
 2EHg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:sender:from:to:cc:subject:date:message-id
 :in-reply-to:references;
 bh=27C1aYr9nIq0w2zRR3dHopzvOKOmG1t7h6Zy0kvJ+eM=;
 b=dvNL3YgH7MEMVIPbPuEb01BVNKMP0K5c4J6q7Trxxtm4VUTiFs0WNysiP69xEG4aNA
 0OIMNPNwPgUxqiv9s/FKfOM2Zf+b2MOadqU6cCmzaaGTjo0ASykPp0gIhdloKo44/L5w
 GIYwoRLYR0MxNUjk6gGJimpObNIcRwdO2Pi+VHuBqFwEeKPBsiwWMw1faewb8td3Wcxs
 bfMUeaKPUhXMdfRs9K130GqQ3HhujsoAJfU2eoCMWUdc+FZhwaYmKi65xvtqKI3fJIix
 LesnyqMon2byDsFqYMU7XDm72HXlA45iVE3+ALyUqxhTB0hZItkw9kzKa/+obJuFFD9q
 lLWg==
X-Gm-Message-State: AIkVDXIjb1JOJmasB0ed+EN8TkNtpq/a7VmdQLVCndkRCEA354HYPc6TYbUcS9uRHNrlFA==
X-Received: by 10.28.72.3 with SMTP id v3mr1574566wma.20.1482232342879;
 Tue, 20 Dec 2016 03:12:22 -0800 (PST)
Received: from weierstrass.local.net ([91.200.109.169])
 by smtp.gmail.com with ESMTPSA id q65sm21527756wmd.6.2016.12.20.03.12.21
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Tue, 20 Dec 2016 03:12:22 -0800 (PST)
Sender: Jan Blunck <jblunck@gmail.com>
From: Jan Blunck <jblunck@infradead.org>
To: dev@dpdk.org
Cc: shreyansh.jain@nxp.com, david.marchand@6wind.com,
 stephen@networkplumber.org
Date: Tue, 20 Dec 2016 12:11:52 +0100
Message-Id: <1482232315-21626-7-git-send-email-jblunck@infradead.org>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1482232315-21626-1-git-send-email-jblunck@infradead.org>
References: <1482232315-21626-1-git-send-email-jblunck@infradead.org>
Subject: [dpdk-dev] [PATCH v3 6/9] virtio: Don't depend on struct
	rte_eth_dev's pci_dev
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Tue, 20 Dec 2016 11:12:23 -0000

We don't need to depend on rte_eth_dev->pci_dev to differentiate between
the virtio_user and the virtio_pci case. Instead we can use the private
virtio_hw struct to get that information.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/net/virtio/virtio_ethdev.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index da9668e..023101d 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -483,11 +483,11 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 		hw->cvq = cvq;
 	}
 
-	/* For virtio_user case (that is when dev->pci_dev is NULL), we use
+	/* For virtio_user case (that is when hw->dev is NULL), we use
 	 * virtual address. And we need properly set _offset_, please see
 	 * VIRTIO_MBUF_DATA_DMA_ADDR in virtqueue.h for more information.
 	 */
-	if (dev->pci_dev)
+	if (hw->dev)
 		vq->offset = offsetof(struct rte_mbuf, buf_physaddr);
 	else {
 		vq->vq_ring_mem = (uintptr_t)mz->addr;
@@ -1190,7 +1190,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	struct virtio_hw *hw = eth_dev->data->dev_private;
 	struct virtio_net_config *config;
 	struct virtio_net_config local_config;
-	struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+	struct rte_pci_device *pci_dev = hw->dev;
 	int ret;
 
 	/* Reset the device although not necessary at startup */
@@ -1294,7 +1294,6 @@ int
 eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 {
 	struct virtio_hw *hw = eth_dev->data->dev_private;
-	struct rte_pci_device *pci_dev;
 	uint32_t dev_flags = RTE_ETH_DEV_DETACHABLE;
 	int ret;
 
@@ -1317,10 +1316,11 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 		return -ENOMEM;
 	}
 
-	pci_dev = eth_dev->pci_dev;
-
-	if (pci_dev) {
-		ret = vtpci_init(pci_dev, hw, &dev_flags);
+	/* For virtio_user case the hw->virtio_user_dev is populated by
+	 * virtio_user_eth_dev_alloc() before eth_virtio_dev_init() is called.
+	 */
+	if (!hw->virtio_user_dev) {
+		ret = vtpci_init(ETH_DEV_PCI_DEV(eth_dev), hw, &dev_flags);
 		if (ret)
 			return ret;
 	}
@@ -1343,7 +1343,6 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-	struct rte_pci_device *pci_dev;
 	struct virtio_hw *hw = eth_dev->data->dev_private;
 
 	PMD_INIT_FUNC_TRACE();
@@ -1353,7 +1352,6 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 
 	virtio_dev_stop(eth_dev);
 	virtio_dev_close(eth_dev);
-	pci_dev = eth_dev->pci_dev;
 
 	eth_dev->dev_ops = NULL;
 	eth_dev->tx_pkt_burst = NULL;
@@ -1367,7 +1365,8 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 		rte_intr_callback_unregister(vtpci_intr_handle(hw),
 						virtio_interrupt_handler,
 						eth_dev);
-	rte_eal_pci_unmap_device(pci_dev);
+	if (hw->dev)
+		rte_eal_pci_unmap_device(hw->dev);
 
 	PMD_INIT_LOG(DEBUG, "dev_uninit completed");
 
-- 
2.7.4