From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A35BF43D1E; Fri, 22 Mar 2024 08:09:33 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E631242E67; Fri, 22 Mar 2024 08:09:29 +0100 (CET) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id 489174003C for ; Fri, 22 Mar 2024 08:09:26 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4V1D2g4x2hz1GChm; Fri, 22 Mar 2024 15:08:59 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id EE73718005F; Fri, 22 Mar 2024 15:09:24 +0800 (CST) Received: from localhost.huawei.com (10.50.165.33) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Fri, 22 Mar 2024 15:09:24 +0800 From: Dengdui Huang To: CC: , , , , , , , , , , , , Subject: [PATCH v2 3/6] ethdev: add function to parse link mode info Date: Fri, 22 Mar 2024 15:09:20 +0800 Message-ID: <20240322070923.244417-4-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240322070923.244417-1-huangdengdui@huawei.com> References: <20240312075238.3319480-4-huangdengdui@huawei.com> <20240322070923.244417-1-huangdengdui@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500011.china.huawei.com (7.185.36.84) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Added function rte_eth_link_mode_parse() to parse the speed number, lanes and duplex parameters from the Link speed apabilities bitmap flags. Signed-off-by: Dengdui Huang --- doc/guides/rel_notes/release_24_03.rst | 3 + lib/ethdev/rte_ethdev.c | 199 +++++++++++++++++++++++++ lib/ethdev/rte_ethdev.h | 29 ++++ lib/ethdev/version.map | 1 + 4 files changed, 232 insertions(+) diff --git a/doc/guides/rel_notes/release_24_03.rst b/doc/guides/rel_notes/release_24_03.rst index 4621689c68..b41b0028b2 100644 --- a/doc/guides/rel_notes/release_24_03.rst +++ b/doc/guides/rel_notes/release_24_03.rst @@ -78,6 +78,9 @@ New Features * **Support setting lanes for ethdev.** * Support setting lanes by extended ``RTE_ETH_LINK_SPEED_*``. + * Added function to parse the speed number, lanes and duplex parameters from + * the Link speed apabilities bitmap flags: + ``rte_eth_link_mode_parse()`` * **Added hash calculation of an encapsulated packet as done by the HW.** diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 6571116fbf..bac7c652be 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -1105,6 +1105,205 @@ rte_eth_dev_rx_offload_name(uint64_t offload) return name; } +int +rte_eth_link_mode_parse(uint32_t link_speed, + struct rte_eth_link_mode_info *mode_onfo) +{ + const struct { + uint32_t speed_capa; + struct rte_eth_link_mode_info mode_onfo; + } speed_mode_onfo_map[] = { + { + RTE_ETH_LINK_SPEED_10M_HD, + { + RTE_ETH_SPEED_NUM_10M, + RTE_ETH_LANES_1, + RTE_ETH_LINK_HALF_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_10M, + { + RTE_ETH_SPEED_NUM_10M, + RTE_ETH_LANES_1, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_100M_HD, + { + RTE_ETH_SPEED_NUM_100M, + RTE_ETH_LANES_1, + RTE_ETH_LINK_HALF_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_100M, + { + RTE_ETH_SPEED_NUM_100M, + RTE_ETH_LANES_1, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_1G, + { + RTE_ETH_SPEED_NUM_1G, + RTE_ETH_LANES_1, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_2_5G, + { + RTE_ETH_SPEED_NUM_2_5G, + RTE_ETH_LANES_1, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_5G, + { + RTE_ETH_SPEED_NUM_5G, + RTE_ETH_LANES_1, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_10G, + { + RTE_ETH_SPEED_NUM_10G, + RTE_ETH_LANES_1, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_20G_2LANES, + { + RTE_ETH_SPEED_NUM_20G, + RTE_ETH_LANES_2, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_25G, + { + RTE_ETH_SPEED_NUM_25G, + RTE_ETH_LANES_1, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_40G_4LANES, + { + RTE_ETH_SPEED_NUM_40G, + RTE_ETH_LANES_4, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_50G, + { + RTE_ETH_SPEED_NUM_50G, + RTE_ETH_LANES_1, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_56G_4LANES, + { + RTE_ETH_SPEED_NUM_56G, + RTE_ETH_LANES_4, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_100G, + { + RTE_ETH_SPEED_NUM_100G, + RTE_ETH_LANES_1, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_200G_4LANES, + { + RTE_ETH_SPEED_NUM_200G, + RTE_ETH_LANES_4, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_400G_4LANES, + { + RTE_ETH_SPEED_NUM_400G, + RTE_ETH_LANES_4, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_10G_4LANES, + { + RTE_ETH_SPEED_NUM_10G, + RTE_ETH_LANES_4, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_50G_2LANES, + { + RTE_ETH_SPEED_NUM_50G, + RTE_ETH_LANES_2, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_100G_2LANES, + { + RTE_ETH_SPEED_NUM_100G, + RTE_ETH_LANES_2, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_100G_4LANES, + { + RTE_ETH_SPEED_NUM_100G, + RTE_ETH_LANES_4, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_200G_2LANES, + { + RTE_ETH_SPEED_NUM_200G, + RTE_ETH_LANES_2, + RTE_ETH_LINK_FULL_DUPLEX + } + }, + { + RTE_ETH_LINK_SPEED_400G_8LANES, + { + RTE_ETH_SPEED_NUM_400G, + RTE_ETH_LANES_8, + RTE_ETH_LINK_FULL_DUPLEX + } + } + }; + uint32_t i; + + for (i = 0; i < RTE_DIM(speed_mode_onfo_map); i++) { + if (link_speed == speed_mode_onfo_map[i].speed_capa) { + mode_onfo->speed_num = speed_mode_onfo_map[i].mode_onfo.speed_num; + mode_onfo->lanes = speed_mode_onfo_map[i].mode_onfo.lanes; + mode_onfo->duplex = speed_mode_onfo_map[i].mode_onfo.duplex; + return 0; + } + } + + return -EINVAL; +} + const char * rte_eth_dev_tx_offload_name(uint64_t offload) { diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index 123b771046..b7aacf6da8 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -355,6 +355,15 @@ struct rte_eth_stats { #define RTE_ETH_LANES_8 8 /**< 8 lanes */ /**@}*/ +/** + * A structure used to store information of link mode. + */ +struct rte_eth_link_mode_info { + uint32_t speed_num; /**< RTE_ETH_SPEED_NUM_ */ + uint8_t lanes; /**< RTE_ETH_LANES_ */ + uint8_t duplex; /**< RTE_ETH_LINK_[HALF/FULL]_DUPLEX */ +}; + /** * A structure used to retrieve link-level information of an Ethernet port. */ @@ -2345,6 +2354,26 @@ uint16_t rte_eth_dev_count_total(void); */ uint32_t rte_eth_speed_bitflag(uint32_t speed, uint8_t lanes, int duplex); +/** + * @warning + * @b EXPERIMENTAL: this API may change, or be removed, without prior notice + * + * Parse the speed number, lanes and duplex parameters from the Link speed + * capabilities bitmap flags. + * + * @param link_speed + * speed capabilities bitmap flag (RTE_ETH_LINK_SPEED_) + * @param mode_onfo + * A pointer to a structure of type *rte_eth_link_mode_info* to be filled + * with the information of link mode. + * @return + * - (0) if successful. + * - (-EINVAL) if bad parameter. + */ +__rte_experimental +int rte_eth_link_mode_parse(uint32_t link_speed, + struct rte_eth_link_mode_info *mode_info); + /** * Get RTE_ETH_RX_OFFLOAD_* flag name. * diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map index 9fa2439976..5726498dd1 100644 --- a/lib/ethdev/version.map +++ b/lib/ethdev/version.map @@ -326,6 +326,7 @@ EXPERIMENTAL { # added in 24.03 __rte_eth_trace_tx_queue_count; rte_eth_find_rss_algo; + rte_eth_link_mode_parse; rte_flow_async_update_resized; rte_flow_calc_encap_hash; rte_flow_template_table_resizable; -- 2.33.0