From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by dpdk.org (Postfix) with ESMTP id 47C0C4C91 for ; Mon, 1 Apr 2019 04:27:27 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id C8E4221ADA; Sun, 31 Mar 2019 22:27:26 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 31 Mar 2019 22:27:26 -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=mesmtp; bh=UKuiSD+Ujj c2eeMVXzGHLYl/5C8iShIhuBy6awAD470=; b=rbx20xQlYhN3ULugw0+NG4KQuX YCo8M3bhT4U+1bKhCDfc3bF3c/EDeDNwMYBMe4jgDNyogqnhA/ft2dNs69KkJSyF +z5rEWN57S+j+i3sOY05GJsPBF6pC5P/EM0dQhQtmN+6KlKSlJj/QcIFi5j65XO4 PiOImtORJ0hg572As= 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=UKuiSD+Ujjc2eeMVXzGHLYl/5C8iShIhuBy6awAD470=; b=EQBAyJeK xU12QxtBPT1nacroDKDkk+L3WiVsCMuJ1Q3jU5nYNw+7RconqH4JH0kkja0p9FMX qC1TgZk/Yl8vRDTVkd1URgwrLtOa4yt3t3YsLH6d9X3sEHRv2r+N2wTEcr3BitWm 3Ex8C5vA8VHdkpb4w67ijT2AfdksYg5pVmH1HBjbjOZfdLF75baptJRytNQc+alr tQRBf4v0WNdZkkzZ0Zy6Ret66Tci5M1JftCagq7L3HJrNpcKwfQpyzpjxGFjJlml 5cNijH3y+2rrTTnb5FB7X+aWj3/PWjhAEhl6AZelwINKeIzlR/n1wuxnLtEEErcS a+c5wQAPB8iwVw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrleefgdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhmrghs ucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenucfkph epjeejrddufeegrddvtdefrddukeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhho mhgrshesmhhonhhjrghlohhnrdhnvghtnecuvehluhhsthgvrhfuihiivgepvd 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 DEA4C10392; Sun, 31 Mar 2019 22:27:25 -0400 (EDT) From: Thomas Monjalon To: gaetan.rivet@6wind.com, Ferruh Yigit , Andrew Rybchenko Cc: dev@dpdk.org Date: Mon, 1 Apr 2019 04:26:58 +0200 Message-Id: <20190401022700.1570-3-thomas@monjalon.net> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401022700.1570-1-thomas@monjalon.net> References: <20181130002716.27325-1-thomas@monjalon.net> <20190401022700.1570-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 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: Mon, 01 Apr 2019 02:27:27 -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 --- v2: Reviewed-by: Andrew Rybchenko - not kept because of changes in v3 v3: - fix logic + re-use rte_eth_find_next() - longer parameter names - more and better doxygen comments --- lib/librte_ethdev/rte_ethdev.c | 19 +++++++ lib/librte_ethdev/rte_ethdev.h | 63 ++++++++++++++++++++++++ lib/librte_ethdev/rte_ethdev_version.map | 2 + 3 files changed, 84 insertions(+) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 33cffc498..3b125a642 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -339,6 +339,25 @@ 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) +{ + port_id = rte_eth_find_next(port_id); + while (port_id < RTE_MAX_ETHPORTS && + rte_eth_devices[port_id].device != parent) + port_id = rte_eth_find_next(port_id + 1); + + return port_id; +} + +uint16_t __rte_experimental +rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref_port_id) +{ + RTE_ETH_VALID_PORTID_OR_ERR_RET(ref_port_id, RTE_MAX_ETHPORTS); + return rte_eth_find_next_of(port_id, + rte_eth_devices[ref_port_id].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 b6023c050..3d5bacaee 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -1387,6 +1387,69 @@ 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) +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * 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, possibly port_id_start, + * 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 of a specified device. + * + * @param port_id + * The id of the matching port being iterated. + * @param parent + * The rte_device pointer matching the iterated ports. + */ +#define RTE_ETH_FOREACH_DEV_OF(port_id, parent) \ + for (port_id = rte_eth_find_next_of(0, parent); \ + port_id < RTE_MAX_ETHPORTS; \ + port_id = rte_eth_find_next_of(port_id + 1, parent)) + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * 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_port_id + * The id of a reference port to compare rte_device with. + * @return + * Next sibling port id, possibly port_id_start or ref_port_id 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_port_id); + +/** + * Macro to iterate over all ethdev ports sharing the same rte_device + * as the specified port. + * Note: the specified reference port is part of the loop iterations. + * + * @param port_id + * The id of the matching port being iterated. + * @param ref_port_id + * The id of the port being compared. + */ +#define RTE_ETH_FOREACH_DEV_SIBLING(port_id, ref_port_id) \ + for (port_id = rte_eth_find_next_sibling(0, ref_port_id); \ + port_id < RTE_MAX_ETHPORTS; \ + port_id = rte_eth_find_next_sibling(port_id + 1, ref_port_id)) /** * @warning diff --git a/lib/librte_ethdev/rte_ethdev_version.map b/lib/librte_ethdev/rte_ethdev_version.map index 92ac3de25..b37a4167d 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.21.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 4B340A00B9 for ; Mon, 1 Apr 2019 04:27:36 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6A4E04C9D; Mon, 1 Apr 2019 04:27:29 +0200 (CEST) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by dpdk.org (Postfix) with ESMTP id 47C0C4C91 for ; Mon, 1 Apr 2019 04:27:27 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id C8E4221ADA; Sun, 31 Mar 2019 22:27:26 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 31 Mar 2019 22:27:26 -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=mesmtp; bh=UKuiSD+Ujj c2eeMVXzGHLYl/5C8iShIhuBy6awAD470=; b=rbx20xQlYhN3ULugw0+NG4KQuX YCo8M3bhT4U+1bKhCDfc3bF3c/EDeDNwMYBMe4jgDNyogqnhA/ft2dNs69KkJSyF +z5rEWN57S+j+i3sOY05GJsPBF6pC5P/EM0dQhQtmN+6KlKSlJj/QcIFi5j65XO4 PiOImtORJ0hg572As= 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=UKuiSD+Ujjc2eeMVXzGHLYl/5C8iShIhuBy6awAD470=; b=EQBAyJeK xU12QxtBPT1nacroDKDkk+L3WiVsCMuJ1Q3jU5nYNw+7RconqH4JH0kkja0p9FMX qC1TgZk/Yl8vRDTVkd1URgwrLtOa4yt3t3YsLH6d9X3sEHRv2r+N2wTEcr3BitWm 3Ex8C5vA8VHdkpb4w67ijT2AfdksYg5pVmH1HBjbjOZfdLF75baptJRytNQc+alr tQRBf4v0WNdZkkzZ0Zy6Ret66Tci5M1JftCagq7L3HJrNpcKwfQpyzpjxGFjJlml 5cNijH3y+2rrTTnb5FB7X+aWj3/PWjhAEhl6AZelwINKeIzlR/n1wuxnLtEEErcS a+c5wQAPB8iwVw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrleefgdehlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfhhohhmrghs ucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenucfkph epjeejrddufeegrddvtdefrddukeegnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhho mhgrshesmhhonhhjrghlohhnrdhnvghtnecuvehluhhsthgvrhfuihiivgepvd 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 DEA4C10392; Sun, 31 Mar 2019 22:27:25 -0400 (EDT) From: Thomas Monjalon To: gaetan.rivet@6wind.com, Ferruh Yigit , Andrew Rybchenko Cc: dev@dpdk.org Date: Mon, 1 Apr 2019 04:26:58 +0200 Message-Id: <20190401022700.1570-3-thomas@monjalon.net> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401022700.1570-1-thomas@monjalon.net> References: <20181130002716.27325-1-thomas@monjalon.net> <20190401022700.1570-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190401022658.MF-H90vZ2_9172zXkpX9qXAa1v5CEk2jAuIWmWKT55A@z> 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 --- v2: Reviewed-by: Andrew Rybchenko - not kept because of changes in v3 v3: - fix logic + re-use rte_eth_find_next() - longer parameter names - more and better doxygen comments --- lib/librte_ethdev/rte_ethdev.c | 19 +++++++ lib/librte_ethdev/rte_ethdev.h | 63 ++++++++++++++++++++++++ lib/librte_ethdev/rte_ethdev_version.map | 2 + 3 files changed, 84 insertions(+) diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 33cffc498..3b125a642 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -339,6 +339,25 @@ 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) +{ + port_id = rte_eth_find_next(port_id); + while (port_id < RTE_MAX_ETHPORTS && + rte_eth_devices[port_id].device != parent) + port_id = rte_eth_find_next(port_id + 1); + + return port_id; +} + +uint16_t __rte_experimental +rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref_port_id) +{ + RTE_ETH_VALID_PORTID_OR_ERR_RET(ref_port_id, RTE_MAX_ETHPORTS); + return rte_eth_find_next_of(port_id, + rte_eth_devices[ref_port_id].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 b6023c050..3d5bacaee 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -1387,6 +1387,69 @@ 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) +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * 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, possibly port_id_start, + * 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 of a specified device. + * + * @param port_id + * The id of the matching port being iterated. + * @param parent + * The rte_device pointer matching the iterated ports. + */ +#define RTE_ETH_FOREACH_DEV_OF(port_id, parent) \ + for (port_id = rte_eth_find_next_of(0, parent); \ + port_id < RTE_MAX_ETHPORTS; \ + port_id = rte_eth_find_next_of(port_id + 1, parent)) + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * 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_port_id + * The id of a reference port to compare rte_device with. + * @return + * Next sibling port id, possibly port_id_start or ref_port_id 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_port_id); + +/** + * Macro to iterate over all ethdev ports sharing the same rte_device + * as the specified port. + * Note: the specified reference port is part of the loop iterations. + * + * @param port_id + * The id of the matching port being iterated. + * @param ref_port_id + * The id of the port being compared. + */ +#define RTE_ETH_FOREACH_DEV_SIBLING(port_id, ref_port_id) \ + for (port_id = rte_eth_find_next_sibling(0, ref_port_id); \ + port_id < RTE_MAX_ETHPORTS; \ + port_id = rte_eth_find_next_sibling(port_id + 1, ref_port_id)) /** * @warning diff --git a/lib/librte_ethdev/rte_ethdev_version.map b/lib/librte_ethdev/rte_ethdev_version.map index 92ac3de25..b37a4167d 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.21.0