DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jiawen Wu <jiawenwu@trustnetic.com>
To: dev@dpdk.org
Cc: Jiawen Wu <jiawenwu@trustnetic.com>
Subject: [PATCH v2 05/12] net/ngbe: optimize the PHY initialization process
Date: Wed,  9 Feb 2022 18:42:06 +0800	[thread overview]
Message-ID: <20220209104213.602728-6-jiawenwu@trustnetic.com> (raw)
In-Reply-To: <20220209104213.602728-1-jiawenwu@trustnetic.com>

Reduce the probability of PHY init failure, And add its error return.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
 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




  parent reply	other threads:[~2022-02-09 10:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-09 10:42 [PATCH v2 00/12] Wangxun fixes and supports Jiawen Wu
2022-02-09 10:42 ` [PATCH v2 01/12] net/ngbe: fix failed to receive packets Jiawen Wu
2022-02-09 10:42 ` [PATCH v2 02/12] net/ngbe: fix link interrupt sometimes lost Jiawen Wu
2022-02-09 10:42 ` [PATCH v2 03/12] net/ngbe: fix Tx pending Jiawen Wu
2022-02-09 19:07   ` Ferruh Yigit
2022-02-09 10:42 ` [PATCH v2 04/12] net/ngbe: fix RxTx packet statistics Jiawen Wu
2022-02-09 10:42 ` Jiawen Wu [this message]
2022-02-09 10:42 ` [PATCH v2 06/12] net/ngbe: add support to custom PHY interfaces Jiawen Wu
2022-02-09 10:42 ` [PATCH v2 07/12] net/ngbe: add LED OEM support Jiawen Wu
2022-02-09 19:06   ` Ferruh Yigit
2022-02-09 10:42 ` [PATCH v2 08/12] net/ngbe: fix debug log Jiawen Wu
2022-02-09 19:07   ` Ferruh Yigit
2022-02-10  8:03     ` Jiawen Wu
2022-02-10  9:02       ` Ferruh Yigit
2022-02-10  9:49         ` Jiawen Wu
2022-02-10 10:16           ` Ferruh Yigit
2022-02-11  2:02             ` Jiawen Wu
2022-02-09 10:42 ` [PATCH v2 09/12] net/txgbe: add LED OEM support Jiawen Wu
2022-02-09 10:42 ` [PATCH v2 10/12] net/txgbe: fix debug log Jiawen Wu
2022-02-09 19:07   ` Ferruh Yigit
2022-02-09 10:42 ` [PATCH v2 11/12] net/txgbe: fix to set link up and down Jiawen Wu
2022-02-09 10:42 ` [PATCH v2 12/12] net/txgbe: fix KR auto-negotiation Jiawen Wu
2022-02-09 19:06 ` [PATCH v2 00/12] Wangxun fixes and supports Ferruh Yigit
2022-02-11 13:10 ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220209104213.602728-6-jiawenwu@trustnetic.com \
    --to=jiawenwu@trustnetic.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).