From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 4458EA04C9;
	Mon, 14 Sep 2020 00:10:02 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 240B31C192;
	Mon, 14 Sep 2020 00:09:11 +0200 (CEST)
Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com
 [64.147.123.25]) by dpdk.org (Postfix) with ESMTP id 83CE11C192
 for <dev@dpdk.org>; Mon, 14 Sep 2020 00:09:09 +0200 (CEST)
Received: from compute7.internal (compute7.nyi.internal [10.202.2.47])
 by mailout.west.internal (Postfix) with ESMTP id 5CFF94A2;
 Sun, 13 Sep 2020 18:09:08 -0400 (EDT)
Received: from mailfrontend2 ([10.202.2.163])
 by compute7.internal (MEProxy); Sun, 13 Sep 2020 18:09:08 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h=
 from:to:cc:subject:date:message-id:in-reply-to:references
 :mime-version:content-transfer-encoding; s=fm2; bh=1y6/fs8bu+lqK
 rLjaStWy2xeNQLaxhSBsY5e29Mqd/Y=; b=AAo47BcqjXltgfBLHp3S1dSW/rD/x
 3XXBWEWgh5v/vFruFmYG7EfBb91NsYzZWF0EII89JqZiqS5FTznOwtxX/30UlZ1H
 iaMcLQiOmncwJhGGALX48+24xRh++jZBEVXRDGV8O9HnK4CkV47sHKc4vTFR43ia
 u9hxf8Bcci5id8Gj9+Oq9bYrC/RA1Wkq6B4e3CpJeC/1aGjOF8JMRgcRC7LZk9a7
 I3l5iwjSh879IqwaHzSUWToYu/8wWwVrg43D5Om1R6RUE5sAv1CwLkQQc8bK3vgi
 3sJ0k2L7LEawkzijgxCCGJZUKC29wF/OSXMjE3wS+UpAdxe4EaL2IfqVA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:content-transfer-encoding:date:from
 :in-reply-to:message-id:mime-version:references:subject:to
 :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=
 fm3; bh=1y6/fs8bu+lqKrLjaStWy2xeNQLaxhSBsY5e29Mqd/Y=; b=RkPNZUGg
 auJ3xBoCro6EL2Pkgr1EVh4XU8ndgWs07K4Ul6wsUwMR7p2FFKzRwbxH9ImIJ584
 B3i2j4uFOR+D6NhIElqJCX3mH7AhWF4PSM9NZnV9vopIalMq4hcrpuVtQJCqvROb
 qB1lPMTAK6fJ7QSikctL9relbW4XgIkSlEICsnfaaUx9vxuhHe3Ku7FRp7zSj/Rw
 rKFR7qjFivUWEGb1ZYYnS9FkWlpoRzv6BkFDmahYeRxDJTPJn2dd9KJL62Tq+5tz
 Dluwa3W74byoesKKtbgg3TZMmQQG4GTSFODwd3aC30sVK44JdUSWRYyBNvivL0gy
 3wFNeEBKrXybhA==
X-ME-Sender: <xms:g5heXwQ94bNygRDYMKFjyEsUzoEjcIl0hTM05ldkpe1pECMpNtRLkA>
 <xme:g5heX9yuXvPD2f0IYjlXVf_8r__Qw23REQ_ZLBxYh3M_k1vkdUybbESCPjXVKTHCp
 r5Clhqn_YX1ke9hnA>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrudeihedgtdehucetufdoteggodetrfdotf
 fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen
 uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne
 cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvhhhomhgr
 shcuofhonhhjrghlohhnuceothhhohhmrghssehmohhnjhgrlhhonhdrnhgvtheqnecugg
 ftrfgrthhtvghrnhepvdehgfeivdejgedtveehfefhteelfefgieevgfffveefjeegtdfg
 uedthedtgeevnecukfhppeejjedrudefgedrvddtfedrudekgeenucevlhhushhtvghruf
 hiiigvpeduleenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhmrghssehmohhnjhgr
 lhhonhdrnhgvth
X-ME-Proxy: <xmx:g5heX91zmqLVIOUzvYIx4HNPeN-C7KkAEHzsjvcoOSqehHkGRxcKJg>
 <xmx:g5heX0BPe7ruZ80xXscjJ24dDfldchVA9F8LB4EN0W9tF77iETJSlg>
 <xmx:g5heX5gC-PodT4Fn-IvA7V_7Oe61HJakhrrdNfiYgL19AFFOuPCUkw>
 <xmx:hJheX-vDttn2qv8TdOHdXO6H7sZzQltWoJgrEbp_LruQRmM4hDnH3w>
Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184])
 by mail.messagingengine.com (Postfix) with ESMTPA id 0FED33064674;
 Sun, 13 Sep 2020 18:09:06 -0400 (EDT)
From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, arybchenko@solarflare.com,
 Wenzhuo Lu <wenzhuo.lu@intel.com>, Beilei Xing <beilei.xing@intel.com>,
 Bernard Iremonger <bernard.iremonger@intel.com>
Date: Mon, 14 Sep 2020 00:07:11 +0200
Message-Id: <20200913220711.3768597-21-thomas@monjalon.net>
X-Mailer: git-send-email 2.28.0
In-Reply-To: <20200913220711.3768597-1-thomas@monjalon.net>
References: <20200913220711.3768597-1-thomas@monjalon.net>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Subject: [dpdk-dev] [PATCH 20/20] app/testpmd: align behaviour of multi-port
	detach
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

A port can be closed in multiple situations:
	- close command calling close_port() -> rte_eth_dev_close()
	- exit calling close_port() -> rte_eth_dev_close()
	- hotplug calling close_port() -> rte_eth_dev_close()
	- hotplug calling detach_device() -> rte_dev_remove()
	- port detach command, detach_device() -> rte_dev_remove()
	- device detach command, detach_devargs() -> rte_eal_hotplug_remove()

The flow rules are flushed before each close.
It was already done in close_port(), detach_devargs() and
detach_port_device() which calls detach_device(),
but not in detach_device(). As a consequence, it was missing for siblings
of port detach command and unplugged device.
The check before calling port_flow_flush() is moved inside the function.

The state of the port to close is checked to be stopped.
As above, this check was missing in detach_device(),
impacting the cases of a multi-port device unplugged or detached
with the port detach command.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 app/test-pmd/config.c  |  7 +++++--
 app/test-pmd/testpmd.c | 22 +++++++++++-----------
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 30bee33248..21513a2978 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1588,9 +1588,12 @@ int
 port_flow_flush(portid_t port_id)
 {
 	struct rte_flow_error error;
-	struct rte_port *port;
+	struct rte_port *port = &ports[port_id];
 	int ret = 0;
 
+	if (port->flow_list == NULL)
+		return ret;
+
 	/* Poisoning to make sure PMDs update it in case of error. */
 	memset(&error, 0x44, sizeof(error));
 	if (rte_flow_flush(port_id, &error)) {
@@ -1599,7 +1602,7 @@ port_flow_flush(portid_t port_id)
 		    port_id == (portid_t)RTE_PORT_ALL)
 			return ret;
 	}
-	port = &ports[port_id];
+
 	while (port->flow_list) {
 		struct port_flow *pf = port->flow_list->next;
 
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 31dc97239b..a76e9877f6 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -2694,8 +2694,7 @@ close_port(portid_t pid)
 			continue;
 		}
 
-		if (port->flow_list)
-			port_flow_flush(pi);
+		port_flow_flush(pi);
 		rte_eth_dev_close(pi);
 	}
 
@@ -2825,15 +2824,20 @@ detach_device(struct rte_device *dev)
 
 	printf("Removing a device...\n");
 
-	if (rte_dev_remove(dev) < 0) {
-		TESTPMD_LOG(ERR, "Failed to detach device %s\n", dev->name);
-		return;
-	}
 	RTE_ETH_FOREACH_DEV_OF(sibling, dev) {
 		if (ports[sibling].port_status != RTE_PORT_CLOSED) {
+			if (ports[sibling].port_status != RTE_PORT_STOPPED) {
+				printf("Port %u not stopped\n", sibling);
+				return;
+			}
+			port_flow_flush(sibling);
 		}
 	}
 
+	if (rte_dev_remove(dev) < 0) {
+		TESTPMD_LOG(ERR, "Failed to detach device %s\n", dev->name);
+		return;
+	}
 	remove_invalid_ports();
 
 	printf("Device is detached\n");
@@ -2854,8 +2858,6 @@ detach_port_device(portid_t port_id)
 			return;
 		}
 		printf("Port was not closed\n");
-		if (ports[port_id].flow_list)
-			port_flow_flush(port_id);
 	}
 
 	detach_device(rte_eth_devices[port_id].device);
@@ -2885,9 +2887,7 @@ detach_devargs(char *identifier)
 				rte_eth_iterator_cleanup(&iterator);
 				return;
 			}
-
-			if (ports[port_id].flow_list)
-				port_flow_flush(port_id);
+			port_flow_flush(port_id);
 		}
 	}
 
-- 
2.28.0