From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by dpdk.org (Postfix) with ESMTP id 52BC71E34 for ; Wed, 20 Feb 2019 23:11:12 +0100 (CET) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 5E93831F0; Wed, 20 Feb 2019 17:11:11 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 20 Feb 2019 17:11:11 -0500 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=mesmtp; bh=LQVWCBTkxF aKkcRlAWa/VqUPT5+gNtjDOgJHAmnCeC0=; b=EkqFoMAKAOWz/+hnb+sVRMax+t 2nFfQ5yD0QGQjfjmxdm87GfwEZBA9Qw0AD66Cfq4mNv7gYtc36AUAu5K3HAxwxJd wofye7vzGpTONlTgK6uIZGHMGoh37XWR5u3/iwv5K6C/xsZu6nsXAKABreBT/iY3 UuvJGtFkWRbA4Dn+U= 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= fm2; bh=LQVWCBTkxFaKkcRlAWa/VqUPT5+gNtjDOgJHAmnCeC0=; b=BAkmQSIw xpKRJibtiJgWx7AE8gEJo7JBT3sI4S2RZkrqc1hjVZPmGCsh6BJ/Xp6Nie/wzs9r iwWr8Vgnf/uCeN6CIC0B4TzililC9q0Vee0a8BID58b8Nb2McZVlTJIrqbIxh8l3 i9PNnpvEsK/wrf4aontfWIIrMm25iZ3pxheYPFvRMI9kMrQc72N/ks3RfW3YFbDW VYI/Mp5Cfomfn1R0dAnLQ49ed0dCQoNDUsLpMQvpjNLOSLl8qnVYDBON40kvdHf3 Qw9UmNs8Ub1xnvUGDCpqqCkU+CITfrhYvXxs5bdV7fsOqc/BcJvF3XAPJSOfk/sv GvG3IWk0IKhnnQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrtdeigdduheekucdltddurdegtdelrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhht necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhm rghsucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenuc fkphepjeejrddufeegrddvtdefrddukeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpeht hhhomhgrshesmhhonhhjrghlohhnrdhnvghtnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id E117E10336; Wed, 20 Feb 2019 17:11:09 -0500 (EST) From: Thomas Monjalon To: Ferruh Yigit , Andrew Rybchenko Cc: dev@dpdk.org Date: Wed, 20 Feb 2019 23:10:49 +0100 Message-Id: <20190220221051.7928-3-thomas@monjalon.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190220221051.7928-1-thomas@monjalon.net> References: <20181130002716.27325-1-thomas@monjalon.net> <20190220221051.7928-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 2/4] ethdev: add siblings iterators 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: Wed, 20 Feb 2019 22:11:12 -0000 If multiple ports share the same hardware device (rte_device), they are siblings and can be found thanks to the new functions and loop macros. One iterator takes a port id as reference, while the other one directly refers to the parent device. The ownership is not checked because siblings may have different owners. Signed-off-by: Thomas Monjalon --- lib/librte_ethdev/rte_ethdev.c | 20 +++++++++++ lib/librte_ethdev/rte_ethdev.h | 46 ++++++++++++++++++++++++ lib/librte_ethdev/rte_ethdev_version.map | 2 ++ 3 files changed, 68 insertions(+) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index b3b2fb1dba..42154787f8 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -340,6 +340,26 @@ rte_eth_find_next(uint16_t port_id) return port_id; } +uint16_t __rte_experimental +rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent) +{ + while (port_id < RTE_MAX_ETHPORTS && + rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED && + rte_eth_devices[port_id].device != parent) + port_id++; + + if (port_id >= RTE_MAX_ETHPORTS) + return RTE_MAX_ETHPORTS; + + return port_id; +} + +uint16_t __rte_experimental +rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref) +{ + return rte_eth_find_next_of(port_id, rte_eth_devices[ref].device); +} + static void rte_eth_dev_shared_data_prepare(void) { diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index a3c864a134..a7c5c36277 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -1383,6 +1383,52 @@ uint16_t rte_eth_find_next(uint16_t port_id); #define RTE_ETH_FOREACH_DEV(p) \ RTE_ETH_FOREACH_DEV_OWNED_BY(p, RTE_ETH_DEV_NO_OWNER) +/** + * Iterates over ethdev ports of a specified device. + * + * @param port_id_start + * The id of the next possible valid port. + * @param parent + * The generic device behind the ports to iterate. + * @return + * Next port id of the device, RTE_MAX_ETHPORTS if there is none. + */ +__rte_experimental +uint16_t rte_eth_find_next_of(uint16_t port_id_start, + const struct rte_device *parent); + +/** + * Macro to iterate over all ethdev ports sharing the same rte_device + * as the specified port. + * Note: the specified port is part of the loop iterations. + */ +#define RTE_ETH_FOREACH_DEV_OF(p, parent) \ + for (p = rte_eth_find_next_of(0, parent); \ + p < RTE_MAX_ETHPORTS; \ + p = rte_eth_find_next_of(p + 1, parent)) + +/** + * Iterates over sibling ethdev ports (i.e. sharing the same rte_device). + * + * @param port_id_start + * The id of the next possible valid sibling port. + * @param ref + * The id of a reference port to compare rte_device with. + * @return + * Next sibling port id (or ref itself), RTE_MAX_ETHPORTS if there is none. + */ +__rte_experimental +uint16_t rte_eth_find_next_sibling(uint16_t port_id_start, uint16_t ref); + +/** + * Macro to iterate over all ethdev ports sharing the same rte_device + * as the specified port. + * Note: the specified port is part of the loop iterations. + */ +#define RTE_ETH_FOREACH_DEV_SIBLING(p, ref) \ + for (p = rte_eth_find_next_sibling(0, ref); \ + p < RTE_MAX_ETHPORTS; \ + p = rte_eth_find_next_sibling(p + 1, ref)) /** * @warning diff --git a/lib/librte_ethdev/rte_ethdev_version.map b/lib/librte_ethdev/rte_ethdev_version.map index 92ac3de250..b37a4167d7 100644 --- a/lib/librte_ethdev/rte_ethdev_version.map +++ b/lib/librte_ethdev/rte_ethdev_version.map @@ -245,6 +245,8 @@ EXPERIMENTAL { rte_eth_dev_owner_set; rte_eth_dev_owner_unset; rte_eth_dev_rx_intr_ctl_q_get_fd; + rte_eth_find_next_of; + rte_eth_find_next_sibling; rte_eth_switch_domain_alloc; rte_eth_switch_domain_free; rte_flow_conv; -- 2.20.1