From 268531be211f18c55f7ff5a1641d32c0fd0571cd Mon Sep 17 00:00:00 2001 From: Justin Chen Date: Wed, 13 Dec 2023 14:27:43 -0800 Subject: [PATCH 1/2] net: mdio: mdio-bcm-unimac: Delay before first poll With a clock interval of 400 nsec and a 64 bit transactions (32 bit preamble & 16 bit control & 16 bit data), it is reasonable to assume the mdio transaction will take 25.6 usec. Add a 30 usec delay before the first poll to reduce the chance of a 1000-2000 usec sleep. Reduce the timeout from 1000ms to 100ms as it is unlikely for the bus to take this long. Signed-off-by: Justin Chen Acked-by: Florian Fainelli Reviewed-by: Andrew Lunn Link: https://lore.kernel.org/r/20231213222744.2891184-2-justin.chen@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-bcm-unimac.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c index e8cd8eef319b..297ea4a58d79 100644 --- a/drivers/net/mdio/mdio-bcm-unimac.c +++ b/drivers/net/mdio/mdio-bcm-unimac.c @@ -81,7 +81,13 @@ static inline unsigned int unimac_mdio_busy(struct unimac_mdio_priv *priv) static int unimac_mdio_poll(void *wait_func_data) { struct unimac_mdio_priv *priv = wait_func_data; - unsigned int timeout = 1000; + unsigned int timeout = 100; + + /* + * C22 transactions should take ~25 usec, will need to adjust + * if C45 support is added. + */ + udelay(30); do { if (!unimac_mdio_busy(priv)) From 54a600ed217036f231805703cedd9f8f98d3f40a Mon Sep 17 00:00:00 2001 From: Justin Chen Date: Wed, 13 Dec 2023 14:27:44 -0800 Subject: [PATCH 2/2] net: mdio: mdio-bcm-unimac: Use read_poll_timeout Simplify the code by using read_poll_timeout(). Signed-off-by: Justin Chen Reviewed-by: Andrew Lunn Link: https://lore.kernel.org/r/20231213222744.2891184-3-justin.chen@broadcom.com Signed-off-by: Jakub Kicinski --- drivers/net/mdio/mdio-bcm-unimac.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/drivers/net/mdio/mdio-bcm-unimac.c b/drivers/net/mdio/mdio-bcm-unimac.c index 297ea4a58d79..68f8ee0ec8ba 100644 --- a/drivers/net/mdio/mdio-bcm-unimac.c +++ b/drivers/net/mdio/mdio-bcm-unimac.c @@ -73,15 +73,10 @@ static inline void unimac_mdio_start(struct unimac_mdio_priv *priv) unimac_mdio_writel(priv, reg, MDIO_CMD); } -static inline unsigned int unimac_mdio_busy(struct unimac_mdio_priv *priv) -{ - return unimac_mdio_readl(priv, MDIO_CMD) & MDIO_START_BUSY; -} - static int unimac_mdio_poll(void *wait_func_data) { struct unimac_mdio_priv *priv = wait_func_data; - unsigned int timeout = 100; + u32 val; /* * C22 transactions should take ~25 usec, will need to adjust @@ -89,14 +84,8 @@ static int unimac_mdio_poll(void *wait_func_data) */ udelay(30); - do { - if (!unimac_mdio_busy(priv)) - return 0; - - usleep_range(1000, 2000); - } while (--timeout); - - return -ETIMEDOUT; + return read_poll_timeout(unimac_mdio_readl, val, !(val & MDIO_START_BUSY), + 2000, 100000, false, priv, MDIO_CMD); } static int unimac_mdio_read(struct mii_bus *bus, int phy_id, int reg)