[dpdk-dev] [PATCH 09/14] lib/ether: generalize attach/detach of devices

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


Make the attach and detach functions independent on the PCI infra. Mostly, this
means to utilize the rte_bus_addr instead of rte_pci_addr.

Signed-off-by: Jan Viktorin <viktorin at rehivetech.com>
---
 lib/librte_ether/rte_ethdev.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 826d4b9..db12515 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -432,7 +432,7 @@ rte_eth_dev_get_device_type(uint8_t port_id)
 }
 
 static int
-rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
+rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_bus_addr *addr)
 {
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
 
@@ -441,8 +441,15 @@ rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)
 		return -EINVAL;
 	}
 
-	*addr = rte_eth_devices[port_id].pci_dev->addr;
-	return 0;
+	if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
+		addr->pci = rte_eth_devices[port_id].pci_dev->addr;
+		addr->dev_magic = RTE_PCI_DEVICE_MAGIC;
+		return 0;
+	} else {
+		rte_panic("%s(): unexpected dev_type: %u\n", __func__,
+				rte_eth_devices[port_id].dev_type);
+		return -ENODEV;
+	}
 }
 
 static int
@@ -566,10 +573,10 @@ err:
 
 /* detach the new physical device, then store pci_addr of the device */
 static int
-rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
+rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_bus_addr *addr)
 {
-	struct rte_pci_addr freed_addr;
-	struct rte_pci_addr vp;
+	struct rte_bus_addr freed_addr;
+	struct rte_bus_addr vp;
 
 	if (addr == NULL)
 		goto err;
@@ -583,13 +590,16 @@ rte_eth_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr)
 		goto err;
 
 	/* Zeroed pci addr means the port comes from virtual device */
-	vp.domain = vp.bus = vp.devid = vp.function = 0;
-	if (rte_eal_compare_pci_addr(&vp, &freed_addr) == 0)
+	memset(&vp, 0, sizeof(vp));
+	if (rte_eal_compare_bus_addr(&vp, &freed_addr) == 0)
 		goto err;
 
 	/* invoke devuninit func of the pci driver,
 	 * also remove the device from pci_device_list */
-	if (rte_eal_pci_detach(&freed_addr))
+	if (freed_addr.dev_magic == RTE_PCI_DEVICE_MAGIC) {
+		if (rte_eal_pci_detach(&freed_addr.pci))
+			goto err;
+	} else
 		goto err;
 
 	*addr = freed_addr;
@@ -683,7 +693,7 @@ rte_eth_dev_attach(const char *devargs, uint8_t *port_id)
 int
 rte_eth_dev_detach(uint8_t port_id, char *name)
 {
-	struct rte_pci_addr addr;
+	struct rte_bus_addr addr;
 	int ret;
 
 	if (name == NULL)
@@ -698,8 +708,8 @@ rte_eth_dev_detach(uint8_t port_id, char *name)
 		if (ret == 0)
 			snprintf(name, RTE_ETH_NAME_MAX_LEN,
 				"%04x:%02x:%02x.%d",
-				addr.domain, addr.bus,
-				addr.devid, addr.function);
+				addr.pci.domain, addr.pci.bus,
+				addr.pci.devid, addr.pci.function);
 
 		return ret;
 	} else
-- 
2.6.3



More information about the dev mailing list