All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Hershberger <joe.hershberger@ni.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] net: Add ag7xxx driver for Atheros MIPS
Date: Thu, 8 Jun 2017 10:04:27 -0500	[thread overview]
Message-ID: <CANr=Z=bt_OA0nTcPVxwxVX3oXDnVbpk95UPfFW3YiWgY2hdqmA@mail.gmail.com> (raw)
In-Reply-To: <1464125349-5321-1-git-send-email-marex@denx.de>

Hi Marek,

I was looking at something else and noticed what looks like an issue
with this code you submitted.

On Tue, May 24, 2016 at 4:29 PM, Marek Vasut <marex@denx.de> wrote:
> Add ethernet driver for the AR933x and AR934x Atheros MIPS machines.
> The driver could be easily extended to other WiSoCs.
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> Cc: Wills Wang <wills.wang@live.com>
> ---
> V2: - Drop the printf() in case malloc fails, it's pointless to try
>       and print something if we cannot allocate memory, since printf
>       also allocates memory.
> V3: - Replace magic 0x11 with MII_MIPSCR register
> ---

[...] SNIP

> +static u16 ag7xxx_mdio_rw(struct mii_dev *bus, int addr, int reg, u32 val)

Returns a u16

> +{
> +       u32 data;
> +
> +       /* Dummy read followed by PHY read/write command. */
> +       ag7xxx_switch_reg_read(bus, 0x98, &data);
> +       data = val | (reg << 16) | (addr << 21) | BIT(30) | BIT(31);
> +       ag7xxx_switch_reg_write(bus, 0x98, data);
> +
> +       /* Wait for operation to finish */
> +       do {
> +               ag7xxx_switch_reg_read(bus, 0x98, &data);
> +       } while (data & BIT(31));
> +
> +       return data & 0xffff;
> +}
> +
> +static int ag7xxx_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
> +{
> +       return ag7xxx_mdio_rw(bus, addr, reg, BIT(27));

Directly returns said u16 as an int.

> +}
> +
> +static int ag7xxx_mdio_write(struct mii_dev *bus, int addr, int devad, int reg,
> +                            u16 val)
> +{
> +       ag7xxx_mdio_rw(bus, addr, reg, val);
> +       return 0;
> +}

[...] SNIP

> +static int ag933x_phy_setup_common(struct udevice *dev)
> +{
> +       struct ar7xxx_eth_priv *priv = dev_get_priv(dev);
> +       int i, ret, phymax;
> +
> +       if (priv->model == AG7XXX_MODEL_AG933X)
> +               phymax = 4;
> +       else if (priv->model == AG7XXX_MODEL_AG934X)
> +               phymax = 5;
> +       else
> +               return -EINVAL;
> +
> +       if (priv->interface == PHY_INTERFACE_MODE_RMII) {
> +               ret = ag933x_phy_setup_reset_set(dev, phymax);
> +               if (ret)
> +                       return ret;
> +
> +               ret = ag933x_phy_setup_reset_fin(dev, phymax);
> +               if (ret)
> +                       return ret;
> +
> +               /* Read out link status */
> +               ret = ag7xxx_mdio_read(priv->bus, phymax, 0, MII_MIPSCR);

Read the link status, which can never be negative.

Another issue: Is MII_MIPSCR really the register name? It's not better
than "17" - constants should mean something, just just be a random
name with the right value.

> +               if (ret < 0)
> +                       return ret;
> +
> +               return 0;

Return 0 unconditionally. Presumably you want to actually check the
link status to be something specific if you bother to read it out.

> +       }
> +
> +       /* Switch ports */
> +       for (i = 0; i < phymax; i++) {
> +               ret = ag933x_phy_setup_reset_set(dev, i);
> +               if (ret)
> +                       return ret;
> +       }
> +
> +       for (i = 0; i < phymax; i++) {
> +               ret = ag933x_phy_setup_reset_fin(dev, i);
> +               if (ret)
> +                       return ret;
> +       }
> +
> +       for (i = 0; i < phymax; i++) {
> +               /* Read out link status */
> +               ret = ag7xxx_mdio_read(priv->bus, i, 0, MII_MIPSCR);

Same thing here.

> +               if (ret < 0)
> +                       return ret;
> +       }
> +
> +       return 0;
> +}

  parent reply	other threads:[~2017-06-08 15:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-24 21:29 [U-Boot] [PATCH] net: Add ag7xxx driver for Atheros MIPS Marek Vasut
2016-05-30 10:05 ` Daniel Schwierzeck
2017-06-08 15:04 ` Joe Hershberger [this message]
2017-06-09  9:02   ` Marek Vasut
  -- strict thread matches above, loose matches on Subject: below --
2016-05-05 19:34 Marek Vasut
2016-05-08 12:58 ` Daniel Schwierzeck
2016-05-08 15:22   ` Marek Vasut
2016-05-20  4:18     ` Wills Wang
2016-05-20 11:59       ` Marek Vasut
2016-05-20 16:43         ` Wills Wang
2016-05-20 17:08           ` Marek Vasut
2016-05-21  3:25             ` Wills Wang
2016-05-21  9:29               ` Marek Vasut
2016-05-24 15:15                 ` Joe Hershberger
2016-05-24 15:17                   ` Marek Vasut
2016-05-24 15:22                     ` Marek Vasut
2016-05-21 11:03             ` Wills Wang
2016-05-21 11:37               ` Marek Vasut
2016-05-08 21:25 ` Amit Tomer
2016-05-08 22:09   ` Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CANr=Z=bt_OA0nTcPVxwxVX3oXDnVbpk95UPfFW3YiWgY2hdqmA@mail.gmail.com' \
    --to=joe.hershberger@ni.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.