From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <jblunck@gmail.com>
Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65])
 by dpdk.org (Postfix) with ESMTP id D0976FB4C
 for <dev@dpdk.org>; Tue, 20 Dec 2016 12:12:26 +0100 (CET)
Received: by mail-wm0-f65.google.com with SMTP id m203so23621043wma.3
 for <dev@dpdk.org>; Tue, 20 Dec 2016 03:12:26 -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=ISHeKsp568izqQgvAl6gDEIN/Khu7TgCEqnQOjdOm/I=;
 b=DQXH6e9lHpu42AfqzGqKHZk3MEsydzsluFc4Wzgd1HjhGa7Hjx31b6LK0xVeqDXOh8
 Z67mRATABd27bO/Ad+LPTT3gyx7flHhtnLmyF28DoYIBVXWsxbQiLaHE/H04lt6v0QeY
 0pXEu9bns1zuYRvvfUH+Sd7iCNKlIRASdyoI06sYhaDRxxWHXWKvTlCDXKuVPBErMxmU
 Z+o2OIMNWn5comvfnVms9ZSKNzxvjXxXvbOM/WqcHYYTfkC7YzCdJOGZfkQ56ayKbIc7
 KGci6OpK9lG1FXm6MdmTQ52YKbnqLb4gWnwf1bKRcQodlgT3vFj5LSQYfxhXaO0r0LH4
 1bYA==
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=ISHeKsp568izqQgvAl6gDEIN/Khu7TgCEqnQOjdOm/I=;
 b=bogq92/u/+ICw9Ys2FcJJLQPS1MCDCXz4Nv9MegdnA5OyxAzIIDbaPQAfQ65jStxcZ
 AYkNZFHX0RoahCwJ5vOaUaX3r15UDQPr2fiNd+81xcjVJx771BHL5SQWQGy/elk3EjjK
 ZwOX6a5Ku9hcJ6k3vtV4kl6gNvo+6WNFMAeJYC9j6QDVV2VaKzPeoC8bqKzjOukmtwSn
 8Q2Ho/dzreIgp+ymYqQ+f/TlBBtYcPNLeHu8tH4PdHn+dcLhaL7aKyHCKuMn5GUgnCl+
 VE6RC6b9TuMbqNsKdg60wndSyhnl4FZ3FH00mazc6GjSkSFMi8SJFZ+8KnX/nM0PiG1m
 VicQ==
X-Gm-Message-State: AIkVDXKCc2+vNyeA9RLOTfbLJpI21eB5LieuO+kTartLejyZcob9kCCC61NMWla8KSCzng==
X-Received: by 10.28.225.138 with SMTP id y132mr1381046wmg.52.1482232346492;
 Tue, 20 Dec 2016 03:12:26 -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.25
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Tue, 20 Dec 2016 03:12:25 -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:55 +0100
Message-Id: <1482232315-21626-10-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 9/9] ethdev: Decouple struct rte_eth_dev from
	struct rte_pci_device
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:27 -0000

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 app/test/virtual_pmd.c                  |  4 ++--
 drivers/net/bonding/rte_eth_bond_args.c | 12 ++++++++++--
 drivers/net/cxgbe/cxgbe_main.c          |  4 ++--
 drivers/net/fm10k/fm10k_ethdev.c        |  6 +++---
 drivers/net/virtio/virtio_user_ethdev.c |  1 -
 lib/librte_eal/common/include/rte_pci.h |  6 ++++++
 lib/librte_ether/rte_ethdev.c           |  6 +++---
 lib/librte_ether/rte_ethdev.h           |  4 ++--
 8 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c
index 65b44c6..bd30b14 100644
--- a/app/test/virtual_pmd.c
+++ b/app/test/virtual_pmd.c
@@ -625,8 +625,8 @@ virtual_ethdev_create(const char *name, struct ether_addr *mac_addr,
 	dev_private->dev_ops = virtual_ethdev_default_dev_ops;
 	eth_dev->dev_ops = &dev_private->dev_ops;
 
-	eth_dev->pci_dev = pci_dev;
-	eth_dev->pci_dev->device.driver = &eth_drv->pci_drv.driver;
+	pci_dev->device.driver = &eth_drv->pci_drv.driver;
+	eth_dev->device = &pci_dev->device;
 
 	eth_dev->rx_pkt_burst = virtual_ethdev_rx_burst_success;
 	eth_dev->tx_pkt_burst = virtual_ethdev_tx_burst_success;
diff --git a/drivers/net/bonding/rte_eth_bond_args.c b/drivers/net/bonding/rte_eth_bond_args.c
index 02ecde6..29436ea 100644
--- a/drivers/net/bonding/rte_eth_bond_args.c
+++ b/drivers/net/bonding/rte_eth_bond_args.c
@@ -54,15 +54,23 @@ const char *pmd_bond_init_valid_arguments[] = {
 static inline int
 find_port_id_by_pci_addr(const struct rte_pci_addr *pci_addr)
 {
+	struct rte_pci_device *pci_dev;
 	struct rte_pci_addr *eth_pci_addr;
 	unsigned i;
 
 	for (i = 0; i < rte_eth_dev_count(); i++) {
 
-		if (rte_eth_devices[i].pci_dev == NULL)
+		/* Currently populated by rte_eth_copy_pci_info().
+		 *
+		 * TODO: Once the PCI bus has arrived we should have a better
+		 * way to test for being a PCI device or not.
+		 */
+		if (rte_eth_devices[i].data->kdrv == RTE_KDRV_UNKNOWN ||
+		    rte_eth_devices[i].data->kdrv == RTE_KDRV_NONE)
 			continue;
 
-		eth_pci_addr = &(rte_eth_devices[i].pci_dev->addr);
+		pci_dev = ETH_DEV_PCI_DEV(&rte_eth_devices[i]);
+		eth_pci_addr = &pci_dev->addr;
 
 		if (pci_addr->bus == eth_pci_addr->bus &&
 			pci_addr->devid == eth_pci_addr->devid &&
diff --git a/drivers/net/cxgbe/cxgbe_main.c b/drivers/net/cxgbe/cxgbe_main.c
index 922155b..ea13c7e 100644
--- a/drivers/net/cxgbe/cxgbe_main.c
+++ b/drivers/net/cxgbe/cxgbe_main.c
@@ -1163,14 +1163,14 @@ int cxgbe_probe(struct adapter *adapter)
 		pi->eth_dev->data = data;
 
 allocate_mac:
-		pi->eth_dev->pci_dev = adapter->pdev;
+		pi->eth_dev->device = &adapter->pdev->device;
 		pi->eth_dev->data->dev_private = pi;
 		pi->eth_dev->driver = adapter->eth_dev->driver;
 		pi->eth_dev->dev_ops = adapter->eth_dev->dev_ops;
 		pi->eth_dev->tx_pkt_burst = adapter->eth_dev->tx_pkt_burst;
 		pi->eth_dev->rx_pkt_burst = adapter->eth_dev->rx_pkt_burst;
 
-		rte_eth_copy_pci_info(pi->eth_dev, pi->eth_dev->pci_dev);
+		rte_eth_copy_pci_info(pi->eth_dev, adapter->pdev);
 
 		TAILQ_INIT(&pi->eth_dev->link_intr_cbs);
 
diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index 5d0bce5..5718b39 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -678,7 +678,7 @@ fm10k_dev_tx_init(struct rte_eth_dev *dev)
 		/* Enable use of FTAG bit in TX descriptor, PFVTCTL
 		 * register is read-only for VF.
 		 */
-		if (fm10k_check_ftag(dev->pci_dev->device.devargs)) {
+		if (fm10k_check_ftag(dev->device->devargs)) {
 			if (hw->mac.type == fm10k_mac_pf) {
 				FM10K_WRITE_REG(hw, FM10K_PFVTCTL(i),
 						FM10K_PFVTCTL_FTAG_DESC_ENABLE);
@@ -2740,7 +2740,7 @@ fm10k_set_tx_function(struct rte_eth_dev *dev)
 	int use_sse = 1;
 	uint16_t tx_ftag_en = 0;
 
-	if (fm10k_check_ftag(dev->pci_dev->device.devargs))
+	if (fm10k_check_ftag(dev->device->devargs))
 		tx_ftag_en = 1;
 
 	for (i = 0; i < dev->data->nb_tx_queues; i++) {
@@ -2771,7 +2771,7 @@ fm10k_set_rx_function(struct rte_eth_dev *dev)
 	uint16_t i, rx_using_sse;
 	uint16_t rx_ftag_en = 0;
 
-	if (fm10k_check_ftag(dev->pci_dev->device.devargs))
+	if (fm10k_check_ftag(dev->device->devargs))
 		rx_ftag_en = 1;
 
 	/* In order to allow Vector Rx there are a few configuration
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index 406beea..8cb983c 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -310,7 +310,6 @@ virtio_user_eth_dev_alloc(const char *name)
 	data->numa_node = SOCKET_ID_ANY;
 	data->kdrv = RTE_KDRV_NONE;
 	data->dev_flags = RTE_ETH_DEV_DETACHABLE;
-	eth_dev->pci_dev = NULL;
 	eth_dev->driver = NULL;
 	return eth_dev;
 }
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 9ce8847..19deaf6 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -160,6 +160,12 @@ struct rte_pci_device {
 	enum rte_kernel_driver kdrv;            /**< Kernel driver passthrough */
 };
 
+/**
+ * @internal
+ * Helper macro for drivers that need to convert to struct rte_pci_device.
+ */
+#define DEV_PCI_DEV(ptr) container_of(ptr, struct rte_pci_device, device)
+
 /** Any PCI device identifier (vendor, device, ...) */
 #define PCI_ANY_ID (0xffff)
 #define RTE_CLASS_ANY_ID (0xffffff)
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 4ecea50..cc01672 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -257,7 +257,7 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv,
 		if (eth_dev->data->dev_private == NULL)
 			rte_panic("Cannot allocate memzone for private port data\n");
 	}
-	eth_dev->pci_dev = pci_dev;
+	eth_dev->device = &pci_dev->device;
 	eth_dev->intr_handle = &pci_dev->intr_handle;
 	eth_dev->driver = eth_drv;
 	eth_dev->data->rx_mbuf_alloc_failed = 0;
@@ -318,7 +318,7 @@ rte_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
 		rte_free(eth_dev->data->dev_private);
 
-	eth_dev->pci_dev = NULL;
+	eth_dev->device = NULL;
 	eth_dev->driver = NULL;
 	eth_dev->data = NULL;
 
@@ -2578,7 +2578,7 @@ rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name,
 	const struct rte_memzone *mz;
 
 	snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
-		 dev->driver->pci_drv.driver.name, ring_name,
+		 dev->data->drv_name, ring_name,
 		 dev->data->port_id, queue_id);
 
 	mz = rte_memzone_lookup(z_name);
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index f1f656a..58ef798 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1628,7 +1628,7 @@ struct rte_eth_dev {
 	struct rte_eth_dev_data *data;  /**< Pointer to device data */
 	const struct eth_driver *driver;/**< Driver for this device */
 	const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
-	struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing */
+	struct rte_device *device; /**< Backing device for this device */
 	struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
 	/** User application callbacks for NIC interrupts */
 	struct rte_eth_dev_cb_list link_intr_cbs;
@@ -1649,7 +1649,7 @@ struct rte_eth_dev {
  * @internal
  * Helper for drivers that need to convert from rte_eth_dev to rte_pci_device.
  */
-#define ETH_DEV_PCI_DEV(ptr) ((ptr)->pci_dev)
+#define ETH_DEV_PCI_DEV(ptr) DEV_PCI_DEV((ptr)->device)
 
 struct rte_eth_dev_sriov {
 	uint8_t active;               /**< SRIOV is active with 16, 32 or 64 pools */
-- 
2.7.4