[U-Boot] [RFC PATCH v2 2/3] net: ag7xxx: Propagate errors on phy access
Marek Vasut
marex at denx.de
Tue Jun 27 09:32:13 UTC 2017
On 06/26/2017 09:40 PM, Joe Hershberger wrote:
> Don't wait forever.
> Pass errors back to the caller.
>
> Signed-off-by: Joe Hershberger <joe.hershberger at ni.com>
Acked-by: Marek Vasut <marex at denx.de>
> ---
>
> Changes in v2:
> - Isolate error propagation changes
>
> drivers/net/ag7xxx.c | 29 ++++++++++++++++++++++++-----
> 1 file changed, 24 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ag7xxx.c b/drivers/net/ag7xxx.c
> index 30771b9..00e6806 100644
> --- a/drivers/net/ag7xxx.c
> +++ b/drivers/net/ag7xxx.c
> @@ -285,18 +285,33 @@ static int ag7xxx_switch_reg_write(struct mii_dev *bus, int reg, u32 val)
> return 0;
> }
>
> -static u16 ag7xxx_mdio_rw(struct mii_dev *bus, int addr, int reg, u32 val)
> +static int ag7xxx_mdio_rw(struct mii_dev *bus, int addr, int reg, u32 val)
> {
> u32 data;
> + unsigned long start;
> + int ret;
> + /* No idea if this is long enough or too long */
> + int timeout_ms = 1000;
>
> /* Dummy read followed by PHY read/write command. */
> - ag7xxx_switch_reg_read(bus, 0x98, &data);
> + ret = ag7xxx_switch_reg_read(bus, 0x98, &data);
> + if (ret < 0)
> + return ret;
> data = val | (reg << 16) | (addr << 21) | BIT(30) | BIT(31);
> - ag7xxx_switch_reg_write(bus, 0x98, data);
> + ret = ag7xxx_switch_reg_write(bus, 0x98, data);
> + if (ret < 0)
> + return ret;
> +
> + start = get_timer(0);
>
> /* Wait for operation to finish */
> do {
> - ag7xxx_switch_reg_read(bus, 0x98, &data);
> + ret = ag7xxx_switch_reg_read(bus, 0x98, &data);
> + if (ret < 0)
> + return ret;
> +
> + if (get_timer(start) > timeout_ms)
> + return -ETIMEDOUT;
> } while (data & BIT(31));
>
> return data & 0xffff;
> @@ -310,7 +325,11 @@ static int ag7xxx_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
> static int ag7xxx_mdio_write(struct mii_dev *bus, int addr, int devad, int reg,
> u16 val)
> {
> - ag7xxx_mdio_rw(bus, addr, reg, val);
> + int ret;
> +
> + ret = ag7xxx_mdio_rw(bus, addr, reg, val);
> + if (ret < 0)
> + return ret;
> return 0;
> }
>
>
--
Best regards,
Marek Vasut
More information about the U-Boot
mailing list