From d6cecc7f627fab8404c6d5961e4407cd035398af Mon Sep 17 00:00:00 2001 From: Rene Straub Date: Sat, 5 Jan 2019 12:25:51 +0100 Subject: [PATCH] nmhw21: add configuration option for Ethernet link timeout - env variable linktimeout defines timeout in milliseconds - valid range is 1000 to 10000 ms - default timeout is 5 seconds BugzID: 55019 --- board/nm/nmhw21/board.c | 35 ++++++++++++++++++++++++++++++++- drivers/net/phy/phy.c | 7 +++++-- include/configs/am335x_nmhw21.h | 10 +++++++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/board/nm/nmhw21/board.c b/board/nm/nmhw21/board.c index eae312d76b..afd998d01d 100644 --- a/board/nm/nmhw21/board.c +++ b/board/nm/nmhw21/board.c @@ -494,6 +494,40 @@ void sdram_init(void) #if !defined(CONFIG_SPL_BUILD) +/* + * Override for Ethernet link timeout definition, + * with option to specify via environment variable linktimeout + */ +int eth_phy_timeout(void) +{ + const char* timeout_env = NULL; + int timeout; + + timeout = PHY_ANEG_DEFAULT_TIMEOUT; + + /* + * Check if timeout has been defined by environment. + * Valid range: 1000..10000 milliseconds + */ + timeout_env = getenv("linktimeout"); + if (timeout_env != NULL) { + timeout = simple_strtoul(timeout_env, NULL, 10); + if (timeout == 0) { + timeout = PHY_ANEG_DEFAULT_TIMEOUT; + } else if (timeout < 1000) { + timeout = 1000; + } else if (timeout > 10000) { + timeout = 10000; + } + } + + return timeout; +} + +#endif /* !defined(CONFIG_SPL_BUILD) */ + +#if !defined(CONFIG_SPL_BUILD) + static void init_ethernet(void) { REQUEST_AND_CLEAR_GPIO(GPIO_RST_ETH_N); @@ -899,7 +933,6 @@ static void check_reset_button(void) #endif /* !defined(CONFIG_SPL_BUILD) */ - int board_late_init(void) { #if !defined(CONFIG_SPL_BUILD) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index b8b9b04723..9d4e6956ef 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -222,9 +222,11 @@ int genphy_update_link(struct phy_device *phydev) { unsigned int mii_reg; - /* TODO */ +#ifdef __CONFIG_AM335X_NRHW20_H + /* TODO: Check and remove this NRHW20 work around */ phydev->link = 1; return 0; +#endif /* * Wait if the link is up, and autonegotiation is in progress @@ -241,6 +243,7 @@ int genphy_update_link(struct phy_device *phydev) if ((phydev->autoneg == AUTONEG_ENABLE) && !(mii_reg & BMSR_ANEGCOMPLETE)) { + const int timeout = PHY_ANEG_TIMEOUT; int i = 0; printf("%s Waiting for PHY auto negotiation to complete", @@ -249,7 +252,7 @@ int genphy_update_link(struct phy_device *phydev) /* * Timeout reached ? */ - if (i > PHY_ANEG_TIMEOUT) { + if (i > timeout) { printf(" TIMEOUT !\n"); phydev->link = 0; return -ETIMEDOUT; diff --git a/include/configs/am335x_nmhw21.h b/include/configs/am335x_nmhw21.h index 663b7ee6ec..f846ae75ab 100644 --- a/include/configs/am335x_nmhw21.h +++ b/include/configs/am335x_nmhw21.h @@ -42,6 +42,15 @@ #include +/* Dynamic override for PHY_ANEG_TIMEOUT value */ +#ifndef CONFIG_SPL_BUILD +# ifndef __ASSEMBLER__ +int eth_phy_timeout(void); +# endif +#endif +#define PHY_ANEG_TIMEOUT eth_phy_timeout() +#define PHY_ANEG_DEFAULT_TIMEOUT 5000 + #define CONFIG_ARP_TIMEOUT 200 #undef CONFIG_NET_RETRY_COUNT #define CONFIG_NET_RETRY_COUNT 5 @@ -241,7 +250,6 @@ Memory map: #define CONFIG_PHYLIB #define CONFIG_PHY_SMSC - #define CONFIG_CMD_MEMTEST #define CONFIG_SYS_MEMTEST_START 0x84000000 #define CONFIG_SYS_MEMTEST_END 0x87900000