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 96131A0547; Mon, 19 Apr 2021 08:21:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 710434119F; Mon, 19 Apr 2021 08:21:39 +0200 (CEST) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by mails.dpdk.org (Postfix) with ESMTP id 2302F4118C for ; Mon, 19 Apr 2021 08:21:35 +0200 (CEST) Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FNxV75fszzBrPp for ; Mon, 19 Apr 2021 14:19:11 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.498.0; Mon, 19 Apr 2021 14:21:31 +0800 From: "Min Hu (Connor)" To: CC: , Date: Mon, 19 Apr 2021 14:21:42 +0800 Message-ID: <1618813303-32945-2-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1618813303-32945-1-git-send-email-humin29@huawei.com> References: <1618813303-32945-1-git-send-email-humin29@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH 1/2] app/testpmd: add link speed check before port start 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 Sender: "dev" From: Huisong Li Currently, to check whether the configured link_speeds is valid, we have to run "port start". In addition, if the configuration fails, "port->dev_conf.link_speeds" maintained in testpmd cannot be restored. This patch adds the link_speeds check before port start by calling dev_configure, and resolves these problems. Signed-off-by: Huisong Li Signed-off-by: Min Hu (Connor) --- app/test-pmd/cmdline.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 5bf1497..09e30cf 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -1537,8 +1537,12 @@ cmd_config_speed_all_parsed(void *parsed_result, __rte_unused void *data) { struct cmd_config_speed_all *res = parsed_result; + uint32_t old_link_speeds[RTE_MAX_ETHPORTS]; + struct rte_port *port; uint32_t link_speed; portid_t pid; + portid_t i; + int ret; if (!all_ports_stopped()) { printf("Please stop all ports first\n"); @@ -1550,7 +1554,26 @@ cmd_config_speed_all_parsed(void *parsed_result, return; RTE_ETH_FOREACH_DEV(pid) { - ports[pid].dev_conf.link_speeds = link_speed; + port = &ports[pid]; + old_link_speeds[pid] = port->dev_conf.link_speeds; + port->dev_conf.link_speeds = link_speed; + ret = rte_eth_dev_configure(pid, nb_rxq, nb_txq, + &port->dev_conf); + if (ret < 0) { + printf("Failed to check link speeds for port %d, ret = %d.\n", + pid, ret); + goto roolback; + } + } + + cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); + + return; + +roolback: + for (i = 0; i <= pid; i++) { + port = &ports[i]; + port->dev_conf.link_speeds = old_link_speeds[i]; } cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); @@ -1609,7 +1632,10 @@ cmd_config_speed_specific_parsed(void *parsed_result, __rte_unused void *data) { struct cmd_config_speed_specific *res = parsed_result; + uint32_t old_link_speeds; + struct rte_port *port; uint32_t link_speed; + int ret; if (!all_ports_stopped()) { printf("Please stop all ports first\n"); @@ -1623,7 +1649,17 @@ cmd_config_speed_specific_parsed(void *parsed_result, &link_speed) < 0) return; - ports[res->id].dev_conf.link_speeds = link_speed; + port = &ports[res->id]; + old_link_speeds = port->dev_conf.link_speeds; + port->dev_conf.link_speeds = link_speed; + ret = rte_eth_dev_configure(res->id, nb_rxq, nb_txq, + &port->dev_conf); + if (ret < 0) { + printf("Failed to check link speeds for port %d, ret = %d.\n", + res->id, ret); + port->dev_conf.link_speeds = old_link_speeds; + return; + } cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1); } -- 2.7.4