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 E042243D1E; Fri, 22 Mar 2024 08:09:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 68A7842E8A; Fri, 22 Mar 2024 08:09:32 +0100 (CET) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by mails.dpdk.org (Postfix) with ESMTP id A581042E62 for ; Fri, 22 Mar 2024 08:09:26 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4V1D095XF8z1R7lC; Fri, 22 Mar 2024 15:06:49 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id 29127140133; Fri, 22 Mar 2024 15:09:25 +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 4/6] net/hns3: use parse link mode info function Date: Fri, 22 Mar 2024 15:09:21 +0800 Message-ID: <20240322070923.244417-5-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 This patch use the framework public function to replace the driver's private function. Signed-off-by: Dengdui Huang --- drivers/net/hns3/hns3_ethdev.c | 51 +++++++--------------------------- 1 file changed, 10 insertions(+), 41 deletions(-) diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c index ecd3b2ef64..1b380ac75f 100644 --- a/drivers/net/hns3/hns3_ethdev.c +++ b/drivers/net/hns3/hns3_ethdev.c @@ -4810,45 +4810,6 @@ hns3_check_port_speed(struct hns3_hw *hw, uint32_t link_speeds) return 0; } -static uint32_t -hns3_get_link_speed(uint32_t link_speeds) -{ - uint32_t speed = RTE_ETH_SPEED_NUM_NONE; - - if (link_speeds & RTE_ETH_LINK_SPEED_10M || - link_speeds & RTE_ETH_LINK_SPEED_10M_HD) - speed = RTE_ETH_SPEED_NUM_10M; - if (link_speeds & RTE_ETH_LINK_SPEED_100M || - link_speeds & RTE_ETH_LINK_SPEED_100M_HD) - speed = RTE_ETH_SPEED_NUM_100M; - if (link_speeds & RTE_ETH_LINK_SPEED_1G) - speed = RTE_ETH_SPEED_NUM_1G; - if (link_speeds & RTE_ETH_LINK_SPEED_10G) - speed = RTE_ETH_SPEED_NUM_10G; - if (link_speeds & RTE_ETH_LINK_SPEED_25G) - speed = RTE_ETH_SPEED_NUM_25G; - if (link_speeds & RTE_ETH_LINK_SPEED_40G) - speed = RTE_ETH_SPEED_NUM_40G; - if (link_speeds & RTE_ETH_LINK_SPEED_50G) - speed = RTE_ETH_SPEED_NUM_50G; - if (link_speeds & RTE_ETH_LINK_SPEED_100G) - speed = RTE_ETH_SPEED_NUM_100G; - if (link_speeds & RTE_ETH_LINK_SPEED_200G) - speed = RTE_ETH_SPEED_NUM_200G; - - return speed; -} - -static uint8_t -hns3_get_link_duplex(uint32_t link_speeds) -{ - if ((link_speeds & RTE_ETH_LINK_SPEED_10M_HD) || - (link_speeds & RTE_ETH_LINK_SPEED_100M_HD)) - return RTE_ETH_LINK_HALF_DUPLEX; - else - return RTE_ETH_LINK_FULL_DUPLEX; -} - static int hns3_set_copper_port_link_speed(struct hns3_hw *hw, struct hns3_set_link_speed_cfg *cfg) @@ -4980,14 +4941,22 @@ static int hns3_apply_link_speed(struct hns3_hw *hw) { struct rte_eth_conf *conf = &hw->data->dev_conf; + struct rte_eth_link_mode_info mode_info = {0}; struct hns3_set_link_speed_cfg cfg; + int ret; memset(&cfg, 0, sizeof(struct hns3_set_link_speed_cfg)); cfg.autoneg = (conf->link_speeds == RTE_ETH_LINK_SPEED_AUTONEG) ? RTE_ETH_LINK_AUTONEG : RTE_ETH_LINK_FIXED; if (cfg.autoneg != RTE_ETH_LINK_AUTONEG) { - cfg.speed = hns3_get_link_speed(conf->link_speeds); - cfg.duplex = hns3_get_link_duplex(conf->link_speeds); + ret = rte_eth_link_mode_parse(conf->link_speeds, &mode_info); + if (ret) { + hns3_err(hw, "failed to parse link mode, ret = %d", ret); + return ret; + } + cfg.speed = mode_onfo.speed_num; + cfg.speed = mode_info.speed_num; + cfg.duplex = mode_info.duplex; } return hns3_set_port_link_speed(hw, &cfg); -- 2.33.0