Re: [PATCH net-next 4/4] net: phy: mscc-miim: read poll when high resolution timers are disabled

From: Florian Fainelli
Date: Tue May 26 2020 - 17:22:36 EST




On 5/26/2020 9:22 AM, Antoine Tenart wrote:
> The driver uses a read polling mechanism to check the status of the MDIO
> bus, to know if it is ready to accept next commands. This polling
> mechanism uses usleep_delay() under the hood between reads which is fine
> as long as high resolution timers are enabled. Otherwise the delays will
> end up to be much longer than expected.
>
> This patch fixes this by using udelay() under the hood when
> CONFIG_HIGH_RES_TIMERS isn't enabled. This increases CPU usage.
>
> Signed-off-by: Antoine Tenart <antoine.tenart@xxxxxxxxxxx>
> ---
> drivers/net/phy/Kconfig | 3 ++-
> drivers/net/phy/mdio-mscc-miim.c | 22 +++++++++++++++++-----
> 2 files changed, 19 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
> index 2a32f26ead0b..047c27087b10 100644
> --- a/drivers/net/phy/Kconfig
> +++ b/drivers/net/phy/Kconfig
> @@ -184,7 +184,8 @@ config MDIO_MSCC_MIIM
> depends on HAS_IOMEM
> help
> This driver supports the MIIM (MDIO) interface found in the network
> - switches of the Microsemi SoCs
> + switches of the Microsemi SoCs; it is recommended to switch on
> + CONFIG_HIGH_RES_TIMERS
>
> config MDIO_MVUSB
> tristate "Marvell USB to MDIO Adapter"
> diff --git a/drivers/net/phy/mdio-mscc-miim.c b/drivers/net/phy/mdio-mscc-miim.c
> index aed9afa1e8f1..11f583fd4611 100644
> --- a/drivers/net/phy/mdio-mscc-miim.c
> +++ b/drivers/net/phy/mdio-mscc-miim.c
> @@ -39,13 +39,25 @@ struct mscc_miim_dev {
> void __iomem *phy_regs;
> };
>
> +/* When high resolution timers aren't built-in: we can't use usleep_range() as
> + * we would sleep way too long. Use udelay() instead.
> + */
> +#define mscc_readl_poll_timeout(addr, val, cond, delay_us, timeout_us) \
> +({ \
> + if (!IS_ENABLED(CONFIG_HIGH_RES_TIMERS)) \
> + readl_poll_timeout_atomic(addr, val, cond, delay_us, \
> + timeout_us); \
> + readl_poll_timeout(addr, val, cond, delay_us, timeout_us); \
> +})
> +

I would make this a regular function which would not harm the compiler's
ability to optimize it, but would give you type checking. With that fixed:

Reviewed-by: Florian Fainelli <f.fainelli@xxxxxxxxx>
--
Florian