2020-05-26 16:26:24

by Antoine Tenart

[permalink] [raw]
Subject: [PATCH net-next 3/4] net: phy: mscc-miim: improve waiting logic

The MSCC MIIM MDIO driver uses a waiting logic to wait for the MDIO bus
to be ready to accept next commands. It does so by polling the BUSY
status bit which indicates the MDIO bus has completed all pending
operations. This can take time, and the controller supports writing the
next command as soon as there are no pending commands (which happens
while the MDIO bus is busy completing its current command).

This patch implements this improved logic by adding an helper to poll
the PENDING status bit, and by adjusting where we should wait for the
bus to not be busy or to not be pending.

Signed-off-by: Antoine Tenart <[email protected]>
---
drivers/net/phy/mdio-mscc-miim.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/mdio-mscc-miim.c b/drivers/net/phy/mdio-mscc-miim.c
index 42119f661452..aed9afa1e8f1 100644
--- a/drivers/net/phy/mdio-mscc-miim.c
+++ b/drivers/net/phy/mdio-mscc-miim.c
@@ -16,6 +16,7 @@
#include <linux/of_mdio.h>

#define MSCC_MIIM_REG_STATUS 0x0
+#define MSCC_MIIM_STATUS_STAT_PENDING BIT(2)
#define MSCC_MIIM_STATUS_STAT_BUSY BIT(3)
#define MSCC_MIIM_REG_CMD 0x8
#define MSCC_MIIM_CMD_OPR_WRITE BIT(1)
@@ -47,13 +48,23 @@ static int mscc_miim_wait_ready(struct mii_bus *bus)
!(val & MSCC_MIIM_STATUS_STAT_BUSY), 50, 10000);
}

+static int mscc_miim_wait_pending(struct mii_bus *bus)
+{
+ struct mscc_miim_dev *miim = bus->priv;
+ u32 val;
+
+ return readl_poll_timeout(miim->regs + MSCC_MIIM_REG_STATUS, val,
+ !(val & MSCC_MIIM_STATUS_STAT_PENDING),
+ 50, 10000);
+}
+
static int mscc_miim_read(struct mii_bus *bus, int mii_id, int regnum)
{
struct mscc_miim_dev *miim = bus->priv;
u32 val;
int ret;

- ret = mscc_miim_wait_ready(bus);
+ ret = mscc_miim_wait_pending(bus);
if (ret)
goto out;

@@ -82,7 +93,7 @@ static int mscc_miim_write(struct mii_bus *bus, int mii_id,
struct mscc_miim_dev *miim = bus->priv;
int ret;

- ret = mscc_miim_wait_ready(bus);
+ ret = mscc_miim_wait_pending(bus);
if (ret < 0)
goto out;

--
2.26.2


2020-05-27 00:55:06

by Florian Fainelli

[permalink] [raw]
Subject: Re: [PATCH net-next 3/4] net: phy: mscc-miim: improve waiting logic



On 5/26/2020 9:22 AM, Antoine Tenart wrote:
> The MSCC MIIM MDIO driver uses a waiting logic to wait for the MDIO bus
> to be ready to accept next commands. It does so by polling the BUSY
> status bit which indicates the MDIO bus has completed all pending
> operations. This can take time, and the controller supports writing the
> next command as soon as there are no pending commands (which happens
> while the MDIO bus is busy completing its current command).
>
> This patch implements this improved logic by adding an helper to poll
> the PENDING status bit, and by adjusting where we should wait for the
> bus to not be busy or to not be pending.
>
> Signed-off-by: Antoine Tenart <[email protected]>

Reviewed-by: Florian Fainelli <[email protected]>
--
Florian

2020-05-27 03:51:58

by Alexandre Belloni

[permalink] [raw]
Subject: Re: [PATCH net-next 3/4] net: phy: mscc-miim: improve waiting logic

On 26/05/2020 18:22:55+0200, Antoine T?nart wrote:
> The MSCC MIIM MDIO driver uses a waiting logic to wait for the MDIO bus
> to be ready to accept next commands. It does so by polling the BUSY
> status bit which indicates the MDIO bus has completed all pending
> operations. This can take time, and the controller supports writing the
> next command as soon as there are no pending commands (which happens
> while the MDIO bus is busy completing its current command).
>
> This patch implements this improved logic by adding an helper to poll
> the PENDING status bit, and by adjusting where we should wait for the
> bus to not be busy or to not be pending.
>
> Signed-off-by: Antoine Tenart <[email protected]>
Reviewed-by: Alexandre Belloni <[email protected]>

> ---
> drivers/net/phy/mdio-mscc-miim.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/phy/mdio-mscc-miim.c b/drivers/net/phy/mdio-mscc-miim.c
> index 42119f661452..aed9afa1e8f1 100644
> --- a/drivers/net/phy/mdio-mscc-miim.c
> +++ b/drivers/net/phy/mdio-mscc-miim.c
> @@ -16,6 +16,7 @@
> #include <linux/of_mdio.h>
>
> #define MSCC_MIIM_REG_STATUS 0x0
> +#define MSCC_MIIM_STATUS_STAT_PENDING BIT(2)
> #define MSCC_MIIM_STATUS_STAT_BUSY BIT(3)
> #define MSCC_MIIM_REG_CMD 0x8
> #define MSCC_MIIM_CMD_OPR_WRITE BIT(1)
> @@ -47,13 +48,23 @@ static int mscc_miim_wait_ready(struct mii_bus *bus)
> !(val & MSCC_MIIM_STATUS_STAT_BUSY), 50, 10000);
> }
>
> +static int mscc_miim_wait_pending(struct mii_bus *bus)
> +{
> + struct mscc_miim_dev *miim = bus->priv;
> + u32 val;
> +
> + return readl_poll_timeout(miim->regs + MSCC_MIIM_REG_STATUS, val,
> + !(val & MSCC_MIIM_STATUS_STAT_PENDING),
> + 50, 10000);
> +}
> +
> static int mscc_miim_read(struct mii_bus *bus, int mii_id, int regnum)
> {
> struct mscc_miim_dev *miim = bus->priv;
> u32 val;
> int ret;
>
> - ret = mscc_miim_wait_ready(bus);
> + ret = mscc_miim_wait_pending(bus);
> if (ret)
> goto out;
>
> @@ -82,7 +93,7 @@ static int mscc_miim_write(struct mii_bus *bus, int mii_id,
> struct mscc_miim_dev *miim = bus->priv;
> int ret;
>
> - ret = mscc_miim_wait_ready(bus);
> + ret = mscc_miim_wait_pending(bus);
> if (ret < 0)
> goto out;
>
> --
> 2.26.2
>

--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com