[dpdk-dev] [PATCH 14/14] lib/ether: introduce rte_eth_copy_dev_info

Jan Viktorin viktorin at rehivetech.com
Mon Jan 4 21:08:26 CET 2016


This function should be preferred over the rte_eth_copy_pci_info as it is not
PCI-specific.

Signed-off-by: Jan Viktorin <viktorin at rehivetech.com>
---
 lib/librte_ether/rte_ethdev.c | 38 ++++++++++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.h | 15 +++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 75121bc..6d58544 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -3309,3 +3309,41 @@ rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_de
 	eth_dev->data->numa_node = pci_dev->numa_node;
 	eth_dev->data->drv_name = pci_dev->driver->name;
 }
+
+void
+rte_eth_copy_dev_info(struct rte_eth_dev *eth_dev, const union rte_device *dev)
+{
+	unsigned int drv_flags;
+
+	if (eth_dev == NULL || dev == NULL) {
+		RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p dev=%p\n",
+				eth_dev, dev);
+		return;
+	}
+
+	if (eth_dev->dev->magic != dev->magic) {
+		rte_panic("%s() incompatible magic set: %08x != %08x\n",
+				__func__, eth_dev->dev->magic, dev->magic);
+		return;
+	}
+
+	eth_dev->data->dev_flags = 0;
+
+	switch (eth_dev->dev->magic) {
+	case RTE_PCI_DEVICE_MAGIC:
+		drv_flags = dev->pci.driver->drv_flags;
+		if (drv_flags & RTE_PCI_DRV_INTR_LSC)
+			eth_dev->data->dev_flags |= RTE_PCI_DRV_INTR_LSC;
+		if (drv_flags & RTE_PCI_DRV_DETACHABLE)
+			eth_dev->data->dev_flags |= RTE_PCI_DRV_DETACHABLE;
+
+		eth_dev->data->kdrv = dev->pci.kdrv;
+		eth_dev->data->numa_node = dev->pci.numa_node;
+		eth_dev->data->drv_name = dev->pci.driver->name;
+		break;
+	default:
+		rte_panic("%s() unrecognized dev magic: %08x\n",
+				__func__, dev->magic);
+		break;
+	}
+}
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 5dd2e1a..020c0f7 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -3864,6 +3864,21 @@ extern int rte_eth_timesync_write_time(uint8_t port_id,
  */
 extern void rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev);
 
+/**
+ * Copy device info to the Ethernet device data. The target eth_dev must be
+ * compatible with the given device (from the same infrastructure - eg. PCI).
+ *
+ * @param eth_dev
+ * The *eth_dev* pointer is the address of the *rte_eth_dev* structure.
+ * @param pci_dev
+ * The *dev* pointer is the address of the *rte_device* union.
+ *
+ * @return
+ *   - 0 on success, negative on error
+ */
+extern void rte_eth_copy_dev_info(struct rte_eth_dev *eth_dev,
+		const union rte_device *dev);
+
 
 /**
  * Create memzone for HW rings.
-- 
2.6.3



More information about the dev mailing list