From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gaetan.rivet@6wind.com>
Received: from mail-wr0-f181.google.com (mail-wr0-f181.google.com
 [209.85.128.181]) by dpdk.org (Postfix) with ESMTP id DABA92B94
 for <dev@dpdk.org>; Fri,  3 Mar 2017 16:40:25 +0100 (CET)
Received: by mail-wr0-f181.google.com with SMTP id g10so76171034wrg.2
 for <dev@dpdk.org>; Fri, 03 Mar 2017 07:40:25 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=6wind-com.20150623.gappssmtp.com; s=20150623;
 h=from:to:subject:date:message-id:in-reply-to:references;
 bh=Ki/68xsJla+Bi59xSg8PnS3XcVqn51wv1p4YRFu+yIY=;
 b=Nce++My2Y9TgEZ6mK5q9Vec6LY78f1h7UsPgPLGcAUEHKvZ8A9OwavsA+8Sri4lwpg
 NdfgQFeYYuvDeFfYm9u4Sjf1/izvb9ierYqOvEi4qEOsVsEg34peWDImI0V5nq8obW0p
 895HkcgkwRi2mDJCuEdlCLCip/L6Hh9ci6NVeGsUxX+126mrIu4hkT26NdOxyVxpQfUT
 riwfueA+st3ItWxspJVqmyw42MnlU2vk6QW4Hu51vMwkV1BAOs4az4/A4tGH63kkz/ud
 I6mWcRwYBNqR6Z6XoIlOKRoNtejEeZs2zvze92K6fknlEa5lxg/FHgHCKg9np3xzfrJV
 ZosA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
 :references;
 bh=Ki/68xsJla+Bi59xSg8PnS3XcVqn51wv1p4YRFu+yIY=;
 b=Z3Ep7hkyc436DeN6jubwvHqGcWqsyVFiXCd3E4zHl00MLt33jv7K5SwdmVNPwjXoGj
 Czc3/VmJGWVB0DOfDX/TNyH6YmBo7Pz/A3tyHG/SIy3KrIiqQmtDKFpyfYa6lHt7Vx7m
 qetq60MkdOHu84m9m84ZKP3Ung1E88Z6H/hvwOR2q6OtpkT+7kkICwtiyJoLYAYzFOOY
 VxB36FIplf2bv/mYqeCFl8CmbJTU/imBCwdEMF4NwBBVbFnaVeLE3we0itEBw0Oz158m
 SShPwiLbGGFnzRiIAG5cXPOBNQIkSmtOWs7MRDmgbdbxUP6K/Fq1rauYgWabJxD96gR2
 eJ7w==
X-Gm-Message-State: AMke39mt4w1b2KQALwCAvfuDQd6R0PRIJURworc7asYpwpxRZc1NGXoLVJcVrBvS/hmrKvDY
X-Received: by 10.223.182.133 with SMTP id j5mr3593847wre.19.1488555625395;
 Fri, 03 Mar 2017 07:40:25 -0800 (PST)
Received: from bidouze.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com.
 [62.23.145.78])
 by smtp.gmail.com with ESMTPSA id k195sm3513175wmd.7.2017.03.03.07.40.24
 for <dev@dpdk.org>
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Fri, 03 Mar 2017 07:40:25 -0800 (PST)
From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Date: Fri,  3 Mar 2017 16:40:10 +0100
Message-Id: <673f83e0ddb94ef58038286b3794ff2f3b0eec2a.1488550937.git.gaetan.rivet@6wind.com>
X-Mailer: git-send-email 2.1.4
In-Reply-To: <cover.1488550937.git.gaetan.rivet@6wind.com>
References: <cover.1488550937.git.gaetan.rivet@6wind.com>
Subject: [dpdk-dev] [PATCH 1/4] ethdev: expose device states
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Fri, 03 Mar 2017 15:40:26 -0000

The hotplug API introduced multiple states for a device with possible
values defined internally, while the related field in struct rte_eth_dev
was made public.

Exposing those states improves consistency because applications have to
deal with the device list directly.

"DEV_DETACHED" is renamed "RTE_ETH_DEV_UNUSED" to better reflect that
the emptiness of a slot is not necessarily the result of detaching a
device.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_ether/rte_ethdev.c | 15 +++++----------
 lib/librte_ether/rte_ethdev.h | 10 +++++++++-
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index f3c32c4..d5d1b52 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -138,11 +138,6 @@ enum {
 	STAT_QMAP_RX
 };
 
-enum {
-	DEV_DETACHED = 0,
-	DEV_ATTACHED
-};
-
 static void
 rte_eth_dev_data_alloc(void)
 {
@@ -170,7 +165,7 @@ rte_eth_dev_allocated(const char *name)
 	unsigned i;
 
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-		if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
+		if ((rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED) &&
 		    strcmp(rte_eth_devices[i].data->name, name) == 0)
 			return &rte_eth_devices[i];
 	}
@@ -183,7 +178,7 @@ rte_eth_dev_find_free_port(void)
 	unsigned i;
 
 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-		if (rte_eth_devices[i].attached == DEV_DETACHED)
+		if (rte_eth_devices[i].state == RTE_ETH_DEV_UNUSED)
 			return i;
 	}
 	return RTE_MAX_ETHPORTS;
@@ -195,7 +190,7 @@ eth_dev_get(uint8_t port_id)
 	struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
 
 	eth_dev->data = &rte_eth_dev_data[port_id];
-	eth_dev->attached = DEV_ATTACHED;
+	eth_dev->state = RTE_ETH_DEV_ATTACHED;
 	TAILQ_INIT(&(eth_dev->link_intr_cbs));
 
 	eth_dev_last_created_port = port_id;
@@ -271,7 +266,7 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
 	if (eth_dev == NULL)
 		return -EINVAL;
 
-	eth_dev->attached = DEV_DETACHED;
+	eth_dev->state = RTE_ETH_DEV_UNUSED;
 	nb_ports--;
 	return 0;
 }
@@ -377,7 +372,7 @@ int
 rte_eth_dev_is_valid_port(uint8_t port_id)
 {
 	if (port_id >= RTE_MAX_ETHPORTS ||
-	    rte_eth_devices[port_id].attached != DEV_ATTACHED)
+	    rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
 		return 0;
 	else
 		return 1;
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 97f3e2d..d51b8e9 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1614,6 +1614,14 @@ struct rte_eth_rxtx_callback {
 };
 
 /**
+ * A set of values to describe the possible states of an eth device.
+ */
+enum rte_eth_dev_state {
+	RTE_ETH_DEV_UNUSED = 0,
+	RTE_ETH_DEV_ATTACHED,
+};
+
+/**
  * @internal
  * The generic data structure associated with each ethernet device.
  *
@@ -1644,7 +1652,7 @@ struct rte_eth_dev {
 	 * received packets before passing them to the driver for transmission.
 	 */
 	struct rte_eth_rxtx_callback *pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
-	uint8_t attached; /**< Flag indicating the port is attached */
+	enum rte_eth_dev_state state:8; /**< Flag indicating the port state */
 } __rte_cache_aligned;
 
 struct rte_eth_dev_sriov {
-- 
2.1.4