From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from wes1-so2.wedos.net (wes1-so2.wedos.net [46.28.106.16]) by dpdk.org (Postfix) with ESMTP id AEECF91DB for ; Mon, 4 Jan 2016 21:09:51 +0100 (CET) Received: from pcviktorin.fit.vutbr.cz (pcviktorin.fit.vutbr.cz [147.229.13.147]) by wes1-so2.wedos.net (Postfix) with ESMTPSA id 3pZ7NH3z5czrl; Mon, 4 Jan 2016 21:09:51 +0100 (CET) From: Jan Viktorin To: dev@dpdk.org Date: Mon, 4 Jan 2016 21:08:21 +0100 Message-Id: <1451938106-12145-10-git-send-email-viktorin@rehivetech.com> X-Mailer: git-send-email 2.6.3 In-Reply-To: <1451938106-12145-1-git-send-email-viktorin@rehivetech.com> References: <1451938106-12145-1-git-send-email-viktorin@rehivetech.com> Cc: Jan Viktorin Subject: [dpdk-dev] [PATCH 09/14] lib/ether: generalize attach/detach of devices 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: Mon, 04 Jan 2016 20:09:51 -0000 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 --- 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