mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v1] net: phy: dp83tg720: Decouple PHY reset frequency from link polling interval
Date: Fri, 14 Jun 2024 14:51:17 +0200	[thread overview]
Message-ID: <20240614125117.1707748-1-o.rempel@pengutronix.de> (raw)

Reduce PHY reset frequency to allow for more frequent link polling in
certain cases. This is necessary to ensure barebox can establish a link on
"ifup -a".

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 drivers/net/phy/dp83tg720.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/drivers/net/phy/dp83tg720.c b/drivers/net/phy/dp83tg720.c
index 7e807314ce..385b32046e 100644
--- a/drivers/net/phy/dp83tg720.c
+++ b/drivers/net/phy/dp83tg720.c
@@ -29,6 +29,10 @@
 
 #define DP83TG720S_POLL_TIMEOUT_MS		100
 
+struct dp83tg720_priv {
+	uint64_t last_reset;
+};
+
 static int dp83tg720_config_rgmii_delay(struct phy_device *phydev)
 {
 	u16 rgmii_delay_mask;
@@ -62,6 +66,7 @@ static int dp83tg720_config_rgmii_delay(struct phy_device *phydev)
 
 static int dp83tg720_phy_init(struct phy_device *phydev)
 {
+	struct dp83tg720_priv *priv = phydev->priv;
 	int ret = 0;
 
 	/* HW reset is needed to recover link if previous link was lost. SW
@@ -71,6 +76,12 @@ static int dp83tg720_phy_init(struct phy_device *phydev)
 
 	phydev->supported = SUPPORTED_1000baseT_Full;
 	phydev->advertising = SUPPORTED_1000baseT_Full;
+	priv->last_reset = get_time_ns();
+	/* Randomize the polling interval to avoid reset synchronization with
+	 * the link partner.  The polling interval is set to 150ms +/- 50ms.
+	 */
+	phydev->polling_interval = (DP83TG720S_POLL_TIMEOUT_MS +
+				    (rand() % 10) * 10) * MSECOND;
 
 	/* According to the "DP83TG720R-Q1 1000BASE-T1 Automotive Ethernet PHY
 	 * datasheet (Rev. C)" - "T6.2 Post reset stabilization-time prior to
@@ -93,14 +104,9 @@ static int dp83tg720_phy_init(struct phy_device *phydev)
 
 static int dp83tg720_read_status(struct phy_device *phydev)
 {
+	struct dp83tg720_priv *priv = phydev->priv;
 	u16 phy_sts;
 
-	/* Randomize the polling interval to avoid reset synchronization with
-	 * the link partner.  The polling interval is set to 150ms +/- 50ms.
-	 */
-	phydev->polling_interval = (DP83TG720S_POLL_TIMEOUT_MS +
-				    (rand() % 10) * 10) * MSECOND;
-
 	phy_sts = phy_read(phydev, DP83TG720S_MII_REG_10);
 	phydev->link = !!(phy_sts & DP83TG720S_LINK_STATUS);
 	if (!phydev->link) {
@@ -111,18 +117,24 @@ static int dp83tg720_read_status(struct phy_device *phydev)
 		 * Implementation Guide", the PHY needs to be reset after a
 		 * link loss or if no link is created after at least 100ms.
 		 */
-		dp83tg720_phy_init(phydev);
-		return 0;
+		if (!priv->last_reset ||
+		    is_timeout(priv->last_reset, phydev->polling_interval))
+			dp83tg720_phy_init(phydev);
+	} else {
+		phydev->duplex = DUPLEX_FULL;
+		phydev->speed = SPEED_1000;
 	}
 
-	phydev->duplex = DUPLEX_FULL;
-	phydev->speed = SPEED_1000;
-
 	return 0;
 }
 
 static int dp83tg720_probe(struct phy_device *phydev)
 {
+	struct dp83tg720_priv *priv;
+
+	priv = xzalloc(sizeof(*priv));
+
+	phydev->priv = priv;
 	phydev->polling_interval = DP83TG720S_POLL_TIMEOUT_MS * MSECOND;
 
 	return 0;
-- 
2.39.2




             reply	other threads:[~2024-06-14 12:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-14 12:51 Oleksij Rempel [this message]
2024-06-18  6:50 ` Sascha Hauer

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=20240614125117.1707748-1-o.rempel@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=barebox@lists.infradead.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