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 EB98EA04C0;
	Mon, 28 Sep 2020 01:48:51 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 741151D66F;
	Mon, 28 Sep 2020 01:44:11 +0200 (CEST)
Received: from new4-smtp.messagingengine.com (new4-smtp.messagingengine.com
 [66.111.4.230]) by dpdk.org (Postfix) with ESMTP id 6E4461D5F3
 for <dev@dpdk.org>; Mon, 28 Sep 2020 01:43:55 +0200 (CEST)
Received: from compute7.internal (compute7.nyi.internal [10.202.2.47])
 by mailnew.nyi.internal (Postfix) with ESMTP id 1EA02580131;
 Sun, 27 Sep 2020 19:43:54 -0400 (EDT)
Received: from mailfrontend1 ([10.202.2.162])
 by compute7.internal (MEProxy); Sun, 27 Sep 2020 19:43:54 -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=2rThejk/Rv4bf
 Rg4HNaKxkPgmHJq/9H/EjksWtNdqKk=; b=VEIUbpWkk0/GHuM0ZiQiVKOhcuawk
 YP4yrFYDQi+axjwiHr18KB4PEVooZC89FvXuY05lzbKRL1/G8k4FtFY4Zs4vhMxi
 gJ4LG0oX3OCrrZJ61oQj3kAPacKQLzDBn3feN/NP3Njd3aRnIMO5K802jlTJRRZ8
 O8HOBZcq/7b5AXZFsa0sdGkADnpiACbP18CbIzFQQuSsdyCBxf7grYRE/LmXW6l4
 36wLc2P9eb/vTyShrhHdDKZgd8fAH3l8gN72KHAnrRtpk1O51JCDHMvJGrQMl7Ah
 V/jr60XSn/G+K/Hm8u3VcEJyOJssEXPXloKIkGnEqK2k+o1VoMFIr/vuA==
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=2rThejk/Rv4bfRg4HNaKxkPgmHJq/9H/EjksWtNdqKk=; b=R4btM7Hw
 6RX6+YcPZbjF6JHrg2XELlgClOEsRfKa1nhugsY+kn9c8CS0nRssenp+hdEgqF35
 fJcysbNETpVpDdwGYv+xb7/mGQiPTnguFM8v5JsbNn4RTZ4jnfU7bzYG/FODTyH2
 jN3+jCqSYspbOcqfQDPuuZ5wk37e4TVrY3gBDA3nbQ7uWgN9VsjNGpjjfkdUoRhc
 lpE7+Ng4aC8A1fGBiorQ3Ek740uE1JfkHXuWRBd/Oxzf/GFNbKIEGwQCmJYAwYbI
 bYVu7yStLaCC4WJ1Q7iszn334Yq9Wv+M6tVHkJqFbATo503IHllToY2xMR/MBhTX
 YKnNbHrBIXFZ2Q==
X-ME-Sender: <xms:uSNxX4bG-qkwEajjN87lpClYZA1fCUyBACn73Q-zglnbSpbkQyIXbA>
 <xme:uSNxXzYHoS2mwaclxaVvPZzW7DKtYQ3_-ZYnAl5xUDvzg-COfWtWJMn7duUZmNE9N
 vJKANYT4oTinClUtQ>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvdehgddvhecutefuodetggdotefrodftvf
 curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu
 uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc
 fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhmrghs
 ucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenucggtf
 frrghtthgvrhhnpedvhefgiedvjeegtdevheefhfetleefgfeivefgffevfeejgedtgfeu
 tdehtdegveenucfkphepjeejrddufeegrddvtdefrddukeegnecuvehluhhsthgvrhfuih
 iivgepudeknecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhomhgrshesmhhonhhjrghl
 ohhnrdhnvght
X-ME-Proxy: <xmx:uSNxXy_uMovRBTIzA4HFDKVuXxLsGIfwk_acjPoV4Ae1VBQekSofpA>
 <xmx:uSNxXyoQ5aARkVsoR16ExxqfXQTj_Hy5w2imaV0xKYIpY_l-nV29PA>
 <xmx:uSNxXzpiCd3k-aWAQtovyDneHQI0VkL-Dtxse5XPxNi8CrJ2Xtf9zg>
 <xmx:uiNxXwj31AQ2srlNuwTmnZxzwa_nEV3LO722_wMtuuBF9HfVEgOVKg>
Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184])
 by mail.messagingengine.com (Postfix) with ESMTPA id 7B49F328005A;
 Sun, 27 Sep 2020 19:43:52 -0400 (EDT)
From: Thomas Monjalon <thomas@monjalon.net>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, arybchenko@solarflare.com,
 Rosen Xu <rosen.xu@intel.com>, Stephen Hemminger <sthemmin@microsoft.com>,
 "K. Y. Srinivasan" <kys@microsoft.com>,
 Haiyang Zhang <haiyangz@microsoft.com>, Long Li <longli@microsoft.com>,
 Heinrich Kuhn <heinrich.kuhn@netronome.com>,
 Gagandeep Singh <g.singh@nxp.com>, Akhil Goyal <akhil.goyal@nxp.com>,
 Martin Spinler <spinler@cesnet.cz>,
 Anatoly Burakov <anatoly.burakov@intel.com>
Date: Mon, 28 Sep 2020 01:42:42 +0200
Message-Id: <20200927234249.3198780-19-thomas@monjalon.net>
X-Mailer: git-send-email 2.28.0
In-Reply-To: <20200927234249.3198780-1-thomas@monjalon.net>
References: <20200913220711.3768597-1-thomas@monjalon.net>
 <20200927234249.3198780-1-thomas@monjalon.net>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Subject: [dpdk-dev] [PATCH v2 18/25] drivers/net: accept removing device
	without any port
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>

The ports can be closed (i.e. completely released)
before removing the whole device.
Such case was wrongly considered an error by some drivers.

If the device supports only one port, there is nothing much
to free after the port is closed.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
Reviewed-by: Rosen Xu <rosen.xu@intel.com>
---
 drivers/net/ipn3ke/ipn3ke_ethdev.c      |  6 ++----
 drivers/net/kni/rte_eth_kni.c           | 16 +++++++---------
 drivers/net/netvsc/hn_ethdev.c          |  2 +-
 drivers/net/nfp/nfp_net.c               |  2 ++
 drivers/net/pfe/pfe_ethdev.c            |  6 ++----
 drivers/net/szedata2/rte_eth_szedata2.c |  6 ++----
 6 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/drivers/net/ipn3ke/ipn3ke_ethdev.c b/drivers/net/ipn3ke/ipn3ke_ethdev.c
index 027be29bd8..4446d2af9e 100644
--- a/drivers/net/ipn3ke/ipn3ke_ethdev.c
+++ b/drivers/net/ipn3ke/ipn3ke_ethdev.c
@@ -562,10 +562,8 @@ static int ipn3ke_vswitch_remove(struct rte_afu_device *afu_dev)
 			afu_dev->device.name, i);
 
 		ethdev = rte_eth_dev_allocated(afu_dev->device.name);
-		if (!ethdev)
-			return -ENODEV;
-
-		rte_eth_dev_destroy(ethdev, ipn3ke_rpst_uninit);
+		if (ethdev != NULL)
+			rte_eth_dev_destroy(ethdev, ipn3ke_rpst_uninit);
 	}
 
 	ret = rte_eth_switch_domain_free(hw->switch_domain_id);
diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c
index 45ab1b17a8..2a4058f7b0 100644
--- a/drivers/net/kni/rte_eth_kni.c
+++ b/drivers/net/kni/rte_eth_kni.c
@@ -488,17 +488,15 @@ eth_kni_remove(struct rte_vdev_device *vdev)
 
 	/* find the ethdev entry */
 	eth_dev = rte_eth_dev_allocated(name);
-	if (eth_dev == NULL)
-		return -1;
-
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
-		eth_kni_dev_stop(eth_dev);
-		return rte_eth_dev_release_port(eth_dev);
+	if (eth_dev != NULL) {
+		if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
+			eth_kni_dev_stop(eth_dev);
+			return rte_eth_dev_release_port(eth_dev);
+		}
+		eth_kni_close(eth_dev);
+		rte_eth_dev_release_port(eth_dev);
 	}
 
-	eth_kni_close(eth_dev);
-	rte_eth_dev_release_port(eth_dev);
-
 	is_kni_initialized--;
 	if (is_kni_initialized == 0)
 		rte_kni_close();
diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.c
index 15d6e9762d..19a9eb6bc2 100644
--- a/drivers/net/netvsc/hn_ethdev.c
+++ b/drivers/net/netvsc/hn_ethdev.c
@@ -1092,7 +1092,7 @@ static int eth_hn_remove(struct rte_vmbus_device *dev)
 
 	eth_dev = rte_eth_dev_allocated(dev->device.name);
 	if (!eth_dev)
-		return -ENODEV;
+		return 0; /* port already released */
 
 	ret = eth_hn_dev_uninit(eth_dev);
 	if (ret)
diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 9509dc8bd6..ce25cf1ed4 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -3739,6 +3739,8 @@ static int eth_nfp_pci_remove(struct rte_pci_device *pci_dev)
 	int port = 0;
 
 	eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
+	if (eth_dev == NULL)
+		return 0; /* port already released */
 	if ((pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC) ||
 	    (pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC)) {
 		port = get_pf_port_number(eth_dev->data->name);
diff --git a/drivers/net/pfe/pfe_ethdev.c b/drivers/net/pfe/pfe_ethdev.c
index 187a0019ff..9d5415d9b1 100644
--- a/drivers/net/pfe/pfe_ethdev.c
+++ b/drivers/net/pfe/pfe_ethdev.c
@@ -1155,10 +1155,8 @@ pmd_pfe_remove(struct rte_vdev_device *vdev)
 		return 0;
 
 	eth_dev = rte_eth_dev_allocated(name);
-	if (eth_dev == NULL)
-		return -ENODEV;
-
-	pfe_eth_exit(eth_dev, g_pfe);
+	if (eth_dev != NULL)
+		pfe_eth_exit(eth_dev, g_pfe);
 	munmap(g_pfe->cbus_baseaddr, g_pfe->cbus_size);
 
 	if (g_pfe->nb_devs == 0) {
diff --git a/drivers/net/szedata2/rte_eth_szedata2.c b/drivers/net/szedata2/rte_eth_szedata2.c
index 4325b9a30d..5f589dfa4c 100644
--- a/drivers/net/szedata2/rte_eth_szedata2.c
+++ b/drivers/net/szedata2/rte_eth_szedata2.c
@@ -1910,10 +1910,8 @@ static int szedata2_eth_pci_remove(struct rte_pci_device *pci_dev)
 				pci_dev->device.name, i);
 		PMD_DRV_LOG(DEBUG, "Removing eth_dev %s", name);
 		eth_dev = rte_eth_dev_allocated(name);
-		if (!eth_dev) {
-			PMD_DRV_LOG(ERR, "eth_dev %s not found", name);
-			retval = retval ? retval : -ENODEV;
-		}
+		if (eth_dev == NULL)
+			continue; /* port already released */
 
 		ret = rte_szedata2_eth_dev_uninit(eth_dev);
 		if (ret != 0) {
-- 
2.28.0