[PATCH] net: phy: Support overriding Auto Negotiation timeout with env variable
Siddharth Vadapalli
s-vadapalli at ti.com
Tue Jul 22 15:03:51 CEST 2025
On Tue, Jul 22, 2025 at 02:57:33PM +0200, Marek Vasut wrote:
> On 7/22/25 8:05 AM, Siddharth Vadapalli wrote:
> > The Auto Negotiation procedure between two Ethernet PHYs consists of
> > determining the best commonly supported parameters among Speed,
> > Duplex Mode and Flow Control.
> >
> > The time taken for this procedure is not only dependent on the local
> > PHY used, but also on the link-partner PHY.
> >
> > While a timeout can be specified in the form of a "CONFIG" on the basis
> > of the local PHY present on the device, since the timeout also depends
> > on the link-partner PHY, it might be necessary to modify the timeout.
> >
> > To avoid rebuilding the bootloader for a given device, just because it
> > may be connected to various link-partner PHYs, each with a different
> > timeout, introduce an environment variable named "phy_aneg_timeout" and
> > override "CONFIG_PHY_ANEG_TIMEOUT" with "phy_aneg_timeout".
> >
> > Signed-off-by: Siddharth Vadapalli <s-vadapalli at ti.com>
> > ---
> >
> > Hello,
> >
> > This patch is based on commit
> > 7598b469c16 Merge tag 'u-boot-dfu-next-20250703' of https://source.denx.de/u-boot/custodians/u-boot-dfu into next
> > of the next branch of Mainline U-Boot.
> >
> > Patch has been tested on J784S4-EVM validating the following cases:
> > 1. PHY Auto-Negotiation performed with "phy_aneg_timeout" unset.
> > CONFIG_PHY_TIMEOUT with a value of 4,000 takes effect.
> > => Auto Negotiation succeeds
> > 2. PHY Auto-Negotiation performed with "phy_aneg_timeout" set to 10,000.
> > "phy_aneg_timeout" overrides CONFIG_PHY_TIMEOUT.
> > [Higher value than default specified by CONFIG_PHY_ANEG_TIMEOUT]
> > => Auto Negotiation succeeds
> > 3. PHY Auto-Negotiation performed with "phy_aneg_timeout" set to 2,000.
> > "phy_aneg_timeout" overrides CONFIG_PHY_TIMEOUT.
> > [Lower value than default specified by CONFIG_PHY_ANEG_TIMEOUT]
> > => Auto Negotiation times out
> >
> > Test Logs:
> > https://gist.github.com/Siddharth-Vadapalli-at-TI/697eadcbb26786435df48a834c968375
> >
> > Regards,
> > Siddharth.
> >
> > doc/usage/environment.rst | 8 ++++++++
> > drivers/net/phy/phy.c | 6 +++++-
> > 2 files changed, 13 insertions(+), 1 deletion(-)
> >
> > diff --git a/doc/usage/environment.rst b/doc/usage/environment.rst
> > index bb6c351b441..7447bb85d3e 100644
> > --- a/doc/usage/environment.rst
> > +++ b/doc/usage/environment.rst
> > @@ -335,6 +335,14 @@ netretry
> > Useful on scripts which control the retry operation
> > themselves.
> > +phy_aneg_timeout
> > + If set, the specified value will override CONFIG_PHY_ANEG_TIMEOUT
> > + which defaults to 4000. The default value of CONFIG_PHY_ANEG_TIMEOUT
> > + may be sufficient for most use-cases, but certain link-partners
> > + may require a larger timeout due to the Ethernet PHY they use.
> > + Alternatively, the timeout can be reduced as well if the use-case
> > + demands it.
> > +
> > rng_seed_size
> > Size of random value added to device-tree node /chosen/rng-seed.
> > This variable is given as a decimal number.
> > diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> > index e6fed8c41d7..0f5c9685b59 100644
> > --- a/drivers/net/phy/phy.c
> > +++ b/drivers/net/phy/phy.c
> > @@ -9,6 +9,7 @@
> > */
> > #include <console.h>
> > #include <dm.h>
> > +#include <env.h>
> > #include <log.h>
> > #include <malloc.h>
> > #include <net.h>
> > @@ -243,6 +244,9 @@ int genphy_update_link(struct phy_device *phydev)
> > if ((phydev->autoneg == AUTONEG_ENABLE) &&
> > !(mii_reg & BMSR_ANEGCOMPLETE)) {
> > int i = 0;
> > + char *s = env_get("phy_aneg_timeout");
> env_get_ulong("phy_aneg_timeout", 10, CONFIG_PHY_ANEG_TIMEOUT);
Thank you for the suggestion. I will use the helper mentioned above
instead of the custom implementation in the next version of the patch.
Regards,
Siddharth.
More information about the U-Boot
mailing list