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 9D471A04A6; Wed, 9 Feb 2022 11:36:17 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4B75C411E1; Wed, 9 Feb 2022 11:35:53 +0100 (CET) Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) by mails.dpdk.org (Postfix) with ESMTP id 860BF411B2 for ; Wed, 9 Feb 2022 11:35:51 +0100 (CET) X-QQ-mid: bizesmtp37t1644402943tcx5ws31 Received: from wxdbg.localdomain.com (unknown [183.129.236.74]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 09 Feb 2022 18:35:42 +0800 (CST) X-QQ-SSF: 01400000002000F0L000B00A0000000 X-QQ-FEAT: jfdGVjI73+RkmG2ygSEvPskmtH364P1KcwvGy6RlQm1cW9Qf9CR9g+hO4gIQa 73PAZUww5uxhH7+X5ACh6TDCVpfO9MUU120n1pUPYjSf7t5IBHhOTMgDfX5eoeNACb5aIjT vxHVTKXp/LtrBWfRktn12O7OY5nFaevJrQQB8Rfj58yeW4P3XUN9+7BUcLK0IKfJxIohrZA ly2khjfKsT8G7jtwzHuWkNVSPKQz1z4RrgN0QIe7Q/AEK4EqP4gKAgQfp5p46+yYRKSKuaU FsFLfyHyNP1UQThmrtsRCRMHi0LCvXpy3FZmA1R6EEL6kz0VPV20uEh1ty9Qmka+hLquYnh xMuiD1RFwVgPE3UMUXmKgM2YB38gOll0VxvJZaoCbhQFnsn/XkEh/H1gW1p/g== X-QQ-GoodBg: 2 From: Jiawen Wu To: dev@dpdk.org Cc: Jiawen Wu Subject: [PATCH v2 05/12] net/ngbe: optimize the PHY initialization process Date: Wed, 9 Feb 2022 18:42:06 +0800 Message-Id: <20220209104213.602728-6-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220209104213.602728-1-jiawenwu@trustnetic.com> References: <20220209104213.602728-1-jiawenwu@trustnetic.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybgforeign:qybgforeign7 X-QQ-Bgrelay: 1 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 Reduce the probability of PHY init failure, And add its error return. Signed-off-by: Jiawen Wu --- drivers/net/ngbe/base/ngbe_hw.c | 7 ++--- drivers/net/ngbe/base/ngbe_phy_rtl.c | 40 +++++++++++++--------------- drivers/net/ngbe/ngbe_ethdev.c | 6 ++++- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/drivers/net/ngbe/base/ngbe_hw.c b/drivers/net/ngbe/base/ngbe_hw.c index 782fd71d29..72d475ccf9 100644 --- a/drivers/net/ngbe/base/ngbe_hw.c +++ b/drivers/net/ngbe/base/ngbe_hw.c @@ -1145,6 +1145,7 @@ s32 ngbe_set_pcie_master(struct ngbe_hw *hw, bool enable) s32 ngbe_acquire_swfw_sync(struct ngbe_hw *hw, u32 mask) { u32 mngsem = 0; + u32 fwsm = 0; u32 swmask = NGBE_MNGSEM_SW(mask); u32 fwmask = NGBE_MNGSEM_FW(mask); u32 timeout = 200; @@ -1173,9 +1174,9 @@ s32 ngbe_acquire_swfw_sync(struct ngbe_hw *hw, u32 mask) } } - /* If time expired clear the bits holding the lock and retry */ - if (mngsem & (fwmask | swmask)) - ngbe_release_swfw_sync(hw, mngsem & (fwmask | swmask)); + fwsm = rd32(hw, NGBE_MNGFWSYNC); + DEBUGOUT("SWFW semaphore not granted: MNG_SWFW_SYNC = 0x%x, MNG_FW_SM = 0x%x\n", + mngsem, fwsm); msec_delay(5); return NGBE_ERR_SWFW_SYNC; diff --git a/drivers/net/ngbe/base/ngbe_phy_rtl.c b/drivers/net/ngbe/base/ngbe_phy_rtl.c index 7b08b7a46c..c59efe3153 100644 --- a/drivers/net/ngbe/base/ngbe_phy_rtl.c +++ b/drivers/net/ngbe/base/ngbe_phy_rtl.c @@ -4,8 +4,6 @@ #include "ngbe_phy_rtl.h" -#define RTL_PHY_RST_WAIT_PERIOD 5 - s32 ngbe_read_phy_reg_rtl(struct ngbe_hw *hw, u32 reg_addr, u32 device_type, u16 *phy_data) { @@ -61,34 +59,44 @@ s32 ngbe_init_phy_rtl(struct ngbe_hw *hw) return NGBE_ERR_PHY_TIMEOUT; } - for (i = 0; i < 1000; i++) { - hw->phy.read_reg(hw, RTL_INSR, 0xa43, &value); - if (value & RTL_INSR_ACCESS) - break; + hw->phy.write_reg(hw, RTL_SCR, 0xa46, RTL_SCR_EFUSE); + hw->phy.read_reg(hw, RTL_SCR, 0xa46, &value); + if (!(value & RTL_SCR_EFUSE)) { + DEBUGOUT("Write EFUSE failed.\n"); + return NGBE_ERR_PHY_TIMEOUT; } - hw->phy.write_reg(hw, RTL_SCR, 0xa46, RTL_SCR_EFUSE); for (i = 0; i < 1000; i++) { hw->phy.read_reg(hw, RTL_INSR, 0xa43, &value); if (value & RTL_INSR_ACCESS) break; + msec_delay(1); } if (i == 1000) - return NGBE_ERR_PHY_TIMEOUT; + DEBUGOUT("PHY wait mdio 1 access timeout.\n"); + hw->phy.write_reg(hw, RTL_SCR, 0xa46, RTL_SCR_EXTINI); + hw->phy.read_reg(hw, RTL_SCR, 0xa46, &value); + if (!(value & RTL_SCR_EXTINI)) { + DEBUGOUT("Write EXIINI failed.\n"); + return NGBE_ERR_PHY_TIMEOUT; + } + for (i = 0; i < 1000; i++) { hw->phy.read_reg(hw, RTL_INSR, 0xa43, &value); if (value & RTL_INSR_ACCESS) break; + msec_delay(1); } if (i == 1000) - return NGBE_ERR_PHY_TIMEOUT; + DEBUGOUT("PHY wait mdio 2 access timeout.\n"); for (i = 0; i < 1000; i++) { hw->phy.read_reg(hw, RTL_GSR, 0xa42, &value); if ((value & RTL_GSR_ST) == RTL_GSR_ST_LANON) break; + msec_delay(1); } if (i == 1000) return NGBE_ERR_PHY_TIMEOUT; @@ -226,7 +234,7 @@ s32 ngbe_setup_phy_link_rtl(struct ngbe_hw *hw, s32 ngbe_reset_phy_rtl(struct ngbe_hw *hw) { - u16 value = 0, i; + u16 value = 0; s32 status = 0; DEBUGFUNC("ngbe_reset_phy_rtl"); @@ -234,17 +242,7 @@ s32 ngbe_reset_phy_rtl(struct ngbe_hw *hw) value |= RTL_BMCR_RESET; status = hw->phy.write_reg(hw, RTL_BMCR, RTL_DEV_ZERO, value); - for (i = 0; i < RTL_PHY_RST_WAIT_PERIOD; i++) { - status = hw->phy.read_reg(hw, RTL_BMCR, RTL_DEV_ZERO, &value); - if (!(value & RTL_BMCR_RESET)) - break; - msleep(1); - } - - if (i == RTL_PHY_RST_WAIT_PERIOD) { - DEBUGOUT("PHY reset polling failed to complete.\n"); - return NGBE_ERR_RESET_FAILED; - } + msec_delay(5); return status; } diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c index 30c9e68579..cc530fdced 100644 --- a/drivers/net/ngbe/ngbe_ethdev.c +++ b/drivers/net/ngbe/ngbe_ethdev.c @@ -1058,7 +1058,11 @@ ngbe_dev_start(struct rte_eth_dev *dev) speed |= NGBE_LINK_SPEED_10M_FULL; } - hw->phy.init_hw(hw); + err = hw->phy.init_hw(hw); + if (err != 0) { + PMD_INIT_LOG(ERR, "PHY init failed"); + goto error; + } err = hw->mac.setup_link(hw, speed, link_up); if (err != 0) goto error; -- 2.21.0.windows.1