From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Cc: Thomas Monjalon <thomas.monjalon@6wind.com>,
Jingjing Wu <jingjing.wu@intel.com>
Subject: [dpdk-dev] [PATCH v2 2/3] ethdev: add device iterator
Date: Fri, 31 Mar 2017 14:04:38 +0200 [thread overview]
Message-ID: <3ae96511a71fa9f79be09eb518e7837c9a637599.1490961533.git.gaetan.rivet@6wind.com> (raw)
In-Reply-To: <cover.1488550937.git.gaetan.rivet@6wind.com>
In-Reply-To: <cover.1490961533.git.gaetan.rivet@6wind.com>
This iterator helps applications iterate over the device list and skip
holes caused by invalid or detached devices.
Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
lib/librte_ether/rte_ethdev.c | 17 ++++++++++++++---
lib/librte_ether/rte_ethdev.h | 21 ++++++++++++++++++++-
2 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 90d0713..ca7af35 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)
{
@@ -424,9 +437,7 @@ rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
return -ENODEV;
*port_id = RTE_MAX_ETHPORTS;
-
- for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-
+ RTE_ETH_FOREACH_DEV(i) {
if (!strncmp(name,
rte_eth_dev_data[i].name, strlen(name))) {
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index b9531f3..bed7dff 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1736,6 +1736,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 if 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); \
+ (unsigned int)p < (unsigned int)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
@@ -1743,7 +1762,7 @@ extern struct rte_eth_dev rte_eth_devices[];
* immediately after invoking rte_eal_init().
* If the application unplugs a port using hotplug function, The enabled port
* numbers may be noncontiguous. In the case, the applications need to manage
- * enabled port by themselves.
+ * enabled port by using the ``RTE_ETH_FOREACH_DEV()`` macro.
*
* @return
* - The total number of usable Ethernet devices.
--
2.1.4
next prev parent reply other threads:[~2017-03-31 12:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-03 15:40 [dpdk-dev] [PATCH 0/4] clarify eth_dev state management Gaetan Rivet
2017-03-03 15:40 ` [dpdk-dev] [PATCH 1/4] ethdev: expose device states Gaetan Rivet
2017-03-03 15:40 ` [dpdk-dev] [PATCH 2/4] ethdev: add device iterator Gaetan Rivet
2017-03-03 15:40 ` [dpdk-dev] [PATCH 3/4] ethdev: count devices consistently Gaetan Rivet
2017-03-30 19:26 ` Thomas Monjalon
2017-03-31 9:13 ` Gaëtan Rivet
2017-03-03 15:40 ` [dpdk-dev] [PATCH 4/4] app/testpmd: use ethdev iterator to list devices Gaetan Rivet
2017-03-31 12:04 ` [dpdk-dev] [PATCH v2 0/3] clarify eth_dev state management Gaetan Rivet
2017-03-31 12:04 ` [dpdk-dev] [PATCH v2 1/3] ethdev: expose device states Gaetan Rivet
2017-03-31 12:04 ` Gaetan Rivet [this message]
2017-04-05 20:42 ` [dpdk-dev] [PATCH v2 2/3] ethdev: add device iterator Thomas Monjalon
2017-03-31 12:04 ` [dpdk-dev] [PATCH v2 3/3] app/testpmd: use ethdev iterator to list devices Gaetan Rivet
2017-04-05 20:46 ` [dpdk-dev] [PATCH v2 0/3] clarify eth_dev state management Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3ae96511a71fa9f79be09eb518e7837c9a637599.1490961533.git.gaetan.rivet@6wind.com \
--to=gaetan.rivet@6wind.com \
--cc=dev@dpdk.org \
--cc=jingjing.wu@intel.com \
--cc=thomas.monjalon@6wind.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).