From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f49.google.com (mail-wm0-f49.google.com [74.125.82.49]) by dpdk.org (Postfix) with ESMTP id BE6D7D592 for ; Fri, 3 Mar 2017 16:40:26 +0100 (CET) Received: by mail-wm0-f49.google.com with SMTP id n11so18285073wma.1 for ; Fri, 03 Mar 2017 07:40:26 -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=zBS7TwYSXee51eFYq3n/Z8zha8cKDBBcP5L0m2p0QgQ=; b=Gqvefzxl6eukLM5WYJrKpoSaeqg8RxmWerrz7N6zRkF+B1Ir3rv26b9jLSQfS7jJie ZspadXYQQQI3dih2YqTm65XAvaL3Ifg0oZRgiPHgMeBSbvckOEBwDs6NwvFtpvc3jo5I FQSBoTTyBdFrmOrTEIkGce5tZ620woKuMs4JO5Xv3juD0NjH3+E9arJtbkm6wIeREH1F NVWDm5Gdp92pEcW7LAjQEWwjm36xERIeaKFRLJ6Mcq1VXFZ95et79Ez4+bD9I16ODqEg G6BCnNaZpiku6OfYWGpaqcs8qsT8h6DmzWcepKb+yfimmiE2AnEhPhr0e0aKFxg+YcrI HSuw== 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=zBS7TwYSXee51eFYq3n/Z8zha8cKDBBcP5L0m2p0QgQ=; b=IjcfWLj3lLe/DM3+PoRxm0vS8FxvyXODP9jDWuFX/2edyHanaD2UzhgjQ2FrExXDp5 z4v4/fc8wDJSzAan3/CBD+za5WZGZE3NRPKQC9FnwsEkb+gBOxw7yiyL1/x2tmKEjizg cFBp3KbLTA+1B64ueyArFfQb/GsSqFxDAS2FC0kQSvT7z2PdjrfYhL1VIr/OizUpvqiY UkwoReL29kx5m8r9Xzul88JT2dVZV4IPA91KnhJtsij7H9uQ/K0JS41saVOimUFI2ZKy oYijjpGhNjkdXECLMFl8eNYARWZlNR81l8Z6QntXC7uU0kwukXD7ocbZXwnXLTDlliem a1KQ== X-Gm-Message-State: AMke39nB2MwlVrArmeT6iWXJCIk5tjEEslgYLLAaZb6yHvNEeb3lIc+OPR1O9NiimGojR43m X-Received: by 10.28.103.3 with SMTP id b3mr3378140wmc.99.1488555626171; Fri, 03 Mar 2017 07:40:26 -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.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Mar 2017 07:40:25 -0800 (PST) From: Gaetan Rivet To: dev@dpdk.org Date: Fri, 3 Mar 2017 16:40:11 +0100 Message-Id: <4b24ee0f847868d26edee14d09ca2455894201a9.1488550937.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: Subject: [dpdk-dev] [PATCH 2/4] ethdev: add device iterator X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Mar 2017 15:40:27 -0000 This iterator helps applications iterate over the device list and skip holes caused by invalid or detached devices. Signed-off-by: Gaetan Rivet --- lib/librte_ether/rte_ethdev.c | 13 +++++++++++++ lib/librte_ether/rte_ethdev.h | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index d5d1b52..fcb9933 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -138,6 +138,19 @@ enum { STAT_QMAP_RX }; +uint8_t +rte_eth_find_next(uint8_t port_id) +{ + while (port_id < RTE_MAX_ETHPORTS && + rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED) + port_id++; + + if (port_id >= RTE_MAX_ETHPORTS) + return RTE_MAX_ETHPORTS; + + return port_id; +} + static void rte_eth_dev_data_alloc(void) { diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index d51b8e9..59c4123 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1731,6 +1731,25 @@ struct rte_eth_dev_data { extern struct rte_eth_dev rte_eth_devices[]; /** + * Iterates over valid ethdev ports. + * + * @param: port_id + * The id of the next possible valid port. + * @return + * Next valid port id, RTE_MAX_ETHPORTS is there is none. + */ +uint8_t rte_eth_find_next(uint8_t port_id); + +/** + * Macro to iterate over all enabled ethdev ports. + */ +#define RTE_ETH_FOREACH_DEV(p) \ + for (p = rte_eth_find_next(0); \ + p < RTE_MAX_ETHPORTS; \ + p = rte_eth_find_next(p + 1)) + + +/** * Get the total number of Ethernet devices that have been successfully * initialized by the [matching] Ethernet driver during the PCI probing phase. * All devices whose port identifier is in the range -- 2.1.4