From patchwork Tue Mar 30 12:53:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "humin (Q)" X-Patchwork-Id: 90107 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A2937A0548; Tue, 30 Mar 2021 14:53:07 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 33670406B4; Tue, 30 Mar 2021 14:53:07 +0200 (CEST) Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by mails.dpdk.org (Postfix) with ESMTP id 143CA40691 for ; Tue, 30 Mar 2021 14:53:06 +0200 (CEST) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F8q6p011Wzmbcy for ; Tue, 30 Mar 2021 20:50:25 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.498.0; Tue, 30 Mar 2021 20:52:59 +0800 From: "Min Hu (Connor)" To: CC: Date: Tue, 30 Mar 2021 20:53:25 +0800 Message-ID: <1617108805-9096-1-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH] net/hns3: support wait to complete in link update API 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 There are two APIs in ethdev layer to get link status of device, namely, "rte_eth_link_get" and "rte_eth_link_get_nowait". When the device link is unstable or auto-negotiation is in progress, the first API supports the function of waiting for the NIC to link up, and the maximum waiting time is 9 seconds based on DPDK Documentation. For the hns3 PMD driver, the link can be established within 2 seconds. Signed-off-by: Huisong Li Signed-off-by: Min Hu (Connor) --- drivers/net/hns3/hns3_ethdev.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c index 9c71808..4883cb7 100644 --- a/drivers/net/hns3/hns3_ethdev.c +++ b/drivers/net/hns3/hns3_ethdev.c @@ -2741,19 +2741,31 @@ hns3_setup_linkstatus(struct rte_eth_dev *eth_dev, } static int -hns3_dev_link_update(struct rte_eth_dev *eth_dev, - __rte_unused int wait_to_complete) +hns3_dev_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete) { +#define HNS3_LINK_CHECK_INTERVAL 100 /* 100ms */ +#define HNS3_MAX_LINK_CHECK_TIMES 20 /* 2s (100 * 20ms) in total */ + struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private); + uint32_t retry_cnt = HNS3_MAX_LINK_CHECK_TIMES; struct hns3_mac *mac = &hw->mac; struct rte_eth_link new_link; int ret; - ret = hns3_update_port_link_info(eth_dev); - if (ret) { - mac->link_status = ETH_LINK_DOWN; - hns3_err(hw, "failed to get port link info, ret = %d.", ret); - } + do { + ret = hns3_update_port_link_info(eth_dev); + if (ret) { + mac->link_status = ETH_LINK_DOWN; + hns3_err(hw, "failed to get port link info, ret = %d.", + ret); + break; + } + + if (!wait_to_complete || mac->link_status == ETH_LINK_UP) + break; + + rte_delay_ms(HNS3_LINK_CHECK_INTERVAL); + } while (retry_cnt--); memset(&new_link, 0, sizeof(new_link)); hns3_setup_linkstatus(eth_dev, &new_link);