From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Monjalon Subject: [PATCH v7 7/7] app/testpmd: check not detaching device twice Date: Tue, 23 Oct 2018 10:28:42 +0200 Message-ID: <20181023082842.7963-8-thomas@monjalon.net> References: <20181007222554.4886-1-thomas@monjalon.net> <20181023082842.7963-1-thomas@monjalon.net> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, wisamm@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com, bernard.iremonger@intel.com To: dev@dpdk.org Return-path: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 95EFA1B3B1 for ; Tue, 23 Oct 2018 10:28:58 +0200 (CEST) In-Reply-To: <20181023082842.7963-1-thomas@monjalon.net> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The command "port detach" is removing the EAL rte_device of the ethdev port specified as parameter. After detaching, the pointer, which maps a port to its device, is resetted. This way, it is possible to check whether a port is still associated to a (not removed) device. Signed-off-by: Thomas Monjalon --- app/test-pmd/testpmd.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 14647fa19..d5998fddc 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -2353,8 +2353,17 @@ setup_attached_port(portid_t pi) void detach_port(portid_t port_id) { + struct rte_device *dev; + portid_t sibling; + printf("Removing a device...\n"); + dev = rte_eth_devices[port_id].device; + if (dev == NULL) { + printf("Device already removed\n"); + return; + } + if (ports[port_id].port_status != RTE_PORT_CLOSED) { if (ports[port_id].port_status != RTE_PORT_STOPPED) { printf("Port not stopped\n"); @@ -2365,15 +2374,24 @@ detach_port(portid_t port_id) port_flow_flush(port_id); } - if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) { + if (rte_dev_remove(dev) != 0) { TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id); return; } + /* reset mapping between old ports and removed device */ + for (sibling = 0; sibling < RTE_MAX_ETHPORTS; sibling++) + if (rte_eth_devices[sibling].device == dev) { + rte_eth_devices[sibling].device = NULL; + if (ports[sibling].port_status != RTE_PORT_CLOSED) { + ports[sibling].port_status = RTE_PORT_CLOSED; + printf("Port %u is closed\n", sibling); + } + } + remove_unused_fwd_ports(); - printf("Port %u is detached. Now total ports is %d\n", - port_id, nb_ports); + printf("Now total ports is %d\n", nb_ports); printf("Done\n"); return; } -- 2.19.0